Function: display-buffer-reuse-mode-window
display-buffer-reuse-mode-window is a byte-compiled function defined
in window.el.gz.
Signature
(display-buffer-reuse-mode-window BUFFER ALIST)
Documentation
Return a window based on the mode of the buffer it displays.
Display BUFFER in the returned window. Return nil if no usable window is found.
ALIST is an association list of action symbols and values. See Info node (elisp) Buffer Display Action Alists for details of such alists.
If ALIST contains a mode entry, its value is a major mode (a
symbol) or a list of modes. A window is a candidate if it
displays a buffer that derives from one of the given modes. When
ALIST contains no mode entry, the current major mode of BUFFER
is used.
The behavior is also controlled by entries for
inhibit-same-window, reusable-frames and
inhibit-switch-frame as is done in the function
display-buffer-reuse-window.
This is an action function for buffer display, see Info
node (elisp) Buffer Display Action Functions. It should be
called only by display-buffer or a function directly or
indirectly called by the latter.
Probably introduced at or before Emacs version 26.1.
Source Code
;; Defined in /usr/src/emacs/lisp/window.el.gz
(defun display-buffer-reuse-mode-window (buffer alist)
"Return a window based on the mode of the buffer it displays.
Display BUFFER in the returned window. Return nil if no usable
window is found.
ALIST is an association list of action symbols and values. See
Info node `(elisp) Buffer Display Action Alists' for details of
such alists.
If ALIST contains a `mode' entry, its value is a major mode (a
symbol) or a list of modes. A window is a candidate if it
displays a buffer that derives from one of the given modes. When
ALIST contains no `mode' entry, the current major mode of BUFFER
is used.
The behavior is also controlled by entries for
`inhibit-same-window', `reusable-frames' and
`inhibit-switch-frame' as is done in the function
`display-buffer-reuse-window'.
This is an action function for buffer display, see Info
node `(elisp) Buffer Display Action Functions'. It should be
called only by `display-buffer' or a function directly or
indirectly called by the latter."
(let* ((alist-entry (assq 'reusable-frames alist))
(alist-mode-entry (assq 'mode alist))
(frames (cond (alist-entry (cdr alist-entry))
((window--pop-up-frames alist)
0)
(display-buffer-reuse-frames 0)
(t (last-nonminibuffer-frame))))
(inhibit-same-window-p (cdr (assq 'inhibit-same-window alist)))
(windows (window-list-1 nil 'nomini frames))
(buffer-mode (with-current-buffer buffer major-mode))
(allowed-modes (if alist-mode-entry
(cdr alist-mode-entry)
buffer-mode))
(curwin (selected-window))
(curframe (selected-frame)))
(setq allowed-modes (ensure-list allowed-modes))
(let (same-mode-same-frame
same-mode-other-frame
derived-mode-same-frame
derived-mode-other-frame)
(dolist (window windows)
(let ((mode?
(with-current-buffer (window-buffer window)
(cond ((memq major-mode allowed-modes) 'same)
((derived-mode-p allowed-modes) 'derived)))))
(when (and mode?
(or (not (window-dedicated-p window))
(eq buffer (window-buffer window)))
(not (and inhibit-same-window-p
(eq window curwin))))
(push window (if (eq curframe (window-frame window))
(if (eq mode? 'same)
same-mode-same-frame
derived-mode-same-frame)
(if (eq mode? 'same)
same-mode-other-frame
derived-mode-other-frame))))))
(let ((window (car (nconc same-mode-same-frame
same-mode-other-frame
derived-mode-same-frame
derived-mode-other-frame))))
(when (window-live-p window)
(prog1 (window--display-buffer buffer window 'reuse alist)
(unless (cdr (assq 'inhibit-switch-frame alist))
(window--maybe-raise-frame (window-frame window)))))))))