vim-patch:8.1.1510: a plugin cannot easily expand a command like done internally

Problem:    A plugin cannot easily expand a command like done internally.
Solution:   Add the expandcmd() function. (Yegappan Lakshmanan, closes vim/vim#4514)
80dad48c50
This commit is contained in:
Jan Edmund Lazo
2020-02-21 22:05:59 -05:00
parent 5e0c435ca1
commit eba8a9ca1d
5 changed files with 75 additions and 0 deletions

View File

@@ -102,6 +102,7 @@ return {
exists={args=1},
exp={args=1, func="float_op_wrapper", data="&exp"},
expand={args={1, 3}},
expandcmd={args=1},
extend={args={2, 3}},
feedkeys={args={1, 2}},
file_readable={args=1, func='f_filereadable'}, -- obsolete

View File

@@ -2103,6 +2103,31 @@ static void f_menu_get(typval_T *argvars, typval_T *rettv, FunPtr fptr)
menu_get((char_u *)tv_get_string(&argvars[0]), modes, rettv->vval.v_list);
}
// "expandcmd()" function
// Expand all the special characters in a command string.
static void f_expandcmd(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *errormsg = NULL;
rettv->v_type = VAR_STRING;
char_u *cmdstr = (char_u *)xstrdup(tv_get_string(&argvars[0]));
exarg_T eap = {
.cmd = cmdstr,
.arg = cmdstr,
.usefilter = false,
.nextcmd = NULL,
.cmdidx = CMD_USER,
};
eap.argt |= NOSPC;
expand_filename(&eap, &cmdstr, &errormsg);
if (errormsg != NULL && *errormsg != NUL) {
EMSG(errormsg);
}
rettv->vval.v_string = cmdstr;
}
/*
* "extend(list, list [, idx])" function
* "extend(dict, dict [, action])" function