Skip to content

Commit 0c4dc88

Browse files
committed
patch 8.0.1274: setbufline() fails when using folding
Problem: setbufline() fails when using folding. Solution: Set "curwin" if needed. (Ozaki Kiichi, closes #2293)
1 parent 4148be4 commit 0c4dc88

3 files changed

Lines changed: 51 additions & 4 deletions

File tree

src/evalfunc.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9891,7 +9891,8 @@ set_buffer_lines(buf_T *buf, linenr_T lnum, typval_T *lines, typval_T *rettv)
98919891
listitem_T *li = NULL;
98929892
long added = 0;
98939893
linenr_T lcount;
9894-
buf_T *curbuf_save;
9894+
buf_T *curbuf_save = NULL;
9895+
win_T *curwin_save = NULL;
98959896
int is_curbuf = buf == curbuf;
98969897

98979898
/* When using the current buffer ml_mfp will be set if needed. Useful when
@@ -9903,8 +9904,22 @@ set_buffer_lines(buf_T *buf, linenr_T lnum, typval_T *lines, typval_T *rettv)
99039904
return;
99049905
}
99059906

9906-
curbuf_save = curbuf;
9907-
curbuf = buf;
9907+
if (!is_curbuf)
9908+
{
9909+
wininfo_T *wip;
9910+
9911+
curbuf_save = curbuf;
9912+
curwin_save = curwin;
9913+
curbuf = buf;
9914+
for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next)
9915+
{
9916+
if (wip->wi_win != NULL)
9917+
{
9918+
curwin = wip->wi_win;
9919+
break;
9920+
}
9921+
}
9922+
}
99089923

99099924
lcount = curbuf->b_ml.ml_line_count;
99109925

@@ -9967,7 +9982,11 @@ set_buffer_lines(buf_T *buf, linenr_T lnum, typval_T *lines, typval_T *rettv)
99679982
if (added > 0)
99689983
appended_lines_mark(lcount, added);
99699984

9970-
curbuf = curbuf_save;
9985+
if (!is_curbuf)
9986+
{
9987+
curbuf = curbuf_save;
9988+
curwin = curwin_save;
9989+
}
99719990
}
99729991

99739992
/*

src/testdir/test_bufline.vim

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,32 @@ func Test_setbufline_getbufline()
2727
exe "bwipe! " . b
2828
endfunc
2929

30+
func Test_setbufline_getbufline_fold()
31+
split Xtest
32+
setlocal foldmethod=expr foldexpr=0
33+
let b = bufnr('%')
34+
new
35+
call assert_equal(0, setbufline(b, 1, ['foo', 'bar']))
36+
call assert_equal(['foo'], getbufline(b, 1))
37+
call assert_equal(['bar'], getbufline(b, 2))
38+
call assert_equal(['foo', 'bar'], getbufline(b, 1, 2))
39+
exe "bwipe!" b
40+
bwipe!
41+
endfunc
42+
43+
func Test_setbufline_getbufline_fold_tab()
44+
split Xtest
45+
setlocal foldmethod=expr foldexpr=0
46+
let b = bufnr('%')
47+
tab new
48+
call assert_equal(0, setbufline(b, 1, ['foo', 'bar']))
49+
call assert_equal(['foo'], getbufline(b, 1))
50+
call assert_equal(['bar'], getbufline(b, 2))
51+
call assert_equal(['foo', 'bar'], getbufline(b, 1, 2))
52+
exe "bwipe!" b
53+
bwipe!
54+
endfunc
55+
3056
func Test_setline_startup()
3157
let cmd = GetVimCommand('Xscript')
3258
if cmd == ''

src/version.c

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

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
1274,
764766
/**/
765767
1273,
766768
/**/

0 commit comments

Comments
 (0)