aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-11-05 15:14:09 +0800
committerGitHub <noreply@github.com>2022-11-05 15:14:09 +0800
commit45a3e7f6694c66c3577a47c7ff1fb8bfcc2ab7be (patch)
tree0a52ff4bcb4eebd88b70e36d51a7797b3105dd96 /src
parent86fe2c8d94d212af098002ce04c87fb73fdf9c52 (diff)
parent30cfdd0ea1f67afed6732ecbcdda9dda72a2b0a0 (diff)
downloadrneovim-45a3e7f6694c66c3577a47c7ff1fb8bfcc2ab7be.tar.gz
rneovim-45a3e7f6694c66c3577a47c7ff1fb8bfcc2ab7be.tar.bz2
rneovim-45a3e7f6694c66c3577a47c7ff1fb8bfcc2ab7be.zip
Merge pull request #20942 from zeertzjq/vim-8.2.5027
vim-patch:8.2.{3252,3919,5027}
Diffstat (limited to 'src')
-rw-r--r--src/nvim/eval.c1
-rw-r--r--src/nvim/eval/funcs.c50
-rw-r--r--src/nvim/ex_docmd.c2
-rw-r--r--src/nvim/testdir/test_trycatch.vim17
4 files changed, 50 insertions, 20 deletions
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 0e3de29cce..cf924b1c49 100644
--- a/src/nvim/eval/funcs.c
+++ b/src/nvim/eval/funcs.c
@@ -365,23 +365,34 @@ 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);
+ }
}
-/// "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)
{
+ 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, true, &argvars[2], rettv);
+ if (did_emsg == did_emsg_before) {
+ 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)
{
@@ -1470,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;
@@ -1480,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 {
@@ -1488,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;
}
@@ -1541,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
@@ -2575,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));
@@ -7501,16 +7519,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.
@@ -7639,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
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