Blame SOURCES/0001-patch-8.2.4327-may-end-up-with-no-current-buffer.patch

83f671
From e3537aec2f8d6470010547af28dcbd83d41461b8 Mon Sep 17 00:00:00 2001
83f671
From: Bram Moolenaar <Bram@vim.org>
83f671
Date: Tue, 8 Feb 2022 15:05:20 +0000
83f671
Subject: [PATCH] patch 8.2.4327: may end up with no current buffer
83f671
83f671
Problem:    May end up with no current buffer.
83f671
Solution:   When deleting the current buffer to not pick a quickfix buffer as
83f671
            the new current buffer.
83f671
---
83f671
 src/buffer.c                  | 26 ++++++++++++++++++++++----
83f671
 src/testdir/test_quickfix.vim | 25 +++++++++++++++++++++++++
83f671
 src/version.c                 |  2 ++
83f671
 3 files changed, 49 insertions(+), 4 deletions(-)
83f671
83f671
diff --git a/src/buffer.c b/src/buffer.c
83f671
index 81bdb31ca..b3e2bc3f9 100644
83f671
--- a/src/buffer.c
83f671
+++ b/src/buffer.c
83f671
@@ -1430,8 +1430,14 @@ do_buffer_ext(
83f671
 		buf = buflist_findnr(curwin->w_jumplist[jumpidx].fmark.fnum);
83f671
 		if (buf != NULL)
83f671
 		{
83f671
-		    if (buf == curbuf || !buf->b_p_bl)
83f671
-			buf = NULL;	// skip current and unlisted bufs
83f671
+		    // Skip current and unlisted bufs.  Also skip a quickfix
83f671
+		    // buffer, it might be deleted soon.
83f671
+		    if (buf == curbuf || !buf->b_p_bl
83f671
+#if defined(FEAT_QUICKFIX)
83f671
+			    || bt_quickfix(buf)
83f671
+#endif
83f671
+			    )
83f671
+			buf = NULL;
83f671
 		    else if (buf->b_ml.ml_mfp == NULL)
83f671
 		    {
83f671
 			// skip unloaded buf, but may keep it for later
83f671
@@ -1467,7 +1473,11 @@ do_buffer_ext(
83f671
 		    continue;
83f671
 		}
83f671
 		// in non-help buffer, try to skip help buffers, and vv
83f671
-		if (buf->b_help == curbuf->b_help && buf->b_p_bl)
83f671
+		if (buf->b_help == curbuf->b_help && buf->b_p_bl
83f671
+#if defined(FEAT_QUICKFIX)
83f671
+			    && !bt_quickfix(buf)
83f671
+#endif
83f671
+			   )
83f671
 		{
83f671
 		    if (buf->b_ml.ml_mfp != NULL)   // found loaded buffer
83f671
 			break;
83f671
@@ -1485,7 +1495,11 @@ do_buffer_ext(
83f671
 	if (buf == NULL)	// No loaded buffer, find listed one
83f671
 	{
83f671
 	    FOR_ALL_BUFFERS(buf)
83f671
-		if (buf->b_p_bl && buf != curbuf)
83f671
+		if (buf->b_p_bl && buf != curbuf
83f671
+#if defined(FEAT_QUICKFIX)
83f671
+			    && !bt_quickfix(buf)
83f671
+#endif
83f671
+		       )
83f671
 		    break;
83f671
 	}
83f671
 	if (buf == NULL)	// Still no buffer, just take one
83f671
@@ -1494,6 +1508,10 @@ do_buffer_ext(
83f671
 		buf = curbuf->b_next;
83f671
 	    else
83f671
 		buf = curbuf->b_prev;
83f671
+#if defined(FEAT_QUICKFIX)
83f671
+	    if (bt_quickfix(buf))
83f671
+		buf = NULL;
83f671
+#endif
83f671
 	}
83f671
     }
83f671
 
83f671
diff --git a/src/testdir/test_quickfix.vim b/src/testdir/test_quickfix.vim
83f671
index 07fdb9644..adb0ea4fd 100644
83f671
--- a/src/testdir/test_quickfix.vim
83f671
+++ b/src/testdir/test_quickfix.vim
83f671
@@ -5851,5 +5851,30 @@ func Test_lopen_bwipe()
83f671
   delfunc R
83f671
 endfunc
83f671
 
83f671
+" Another sequence of commands that caused all buffers to be wiped out
83f671
+func Test_lopen_bwipe_all()
83f671
+  let lines =<< trim END
83f671
+    func R()
83f671
+      silent! tab lopen
83f671
+      e foo
83f671
+      silent! lfile
83f671
+    endfunc
83f671
+    cal R()
83f671
+    exe "norm \<C-W>\<C-V>0"
83f671
+    cal R()
83f671
+    bwipe
83f671
+
83f671
+    call writefile(['done'], 'Xresult')
83f671
+    qall!
83f671
+  END
83f671
+  call writefile(lines, 'Xscript')
83f671
+  if RunVim([], [], '-u NONE -n -X -Z -e -m -s -S Xscript')
83f671
+    call assert_equal(['done'], readfile('Xresult'))
83f671
+  endif
83f671
+
83f671
+  call delete('Xscript')
83f671
+  call delete('Xresult')
83f671
+endfunc
83f671
+
83f671
 
83f671
 " vim: shiftwidth=2 sts=2 expandtab
83f671
-- 
83f671
2.35.1
83f671