mirror of
https://github.com/neovim/neovim.git
synced 2026-04-01 05:12:02 +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;
|
Array entries = ARRAY_DICT_INIT;
|
||||||
MessageHistoryEntry *p = eap->skip ? msg_hist_temp : msg_hist_first;
|
MessageHistoryEntry *p = eap->skip ? msg_hist_temp : msg_hist_first;
|
||||||
int skip = eap->addr_count ? (msg_hist_len - eap->line2) : 0;
|
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) {
|
if ((p->temp && !eap->skip) || skip-- > 0) {
|
||||||
// Skipping over count or temporary "g<" messages.
|
continue;
|
||||||
} else if (ui_has(kUIMessages)) {
|
}
|
||||||
|
if (ui_has(kUIMessages) && !msg_silent) {
|
||||||
Array entry = ARRAY_DICT_INIT;
|
Array entry = ARRAY_DICT_INIT;
|
||||||
ADD(entry, CSTR_TO_OBJ(p->kind));
|
ADD(entry, CSTR_TO_OBJ(p->kind));
|
||||||
Array content = ARRAY_DICT_INIT;
|
Array content = ARRAY_DICT_INIT;
|
||||||
@@ -1204,10 +1206,12 @@ void ex_messages(exarg_T *eap)
|
|||||||
}
|
}
|
||||||
ADD(entry, ARRAY_OBJ(content));
|
ADD(entry, ARRAY_OBJ(content));
|
||||||
ADD(entries, ARRAY_OBJ(entry));
|
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) {
|
if (kv_size(entries) > 0) {
|
||||||
ui_call_msg_history_show(entries);
|
ui_call_msg_history_show(entries);
|
||||||
|
|||||||
@@ -1722,6 +1722,32 @@ stack traceback:
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
end)
|
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)
|
end)
|
||||||
|
|
||||||
describe('ui/builtin messages', function()
|
describe('ui/builtin messages', function()
|
||||||
|
|||||||
Reference in New Issue
Block a user