From 5731f406fa6ddf9c8340329ec1e534cd968df94f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 14:35:46 +0800 Subject: vim-patch:8.2.3252: duplicated code for adding buffer lines Problem: Duplicated code for adding buffer lines. Solution: Move code to a common function. Also move map functions to map.c. (Yegappan Lakshmanan, closes vim/vim#8665) https://github.com/vim/vim/commit/4a15504e911bc90a29d862862f0b7a46d8acd12a Co-authored-by: Yegappan Lakshmanan --- src/nvim/eval/funcs.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 0e3de29cce..c4d0604b67 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -370,18 +370,24 @@ static void f_append(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) set_buffer_lines(curbuf, lnum, true, &argvars[1], rettv); } -/// "appendbufline(buf, lnum, string/list)" function -static void f_appendbufline(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) +/// Set or append lines to a buffer. +static void buf_set_append_line(typval_T *argvars, typval_T *rettv, bool append) { 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, true, &argvars[2], rettv); + set_buffer_lines(buf, lnum, append, &argvars[2], rettv); } } +/// "appendbufline(buf, lnum, string/list)" function +static void f_appendbufline(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) +{ + buf_set_append_line(argvars, rettv, true); +} + /// "atan2()" function static void f_atan2(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { @@ -7501,16 +7507,7 @@ static void f_serverstop(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) /// "setbufline()" function static void f_setbufline(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { - linenr_T lnum; - buf_T *buf; - - buf = tv_get_buf(&argvars[0], false); - if (buf == NULL) { - rettv->vval.v_number = 1; // FAIL - } else { - lnum = tv_get_lnum_buf(&argvars[1], buf); - set_buffer_lines(buf, lnum, false, &argvars[2], rettv); - } + buf_set_append_line(argvars, rettv, false); } /// Set the cursor or mark position. -- cgit From 48405df046e6d15c26aeea429fa44950ccc1a8ac Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 14:31:40 +0800 Subject: 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 --- src/nvim/eval.c | 1 + src/nvim/eval/funcs.c | 29 ++++++++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) (limited to 'src') 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 -- cgit From 30cfdd0ea1f67afed6732ecbcdda9dda72a2b0a0 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 14:26:28 +0800 Subject: vim-patch:8.2.5027: error for missing :endif when an exception was thrown Problem: Error for missing :endif when an exception was thrown. (Dani Dickstein) Solution: Do not give an error when aborting. (closes vim/vim#10490) https://github.com/vim/vim/commit/bf79a4e48d09a5ae08645592885d54230fed30b8 Co-authored-by: Bram Moolenaar --- src/nvim/ex_docmd.c | 2 +- src/nvim/testdir/test_trycatch.vim | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index dad656d8b6..ed74993b84 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -726,7 +726,7 @@ int do_cmdline(char *cmdline, LineGetter fgetline, void *cookie, int flags) if (cstack.cs_idx >= 0) { // If a sourced file or executed function ran to its end, report the // unclosed conditional. - if (!got_int && !did_throw + if (!got_int && !did_throw && !aborting() && ((getline_equal(fgetline, cookie, getsourceline) && !source_finished(fgetline, cookie)) || (getline_equal(fgetline, cookie, get_func_line) diff --git a/src/nvim/testdir/test_trycatch.vim b/src/nvim/testdir/test_trycatch.vim index 3dff8fa2d8..8a1d2d3fa7 100644 --- a/src/nvim/testdir/test_trycatch.vim +++ b/src/nvim/testdir/test_trycatch.vim @@ -2221,6 +2221,23 @@ func Test_user_command_throw_in_function_call() unlet g:caught endfunc +" Test that after reporting an uncaught exception there is no error for a +" missing :endif +func Test_after_exception_no_endif_error() + function Throw() + throw "Failure" + endfunction + + function Foo() + if 1 + call Throw() + endif + endfunction + call assert_fails('call Foo()', ['E605:', 'E605:']) + delfunc Throw + delfunc Foo +endfunc + " Test for using throw in a called function with following endtry {{{1 func Test_user_command_function_call_with_endtry() let lines =<< trim END -- cgit