From e11331ed716c97d7cb1306037a60c31bc189af6d Mon Sep 17 00:00:00 2001 From: Tom Gillespie 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. 'display-buffer-pop-up-window' is used to split the window in this case so that permenent changes are not made to the window layout. 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..86c26d3a087 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 (display-buffer-pop-up-window buffer 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