diff options
author | Bram Moolenaar <Bram@vim.org> | 2018-09-10 21:05:02 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2018-09-10 21:05:02 +0200 |
commit | f29c1c6aa3f365c025890fab5fb9efbe88eb1761 (patch) | |
tree | 3cd43ee75a7e0fbdce4902426512ae804b1c7ff0 | |
parent | 6b0b83f768cf536b34ce4d3f2de6bf62324229aa (diff) |
patch 8.1.0362: cannot get the script line number when executing a functionv8.1.0362
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".
-rw-r--r-- | runtime/doc/cmdline.txt | 27 | ||||
-rw-r--r-- | runtime/doc/eval.txt | 6 | ||||
-rw-r--r-- | src/Make_all.mak | 4 | ||||
-rw-r--r-- | src/buffer.c | 9 | ||||
-rw-r--r-- | src/eval.c | 23 | ||||
-rw-r--r-- | src/evalfunc.c | 5 | ||||
-rw-r--r-- | src/ex_cmds2.c | 52 | ||||
-rw-r--r-- | src/ex_docmd.c | 42 | ||||
-rw-r--r-- | src/ex_getln.c | 6 | ||||
-rw-r--r-- | src/fileio.c | 15 | ||||
-rw-r--r-- | src/getchar.c | 8 | ||||
-rw-r--r-- | src/globals.h | 4 | ||||
-rw-r--r-- | src/main.c | 17 | ||||
-rw-r--r-- | src/menu.c | 4 | ||||
-rw-r--r-- | src/option.c | 898 | ||||
-rw-r--r-- | src/proto/eval.pro | 2 | ||||
-rw-r--r-- | src/structs.h | 25 | ||||
-rw-r--r-- | src/syntax.c | 18 | ||||
-rw-r--r-- | src/term.c | 5 | ||||
-rw-r--r-- | src/testdir/test_alot.vim | 1 | ||||
-rw-r--r-- | src/testdir/test_expand_func.vim | 66 | ||||
-rw-r--r-- | src/testdir/test_maparg.vim | 15 | ||||
-rw-r--r-- | src/userfunc.c | 24 | ||||
-rw-r--r-- | src/version.c | 2 |
24 files changed, 716 insertions, 562 deletions
diff --git a/runtime/doc/cmdline.txt b/runtime/doc/cmdline.txt index df18ec6c45..3b2dd32060 100644 --- a/runtime/doc/cmdline.txt +++ b/runtime/doc/cmdline.txt @@ -832,11 +832,12 @@ it, no matter how many backslashes. \\# \# Also see |`=|. - *:<cword>* *:<cWORD>* *:<cfile>* *<cfile>* - *:<sfile>* *<sfile>* *:<afile>* *<afile>* - *:<abuf>* *<abuf>* *:<amatch>* *<amatch>* - *:<cexpr>* *<cexpr>* - *<slnum>* *E495* *E496* *E497* *E499* *E500* + *:<cword>* *<cword>* *:<cWORD>* *<cWORD>* + *:<cexpr>* *<cexpr>* *:<cfile>* *<cfile>* + *:<afile>* *<afile>* *:<abuf>* *<abuf>* + *:<amatch>* *<amatch>* + *:<sfile>* *<sfile>* *:<slnum>* *<slnum>* + *:<sflnum>* *<sflnum>* *E499* *E500* Note: these are typed literally, they are not special keys! <cword> is replaced with the word under the cursor (like |star|) <cWORD> is replaced with the WORD under the cursor (see |WORD|) @@ -849,15 +850,16 @@ Note: these are typed literally, they are not special keys! |gf| uses) <afile> When executing autocommands, is replaced with the file name of the buffer being manipulated, or the file for a read or - write. + write. *E495* <abuf> When executing autocommands, is replaced with the currently effective buffer number (for ":r file" and ":so file" it is the current buffer, the file being read/sourced is not in a - buffer). + buffer). *E496* <amatch> When executing autocommands, is replaced with the match for - which this autocommand was executed. It differs from - <afile> only when the file name isn't used to match with - (for FileType, Syntax and SpellFileMissing events). + which this autocommand was executed. *E497* + It differs from <afile> only when the file name isn't used + to match with (for FileType, Syntax and SpellFileMissing + events). <sfile> When executing a ":source" command, is replaced with the file name of the sourced file. *E498* When executing a function, is replaced with: @@ -867,9 +869,12 @@ Note: these are typed literally, they are not special keys! Note that filename-modifiers are useless when <sfile> is used inside a function. <slnum> When executing a ":source" command, is replaced with the - line number. *E842* + line number. *E842* When executing a function it's the line number relative to the start of the function. + <sflnum> When executing a script, is replaced with the line number. + It differs from <slnum> in that <sflnum> is replaced with + the script line number in any situation. *E961* *filename-modifiers* *:_%:* *::8* *::p* *::.* *::~* *::h* *::t* *::r* *::e* *::s* *::gs* *::S* diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 21cb4abade..2ff124b691 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -3798,7 +3798,10 @@ expand({expr} [, {nosuf} [, {list}]]) *expand()* <abuf> autocmd buffer number (as a String!) <amatch> autocmd matched name <sfile> sourced script file or function name - <slnum> sourced script file line number + <slnum> sourced script line number or function + line number + <sflnum> script file line number, also when in + a function <cword> word under the cursor <cWORD> WORD under the cursor <client> the {clientid} of the last received @@ -5931,6 +5934,7 @@ maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()* (|mapmode-ic|) "sid" The script local ID, used for <sid> mappings (|<SID>|). + "lnum" The line number in "sid", zero if unknown. "nowait" Do not wait for other, longer mappings. (|:map-<nowait>|). diff --git a/src/Make_all.mak b/src/Make_all.mak index 49ad4f0af8..79b8b94798 100644 --- a/src/Make_all.mak +++ b/src/Make_all.mak @@ -2,7 +2,8 @@ # Common Makefile, defines the list of tests to run. # -# Individual tests, including the ones part of test_alot +# Individual tests, including the ones part of test_alot. +# Please keep sorted up to test_alot. NEW_TESTS = \ test_arglist \ test_arabic \ @@ -52,6 +53,7 @@ NEW_TESTS = \ test_exists_autocmd \ test_expand \ test_expand_dllpath \ + test_expand_func \ test_expr \ test_expr_utf8 \ test_farsi \ diff --git a/src/buffer.c b/src/buffer.c index dcff94ba8b..0bf6aa9125 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -5412,7 +5412,7 @@ chk_modeline( char_u *save_sourcing_name; linenr_T save_sourcing_lnum; #ifdef FEAT_EVAL - scid_T save_SID; + sctx_T save_current_sctx; #endif prev = -1; @@ -5497,12 +5497,13 @@ chk_modeline( if (*s != NUL) /* skip over an empty "::" */ { #ifdef FEAT_EVAL - save_SID = current_SID; - current_SID = SID_MODELINE; + save_current_sctx = current_sctx; + current_sctx.sc_sid = SID_MODELINE; + current_sctx.sc_lnum = 0; #endif retval = do_set(s, OPT_MODELINE | OPT_LOCAL | flags); #ifdef FEAT_EVAL - current_SID = save_SID; + current_sctx = save_current_sctx; #endif if (retval == FAIL) /* stop if error found */ break; diff --git a/src/eval.c b/src/eval.c index 3a275213cb..358217a824 100644 --- a/src/eval.c +++ b/src/eval.c @@ -1495,8 +1495,8 @@ list_vim_vars(int *first) static void list_script_vars(int *first) { - if (current_SID > 0 && current_SID <= ga_scripts.ga_len) - list_hashtable_vars(&SCRIPT_VARS(current_SID), + if (current_sctx.sc_sid > 0 && current_sctx.sc_sid <= ga_scripts.ga_len) + list_hashtable_vars(&SCRIPT_VARS(current_sctx.sc_sid), (char_u *)"s:", FALSE, first); } @@ -7202,7 +7202,7 @@ find_var_in_ht( /* Must be something like "s:", otherwise "ht" would be NULL. */ switch (htname) { - case 's': return &SCRIPT_SV(current_SID)->sv_var; + case 's': return &SCRIPT_SV(current_sctx.sc_sid)->sv_var; case 'g': return &globvars_var; case 'v': return &vimvars_var; case 'b': return &curbuf->b_bufvar; @@ -7286,8 +7286,8 @@ find_var_ht(char_u *name, char_u **varname) if (*name == 'l') /* l: local function variable */ return get_funccal_local_ht(); if (*name == 's' /* script variable */ - && current_SID > 0 && current_SID <= ga_scripts.ga_len) - return &SCRIPT_VARS(current_SID); + && current_sctx.sc_sid > 0 && current_sctx.sc_sid <= ga_scripts.ga_len) + return &SCRIPT_VARS(current_sctx.sc_sid); return NULL; } @@ -8729,20 +8729,25 @@ store_session_globals(FILE *fd) * Should only be invoked when 'verbose' is non-zero. */ void -last_set_msg(scid_T scriptID) +last_set_msg(sctx_T script_ctx) { char_u *p; - if (scriptID != 0) + if (script_ctx.sc_sid != 0) { - p = home_replace_save(NULL, get_scriptname(scriptID)); + p = home_replace_save(NULL, get_scriptname(script_ctx.sc_sid)); if (p != NULL) { verbose_enter(); MSG_PUTS(_("\n\tLast set from ")); MSG_PUTS(p); - vim_free(p); + if (script_ctx.sc_lnum > 0) + { + MSG_PUTS(_(" line ")); + msg_outnum((long)script_ctx.sc_lnum); + } verbose_leave(); + vim_free(p); } } } diff --git a/src/evalfunc.c b/src/evalfunc.c index 90fb8881b4..54e7dcdd39 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -4061,7 +4061,7 @@ common_function(typval_T *argvars, typval_T *rettv, int is_funcref) * also be called from another script. Using trans_function_name() * would also work, but some plugins depend on the name being * printable text. */ - sprintf(sid_buf, "<SNR>%ld_", (long)current_SID); + sprintf(sid_buf, "<SNR>%ld_", (long)current_sctx.sc_sid); name = alloc((int)(STRLEN(sid_buf) + STRLEN(s + off) + 1)); if (name != NULL) { @@ -7618,7 +7618,8 @@ get_maparg(typval_T *argvars, typval_T *rettv, int exact) dict_add_number(dict, "noremap", mp->m_noremap ? 1L : 0L); dict_add_number(dict, "expr", mp->m_expr ? 1L : 0L); dict_add_number(dict, "silent", mp->m_silent ? 1L : 0L); - dict_add_number(dict, "sid", (long)mp->m_script_ID); + dict_add_number(dict, "sid", (long)mp->m_script_ctx.sc_sid); + dict_add_number(dict, "lnum", (long)mp->m_script_ctx.sc_lnum); dict_add_number(dict, "buffer", (long)buffer_local); dict_add_number(dict, "nowait", mp->m_nowait ? 1L : 0L); dict_add_string(dict, "mode", mapmode); diff --git a/src/ex_cmds2.c b/src/ex_cmds2.c index 08eb181787..28245d1781 100644 --- a/src/ex_cmds2.c +++ b/src/ex_cmds2.c @@ -1866,9 +1866,9 @@ script_prof_save( { scriptitem_T *si; - if (current_SID > 0 && current_SID <= script_items.ga_len) + if (current_sctx.sc_sid > 0 && current_sctx.sc_sid <= script_items.ga_len) { - si = &SCRIPT_ITEM(current_SID); + si = &SCRIPT_ITEM(current_sctx.sc_sid); if (si->sn_prof_on && si->sn_pr_nest++ == 0) profile_start(&si->sn_pr_child); } @@ -1883,9 +1883,9 @@ script_prof_restore(proftime_T *tm) { scriptitem_T *si; - if (current_SID > 0 && current_SID <= script_items.ga_len) + if (current_sctx.sc_sid > 0 && current_sctx.sc_sid <= script_items.ga_len) { - si = &SCRIPT_ITEM(current_SID); + si = &SCRIPT_ITEM(current_sctx.sc_sid); if (si->sn_prof_on && --si->sn_pr_nest == 0) { profile_end(&si->sn_pr_child); @@ -2003,8 +2003,8 @@ script_dump_profile(FILE *fd) int prof_def_func(void) { - if (current_SID > 0) - return SCRIPT_ITEM(current_SID).sn_pr_force; + if (current_sctx.sc_sid > 0) + return SCRIPT_ITEM(current_sctx.sc_sid).sn_pr_force; return FALSE; } @@ -4351,7 +4351,7 @@ do_source( char_u *firstline = NULL; int retval = FAIL; #ifdef FEAT_EVAL - scid_T save_current_SID; + sctx_T save_current_sctx; static scid_T last_current_SID = 0; void *save_funccalp; int save_debug_break_level = debug_break_level; @@ -4521,13 +4521,15 @@ do_source( * Check if this script was sourced before to finds its SID. * If it's new, generate a new SID. */ - save_current_SID = current_SID; + save_current_sctx = current_sctx; + current_sctx.sc_lnum = 0; # ifdef UNIX stat_ok = (mch_stat((char *)fname_exp, &st) >= 0); # endif - for (current_SID = script_items.ga_len; current_SID > 0; --current_SID) + for (current_sctx.sc_sid = script_items.ga_len; current_sctx.sc_sid > 0; + --current_sctx.sc_sid) { - si = &SCRIPT_ITEM(current_SID); + si = &SCRIPT_ITEM(current_sctx.sc_sid); if (si->sn_name != NULL && ( # ifdef UNIX @@ -4541,13 +4543,13 @@ do_source( fnamecmp(si->sn_name, fname_exp) == 0)) break; } - if (current_SID == 0) + if (current_sctx.sc_sid == 0) { - current_SID = ++last_current_SID; - if (ga_grow(&script_items, (int)(current_SID - script_items.ga_len)) - == FAIL) + current_sctx.sc_sid = ++last_current_SID; + if (ga_grow(&script_items, + (int)(current_sctx.sc_sid - script_items.ga_len)) == FAIL) goto almosttheend; - while (script_items.ga_len < current_SID) + while (script_items.ga_len < current_sctx.sc_sid) { ++script_items.ga_len; SCRIPT_ITEM(script_items.ga_len).sn_name = NULL; @@ -4555,7 +4557,7 @@ do_source( SCRIPT_ITEM(script_items.ga_len).sn_prof_on = FALSE; # endif } - si = &SCRIPT_ITEM(current_SID); + si = &SCRIPT_ITEM(current_sctx.sc_sid); si->sn_name = fname_exp; fname_exp = NULL; # ifdef UNIX @@ -4570,7 +4572,7 @@ do_source( # endif /* Allocate the local script variables to use for this script. */ - new_script_vars(current_SID); + new_script_vars(current_sctx.sc_sid); } # ifdef FEAT_PROFILE @@ -4626,7 +4628,7 @@ do_source( if (do_profiling == PROF_YES) { /* Get "si" again, "script_items" may have been reallocated. */ - si = &SCRIPT_ITEM(current_SID); + si = &SCRIPT_ITEM(current_sctx.sc_sid); if (si->sn_prof_on) { profile_end(&si->sn_pr_start); @@ -4671,7 +4673,7 @@ do_source( #ifdef FEAT_EVAL almosttheend: - current_SID = save_current_SID; + current_sctx = save_current_sctx; restore_funccal(save_funccalp); # ifdef FEAT_PROFILE if (do_profiling == PROF_YES) @@ -5090,9 +5092,9 @@ script_line_start(void) scriptitem_T *si; sn_prl_T *pp; - if (current_SID <= 0 || current_SID > script_items.ga_len) + if (current_sctx.sc_sid <= 0 || current_sctx.sc_sid > script_items.ga_len) return; - si = &SCRIPT_ITEM(current_SID); + si = &SCRIPT_ITEM(current_sctx.sc_sid); if (si->sn_prof_on && sourcing_lnum >= 1) { /* Grow the array before starting the timer, so that the time spent @@ -5125,9 +5127,9 @@ script_line_exec(void) { scriptitem_T *si; - if (current_SID <= 0 || current_SID > script_items.ga_len) + if (current_sctx.sc_sid <= 0 || current_sctx.sc_sid > script_items.ga_len) return; - si = &SCRIPT_ITEM(current_SID); + si = &SCRIPT_ITEM(current_sctx.sc_sid); if (si->sn_prof_on && si->sn_prl_idx >= 0) si->sn_prl_execed = TRUE; } @@ -5141,9 +5143,9 @@ script_line_end(void) scriptitem_T *si; sn_prl_T *pp; - if (current_SID <= 0 || current_SID > script_items.ga_len) + if (current_sctx.sc_sid <= 0 || current_sctx.sc_sid > script_items.ga_len) return; - si = &SCRIPT_ITEM(current_SID); + si = &SCRIPT_ITEM(current_sctx.sc_sid); if (si->sn_prof_on && si->sn_prl_idx >= 0 && si->sn_prl_idx < si->sn_prl_ga.ga_len) { 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) "<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; diff --git a/src/ex_getln.c b/src/ex_getln.c index 9a8806c14b..a72b9a4096 100644 --- a/src/ex_getln.c +++ b/src/ex_getln.c @@ -5591,7 +5591,7 @@ call_user_expand_func( { int keep = 0; typval_T args[4]; - int save_current_SID = current_SID; + sctx_T save_current_sctx = current_sctx; char_u *pat = NULL; void *ret; struct cmdline_info save_ccline; @@ -5621,12 +5621,12 @@ call_user_expand_func( save_ccline = ccline; ccline.cmdbuff = NULL; ccline.cmdprompt = NULL; - current_SID = xp->xp_scriptID; + current_sctx = xp->xp_script_ctx; ret = user_expand_func(xp->xp_arg, 3, args); ccline = save_ccline; - current_SID = save_current_SID; + current_sctx = save_current_sctx; if (ccline.cmdbuff != NULL) ccline.cmdbuff[ccline.cmdlen] = keep; diff --git a/src/fileio.c b/src/fileio.c index d00dc5e47b..056ac914d7 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -7700,7 +7700,7 @@ typedef struct AutoCmd char nested; /* If autocommands nest here */ char last; /* last command in list */ #ifdef FEAT_EVAL - scid_T scriptID; /* script ID where defined */ + sctx_T script_ctx; /* script context where defined */ #endif struct AutoCmd *next; /* Next AutoCmd in list */ } AutoCmd; @@ -7962,7 +7962,7 @@ show_autocmd(AutoPat *ap, event_T event) msg_outtrans(ac->cmd); #ifdef FEAT_EVAL if (p_verbose > 0) - last_set_msg(ac->scriptID); + last_set_msg(ac->script_ctx); #endif if (got_int) return; @@ -8845,7 +8845,8 @@ do_autocmd_event( return FAIL; ac->cmd = vim_strsave(cmd); #ifdef FEAT_EVAL - ac->scriptID = current_SID; + ac->script_ctx = current_sctx; + ac->script_ctx.sc_lnum += sourcing_lnum; #endif if (ac->cmd == NULL) { @@ -9412,7 +9413,7 @@ apply_autocmds_group( AutoPatCmd patcmd; AutoPat *ap; #ifdef FEAT_EVAL - scid_T save_current_SID; + sctx_T save_current_sctx; void *save_funccalp; char_u *save_cmdarg; long save_cmdbang; @@ -9621,7 +9622,7 @@ apply_autocmds_group( sourcing_lnum = 0; /* no line number here */ #ifdef FEAT_EVAL - save_current_SID = current_SID; + save_current_sctx = current_sctx; # ifdef FEAT_PROFILE if (do_profiling == PROF_YES) @@ -9725,7 +9726,7 @@ apply_autocmds_group( autocmd_bufnr = save_autocmd_bufnr; autocmd_match = save_autocmd_match; #ifdef FEAT_EVAL - current_SID = save_current_SID; + current_sctx = save_current_sctx; restore_funccal(save_funccalp); # ifdef FEAT_PROFILE if (do_profiling == PROF_YES) @@ -9949,7 +9950,7 @@ getnextac(int c UNUSED, void *cookie, int indent UNUSED) retval = vim_strsave(ac->cmd); autocmd_nested = ac->nested; #ifdef FEAT_EVAL - current_SID = ac->scriptID; + current_sctx = ac->script_ctx; #endif if (ac->last) acp->nextcmd = NULL; diff --git a/src/getchar.c b/src/getchar.c index 496e33fa86..cc8b344e11 100644 --- a/src/getchar.c +++ b/src/getchar.c @@ -3677,7 +3677,8 @@ do_map( mp->m_mode = mode; #ifdef FEAT_EVAL mp->m_expr = expr; - mp->m_script_ID = current_SID; + mp->m_script_ctx = current_sctx; + mp->m_script_ctx.sc_lnum += sourcing_lnum; #endif did_it = TRUE; } @@ -3783,7 +3784,8 @@ do_map( mp->m_mode = mode; #ifdef FEAT_EVAL mp->m_expr = expr; - mp->m_script_ID = current_SID; + mp->m_script_ctx = current_sctx; + mp->m_script_ctx.sc_lnum += sourcing_lnum; #endif /* add the new entry in front of the abbrlist or maphash[] list */ @@ -4097,7 +4099,7 @@ showmap( } #ifdef FEAT_EVAL if (p_verbose > 0) - last_set_msg(mp->m_script_ID); + last_set_msg(mp->m_script_ctx); #endif out_flush(); /* show one line at a time */ } diff --git a/src/globals.h b/src/globals.h index 3446cba751..3f5b61ff78 100644 --- a/src/globals.h +++ b/src/globals.h @@ -325,8 +325,8 @@ EXTERN int may_garbage_collect INIT(= FALSE); EXTERN int want_garbage_collect INIT(= FALSE); EXTERN int garbage_collect_at_exit INIT(= FALSE); -/* ID of script being sourced or was sourced to define the current function. */ -EXTERN scid_T current_SID INIT(= 0); +// Script CTX being sourced or was sourced to define the current function. +EXTERN sctx_T current_sctx INIT(= {0 COMMA 0}); #endif EXTERN int did_source_packages INIT(= FALSE); diff --git a/src/main.c b/src/main.c index d3a509be3f..cb0676ce56 100644 --- a/src/main.c +++ b/src/main.c @@ -2912,13 +2912,13 @@ exe_pre_commands(mparm_T *parmp) curwin->w_cursor.lnum = 0; /* just in case.. */ sourcing_name = (char_u *)_("pre-vimrc command line"); # ifdef FEAT_EVAL - current_SID = SID_CMDARG; + current_sctx.sc_sid = SID_CMDARG; # endif for (i = 0; i < cnt; ++i) do_cmdline_cmd(cmds[i]); sourcing_name = NULL; # ifdef FEAT_EVAL - current_SID = 0; + current_sctx.sc_sid = 0; # endif TIME_MSG("--cmd commands"); } @@ -2942,7 +2942,7 @@ exe_commands(mparm_T *parmp) curwin->w_cursor.lnum = 0; sourcing_name = (char_u *)"command line"; #ifdef FEAT_EVAL - current_SID = SID_CARG; + current_sctx.sc_sid = SID_CARG; #endif for (i = 0; i < parmp->n_commands; ++i) { @@ -2952,7 +2952,7 @@ exe_commands(mparm_T *parmp) } sourcing_name = NULL; #ifdef FEAT_EVAL - current_SID = 0; + current_sctx.sc_sid = 0; #endif if (curwin->w_cursor.lnum == 0) curwin->w_cursor.lnum = 1; @@ -3159,7 +3159,7 @@ process_env( char_u *save_sourcing_name; linenr_T save_sourcing_lnum; #ifdef FEAT_EVAL - scid_T save_sid; + sctx_T save_current_sctx; #endif if ((initstr = mch_getenv(env)) != NULL && *initstr != NUL) @@ -3171,14 +3171,15 @@ process_env( sourcing_name = env; sourcing_lnum = 0; #ifdef FEAT_EVAL - save_sid = current_SID; - current_SID = SID_ENV; + save_current_sctx = current_sctx; + current_sctx.sc_sid = SID_ENV; + current_sctx.sc_lnum = 0; #endif do_cmdline_cmd(initstr); sourcing_name = save_sourcing_name; sourcing_lnum = save_sourcing_lnum; #ifdef FEAT_EVAL - current_SID = save_sid; + current_sctx = save_current_sctx; #endif return OK; } diff --git a/src/menu.c b/src/menu.c index 58429dc8aa..d253e72cb5 100644 --- a/src/menu.c +++ b/src/menu.c @@ -2259,7 +2259,7 @@ execute_menu(exarg_T *eap, vimmenu_T *menu) /* Use the Insert mode entry when returning to Insert mode. */ if (restart_edit #ifdef FEAT_EVAL - && !current_SID + && !current_sctx.sc_sid #endif ) { @@ -2333,7 +2333,7 @@ execute_menu(exarg_T *eap, vimmenu_T *menu) * Otherwise put them in the typeahead buffer. */ if (eap == NULL #ifdef FEAT_EVAL - || current_SID != 0 + || current_sctx.sc_sid != 0 #endif ) { diff --git a/src/option.c b/src/option.c index a7a6ebbd92..98ef98a274 100644 --- a/src/option.c +++ b/src/option.c @@ -404,20 +404,20 @@ static char_u *p_vsts_nopaste; struct vimoption { - char *fullname; /* full option name */ - char *shortname; /* permissible abbreviation */ - long_u flags; /* see below */ - char_u *var; /* global option: pointer to variable; - * window-local option: VAR_WIN; - * buffer-local option: global value */ - idopt_T indir; /* global option: PV_NONE; - * local option: indirect option index */ - char_u *def_val[2]; /* default values for variable (vi and vim) */ + char *fullname; // full option name + char *shortname; // permissible abbreviation + long_u flags; // see below + char_u *var; // global option: pointer to variable; + // window-local option: VAR_WIN; + // buffer-local option: global value + idopt_T indir; // global option: PV_NONE; + // local option: indirect option index + char_u *def_val[2]; // default values for variable (vi and vim) #ifdef FEAT_EVAL - scid_T scriptID; /* script in which the option was last set */ -# define SCRIPTID_INIT , 0 + sctx_T script_ctx; // script context where the option was last set +# define SCTX_INIT , {0, 0} #else -# define SCRIPTID_INIT +# define SCTX_INIT #endif }; @@ -515,7 +515,7 @@ static struct vimoption options[] = #else (char_u *)224L, #endif - (char_u *)0L} SCRIPTID_INIT}, + (char_u *)0L} SCTX_INIT}, {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR, #if defined(FEAT_GUI_MAC) (char_u *)&p_antialias, PV_NONE, @@ -524,35 +524,35 @@ static struct vimoption options[] = (char_u *)NULL, PV_NONE, {(char_u *)FALSE, (char_u *)FALSE} #endif - SCRIPTID_INIT}, + SCTX_INIT}, {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT, #ifdef FEAT_ARABIC (char_u *)VAR_WIN, PV_ARAB, #else (char_u *)NULL, PV_NONE, #endif - {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT}, + {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR, #ifdef FEAT_ARABIC (char_u *)&p_arshape, PV_NONE, #else (char_u *)NULL, PV_NONE, #endif - {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT}, + {(char_u *)TRUE, (char_u *)0L} SCTX_INIT}, {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM, #ifdef FEAT_RIGHTLEFT (char_u *)&p_ari, PV_NONE, #else (char_u *)NULL, PV_NONE, #endif - {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT}, + {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, {"altkeymap", "akm", P_BOOL|P_VI_DEF, #ifdef FEAT_FKMAP (char_u *)&p_altkeymap, PV_NONE, #else (char_u *)NULL, PV_NONE, #endif - {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT}, + {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR, #if defined(FEAT_MBYTE) (char_u *)&p_ambw, PV_NONE, @@ -561,7 +561,7 @@ static struct vimoption options[] = (char_u *)NULL, PV_NONE, {(char_u *)0L, (char_u *)0L} #endif - SCRIPTID_INIT}, + SCTX_INIT}, {"autochdir", "acd", P_BOOL|P_VI_DEF, #ifdef FEAT_AUTOCHDIR (char_u *)&p_acd, PV_NONE, @@ -570,22 +570,22 @@ static struct vimoption options[] = (char_u *)NULL, PV_NONE, {(char_u *)0L, (char_u *)0L} #endif - SCRIPTID_INIT}, + SCTX_INIT}, {"autoindent", "ai", P_BOOL|P_VI_DEF, (char_u *)&p_ai, PV_AI, - {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT}, + {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, {"autoprint", "ap", P_BOOL|P_VI_DEF, (char_u *)NULL, PV_NONE, - {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT}, + {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, {"autoread", "ar", P_BOOL|P_VI_DEF, (char_u *)&p_ar, PV_AR, - {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT}, + {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, {"au |