diff options
| -rw-r--r-- | doc/lispref/windows.texi | 3 | ||||
| -rw-r--r-- | lisp/window.el | 31 |
2 files changed, 24 insertions, 10 deletions
diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi index b5ca053e466..1035739e2b0 100644 --- a/doc/lispref/windows.texi +++ b/doc/lispref/windows.texi | |||
| @@ -2536,7 +2536,8 @@ to another buffer (@pxref{Dedicated Windows}). It also fails if | |||
| 2536 | 2536 | ||
| 2537 | @defun display-buffer-reuse-window buffer alist | 2537 | @defun display-buffer-reuse-window buffer alist |
| 2538 | This function tries to display @var{buffer} by finding a window that | 2538 | This function tries to display @var{buffer} by finding a window that |
| 2539 | is already displaying it. | 2539 | is already displaying it. Windows on the selected frame are preferred |
| 2540 | to windows on other frames. | ||
| 2540 | 2541 | ||
| 2541 | If @var{alist} has a non-@code{nil} @code{inhibit-same-window} entry, | 2542 | If @var{alist} has a non-@code{nil} @code{inhibit-same-window} entry, |
| 2542 | the selected window is not eligible for reuse. The set of frames to | 2543 | the selected window is not eligible for reuse. The set of frames to |
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." | |||
| 7332 | 7332 | ||
| 7333 | (defun display-buffer-reuse-window (buffer alist) | 7333 | (defun display-buffer-reuse-window (buffer alist) |
| 7334 | "Return a window that is already displaying BUFFER. | 7334 | "Return a window that is already displaying BUFFER. |
| 7335 | Return nil if no usable window is found. | 7335 | Preferably use a window on the selected frame if such a window |
| 7336 | exists. Return nil if no usable window is found. | ||
| 7336 | 7337 | ||
| 7337 | If ALIST has a non-nil `inhibit-same-window' entry, the selected | 7338 | If ALIST has a non-nil 'inhibit-same-window' entry, the selected |
| 7338 | window is not eligible for reuse. | 7339 | window is not eligible for reuse. |
| 7339 | 7340 | ||
| 7340 | If ALIST contains a `reusable-frames' entry, its value determines | 7341 | If ALIST contains a 'reusable-frames' entry, its value determines |
| 7341 | which frames to search for a reusable window: | 7342 | which frames to search for a reusable window: |
| 7342 | nil -- the selected frame (actually the last non-minibuffer frame) | 7343 | nil -- the selected frame (actually the last non-minibuffer frame) |
| 7343 | A frame -- just that frame | 7344 | A frame -- just that frame |
| 7344 | `visible' -- all visible frames | 7345 | 'visible' -- all visible frames |
| 7345 | 0 -- all frames on the current terminal | 7346 | 0 -- all frames on the current terminal |
| 7346 | t -- all frames. | 7347 | t -- all frames. |
| 7347 | 7348 | ||
| 7348 | If ALIST contains no `reusable-frames' entry, search just the | 7349 | If ALIST contains no 'reusable-frames' entry, search just the |
| 7349 | selected frame if `display-buffer-reuse-frames' and | 7350 | selected frame if `display-buffer-reuse-frames' and |
| 7350 | `pop-up-frames' are both nil; search all frames on the current | 7351 | `pop-up-frames' are both nil; search all frames on the current |
| 7351 | terminal if either of those variables is non-nil. | 7352 | terminal if either of those variables is non-nil. |
| 7352 | 7353 | ||
| 7353 | If ALIST has a non-nil `inhibit-switch-frame' entry, then in the | 7354 | If ALIST has a non-nil 'inhibit-switch-frame' entry, then in the |
| 7354 | event that a window on another frame is chosen, avoid raising | 7355 | event that a window on another frame is chosen, avoid raising |
| 7355 | that frame." | 7356 | that frame." |
| 7356 | (let* ((alist-entry (assq 'reusable-frames alist)) | 7357 | (let* ((alist-entry (assq 'reusable-frames alist)) |
| @@ -7364,9 +7365,21 @@ that frame." | |||
| 7364 | (window (if (and (eq buffer (window-buffer)) | 7365 | (window (if (and (eq buffer (window-buffer)) |
| 7365 | (not (cdr (assq 'inhibit-same-window alist)))) | 7366 | (not (cdr (assq 'inhibit-same-window alist)))) |
| 7366 | (selected-window) | 7367 | (selected-window) |
| 7367 | (car (delq (selected-window) | 7368 | ;; Preferably use a window on the selected frame, |
| 7368 | (get-buffer-window-list buffer 'nomini | 7369 | ;; if such a window exists (Bug#36680). |
| 7369 | frames)))))) | 7370 | (let* ((windows (delq (selected-window) |
| 7371 | (get-buffer-window-list | ||
| 7372 | buffer 'nomini frames))) | ||
| 7373 | (first (car windows)) | ||
| 7374 | (this-frame (selected-frame))) | ||
| 7375 | (cond | ||
| 7376 | ((eq (window-frame first) this-frame) | ||
| 7377 | first) | ||
| 7378 | ((catch 'found | ||
| 7379 | (dolist (next (cdr windows)) | ||
| 7380 | (when (eq (window-frame next) this-frame) | ||
| 7381 | (throw 'found next))))) | ||
| 7382 | (t first)))))) | ||
| 7370 | (when (window-live-p window) | 7383 | (when (window-live-p window) |
| 7371 | (prog1 (window--display-buffer buffer window 'reuse alist) | 7384 | (prog1 (window--display-buffer buffer window 'reuse alist) |
| 7372 | (unless (cdr (assq 'inhibit-switch-frame alist)) | 7385 | (unless (cdr (assq 'inhibit-switch-frame alist)) |