diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-08-16 17:30:39 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-16 17:30:39 +0800 |
commit | 03fddfd92887bbac920d80cd9e04f28f32843f5d (patch) | |
tree | 57de450593501bed498f6b7b22d74a647db8a445 /src | |
parent | dee96f4725da8f05d5b62fa08a4daf802d780813 (diff) | |
download | rneovim-03fddfd92887bbac920d80cd9e04f28f32843f5d.tar.gz rneovim-03fddfd92887bbac920d80cd9e04f28f32843f5d.tar.bz2 rneovim-03fddfd92887bbac920d80cd9e04f28f32843f5d.zip |
fix(api): nvim_exec and nvim_cmd restore msg_col when capturing output (#19789)
This matches the code in execute_common(), preventing messages after the
API call from being printed at the wrong column.
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/api/command.c | 4 | ||||
-rw-r--r-- | src/nvim/api/vimscript.c | 4 |
2 files changed, 8 insertions, 0 deletions
diff --git a/src/nvim/api/command.c b/src/nvim/api/command.c index e77add6210..1323fc347b 100644 --- a/src/nvim/api/command.c +++ b/src/nvim/api/command.c @@ -626,6 +626,7 @@ String nvim_cmd(uint64_t channel_id, Dict(cmd) *cmd, Dict(cmd_opts) *opts, Error garray_T capture_local; const int save_msg_silent = msg_silent; garray_T * const save_capture_ga = capture_ga; + const int save_msg_col = msg_col; if (output) { ga_init(&capture_local, 1, 80); @@ -636,6 +637,7 @@ String nvim_cmd(uint64_t channel_id, Dict(cmd) *cmd, Dict(cmd_opts) *opts, Error try_start(); if (output) { msg_silent++; + msg_col = 0; // prevent leading spaces } WITH_SCRIPT_CONTEXT(channel_id, { @@ -645,6 +647,8 @@ String nvim_cmd(uint64_t channel_id, Dict(cmd) *cmd, Dict(cmd_opts) *opts, Error if (output) { capture_ga = save_capture_ga; msg_silent = save_msg_silent; + // Put msg_col back where it was, since nothing should have been written. + msg_col = save_msg_col; } try_end(err); diff --git a/src/nvim/api/vimscript.c b/src/nvim/api/vimscript.c index 3b25e3aa38..a28bfd2ab9 100644 --- a/src/nvim/api/vimscript.c +++ b/src/nvim/api/vimscript.c @@ -49,6 +49,7 @@ String nvim_exec(uint64_t channel_id, String src, Boolean output, Error *err) { const int save_msg_silent = msg_silent; garray_T *const save_capture_ga = capture_ga; + const int save_msg_col = msg_col; garray_T capture_local; if (output) { ga_init(&capture_local, 1, 80); @@ -58,6 +59,7 @@ String nvim_exec(uint64_t channel_id, String src, Boolean output, Error *err) try_start(); if (output) { msg_silent++; + msg_col = 0; // prevent leading spaces } const sctx_T save_current_sctx = api_set_sctx(channel_id); @@ -66,6 +68,8 @@ String nvim_exec(uint64_t channel_id, String src, Boolean output, Error *err) if (output) { capture_ga = save_capture_ga; msg_silent = save_msg_silent; + // Put msg_col back where it was, since nothing should have been written. + msg_col = save_msg_col; } current_sctx = save_current_sctx; |