0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 9.0.0841: deletebufline() does not always return 1 on failure

Problem:    deletebufline() does not always return 1 on failure.
Solution:   Refactor the code to make it work more predictable. (closes #11511)
This commit is contained in:
zeertzjq
2022-11-06 22:26:05 +00:00
committed by Bram Moolenaar
parent adbc08fd69
commit 7af3ee2b83
3 changed files with 40 additions and 24 deletions

View File

@@ -535,6 +535,7 @@ f_deletebufline(typval_T *argvars, typval_T *rettv)
|| first > buf->b_ml.ml_line_count || last < first)
return;
// After this don't use "return", goto "cleanup"!
if (!is_curbuf)
{
VIsual_active = FALSE;
@@ -556,11 +557,8 @@ f_deletebufline(typval_T *argvars, typval_T *rettv)
}
if (u_save(first - 1, last + 1) == FAIL)
{
rettv->vval.v_number = 1; // FAIL
}
else
{
goto cleanup;
for (lnum = first; lnum <= last; ++lnum)
ml_delete_flags(first, ML_DEL_MESSAGE);
@@ -579,15 +577,15 @@ f_deletebufline(typval_T *argvars, typval_T *rettv)
}
check_cursor_col();
deleted_lines_mark(first, count);
}
rettv->vval.v_number = 0; // OK
cleanup:
if (!is_curbuf)
{
curbuf = curbuf_save;
curwin = curwin_save;
VIsual_active = save_VIsual_active;
}
rettv->vval.v_number = 0; // OK
}
/*

View File

@@ -279,4 +279,20 @@ func Test_setbufline_startup_nofile()
call delete('Xresult')
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

View File

@@ -695,6 +695,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
841,
/**/
840,
/**/