all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] Fix display-buffer-use-some-window to honor reusable-frames
@ 2023-01-27  5:17 Tom Gillespie
  2023-01-27  5:25 ` Tom Gillespie
  0 siblings, 1 reply; 49+ messages in thread
From: Tom Gillespie @ 2023-01-27  5:17 UTC (permalink / raw)
  To: Emacs developers; +Cc: Lars Ingebrigtsen

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

Hi,
   Here is a patch to fix strange and disruptive behavior
caused by a bug in display-buffer-use-least-recent-window
and display-buffer-use-some-window. I have made the patch
against the emacs-29 branch. A detailed explanation is in
the commit message. Best!
Tom

[-- Attachment #2: 0001-Fix-display-buffer-use-some-window-to-honor-reusable.patch --]
[-- Type: text/x-patch, Size: 3706 bytes --]

From 60cc79088e440e66d24d4c13d91c4d3c8e44bda3 Mon Sep 17 00:00:00 2001
From: Tom Gillespie <tgbugs@gmail.com>
Date: Thu, 26 Jan 2023 23:47:22 -0500
Subject: [PATCH] Fix display-buffer-use-some-window to honor reusable-frames
 setting.

* lisp/window.el (display-buffer-use-some-window): Honor user supplied
reusable-frames setting if it is present in the alist.
* lisp/window.el (display-buffer-use-least-recent-window): Set
reusable-frames nil unless it is already present in the alist.

The docs for 'display-buffer-use-least-recent-window' state that it
will pick the least recently used window or and if there is only a
single window it will split the window.

Prior to this commit that behavior was impossible to achieve because
'display-buffer-use-some-window' would attempt to find a valid window
in other frames. The old behavior is retained when reusable-frames is
not explicitly included in the alist. When reusable-frames is provided
in the alist then 'display-buffer-use-some-window' honors that and
will split the window if the value is (reusable-frames . nil) since
the user's intention is clear, they do not want to reuse some other
frame.

This makes it possible to obtain the documented behavior for
'display-buffer-use-least-recent-window' by adding reusable-frames nil
to the alist if it is absent.

I'm not sure that this behavior is exactly correct, but it prevents
the insanity of having multiple random windows in random frames
changed to the buffer to be displayed, destroying whatever state the
user was maintaining in those windows.
---
 lisp/window.el | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/lisp/window.el b/lisp/window.el
index 0cd30822ff6..9bdcf7b8b36 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -8509,7 +8509,11 @@ display-buffer-use-least-recent-window
 when displaying buffers repeatedly, and if there's only a single
 window, it will split the window."
   (when-let ((window (display-buffer-use-some-window
-                      buffer (cons (cons 'inhibit-same-window t) alist))))
+                      buffer
+                      (let ((alist (cons (cons 'inhibit-same-window t) alist)))
+                        (if (assq 'reusable-frames alist)
+                            alist
+                          (cons (cons 'reusable-frames nil) alist))))))
     (window-bump-use-time window)))
 
 (defun display-buffer-use-some-window (buffer alist)
@@ -8530,11 +8534,27 @@ display-buffer-use-some-window
 called only by `display-buffer' or a function directly or
 indirectly called by the latter."
   (let* ((not-this-window (cdr (assq 'inhibit-same-window alist)))
+         (explicit-reusable-frames (assq 'reusable-frames alist))
+         (reusable-frames (cdr explicit-reusable-frames))
 	 (frame (or (window--frame-usable-p (selected-frame))
 		    (window--frame-usable-p (last-nonminibuffer-frame))))
 	 (window
 	  ;; Reuse an existing window.
 	  (or (get-lru-window frame nil not-this-window)
+          (and
+           explicit-reusable-frames
+           (or
+            (and
+             (not reusable-frames)
+             (let ((window (window--try-to-split-window (selected-window) alist)))
+               (unless (and not-this-window
+			                (eq window (selected-window)))
+		         window)))
+            (let ((window (get-buffer-window buffer reusable-frames)))
+		      (unless (and not-this-window
+			               (eq window (selected-window)))
+		        window))
+            (display-buffer-no-window buffer alist)))
 	      (let ((window (get-buffer-window buffer 'visible)))
 		(unless (and not-this-window
 			     (eq window (selected-window)))
-- 
2.39.1


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

end of thread, other threads:[~2023-02-21 12:02 UTC | newest]

Thread overview: 49+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-27  5:17 [PATCH] Fix display-buffer-use-some-window to honor reusable-frames Tom Gillespie
2023-01-27  5:25 ` Tom Gillespie
2023-01-27  6:19   ` Tom Gillespie
2023-01-27 13:03     ` Eli Zaretskii
2023-01-28 10:46       ` martin rudalics
2023-01-28 11:12         ` Eli Zaretskii
2023-01-28 15:35           ` martin rudalics
2023-01-28 16:02             ` Eli Zaretskii
2023-01-29 17:39               ` martin rudalics
2023-01-29 18:41                 ` Eli Zaretskii
2023-01-29 18:50                   ` Tom Gillespie
2023-01-30 16:43                   ` martin rudalics
2023-01-30 17:38                     ` Eli Zaretskii
2023-01-30 17:57                       ` martin rudalics
2023-01-30 18:04                         ` Eli Zaretskii
2023-01-31  8:45                           ` martin rudalics
2023-01-31 14:01                             ` Eli Zaretskii
2023-02-01 10:45                               ` martin rudalics
2023-02-01 17:38                                 ` Eli Zaretskii
2023-02-01 18:33                                   ` martin rudalics
2023-01-28 19:04         ` Tom Gillespie
2023-01-28 20:01           ` Tom Gillespie
2023-01-29 17:39             ` martin rudalics
2023-01-29 19:02               ` Tom Gillespie
2023-01-30 16:44                 ` martin rudalics
2023-01-30 17:43                   ` Tom Gillespie
2023-01-30 17:58                     ` martin rudalics
2023-01-30 19:40                       ` Tom Gillespie
2023-01-30 22:45                         ` Tom Gillespie
2023-01-31  8:46                           ` martin rudalics
2023-01-31 18:38                             ` Tom Gillespie
2023-02-01  9:08                               ` martin rudalics
2023-02-01 17:19                                 ` Tom Gillespie
2023-02-01 18:32                                   ` martin rudalics
2023-02-02 16:39                                     ` martin rudalics
2023-02-02 19:57                                       ` Tom Gillespie
2023-02-03  9:09                                         ` martin rudalics
2023-02-11 15:44                                           ` Eli Zaretskii
2023-02-11 18:15                                           ` Tom Gillespie
2023-02-12  9:33                                             ` martin rudalics
2023-02-18 17:46                                               ` Eli Zaretskii
2023-02-20  9:03                                                 ` martin rudalics
2023-02-20 11:55                                                   ` Eli Zaretskii
2023-02-20 18:14                                                     ` martin rudalics
2023-02-21 12:02                                                       ` Eli Zaretskii
2023-01-31  8:46                         ` martin rudalics
2023-01-29 17:48         ` Juri Linkov
2023-01-29 18:48           ` Eli Zaretskii
2023-02-06 10:01         ` martin rudalics

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.