diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-11-05 14:31:40 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2022-11-05 14:44:26 +0800 |
commit | 48405df046e6d15c26aeea429fa44950ccc1a8ac (patch) | |
tree | 5ddd340c991998302b74e46862ebdd35cd982b8e | |
parent | 5731f406fa6ddf9c8340329ec1e534cd968df94f (diff) | |
download | rneovim-48405df046e6d15c26aeea429fa44950ccc1a8ac.tar.gz rneovim-48405df046e6d15c26aeea429fa44950ccc1a8ac.tar.bz2 rneovim-48405df046e6d15c26aeea429fa44950ccc1a8ac.zip |
vim-patch:8.2.3919: Vim9: wrong argument for append() results in two errors
Problem: Vim9: wrong argument for append() results in two errors.
Solution: Check did_emsg. Also for setline(). Adjust the help for
appendbufline().
https://github.com/vim/vim/commit/8b6256f6ec075cca40341e61ebc9f538b4902dd1
Co-authored-by: Bram Moolenaar <Bram@vim.org>
-rw-r--r-- | runtime/doc/builtin.txt | 7 | ||||
-rw-r--r-- | src/nvim/eval.c | 1 | ||||
-rw-r--r-- | src/nvim/eval/funcs.c | 29 |
3 files changed, 27 insertions, 10 deletions
diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt index 2cd2eed3a1..e7e44374c6 100644 --- a/runtime/doc/builtin.txt +++ b/runtime/doc/builtin.txt @@ -654,9 +654,10 @@ appendbufline({buf}, {lnum}, {text}) *appendbufline()* For the use of {buf}, see |bufname()|. - {lnum} is used like with |append()|. Note that using |line()| - would use the current buffer, not the one appending to. - Use "$" to append at the end of the buffer. + {lnum} is the line number to append below. Note that using + |line()| would use the current buffer, not the one appending + to. Use "$" to append at the end of the buffer. Other string + values are not supported. On success 0 is returned, on failure 1 is returned. diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 5b8cbcfbb3..1200ba20ba 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -5200,6 +5200,7 @@ linenr_T tv_get_lnum_buf(const typval_T *const tv, const buf_T *const buf) if (tv->v_type == VAR_STRING && tv->vval.v_string != NULL && tv->vval.v_string[0] == '$' + && tv->vval.v_string[1] == NUL && buf != NULL) { return buf->b_ml.ml_line_count; } diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index c4d0604b67..cf924b1c49 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -365,20 +365,25 @@ static void f_api_info(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) /// "append(lnum, string/list)" function static void f_append(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { + const int did_emsg_before = did_emsg; const linenr_T lnum = tv_get_lnum(&argvars[0]); - - set_buffer_lines(curbuf, lnum, true, &argvars[1], rettv); + if (did_emsg == did_emsg_before) { + set_buffer_lines(curbuf, lnum, true, &argvars[1], rettv); + } } /// Set or append lines to a buffer. static void buf_set_append_line(typval_T *argvars, typval_T *rettv, bool append) { + const int did_emsg_before = did_emsg; buf_T *const buf = tv_get_buf(&argvars[0], false); if (buf == NULL) { rettv->vval.v_number = 1; // FAIL } else { const linenr_T lnum = tv_get_lnum_buf(&argvars[1], buf); - set_buffer_lines(buf, lnum, append, &argvars[2], rettv); + if (did_emsg == did_emsg_before) { + set_buffer_lines(buf, lnum, append, &argvars[2], rettv); + } } } @@ -1476,9 +1481,10 @@ static void f_dictwatcherdel(typval_T *argvars, typval_T *rettv, EvalFuncData fp /// "deletebufline()" function static void f_deletebufline(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { + const int did_emsg_before = did_emsg; + rettv->vval.v_number = 1; // FAIL by default buf_T *const buf = tv_get_buf(&argvars[0], false); if (buf == NULL) { - rettv->vval.v_number = 1; // FAIL return; } const bool is_curbuf = buf == curbuf; @@ -1486,6 +1492,9 @@ static void f_deletebufline(typval_T *argvars, typval_T *rettv, EvalFuncData fpt linenr_T last; const linenr_T first = tv_get_lnum_buf(&argvars[1], buf); + if (did_emsg > did_emsg_before) { + return; + } if (argvars[2].v_type != VAR_UNKNOWN) { last = tv_get_lnum_buf(&argvars[2], buf); } else { @@ -1494,7 +1503,6 @@ static void f_deletebufline(typval_T *argvars, typval_T *rettv, EvalFuncData fpt if (buf->b_ml.ml_mfp == NULL || first < 1 || first > buf->b_ml.ml_line_count || last < first) { - rettv->vval.v_number = 1; // FAIL return; } @@ -1547,6 +1555,7 @@ static void f_deletebufline(typval_T *argvars, typval_T *rettv, EvalFuncData fpt curwin = curwin_save; VIsual_active = save_VIsual_active; } + rettv->vval.v_number = 0; // OK } /// "did_filetype()" function @@ -2581,9 +2590,12 @@ static void get_buffer_lines(buf_T *buf, linenr_T start, linenr_T end, int retli /// "getbufline()" function static void f_getbufline(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { + const int did_emsg_before = did_emsg; buf_T *const buf = tv_get_buf_from_arg(&argvars[0]); - const linenr_T lnum = tv_get_lnum_buf(&argvars[1], buf); + if (did_emsg > did_emsg_before) { + return; + } const linenr_T end = (argvars[2].v_type == VAR_UNKNOWN ? lnum : tv_get_lnum_buf(&argvars[2], buf)); @@ -7636,8 +7648,11 @@ static void f_setfperm(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) /// "setline()" function static void f_setline(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { + const int did_emsg_before = did_emsg; linenr_T lnum = tv_get_lnum(&argvars[0]); - set_buffer_lines(curbuf, lnum, false, &argvars[1], rettv); + if (did_emsg == did_emsg_before) { + set_buffer_lines(curbuf, lnum, false, &argvars[1], rettv); + } } /// "setpos()" function |