vim-patch:9.0.0841: deletebufline() does not always return 1 on failure (#20980)

Problem:    deletebufline() does not always return 1 on failure.
Solution:   Refactor the code to make it work more predictable. (closes vim/vim#11511)

7af3ee2b83
This commit is contained in:
zeertzjq
2022-11-07 07:03:31 +08:00
committed by GitHub
parent 08d53633d4
commit 3b3611a3d0
2 changed files with 39 additions and 21 deletions

View File

@@ -1510,6 +1510,7 @@ static void f_deletebufline(typval_T *argvars, typval_T *rettv, EvalFuncData fpt
buf_T *curbuf_save = NULL; buf_T *curbuf_save = NULL;
win_T *curwin_save = NULL; win_T *curwin_save = NULL;
// After this don't use "return", goto "cleanup"!
if (!is_curbuf) { if (!is_curbuf) {
VIsual_active = false; VIsual_active = false;
curbuf_save = curbuf; curbuf_save = curbuf;
@@ -1530,8 +1531,9 @@ static void f_deletebufline(typval_T *argvars, typval_T *rettv, EvalFuncData fpt
} }
if (u_save(first - 1, last + 1) == FAIL) { if (u_save(first - 1, last + 1) == FAIL) {
rettv->vval.v_number = 1; // FAIL goto cleanup;
} else { }
for (linenr_T lnum = first; lnum <= last; lnum++) { for (linenr_T lnum = first; lnum <= last; lnum++) {
ml_delete(first, true); ml_delete(first, true);
} }
@@ -1550,14 +1552,14 @@ static void f_deletebufline(typval_T *argvars, typval_T *rettv, EvalFuncData fpt
} }
check_cursor_col(); check_cursor_col();
deleted_lines_mark(first, count); deleted_lines_mark(first, count);
} rettv->vval.v_number = 0; // OK
cleanup:
if (!is_curbuf) { if (!is_curbuf) {
curbuf = curbuf_save; curbuf = curbuf_save;
curwin = curwin_save; curwin = curwin_save;
VIsual_active = save_VIsual_active; VIsual_active = save_VIsual_active;
} }
rettv->vval.v_number = 0; // OK
} }
/// "did_filetype()" function /// "did_filetype()" function

View File

@@ -239,4 +239,20 @@ func Test_setbufline_startup_nofile()
call delete('Xresult') call delete('Xresult')
endfunc endfunc
" Test that setbufline(), appendbufline() and deletebufline() should fail and
" return 1 when "textlock" is active.
func Test_change_bufline_with_textlock()
new
inoremap <buffer> <expr> <F2> setbufline('', 1, '')
call assert_fails("normal a\<F2>", 'E565:')
call assert_equal('1', getline(1))
inoremap <buffer> <expr> <F2> appendbufline('', 1, '')
call assert_fails("normal a\<F2>", 'E565:')
call assert_equal('11', getline(1))
inoremap <buffer> <expr> <F2> deletebufline('', 1)
call assert_fails("normal a\<F2>", 'E565:')
call assert_equal('111', getline(1))
bwipe!
endfunc
" vim: shiftwidth=2 sts=2 expandtab " vim: shiftwidth=2 sts=2 expandtab