mirror of
https://github.com/neovim/neovim
synced 2025-07-16 01:01:49 +00:00
fix(messages): capture execute("messages") with ext_messages (#34342)
Problem: "msg_history_show" event is emitted when `msg_silent > 0`. E.g. when capturing its output with `execute()`, which also doesn't work with ext_messages. Solution: Don't emit the "msg_history_show" event when `msg_silent > 0`. Call regular messaging functions when `redirecting()`, to execute `redir_write()` while ensuring the message itself is not emitted.
This commit is contained in:
@ -1187,10 +1187,12 @@ void ex_messages(exarg_T *eap)
|
||||
Array entries = ARRAY_DICT_INIT;
|
||||
MessageHistoryEntry *p = eap->skip ? msg_hist_temp : msg_hist_first;
|
||||
int skip = eap->addr_count ? (msg_hist_len - eap->line2) : 0;
|
||||
while (p != NULL) {
|
||||
for (; p != NULL; p = p->next) {
|
||||
// Skip over count or temporary "g<" messages.
|
||||
if ((p->temp && !eap->skip) || skip-- > 0) {
|
||||
// Skipping over count or temporary "g<" messages.
|
||||
} else if (ui_has(kUIMessages)) {
|
||||
continue;
|
||||
}
|
||||
if (ui_has(kUIMessages) && !msg_silent) {
|
||||
Array entry = ARRAY_DICT_INIT;
|
||||
ADD(entry, CSTR_TO_OBJ(p->kind));
|
||||
Array content = ARRAY_DICT_INIT;
|
||||
@ -1204,10 +1206,12 @@ void ex_messages(exarg_T *eap)
|
||||
}
|
||||
ADD(entry, ARRAY_OBJ(content));
|
||||
ADD(entries, ARRAY_OBJ(entry));
|
||||
} else {
|
||||
msg_multihl(p->msg, p->kind, false, false);
|
||||
}
|
||||
p = p->next;
|
||||
if (redirecting() || !ui_has(kUIMessages)) {
|
||||
msg_silent += ui_has(kUIMessages);
|
||||
msg_multihl(p->msg, p->kind, false, false);
|
||||
msg_silent -= ui_has(kUIMessages);
|
||||
}
|
||||
}
|
||||
if (kv_size(entries) > 0) {
|
||||
ui_call_msg_history_show(entries);
|
||||
|
@ -1722,6 +1722,32 @@ stack traceback:
|
||||
},
|
||||
})
|
||||
end)
|
||||
|
||||
it('can capture execute("messages"))', function()
|
||||
feed('Q')
|
||||
screen:expect({
|
||||
grid = [[
|
||||
^ |
|
||||
{1:~ }|*4
|
||||
]],
|
||||
messages = {
|
||||
{
|
||||
content = { { "E354: Invalid register name: '^@'", 9, 6 } },
|
||||
history = true,
|
||||
kind = 'emsg',
|
||||
},
|
||||
},
|
||||
})
|
||||
feed(':let msg = execute("messages")<CR>')
|
||||
screen:expect({
|
||||
grid = [[
|
||||
^ |
|
||||
{1:~ }|*4
|
||||
]],
|
||||
cmdline = { { abort = false } },
|
||||
})
|
||||
eq("E354: Invalid register name: '^@'", eval('msg'):gsub('\n', ''))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('ui/builtin messages', function()
|
||||
|
Reference in New Issue
Block a user