forked from aniani/vim
patch 9.1.0572: cannot specify tab page closing behaviour
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>
This commit is contained in:
committed by
Christian Brabandt
parent
74703f1086
commit
5247b0b92e
@@ -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'
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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': [[], []],
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -704,6 +704,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
572,
|
||||
/**/
|
||||
571,
|
||||
/**/
|
||||
|
||||
22
src/window.c
22
src/window.c
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user