unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#48367: 28.0.50; quit-restore-buffer may jam
@ 2021-05-11 20:26 pillule
  2021-05-12  8:47 ` martin rudalics
  0 siblings, 1 reply; 8+ messages in thread
From: pillule @ 2021-05-11 20:26 UTC (permalink / raw)
  To: 48367

[-- Attachment #1: Type: text/plain, Size: 1289 bytes --]


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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: quit-restore-window-patch1 --]
[-- Type: text/x-diff, Size: 690 bytes --]

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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: quit-restore-window-patch2 --]
[-- Type: text/x-diff, Size: 952 bytes --]

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

[-- Attachment #4: Type: text/plain, Size: 4 bytes --]


--

^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#48367: 28.0.50; quit-restore-buffer may jam
  2021-05-11 20:26 bug#48367: 28.0.50; quit-restore-buffer may jam pillule
@ 2021-05-12  8:47 ` martin rudalics
  2021-05-12 11:25   ` bug#48367: 28.0.50; quit-restore-window " pillule
  0 siblings, 1 reply; 8+ messages in thread
From: martin rudalics @ 2021-05-12  8:47 UTC (permalink / raw)
  To: pillule, 48367

 > 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.

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

And please try to avoid putting your local settings in diffs as with

--- /usr/share/emacs/28.0.50/lisp/window.el.gz
+++ /home/user/src/patches/window.el

Many thanks, martin





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#48367: 28.0.50; quit-restore-window may jam
  2021-05-12  8:47 ` martin rudalics
@ 2021-05-12 11:25   ` pillule
  2021-05-12 12:32     ` martin rudalics
  0 siblings, 1 reply; 8+ messages in thread
From: pillule @ 2021-05-12 11:25 UTC (permalink / raw)
  To: martin rudalics; +Cc: pillule, 48367

[-- Attachment #1: Type: text/plain, Size: 699 bytes --]


martin rudalics <rudalics@gmx.at> 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 ?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: reformated-patchs --]
[-- Type: text/x-diff, Size: 2460 bytes --]

From b0e58a68a2f67b3ef2b2467f6473929fc6a720e9 Mon Sep 17 00:00:00 2001
From: Trust me I am a doctor <pillule@riseup.net>
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 <pillule@riseup.net>
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


[-- Attachment #3: Type: text/plain, Size: 455 bytes --]


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 assign@gnu.org 
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.


-- 



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* bug#48367: 28.0.50; quit-restore-window may jam
  2021-05-12 11:25   ` bug#48367: 28.0.50; quit-restore-window " pillule
@ 2021-05-12 12:32     ` martin rudalics
  2021-05-12 14:10       ` pillule
  0 siblings, 1 reply; 8+ messages in thread
From: martin rudalics @ 2021-05-12 12:32 UTC (permalink / raw)
  To: pillule; +Cc: 48367

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

Yes.

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

No.  I only re-compiled and did not build.  Please try to avoid it since
otherwise we get a

In end of data:
../../lisp/window.el:5039:29: Warning: the function ‘cl-find-if-not’ is not
     known to be defined.

warning.

 >> 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 assign@gnu.org today to do so. I was hoping sloppily that you consider these contributions as trivial.

They are trivial and we don't need an assignment for them.  But signing
the agreement is always a good idea.

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

Then "pillule" be it.

Thanks again, martin






^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#48367: 28.0.50; quit-restore-window may jam
  2021-05-12 12:32     ` martin rudalics
@ 2021-05-12 14:10       ` pillule
  2021-05-12 16:40         ` martin rudalics
  2021-05-15  8:56         ` martin rudalics
  0 siblings, 2 replies; 8+ messages in thread
From: pillule @ 2021-05-12 14:10 UTC (permalink / raw)
  To: martin rudalics; +Cc: pillule, 48367

[-- Attachment #1: Type: text/plain, Size: 479 bytes --]


martin rudalics <rudalics@gmx.at> writes:

>> Is that OK to call a cl-lib function in the second patch even 
>> if this library is not required in window.el ?
>
> No.  I only re-compiled and did not build.  Please try to avoid 
> it since
> otherwise we get a
>
> In end of data:
> ../../lisp/window.el:5039:29: Warning: the function 
> ‘cl-find-if-not’ is not
>     known to be defined.
>
> warning.

Here an alternative version using subr.el instead :


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: quit-restore-patch-with-subr.el.patch --]
[-- Type: text/x-diff, Size: 1335 bytes --]

From 5c18c2b416b8fb6ef50dee6acc863130847eec03 Mon Sep 17 00:00:00 2001
From: Trust me I am a doctor <pillule@riseup.net>
Date: Wed, 12 May 2021 10:34:40 +0000
Subject: [PATCH] Clarifying code of quit-restore-window

Still (bug #48367)

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

diff --git a/lisp/window.el b/lisp/window.el
index 24b5df3396..914467aba0 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -5036,14 +5036,10 @@ 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 (catch 'prev-buffer
+                        (dolist (buf (window-prev-buffers window))
+                          (unless (eq (car buf) buffer)
+                            (throw 'prev-buffer (car buf))))))
 	 quad entry)
     (cond
      ((and (not prev-buffer)
-- 
2.20.1


[-- Attachment #3: Type: text/plain, Size: 175 bytes --]


> They are trivial and we don't need an assignment for them.  But 
> signing
> the agreement is always a good idea.

Ok, it's on its way.

Thank you for the guidance.

-- 



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* bug#48367: 28.0.50; quit-restore-window may jam
  2021-05-12 14:10       ` pillule
@ 2021-05-12 16:40         ` martin rudalics
  2021-05-15  8:56         ` martin rudalics
  1 sibling, 0 replies; 8+ messages in thread
From: martin rudalics @ 2021-05-12 16:40 UTC (permalink / raw)
  To: pillule; +Cc: 48367

 > Here an alternative version using subr.el instead :

OK.  I trust you that it works as intended.

martin





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#48367: 28.0.50; quit-restore-window may jam
  2021-05-12 14:10       ` pillule
  2021-05-12 16:40         ` martin rudalics
@ 2021-05-15  8:56         ` martin rudalics
  2021-05-15 10:34           ` pillule
  1 sibling, 1 reply; 8+ messages in thread
From: martin rudalics @ 2021-05-15  8:56 UTC (permalink / raw)
  To: pillule; +Cc: 48367

 > 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.

Thanks, martin





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#48367: 28.0.50; quit-restore-window may jam
  2021-05-15  8:56         ` martin rudalics
@ 2021-05-15 10:34           ` pillule
  0 siblings, 0 replies; 8+ messages in thread
From: pillule @ 2021-05-15 10:34 UTC (permalink / raw)
  To: 48367-close; +Cc: pillule


martin rudalics <rudalics@gmx.at> 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.

-- 







^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-05-15 10:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-11 20:26 bug#48367: 28.0.50; quit-restore-buffer may jam pillule
2021-05-12  8:47 ` martin rudalics
2021-05-12 11:25   ` bug#48367: 28.0.50; quit-restore-window " pillule
2021-05-12 12:32     ` martin rudalics
2021-05-12 14:10       ` pillule
2021-05-12 16:40         ` martin rudalics
2021-05-15  8:56         ` martin rudalics
2021-05-15 10:34           ` pillule

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).