--- a/lisp/window.el +++ b/lisp/window.el @@ -6371,6 +6371,10 @@ Recognized alist entries include: window that already displays the buffer. See `display-buffer-reuse-window'. + `previous-window' -- A window `display-buffer-in-previous-window' + should use or nil to not try finding such a + window. + `pop-up-frame-parameters' -- Value specifies an alist of frame parameters to give a new frame, if one is created. @@ -6678,43 +6682,47 @@ 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 `previous-window' entry, the window specified by -that entry will override any other window found by the methods -above, even if that window never showed BUFFER before." - (let* ((alist-entry (assq 'reusable-frames alist)) - (inhibit-same-window - (cdr (assq 'inhibit-same-window alist))) - (frames (cond - (alist-entry (cdr alist-entry)) - ((if (eq pop-up-frames 'graphic-only) - (display-graphic-p) - pop-up-frames) - 0) - (display-buffer-reuse-frames 0) - (t (last-nonminibuffer-frame)))) - best-window second-best-window window) - ;; Scan windows whether they have shown the buffer recently. - (catch 'best - (dolist (window (window-list-1 (frame-first-window) 'nomini frames)) - (when (and (assq buffer (window-prev-buffers window)) - (not (window-dedicated-p window))) - (if (eq window (selected-window)) - (unless inhibit-same-window - (setq second-best-window window)) - (setq best-window window) - (throw 'best t))))) - ;; When ALIST has a `previous-window' entry, that entry may override - ;; anything we found so far. - (when (and (setq window (cdr (assq 'previous-window alist))) - (window-live-p window) - (not (window-dedicated-p window))) - (if (eq window (selected-window)) - (unless inhibit-same-window - (setq second-best-window window)) - (setq best-window window))) - ;; Return best or second best window found. - (when (setq window (or best-window second-best-window)) - (window--display-buffer buffer window 'reuse alist)))) +If ALIST has a `previous-window' entry, the window specified in +the cdr of that entry will override any other window found by the +methods above, even if that window never showed BUFFER before. +If the cdr of that entry is nil, do not try to find a window that +previously showed BUFFER." + (unless (let ((previous-window (assq 'previous-window alist))) + (and previous-window (not (cdr previous-window)))) + (let* ((alist-entry (assq 'reusable-frames alist)) + (inhibit-same-window + (cdr (assq 'inhibit-same-window alist))) + (frames (cond + (alist-entry (cdr alist-entry)) + ((if (eq pop-up-frames 'graphic-only) + (display-graphic-p) + pop-up-frames) + 0) + (display-buffer-reuse-frames 0) + (t (last-nonminibuffer-frame)))) + best-window second-best-window window) + ;; Scan windows whether they have shown the buffer recently. + (catch 'best + (dolist (window (window-list-1 (frame-first-window) 'nomini frames)) + (when (and (assq buffer (window-prev-buffers window)) + (not (window-dedicated-p window))) + (if (eq window (selected-window)) + (unless inhibit-same-window + (setq second-best-window window)) + (setq best-window window) + (throw 'best t))))) + ;; When ALIST has a `previous-window' entry, that entry may override + ;; anything we found so far. + (when (and (setq window (cdr (assq 'previous-window alist))) + (window-live-p window) + (not (window-dedicated-p window))) + (if (eq window (selected-window)) + (unless inhibit-same-window + (setq second-best-window window)) + (setq best-window window))) + ;; Return best or second best window found. + (when (setq window (or best-window second-best-window)) + (window--display-buffer buffer window 'reuse alist))))) (defun display-buffer-use-some-window (buffer alist) "Display BUFFER in an existing window.