To: vim_dev@googlegroups.com Subject: Patch 9.0.0269 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.0269 Problem: getscriptinfo() does not include the version. Cannot select entries by script name. Solution: Add the "version" item and the "name" argument. (Yegappan Lakshmanan, closes #10962) Files: runtime/doc/builtin.txt, src/evalfunc.c, src/scriptfile.c, src/testdir/test_scriptnames.vim, src/testdir/test_vim9_builtin.vim, src/testdir/test_vim9_import.vim *** ../vim-9.0.0268/runtime/doc/builtin.txt 2022-08-25 16:02:09.673816447 +0100 --- runtime/doc/builtin.txt 2022-08-25 17:34:56.086726901 +0100 *************** *** 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} --- 253,259 ---- String or List contents of a register getreginfo([{regname}]) Dict information about a register getregtype([{regname}]) String type of a register ! getscriptinfo([{opts}]) List list of sourced scripts gettabinfo([{expr}]) List list of tab pages gettabvar({nr}, {varname} [, {def}]) any variable {varname} in tab {nr} or {def} *************** *** 4083,4089 **** 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, like what `:scriptnames` shows. --- 4089,4095 ---- Can also be used as a |method|: > GetRegname()->getregtype() ! getscriptinfo([{opts}) *getscriptinfo()* Returns a |List| with information about all the sourced Vim scripts in the order they were sourced, like what `:scriptnames` shows. *************** *** 4095,4102 **** yet (see |import-autoload|). name vim script file name. sid script ID ||. ! sourced if this script is an alias this is the script ! ID of the actually sourced script, otherwise zero gettabinfo([{tabnr}]) *gettabinfo()* If {tabnr} is not specified, then information about all the --- 4101,4116 ---- yet (see |import-autoload|). name vim script file name. sid script ID ||. ! sourced script ID of the actually sourced script that ! this script name links to, if any, otherwise ! zero ! version vimscript version (|scriptversion|) ! ! The optional Dict argument {opts} supports the following ! items: ! name script name match pattern. If specified, ! information about scripts with name ! that match the pattern "name" are returned. gettabinfo([{tabnr}]) *gettabinfo()* If {tabnr} is not specified, then information about all the *** ../vim-9.0.0268/src/evalfunc.c 2022-08-25 16:02:09.677816456 +0100 --- src/evalfunc.c 2022-08-25 17:35:02.658692892 +0100 *************** *** 1935,1941 **** 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}, --- 1935,1941 ---- ret_dict_any, f_getreginfo}, {"getregtype", 0, 1, FEARG_1, arg1_string, ret_string, f_getregtype}, ! {"getscriptinfo", 0, 1, 0, arg1_dict_any, ret_list_dict_any, f_getscriptinfo}, {"gettabinfo", 0, 1, FEARG_1, arg1_number, ret_list_dict_any, f_gettabinfo}, *** ../vim-9.0.0268/src/scriptfile.c 2022-08-24 17:32:31.969668849 +0100 --- src/scriptfile.c 2022-08-25 17:35:02.658692892 +0100 *************** *** 1946,1962 **** : 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); --- 1946,1980 ---- : SOURCING_LNUM; } + /* + * getscriptinfo() function + */ void ! f_getscriptinfo(typval_T *argvars, typval_T *rettv) { int i; list_T *l; + char_u *pat = NULL; + regmatch_T regmatch; if (rettv_list_alloc(rettv) == FAIL) return; + if (check_for_opt_dict_arg(argvars, 0) == FAIL) + return; + l = rettv->vval.v_list; + regmatch.regprog = NULL; + regmatch.rm_ic = p_ic; + + if (argvars[0].v_type == VAR_DICT) + { + pat = dict_get_string(argvars[0].vval.v_dict, "name", TRUE); + if (pat != NULL) + regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING); + } + for (i = 1; i <= script_items.ga_len; ++i) { scriptitem_T *si = SCRIPT_ITEM(i); *************** *** 1965,1979 **** --- 1983,2005 ---- if (si->sn_name == NULL) continue; + if (pat != NULL && regmatch.regprog != NULL + && !vim_regexec(®match, si->sn_name, (colnr_T)0)) + 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_number(d, "sourced", si->sn_sourced_sid) == FAIL + || dict_add_number(d, "version", si->sn_version) == FAIL || dict_add_bool(d, "autoload", si->sn_state == SN_STATE_NOT_LOADED) == FAIL) return; } + + vim_regfree(regmatch.regprog); + vim_free(pat); } #endif *** ../vim-9.0.0268/src/testdir/test_scriptnames.vim 2022-08-22 13:14:31.892769316 +0100 --- src/testdir/test_scriptnames.vim 2022-08-25 17:35:02.658692892 +0100 *************** *** 31,42 **** " Test for the getscriptinfo() function func Test_getscriptinfo() ! call writefile(['let loaded_script_id = expand("")'], 'Xscript') ! source Xscript let l = getscriptinfo() ! call assert_match('Xscript$', l[-1].name) call assert_equal(g:loaded_script_id, $"{l[-1].sid}_") ! call delete('Xscript') endfunc " vim: shiftwidth=2 sts=2 expandtab --- 31,64 ---- " Test for the getscriptinfo() function func Test_getscriptinfo() ! let lines =<< trim END ! let g:loaded_script_id = expand("") ! let s:XscriptVar = [1, #{v: 2}] ! func s:XscriptFunc() ! endfunc ! END ! call writefile(lines, 'X22script91') ! source X22script91 let l = getscriptinfo() ! call assert_match('X22script91$', l[-1].name) call assert_equal(g:loaded_script_id, $"{l[-1].sid}_") ! ! let l = getscriptinfo({'name': '22script91'}) ! call assert_equal(1, len(l)) ! call assert_match('22script91$', l[0].name) ! ! let l = getscriptinfo({'name': 'foobar'}) ! call assert_equal(0, len(l)) ! let l = getscriptinfo({'name': ''}) ! call assert_true(len(l) > 1) ! ! call assert_fails("echo getscriptinfo({'name': []})", 'E730:') ! call assert_fails("echo getscriptinfo({'name': '\\@'})", 'E866:') ! let l = getscriptinfo({'name': test_null_string()}) ! call assert_true(len(l) > 1) ! call assert_fails("echo getscriptinfo('foobar')", 'E1206:') ! ! call delete('X22script91') endfunc " vim: shiftwidth=2 sts=2 expandtab *** ../vim-9.0.0268/src/testdir/test_vim9_builtin.vim 2022-08-18 15:22:05.600871575 +0100 --- src/testdir/test_vim9_builtin.vim 2022-08-25 17:35:02.658692892 +0100 *************** *** 1896,1901 **** --- 1896,1905 ---- getregtype('')->assert_equal("\4") enddef + def Test_getscriptinfo() + v9.CheckDefAndScriptFailure(['getscriptinfo("x")'], ['E1013: Argument 1: type mismatch, expected dict but got string', 'E1206: Dictionary required for argument 1']) + enddef + def Test_gettabinfo() v9.CheckDefAndScriptFailure(['gettabinfo("x")'], ['E1013: Argument 1: type mismatch, expected number but got string', 'E1210: Number required for argument 1']) enddef *** ../vim-9.0.0268/src/testdir/test_vim9_import.vim 2022-08-24 17:46:05.065197599 +0100 --- src/testdir/test_vim9_import.vim 2022-08-25 17:35:02.658692892 +0100 *************** *** 732,741 **** 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("\", "xt") assert_equal(42, g:result) unlet g:result delete('XrelautoloadExport.vim') --- 732,746 ---- source Xmapscript.vim assert_match('\d\+ A: .*XrelautoloadExport.vim', execute('scriptnames')->split("\n")[-1]) ! var l = getscriptinfo() ! assert_match('XrelautoloadExport.vim$', l[-1].name) ! assert_true(l[-1].autoload) feedkeys("\", "xt") assert_equal(42, g:result) + l = getscriptinfo({name: 'XrelautoloadExport'}) + assert_true(len(l) == 1) + assert_match('XrelautoloadExport.vim$', l[0].name) + assert_false(l[0].autoload) unlet g:result delete('XrelautoloadExport.vim') *** ../vim-9.0.0268/src/version.c 2022-08-25 16:29:56.842870665 +0100 --- src/version.c 2022-08-25 17:36:01.411154341 +0100 *************** *** 729,730 **** --- 729,732 ---- { /* Add new patch number below this line */ + /**/ + 269, /**/ -- A special law prohibits unmarried women from parachuting on Sunday or she shall risk arrest, fine, and/or jailing. [real standing law in Florida, United States of America] /// Bram Moolenaar -- Bram@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 ///