]> granicus.if.org Git - vim/commitdiff
patch 8.1.1360: buffer left 'nomodifiable' after :substitute v8.1.1360
authorBram Moolenaar <Bram@vim.org>
Mon, 20 May 2019 18:34:51 +0000 (20:34 +0200)
committerBram Moolenaar <Bram@vim.org>
Mon, 20 May 2019 18:34:51 +0000 (20:34 +0200)
Problem:    Buffer left 'nomodifiable' after :substitute. (Ingo Karkat)
Solution:   Save the value of 'modifiable' earlier' (Christian Brabandt,
            closes #4403)

src/ex_cmds.c
src/testdir/test_substitute.vim
src/version.c

index df5dcd01ffbea895b5398e42eed853211124de58..0174fd6b012f927e1b5e6f25bf67753affac738f 100644 (file)
@@ -5557,6 +5557,7 @@ do_sub(exarg_T *eap)
                 * 3. substitute the string.
                 */
 #ifdef FEAT_EVAL
+               save_ma = curbuf->b_p_ma;
                if (subflags.do_count)
                {
                    // prevent accidentally changing the buffer by a function
@@ -5566,7 +5567,6 @@ do_sub(exarg_T *eap)
                // Save flags for recursion.  They can change for e.g.
                // :s/^/\=execute("s#^##gn")
                subflags_save = subflags;
-               save_ma = curbuf->b_p_ma;
 #endif
                // get length of substitution part
                sublen = vim_regsub_multi(&regmatch,
index 06bdc243db957ee53f40deb44a0a6876f4a757ef..344bb68da79cac433aa4eb02e288861d47890e8a 100644 (file)
@@ -611,9 +611,24 @@ func Test_sub_cmd_8()
   set titlestring&
 endfunc
 
+func Test_sub_cmd_9()
+  new
+  let input = ['1 aaa', '2 aaa', '3 aaa']
+  call setline(1, input)
+  func Foo()
+    return submatch(0)
+  endfunc
+  %s/aaa/\=Foo()/gn
+  call assert_equal(input, getline(1, '$'))
+  call assert_equal(1, &modifiable)
+
+  delfunc Foo
+  bw!
+endfunc
+
 func Test_nocatch_sub_failure_handling()
   " normal error results in all replacements 
-  func! Foo()
+  func Foo()
     foobar
   endfunc
   new
@@ -649,6 +664,7 @@ func Test_nocatch_sub_failure_handling()
   call assert_equal(1, error_caught)
   call assert_equal(['1 aaa', '2 aaa', '3 aaa'], getline(1, 3))
 
+  delfunc Foo
   bwipe!
 endfunc
 
index f9962a0cfdeaab31ab8d014123d21f8d91c4cd0c..01a0b0d6223024642eadc44b574e6e7aceac405f 100644 (file)
@@ -767,6 +767,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1360,
 /**/
     1359,
 /**/