Skip to content

Commit 539aa6b

Browse files
committed
patch 8.1.2315: not always using the right window when jumping to an error
Problem: Not always using the right window when jumping to an error. Solution: Add the "uselast" flag in 'switchbuf'. (closes #1652)
1 parent 7170b29 commit 539aa6b

6 files changed

Lines changed: 21 additions & 3 deletions

File tree

runtime/doc/options.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7417,6 +7417,8 @@ A jump table for the options with a short description can be found at |Q_op|.
74177417
vsplit Just like "split" but split vertically.
74187418
newtab Like "split", but open a new tab page. Overrules
74197419
"split" when both are present.
7420+
uselast If included, jump to the previously used window when
7421+
jumping to errors with |quickfix| commands.
74207422

74217423
*'synmaxcol'* *'smc'*
74227424
'synmaxcol' 'smc' number (default 3000)

src/option.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,11 +911,13 @@ EXTERN char_u *p_su; // 'suffixes'
911911
EXTERN char_u *p_sws; // 'swapsync'
912912
EXTERN char_u *p_swb; // 'switchbuf'
913913
EXTERN unsigned swb_flags;
914+
// Keep in sync with p_swb_values in optionstr.c
914915
#define SWB_USEOPEN 0x001
915916
#define SWB_USETAB 0x002
916917
#define SWB_SPLIT 0x004
917918
#define SWB_NEWTAB 0x008
918919
#define SWB_VSPLIT 0x010
920+
#define SWB_USELAST 0x020
919921
EXTERN char_u *p_syn; // 'syntax'
920922
EXTERN long p_ts; // 'tabstop'
921923
EXTERN int p_tbs; // 'tagbsearch'

src/optionstr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ static char *(p_ssop_values[]) = {"buffers", "winpos", "resize", "winsize",
3939
"localoptions", "options", "help", "blank", "globals", "slash", "unix",
4040
"sesdir", "curdir", "folds", "cursor", "tabpages", "terminal", NULL};
4141
#endif
42-
static char *(p_swb_values[]) = {"useopen", "usetab", "split", "newtab", "vsplit", NULL};
42+
// Keep in sync with SWB_ flags in option.h
43+
static char *(p_swb_values[]) = {"useopen", "usetab", "split", "newtab", "vsplit", "uselast", NULL};
4344
static char *(p_tc_values[]) = {"followic", "ignore", "match", "followscs", "smart", NULL};
4445
#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
4546
static char *(p_toolbar_values[]) = {"text", "icons", "tooltips", "horiz", NULL};

src/quickfix.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3013,8 +3013,11 @@ qf_goto_win_with_qfl_file(int qf_fnum)
30133013
if (IS_QF_WINDOW(win))
30143014
{
30153015
// Didn't find it, go to the window before the quickfix
3016-
// window.
3017-
if (altwin != NULL)
3016+
// window, unless 'switchbuf' contains 'uselast': in this case we
3017+
// try to jump to the previously used window first.
3018+
if ((swb_flags & SWB_USELAST) && win_valid(prevwin))
3019+
win = prevwin;
3020+
else if (altwin != NULL)
30183021
win = altwin;
30193022
else if (curwin->w_prev != NULL)
30203023
win = curwin->w_prev;

src/testdir/test_quickfix.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,6 +1664,14 @@ func Test_switchbuf()
16641664
call assert_equal(3, tabpagenr('$'))
16651665
tabfirst | enew | tabonly | only
16661666

1667+
set switchbuf=uselast
1668+
split
1669+
let last_winid = win_getid()
1670+
copen
1671+
exe "normal 1G\<CR>"
1672+
call assert_equal(last_winid, win_getid())
1673+
enew | only
1674+
16671675
set switchbuf=
16681676
edit Xqftestfile1
16691677
let file1_winid = win_getid()

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,8 @@ static char *(features[]) =
741741

742742
static int included_patches[] =
743743
{ /* Add new patch number below this line */
744+
/**/
745+
2315,
744746
/**/
745747
2314,
746748
/**/

0 commit comments

Comments
 (0)