Skip to content

Commit 80341bc

Browse files
committed
patch 8.1.1360: buffer left 'nomodifiable' after :substitute
Problem: Buffer left 'nomodifiable' after :substitute. (Ingo Karkat) Solution: Save the value of 'modifiable' earlier' (Christian Brabandt, closes #4403)
1 parent f3333b0 commit 80341bc

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

src/ex_cmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5557,6 +5557,7 @@ do_sub(exarg_T *eap)
55575557
* 3. substitute the string.
55585558
*/
55595559
#ifdef FEAT_EVAL
5560+
save_ma = curbuf->b_p_ma;
55605561
if (subflags.do_count)
55615562
{
55625563
// prevent accidentally changing the buffer by a function
@@ -5566,7 +5567,6 @@ do_sub(exarg_T *eap)
55665567
// Save flags for recursion. They can change for e.g.
55675568
// :s/^/\=execute("s#^##gn")
55685569
subflags_save = subflags;
5569-
save_ma = curbuf->b_p_ma;
55705570
#endif
55715571
// get length of substitution part
55725572
sublen = vim_regsub_multi(&regmatch,

src/testdir/test_substitute.vim

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,9 +611,24 @@ func Test_sub_cmd_8()
611611
set titlestring&
612612
endfunc
613613

614+
func Test_sub_cmd_9()
615+
new
616+
let input = ['1 aaa', '2 aaa', '3 aaa']
617+
call setline(1, input)
618+
func Foo()
619+
return submatch(0)
620+
endfunc
621+
%s/aaa/\=Foo()/gn
622+
call assert_equal(input, getline(1, '$'))
623+
call assert_equal(1, &modifiable)
624+
625+
delfunc Foo
626+
bw!
627+
endfunc
628+
614629
func Test_nocatch_sub_failure_handling()
615630
" normal error results in all replacements
616-
func! Foo()
631+
func Foo()
617632
foobar
618633
endfunc
619634
new
@@ -649,6 +664,7 @@ func Test_nocatch_sub_failure_handling()
649664
call assert_equal(1, error_caught)
650665
call assert_equal(['1 aaa', '2 aaa', '3 aaa'], getline(1, 3))
651666

667+
delfunc Foo
652668
bwipe!
653669
endfunc
654670

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,8 @@ static char *(features[]) =
767767

768768
static int included_patches[] =
769769
{ /* Add new patch number below this line */
770+
/**/
771+
1360,
770772
/**/
771773
1359,
772774
/**/

0 commit comments

Comments
 (0)