diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-04-15 19:50:23 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2023-04-15 21:06:16 +0800 |
commit | bcc971de15ed540356405f937d640eaffa4a03bb (patch) | |
tree | ebd853d8e81134cd7dad02ed4c7bd51849f8683b /src/nvim/runtime.c | |
parent | eb151a9730f0000ff46e0b3467e29bb9f02ae362 (diff) | |
download | rneovim-bcc971de15ed540356405f937d640eaffa4a03bb.tar.gz rneovim-bcc971de15ed540356405f937d640eaffa4a03bb.tar.bz2 rneovim-bcc971de15ed540356405f937d640eaffa4a03bb.zip |
vim-patch:9.0.0269: getscriptinfo() does not include the version
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 vim/vim#10962)
https://github.com/vim/vim/commit/520f6ef60a59f7b5f3da9199999d13dbe817d3ce
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Diffstat (limited to 'src/nvim/runtime.c')
-rw-r--r-- | src/nvim/runtime.c | 27 |
1 files changed, 27 insertions, 0 deletions
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. |