Patch 9.0.1064

3 views
Skip to first unread message

Bram Moolenaar

unread,
Dec 16, 2022, 11:42:07 AM12/16/22
to vim...@googlegroups.com

Patch 9.0.1064
Problem: Code for making 'shortmess' temporarily empty is repeated.
Solution: Add functions for making 'shortmess' empty and restoring it.
(Christian Brabandt, closes #11709)
Files: src/errors.h, src/ex_cmds2.c, src/option.h, src/optionstr.c,
src/proto/optionstr.pro, src/testdir/test_autocmd.vim


*** ../vim-9.0.1063/src/errors.h 2022-12-14 20:54:52.407699483 +0000
--- src/errors.h 2022-12-16 15:50:37.005032151 +0000
***************
*** 3389,3391 ****
--- 3389,3393 ----
EXTERN char e_object_member_is_not_writable_str[]
INIT(= N_("E1335: Object member is not writable: %s"));
#endif
+ EXTERN char e_internal_error_shortmess_too_long[]
+ INIT(= N_("E1336: Internal error: shortmess too long"));
*** ../vim-9.0.1063/src/ex_cmds2.c 2022-11-28 18:51:38.963571609 +0000
--- src/ex_cmds2.c 2022-12-16 15:53:53.569061185 +0000
***************
*** 460,466 ****
#if defined(FEAT_SYN_HL)
char_u *save_ei = NULL;
#endif
- char_u *p_shm_save;
#ifdef FEAT_QUICKFIX
int qf_size = 0;
int qf_idx;
--- 460,465 ----
***************
*** 541,547 ****
--- 540,548 ----
buf = NULL;
else
{
+ save_clear_shm_value();
ex_cc(eap);
+ restore_shm_value();

buf = curbuf;
i = eap->line1 - 1;
***************
*** 568,580 ****
{
// Clear 'shm' to avoid that the file message overwrites
// any output from the command.
! p_shm_save = vim_strsave(p_shm);
! set_option_value_give_err((char_u *)"shm",
! 0L, (char_u *)"", 0);
do_argfile(eap, i);
! set_option_value_give_err((char_u *)"shm",
! 0L, p_shm_save, 0);
! vim_free(p_shm_save);
}
if (curwin->w_arg_idx != i)
break;
--- 569,577 ----
{
// 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;
***************
*** 630,640 ****

// Go to the next buffer. Clear 'shm' to avoid that the file
// message overwrites any output from the command.
! p_shm_save = vim_strsave(p_shm);
! set_option_value_give_err((char_u *)"shm", 0L, (char_u *)"", 0);
goto_buffer(eap, DOBUF_FIRST, FORWARD, next_fnum);
! set_option_value_give_err((char_u *)"shm", 0L, p_shm_save, 0);
! vim_free(p_shm_save);

// If autocommands took us elsewhere, quit here.
if (curbuf->b_fnum != next_fnum)
--- 627,635 ----

// Go to the next buffer. Clear 'shm' to avoid that the file
// message overwrites any output from the command.
! save_clear_shm_value();
goto_buffer(eap, DOBUF_FIRST, FORWARD, next_fnum);
! restore_shm_value();

// If autocommands took us elsewhere, quit here.
if (curbuf->b_fnum != next_fnum)
***************
*** 650,662 ****

qf_idx = qf_get_cur_idx(eap);

! // Clear 'shm' to avoid that the file message overwrites
! // 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);
! set_option_value_give_err((char_u *)"shm", 0L, p_shm_save, 0);
! vim_free(p_shm_save);

// If jumping to the next quickfix entry fails, quit here
if (qf_get_cur_idx(eap) == qf_idx)
--- 645,653 ----

qf_idx = qf_get_cur_idx(eap);

! 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)
*** ../vim-9.0.1063/src/option.h 2022-12-15 13:14:17.411527402 +0000
--- src/option.h 2022-12-16 15:54:14.249061438 +0000
***************
*** 271,276 ****
--- 271,278 ----
#define SHM_SEARCHCOUNT 'S' // search stats: '[1/10]'
#define SHM_POSIX "AS" // POSIX value
#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:
#define GO_TERMINAL '!' // use terminal for system commands
*** ../vim-9.0.1063/src/optionstr.c 2022-12-15 13:14:17.411527402 +0000
--- src/optionstr.c 2022-12-16 16:41:00.716704236 +0000
***************
*** 13,18 ****
--- 13,21 ----

#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_bg_values[]) = {"light", "dark", NULL};
static char *(p_bkc_values[]) = {"yes", "auto", "no", "breaksymlink", "breakhardlink", NULL};
***************
*** 2697,2699 ****
--- 2700,2739 ----
{
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);
+ }
+ }
*** ../vim-9.0.1063/src/proto/optionstr.pro 2022-11-28 11:36:46.295659899 +0000
--- src/proto/optionstr.pro 2022-12-16 15:55:02.689060282 +0000
***************
*** 11,14 ****
--- 11,16 ----
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);
int check_ff_value(char_u *p);
+ void save_clear_shm_value(void);
+ void restore_shm_value(void);
/* vim: set ft=c : */
*** ../vim-9.0.1063/src/testdir/test_autocmd.vim 2022-12-09 12:21:46.473444271 +0000
--- src/testdir/test_autocmd.vim 2022-12-16 15:56:25.145053200 +0000
***************
*** 4161,4165 ****
--- 4161,4220 ----
%bwipe!
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-9.0.1063/src/version.c 2022-12-16 13:08:32.742359073 +0000
--- src/version.c 2022-12-16 15:49:55.681018812 +0000
***************
*** 697,698 ****
--- 697,700 ----
{ /* Add new patch number below this line */
+ /**/
+ 1064,
/**/

--
Why doesn't Tarzan have a beard?

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages