Commit: patch 9.1.2136: :tab sbuffer may close old tabpage

0 views
Skip to first unread message

Christian Brabandt

unread,
Feb 7, 2026, 5:31:33 AM (yesterday) Feb 7
to vim...@googlegroups.com
patch 9.1.2136: :tab sbuffer may close old tabpage

Commit: https://github.com/vim/vim/commit/6da9f757c48ce87df381d726b165bed6fa301423
Author: zeertzjq <zeer...@outlook.com>
Date: Sat Feb 7 10:20:51 2026 +0000

patch 9.1.2136: :tab sbuffer may close old tabpage

Problem: :tab sbuffer may close old tabpage if BufLeave autocommand
splits window (after 9.1.0143).
Solution: Only close other windows if the buffer will be unloaded
(zeertzjq).

related: neovim/neovim#37749
closes: #19352

Signed-off-by: zeertzjq <zeer...@outlook.com>
Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/runtime/doc/version9.txt b/runtime/doc/version9.txt
index 05d4da2be..3dd3754b1 100644
--- a/runtime/doc/version9.txt
+++ b/runtime/doc/version9.txt
@@ -1,4 +1,4 @@
-*version9.txt* For Vim version 9.1. Last change: 2026 Feb 06
+*version9.txt* For Vim version 9.1. Last change: 2026 Feb 07


VIM REFERENCE MANUAL by Bram Moolenaar
@@ -52502,4 +52502,9 @@ Problem: search() is used to check for the message from tar that
src/testdir/samples/evil.tar.
Solution: Use the 'w' flag for search() (Kevin Goodsell)

+Patch 9.1.2136
+Problem: :tab sbuffer may close old tabpage if BufLeave autocommand
+ splits window (after 9.1.0143).
+Solution: Only close other windows if the buffer will be unloaded (zeertzjq).
+
vim:tw=78:ts=8:noet:ft=help:norl:fdm=manual:nofoldenable
diff --git a/src/buffer.c b/src/buffer.c
index 86b784023..8a5d883e7 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1886,6 +1886,7 @@ set_curbuf(buf_T *buf, int action)
prevbuf = curbuf;
set_bufref(&prevbufref, prevbuf);
set_bufref(&newbufref, buf);
+ int prev_nwindows = prevbuf->b_nwindows;

// Autocommands may delete the current buffer and/or the buffer we want to
// go to. In those cases don't close the buffer.
@@ -1904,8 +1905,8 @@ set_curbuf(buf_T *buf, int action)
// autocommands may have opened a new window
// with prevbuf, grr
if (unload ||
- (last_winid != get_last_winid() &&
- strchr((char *)"wdu", prevbuf->b_p_bh[0]) != NULL))
+ (prev_nwindows <= 1 && last_winid != get_last_winid()
+ && action == DOBUF_GOTO && !buf_hide(prevbuf)))
close_windows(prevbuf, FALSE);
#if defined(FEAT_EVAL)
if (bufref_valid(&prevbufref) && !aborting())
diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim
index 82d62e763..74b1aabdf 100644
--- a/src/testdir/test_autocmd.vim
+++ b/src/testdir/test_autocmd.vim
@@ -4757,7 +4757,7 @@ func Test_autocmd_invalidates_undo_on_textchanged()
call StopVimInTerminal(buf)
endfunc

-func Test_autocmd_creates_new_buffer_on_bufleave()
+func Test_autocmd_creates_new_window_on_bufleave()
e a.txt
e b.txt
setlocal bufhidden=wipe
diff --git a/src/testdir/test_buffer.vim b/src/testdir/test_buffer.vim
index 4ededa15d..934bc6fe1 100644
--- a/src/testdir/test_buffer.vim
+++ b/src/testdir/test_buffer.vim
@@ -880,4 +880,37 @@ func Test_bdelete_skip_closing_bufs()
%bw!
endfunc

+func Test_split_window_in_BufLeave_from_tab_sbuffer()
+ tabnew Xa
+ setlocal bufhidden=wipe
+ let t0 = tabpagenr()
+ let b0 = bufnr()
+ let b1 = bufadd('Xb')
+ autocmd BufLeave Xa ++once split
+ exe 'tab sbuffer' b1
+ call assert_equal(t0 + 1, tabpagenr())
+ call assert_equal([b1, b0], tabpagebuflist())
+ call assert_equal([b0], tabpagebuflist(t0))
+ tabclose
+ call assert_equal(t0, tabpagenr())
+ call assert_equal([b0], tabpagebuflist())
+
+ bwipe! Xa
+ bwipe! Xb
+endfunc
+
+func Test_split_window_in_BufLeave_from_switching_buffer()
+ tabnew Xa
+ setlocal bufhidden=wipe
+ split
+ let b0 = bufnr()
+ let b1 = bufadd('Xb')
+ autocmd BufLeave Xa ++once split
+ exe 'buffer' b1
+ call assert_equal([b1, b0, b0], tabpagebuflist())
+
+ bwipe! Xa
+ bwipe! Xb
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index 0adf730af..8721de449 100644
--- a/src/version.c
+++ b/src/version.c
@@ -734,6 +734,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 2136,
/**/
2135,
/**/
Reply all
Reply to author
Forward
0 new messages