]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1599: :bnext doesn't go to unlisted help buffers v9.1.1599
authorzeertzjq <zeertzjq@outlook.com>
Thu, 7 Aug 2025 13:24:29 +0000 (15:24 +0200)
committerChristian Brabandt <cb@256bit.org>
Thu, 7 Aug 2025 13:24:29 +0000 (15:24 +0200)
Problem:  :bnext doesn't go to unlisted help buffers when cycling
          through help buffers (after 9.1.0557).
Solution: Don't check if a help buffer is listed (zeertzjq).

From <https://github.com/vim/vim/issues/4478#issuecomment-498831057>:

> I think we should fix that, since once you get to a non-help buffer
> all unlisted buffers are skipped, thus you won't encounter another
> help buffer.

This implies that cycling through help buffers should work even if help
buffers are unlisted. Otherwise this part of :bnext isn't really useful,
as :h makes help buffers unlisted by default.

related: #4478
related: #15198
closes: #17913

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/buffer.c
src/testdir/test_buffer.vim
src/version.c

index 748ffdaa7e2dec91ac31b16293629baed2a36903..49db39d8f63e9face2f8e44eba274fdb0c428905 100644 (file)
@@ -1371,8 +1371,11 @@ do_buffer_ext(
     }
     else
     {
+       int help_only = (flags & DOBUF_SKIPHELP) != 0 && buf->b_help;
+
        bp = NULL;
-       while (count > 0 || (!unload && !buf->b_p_bl && bp != buf))
+       while (count > 0 || (bp != buf && !unload
+                               && !(help_only ? buf->b_help : buf->b_p_bl)))
        {
            // remember the buffer where we start, we come back there when all
            // buffers are unlisted.
@@ -1390,14 +1393,17 @@ do_buffer_ext(
                if (buf == NULL)
                    buf = lastbuf;
            }
+           // Avoid non-help buffers if the starting point was a help buffer
+           // and vice-versa.
            // Don't count unlisted buffers.
-           // Avoid non-help buffers if the starting point was a non-help buffer and
-           // vice-versa.
-           if (unload || (buf->b_p_bl
-                       && ((flags & DOBUF_SKIPHELP) == 0 || buf->b_help == bp->b_help)))
+           if (unload
+                   || (help_only
+                       ? buf->b_help
+                       : (buf->b_p_bl && ((flags & DOBUF_SKIPHELP) == 0
+                                                           || !buf->b_help))))
            {
-                --count;
-                bp = NULL;     // use this buffer as new starting point
+               --count;
+               bp = NULL;      // use this buffer as new starting point
            }
            if (bp == buf)
            {
index d6d668799f212196616280752a28e52cf27279f5..e16a537ef2fc6e53dd7b9fc2aabfbcda8b1c8a07 100644 (file)
@@ -167,6 +167,17 @@ func Test_bnext_bprev_help()
   b XHelp1
   blast   | call assert_equal(b4, bufnr())
 
+  " Cycling through help buffers works even if they aren't listed.
+  b XHelp1
+  setlocal nobuflisted
+  bnext | call assert_equal(b3, bufnr())
+  bnext | call assert_equal(b1, bufnr())
+  bprev | call assert_equal(b3, bufnr())
+  setlocal nobuflisted
+  bprev | call assert_equal(b1, bufnr())
+  bprev | call assert_equal(b3, bufnr())
+  bnext | call assert_equal(b1, bufnr())
+
   %bwipe!
 endfunc
 
index ff47328d42840a2352bd341833cda4c9b06d4aa8..d1923b1dbe70ec93428512eca285f3954699373e 100644 (file)
@@ -719,6 +719,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1599,
 /**/
     1598,
 /**/