0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 9.0.1064: code for making 'shortmess' temporarily empty is repeated

Problem:    Code for making 'shortmess' temporarily empty is repeated.
Solution:   Add functions for making 'shortmess' empty and restoring it.
            (Christian Brabandt, closes #11709)
This commit is contained in:
Christian Brabandt
2022-12-16 16:41:23 +00:00
committed by Bram Moolenaar
parent 4ab1f4a32f
commit 9aee8ec400
7 changed files with 111 additions and 17 deletions

View File

@@ -3389,3 +3389,5 @@ EXTERN char e_object_member_not_found_str[]
EXTERN char e_object_member_is_not_writable_str[] EXTERN char e_object_member_is_not_writable_str[]
INIT(= N_("E1335: Object member is not writable: %s")); INIT(= N_("E1335: Object member is not writable: %s"));
#endif #endif
EXTERN char e_internal_error_shortmess_too_long[]
INIT(= N_("E1336: Internal error: shortmess too long"));

View File

@@ -460,7 +460,6 @@ ex_listdo(exarg_T *eap)
#if defined(FEAT_SYN_HL) #if defined(FEAT_SYN_HL)
char_u *save_ei = NULL; char_u *save_ei = NULL;
#endif #endif
char_u *p_shm_save;
#ifdef FEAT_QUICKFIX #ifdef FEAT_QUICKFIX
int qf_size = 0; int qf_size = 0;
int qf_idx; int qf_idx;
@@ -541,7 +540,9 @@ ex_listdo(exarg_T *eap)
buf = NULL; buf = NULL;
else else
{ {
save_clear_shm_value();
ex_cc(eap); ex_cc(eap);
restore_shm_value();
buf = curbuf; buf = curbuf;
i = eap->line1 - 1; i = eap->line1 - 1;
@@ -568,13 +569,9 @@ ex_listdo(exarg_T *eap)
{ {
// Clear 'shm' to avoid that the file message overwrites // Clear 'shm' to avoid that the file message overwrites
// any output from the command. // any output from the command.
p_shm_save = vim_strsave(p_shm); save_clear_shm_value();
set_option_value_give_err((char_u *)"shm",
0L, (char_u *)"", 0);
do_argfile(eap, i); do_argfile(eap, i);
set_option_value_give_err((char_u *)"shm", restore_shm_value();
0L, p_shm_save, 0);
vim_free(p_shm_save);
} }
if (curwin->w_arg_idx != i) if (curwin->w_arg_idx != i)
break; break;
@@ -630,11 +627,9 @@ ex_listdo(exarg_T *eap)
// Go to the next buffer. Clear 'shm' to avoid that the file // Go to the next buffer. Clear 'shm' to avoid that the file
// message overwrites any output from the command. // message overwrites any output from the command.
p_shm_save = vim_strsave(p_shm); save_clear_shm_value();
set_option_value_give_err((char_u *)"shm", 0L, (char_u *)"", 0);
goto_buffer(eap, DOBUF_FIRST, FORWARD, next_fnum); goto_buffer(eap, DOBUF_FIRST, FORWARD, next_fnum);
set_option_value_give_err((char_u *)"shm", 0L, p_shm_save, 0); restore_shm_value();
vim_free(p_shm_save);
// If autocommands took us elsewhere, quit here. // If autocommands took us elsewhere, quit here.
if (curbuf->b_fnum != next_fnum) if (curbuf->b_fnum != next_fnum)
@@ -650,13 +645,9 @@ ex_listdo(exarg_T *eap)
qf_idx = qf_get_cur_idx(eap); qf_idx = qf_get_cur_idx(eap);
// Clear 'shm' to avoid that the file message overwrites save_clear_shm_value();
// any output from the command.
p_shm_save = vim_strsave(p_shm);
set_option_value_give_err((char_u *)"shm", 0L, (char_u *)"", 0);
ex_cnext(eap); ex_cnext(eap);
set_option_value_give_err((char_u *)"shm", 0L, p_shm_save, 0); restore_shm_value();
vim_free(p_shm_save);
// If jumping to the next quickfix entry fails, quit here // If jumping to the next quickfix entry fails, quit here
if (qf_get_cur_idx(eap) == qf_idx) if (qf_get_cur_idx(eap) == qf_idx)

View File

@@ -271,6 +271,8 @@ typedef enum {
#define SHM_SEARCHCOUNT 'S' // search stats: '[1/10]' #define SHM_SEARCHCOUNT 'S' // search stats: '[1/10]'
#define SHM_POSIX "AS" // POSIX value #define SHM_POSIX "AS" // POSIX value
#define SHM_ALL "rmfixlnwaWtToOsAIcCqFS" // all possible flags for 'shm' #define SHM_ALL "rmfixlnwaWtToOsAIcCqFS" // all possible flags for 'shm'
#define SHM_LEN 30 // max length of all flags together
// plus a NUL character
// characters for p_go: // characters for p_go:
#define GO_TERMINAL '!' // use terminal for system commands #define GO_TERMINAL '!' // use terminal for system commands

View File

@@ -13,6 +13,9 @@
#include "vim.h" #include "vim.h"
static char_u shm_buf[SHM_LEN];
static int set_shm_recursive = 0;
static char *(p_ambw_values[]) = {"single", "double", NULL}; static char *(p_ambw_values[]) = {"single", "double", NULL};
static char *(p_bg_values[]) = {"light", "dark", NULL}; static char *(p_bg_values[]) = {"light", "dark", NULL};
static char *(p_bkc_values[]) = {"yes", "auto", "no", "breaksymlink", "breakhardlink", NULL}; static char *(p_bkc_values[]) = {"yes", "auto", "no", "breaksymlink", "breakhardlink", NULL};
@@ -2697,3 +2700,40 @@ check_ff_value(char_u *p)
{ {
return check_opt_strings(p, p_ff_values, FALSE); return check_opt_strings(p, p_ff_values, FALSE);
} }
/*
* Save the acutal 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()
{
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((char_u *)"shm", 0L, (char_u *)"", 0);
}
}
/*
* Restore the shortmess Flags set from the save_clear_shm_value() function.
*/
void
restore_shm_value()
{
if (--set_shm_recursive == 0)
{
set_option_value_give_err((char_u *)"shm", 0L, shm_buf, 0);
vim_memset(shm_buf, 0, SHM_LEN);
}
}

View File

@@ -11,4 +11,6 @@ void set_string_option_direct_in_buf(buf_T *buf, char_u *name, int opt_idx, char
char *set_string_option(int opt_idx, char_u *value, int opt_flags); char *set_string_option(int opt_idx, char_u *value, int opt_flags);
char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, char *errbuf, int opt_flags, int *value_checked); char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, char *errbuf, int opt_flags, int *value_checked);
int check_ff_value(char_u *p); int check_ff_value(char_u *p);
void save_clear_shm_value(void);
void restore_shm_value(void);
/* vim: set ft=c : */ /* vim: set ft=c : */

View File

@@ -4161,5 +4161,60 @@ func Test_autocmd_nested_setbufvar()
%bwipe! %bwipe!
endfunc endfunc
func SetupVimTest_shm()
let g:bwe = []
let g:brp = []
set shortmess+=F
let dirname='XVimTestSHM'
call mkdir(dirname, 'R')
call writefile(['test'], dirname .. '/1')
call writefile(['test'], dirname .. '/2')
call writefile(['test'], dirname .. '/3')
augroup test
autocmd!
autocmd BufWinEnter * call add(g:bwe, $'BufWinEnter: {expand('<amatch>')}')
autocmd BufReadPost * call add(g:brp, $'BufReadPost: {expand('<amatch>')}')
augroup END
call setqflist([
\ {'filename': dirname .. '/1', 'lnum': 1, 'col': 1, 'text': 'test', 'vcol': 0},
\ {'filename': dirname .. '/2', 'lnum': 1, 'col': 1, 'text': 'test', 'vcol': 0},
\ {'filename': dirname .. '/3', 'lnum': 1, 'col': 1, 'text': 'test', 'vcol': 0}
\ ])
cdo! substitute/test/TEST
" clean up
noa enew!
set shortmess&vim
augroup test
autocmd!
augroup END
augroup! test
endfunc
func Test_autocmd_shortmess()
CheckNotMSWindows
call SetupVimTest_shm()
let output = execute(':mess')->split('\n')
let info = copy(output)->filter({idx, val -> val =~# '\d of 3'} )
let bytes = copy(output)->filter({idx, val -> val =~# 'bytes'} )
" We test the following here:
" BufReadPost should have been triggered 3 times, once per file
" BufWinEnter should have been triggered 3 times, once per file
" FileInfoMessage should have been shown 3 times, regardless of shm option
" "(x of 3)" message from :cnext has been shown 3 times
call assert_equal(3, g:brp->len())
call assert_equal(3, g:bwe->len())
call assert_equal(3, info->len())
call assert_equal(3, bytes->len())
delfunc SetupVimTest_shm
endfunc
" vim: shiftwidth=2 sts=2 expandtab " vim: shiftwidth=2 sts=2 expandtab

View File

@@ -695,6 +695,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1064,
/**/ /**/
1063, 1063,
/**/ /**/