]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0572: cannot specify tab page closing behaviour v9.1.0572
authorLemonBoy <thatlemon@gmail.com>
Fri, 12 Jul 2024 17:30:58 +0000 (19:30 +0200)
committerChristian Brabandt <cb@256bit.org>
Fri, 12 Jul 2024 17:36:53 +0000 (19:36 +0200)
Problem:  cannot specify tab page closing behaviour
          (Gianluca Pacchiella)
Solution: Add the 'tabclose' option (LemonBoy).

fixes: #5967
closes: #15204

Signed-off-by: LemonBoy <thatlemon@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
17 files changed:
runtime/doc/options.txt
runtime/doc/quickref.txt
runtime/doc/tabpage.txt
runtime/doc/tags
runtime/doc/version9.txt
runtime/optwin.vim
runtime/syntax/vim.vim
src/option.h
src/optiondefs.h
src/optionstr.c
src/proto/option.pro
src/proto/optionstr.pro
src/testdir/gen_opt_test.vim
src/testdir/test_options.vim
src/testdir/test_tabpage.vim
src/version.c
src/window.c

index 2dc08e2573891708729467c0a74e9c2c514fceaa..5f1a2a074f74a2b199708c477bfba774af413f41 100644 (file)
@@ -8100,6 +8100,19 @@ A jump table for the options with a short description can be found at |Q_op|.
        'S' flag in 'cpoptions'.
        Only normal file name characters can be used, "/\*?[|<>" are illegal.
 
+                                               *'tabclose'* *'tcl'*
+'tabclose' 'tcl'       string  (default "")
+                       global
+       This option controls the behavior when closing tab pages (e.g., using
+       |:tabclose|).  When empty Vim goes to the next (right) tab page.
+
+       Possible values (comma-separated list):
+          left         If included, go to the previous tab page instead of
+                       the next one.
+          uselast      If included, go to the previously used tab page if
+                       possible.  This option takes precedence over the
+                       others.
+
                                                *'tabline'* *'tal'*
 'tabline' 'tal'                string  (default empty)
                        global
index 517fa30426c1591d9d3e38fabe1362d3e7629a69..42b5228a8f8a395d5f2de189de8898bf8573e01b 100644 (file)
@@ -935,6 +935,7 @@ Short explanation of each option:           *option-list*
 'switchbuf'      'swb'     sets behavior when switching to another buffer
 'synmaxcol'      'smc'     maximum column to find syntax items
 'syntax'         'syn'     syntax to be loaded for current buffer
+'tabclose'       'tcl'     which tab page to focus when closing a tab
 'tabline'        'tal'     custom format for the console tab pages line
 'tabpagemax'     'tpm'     maximum number of tab pages for |-p| and "tab all"
 'tabstop'        'ts'      number of spaces that <Tab> in file uses
index abbc77803029f3c93921d326cf87e6df4885ff04..afc2512509e9392ee8fea729e4caccd9b839bac9 100644 (file)
@@ -1,4 +1,4 @@
-*tabpage.txt*   For Vim version 9.1.  Last change: 2024 May 15
+*tabpage.txt*   For Vim version 9.1.  Last change: 2024 Jul 12
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -142,7 +142,8 @@ something else.
                    :tabclose $     " close the last tab page
                    :tabclose #     " close the last accessed tab page
 
-When a tab is closed the next tab page will become the current one.
+When a tab is closed the next tab page will become the current one. This
+behaviour can be customized using the 'tabclose' option.
 
                                                        *:tabo* *:tabonly*
 :tabo[nly][!]  Close all other tab pages.
index b3761e88e2f6160d0475f8497fa6df1676bf17c2..00c216c84740af4bfd693e3dbe45f9ba7913f242 100644 (file)
@@ -1161,6 +1161,7 @@ $quote    eval.txt        /*$quote*
 't_xo' term.txt        /*'t_xo'*
 't_xs' term.txt        /*'t_xs'*
 'ta'   options.txt     /*'ta'*
+'tabclose'     options.txt     /*'tabclose'*
 'tabline'      options.txt     /*'tabline'*
 'tabpagemax'   options.txt     /*'tabpagemax'*
 'tabstop'      options.txt     /*'tabstop'*
@@ -1179,6 +1180,7 @@ $quote    eval.txt        /*$quote*
 'tbis' options.txt     /*'tbis'*
 'tbs'  options.txt     /*'tbs'*
 'tc'   options.txt     /*'tc'*
+'tcl'  options.txt     /*'tcl'*
 'tcldll'       options.txt     /*'tcldll'*
 'tenc' options.txt     /*'tenc'*
 'term' options.txt     /*'term'*
index 7a2cbe416403cb67e63de122ad6cd16edf58b04c..3b719eb9c7c9710346cb9e7a51692483186d77b8 100644 (file)
@@ -1,4 +1,4 @@
-*version9.txt*  For Vim version 9.1.  Last change: 2024 Jul 11
+*version9.txt*  For Vim version 9.1.  Last change: 2024 Jul 12
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -41632,6 +41632,7 @@ Commands: ~
 Options: ~
 
 'winfixbuf'            Keep buffer focused in a window
+'tabclose'             Which tab page to focus after closing a tab page
 't_xo'                 Terminal uses XON/XOFF handshaking (e.g. vt420)
 't_CF'                 Support for alternate font highlighting terminal code
 
index f218ffba20667d342727e669f54a8dcc0593d28a..8306ed39f5a79935b311765d9b3a5cdcccd3a461 100644 (file)
@@ -1,7 +1,7 @@
 " These commands create the option window.
 "
 " Maintainer:  The Vim Project <https://github.com/vim/vim>
-" Last Change: 2024 Jun 05
+" Last Change: 2024 Jul 12
 " Former Maintainer:   Bram Moolenaar <Bram@vim.org>
 
 " If there already is an option window, jump to that one.
@@ -556,6 +556,8 @@ endif
 call <SID>Header(gettext("multiple tab pages"))
 call <SID>AddOption("showtabline", gettext("0, 1 or 2; when to use a tab pages line"))
 call append("$", " \tset stal=" . &stal)
+call <SID>AddOption("tabclose", gettext("behaviour when closing tab pages: left, uselast or empty"))
+call append("$", " \tset tcl=" . &tcl)
 call <SID>AddOption("tabpagemax", gettext("maximum number of tab pages to open for -p and \"tab all\""))
 call append("$", " \tset tpm=" . &tpm)
 call <SID>AddOption("tabline", gettext("custom tab pages line"))
index b10531e961a1ff24231dfd83ff87b26496eaeb5a..db173815c5c27ea27097ab7a7d7d4ce93a934bb9 100644 (file)
@@ -3,7 +3,7 @@
 " Maintainer:     Hirohito Higashi <h.east.727 ATMARK gmail.com>
 "         Doug Kearns <dougkearns@gmail.com>
 " URL:    https://github.com/vim-jp/syntax-vim-ex
-" Last Change:    2024 Jul 11
+" Last Change:    2024 Jul 12
 " Former Maintainer: Charles E. Campbell
 
 " DO NOT CHANGE DIRECTLY.
@@ -48,8 +48,8 @@ syn keyword vimOption contained ft filetype fcs fillchars fixeol fixendofline fc
 syn keyword vimOption contained imst imstyle inc include inex includeexpr is incsearch inde indentexpr indk indentkeys inf infercase im insertmode isf isfname isi isident isk iskeyword isp isprint js joinspaces jop jumpoptions key kmp keymap km keymodel kpc keyprotocol kp keywordprg lmap langmap lm langmenu lnr langnoremap lrm langremap ls laststatus lz lazyredraw lbr linebreak lines lsp linespace lisp lop lispoptions lw lispwords list lcs listchars lpl loadplugins luadll magic mef makeef menc makeencoding mp makeprg mps matchpairs mat matchtime mco maxcombine mfd maxfuncdepth mmd maxmapdepth mm maxmem mmp maxmempattern mmt maxmemtot mis menuitems msm mkspellmem ml modeline mle modelineexpr mls modelines ma modifiable mod modified more mouse mousef mousefocus
 syn keyword vimOption contained mh mousehide mousem mousemodel mousemev mousemoveevent mouses mouseshape mouset mousetime mzq mzquantum mzschemedll mzschemegcdll nf nrformats nu number nuw numberwidth ofu omnifunc odev opendevice opfunc operatorfunc pp packpath para paragraphs paste pt pastetoggle pex patchexpr pm patchmode pa path perldll pi preserveindent pvh previewheight pvp previewpopup pvw previewwindow pdev printdevice penc printencoding pexpr printexpr pfn printfont pheader printheader pmbcs printmbcharset pmbfn printmbfont popt printoptions prompt ph pumheight pw pumwidth pythondll pythonhome pythonthreedll pythonthreehome pyx pyxversion qftf quickfixtextfunc qe quoteescape ro readonly rdt redrawtime re regexpengine rnu relativenumber remap rop renderoptions
 syn keyword vimOption contained report rs restorescreen ri revins rl rightleft rlc rightleftcmd rubydll ru ruler ruf rulerformat rtp runtimepath scr scroll scb scrollbind scf scrollfocus sj scrolljump so scrolloff sbo scrollopt sect sections secure sel selection slm selectmode ssop sessionoptions sh shell shcf shellcmdflag sp shellpipe shq shellquote srr shellredir ssl shellslash stmp shelltemp st shelltype sxe shellxescape sxq shellxquote sr shiftround sw shiftwidth shm shortmess sn shortname sbr showbreak sc showcmd sloc showcmdloc sft showfulltag sm showmatch smd showmode stal showtabline ss sidescroll siso sidescrolloff scl signcolumn scs smartcase si smartindent sta smarttab sms smoothscroll sts softtabstop spell spc spellcapcheck spf spellfile spl spelllang
-syn keyword vimOption contained spo spelloptions sps spellsuggest sb splitbelow spk splitkeep spr splitright sol startofline stl statusline su suffixes sua suffixesadd swf swapfile sws swapsync swb switchbuf smc synmaxcol syn syntax tal tabline tpm tabpagemax ts tabstop tbs tagbsearch tc tagcase tfu tagfunc tl taglength tr tagrelative tag tags tgst tagstack tcldll term tbidi termbidi tenc termencoding tgc termguicolors twk termwinkey twsl termwinscroll tws termwinsize twt termwintype terse ta textauto tx textmode tw textwidth tsr thesaurus tsrfu thesaurusfunc top tildeop to timeout tm timeoutlen title titlelen titleold titlestring tb toolbar tbis toolbariconsize ttimeout ttm ttimeoutlen tbi ttybuiltin tf ttyfast ttym ttymouse tsl ttyscroll tty ttytype udir undodir
-syn keyword vimOption contained udf undofile ul undolevels ur undoreload uc updatecount ut updatetime vsts varsofttabstop vts vartabstop vbs verbose vfile verbosefile vdir viewdir vop viewoptions vi viminfo vif viminfofile ve virtualedit vb visualbell warn wiv weirdinvert ww whichwrap wc wildchar wcm wildcharm wig wildignore wic wildignorecase wmnu wildmenu wim wildmode wop wildoptions wak winaltkeys wcr wincolor wi window wfb winfixbuf wfh winfixheight wfw winfixwidth wh winheight wmh winminheight wmw winminwidth winptydll wiw winwidth wrap wm wrapmargin ws wrapscan write wa writeany wb writebackup wd writedelay xtermcodes
+syn keyword vimOption contained spo spelloptions sps spellsuggest sb splitbelow spk splitkeep spr splitright sol startofline stl statusline su suffixes sua suffixesadd swf swapfile sws swapsync swb switchbuf smc synmaxcol syn syntax tcl tabclose tal tabline tpm tabpagemax ts tabstop tbs tagbsearch tc tagcase tfu tagfunc tl taglength tr tagrelative tag tags tgst tagstack tcldll term tbidi termbidi tenc termencoding tgc termguicolors twk termwinkey twsl termwinscroll tws termwinsize twt termwintype terse ta textauto tx textmode tw textwidth tsr thesaurus tsrfu thesaurusfunc top tildeop to timeout tm timeoutlen title titlelen titleold titlestring tb toolbar tbis toolbariconsize ttimeout ttm ttimeoutlen tbi ttybuiltin tf ttyfast ttym ttymouse tsl ttyscroll tty ttytype
+syn keyword vimOption contained udir undodir udf undofile ul undolevels ur undoreload uc updatecount ut updatetime vsts varsofttabstop vts vartabstop vbs verbose vfile verbosefile vdir viewdir vop viewoptions vi viminfo vif viminfofile ve virtualedit vb visualbell warn wiv weirdinvert ww whichwrap wc wildchar wcm wildcharm wig wildignore wic wildignorecase wmnu wildmenu wim wildmode wop wildoptions wak winaltkeys wcr wincolor wi window wfb winfixbuf wfh winfixheight wfw winfixwidth wh winheight wmh winminheight wmw winminwidth winptydll wiw winwidth wrap wm wrapmargin ws wrapscan write wa writeany wb writebackup wd writedelay xtermcodes
 
 " vimOptions: These are the turn-off setting variants {{{2
 " GEN_SYN_VIM: vimOption turn-off, START_STR='syn keyword vimOption contained', END_STR=''
index 630d7bf6b778dd7636c07fd773d867ec82e67d82..e84f7f9adda19398432990cef4acf1c000063b38 100644 (file)
@@ -955,7 +955,6 @@ EXTERN int  p_sol;          // 'startofline'
 EXTERN char_u  *p_su;          // 'suffixes'
 EXTERN char_u  *p_sws;         // 'swapsync'
 EXTERN char_u  *p_swb;         // 'switchbuf'
-EXTERN char_u  *p_spk;         // 'splitkeep'
 EXTERN unsigned        swb_flags;
 // Keep in sync with p_swb_values in optionstr.c
 #define SWB_USEOPEN            0x001
@@ -964,9 +963,14 @@ EXTERN unsigned    swb_flags;
 #define SWB_NEWTAB             0x008
 #define SWB_VSPLIT             0x010
 #define SWB_USELAST            0x020
+EXTERN char_u  *p_spk;         // 'splitkeep'
 #ifdef FEAT_SYN_HL
 EXTERN char_u  *p_syn;         // 'syntax'
 #endif
+EXTERN char_u  *p_tcl;         // 'tabclose'
+EXTERN unsigned        tcl_flags;      // flags from 'tabclose'
+#define TCL_LEFT               0x001
+#define TCL_USELAST            0x002
 EXTERN long    p_ts;           // 'tabstop'
 EXTERN int     p_tbs;          // 'tagbsearch'
 EXTERN char_u  *p_tc;          // 'tagcase'
index 617f3cec6bfbf994b62ace91a8c3c2d9b24a1a4f..bf3ed35e0b214d6b4b397b4c18fc89046129a6fe 100644 (file)
@@ -2462,6 +2462,9 @@ static struct vimoption options[] =
                            {(char_u *)0L, (char_u *)0L}
 #endif
                            SCTX_INIT},
+    {"tabclose",    "tcl",  P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
+                           (char_u *)&p_tcl, PV_NONE, did_set_tabclose, expand_set_tabclose,
+                           {(char_u *)"", (char_u *)0L} SCTX_INIT},
     {"tabline",            "tal",  P_STRING|P_VI_DEF|P_RALL|P_MLE,
 #ifdef FEAT_STL_OPT
                            (char_u *)&p_tal, PV_NONE, did_set_tabline, NULL,
index 417f7859077a1d6944e5811f9275af6c7b72c447..b6249a2f38840a184946e20fb68be4227f84c461 100644 (file)
@@ -81,6 +81,8 @@ static char *(p_ssop_values[]) = {"buffers", "winpos", "resize", "winsize",
 static char *(p_swb_values[]) = {"useopen", "usetab", "split", "newtab", "vsplit", "uselast", NULL};
 static char *(p_spk_values[]) = {"cursor", "screen", "topline", NULL};
 static char *(p_tc_values[]) = {"followic", "ignore", "match", "followscs", "smart", NULL};
+// Keep in sync with TCL_ flags in option.h
+static char *(p_tcl_values[]) = {"left", "uselast", NULL};
 #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
 static char *(p_toolbar_values[]) = {"text", "icons", "tooltips", "horiz", NULL};
 #endif
@@ -166,6 +168,7 @@ didset_string_options(void)
     (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
 #endif
     (void)opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE);
+    (void)opt_strings_flags(p_tcl, p_tcl_values, &tcl_flags, TRUE);
 }
 
 #if defined(FEAT_EVAL) || defined(PROTO)
@@ -3669,6 +3672,26 @@ expand_set_switchbuf(optexpand_T *args, int *numMatches, char_u ***matches)
            matches);
 }
 
+/*
+ * The 'tabclose' option is changed.
+ */
+    char *
+did_set_tabclose(optset_T *args UNUSED)
+{
+    return did_set_opt_flags(p_tcl, p_tcl_values, &tcl_flags, TRUE);
+}
+
+    int
+expand_set_tabclose(optexpand_T *args, int *numMatches, char_u ***matches)
+{
+    return expand_set_opt_string(
+           args,
+           p_tcl_values,
+           ARRAY_LENGTH(p_tcl_values) - 1,
+           numMatches,
+           matches);
+}
+
 #if defined(FEAT_STL_OPT) || defined(PROTO)
 /*
  * The 'tabline' option is changed.
index 69463d44fc4c79ec6707ead49c87236445ac958d..1659131a3213418c61a9f5695873649c7269de45 100644 (file)
@@ -69,6 +69,7 @@ char *did_set_showtabline(optset_T *args);
 char *did_set_smoothscroll(optset_T *args);
 char *did_set_spell(optset_T *args);
 char *did_set_swapfile(optset_T *args);
+char *did_set_tabclose(optset_T *args);
 char *did_set_termguicolors(optset_T *args);
 char *did_set_terse(optset_T *args);
 char *did_set_textauto(optset_T *args);
index 340ffc428a021e6290e15f847158daa1d90c548c..39c40f39ba3aed9be30800c5fcd973e9093c5c22 100644 (file)
@@ -156,6 +156,7 @@ char *did_set_swapsync(optset_T *args);
 int expand_set_swapsync(optexpand_T *args, int *numMatches, char_u ***matches);
 char *did_set_switchbuf(optset_T *args);
 int expand_set_switchbuf(optexpand_T *args, int *numMatches, char_u ***matches);
+int expand_set_tabclose(optexpand_T *args, int *numMatches, char_u ***matches);
 char *did_set_tabline(optset_T *args);
 char *did_set_tagcase(optset_T *args);
 int expand_set_tagcase(optexpand_T *args, int *numMatches, char_u ***matches);
index 8cca2b932ddda8aea3a0f325ca0b0276646200f5..767471483701a1425831e49da75141411664bfc2 100644 (file)
@@ -144,6 +144,7 @@ let test_values = {
       \ 'splitkeep': [['cursor', 'screen', 'topline'], ['xxx']],
       \ 'swapsync': [['', 'sync', 'fsync'], ['xxx']],
       \ 'switchbuf': [['', 'useopen', 'split,newtab'], ['xxx']],
+      \ 'tabclose': [['', 'left', 'left,uselast'], ['xxx']],
       \ 'tagcase': [['smart', 'match'], ['', 'xxx', 'smart,match']],
       \ 'term': [[], []],
       \ 'termguicolors': [[], []],
index fbfbaae14c4245ef24292b5cab6c8c73d6f832c7..02f5d7e9007dbb3cbb7d0e2d515d29d87bb79e22 100644 (file)
@@ -548,6 +548,9 @@ func Test_set_completion_string_values()
   call assert_equal('sync', getcompletion('set swapsync=', 'cmdline')[1])
   call assert_equal('usetab', getcompletion('set switchbuf=', 'cmdline')[1])
   call assert_equal('ignore', getcompletion('set tagcase=', 'cmdline')[1])
+  if exists('+tabclose')
+    call assert_equal('left uselast', join(sort(getcompletion('set tabclose=', 'cmdline'))), ' ')
+  endif
   if exists('+termwintype')
     call assert_equal('conpty', getcompletion('set termwintype=', 'cmdline')[1])
   endif
@@ -1407,7 +1410,8 @@ func Test_write()
   set nowrite
   call assert_fails('write Xwrfile', 'E142:')
   set write
-  close!
+  " close swapfile
+  bw!
 endfunc
 
 " Test for 'buftype' option
index 3624790e3e24ae64f43ea0c9be8b7583321be288..1a4056708569add4f70ed65e08c8bb0b5080f098 100644 (file)
@@ -965,6 +965,64 @@ func Test_tabpage_alloc_failure()
   call assert_equal(1, tabpagenr('$'))
 endfunc
 
+func Test_tabpage_tabclose()
+  " Default behaviour, move to the right.
+  call s:reconstruct_tabpage_for_test(6)
+  norm! 4gt
+  setl tcl=
+  tabclose
+  call assert_equal("n3", bufname())
+
+  " Move to the left.
+  call s:reconstruct_tabpage_for_test(6)
+  norm! 4gt
+  setl tcl=left
+  tabclose
+  call assert_equal("n1", bufname())
+
+  " Move to the last used tab page.
+  call s:reconstruct_tabpage_for_test(6)
+  norm! 5gt
+  norm! 2gt
+  setl tcl=uselast
+  tabclose
+  call assert_equal("n3", bufname())
+
+  " Same, but the last used tab page is invalid. Move to the right.
+  call s:reconstruct_tabpage_for_test(6)
+  norm! 5gt
+  norm! 3gt
+  setl tcl=uselast
+  tabclose 5
+  tabclose!
+  call assert_equal("n2", bufname())
+
+  " Same, but the last used tab page is invalid. Move to the left.
+  call s:reconstruct_tabpage_for_test(6)
+  norm! 5gt
+  norm! 3gt
+  setl tcl=uselast,left
+  tabclose 5
+  tabclose!
+  call assert_equal("n0", bufname())
+
+  " Move left when moving right is not possible.
+  call s:reconstruct_tabpage_for_test(6)
+  setl tcl=
+  norm! 6gt
+  tabclose
+  call assert_equal("n3", bufname())
+
+  " Move right when moving left is not possible.
+  call s:reconstruct_tabpage_for_test(6)
+  setl tcl=left
+  norm! 1gt
+  tabclose
+  call assert_equal("n0", bufname())
+
+  setl tcl&
+endfunc
+
 " this was giving ml_get errors
 func Test_tabpage_last_line()
   enew
index 194099bbd7bd3781f6ad5369aac5ad2613e17ce0..fc1fb24eac2c9089ae0048e856ca4b346550c81d 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    572,
 /**/
     571,
 /**/
index 73229059eabacdde1642dfc76a2fdee6e0dff105..c87cce0016a21534add8b8e932a41d4da4bdd60a 100644 (file)
@@ -3782,15 +3782,23 @@ win_altframe(
     static tabpage_T *
 alt_tabpage(void)
 {
-    tabpage_T  *tp;
+    tabpage_T  *tp = NULL;
+    int                forward;
 
-    // Use the next tab page if possible.
-    if (curtab->tp_next != NULL)
-       return curtab->tp_next;
+    // Use the last accessed tab page, if possible.
+    if ((tcl_flags & TCL_USELAST) && valid_tabpage(lastused_tabpage))
+       return lastused_tabpage;
+
+    // Use the previous tab page, if possible.
+    forward = curtab->tp_next != NULL &&
+           ((tcl_flags & TCL_LEFT) == 0 || curtab == first_tabpage);
+
+    if (forward)
+       tp = curtab->tp_next;
+    else
+       for (tp = first_tabpage; tp->tp_next != curtab; tp = tp->tp_next)
+           ;
 
-    // Find the last but one tab page.
-    for (tp = first_tabpage; tp->tp_next != curtab; tp = tp->tp_next)
-       ;
     return tp;
 }