mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 8.2.2775: Vim9: wrong line number used for some commands
Problem: Vim9: wrong line number used for some commands. Solution: For :exe, :echo and the like use the line number of the start of the command. When calling a function set the line number in the script context.
This commit is contained in:
parent
6c7cc347af
commit
c70fe460b0
@ -2045,7 +2045,7 @@ typedef struct {
|
|||||||
except_T *except; // exception info
|
except_T *except; // exception info
|
||||||
} es_info;
|
} es_info;
|
||||||
#if defined(FEAT_EVAL)
|
#if defined(FEAT_EVAL)
|
||||||
scid_T es_save_sid; // saved sc_sid when calling function
|
sctx_T es_save_sctx; // saved current_sctx when calling function
|
||||||
#endif
|
#endif
|
||||||
} estack_T;
|
} estack_T;
|
||||||
|
|
||||||
|
@ -3848,6 +3848,37 @@ def Test_unsupported_commands()
|
|||||||
CheckScriptFailure(['vim9script'] + lines, 'E1100:')
|
CheckScriptFailure(['vim9script'] + lines, 'E1100:')
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
def Test_mapping_line_number()
|
||||||
|
var lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
def g:FuncA()
|
||||||
|
# Some comment
|
||||||
|
FuncB(0)
|
||||||
|
enddef
|
||||||
|
# Some comment
|
||||||
|
def FuncB(
|
||||||
|
# Some comment
|
||||||
|
n: number
|
||||||
|
)
|
||||||
|
exe 'nno '
|
||||||
|
# Some comment
|
||||||
|
.. '<F3> a'
|
||||||
|
.. 'b'
|
||||||
|
.. 'c'
|
||||||
|
enddef
|
||||||
|
END
|
||||||
|
CheckScriptSuccess(lines)
|
||||||
|
var res = execute('verbose nmap <F3>')
|
||||||
|
assert_match('No mapping found', res)
|
||||||
|
|
||||||
|
g:FuncA()
|
||||||
|
res = execute('verbose nmap <F3>')
|
||||||
|
assert_match(' <F3> .* abc.*Last set from .*XScriptSuccess\d\+ line 11', res)
|
||||||
|
|
||||||
|
nunmap <F3>
|
||||||
|
delfunc g:FuncA
|
||||||
|
enddef
|
||||||
|
|
||||||
" Keep this last, it messes up highlighting.
|
" Keep this last, it messes up highlighting.
|
||||||
def Test_substitute_cmd()
|
def Test_substitute_cmd()
|
||||||
new
|
new
|
||||||
|
@ -750,6 +750,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
2775,
|
||||||
/**/
|
/**/
|
||||||
2774,
|
2774,
|
||||||
/**/
|
/**/
|
||||||
|
@ -8221,6 +8221,7 @@ compile_mult_expr(char_u *arg, int cmdidx, cctx_T *cctx)
|
|||||||
char_u *p = arg;
|
char_u *p = arg;
|
||||||
char_u *prev = arg;
|
char_u *prev = arg;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
int start_ctx_lnum = cctx->ctx_lnum;
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
@ -8235,6 +8236,11 @@ compile_mult_expr(char_u *arg, int cmdidx, cctx_T *cctx)
|
|||||||
|
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
{
|
{
|
||||||
|
long save_lnum = cctx->ctx_lnum;
|
||||||
|
|
||||||
|
// Use the line number where the command started.
|
||||||
|
cctx->ctx_lnum = start_ctx_lnum;
|
||||||
|
|
||||||
if (cmdidx == CMD_echo || cmdidx == CMD_echon)
|
if (cmdidx == CMD_echo || cmdidx == CMD_echon)
|
||||||
generate_ECHO(cctx, cmdidx == CMD_echo, count);
|
generate_ECHO(cctx, cmdidx == CMD_echo, count);
|
||||||
else if (cmdidx == CMD_execute)
|
else if (cmdidx == CMD_execute)
|
||||||
@ -8243,6 +8249,8 @@ compile_mult_expr(char_u *arg, int cmdidx, cctx_T *cctx)
|
|||||||
generate_MULT_EXPR(cctx, ISN_ECHOMSG, count);
|
generate_MULT_EXPR(cctx, ISN_ECHOMSG, count);
|
||||||
else
|
else
|
||||||
generate_MULT_EXPR(cctx, ISN_ECHOERR, count);
|
generate_MULT_EXPR(cctx, ISN_ECHOERR, count);
|
||||||
|
|
||||||
|
cctx->ctx_lnum = save_lnum;
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
@ -329,9 +329,9 @@ call_dfunc(
|
|||||||
if (entry != NULL)
|
if (entry != NULL)
|
||||||
{
|
{
|
||||||
// Set the script context to the script where the function was defined.
|
// Set the script context to the script where the function was defined.
|
||||||
// TODO: save more than the SID?
|
// Save the current context so it can be restored on return.
|
||||||
entry->es_save_sid = current_sctx.sc_sid;
|
entry->es_save_sctx = current_sctx;
|
||||||
current_sctx.sc_sid = ufunc->uf_script_ctx.sc_sid;
|
current_sctx = ufunc->uf_script_ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start execution at the first instruction.
|
// Start execution at the first instruction.
|
||||||
@ -562,7 +562,7 @@ func_return(funclocal_T *funclocal, ectx_T *ectx)
|
|||||||
// execution context goes one level up
|
// execution context goes one level up
|
||||||
entry = estack_pop();
|
entry = estack_pop();
|
||||||
if (entry != NULL)
|
if (entry != NULL)
|
||||||
current_sctx.sc_sid = entry->es_save_sid;
|
current_sctx = entry->es_save_sctx;
|
||||||
|
|
||||||
if (handle_closure_in_use(ectx, TRUE) == FAIL)
|
if (handle_closure_in_use(ectx, TRUE) == FAIL)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user