vim-patch:9.1.2068: :bd/bw may try to switch to a closing buffer

Problem:  :bdelete/bunload/bwipeout may attempt to switch to a closing
          buffer, which fails. (after 9.1.2058)
Solution: don't consider switching to closing buffers (Sean Dewar)

closes: vim/vim#19107

63d53de72d

Co-authored-by: Sean Dewar <6256228+seandewar@users.noreply.github.com>
This commit is contained in:
Sean Dewar
2026-01-08 21:37:58 +00:00
parent 5f871007d7
commit e002e4d7fc
2 changed files with 156 additions and 7 deletions

View File

@@ -1434,10 +1434,11 @@ static int do_buffer_ext(int action, int start, int dir, int count, int flags)
// Then prefer the buffer we most recently visited.
// Else try to find one that is loaded, after the current buffer,
// then before the current buffer.
// Finally use any buffer.
// Finally use any buffer. Skip buffers that are closing throughout.
buf = NULL; // Selected buffer.
bp = NULL; // Used when no loaded buffer found.
if (au_new_curbuf.br_buf != NULL && bufref_valid(&au_new_curbuf)) {
if (au_new_curbuf.br_buf != NULL && bufref_valid(&au_new_curbuf)
&& !au_new_curbuf.br_buf->b_locked_split) {
buf = au_new_curbuf.br_buf;
} else if (curwin->w_jumplistlen > 0) {
if (jop_flags & kOptJopFlagClean) {
@@ -1469,8 +1470,9 @@ static int do_buffer_ext(int action, int start, int dir, int count, int flags)
if (buf != NULL) {
// Skip current and unlisted bufs. Also skip a quickfix
// buffer, it might be deleted soon.
if (buf == curbuf || !buf->b_p_bl || bt_quickfix(buf)) {
// or closing buffer, it might be deleted soon.
if (buf == curbuf || !buf->b_p_bl || bt_quickfix(buf)
|| buf->b_locked_split) {
buf = NULL;
} else if (buf->b_ml.ml_mfp == NULL) {
// skip unloaded buf, but may keep it for later
@@ -1514,7 +1516,8 @@ static int do_buffer_ext(int action, int start, int dir, int count, int flags)
continue;
}
// in non-help buffer, try to skip help buffers, and vv
if (buf->b_help == curbuf->b_help && buf->b_p_bl && !bt_quickfix(buf)) {
if (buf->b_help == curbuf->b_help && buf->b_p_bl
&& !bt_quickfix(buf) && !buf->b_locked_split) {
if (buf->b_ml.ml_mfp != NULL) { // found loaded buffer
break;
}
@@ -1530,7 +1533,7 @@ static int do_buffer_ext(int action, int start, int dir, int count, int flags)
}
if (buf == NULL) { // No loaded buffer, find listed one
FOR_ALL_BUFFERS(buf2) {
if (buf2->b_p_bl && buf2 != curbuf && !bt_quickfix(buf2)) {
if (buf2->b_p_bl && buf2 != curbuf && !bt_quickfix(buf2) && !buf2->b_locked_split) {
buf = buf2;
break;
}
@@ -1538,7 +1541,7 @@ static int do_buffer_ext(int action, int start, int dir, int count, int flags)
}
if (buf == NULL) { // Still no buffer, just take one
buf = curbuf->b_next != NULL ? curbuf->b_next : curbuf->b_prev;
if (bt_quickfix(buf)) {
if (bt_quickfix(buf) || (buf != curbuf && buf->b_locked_split)) {
buf = NULL;
}
}