api: Implement vim_command_output function

This function can be used by API clients to execute a command and capture the
output.
This commit is contained in:
Thiago de Arruda 2014-06-05 08:25:53 -03:00 committed by Justin M. Keyes
parent c28adf15e6
commit 94f59fc9be
3 changed files with 16 additions and 1 deletions

View File

@ -96,6 +96,19 @@ String vim_replace_termcodes(String str, Boolean from_part, Boolean do_lt,
return cstr_as_string(ptr);
}
String vim_command_output(String str, Error *err)
{
do_cmdline_cmd((char_u *)"redir => v:command_output");
vim_command(str, err);
do_cmdline_cmd((char_u *)"redir END");
if (err->set) {
return (String) STRING_INIT;
}
return cstr_to_string((char *)get_vim_var_str(VV_COMMAND_OUTPUT));
}
/// Evaluates the expression str using the vim internal expression
/// evaluator (see |expression|).
/// Dictionaries and lists are recursively expanded.

View File

@ -424,7 +424,8 @@ static struct vimvar {
{VV_NAME("oldfiles", VAR_LIST), 0},
{VV_NAME("windowid", VAR_NUMBER), VV_RO},
{VV_NAME("progpath", VAR_STRING), VV_RO},
{VV_NAME("job_data", VAR_LIST), 0}
{VV_NAME("job_data", VAR_LIST), 0},
{VV_NAME("command_output", VAR_STRING), 0}
};
/* shorthand */

View File

@ -64,6 +64,7 @@ enum {
VV_WINDOWID,
VV_PROGPATH,
VV_JOB_DATA,
VV_COMMAND_OUTPUT,
VV_LEN, /* number of v: vars */
};