diff options
author | Bram Moolenaar <Bram@vim.org> | 2016-07-07 17:33:02 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2016-07-07 17:33:02 +0200 |
commit | 1e5e1231ac9e1ba9678812c96f9d554a078eeec4 (patch) | |
tree | 21ea01576e37017525dd70dc9f640ad04c5f9456 /src/eval.c | |
parent | 9d5d3c9c4468ad76f16b50eabd3d9e7eab2ed44d (diff) | |
download | vim-1e5e1231ac9e1ba9678812c96f9d554a078eeec4.zip |
patch 7.4.1996
Problem: Capturing the output of a command takes a few commands.
Solution: Add evalcmd().
Diffstat (limited to 'src/eval.c')
-rw-r--r-- | src/eval.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/eval.c b/src/eval.c index 69238c181..74ed263d5 100644 --- a/src/eval.c +++ b/src/eval.c @@ -555,6 +555,7 @@ static void f_diff_hlID(typval_T *argvars, typval_T *rettv); 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); @@ -1133,6 +1134,7 @@ set_internal_string_var(char_u *name, char_u *value) } 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; @@ -1250,6 +1252,12 @@ var_redir_stop(void) { 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. */ @@ -8556,6 +8564,7 @@ static struct fst {"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}, @@ -11337,6 +11346,36 @@ f_eval(typval_T *argvars, typval_T *rettv) } /* + * "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 */ static void |