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

From: pillule <[email-masked]>
Date: Wed, 12 May 2021 11:25:51 +0000

martin rudalics <[email-masked]> writes:

>> 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.
>
> LGTM.  Can you please provide a ChangeLog entry and add a short 
> comment
> in the code that mentions the bug number of your report.

Looking at the CONTRIBUTE file, I have done this new version with 
`git format-patch -l1',
Is that overall better ?

>From b0e58a68a2f67b3ef2b2467f6473929fc6a720e9 Mon Sep 17 00:00:00 2001
From: Trust me I am a doctor <[email-masked]>
Date: Wed, 12 May 2021 10:23:39 +0000
Subject: [PATCH 1/2] Unjam quit-restore-window (bug #48367)

Deleting previous buffers of a window may result in a state where
quit-window have no more effect, using the variable `prev-buffer', we
can avoid it by asking to simply close the window in this case.
---
 lisp/window.el | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lisp/window.el b/lisp/window.el
index db62d3308f..24b5df3396 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -5114,7 +5114,10 @@ nil means to not handle the buffer in a particular way.  This
       (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)
+        ;; delete the window if there is no previous-buffer (bug #48367)
+        (window--delete window nil (eq bury-or-kill 'kill)))))
 
     ;; Deal with the buffer.
     (cond
-- 
2.20.1

>From 55ec1b7a2ba50be0b55cc32601a88ec554c19034 Mon Sep 17 00:00:00 2001
From: Trust me I am a doctor <[email-masked]>
Date: Wed, 12 May 2021 10:34:40 +0000
Subject: [PATCH 2/2] Clarifying code of quit-restore-window

Still (bug #48367)

This portion may be expressed more succinctly with an higher function.
---
 lisp/window.el | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/lisp/window.el b/lisp/window.el
index 24b5df3396..a530761028 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -5036,14 +5036,9 @@ nil means to not handle the buffer in a particular way.  This
   (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)
-- 
2.20.1

Is that OK to call a cl-lib function in the second patch even if 
this library is not required in window.el ?

> Also, have you signed the copyright agreement for Emacs?  How 
> should I
> call you in the commit?  "pillule"?

No, I have not yet signed the agreement, I contact [email-masked] 
today to do so. I was hoping sloppily that you consider these 
contributions as trivial.

If it is fine for you to use my pseudonym, it is fine for me.

--