aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2011-09-01 22:23:43 -0400
committerChong Yidong2011-09-01 22:23:43 -0400
commit89894cd8be3e7d8f77474c9146ccad75cac07ddf (patch)
tree50f2f4d00f9cccaa4ee126c8abc205d541d6916b
parentae0bc9fbe51e3cb1b933fa610e799e30ad611094 (diff)
downloademacs-89894cd8be3e7d8f77474c9146ccad75cac07ddf.tar.gz
emacs-89894cd8be3e7d8f77474c9146ccad75cac07ddf.zip
Split default-buffer-default into separate display action components.
* lisp/window.el (display-buffer-alist): Doc fix. (display-buffer): Add docstring. Don't treat display-buffer-default specially. (display-buffer-reuse-selected-window) (display-buffer-same-window, display-buffer-maybe-same-window) (display-buffer-reuse-window, display-buffer-pop-up-frame) (display-buffer-pop-up-window) (display-buffer-reuse-or-pop-window) (display-buffer-use-some-window): New functions. (display-buffer-default-action): Use them. (display-buffer-default): Deleted. (pop-to-buffer-1): Fix choice of actions.
-rw-r--r--lisp/ChangeLog15
-rw-r--r--lisp/window.el514
2 files changed, 303 insertions, 226 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index a7d2083f4b1..7ea1dffe1c2 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,18 @@
12011-09-02 Chong Yidong <cyd@stupidchicken.com>
2
3 * window.el (display-buffer-alist): Doc fix.
4 (display-buffer): Add docstring. Don't treat
5 display-buffer-default specially.
6 (display-buffer-reuse-selected-window)
7 (display-buffer-same-window, display-buffer-maybe-same-window)
8 (display-buffer-reuse-window, display-buffer-pop-up-frame)
9 (display-buffer-pop-up-window)
10 (display-buffer-reuse-or-pop-window)
11 (display-buffer-use-some-window): New functions.
12 (display-buffer-default-action): Use them.
13 (display-buffer-default): Deleted.
14 (pop-to-buffer-1): Fix choice of actions.
15
12011-09-02 Stefan Monnier <monnier@iro.umontreal.ca> 162011-09-02 Stefan Monnier <monnier@iro.umontreal.ca>
2 17
3 * minibuffer.el (completion--insert-strings): Don't get confused by 18 * minibuffer.el (completion--insert-strings): Don't get confused by
diff --git a/lisp/window.el b/lisp/window.el
index 277b1fd5c09..b33c46acf93 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -4478,155 +4478,6 @@ Return WINDOW."
4478The actual non-nil value of this variable will be copied to the 4478The actual non-nil value of this variable will be copied to the
4479`window-dedicated-p' flag.") 4479`window-dedicated-p' flag.")
4480 4480
4481(defun display-buffer-default (buffer-or-name &optional not-this-window frame)
4482 "Make buffer BUFFER-OR-NAME appear in some window but don't select it.
4483BUFFER-OR-NAME must be a buffer or the name of an existing
4484buffer. Return the window chosen to display BUFFER-OR-NAME or
4485nil if no such window is found.
4486
4487Optional argument NOT-THIS-WINDOW non-nil means display the
4488buffer in a window other than the selected one, even if it is
4489already displayed in the selected window.
4490
4491Optional argument FRAME specifies which frames to investigate
4492when the specified buffer is already displayed. If the buffer is
4493already displayed in some window on one of these frames simply
4494return that window. Possible values of FRAME are:
4495
4496`visible' - consider windows on all visible frames on the current
4497terminal.
4498
44990 - consider windows on all visible or iconified frames on the
4500current terminal.
4501
4502t - consider windows on all frames.
4503
4504A specific frame - consider windows on that frame only.
4505
4506nil - consider windows on the selected frame \(actually the
4507last non-minibuffer frame\) only. If, however, either
4508`display-buffer-reuse-frames' or `pop-up-frames' is non-nil
4509\(non-nil and not graphic-only on a text-only terminal),
4510consider all visible or iconified frames on the current terminal."
4511 (interactive "BDisplay buffer:\nP")
4512 (let* ((can-use-selected-window
4513 ;; The selected window is usable unless either NOT-THIS-WINDOW
4514 ;; is non-nil, it is dedicated to its buffer, or it is the
4515 ;; `minibuffer-window'.
4516 (not (or not-this-window
4517 (window-dedicated-p (selected-window))
4518 (window-minibuffer-p))))
4519 (buffer (if (bufferp buffer-or-name)
4520 buffer-or-name
4521 (get-buffer buffer-or-name)))
4522 (name-of-buffer (buffer-name buffer))
4523 ;; On text-only terminals do not pop up a new frame when
4524 ;; `pop-up-frames' equals graphic-only.
4525 (use-pop-up-frames (if (eq pop-up-frames 'graphic-only)
4526 (display-graphic-p)
4527 pop-up-frames))
4528 ;; `frame-to-use' is the frame where to show `buffer' - either
4529 ;; the selected frame or the last nonminibuffer frame.
4530 (frame-to-use
4531 (or (window--frame-usable-p (selected-frame))
4532 (window--frame-usable-p (last-nonminibuffer-frame))))
4533 ;; `window-to-use' is the window we use for showing `buffer'.
4534 window-to-use popped-up-frame)
4535 (cond
4536 ((not (buffer-live-p buffer))
4537 (error "No such buffer %s" buffer))
4538 (display-buffer-function
4539 ;; Let `display-buffer-function' do the job.
4540 (funcall display-buffer-function buffer not-this-window))
4541 ((and (not not-this-window)
4542 (eq (window-buffer (selected-window)) buffer))
4543 ;; The selected window already displays BUFFER and
4544 ;; `not-this-window' is nil, so use it.
4545 (display-buffer-record-window 'reuse-window (selected-window) buffer)
4546 (window--display-buffer-1 (selected-window)))
4547 ((and can-use-selected-window (same-window-p name-of-buffer))
4548 ;; If the buffer's name tells us to use the selected window do so.
4549 (display-buffer-record-window 'reuse-window (selected-window) buffer)
4550 (window--display-buffer-2 buffer (selected-window)))
4551 ((let ((frames (or frame
4552 (and (or use-pop-up-frames
4553 display-buffer-reuse-frames
4554 (not (last-nonminibuffer-frame)))
4555 0)
4556 (last-nonminibuffer-frame))))
4557 (setq window-to-use
4558 (catch 'found
4559 ;; Search frames for a window displaying BUFFER. Return
4560 ;; the selected window only if we are allowed to do so.
4561 (dolist (window (get-buffer-window-list buffer 'nomini frames))
4562 (when (or can-use-selected-window
4563 (not (eq (selected-window) window)))
4564 (throw 'found window))))))
4565 ;; The buffer is already displayed in some window; use that.
4566 (display-buffer-record-window 'reuse-window window-to-use buffer)
4567 (window--display-buffer-1 window-to-use))
4568 ((and special-display-function
4569 ;; `special-display-p' returns either t or a list of frame
4570 ;; parameters to pass to `special-display-function'.
4571 (let ((pars (special-display-p name-of-buffer)))
4572 (when pars
4573 (funcall special-display-function
4574 buffer (if (listp pars) pars))))))
4575 ((or use-pop-up-frames (not frame-to-use))
4576 ;; We want or need a new frame.
4577 (setq window-to-use
4578 (frame-selected-window (funcall pop-up-frame-function)))
4579 (display-buffer-record-window 'pop-up-frame window-to-use buffer)
4580 (window--display-buffer-2 buffer window-to-use))
4581 ((and pop-up-windows
4582 ;; Make a new window.
4583 (or (not (frame-parameter frame-to-use 'unsplittable))
4584 ;; If the selected frame cannot be split look at
4585 ;; `last-nonminibuffer-frame'.
4586 (and (eq frame-to-use (selected-frame))
4587 (setq frame-to-use (last-nonminibuffer-frame))
4588 (window--frame-usable-p frame-to-use)
4589 (not (frame-parameter frame-to-use 'unsplittable))))
4590 ;; Attempt to split largest or least recently used window.
4591 (setq window-to-use
4592 (or (window--try-to-split-window
4593 (get-largest-window frame-to-use t))
4594 (window--try-to-split-window
4595 (get-lru-window frame-to-use t))))
4596 (display-buffer-record-window 'pop-up-window window-to-use buffer)
4597 (window--display-buffer-2 buffer window-to-use)))
4598 ((let ((window-to-undedicate
4599 ;; When NOT-THIS-WINDOW is non-nil, temporarily dedicate
4600 ;; the selected window to its buffer, to avoid that some of
4601 ;; the `get-' routines below choose it. (Bug#1415)
4602 (and not-this-window (not (window-dedicated-p))
4603 (set-window-dedicated-p (selected-window) t)
4604 (selected-window))))
4605 (unwind-protect
4606 (setq window-to-use
4607 ;; Reuse an existing window.
4608 (or (get-lru-window frame-to-use)
4609 (let ((window (get-buffer-window buffer 'visible)))
4610 (unless (and not-this-window
4611 (eq window (selected-window)))
4612 window))
4613 (get-largest-window 'visible)
4614 (let ((window (get-buffer-window buffer 0)))
4615 (unless (and not-this-window
4616 (eq window (selected-window)))
4617 window))
4618 (get-largest-window 0)
4619 (prog1
4620 (frame-selected-window (funcall pop-up-frame-function))
4621 (setq popped-up-frame t))))
4622 (when (window-live-p window-to-undedicate)
4623 ;; Restore dedicated status of selected window.
4624 (set-window-dedicated-p window-to-undedicate nil))))
4625 (display-buffer-record-window
4626 (if popped-up-frame 'pop-up-frame 'reuse-window) window-to-use buffer)
4627 (window--even-window-heights window-to-use)
4628 (window--display-buffer-2 buffer window-to-use)))))
4629
4630(defun window-normalize-buffer-to-display (buffer-or-name) 4481(defun window-normalize-buffer-to-display (buffer-or-name)
4631 "Normalize BUFFER-OR-NAME argument for buffer display functions. 4482 "Normalize BUFFER-OR-NAME argument for buffer display functions.
4632If BUFFER-OR-NAME is nil, return the curent buffer. Else, if a 4483If BUFFER-OR-NAME is nil, return the curent buffer. Else, if a
@@ -4641,24 +4492,52 @@ BUFFER-OR-NAME and return that buffer."
4641 (current-buffer))) 4492 (current-buffer)))
4642 4493
4643(defvar display-buffer-alist nil 4494(defvar display-buffer-alist nil
4644 "Specifications of user preferences for `display-buffer'. 4495 "Alist of conditional actions for `display-buffer'.
4645This is a list of elements of the form (CONDITION . ACTION) where 4496This is a list of elements (CONDITION . ACTION), where:
4646CONDITION is either a regexp matching buffer names, or a function 4497
4647that takes a buffer and returns a boolean. ACTION is a list of 4498 CONDITION is either a regexp matching buffer names, or a function
4648the form (FUNCTION . ALIST) where FUNCTION can be either a 4499 that takes a buffer and returns a boolean.
4649function or a list of functions. Those functions will be called 4500
4650with 2 arguments: the buffer to display and an ALIST built from 4501 ACTION is a cons cell (FUNCTION . ALIST), where FUNCTION is
4651the various alists specified in the various ACTIONs. It should 4502 either a function or a list of functions. Each such function
4652either return the window used, or nil to fallback to the next 4503 should accept 2 arguments: a buffer to display and an alist of
4653function.") 4504 the same form as ALIST. It should return the window used, or
4654 4505 nil if it fails to display the window. See `display-buffer'
4655(defvar display-buffer-default-action (list #'display-buffer-default) 4506 for more details.
4656 "Default action to perform to display a buffer. 4507
4657This is an ACTION just like in `display-buffer-alist'.") 4508Usable action functions include:
4658 4509 `display-buffer-reuse-selected-window'
4659(defvar display-buffer-overriding-action '(nil) 4510 `display-buffer-same-window'
4511 `display-buffer-maybe-same-window'
4512 `display-buffer-reuse-window'
4513 `display-buffer-pop-up-frame'
4514 `display-buffer-pop-up-window'
4515 `display-buffer-reuse-or-pop-window'
4516 `display-buffer-use-some-window'
4517
4518The above functions recognize the following alist entries:
4519 - `inhibit-same-window', if non-nil, prevents the same window
4520 from being used for display.
4521 - `reuse-frame' specifies the frames that can be searched for a
4522 window displaying the buffer. Its values have the same
4523 meaning as the ALL-FRAMES arg to `get-buffer-window-list'.")
4524
4525(defvar display-buffer-default-action
4526 '((display-buffer-reuse-selected-window
4527 display-buffer-maybe-same-window
4528 display-buffer-reuse-or-pop-window
4529 display-buffer-use-some-window
4530 ;; If all else fails, pop up a new frame regardless of
4531 ;; restrictions.
4532 display-buffer-pop-up-frame))
4533 "List of default actions for `display-buffer'.
4534It should be a cons cell of the form (FUNCTION . ALIST), which
4535has the same meaning as in `display-buffer-alist'.")
4536
4537(defvar display-buffer-overriding-action nil
4660 "Overriding action to perform to display a buffer. 4538 "Overriding action to perform to display a buffer.
4661This is an ACTION just like in `display-buffer-alist'.") 4539If non-nil, it should be a cons cell (FUNCTION . ALIST), which
4540has the same meaning as in `display-buffer-alist'.")
4662 4541
4663(defun display-buffer-assq-regexp (buffer-name alist) 4542(defun display-buffer-assq-regexp (buffer-name alist)
4664 "Retrieve ALIST entry corresponding to BUFFER-NAME." 4543 "Retrieve ALIST entry corresponding to BUFFER-NAME."
@@ -4673,46 +4552,72 @@ This is an ACTION just like in `display-buffer-alist'.")
4673 (throw 'match (cdr entry))))))) 4552 (throw 'match (cdr entry)))))))
4674 4553
4675(defun display-buffer (&optional buffer-or-name action frame) 4554(defun display-buffer (&optional buffer-or-name action frame)
4676 "Display BUFFER in some window." 4555 "Display BUFFER-OR-NAME in some window.
4556BUFFER-OR-NAME must be a buffer or the name of an existing
4557buffer. Return the window chosen for displaying BUFFER-OR-NAME,
4558or nil if no such window is found.
4559
4560Optional argument ACTION should have the form (FUNCTION . ALIST).
4561FUNCTION is either a function or a list of functions. Each such
4562function is called with 2 arguments: the buffer to display and an
4563alist. It should either display the buffer and return the
4564window, or return nil if it is unable to display the buffer.
4565
4566`display-buffer' constructs a list of action functions and an
4567action alist from `display-buffer-overriding-action',
4568`user-action', ACTION, and `display-buffer-default-action' (in
4569order). It calls each action function in turn, passing the
4570consolidated action alist as the second argument, until one of
4571the functions returns non-nil.
4572
4573ACTION can also have a non-nil and non-list value. This means to
4574display the buffer in a window other than the selected one, even
4575if it is already displayed in the selected window. If called
4576interactively with a prefix argument, ACTION is t.
4577
4578Optional argument FRAME specifies where to look for a window that
4579already displays the buffer. If nil, check only the selected
4580frame (actually the last non-minibuffer frame), except if
4581`display-buffer-reuse-frames' or `pop-up-frames' is non-nil
4582\(non-nil and not graphic-only on a text-only terminal), in which
4583case check all visible or iconified frames. Otherwise, FRAME can
4584be a specific frame, `visible' (all visible frames), 0 (all
4585frames on the current terminal), or t (all frames)."
4677 (interactive "BDisplay buffer:\nP") 4586 (interactive "BDisplay buffer:\nP")
4678 (let* ((buffer (window-normalize-buffer-to-display buffer-or-name)) 4587 (let ((buffer (window-normalize-buffer-to-display buffer-or-name))
4679 (buffer-name (buffer-name buffer)) 4588 ;; Handle the old form of the first argument.
4680 (user-action 4589 (inhibit-same-window (and action (not (listp action)))))
4681 (display-buffer-assq-regexp buffer-name display-buffer-alist)) 4590 (unless (listp action) (setq action nil))
4682 (functions 4591 (if display-buffer-function
4683 (append 4592 ;; If `display-buffer-function' is defined, let it do the job.
4684 (list (car display-buffer-overriding-action)) 4593 (funcall display-buffer-function buffer inhibit-same-window)
4685 (list (car user-action)) 4594 ;; Otherwise, use the defined actions.
4686 (and (listp action) (list (car action))) 4595 (let* ((user-action
4687 (list (car display-buffer-default-action)))) 4596 (display-buffer-assq-regexp (buffer-name buffer)
4688 (specifiers (append (cdr display-buffer-overriding-action) 4597 display-buffer-alist))
4689 (cdr user-action) 4598 ;; Extra actions from the arguments to this function:
4690 (and (listp action) (cdr action)) 4599 (extra-action
4691 (cdr display-buffer-default-action))) 4600 (cons nil (append (if inhibit-same-window
4692 function window) 4601 '((inhibit-same-window . t)))
4693 (while (and functions (not window)) 4602 (if frame
4694 (setq function (car functions)) 4603 `((reuse-frame . ,frame))))))
4695 (cond 4604 ;; Construct action function list and action alist.
4696 ((listp function) 4605 (actions (list display-buffer-overriding-action
4697 (while (and function (not window)) 4606 user-action action extra-action
4698 (cond 4607 display-buffer-default-action))
4699 ((eq (car function) 'display-buffer-default) 4608 (functions (apply 'append
4700 (setq window 4609 (mapcar (lambda (x)
4701 (display-buffer-default 4610 (setq x (car x))
4702 buffer (memq action '(t other-window)) frame))) 4611 (if (listp x) x (list x)))
4703 ((functionp (car function)) 4612 actions)))
4704 (setq window (funcall (car function) buffer specifiers)))) 4613 (alist (apply 'append (mapcar 'cdr actions)))
4705 (setq function (cdr function)))) 4614 window)
4706 ((eq function 'display-buffer-default) 4615 (unless (buffer-live-p buffer)
4707 (setq window 4616 (error "Invalid buffer"))
4708 (display-buffer-default 4617 (while (and functions (not window))
4709 buffer (memq action '(t other-window)) frame))) 4618 (setq window (funcall (car functions) buffer alist)
4710 ((functionp function) 4619 functions (cdr functions)))
4711 (setq window 4620 window))))
4712 (funcall function buffer specifiers))))
4713 (setq functions (cdr functions)))
4714
4715 window))
4716 4621
4717(defun display-buffer-other-frame (buffer) 4622(defun display-buffer-other-frame (buffer)
4718 "Display buffer BUFFER in another frame. 4623 "Display buffer BUFFER in another frame.
@@ -4737,24 +4642,182 @@ its documentation for additional customization information."
4737 ;;(make-frame-visible (window-frame old-window)) 4642 ;;(make-frame-visible (window-frame old-window))
4738 )) 4643 ))
4739 4644
4740;;; Functions for use via `display-buffer-alist'. 4645;;; `display-buffer' action functions:
4741 4646
4742(defun display-buffer-same-window (buffer alist) 4647(defun display-buffer-reuse-selected-window (buffer alist)
4743 "Display BUFFER in the selected window, and return the window. 4648 "Try to display BUFFER in the selected window if it is already there.
4744If BUFFER cannot be displayed in the selected window (usually 4649If this succeeds, return the selected window.
4745because it is dedicated to another buffer), return nil."
4746 (let ((norecord (cadr (assq 'norecord alist))))
4747 (cond
4748 ((eq buffer (window-buffer))
4749 (selected-window))
4750 ((not (or (window-minibuffer-p) (window-dedicated-p)))
4751 (set-window-buffer nil buffer)
4752 (selected-window)))))
4753 4650
4754(defun display-buffer-other-window (buffer alist) 4651This fails if BUFFER is not displayed in the selected window, or
4755 "Display BUFFER in another window, and return BUFFER. 4652if ALIST has a non-nil `inhibit-same-window' entry. In that
4756If BUFFER cannot be displayed in another window, just return nil." 4653case, return nil."
4757 (display-buffer-default buffer t)) 4654 (when (and (not (cdr (assq 'inhibit-same-window alist)))
4655 (eq buffer (window-buffer)))
4656 (display-buffer-record-window 'reuse-window (selected-window) buffer)
4657 (window--display-buffer-1 (selected-window))))
4658
4659(defun display-buffer-same-window (buffer alist)
4660 "Try to display BUFFER in the selected window.
4661If this succeeds, return the selected window.
4662
4663This fails if the selected window is a minibuffer window or is
4664dedicated to another buffer, or if ALIST has a non-nil
4665`inhibit-same-window' entry. In that case, return nil."
4666 (unless (or (cdr (assq 'inhibit-same-window alist))
4667 (window-minibuffer-p)
4668 (window-dedicated-p))
4669 (display-buffer-record-window 'reuse-window (selected-window) buffer)
4670 (window--display-buffer-2 buffer (selected-window))))
4671
4672(defun display-buffer-maybe-same-window (buffer alist)
4673 "Try to display BUFFER in the selected window.
4674This acts like `display-buffer-same-window', except that it also
4675fails if `same-window-p' returns nil for this buffer."
4676 (and (same-window-p (buffer-name buffer))
4677 (display-buffer-same-window buffer alist)))
4678
4679(defun display-buffer-reuse-window (buffer alist)
4680 "Return a window that is already displaying BUFFER.
4681If no usable window is found, return nil.
4682
4683If ALIST has a non-nil `inhibit-same-window' entry, the same
4684window cannot be reused.
4685
4686If ALIST contains a `reuse-frame' entry, that determines the
4687frames to check for a window displaying the buffer. If the entry
4688is omitted or the value is nil, check only this frame. The value
4689can also be a specific frame, `visible' (all visible frames),
46900 (all frames on the current terminal), or t (all frames)."
4691 (let* ((can-use-selected-window
4692 (not (cdr (assq 'inhibit-same-window alist))))
4693 (frames (or (cdr (assq 'reuse-frame alist))
4694 (last-nonminibuffer-frame)))
4695 (window (catch 'found
4696 (dolist (window (get-buffer-window-list
4697 buffer 'nomini frames))
4698 (when (or can-use-selected-window
4699 (not (eq (selected-window) window)))
4700 (throw 'found window))))))
4701 (when window
4702 (display-buffer-record-window 'reuse-window window buffer)
4703 (window--display-buffer-1 window))))
4704
4705(defun display-buffer-pop-up-frame (buffer alist)
4706 "Display BUFFER in a new frame.
4707This works by calling `pop-up-frame-function'. If sucessful,
4708return the window on the new frame; otherwise return nil."
4709 (let ((fun pop-up-frame-function)
4710 frame window)
4711 (when (and fun
4712 (setq frame (funcall fun))
4713 (setq window (frame-selected-window frame)))
4714 (display-buffer-record-window 'pop-up-frame window buffer)
4715 (window--display-buffer-2 buffer window))))
4716
4717(defun display-buffer-pop-up-window (buffer alist)
4718 "Display BUFFER by popping up a new window.
4719The new window is created on the selected frame, or in
4720`last-nonminibuffer-frame' if no windows can be created there.
4721If sucessful, return the new window; otherwise return nil."
4722 (let ((frame (or (window--frame-usable-p (selected-frame))
4723 (window--frame-usable-p (last-nonminibuffer-frame))))
4724 window)
4725 (when (and (or (not (frame-parameter frame 'unsplittable))
4726 ;; If the selected frame cannot be split, look at
4727 ;; `last-nonminibuffer-frame'.
4728 (and (eq frame (selected-frame))
4729 (setq frame (last-nonminibuffer-frame))
4730 (window--frame-usable-p frame)
4731 (not (frame-parameter frame 'unsplittable))))
4732 ;; Attempt to split largest or least recently used window.
4733 (setq window (or (window--try-to-split-window
4734 (get-largest-window frame t))
4735 (window--try-to-split-window
4736 (get-lru-window frame t)))))
4737 (display-buffer-record-window 'pop-up-window window buffer)
4738 (window--display-buffer-2 buffer window))))
4739
4740;; This display action function groups together some lower-level ones:
4741(defun display-buffer-reuse-or-pop-window (buffer alist)
4742 "Display BUFFER in some window other than the selected one.
4743This attempts to call the following functions (in order):
4744 - `display-buffer-reuse-window', ensuring that it checks all
4745 frames on this terminal if `display-buffer-reuse-frames' or
4746 `pop-up-frames' is non-nil.
4747 - `special-display-function', if it is available.
4748 - `display-buffer-pop-up-frame', if specified by `pop-up-frames'.
4749 - `display-buffer-pop-up-window', if specified by `pop-up-windows'.
4750
4751If BUFFER is sucessfully display, return its window; otherwise
4752return nil."
4753 (let ((use-pop-up-frames (if (eq pop-up-frames 'graphic-only)
4754 (display-graphic-p)
4755 pop-up-frames)))
4756 (or (display-buffer-reuse-window
4757 buffer
4758 ;; If `display-buffer-reuse-frames' or `pop-up-frames' is
4759 ;; non-nil, check all frames on this terminal.
4760 (if (and (null (cdr (assq 'reuse-frame alist)))
4761 (or use-pop-up-frames display-buffer-reuse-frames))
4762 (cons '(reuse-frame . 0) alist)
4763 alist))
4764 ;; Try with `special-display-function':
4765 (and special-display-function
4766 ;; `special-display-p' returns either t or a list of frame
4767 ;; parameters to pass to `special-display-function'.
4768 (let ((pars (special-display-p (buffer-name buffer))))
4769 (when pars
4770 (funcall special-display-function
4771 buffer (if (listp pars) pars)))))
4772 (and use-pop-up-frames
4773 (display-buffer-pop-up-frame buffer alist))
4774 (and pop-up-windows
4775 (display-buffer-pop-up-window buffer alist)))))
4776
4777(defun display-buffer-use-some-window (buffer alist)
4778 "Display BUFFER in an existing window.
4779Search for a usable window, set that window to the buffer, and
4780return the window. If no suitable window is found, return nil."
4781 (let* ((not-this-window (cdr (assq 'inhibit-same-window alist)))
4782 (window-to-undedicate
4783 ;; When NOT-THIS-WINDOW is non-nil, temporarily dedicate the
4784 ;; selected window to its buffer, to prevent any of the
4785 ;; `get-' routines below from choosing it. (Bug#1415)
4786 (and not-this-window (not (window-dedicated-p))
4787 (set-window-dedicated-p (selected-window) t)
4788 (selected-window)))
4789 (frame (or (window--frame-usable-p (selected-frame))
4790 (window--frame-usable-p (last-nonminibuffer-frame))))
4791 (use-pop-up-frames (if (eq pop-up-frames 'graphic-only)
4792 (display-graphic-p)
4793 pop-up-frames))
4794 window popped-up-frame)
4795 (unwind-protect
4796 (setq window
4797 ;; Reuse an existing window.
4798 (or (get-lru-window frame)
4799 (let ((window (get-buffer-window buffer 'visible)))
4800 (unless (and not-this-window
4801 (eq window (selected-window)))
4802 window))
4803 (get-largest-window 'visible)
4804 (let ((window (get-buffer-window buffer 0)))
4805 (unless (and not-this-window
4806 (eq window (selected-window)))
4807 window))
4808 (get-largest-window 0)
4809 (and use-pop-up-frames
4810 (prog1
4811 (frame-selected-window (funcall pop-up-frame-function))
4812 (setq popped-up-frame t)))))
4813 (when (window-live-p window-to-undedicate)
4814 ;; Restore dedicated status of selected window.
4815 (set-window-dedicated-p window-to-undedicate nil)))
4816 (when window
4817 (display-buffer-record-window
4818 (if popped-up-frame 'pop-up-frame 'reuse-window) window buffer)
4819 (window--even-window-heights window)
4820 (window--display-buffer-2 buffer window))))
4758 4821
4759;;; Display + selection commands: 4822;;; Display + selection commands:
4760 4823
@@ -4808,12 +4871,11 @@ for `pop-to-buffer'."
4808 ;; Based on the WINDOW-CHOICE argument, choose an action 4871 ;; Based on the WINDOW-CHOICE argument, choose an action
4809 ;; argument to pass to `display-buffer'. 4872 ;; argument to pass to `display-buffer'.
4810 (cond 4873 (cond
4811 ((null window-choice)
4812 '((display-buffer-other-window display-buffer-same-window)))
4813 ((eq window-choice 'same-window) 4874 ((eq window-choice 'same-window)
4814 '((display-buffer-same-window display-buffer-other-window))) 4875 '((display-buffer-reuse-selected-window
4815 (t 4876 display-buffer-same-window)))
4816 '((display-buffer-other-window))))) 4877 (window-choice
4878 '(nil (inhibit-same-window . t)))))
4817 (window (display-buffer (current-buffer) action)) 4879 (window (display-buffer (current-buffer) action))
4818 (frame (window-frame window))) 4880 (frame (window-frame window)))
4819 (if (eq frame old-frame) 4881 (if (eq frame old-frame)