Skip to content

Commit 893eeeb

Browse files
LemonBoychrisbra
authored andcommitted
patch 9.1.0557: moving in the buffer list doesn't work as documented
Problem: moving in the buffer list doesn't work as documented (SenileFelineS) Solution: Skip non-help buffers, when run from normal buffers, else only move from help buffers to the next help buffer (LemonBoy) As explained in the help section for :bnext and :bprev the commands should jump from help buffers to help buffers (and from regular ones to regular ones). fixes: #4478 closes: #15198 Signed-off-by: LemonBoy <thatlemon@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 7a85e34 commit 893eeeb

File tree

5 files changed

+79
-5
lines changed

5 files changed

+79
-5
lines changed

runtime/doc/version9.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*version9.txt* For Vim version 9.1. Last change: 2024 Jul 09
1+
*version9.txt* For Vim version 9.1. Last change: 2024 Jul 10
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -41580,6 +41580,9 @@ Changed~
4158041580
- provide information about function arguments using the get(func, "arity")
4158141581
function |get()-func|
4158241582
- |:bwipe| also wipes jumplist and tagstack data
41583+
- moving in the buffer list using |:bnext| and similar commands, behaves as
41584+
documented and skips help buffers (if not run from a help buffer, else
41585+
moves to the next/previous help buffer).
4158341586

4158441587
*added-9.2*
4158541588
Added ~

src/buffer.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ static void free_buffer(buf_T *);
5050
static void free_buffer_stuff(buf_T *buf, int free_options);
5151
static int bt_nofileread(buf_T *buf);
5252
static void no_write_message_buf(buf_T *buf);
53+
static int do_buffer_ext(int action, int start, int dir, int count, int flags);
5354

5455
#ifdef UNIX
5556
# define dev_T dev_t
@@ -1106,13 +1107,30 @@ goto_buffer(
11061107
{
11071108
bufref_T old_curbuf;
11081109
int save_sea = swap_exists_action;
1110+
int skip_help_buf;
1111+
1112+
switch (eap->cmdidx)
1113+
{
1114+
case CMD_bnext:
1115+
case CMD_sbnext:
1116+
case CMD_bNext:
1117+
case CMD_bprevious:
1118+
case CMD_sbNext:
1119+
case CMD_sbprevious:
1120+
skip_help_buf = TRUE;
1121+
break;
1122+
default:
1123+
skip_help_buf = FALSE;
1124+
break;
1125+
}
11091126

11101127
set_bufref(&old_curbuf, curbuf);
11111128

11121129
if (swap_exists_action == SEA_NONE)
11131130
swap_exists_action = SEA_DIALOG;
1114-
(void)do_buffer(*eap->cmd == 's' ? DOBUF_SPLIT : DOBUF_GOTO,
1115-
start, dir, count, eap->forceit);
1131+
(void)do_buffer_ext(*eap->cmd == 's' ? DOBUF_SPLIT : DOBUF_GOTO, start, dir, count,
1132+
(eap->forceit ? DOBUF_FORCEIT : 0) |
1133+
(skip_help_buf ? DOBUF_SKIPHELP : 0));
11161134
if (swap_exists_action == SEA_QUIT && *eap->cmd == 's')
11171135
{
11181136
#if defined(FEAT_EVAL)
@@ -1343,8 +1361,11 @@ do_buffer_ext(
13431361
if (buf == NULL)
13441362
buf = lastbuf;
13451363
}
1346-
// don't count unlisted buffers
1347-
if (unload || buf->b_p_bl)
1364+
// Don't count unlisted buffers.
1365+
// Avoid non-help buffers if the starting point was a non-help buffer and
1366+
// vice-versa.
1367+
if (unload || (buf->b_p_bl
1368+
&& ((flags & DOBUF_SKIPHELP) == 0 || buf->b_help == bp->b_help)))
13481369
{
13491370
--count;
13501371
bp = NULL; // use this buffer as new starting point

src/testdir/test_buffer.vim

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,52 @@ func Test_buflist_browse()
126126
%bwipe!
127127
endfunc
128128

129+
" Test for :bnext and :bprev when called from help and non-help buffers.
130+
func Test_bnext_bprev_help()
131+
%bwipe!
132+
133+
e XHelp1 | set bt=help
134+
let b1 = bufnr()
135+
e Xbuf1
136+
let b2 = bufnr()
137+
138+
" There's only one buffer of each type.
139+
b XHelp1
140+
bnext | call assert_equal(b1, bufnr())
141+
bprev | call assert_equal(b1, bufnr())
142+
b Xbuf1
143+
bnext | call assert_equal(b2, bufnr())
144+
bprev | call assert_equal(b2, bufnr())
145+
146+
" Add one more buffer of each type.
147+
e XHelp2 | set bt=help
148+
let b3 = bufnr()
149+
e Xbuf2
150+
let b4 = bufnr()
151+
152+
" Help buffer jumps to help buffer.
153+
b XHelp1
154+
bnext | call assert_equal(b3, bufnr())
155+
bnext | call assert_equal(b1, bufnr())
156+
bprev | call assert_equal(b3, bufnr())
157+
bprev | call assert_equal(b1, bufnr())
158+
159+
" Regular buffer jumps to regular buffer.
160+
b Xbuf1
161+
bnext | call assert_equal(b4, bufnr())
162+
bnext | call assert_equal(b2, bufnr())
163+
bprev | call assert_equal(b4, bufnr())
164+
bprev | call assert_equal(b2, bufnr())
165+
166+
" :brewind and :blast are not affected by the buffer type.
167+
b Xbuf2
168+
brewind | call assert_equal(b1, bufnr())
169+
b XHelp1
170+
blast | call assert_equal(b4, bufnr())
171+
172+
%bwipe!
173+
endfunc
174+
129175
" Test for :bdelete
130176
func Test_bdelete_cmd()
131177
%bwipe!

src/version.c

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

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
557,
707709
/**/
708710
556,
709711
/**/

src/vim.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,8 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
10741074
// Values for flags argument of do_buffer()
10751075
#define DOBUF_FORCEIT 1 // :cmd!
10761076
#define DOBUF_NOPOPUP 2 // skip popup window buffers
1077+
#define DOBUF_SKIPHELP 4 // skip or keep help buffers depending on b_help of the
1078+
// starting buffer
10771079

10781080
// Values for sub_cmd and which_pat argument for search_regcomp()
10791081
// Also used for which_pat argument for searchit()

0 commit comments

Comments
 (0)