patch 9.1.0557: moving in the buffer list doesn't work as documented

Commit: 
https://github.com/vim/vim/commit/893eeeb44583ca33276e263165b2a6e50fd297d0
Author: LemonBoy <thatle...@gmail.com>
Date:   Wed Jul 10 20:20:48 2024 +0200

    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 <thatle...@gmail.com>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/runtime/doc/version9.txt b/runtime/doc/version9.txt
index df56215ea..ed1cd4308 100644
--- a/runtime/doc/version9.txt
+++ b/runtime/doc/version9.txt
@@ -1,4 +1,4 @@
-*version9.txt*  For Vim version 9.1.  Last change: 2024 Jul 09
+*version9.txt*  For Vim version 9.1.  Last change: 2024 Jul 10
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -41580,6 +41580,9 @@ Changed~
 - provide information about function arguments using the get(func, "arity")
   function |get()-func|
 - |:bwipe| also wipes jumplist and tagstack data
+- moving in the buffer list using |:bnext| and similar commands, behaves as
+  documented and skips help buffers (if not run from a help buffer, else 
+  moves to the next/previous help buffer).
 
                                                        *added-9.2*
 Added ~
diff --git a/src/buffer.c b/src/buffer.c
index 82957f986..447ce76d4 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -50,6 +50,7 @@ static void   free_buffer(buf_T *);
 static void    free_buffer_stuff(buf_T *buf, int free_options);
 static int     bt_nofileread(buf_T *buf);
 static void    no_write_message_buf(buf_T *buf);
+static int     do_buffer_ext(int action, int start, int dir, int count, int 
flags);
 
 #ifdef UNIX
 # define dev_T dev_t
@@ -1106,13 +1107,30 @@ goto_buffer(
 {
     bufref_T   old_curbuf;
     int                save_sea = swap_exists_action;
+    int                skip_help_buf;
+
+    switch (eap->cmdidx)
+    {
+       case CMD_bnext:
+       case CMD_sbnext:
+       case CMD_bNext:
+       case CMD_bprevious:
+       case CMD_sbNext:
+       case CMD_sbprevious:
+           skip_help_buf = TRUE;
+           break;
+       default:
+           skip_help_buf = FALSE;
+           break;
+    }
 
     set_bufref(&old_curbuf, curbuf);
 
     if (swap_exists_action == SEA_NONE)
        swap_exists_action = SEA_DIALOG;
-    (void)do_buffer(*eap->cmd == 's' ? DOBUF_SPLIT : DOBUF_GOTO,
-                                            start, dir, count, eap->forceit);
+    (void)do_buffer_ext(*eap->cmd == 's' ? DOBUF_SPLIT : DOBUF_GOTO, start, 
dir, count,
+           (eap->forceit ? DOBUF_FORCEIT : 0) |
+           (skip_help_buf ? DOBUF_SKIPHELP : 0));
     if (swap_exists_action == SEA_QUIT && *eap->cmd == 's')
     {
 #if defined(FEAT_EVAL)
@@ -1343,8 +1361,11 @@ do_buffer_ext(
                if (buf == NULL)
                    buf = lastbuf;
            }
-           // don't count unlisted buffers
-           if (unload || buf->b_p_bl)
+           // 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)))
            {
                 --count;
                 bp = NULL;     // use this buffer as new starting point
diff --git a/src/testdir/test_buffer.vim b/src/testdir/test_buffer.vim
index de088bd8e..757ba0578 100644
--- a/src/testdir/test_buffer.vim
+++ b/src/testdir/test_buffer.vim
@@ -126,6 +126,52 @@ func Test_buflist_browse()
   %bwipe!
 endfunc
 
+" Test for :bnext and :bprev when called from help and non-help buffers.
+func Test_bnext_bprev_help()
+  %bwipe!
+
+  e XHelp1 | set bt=help
+  let b1 = bufnr()
+  e Xbuf1
+  let b2 = bufnr()
+
+  " There's only one buffer of each type.
+  b XHelp1
+  bnext | call assert_equal(b1, bufnr())
+  bprev | call assert_equal(b1, bufnr())
+  b Xbuf1
+  bnext | call assert_equal(b2, bufnr())
+  bprev | call assert_equal(b2, bufnr())
+
+  " Add one more buffer of each type.
+  e XHelp2 | set bt=help
+  let b3 = bufnr()
+  e Xbuf2
+  let b4 = bufnr()
+
+  " Help buffer jumps to help buffer.
+  b XHelp1
+  bnext | call assert_equal(b3, bufnr())
+  bnext | call assert_equal(b1, bufnr())
+  bprev | call assert_equal(b3, bufnr())
+  bprev | call assert_equal(b1, bufnr())
+
+  " Regular buffer jumps to regular buffer.
+  b Xbuf1
+  bnext | call assert_equal(b4, bufnr())
+  bnext | call assert_equal(b2, bufnr())
+  bprev | call assert_equal(b4, bufnr())
+  bprev | call assert_equal(b2, bufnr())
+
+  " :brewind and :blast are not affected by the buffer type.
+  b Xbuf2
+  brewind | call assert_equal(b1, bufnr())
+  b XHelp1
+  blast   | call assert_equal(b4, bufnr())
+
+  %bwipe!
+endfunc
+
 " Test for :bdelete
 func Test_bdelete_cmd()
   %bwipe!
diff --git a/src/version.c b/src/version.c
index 8a392cac6..9c076f86b 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    557,
 /**/
     556,
 /**/
diff --git a/src/vim.h b/src/vim.h
index a80f84484..1b64e0dd9 100644
--- a/src/vim.h
+++ b/src/vim.h
@@ -1074,6 +1074,8 @@ extern int (*dyn_libintl_wputenv)(const wchar_t 
*envstring);
 // Values for flags argument of do_buffer()
 #define DOBUF_FORCEIT  1       // :cmd!
 #define DOBUF_NOPOPUP  2       // skip popup window buffers
+#define DOBUF_SKIPHELP 4       // skip or keep help buffers depending on 
b_help of the
+                               // starting buffer
 
 // Values for sub_cmd and which_pat argument for search_regcomp()
 // Also used for which_pat argument for searchit()

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1sRc4q-00FcJk-9C%40256bit.org.

Raspunde prin e-mail lui