From f29c1c6aa3f365c025890fab5fb9efbe88eb1761 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Mon, 10 Sep 2018 21:05:02 +0200 Subject: 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". --- src/ex_docmd.c | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) (limited to 'src/ex_docmd.c') diff --git a/src/ex_docmd.c b/src/ex_docmd.c index 767791776e..e9f661bcad 100644 --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -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) "", /* ":so" file line number */ #define SPEC_SLNUM (SPEC_SFILE + 1) "", /* autocommand file name */ -#define SPEC_AFILE (SPEC_SLNUM + 1) +#define SPEC_AFILE (SPEC_SLNUM + 1) "", /* autocommand buffer number */ -#define SPEC_ABUF (SPEC_AFILE + 1) +#define SPEC_ABUF (SPEC_AFILE + 1) "", /* autocommand match name */ #define SPEC_AMATCH (SPEC_ABUF + 1) + "", /* script file line number */ +#define SPEC_SFLNUM (SPEC_AMATCH + 1) #ifdef FEAT_CLIENTSERVER "" -# 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 \"\""); + 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; -- cgit v1.2.3