neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 3b3611a3d0f1e13e277360d6bacf97a0fb7eb6de
parent 08d53633d41063f2d14ea7713edc70620ce1fcc4
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Mon,  7 Nov 2022 07:03:31 +0800

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)

https://github.com/vim/vim/commit/7af3ee2b83545169d78a28ab1cd89aff1127f8b3
Diffstat:
Msrc/nvim/eval/funcs.c | 38++++++++++++++++++++------------------
Msrc/nvim/testdir/test_bufline.vim | 16++++++++++++++++
2 files changed, 36 insertions(+), 18 deletions(-)

diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c @@ -1510,6 +1510,7 @@ static void f_deletebufline(typval_T *argvars, typval_T *rettv, EvalFuncData fpt buf_T *curbuf_save = NULL; win_T *curwin_save = NULL; + // After this don't use "return", goto "cleanup"! if (!is_curbuf) { VIsual_active = false; curbuf_save = curbuf; @@ -1530,34 +1531,35 @@ static void f_deletebufline(typval_T *argvars, typval_T *rettv, EvalFuncData fpt } if (u_save(first - 1, last + 1) == FAIL) { - rettv->vval.v_number = 1; // FAIL - } else { - for (linenr_T lnum = first; lnum <= last; lnum++) { - ml_delete(first, true); - } + goto cleanup; + } - FOR_ALL_TAB_WINDOWS(tp, wp) { - if (wp->w_buffer == buf) { - if (wp->w_cursor.lnum > last) { - wp->w_cursor.lnum -= (linenr_T)count; - } else if (wp->w_cursor.lnum > first) { - wp->w_cursor.lnum = first; - } - if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count) { - wp->w_cursor.lnum = wp->w_buffer->b_ml.ml_line_count; - } + for (linenr_T lnum = first; lnum <= last; lnum++) { + ml_delete(first, true); + } + + FOR_ALL_TAB_WINDOWS(tp, wp) { + if (wp->w_buffer == buf) { + if (wp->w_cursor.lnum > last) { + wp->w_cursor.lnum -= (linenr_T)count; + } else if (wp->w_cursor.lnum > first) { + wp->w_cursor.lnum = first; + } + if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count) { + wp->w_cursor.lnum = wp->w_buffer->b_ml.ml_line_count; } } - check_cursor_col(); - deleted_lines_mark(first, count); } + 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 } /// "did_filetype()" function diff --git a/src/nvim/testdir/test_bufline.vim b/src/nvim/testdir/test_bufline.vim @@ -239,4 +239,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