diff options
Diffstat (limited to 'src/nvim/message.c')
-rw-r--r-- | src/nvim/message.c | 60 |
1 files changed, 56 insertions, 4 deletions
diff --git a/src/nvim/message.c b/src/nvim/message.c index 1de2347b12..3163a797ed 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -19,6 +19,7 @@ #include "nvim/fileio.h" #include "nvim/func_attr.h" #include "nvim/getchar.h" +#include "nvim/main.h" #include "nvim/mbyte.h" #include "nvim/memory.h" #include "nvim/misc1.h" @@ -581,6 +582,24 @@ bool emsgf(const char *const fmt, ...) return emsg(IObuff); } +static void msg_emsgf_event(void **argv) +{ + char *s = argv[0]; + (void)emsg((char_u *)s); + xfree(s); +} + +void msg_schedule_emsgf(const char *const fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + vim_vsnprintf((char *)IObuff, IOSIZE, fmt, ap, NULL); + va_end(ap); + + char *s = xstrdup((char *)IObuff); + loop_schedule(&main_loop, event_create(1, msg_emsgf_event, 1, s)); +} + /* * Like msg(), but truncate to a single line if p_shm contains 't', or when * "force" is TRUE. This truncates in another way as for normal messages. @@ -701,14 +720,47 @@ int delete_first_msg(void) void ex_messages(exarg_T *eap) { struct msg_hist *p; + int c = 0; - msg_hist_off = TRUE; + if (STRCMP(eap->arg, "clear") == 0) { + int keep = eap->addr_count == 0 ? 0 : eap->line2; + + while (msg_hist_len > keep) { + (void)delete_first_msg(); + } + return; + } - for (p = first_msg_hist; p != NULL && !got_int; p = p->next) - if (p->msg != NULL) + if (*eap->arg != NUL) { + EMSG(_(e_invarg)); + return; + } + + msg_hist_off = true; + + p = first_msg_hist; + + if (eap->addr_count != 0) { + // Count total messages + for (; p != NULL && !got_int; p = p->next) { + c++; + } + + c -= eap->line2; + + // Skip without number of messages specified + for (p = first_msg_hist; p != NULL && !got_int && c > 0; p = p->next, c--) { + } + } + + // Display what was not skipped. + for (; p != NULL && !got_int; p = p->next) { + if (p->msg != NULL) { msg_attr(p->msg, p->attr); + } + } - msg_hist_off = FALSE; + msg_hist_off = false; } /* |