Merge pull request #20942 from zeertzjq/vim-8.2.5027

vim-patch:8.2.{3252,3919,5027}
This commit is contained in:
zeertzjq 2022-11-05 15:14:09 +08:00 committed by GitHub
commit 45a3e7f669
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 23 deletions

View File

@ -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.

View File

@ -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;
}

View File

@ -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

View File

@ -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)

View File

@ -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