Subject: bug#48367: closed (Re: bug#48367: 28.0.50; quit-restore-window may jam)

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 15 May 2021 10:35:01 +0000

Your bug report

#48367: 28.0.50; quit-restore-buffer may jam

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
48367: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=48367
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#48367: 28.0.50; quit-restore-window may jam
From: pillule <[email-masked]>
To: [email-masked]
Cc: pillule <[email-masked]>, [email-masked]
Date: Sat, 15 May 2021 10:34:16 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

martin rudalics <[email-masked]> writes:

>> Here an alternative version using subr.el instead :
>
> I've pushed this and the other change now to master in commit
> 0a681590268a4039f95a5a919b6b6d4f4e880d4c, converting your 
> ChangeLog
> exercises to our style.  Please have a look and close this bug 
> if
> everything is alright.

Looks fine to me, thanks.

Looking at https://debbugs.gnu.org/Developer.html how to close 
this bug, I hope it worked.

-- 

Subject: 28.0.50; quit-restore-buffer may jam
From: pillule <[email-masked]>
To: [email-masked]
Date: Tue, 11 May 2021 20:26:08 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

Hello there,

I think there is a small bug with quit-window / 
quit-restore-window :

with emacs -Q

;; set some rules
(setq display-buffer-alist
      '(("\\*\\(Backtrace\\|Messages\\)\\*"
        (display-buffer-in-side-window)
        (window-height . 0.2)
        (side . bottom))))

;; trigger a logical error to display the *Backtrace* buffer
(> vim emacs)

;; display the *Messages* buffer
(view-echo-area-messages)

;; mess the `quit-restore' window parameter
(kill-buffer (get-buffer "*Backtrace*"))

;; which looks now like that in the *Messages* window :
;; ((quit-restore) (window-slot . 0) (window-side . bottom))

;; try to quit the *Messages* window
(progn (select-window (view-echo-area-messages))
       (quit-window))

;; nothing happens :

The first `cond' of quit-restore-window end up to 't,
it calls (switch-to-prev-buffer window bury-or-kill)
but there is no previous-window available.

The first patch adress this, and a similar one : when there is a previous-buffer available, but it referes to the 
same buffer. (eg: try the recipe again but exchange the role of 
*Messages* and *Backtrace*, you will finish with a blank buffer for backtrace, that you can quit again to end up to the same point)

The second patch is a proposition to clarify a little the code.

diff -u --label /usr/share/emacs/28.0.50/lisp/window.el.gz --label /home/user/src/patches/window.el /tmp/jka-comHlW7wF /home/user/src/patches/window.el
--- /usr/share/emacs/28.0.50/lisp/window.el.gz
+++ /home/user/src/patches/window.el
@@ -5151,7 +5151,9 @@
       (set-window-parameter window 'quit-restore nil)
       ;; Make sure that WINDOW is no more dedicated.
       (set-window-dedicated-p window nil)
-      (switch-to-prev-buffer window bury-or-kill)))
+      (if prev-buffer
+          (switch-to-prev-buffer window bury-or-kill)
+        (window--delete window nil (eq bury-or-kill 'kill)))))
 
     ;; Deal with the buffer.
     (cond

Diff finished.  Tue May 11 21:26:38 2021
diff -u --label /usr/share/emacs/28.0.50/lisp/window.el.gz --label /home/user/src/patches/window.el /tmp/jka-comAXCNZa /home/user/src/patches/window.el
--- /usr/share/emacs/28.0.50/lisp/window.el.gz
+++ /home/user/src/patches/window.el
@@ -5073,14 +5073,9 @@
   (setq window (window-normalize-window window t))
   (let* ((buffer (window-buffer window))
 	 (quit-restore (window-parameter window 'quit-restore))
-	 (prev-buffer
-	  (let* ((prev-buffers (window-prev-buffers window))
-		 (prev-buffer (caar prev-buffers)))
-	    (and (or (not (eq prev-buffer buffer))
-		     (and (cdr prev-buffers)
-			  (not (eq (setq prev-buffer (cadr prev-buffers))
-				   buffer))))
-		 prev-buffer)))
+	 (prev-buffer (car (cl-find-if-not
+                            (lambda (buf) (eq (car buf) buffer))
+                            (window-prev-buffers window))))
 	 quad entry)
     (cond
      ((and (not prev-buffer)

Diff finished.  Tue May 11 22:00:30 2021

--