aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorNicolas Richard2016-03-01 12:33:05 +0100
committerNicolas Richard2016-03-10 10:44:08 +0100
commit2d382515bfdb44d585bda6515f8d03f9056a83ef (patch)
tree2621ef82726cc75af6d82bdffdac4eac9c1e7f46 /lisp
parentf0b31080140217bf90772a39c66088069f466d8b (diff)
downloademacs-2d382515bfdb44d585bda6515f8d03f9056a83ef.tar.gz
emacs-2d382515bfdb44d585bda6515f8d03f9056a83ef.zip
Add new function display-buffer-reuse-mode-window
* lisp/window.el (display-buffer-reuse-mode-window): New function. * doc/lispref/windows.texi (Display Action Functions): Document it.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/window.el65
1 files changed, 65 insertions, 0 deletions
diff --git a/lisp/window.el b/lisp/window.el
index c45e60e6204..28632a31eee 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -6721,6 +6721,71 @@ that frame."
6721 (unless (cdr (assq 'inhibit-switch-frame alist)) 6721 (unless (cdr (assq 'inhibit-switch-frame alist))
6722 (window--maybe-raise-frame (window-frame window))))))) 6722 (window--maybe-raise-frame (window-frame window)))))))
6723 6723
6724(defun display-buffer-reuse-mode-window (buffer alist)
6725 "Return a window based on the mode of the buffer it displays.
6726Display BUFFER in the returned window. Return nil if no usable
6727window is found.
6728
6729If ALIST contains a `mode' entry, its value is a major mode (a
6730symbol) or a list of modes. A window is a candidate if it
6731displays a buffer that derives from one of the given modes. When
6732ALIST contains no `mode' entry, the current major mode of BUFFER
6733is used.
6734
6735The behaviour is also controlled by entries for
6736`inhibit-same-window', `reusable-frames' and
6737`inhibit-switch-frame' as is done in the function
6738`display-buffer-reuse-window'."
6739 (let* ((alist-entry (assq 'reusable-frames alist))
6740 (alist-mode-entry (assq 'mode alist))
6741 (frames (cond (alist-entry (cdr alist-entry))
6742 ((if (eq pop-up-frames 'graphic-only)
6743 (display-graphic-p)
6744 pop-up-frames)
6745 0)
6746 (display-buffer-reuse-frames 0)
6747 (t (last-nonminibuffer-frame))))
6748 (inhibit-same-window-p (cdr (assq 'inhibit-same-window alist)))
6749 (windows (window-list-1 nil 'nomini frames))
6750 (buffer-mode (with-current-buffer buffer major-mode))
6751 (allowed-modes (if alist-mode-entry
6752 (cdr alist-mode-entry)
6753 buffer-mode))
6754 (curwin (selected-window))
6755 (curframe (selected-frame)))
6756 (unless (listp allowed-modes)
6757 (setq allowed-modes (list allowed-modes)))
6758 (let (same-mode-same-frame
6759 same-mode-other-frame
6760 derived-mode-same-frame
6761 derived-mode-other-frame)
6762 (dolist (window windows)
6763 (let (mode? frame?)
6764 (with-current-buffer (window-buffer window)
6765 (setq mode?
6766 (cond ((memq major-mode allowed-modes)
6767 'same)
6768 ((derived-mode-p allowed-modes)
6769 'derived))))
6770 (when (and mode?
6771 (not (and inhibit-same-window-p
6772 (eq window curwin))))
6773 (if (eq curframe (window-frame window))
6774 (if (eq mode? 'same)
6775 (push window same-mode-same-frame)
6776 (push window derived-mode-same-frame))
6777 (if (eq mode? 'same)
6778 (push window same-mode-other-frame)
6779 (push window derived-mode-other-frame))))))
6780 (let ((window (car (nconc same-mode-same-frame
6781 same-mode-other-frame
6782 derived-mode-same-frame
6783 derived-mode-other-frame))))
6784 (when (window-live-p window)
6785 (prog1 (window--display-buffer buffer window 'reuse alist)
6786 (unless (cdr (assq 'inhibit-switch-frame alist))
6787 (window--maybe-raise-frame (window-frame window)))))))))
6788
6724(defun display-buffer--special-action (buffer) 6789(defun display-buffer--special-action (buffer)
6725 "Return special display action for BUFFER, if any. 6790 "Return special display action for BUFFER, if any.
6726If `special-display-p' returns non-nil for BUFFER, return an 6791If `special-display-p' returns non-nil for BUFFER, return an