From d725ead5ecdb35a359f20901589b9bec7ee8830f Mon Sep 17 00:00:00 2001 From: luukvbaal Date: Mon, 11 May 2026 21:47:19 +0200 Subject: [PATCH] fix(messages): reset redirection message column after :echon #39472 Problem: Message redirection column for captured output is not reset after :echon since (4260f73, e63346df). Solution: Ensure msg_ext_append is set before the kind with :echon. (cherry picked from commit ce9f4f036918f541c0c66a99b2c3b6f0fce0c6c9) --- src/nvim/eval.c | 3 ++- src/nvim/message.c | 8 +++++++- src/nvim/message.h | 2 -- src/nvim/os/shell.c | 2 +- test/functional/api/vim_spec.lua | 2 ++ 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 981a99ec48..745a775949 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -6161,6 +6161,7 @@ void ex_echo(exarg_T *eap) if (!eap->skip) { if (atstart) { atstart = false; + msg_ext_set_append(eap->cmdidx == CMD_echon); msg_ext_set_kind("echo"); // Call msg_start() after eval1(), evaluating the expression // may cause a message to appear. @@ -6177,7 +6178,6 @@ void ex_echo(exarg_T *eap) msg_puts_hl(" ", echo_hl_id, false); } char *tofree = encode_tv2echo(&rettv, NULL); - msg_ext_append = eap->cmdidx == CMD_echon; msg_multiline(cstr_as_string(tofree), echo_hl_id, true, false, &need_clear); xfree(tofree); } @@ -6186,6 +6186,7 @@ void ex_echo(exarg_T *eap) } eap->nextcmd = check_nextcmd(arg); clear_evalarg(&evalarg, eap); + msg_ext_set_append(false); if (eap->skip) { emsg_skip--; diff --git a/src/nvim/message.c b/src/nvim/message.c index 4748bd1db9..fb3d78a275 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -164,6 +164,7 @@ static sattr_T msg_ext_last_attr = -1; static int msg_ext_last_hl_id; static bool msg_ext_history = false; ///< message was added to history +static bool msg_ext_append = false; ///< message appended to previous message line static int msg_grid_pos_at_flush = 0; @@ -1686,9 +1687,14 @@ void msg_ext_set_kind(const char *msg_kind) redir_col = msg_ext_append ? redir_col : 0; } +void msg_ext_set_append(bool append) +{ + msg_ext_ui_flush(); + msg_ext_append = append; +} + void msg_ext_set_trigger(const char *trigger) { - // Don't change the trigger of an existing batch: msg_ext_ui_flush(); msg_ext_trigger = trigger; } diff --git a/src/nvim/message.h b/src/nvim/message.h index f34d79b767..95d5e24d4d 100644 --- a/src/nvim/message.h +++ b/src/nvim/message.h @@ -33,8 +33,6 @@ extern MessageHistoryEntry *msg_hist_last; EXTERN bool msg_ext_need_clear INIT( = false); /// Set to true to force grouping a set of message chunks into a single `cmdline_show` event. EXTERN bool msg_ext_skip_flush INIT( = false); -/// Set to true when message should be appended to previous message line. -EXTERN bool msg_ext_append INIT( = false); /// Set to true when previous message should be overwritten. EXTERN bool msg_ext_overwrite INIT( = false); /// Set to true to avoid setting "verbose" kind for "last set" messages. diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index f082dea849..644e76a5bb 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -1125,7 +1125,7 @@ static void out_data_event(void **argv) bool need_clear = true; int hl = (int)(intptr_t)argv[2] == STDERR_FILENO ? HLF_SE : HLF_SO; msg_ext_set_kind((int)(intptr_t)argv[2] == STDERR_FILENO ? "shell_err" : "shell_out"); - msg_ext_append = true; + msg_ext_set_append(true); msg_multiline(cbuf_as_string((char *)argv[0], (size_t)argv[1]), hl, false, false, &need_clear); xfree(argv[0]); ui_flush(); diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index cc4749a78a..d0fa821cfc 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -442,6 +442,8 @@ describe('API', function() exec_lua('vim.ui_attach(1, { ext_messages = true }, function() end)') api.nvim_exec2('hi VisualNC', { output = true }) eq('VisualNC xxx cleared', api.nvim_exec2('hi VisualNC', { output = true }).output) + api.nvim_exec2('echon 1234567', { output = true }) + eq('VisualNC xxx cleared', api.nvim_exec2('hi VisualNC', { output = true }).output) end) it('captures multi-chunk err nvim_echo() #36883', function()