diff options
| author | Nicolas Richard | 2016-03-01 12:33:05 +0100 |
|---|---|---|
| committer | Nicolas Richard | 2016-03-10 10:44:08 +0100 |
| commit | 2d382515bfdb44d585bda6515f8d03f9056a83ef (patch) | |
| tree | 2621ef82726cc75af6d82bdffdac4eac9c1e7f46 | |
| parent | f0b31080140217bf90772a39c66088069f466d8b (diff) | |
| download | emacs-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.
| -rw-r--r-- | doc/lispref/windows.texi | 17 | ||||
| -rw-r--r-- | lisp/window.el | 65 |
2 files changed, 82 insertions, 0 deletions
diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi index f215eb727a5..bb13934fb3a 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} | |||
| 2409 | entry (@pxref{Choosing Window Options}), raises that frame if necessary. | 2409 | entry (@pxref{Choosing Window Options}), raises that frame if necessary. |
| 2410 | @end defun | 2410 | @end defun |
| 2411 | 2411 | ||
| 2412 | @defun display-buffer-reuse-mode-window buffer alist | ||
| 2413 | This function tries to display @var{buffer} by finding a window | ||
| 2414 | that is displaying a buffer in a given mode. | ||
| 2415 | |||
| 2416 | If @var{alist} contains a @code{mode} entry, its value is a major mode | ||
| 2417 | (a symbol) or a list of major modes. If @var{alist} contains no | ||
| 2418 | @code{mode} entry, the current major mode of @var{buffer} is used. A | ||
| 2419 | window is a candidate if it displays a buffer that derives from one of | ||
| 2420 | the given modes. | ||
| 2421 | |||
| 2422 | The behaviour is also controlled by entries for | ||
| 2423 | @code{inhibit-same-window}, @code{reusable-frames} and | ||
| 2424 | @code{inhibit-switch-frame} as is done in the function | ||
| 2425 | @code{display-buffer-reuse-window}. | ||
| 2426 | |||
| 2427 | @end defun | ||
| 2428 | |||
| 2412 | @defun display-buffer-pop-up-frame buffer alist | 2429 | @defun display-buffer-pop-up-frame buffer alist |
| 2413 | This function creates a new frame, and displays the buffer in that | 2430 | This function creates a new frame, and displays the buffer in that |
| 2414 | frame's window. It actually performs the frame creation by calling | 2431 | frame's window. It actually performs the frame creation by calling |
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. | ||
| 6726 | Display BUFFER in the returned window. Return nil if no usable | ||
| 6727 | window is found. | ||
| 6728 | |||
| 6729 | If ALIST contains a `mode' entry, its value is a major mode (a | ||
| 6730 | symbol) or a list of modes. A window is a candidate if it | ||
| 6731 | displays a buffer that derives from one of the given modes. When | ||
| 6732 | ALIST contains no `mode' entry, the current major mode of BUFFER | ||
| 6733 | is used. | ||
| 6734 | |||
| 6735 | The 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. |
| 6726 | If `special-display-p' returns non-nil for BUFFER, return an | 6791 | If `special-display-p' returns non-nil for BUFFER, return an |