[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 2d38251: Add new function display-buffer-reuse-mode
From: |
Nicolas Richard |
Subject: |
[Emacs-diffs] master 2d38251: Add new function display-buffer-reuse-mode-window |
Date: |
Thu, 10 Mar 2016 09:45:31 +0000 |
branch: master
commit 2d382515bfdb44d585bda6515f8d03f9056a83ef
Author: Nicolas Richard <address@hidden>
Commit: Nicolas Richard <address@hidden>
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.
---
doc/lispref/windows.texi | 17 ++++++++++++
lisp/window.el | 65 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 82 insertions(+), 0 deletions(-)
diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi
index f215eb7..bb13934 100644
--- a/doc/lispref/windows.texi
+++ b/doc/lispref/windows.texi
@@ -2409,6 +2409,23 @@ visible and, unless @var{alist} contains an
@code{inhibit-switch-frame}
entry (@pxref{Choosing Window Options}), raises that frame if necessary.
@end defun
address@hidden display-buffer-reuse-mode-window buffer alist
+This function tries to display @var{buffer} by finding a window
+that is displaying a buffer in a given mode.
+
+If @var{alist} contains a @code{mode} entry, its value is a major mode
+(a symbol) or a list of major modes. If @var{alist} contains no
address@hidden entry, the current major mode of @var{buffer} is used. A
+window is a candidate if it displays a buffer that derives from one of
+the given modes.
+
+The behaviour is also controlled by entries for
address@hidden, @code{reusable-frames} and
address@hidden as is done in the function
address@hidden
+
address@hidden defun
+
@defun display-buffer-pop-up-frame buffer alist
This function creates a new frame, and displays the buffer in that
frame's window. It actually performs the frame creation by calling
diff --git a/lisp/window.el b/lisp/window.el
index c45e60e..28632a3 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -6721,6 +6721,71 @@ that frame."
(unless (cdr (assq 'inhibit-switch-frame alist))
(window--maybe-raise-frame (window-frame window)))))))
+(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.
+
+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 behaviour 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'."
+ (let* ((alist-entry (assq 'reusable-frames alist))
+ (alist-mode-entry (assq 'mode 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))))
+ (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)))
+ (unless (listp allowed-modes)
+ (setq allowed-modes (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? frame?)
+ (with-current-buffer (window-buffer window)
+ (setq mode?
+ (cond ((memq major-mode allowed-modes)
+ 'same)
+ ((derived-mode-p allowed-modes)
+ 'derived))))
+ (when (and mode?
+ (not (and inhibit-same-window-p
+ (eq window curwin))))
+ (if (eq curframe (window-frame window))
+ (if (eq mode? 'same)
+ (push window same-mode-same-frame)
+ (push window derived-mode-same-frame))
+ (if (eq mode? 'same)
+ (push window same-mode-other-frame)
+ (push window 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)))))))))
+
(defun display-buffer--special-action (buffer)
"Return special display action for BUFFER, if any.
If `special-display-p' returns non-nil for BUFFER, return an
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master 2d38251: Add new function display-buffer-reuse-mode-window,
Nicolas Richard <=