Patch 9.0.0244
Problem: Cannot easily get the list of sourced scripts.
Solution: Add the getscriptinfo() function. (Yegappan Lakshmanan,
closes #10957)
Files: runtime/doc/builtin.txt, runtime/doc/usr_41.txt, src/evalfunc.c,
src/proto/
scriptfile.pro, src/scriptfile.c,
src/testdir/test_scriptnames.vim, src/testdir/test_vim9_import.vim
*** ../vim-9.0.0243/runtime/doc/builtin.txt 2022-08-13 21:34:18.999400776 +0100
--- runtime/doc/builtin.txt 2022-08-22 13:08:10.477554983 +0100
***************
*** 253,258 ****
--- 253,259 ----
String or List contents of a register
getreginfo([{regname}]) Dict information about a register
getregtype([{regname}]) String type of a register
+ getscriptinfo() List list of sourced scripts
gettabinfo([{expr}]) List list of tab pages
gettabvar({nr}, {varname} [, {def}])
any variable {varname} in tab {nr} or {def}
***************
*** 1151,1157 ****
Can also be used as a |method|: >
GetBlob()->blob2list()
!
*browse()*
browse({save}, {title}, {initdir}, {default})
Put up a file requester. This only works when "has("browse")"
--- 1152,1158 ----
Can also be used as a |method|: >
GetBlob()->blob2list()
! <
*browse()*
browse({save}, {title}, {initdir}, {default})
Put up a file requester. This only works when "has("browse")"
***************
*** 4082,4087 ****
--- 4089,4106 ----
Can also be used as a |method|: >
GetRegname()->getregtype()
+ getscriptinfo() *getscriptinfo()*
+ Returns a |List| with information about all the sourced Vim
+ scripts in the order they were sourced. (|:scriptinfo|)
+
+ Each item in the returned List is a |Dict| with the following
+ items:
+ autoload set to TRUE for a script that was used with
+ |import autoload| but was not actually sourced
+ yet.
+ name vim script file name.
+ sid script ID |<SID>|.
+
gettabinfo([{tabnr}]) *gettabinfo()*
If {tabnr} is not specified, then information about all the
tab pages is returned as a |List|. Each List item is a
*** ../vim-9.0.0243/runtime/doc/usr_41.txt 2022-08-13 13:08:30.286914784 +0100
--- runtime/doc/usr_41.txt 2022-08-22 13:08:10.477554983 +0100
***************
*** 1309,1314 ****
--- 1310,1323 ----
prompt_setinterrupt() set interrupt callback for a buffer
prompt_setprompt() set the prompt text for a buffer
+ Registers: *register-functions*
+ getreg() get contents of a register
+ getreginfo() get information about a register
+ getregtype() get type of a register
+ setreg() set contents and type of a register
+ reg_executing() return the name of the register being executed
+ reg_recording() return the name of the register being recorded
+
Text Properties: *text-property-functions*
prop_add() attach a property at a position
prop_add_list() attach a property at multiple positions
***************
*** 1340,1345 ****
--- 1349,1355 ----
did_filetype() check if a FileType autocommand was used
eventhandler() check if invoked by an event handler
getpid() get process ID of Vim
+ getscriptinfo() get list of sourced vim scripts
getimstatus() check if IME status is active
interrupt() interrupt script execution
windowsversion() get MS-Windows version
***************
*** 1351,1363 ****
undofile() get the name of the undo file
undotree() return the state of the undo tree
- getreg() get contents of a register
- getreginfo() get information about a register
- getregtype() get type of a register
- setreg() set contents and type of a register
- reg_executing() return the name of the register being executed
- reg_recording() return the name of the register being recorded
-
shiftwidth() effective value of 'shiftwidth'
wordcount() get byte/word/char count of buffer
--- 1361,1366 ----
*** ../vim-9.0.0243/src/evalfunc.c 2022-08-16 20:23:57.398232761 +0100
--- src/evalfunc.c 2022-08-22 13:08:10.481554973 +0100
***************
*** 1935,1940 ****
--- 1935,1942 ----
ret_dict_any, f_getreginfo},
{"getregtype", 0, 1, FEARG_1, arg1_string,
ret_string, f_getregtype},
+ {"getscriptinfo", 0, 0, 0, NULL,
+ ret_list_dict_any, f_getscriptinfo},
{"gettabinfo", 0, 1, FEARG_1, arg1_number,
ret_list_dict_any, f_gettabinfo},
{"gettabvar", 2, 3, FEARG_1, arg3_number_string_any,
*** ../vim-9.0.0243/src/proto/
scriptfile.pro 2022-06-29 12:54:48.068572061 +0100
--- src/proto/
scriptfile.pro 2022-08-22 13:08:10.481554973 +0100
***************
*** 33,38 ****
--- 33,39 ----
void free_scriptnames(void);
void free_autoload_scriptnames(void);
linenr_T get_sourced_lnum(char_u *(*fgetline)(int, void *, int, getline_opt_T), void *cookie);
+ void f_getscriptinfo(typval_T *argvars, typval_T *rettv);
char_u *getsourceline(int c, void *cookie, int indent, getline_opt_T options);
int sourcing_a_script(exarg_T *eap);
void ex_scriptencoding(exarg_T *eap);
*** ../vim-9.0.0243/src/scriptfile.c 2022-08-16 20:23:57.398232761 +0100
--- src/scriptfile.c 2022-08-22 13:08:10.481554973 +0100
***************
*** 1933,1938 ****
--- 1933,1968 ----
? ((source_cookie_T *)cookie)->sourcing_lnum
: SOURCING_LNUM;
}
+
+ void
+ f_getscriptinfo(typval_T *argvars UNUSED, typval_T *rettv)
+ {
+ int i;
+ list_T *l;
+
+ if (rettv_list_alloc(rettv) == FAIL)
+ return;
+
+ l = rettv->vval.v_list;
+
+ for (i = 1; i <= script_items.ga_len; ++i)
+ {
+ scriptitem_T *si = SCRIPT_ITEM(i);
+ dict_T *d;
+
+ if (si->sn_name == NULL)
+ continue;
+
+ if ((d = dict_alloc()) == NULL
+ || list_append_dict(l, d) == FAIL
+ || dict_add_string(d, "name", si->sn_name) == FAIL
+ || dict_add_number(d, "sid", i) == FAIL
+ || dict_add_bool(d, "autoload",
+ si->sn_state == SN_STATE_NOT_LOADED) == FAIL)
+ return;
+ }
+ }
+
#endif
static char_u *
*** ../vim-9.0.0243/src/testdir/test_scriptnames.vim 2022-01-18 13:32:20.000000000 +0000
--- src/testdir/test_scriptnames.vim 2022-08-22 13:08:10.481554973 +0100
***************
*** 1,5 ****
- " Test for :scriptnames
func Test_scriptnames()
call writefile(['let did_load_script = 123'], 'Xscripting')
source Xscripting
--- 1,5 ----
+ " Test for the :scriptnames command
func Test_scriptnames()
call writefile(['let did_load_script = 123'], 'Xscripting')
source Xscripting
***************
*** 29,32 ****
--- 29,42 ----
call assert_equal(msgs, execute('messages'))
endfunc
+ " Test for the getscriptinfo() function
+ func Test_getscriptinfo()
+ call writefile(['let loaded_script_id = expand("<SID>")'], 'Xscript')
+ source Xscript
+ let l = getscriptinfo()
+ call assert_match('Xscript$', l[-1].name)
+ call assert_equal(g:loaded_script_id, $"<SNR>{l[-1].sid}_")
+ call delete('Xscript')
+ endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
*** ../vim-9.0.0243/src/testdir/test_vim9_import.vim 2022-06-26 17:59:12.000000000 +0100
--- src/testdir/test_vim9_import.vim 2022-08-22 13:08:10.481554973 +0100
***************
*** 732,737 ****
--- 732,739 ----
source Xmapscript.vim
assert_match('\d\+ A: .*XrelautoloadExport.vim', execute('scriptnames')->split("\n")[-1])
+ assert_match('XrelautoloadExport.vim$', getscriptinfo()[-1].name)
+ assert_true(getscriptinfo()[-1].autoload)
feedkeys("\<F3>", "xt")
assert_equal(42, g:result)
*** ../vim-9.0.0243/src/version.c 2022-08-22 13:00:13.250390870 +0100
--- src/version.c 2022-08-22 13:10:04.693326836 +0100
***************
*** 733,734 ****
--- 733,736 ----
{ /* Add new patch number below this line */
+ /**/
+ 244,
/**/
--
Why isn't there mouse-flavored cat food?
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///