mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
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:
parent
c28adf15e6
commit
94f59fc9be
@ -96,6 +96,19 @@ String vim_replace_termcodes(String str, Boolean from_part, Boolean do_lt,
|
|||||||
return cstr_as_string(ptr);
|
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
|
/// Evaluates the expression str using the vim internal expression
|
||||||
/// evaluator (see |expression|).
|
/// evaluator (see |expression|).
|
||||||
/// Dictionaries and lists are recursively expanded.
|
/// Dictionaries and lists are recursively expanded.
|
||||||
|
@ -424,7 +424,8 @@ static struct vimvar {
|
|||||||
{VV_NAME("oldfiles", VAR_LIST), 0},
|
{VV_NAME("oldfiles", VAR_LIST), 0},
|
||||||
{VV_NAME("windowid", VAR_NUMBER), VV_RO},
|
{VV_NAME("windowid", VAR_NUMBER), VV_RO},
|
||||||
{VV_NAME("progpath", VAR_STRING), 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 */
|
/* shorthand */
|
||||||
|
@ -64,6 +64,7 @@ enum {
|
|||||||
VV_WINDOWID,
|
VV_WINDOWID,
|
||||||
VV_PROGPATH,
|
VV_PROGPATH,
|
||||||
VV_JOB_DATA,
|
VV_JOB_DATA,
|
||||||
|
VV_COMMAND_OUTPUT,
|
||||||
VV_LEN, /* number of v: vars */
|
VV_LEN, /* number of v: vars */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user