aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/ex_cmds.lua2
-rw-r--r--src/nvim/message.c41
-rw-r--r--src/nvim/testdir/test_alot.vim1
-rw-r--r--src/nvim/testdir/test_messages.vim42
-rw-r--r--src/nvim/version.c2
5 files changed, 82 insertions, 6 deletions
diff --git a/src/nvim/ex_cmds.lua b/src/nvim/ex_cmds.lua
index 95ede4bdc5..98530c04df 100644
--- a/src/nvim/ex_cmds.lua
+++ b/src/nvim/ex_cmds.lua
@@ -1604,7 +1604,7 @@ return {
},
{
command='messages',
- flags=bit.bor(TRLBAR, CMDWIN),
+ flags=bit.bor(EXTRA, TRLBAR, RANGE, CMDWIN),
addr_type=ADDR_LINES,
func='ex_messages',
},
diff --git a/src/nvim/message.c b/src/nvim/message.c
index f9cfc49197..3163a797ed 100644
--- a/src/nvim/message.c
+++ b/src/nvim/message.c
@@ -720,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;
+ }
+
+ 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--) {
+ }
+ }
- for (p = first_msg_hist; p != NULL && !got_int; p = p->next)
- if (p->msg != NULL)
+ // 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;
}
/*
diff --git a/src/nvim/testdir/test_alot.vim b/src/nvim/testdir/test_alot.vim
index 4e8cd54ce3..5a71b4fdd1 100644
--- a/src/nvim/testdir/test_alot.vim
+++ b/src/nvim/testdir/test_alot.vim
@@ -9,6 +9,7 @@ source test_expr.vim
source test_expr_utf8.vim
source test_feedkeys.vim
source test_menu.vim
+source test_messages.vim
source test_options.vim
source test_popup.vim
source test_regexp_utf8.vim
diff --git a/src/nvim/testdir/test_messages.vim b/src/nvim/testdir/test_messages.vim
new file mode 100644
index 0000000000..4d7e41130c
--- /dev/null
+++ b/src/nvim/testdir/test_messages.vim
@@ -0,0 +1,42 @@
+" Tests for :messages
+
+function Test_messages()
+ let oldmore = &more
+ try
+ set nomore
+
+ let arr = map(range(10), '"hello" . v:val')
+ for s in arr
+ echomsg s | redraw
+ endfor
+ let result = ''
+
+ redir => result
+ 2messages | redraw
+ redir END
+
+ " get last two messages
+ let msg = split(result, "\n")[1:][-2:]
+ call assert_equal(["hello8", "hello9"], msg)
+
+ " clear messages without last one
+ 1messages clear
+ redir => result
+ redraw | 1messages
+ redir END
+ " get last last message
+ let msg = split(result, "\n")[1:][-1:]
+ call assert_equal(['hello9'], msg)
+
+ " clear all messages
+ messages clear
+ redir => result
+ redraw | 1messages
+ redir END
+ " get last last message
+ let msg = split(result, "\n")[1:][-1:]
+ call assert_equal([], msg)
+ finally
+ let &more = oldmore
+ endtry
+endfunction
diff --git a/src/nvim/version.c b/src/nvim/version.c
index 82a6f5f9a9..d64e68f66a 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -709,7 +709,7 @@ static int included_patches[] = {
// 1738,
// 1737 NA
// 1736 NA
- // 1735,
+ 1735,
1734,
// 1733 NA
1732,