Ozaki Kiichi wrote:
> This pull-req proposes storing the script line number with script ID. > > ## Purpose > > 1. Get the current script line number in any position. > > We can get the script line number (by `expand('<slnum>')`), but this returns > lnum based on the top of current function, except while doing `:source`. > This patch adds new key `<flnum>` to `expand()`, `expand('<flnum>')` shows > the current line number. > > 2. Get the line number: > > * where option is set > * where function/map/command/autocmd is defined > > Vim saves the script ID for each items, but no line number. > This patch can provide more details, the line number information, to user. > > ## Details > > Replacing "scriptID" field of each struct by `sctx_T` (means Script ConTeXt) : > > ```c > typedef struct { > scid_T sc_scid; // script ID > linenr_T sc_lnum; // script line number > } sctx_T; > ``` > > And add `current_sctx` to save the current context: > > * Redefine `current_SID` as the macro of `current_sctx.sc_scid` > * Define `current_SLN` as the macro of `current_sctx.sc_lnum` > > Thus, by loading `sc_lnum` of context item into `current_SLN`, `current_SLN + > sourcing_lnum` means the current script line number. `expand('<flnum>')` > returns it. > > ## Application examples > > ### Better profiling > > By @blueyed. > #3286 > https://github.com/blueyed/vim/commit/6f9e14aa2e61cb271d654331dc1e11eee4dabd09 > > > ### Detailed information for items > > By @ujihisa. > > * Make `:verbose ...` show the line number > > ```diff > --- a/src/eval.c > +++ b/src/eval.c > @@ -8742,6 +8742,13 @@ last_set_msg(sctx_T sctx) > MSG_PUTS(_("\n\tLast set from ")); > MSG_PUTS(p); > vim_free(p); > + if (sctx.sc_lnum > 0) > + { > + char_u s[21]; > + > + vim_snprintf((char *)s, sizeof(s), ":%ld", sctx.sc_lnum); > + MSG_PUTS(s); > + } > verbose_leave(); > } > } > ``` > > `vim --clean` > > present: > ``` > :verbose map > Q gq > Last set from /usr/local/share/vim/vim81/defaults.vim > ``` > > patched: > ``` > :verbose map > Q gq > Last set from /usr/local/share/vim/vim81/defaults.vim:69 > ``` > > **NOTE** No test and doc yet. Thanks for doing this. Generally looks good. Using sctx_T looks OK, but changing "script_ID" to "sctx" is a bit cryptic. How about using "script_ctx"? -- | Ceci n'est pas une pipe. /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org /// -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.