diff options
author | bfredl <bjorn.linse@gmail.com> | 2023-09-25 12:26:01 +0200 |
---|---|---|
committer | bfredl <bjorn.linse@gmail.com> | 2023-09-25 14:54:20 +0200 |
commit | 68d425ac92599089047d98f1c533981ea917fed1 (patch) | |
tree | 784aa8d4a6b4436fcd7af8004d619f4702c27bac | |
parent | ccd1a84a9655279230be15630d4e5978c806c4e1 (diff) | |
download | rneovim-68d425ac92599089047d98f1c533981ea917fed1.tar.gz rneovim-68d425ac92599089047d98f1c533981ea917fed1.tar.bz2 rneovim-68d425ac92599089047d98f1c533981ea917fed1.zip |
refactor: remove 'shortmess' save/restore panic for ex commands
This was only used to avoid the effect of SHM_OVERALL. This can easily
be handled in isolation, instead of clearing out all of 'shortmess' which
has unwanted side effects and mystifies what really is going on.
-rw-r--r-- | src/nvim/ex_cmds.c | 2 | ||||
-rw-r--r-- | src/nvim/ex_cmds2.c | 18 | ||||
-rw-r--r-- | src/nvim/fileio.c | 4 | ||||
-rw-r--r-- | src/nvim/message.h | 2 | ||||
-rw-r--r-- | src/nvim/optionstr.c | 32 | ||||
-rw-r--r-- | test/old/testdir/test_autocmd.vim | 2 |
6 files changed, 12 insertions, 48 deletions
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 4f6b8f2c8f..dc7136196e 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -2689,7 +2689,7 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum // Obey the 'O' flag in 'cpoptions': overwrite any previous file // message. - if (shortmess(SHM_OVERALL) && !exiting && p_verbose == 0) { + if (shortmess(SHM_OVERALL) && !msg_listdo_overwrite && !exiting && p_verbose == 0) { msg_scroll = false; } if (!msg_scroll) { // wait a bit when overwriting an error msg diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index b37076c62e..86934a645a 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -455,6 +455,10 @@ void ex_listdo(exarg_T *eap) tabpage_T *tp; char *save_ei = NULL; + // Temporarily override SHM_OVER and SHM_OVERALL to avoid that file + // message overwrites output from the command. + msg_listdo_overwrite++; + if (eap->cmdidx != CMD_windo && eap->cmdidx != CMD_tabdo) { // Don't do syntax HL autocommands. Skipping the syntax file is a // great speed improvement. @@ -518,9 +522,7 @@ void ex_listdo(exarg_T *eap) if (qf_size == 0 || (size_t)eap->line1 > qf_size) { buf = NULL; } else { - save_clear_shm_value(); ex_cc(eap); - restore_shm_value(); buf = curbuf; i = (int)eap->line1 - 1; @@ -547,9 +549,7 @@ void ex_listdo(exarg_T *eap) if (curwin->w_arg_idx != i || !editing_arg_idx(curwin)) { // Clear 'shm' to avoid that the file message overwrites // any output from the command. - save_clear_shm_value(); do_argfile(eap, i); - restore_shm_value(); } if (curwin->w_arg_idx != i) { break; @@ -612,11 +612,8 @@ void ex_listdo(exarg_T *eap) break; } - // Go to the next buffer. Clear 'shm' to avoid that the file - // message overwrites any output from the command. - save_clear_shm_value(); + // Go to the next buffer. goto_buffer(eap, DOBUF_FIRST, FORWARD, next_fnum); - restore_shm_value(); // If autocommands took us elsewhere, quit here. if (curbuf->b_fnum != next_fnum) { @@ -633,11 +630,7 @@ void ex_listdo(exarg_T *eap) size_t qf_idx = qf_get_cur_idx(eap); - // Clear 'shm' to avoid that the file message overwrites - // any output from the command. - save_clear_shm_value(); ex_cnext(eap); - restore_shm_value(); // If jumping to the next quickfix entry fails, quit here. if (qf_get_cur_idx(eap) == qf_idx) { @@ -664,6 +657,7 @@ void ex_listdo(exarg_T *eap) listcmd_busy = false; } + msg_listdo_overwrite--; if (save_ei != NULL) { buf_T *bnext; aco_save_T aco; diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 5d7ddb657a..011c5439ea 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -105,7 +105,7 @@ void filemess(buf_T *buf, char *name, char *s, int attr) // For further ones overwrite the previous one, reset msg_scroll before // calling filemess(). msg_scroll_save = msg_scroll; - if (shortmess(SHM_OVERALL) && !exiting && p_verbose == 0) { + if (shortmess(SHM_OVERALL) && !msg_listdo_overwrite && !exiting && p_verbose == 0) { msg_scroll = false; } if (!msg_scroll) { // wait a bit when overwriting an error msg @@ -316,7 +316,7 @@ int readfile(char *fname, char *sfname, linenr_T from, linenr_T lines_to_skip, } } - if ((shortmess(SHM_OVER) || curbuf->b_help) && p_verbose == 0) { + if (((shortmess(SHM_OVER) && !msg_listdo_overwrite) || curbuf->b_help) && p_verbose == 0) { msg_scroll = false; // overwrite previous file message } else { msg_scroll = true; // don't overwrite previous file message diff --git a/src/nvim/message.h b/src/nvim/message.h index 191d3b8da7..78cd5b7d0e 100644 --- a/src/nvim/message.h +++ b/src/nvim/message.h @@ -68,6 +68,8 @@ EXTERN int msg_scrolled_at_flush INIT(= 0); EXTERN int msg_grid_scroll_discount INIT(= 0); +EXTERN int msg_listdo_overwrite INIT(= 0); + #ifdef INCLUDE_GENERATED_DECLARATIONS # include "message.h.generated.h" #endif diff --git a/src/nvim/optionstr.c b/src/nvim/optionstr.c index cf8e6cf641..2382219b55 100644 --- a/src/nvim/optionstr.c +++ b/src/nvim/optionstr.c @@ -69,8 +69,6 @@ static const char e_backupext_and_patchmode_are_equal[] = N_("E589: 'backupext' and 'patchmode' are equal"); static const char e_showbreak_contains_unprintable_or_wide_character[] = N_("E595: 'showbreak' contains unprintable or wide character"); -static const char e_internal_error_shortmess_too_long[] - = N_("E1336: Internal error: shortmess too long"); static char *(p_ambw_values[]) = { "single", "double", NULL }; static char *(p_bg_values[]) = { "light", "dark", NULL }; @@ -2269,36 +2267,6 @@ int check_ff_value(char *p) return check_opt_strings(p, p_ff_values, false); } -static char shm_buf[SHM_LEN]; -static int set_shm_recursive = 0; - -/// Save the actual shortmess Flags and clear them temporarily to avoid that -/// file messages overwrites any output from the following commands. -/// -/// Caller must make sure to first call save_clear_shm_value() and then -/// restore_shm_value() exactly the same number of times. -void save_clear_shm_value(void) -{ - if (strlen(p_shm) >= SHM_LEN) { - iemsg(e_internal_error_shortmess_too_long); - return; - } - - if (++set_shm_recursive == 1) { - STRCPY(shm_buf, p_shm); - set_option_value_give_err("shm", STATIC_CSTR_AS_OPTVAL(""), 0); - } -} - -/// Restore the shortmess Flags set from the save_clear_shm_value() function. -void restore_shm_value(void) -{ - if (--set_shm_recursive == 0) { - set_option_value_give_err("shm", CSTR_AS_OPTVAL(shm_buf), 0); - memset(shm_buf, 0, SHM_LEN); - } -} - static const char e_conflicts_with_value_of_listchars[] = N_("E834: Conflicts with value of 'listchars'"); static const char e_conflicts_with_value_of_fillchars[] diff --git a/test/old/testdir/test_autocmd.vim b/test/old/testdir/test_autocmd.vim index 453ac10c00..b3238e8214 100644 --- a/test/old/testdir/test_autocmd.vim +++ b/test/old/testdir/test_autocmd.vim @@ -3671,7 +3671,7 @@ endfunc func SetupVimTest_shm() let g:bwe = [] let g:brp = [] - set shortmess+=F + set shortmess-=l messages clear let dirname='XVimTestSHM' |