]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.1.1844: buffer no longer unloaded when adding text properties v8.1.1844
authorBram Moolenaar <Bram@vim.org>
Tue, 13 Aug 2019 20:27:32 +0000 (22:27 +0200)
committerBram Moolenaar <Bram@vim.org>
Tue, 13 Aug 2019 20:27:32 +0000 (22:27 +0200)
Problem:    Buffer no longer unloaded when adding text properties to it.
Solution:   Do not create the memfile. (closes #4808)

runtime/doc/textprop.txt
src/testdir/test_textprop.vim
src/textprop.c
src/version.c

index 185a60b2b2777d14dfdf598c92e8f28bd5cc4b51..14ea58fde0e32f60ad4f392564b9bdc17d228dd4 100644 (file)
@@ -322,6 +322,11 @@ will move accordingly.
 When text is deleted and a text property no longer includes any text, it is
 deleted.  However, a text property that was defined as zero-width will remain,
 unless the whole line is deleted.
+`                                                              *E275*
+When a buffer is unloaded, all the text properties are gone.  There is no way
+to store the properties in a file.  You can only re-create them.  When a
+buffer is hidden the text is preserved and so are the text properties.  It is
+not possible to add text properties to an unloaded buffer.
 
 When using replace mode, the text properties stay on the same character
 positions, even though the characters themselves change.
index d7e77f985f5a878aa67cad6188f196b1c30202c4..3d3cce8158e55cdd7c1f812a199eb4abad2a6b65 100644 (file)
@@ -823,3 +823,25 @@ func Test_textprop_remove_from_buf()
   bwipe! x
   close
 endfunc
+
+func Test_textprop_in_unloaded_buf()
+  edit Xaaa
+  call setline(1, 'aaa')
+  write
+  edit Xbbb
+  call setline(1, 'bbb')
+  write
+  let bnr = bufnr('')
+  edit Xaaa
+
+  call prop_type_add('ErrorMsg', #{highlight:'ErrorMsg'})
+  call assert_fails("call prop_add(1, 1, #{end_lnum: 1, endcol: 2, type: 'ErrorMsg', bufnr: bnr})", 'E275:')
+  exe 'buf ' .. bnr
+  call assert_equal('bbb', getline(1))
+  call assert_equal(0, prop_list(1)->len())
+
+  bwipe! Xaaa
+  bwipe! Xbbb
+  cal delete('Xaaa')
+  cal delete('Xbbb')
+endfunc
index a976414290813c9120efaa9b5c1dce246128efcb..309f3cb795d4c49a041a01ce59ec8e425108c958 100644 (file)
@@ -256,7 +256,10 @@ prop_add_common(
     }
 
     if (buf->b_ml.ml_mfp == NULL)
-       ml_open(buf);
+    {
+       emsg(_("E275: Cannot add text property to unloaded buffer"));
+       return;
+    }
 
     for (lnum = start_lnum; lnum <= end_lnum; ++lnum)
     {
index 5741d5fdaacbacb2628385a99f3a12134de2eb88..f998c52586060ca468913707b3b9cc1bc64ee7a5 100644 (file)
@@ -769,6 +769,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1844,
 /**/
     1843,
 /**/