diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/eval.lua | 2 | ||||
-rw-r--r-- | src/nvim/runtime.c | 27 |
2 files changed, 28 insertions, 1 deletions
diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index 66032adbaf..7dbfac80f3 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -189,7 +189,7 @@ return { gettabinfo={args={0, 1}, base=1}, gettabvar={args={2, 3}, base=1}, gettabwinvar={args={3, 4}, base=1}, - getscriptinfo={}, + getscriptinfo={args={0, 1}}, gettagstack={args={0, 1}, base=1}, gettext={args=1, base=1}, getwininfo={args={0, 1}, base=1}, diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c index 1e39b58543..5bc63453c9 100644 --- a/src/nvim/runtime.c +++ b/src/nvim/runtime.c @@ -43,6 +43,7 @@ #include "nvim/os/stdpaths_defs.h" #include "nvim/path.h" #include "nvim/profile.h" +#include "nvim/regexp.h" #include "nvim/runtime.h" #include "nvim/strings.h" #include "nvim/usercmd.h" @@ -2361,8 +2362,25 @@ void f_getscriptinfo(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { tv_list_alloc_ret(rettv, script_items.ga_len); + if (tv_check_for_opt_dict_arg(argvars, 0) == FAIL) { + return; + } + list_T *l = rettv->vval.v_list; + regmatch_T regmatch = { + .regprog = NULL, + .rm_ic = p_ic, + }; + + char *pat = NULL; + if (argvars[0].v_type == VAR_DICT) { + pat = tv_dict_get_string(argvars[0].vval.v_dict, "name", true); + if (pat != NULL) { + regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING); + } + } + for (int i = 1; i <= script_items.ga_len; i++) { scriptitem_T *si = SCRIPT_ITEM(i); @@ -2370,13 +2388,22 @@ void f_getscriptinfo(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) continue; } + if (pat != NULL && regmatch.regprog != NULL + && !vim_regexec(®match, si->sn_name, (colnr_T)0)) { + continue; + } + dict_T *d = tv_dict_alloc(); tv_list_append_dict(l, d); tv_dict_add_str(d, S_LEN("name"), si->sn_name); tv_dict_add_nr(d, S_LEN("sid"), i); + tv_dict_add_nr(d, S_LEN("version"), 1); // Vim9 autoload script (:h vim9-autoload), not applicable to Nvim. tv_dict_add_bool(d, S_LEN("autoload"), false); } + + vim_regfree(regmatch.regprog); + xfree(pat); } /// Get one full line from a sourced file. |