diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-11-24 22:36:33 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-24 14:36:33 +0000 |
commit | 5c603064421b8829cf106c845902fcc41d3e31f2 (patch) | |
tree | 00c8d55c76c9ff447affb8d253ba6e6b9bd14d73 /src | |
parent | ef4f13d85c2612f8dd920f4290f607ec6fdb89cc (diff) | |
download | rneovim-5c603064421b8829cf106c845902fcc41d3e31f2.tar.gz rneovim-5c603064421b8829cf106c845902fcc41d3e31f2.tar.bz2 rneovim-5c603064421b8829cf106c845902fcc41d3e31f2.zip |
vim-patch:9.1.0883: message history cleanup is missing some tests (#31331)
Problem: message history cleanup is missing some tests
Solution: Add tests, refactor common code into did_set_msghistory()
(Shougo Matsushita)
closes: vim/vim#16078
https://github.com/vim/vim/commit/9f860a14c308f7a9a27a6850d36790615717a710
Co-authored-by: Shougo Matsushita <Shougo.Matsu@gmail.com>
Co-authored-by: Milly <milly.ca@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/message.c | 15 | ||||
-rw-r--r-- | src/nvim/option.c | 7 | ||||
-rw-r--r-- | src/nvim/options.lua | 2 |
3 files changed, 19 insertions, 5 deletions
diff --git a/src/nvim/message.c b/src/nvim/message.c index c758d5d76f..0b1156a6bd 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -982,11 +982,6 @@ static void add_msg_hist_multihl(const char *s, int len, int hl_id, bool multili return; } - // Don't let the message history get too big - while (msg_hist_len > p_mhi) { - delete_first_msg(); - } - // allocate an entry and add the message at the end of the history struct msg_hist *p = xmalloc(sizeof(struct msg_hist)); if (s) { @@ -1018,6 +1013,8 @@ static void add_msg_hist_multihl(const char *s, int len, int hl_id, bool multili first_msg_hist = last_msg_hist; } msg_hist_len++; + + check_msg_hist(); } /// Delete the first (oldest) message from the history. @@ -1041,6 +1038,14 @@ int delete_first_msg(void) return OK; } +void check_msg_hist(void) +{ + // Don't let the message history get too big + while (msg_hist_len > 0 && msg_hist_len > p_mhi) { + (void)delete_first_msg(); + } +} + /// :messages command implementation void ex_messages(exarg_T *eap) FUNC_ATTR_NONNULL_ALL diff --git a/src/nvim/option.c b/src/nvim/option.c index 669dac9773..fdc2d8da7d 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -2199,6 +2199,13 @@ static const char *did_set_modified(optset_T *args) return NULL; } +/// Process the updated 'msghistory' option value. +static const char *did_set_msghistory(optset_T *args FUNC_ATTR_UNUSED) +{ + check_msg_hist(); + return NULL; +} + /// Process the updated 'number' or 'relativenumber' option value. static const char *did_set_number_relativenumber(optset_T *args) { diff --git a/src/nvim/options.lua b/src/nvim/options.lua index 2d712ee101..bcb05b107b 100644 --- a/src/nvim/options.lua +++ b/src/nvim/options.lua @@ -5894,10 +5894,12 @@ return { }, { abbreviation = 'mhi', + cb = 'did_set_msghistory', defaults = { if_true = 500 }, desc = [=[ Determines how many entries are remembered in the |:messages| history. The maximum value is 10000. + Setting it to zero clears the message history. ]=], full_name = 'msghistory', scope = { 'global' }, |