1
0
forked from aniani/vim

patch 8.1.0362: cannot get the script line number when executing a function

Problem:    Cannot get the script line number when executing a function.
Solution:   Store the line number besides the script ID. (Ozaki Kiichi,
            closes #3362)  Also display the line number with ":verbose set".
This commit is contained in:
Bram Moolenaar
2018-09-10 21:05:02 +02:00
parent 6b0b83f768
commit f29c1c6aa3
24 changed files with 716 additions and 562 deletions

View File

@@ -29,7 +29,7 @@ typedef struct ucmd
int uc_compl; /* completion type */
int uc_addr_type; /* The command's address type */
# ifdef FEAT_EVAL
scid_T uc_scriptID; /* SID where the command was defined */
sctx_T uc_script_ctx; /* SCTX where the command was defined */
# ifdef FEAT_CMDL_COMPL
char_u *uc_compl_arg; /* completion argument if any */
# endif
@@ -3340,7 +3340,8 @@ find_ucmd(
if (xp != NULL)
{
xp->xp_arg = uc->uc_compl_arg;
xp->xp_scriptID = uc->uc_scriptID;
xp->xp_script_ctx = uc->uc_script_ctx;
xp->xp_script_ctx.sc_lnum += sourcing_lnum;
}
# endif
# endif
@@ -5920,7 +5921,8 @@ uc_add_command(
cmd->uc_def = def;
cmd->uc_compl = compl;
#ifdef FEAT_EVAL
cmd->uc_scriptID = current_SID;
cmd->uc_script_ctx = current_sctx;
cmd->uc_script_ctx.sc_lnum += sourcing_lnum;
# ifdef FEAT_CMDL_COMPL
cmd->uc_compl_arg = compl_arg;
# endif
@@ -6141,7 +6143,7 @@ uc_list(char_u *name, size_t name_len)
msg_outtrans_special(cmd->uc_rep, FALSE);
#ifdef FEAT_EVAL
if (p_verbose > 0)
last_set_msg(cmd->uc_scriptID);
last_set_msg(cmd->uc_script_ctx);
#endif
out_flush();
ui_breakcheck();
@@ -6906,7 +6908,7 @@ do_ucmd(exarg_T *eap)
char_u *split_buf = NULL;
ucmd_T *cmd;
#ifdef FEAT_EVAL
scid_T save_current_SID = current_SID;
sctx_T save_current_sctx = current_sctx;
#endif
if (eap->cmdidx == CMD_USER)
@@ -7007,12 +7009,12 @@ do_ucmd(exarg_T *eap)
}
#ifdef FEAT_EVAL
current_SID = cmd->uc_scriptID;
current_sctx.sc_sid = cmd->uc_script_ctx.sc_sid;
#endif
(void)do_cmdline(buf, eap->getline, eap->cookie,
DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_KEYTYPED);
#ifdef FEAT_EVAL
current_SID = save_current_SID;
current_sctx = save_current_sctx;
#endif
vim_free(buf);
vim_free(split_buf);
@@ -10736,14 +10738,16 @@ find_cmdline_var(char_u *src, int *usedlen)
"<slnum>", /* ":so" file line number */
#define SPEC_SLNUM (SPEC_SFILE + 1)
"<afile>", /* autocommand file name */
#define SPEC_AFILE (SPEC_SLNUM + 1)
#define SPEC_AFILE (SPEC_SLNUM + 1)
"<abuf>", /* autocommand buffer number */
#define SPEC_ABUF (SPEC_AFILE + 1)
#define SPEC_ABUF (SPEC_AFILE + 1)
"<amatch>", /* autocommand match name */
#define SPEC_AMATCH (SPEC_ABUF + 1)
"<sflnum>", /* script file line number */
#define SPEC_SFLNUM (SPEC_AMATCH + 1)
#ifdef FEAT_CLIENTSERVER
"<client>"
# define SPEC_CLIENT (SPEC_AMATCH + 1)
# define SPEC_CLIENT (SPEC_SFLNUM + 1)
#endif
};
@@ -10999,6 +11003,7 @@ eval_vars(
return NULL;
}
break;
case SPEC_SLNUM: /* line in file for ":so" command */
if (sourcing_name == NULL || sourcing_lnum == 0)
{
@@ -11008,13 +11013,28 @@ eval_vars(
sprintf((char *)strbuf, "%ld", (long)sourcing_lnum);
result = strbuf;
break;
#if defined(FEAT_CLIENTSERVER)
#ifdef FEAT_EVAL
case SPEC_SFLNUM: /* line in script file */
if (current_sctx.sc_lnum + sourcing_lnum == 0)
{
*errormsg = (char_u *)_("E961: no line number to use for \"<sflnum>\"");
return NULL;
}
sprintf((char *)strbuf, "%ld",
(long)(current_sctx.sc_lnum + sourcing_lnum));
result = strbuf;
break;
#endif
#ifdef FEAT_CLIENTSERVER
case SPEC_CLIENT: /* Source of last submitted input */
sprintf((char *)strbuf, PRINTF_HEX_LONG_U,
(long_u)clientWindow);
result = strbuf;
break;
#endif
default:
result = (char_u *)""; /* avoid gcc warning */
break;