diff options
author | Martin Rudalics <rudalics@gmx.at> | 2019-07-19 10:08:08 +0200 |
---|---|---|
committer | Martin Rudalics <rudalics@gmx.at> | 2019-07-19 10:08:08 +0200 |
commit | 8d34cb3f07ddddac015e2cf115e19e9423e40cc4 (patch) | |
tree | 4084b5203a41ce941013b8556ab3eb5af7b99eaf /lisp/window.el | |
parent | 8f54998827e416fe1fca7bc384bf0a6281b73f1b (diff) | |
download | emacs-8d34cb3f07ddddac015e2cf115e19e9423e40cc4.tar.gz |
Have 'display-buffer-reuse-window' prefer window on selected frame (Bug#36680)
* lisp/window.el (display-buffer-reuse-window): Preferably reuse
window on selected frame (Bug#36680).
* doc/lispref/windows.texi (Buffer Display Action Functions): Say
that 'display-buffer-reuse-window' prefers window on the selected
frame.
Diffstat (limited to 'lisp/window.el')
-rw-r--r-- | lisp/window.el | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/lisp/window.el b/lisp/window.el index 726d022dfe9..8cb9670ae47 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -7332,25 +7332,26 @@ return nil." (defun display-buffer-reuse-window (buffer alist) "Return a window that is already displaying BUFFER. -Return nil if no usable window is found. +Preferably use a window on the selected frame if such a window +exists. Return nil if no usable window is found. -If ALIST has a non-nil `inhibit-same-window' entry, the selected +If ALIST has a non-nil 'inhibit-same-window' entry, the selected window is not eligible for reuse. -If ALIST contains a `reusable-frames' entry, its value determines +If ALIST contains a 'reusable-frames' entry, its value determines which frames to search for a reusable window: nil -- the selected frame (actually the last non-minibuffer frame) A frame -- just that frame - `visible' -- all visible frames + 'visible' -- all visible frames 0 -- all frames on the current terminal t -- all frames. -If ALIST contains no `reusable-frames' entry, search just the +If ALIST contains no 'reusable-frames' entry, search just the selected frame if `display-buffer-reuse-frames' and `pop-up-frames' are both nil; search all frames on the current terminal if either of those variables is non-nil. -If ALIST has a non-nil `inhibit-switch-frame' entry, then in the +If ALIST has a non-nil 'inhibit-switch-frame' entry, then in the event that a window on another frame is chosen, avoid raising that frame." (let* ((alist-entry (assq 'reusable-frames alist)) @@ -7364,9 +7365,21 @@ that frame." (window (if (and (eq buffer (window-buffer)) (not (cdr (assq 'inhibit-same-window alist)))) (selected-window) - (car (delq (selected-window) - (get-buffer-window-list buffer 'nomini - frames)))))) + ;; Preferably use a window on the selected frame, + ;; if such a window exists (Bug#36680). + (let* ((windows (delq (selected-window) + (get-buffer-window-list + buffer 'nomini frames))) + (first (car windows)) + (this-frame (selected-frame))) + (cond + ((eq (window-frame first) this-frame) + first) + ((catch 'found + (dolist (next (cdr windows)) + (when (eq (window-frame next) this-frame) + (throw 'found next))))) + (t first)))))) (when (window-live-p window) (prog1 (window--display-buffer buffer window 'reuse alist) (unless (cdr (assq 'inhibit-switch-frame alist)) |