Merge pull request #25359 from bfredl/longmess

refactor: remove 'shortmess' save/restore panic for ex commands
This commit is contained in:
bfredl 2023-09-25 18:16:25 +02:00 committed by GitHub
commit ed8b7aae85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 12 additions and 48 deletions

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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[]

View File

@ -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'