empty({expr}) Number |TRUE| if {expr} is empty
escape({string}, {chars}) String escape {chars} in {string} with '\'
eval({string}) any evaluate {string} into its value
+evalcmd({command}) String execute {command} and get the output
eventhandler() Number |TRUE| if inside an event handler
executable({expr}) Number 1 if executable {expr} exists
exepath({expr}) String full path of the command {expr}
them. Also works for |Funcref|s that refer to existing
functions.
+evalcmd({command}) *evalcmd()*
+ Execute Ex {command} and return the output as a string. This
+ is equivalent to: >
+ redir => var
+ {command}
+ redir END
+< To get a list of lines use: >
+ split(evalcmd(cmd), "\n")
+
eventhandler() *eventhandler()*
Returns 1 when inside an event handler. That is that Vim got
interrupted while waiting for the user to type a character,
static void f_empty(typval_T *argvars, typval_T *rettv);
static void f_escape(typval_T *argvars, typval_T *rettv);
static void f_eval(typval_T *argvars, typval_T *rettv);
+static void f_evalcmd(typval_T *argvars, typval_T *rettv);
static void f_eventhandler(typval_T *argvars, typval_T *rettv);
static void f_executable(typval_T *argvars, typval_T *rettv);
static void f_exepath(typval_T *argvars, typval_T *rettv);
}
static lval_T *redir_lval = NULL;
+#define EVALCMD_BUSY (redir_lval == (lval_T *)&redir_lval)
static garray_T redir_ga; /* only valid when redir_lval is not NULL */
static char_u *redir_endp = NULL;
static char_u *redir_varname = NULL;
{
typval_T tv;
+ if (EVALCMD_BUSY)
+ {
+ redir_lval = NULL;
+ return;
+ }
+
if (redir_lval != NULL)
{
/* If there was no error: assign the text to the variable. */
{"empty", 1, 1, f_empty},
{"escape", 2, 2, f_escape},
{"eval", 1, 1, f_eval},
+ {"evalcmd", 1, 1, f_evalcmd},
{"eventhandler", 0, 0, f_eventhandler},
{"executable", 1, 1, f_executable},
{"exepath", 1, 1, f_exepath},
EMSG(_(e_trailing));
}
+/*
+ * "evalcmd()" function
+ */
+ static void
+f_evalcmd(typval_T *argvars, typval_T *rettv)
+{
+ char_u *s;
+
+ rettv->vval.v_string = NULL;
+ rettv->v_type = VAR_STRING;
+
+ s = get_tv_string_chk(&argvars[0]);
+ if (s != NULL)
+ {
+ redir_vname = TRUE;
+ redir_lval = (lval_T *)&redir_lval;
+ ga_init2(&redir_ga, (int)sizeof(char), 500);
+
+ if (do_cmdline_cmd(s) == OK)
+ rettv->vval.v_string = redir_ga.ga_data;
+ else
+ vim_free(redir_ga.ga_data);
+
+ redir_ga.ga_data = NULL;
+ redir_vname = FALSE;
+ redir_lval = NULL;
+ }
+
+}
+
/*
* "eventhandler()" function
*/