aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2018-01-05 11:17:21 +0100
committerJustin M. Keyes <justinkz@gmail.com>2018-01-10 23:45:44 +0100
commitc095f83116eb8ef87983ca5fea61053755fbc4e5 (patch)
tree82be0f4aa1a50be3703a91236d1913462fd6a28a /src
parentf0845197d868735dc97aac72738b69c639c634b3 (diff)
downloadrneovim-c095f83116eb8ef87983ca5fea61053755fbc4e5.tar.gz
rneovim-c095f83116eb8ef87983ca5fea61053755fbc4e5.tar.bz2
rneovim-c095f83116eb8ef87983ca5fea61053755fbc4e5.zip
api: change nvim_command_output behavior
Implement nvim_command_output with `execute({cmd},"silent")`. Behavior changes: - does not provoke any hit-enter prompt - no longer prepends a newline char - does not capture some noise (like the "[New File]" message, see the change to tabnewentered_spec.lua) Technically ("bug-for-bug") this a breaking change. But the previous behavior of nvim_command_output meant that it probably wasn't used for anything outside of tests. Also remove the undocumented `v:command_output` variable which was a hack introduced only for the purposes of nvim_command_output. closes #7726
Diffstat (limited to 'src')
-rw-r--r--src/nvim/api/vim.c40
-rw-r--r--src/nvim/eval.c1
-rw-r--r--src/nvim/eval.h1
3 files changed, 31 insertions, 11 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index 172f2ce18e..8929bc5b9b 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -43,14 +43,15 @@
#endif
/// Executes an ex-command.
-/// On VimL error: Returns the VimL error; v:errmsg is not updated.
+///
+/// On parse error: forwards the Vim error; does not update v:errmsg.
+/// On runtime error: forwards the Vim error; does not update v:errmsg.
///
/// @param command Ex-command string
-/// @param[out] err Error details (including actual VimL error), if any
+/// @param[out] err Error details (Vim error), if any
void nvim_command(String command, Error *err)
FUNC_API_SINCE(1)
{
- // Run the command
try_start();
do_cmdline_cmd(command.data);
update_screen(VALID);
@@ -207,18 +208,39 @@ String nvim_replace_termcodes(String str, Boolean from_part, Boolean do_lt,
return cstr_as_string(ptr);
}
-String nvim_command_output(String str, Error *err)
+/// Executes an ex-command and returns its (non-error) output.
+/// Shell |:!| output is not captured.
+///
+/// On parse error: forwards the Vim error; does not update v:errmsg.
+/// On runtime error: forwards the Vim error; does not update v:errmsg.
+///
+/// @param command Ex-command string
+/// @param[out] err Error details (Vim error), if any
+String nvim_command_output(String command, Error *err)
FUNC_API_SINCE(1)
{
- do_cmdline_cmd("redir => v:command_output");
- nvim_command(str, err);
- do_cmdline_cmd("redir END");
-
+ Array args = ARRAY_DICT_INIT;
+ ADD(args, STRING_OBJ(copy_string(command)));
+ ADD(args, STRING_OBJ(cstr_to_string("silent")));
+ String fn = cstr_to_string("execute");
+ Object rv = nvim_call_function(fn, args, err);
+ api_free_string(fn);
+ api_free_array(args);
if (ERROR_SET(err)) {
+ assert(rv.type == kObjectTypeNil);
return (String)STRING_INIT;
}
- return cstr_to_string((char *)get_vim_var_str(VV_COMMAND_OUTPUT));
+ assert(rv.type == kObjectTypeString);
+ // execute() always(?) prepends a newline; remove it.
+ if (rv.data.string.size > 1) {
+ assert(rv.data.string.data[0] == '\n');
+ String *s = &rv.data.string;
+ s->size--;
+ memmove(s->data, s->data + 1, s->size);
+ s->data[s->size] = '\0';
+ }
+ return rv.data.string;
}
/// Evaluates a VimL expression (:help expression).
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index f34b6db8d8..875f323a28 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -402,7 +402,6 @@ static struct vimvar {
VV(VV_OLDFILES, "oldfiles", VAR_LIST, 0),
VV(VV_WINDOWID, "windowid", VAR_NUMBER, VV_RO_SBX),
VV(VV_PROGPATH, "progpath", VAR_STRING, VV_RO),
- VV(VV_COMMAND_OUTPUT, "command_output", VAR_STRING, 0),
VV(VV_COMPLETED_ITEM, "completed_item", VAR_DICT, VV_RO),
VV(VV_OPTION_NEW, "option_new", VAR_STRING, VV_RO),
VV(VV_OPTION_OLD, "option_old", VAR_STRING, VV_RO),
diff --git a/src/nvim/eval.h b/src/nvim/eval.h
index 0c0a6881f6..b798eae187 100644
--- a/src/nvim/eval.h
+++ b/src/nvim/eval.h
@@ -86,7 +86,6 @@ typedef enum {
VV_OLDFILES,
VV_WINDOWID,
VV_PROGPATH,
- VV_COMMAND_OUTPUT,
VV_COMPLETED_ITEM,
VV_OPTION_NEW,
VV_OPTION_OLD,