Mercurial > vim
diff src/evalfunc.c @ 17020:1841c03a9b5e v8.1.1510
patch 8.1.1510: a plugin cannot easily expand a command like done internally
commit https://github.com/vim/vim/commit/80dad48c5095d30873a42ec82628bdb213125d8e
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jun 9 17:22:31 2019 +0200
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 https://github.com/vim/vim/issues/4514)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 09 Jun 2019 17:30:04 +0200 |
parents | 353ed7ef78df |
children | 905e1b154058 |
line wrap: on
line diff
--- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -149,6 +149,7 @@ static void f_exists(typval_T *argvars, static void f_exp(typval_T *argvars, typval_T *rettv); #endif static void f_expand(typval_T *argvars, typval_T *rettv); +static void f_expandcmd(typval_T *argvars, typval_T *rettv); static void f_extend(typval_T *argvars, typval_T *rettv); static void f_feedkeys(typval_T *argvars, typval_T *rettv); static void f_filereadable(typval_T *argvars, typval_T *rettv); @@ -646,6 +647,7 @@ static struct fst {"exp", 1, 1, f_exp}, #endif {"expand", 1, 3, f_expand}, + {"expandcmd", 1, 1, f_expandcmd}, {"extend", 2, 3, f_extend}, {"feedkeys", 1, 2, f_feedkeys}, {"file_readable", 1, 1, f_filereadable}, /* obsolete */ @@ -3791,6 +3793,35 @@ f_expand(typval_T *argvars, typval_T *re } /* + * "expandcmd()" function + * Expand all the special characters in a command string. + */ + static void +f_expandcmd(typval_T *argvars, typval_T *rettv) +{ + exarg_T eap; + char_u *cmdstr; + char *errormsg = NULL; + + rettv->v_type = VAR_STRING; + cmdstr = vim_strsave(tv_get_string(&argvars[0])); + + memset(&eap, 0, sizeof(eap)); + eap.cmd = cmdstr; + eap.arg = cmdstr; + eap.argt |= NOSPC; + eap.usefilter = FALSE; + eap.nextcmd = NULL; + eap.cmdidx = CMD_USER; + + 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 */