aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Rudalics2011-07-09 14:32:38 +0200
committerMartin Rudalics2011-07-09 14:32:38 +0200
commit4dc2a12911b8064130b9c5caf2739cd3b31f58f6 (patch)
treee13af545df943ab4462bd0c7406c9ddc68254017
parentec3b5374a7e1581685becbe60b09a40f2bc446f6 (diff)
downloademacs-4dc2a12911b8064130b9c5caf2739cd3b31f58f6.tar.gz
emacs-4dc2a12911b8064130b9c5caf2739cd3b31f58f6.zip
Simplify normalization of default buffer display specifieres and options.
* window.el (display-buffer-default-specifiers): Remove. (display-buffer-macro-specifiers): Remove default specifiers. (display-buffer-alist): Default to nil. (display-buffer-reuse-window): New optional argument other-window. (display-buffer-pop-up-window): Allow splitting internal windows. Check whether a live window was created. (display-buffer-other-window-means-other-frame) (display-buffer-normalize-arguments): Rename to display-buffer-normalize-argument and rewrite. Set the other-window specifier. (display-buffer-normalize-special): New function. (display-buffer-normalize-options): Rename to display-buffer-normalize-default and rewrite. (display-buffer-normalize-options-inhibit): Remove. (display-buffer-normalize-specifiers): Rewrite. (display-buffer): Process other-window specifier and call display-buffer-reuse-window with it. Emulate Emacs 23 behavior more faithfully. (pop-up-windows, even-window-heights): Restore Emacs 23 default values. (display-buffer-alist-set): Don't handle 'unset default values. (display-buffer-in-window, display-buffer-alist-set): Replace symbol "dedicated" by "dedicate". Reported by Tassilo Horn <tassilo@member.fsf.org>.
-rw-r--r--lisp/ChangeLog31
-rw-r--r--lisp/window.el496
2 files changed, 278 insertions, 249 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 67615431b8f..8cf95ded608 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,31 @@
12011-07-09 Martin Rudalics <rudalics@gmx.at>
2
3 * window.el (display-buffer-default-specifiers): Remove.
4 (display-buffer-macro-specifiers): Remove default specifiers.
5 (display-buffer-alist): Default to nil.
6 (display-buffer-reuse-window): New optional argument
7 other-window.
8 (display-buffer-pop-up-window): Allow splitting internal
9 windows. Check whether a live window was created.
10 (display-buffer-other-window-means-other-frame)
11 (display-buffer-normalize-arguments): Rename to
12 display-buffer-normalize-argument and rewrite. Set the
13 other-window specifier.
14 (display-buffer-normalize-special): New function.
15 (display-buffer-normalize-options): Rename to
16 display-buffer-normalize-default and rewrite.
17 (display-buffer-normalize-options-inhibit): Remove.
18 (display-buffer-normalize-specifiers): Rewrite.
19 (display-buffer): Process other-window specifier and call
20 display-buffer-reuse-window with it. Emulate Emacs 23 behavior
21 more faithfully.
22 (pop-up-windows, even-window-heights): Restore Emacs 23 default
23 values.
24 (display-buffer-alist-set): Don't handle 'unset default values.
25 (display-buffer-in-window, display-buffer-alist-set): Replace
26 symbol "dedicated" by "dedicate". Reported by Tassilo Horn
27 <tassilo@member.fsf.org>.
28
12011-07-09 Leo Liu <sdl.web@gmail.com> 292011-07-09 Leo Liu <sdl.web@gmail.com>
2 30
3 * register.el (insert-register): Restore accidental change on 31 * register.el (insert-register): Restore accidental change on
@@ -42,6 +70,9 @@
42 The order of searching the available programs is the same as in 70 The order of searching the available programs is the same as in
43 `archive-zip-extract' (bug#8968). 71 `archive-zip-extract' (bug#8968).
44 72
732011-07-07 Lars Magne Ingebrigtsen <larsi@gnus.org>
74
75 * cus-edit.el (custom-show): Marked as obsolete.
452011-07-07 Chong Yidong <cyd@stupidchicken.com> 762011-07-07 Chong Yidong <cyd@stupidchicken.com>
46 77
47 * menu-bar.el (menu-bar-line-wrapping-menu): Revert last change. 78 * menu-bar.el (menu-bar-line-wrapping-menu): Revert last change.
diff --git a/lisp/window.el b/lisp/window.el
index 2c4bf0dcb23..3bc4b3e56e6 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -3829,22 +3829,6 @@ subwindows can get as small as `window-safe-min-height' and
3829 (window-state-put-2 ignore)) 3829 (window-state-put-2 ignore))
3830 (window-check frame)))) 3830 (window-check frame))))
3831 3831
3832;;; Displaying buffers.
3833(defconst display-buffer-default-specifiers
3834 '((reuse-window nil same visible)
3835 (pop-up-window (largest . nil) (lru . nil))
3836 (pop-up-window-min-height . 40)
3837 (pop-up-window-min-width . 80)
3838 (reuse-window other nil nil)
3839 (reuse-window nil other visible)
3840 (reuse-window nil nil t)
3841 (reuse-window-even-sizes . t))
3842 "Buffer display default specifiers.
3843The value specified here is used when no other specifiers have
3844been specified by the user or the application. Consult the
3845documentation of `display-buffer-alist' for a description of
3846buffer display specifiers.")
3847
3848(defconst display-buffer-macro-specifiers 3832(defconst display-buffer-macro-specifiers
3849 '((same-window 3833 '((same-window
3850 ;; Use the same window. 3834 ;; Use the same window.
@@ -3854,11 +3838,6 @@ buffer display specifiers.")
3854 (reuse-window nil same nil) 3838 (reuse-window nil same nil)
3855 (pop-up-window (largest . nil) (lru . nil)) 3839 (pop-up-window (largest . nil) (lru . nil))
3856 (reuse-window nil other nil)) 3840 (reuse-window nil other nil))
3857 ;; (other-window
3858 ;; ;; Avoid selected window.
3859 ;; (reuse-window other same visible)
3860 ;; (pop-up-window (largest . nil) (lru . nil))
3861 ;; (reuse-window other other visible))
3862 (same-frame-other-window 3841 (same-frame-other-window
3863 ;; Avoid other frames and selected window. 3842 ;; Avoid other frames and selected window.
3864 (reuse-window other same nil) 3843 (reuse-window other same nil)
@@ -3868,25 +3847,10 @@ buffer display specifiers.")
3868 ;; Avoid selected frame. 3847 ;; Avoid selected frame.
3869 (reuse-window nil same other) 3848 (reuse-window nil same other)
3870 (pop-up-frame) 3849 (pop-up-frame)
3871 (reuse-window nil other other)) 3850 (reuse-window nil other other)))
3872 (default
3873 ;; The default specifiers.
3874 display-buffer-default-specifiers))
3875 "Buffer display macro specifiers.") 3851 "Buffer display macro specifiers.")
3876 3852
3877(defcustom display-buffer-alist 3853(defcustom display-buffer-alist nil
3878 '((((regexp . ".*"))
3879 ;; Reuse window showing same buffer on same frame.
3880 reuse-window (reuse-window nil same nil)
3881 ;; Pop up window.
3882 pop-up-window
3883 ;; Split largest or lru window.
3884 (pop-up-window (largest . nil) (lru . nil))
3885 (pop-up-window-min-height . 40) ; split-height-threshold / 2
3886 (pop-up-window-min-width . 80) ; split-width-threshold / 2
3887 ;; Reuse any but selected window on same frame.
3888 reuse-window (reuse-window other nil nil)
3889 (reuse-window-even-sizes . t)))
3890 "List associating buffer identifiers with display specifiers. 3854 "List associating buffer identifiers with display specifiers.
3891The car of each element of this list is built from a set of cons 3855The car of each element of this list is built from a set of cons
3892cells called buffer identifiers. `display-buffer' shows a buffer 3856cells called buffer identifiers. `display-buffer' shows a buffer
@@ -4751,15 +4715,15 @@ documentation of `display-buffer-alist' for a description."
4751 (setq window (window-normalize-live-window window)) 4715 (setq window (window-normalize-live-window window))
4752 (let* ((old-frame (selected-frame)) 4716 (let* ((old-frame (selected-frame))
4753 (new-frame (window-frame window)) 4717 (new-frame (window-frame window))
4754 (dedicated (cdr (assq 'dedicated specifiers))) 4718 (dedicate (cdr (assq 'dedicate specifiers)))
4755 (no-other-window (cdr (assq 'no-other-window specifiers)))) 4719 (no-other-window (cdr (assq 'no-other-window specifiers))))
4756 ;; Show BUFFER in WINDOW. 4720 ;; Show BUFFER in WINDOW.
4757 (unless (eq buffer (window-buffer window)) 4721 (unless (eq buffer (window-buffer window))
4758 ;; If we show another buffer in WINDOW, undedicate it first. 4722 ;; If we show another buffer in WINDOW, undedicate it first.
4759 (set-window-dedicated-p window nil)) 4723 (set-window-dedicated-p window nil))
4760 (set-window-buffer window buffer) 4724 (set-window-buffer window buffer)
4761 (when dedicated 4725 (when dedicate
4762 (set-window-dedicated-p window dedicated)) 4726 (set-window-dedicated-p window dedicate))
4763 (when no-other-window 4727 (when no-other-window
4764 (set-window-parameter window 'no-other-window t)) 4728 (set-window-parameter window 'no-other-window t))
4765 (unless (or (eq old-frame new-frame) 4729 (unless (or (eq old-frame new-frame)
@@ -4775,7 +4739,7 @@ documentation of `display-buffer-alist' for a description."
4775 ;; Return window. 4739 ;; Return window.
4776 window)) 4740 window))
4777 4741
4778(defun display-buffer-reuse-window (buffer method &optional specifiers) 4742(defun display-buffer-reuse-window (buffer method &optional specifiers other-window)
4779 "Display BUFFER in an existing window. 4743 "Display BUFFER in an existing window.
4780METHOD must be a list in the form of the cdr of a `reuse-window' 4744METHOD must be a list in the form of the cdr of a `reuse-window'
4781buffer display specifier, see `display-buffer-alist' for an 4745buffer display specifier, see `display-buffer-alist' for an
@@ -4787,8 +4751,9 @@ frame to use - either nil, 0, `visible', `other', t, or a live
4787frame. 4751frame.
4788 4752
4789Optional argument SPECIFIERS must be a list of valid display 4753Optional argument SPECIFIERS must be a list of valid display
4790specifiers. Return the window chosen to display BUFFER, nil if 4754specifiers. Optional argument OTHER-WINDOW, if non-nil, means do
4791none was found." 4755not use the selected window. Return the window chosen to display
4756BUFFER, nil if none was found."
4792 (let* ((method-window (nth 0 method)) 4757 (let* ((method-window (nth 0 method))
4793 (method-buffer (nth 1 method)) 4758 (method-buffer (nth 1 method))
4794 (method-frame (nth 2 method)) 4759 (method-frame (nth 2 method))
@@ -4806,6 +4771,7 @@ none was found."
4806 (eq window-buffer buffer)) 4771 (eq window-buffer buffer))
4807 (or (not method-window) 4772 (or (not method-window)
4808 (and (eq method-window 'same) 4773 (and (eq method-window 'same)
4774 (not other-window)
4809 (eq window (selected-window))) 4775 (eq window (selected-window)))
4810 (and (eq method-window 'other) 4776 (and (eq method-window 'other)
4811 (not (eq window (selected-window)))) 4777 (not (eq window (selected-window))))
@@ -5064,7 +5030,7 @@ description."
5064 ;; A window, directly specified. 5030 ;; A window, directly specified.
5065 cand))) 5031 cand)))
5066 5032
5067 (when (and (window-live-p window) 5033 (when (and (window-any-p window)
5068 ;; The window must be on the correct frame, 5034 ;; The window must be on the correct frame,
5069 (eq (window-frame window) frame) 5035 (eq (window-frame window) frame)
5070 ;; and must be neither a minibuffer window 5036 ;; and must be neither a minibuffer window
@@ -5084,7 +5050,7 @@ description."
5084 ;; Don't pass any specifiers to this function. 5050 ;; Don't pass any specifiers to this function.
5085 (funcall side window))))) 5051 (funcall side window)))))
5086 5052
5087 (when window 5053 (when (window-live-p window)
5088 ;; Adjust sizes if asked for. 5054 ;; Adjust sizes if asked for.
5089 (display-buffer-set-height window specifiers) 5055 (display-buffer-set-height window specifiers)
5090 (display-buffer-set-width window specifiers) 5056 (display-buffer-set-width window specifiers)
@@ -5324,201 +5290,225 @@ Optional argument LABEL is like the same argument of
5324 5290
5325The calculation of the return value is exclusively based on the 5291The calculation of the return value is exclusively based on the
5326user preferences expressed in `display-buffer-alist'." 5292user preferences expressed in `display-buffer-alist'."
5327 (let* ((buffer (window-normalize-buffer buffer-or-name)) 5293 (let* ((buffer-name
5328 (list (display-buffer-normalize-alist (buffer-name buffer) label)) 5294 (buffer-name (window-normalize-buffer buffer-or-name)))
5329 (value (assq 'other-window-means-other-frame 5295 (default (display-buffer-normalize-default buffer-name))
5330 (or (car list) (cdr list))))) 5296 (alist (display-buffer-normalize-alist buffer-name label)))
5331 (when value (cdr value)))) 5297 (or (cdr (assq 'other-window-means-other-frame default))
5332 5298 (cdr (assq 'other-window-means-other-frame (cdr alist))))))
5333(defun display-buffer-normalize-arguments (buffer-name specifiers label other-frame) 5299
5334 "Normalize second and third argument of `display-buffer'. 5300(defun display-buffer-normalize-special (&optional args)
5335BUFFER-NAME is the name of the buffer that shall be displayed, 5301 "Return buffer display specifiers for `special-display-frame-alist'."
5336SPECIFIERS is the second argument of `display-buffer'. LABEL is 5302 (progn ;; <-- reserved for with-no-warnings
5337the same argument of `display-buffer'. OTHER-FRAME non-nil means 5303 (if (and (listp args) (symbolp (car args)))
5338use other-frame for other-window." 5304 ;; Note: `display-buffer' funcalls this so take "(nth 1 args)"
5339 (let (normalized entry specifier pars) 5305 ;; where `special-display-popup-frame' (which uses apply) takes
5340 (setq specifier 5306 ;; "(cdr args)".
5341 (cond 5307 `((function ,(car args) ,(nth 1 args)))
5342 ((not specifiers) 5308 (append
5343 nil) 5309 '((reuse-window nil same 0))
5344 ((listp specifiers) 5310 (when (and (listp args) (cdr (assq 'same-window args)))
5345 ;; If SPECIFIERS is a list, we assume it is a list of specifiers. 5311 '((reuse-window same nil nil) (reuse-dedicated . weak)))
5346 (dolist (specifier specifiers) 5312 (when (and (listp args)
5347 (cond 5313 (or (cdr (assq 'same-frame args))
5348 ((consp specifier) 5314 (cdr (assq 'same-window args))))
5349 (setq normalized (cons specifier normalized))) 5315 '((pop-up-window (largest . nil) (lru . nil))
5350 ((eq specifier 'other-window) 5316 (reuse-window nil nil nil)))
5351 ;; `other-window' must be treated separately. 5317 (unless display-buffer-mark-dedicated
5352 (let ((entry (assq (if other-frame 5318 ;; Don't make anything created above dedicated unless requested.
5353 'other-frame 5319 ;; Otherwise the dedication request below gets in our way.
5354 'same-frame-other-window) 5320 '((dedicated . nil)))
5355 display-buffer-macro-specifiers))) 5321 `((pop-up-frame t)
5356 (dolist (item (cdr entry)) 5322 ,(append '(pop-up-frame-alist)
5357 (setq normalized (cons item normalized))))) 5323 (when (listp args) args)
5358 ((symbolp specifier) 5324 special-display-frame-alist)
5359 ;; Might be a macro specifier, try to expand it (the cdr is a 5325 (dedicated . t))))))
5360 ;; list and we have to reverse it later, so do it one at a 5326
5361 ;; time). 5327(defun display-buffer-normalize-default (buffer-or-name)
5362 (let ((entry (assq specifier display-buffer-macro-specifiers)))
5363 (dolist (item (cdr entry))
5364 (setq normalized (cons item normalized)))))))
5365 ;; Reverse list.
5366 (nreverse normalized))
5367 ((setq entry (assq specifiers display-buffer-macro-specifiers))
5368 ;; A macro specifier.
5369 (cdr entry))
5370 ((or other-frame (with-no-warnings pop-up-frames))
5371 ;; `special-display-p' group.
5372 (if (and (with-no-warnings special-display-function)
5373 ;; `special-display-p' returns either t or a list
5374 ;; of frame parameters to pass to
5375 ;; `special-display-function'.
5376 (setq pars (with-no-warnings
5377 (special-display-p buffer-name))))
5378 (list (list 'function
5379 (with-no-warnings special-display-function)
5380 (when (listp pars) pars)))
5381 ;; Pop up another frame.
5382 (cddr (assq 'other-frame display-buffer-macro-specifiers))))
5383 (t
5384 ;; In any other case pop up a new window.
5385 (cdr (assq 'same-frame-other-window
5386 display-buffer-macro-specifiers)))))
5387
5388 ;; Handle the old meaning of the LABEL argument of `display-buffer'.
5389 (cond
5390 ((or (memq label '(visible 0 t)) (frame-live-p label))
5391 ;; LABEL must be one of visible (and visible frame), 0 (any
5392 ;; visible or iconfied frame), t (any frame), or a live frame.
5393 (cons `(reuse-window nil same ,label) specifier))
5394 ((or other-frame
5395 (with-no-warnings pop-up-frames)
5396 (with-no-warnings display-buffer-reuse-frames))
5397 (cons '(reuse-window nil same 0) specifier))
5398 (t
5399 specifier))))
5400
5401(defun display-buffer-normalize-options (buffer-or-name)
5402 "Subroutine of `display-buffer-normalize-specifiers'. 5328 "Subroutine of `display-buffer-normalize-specifiers'.
5403BUFFER-OR-NAME is the buffer to display. This routine provides a 5329BUFFER-OR-NAME is the buffer to display.
5404compatibility layer for the now obsolete Emacs 23 buffer display 5330
5405options." 5331This routine provides a compatibility layer for the obsolete
5406 (with-no-warnings 5332Emacs 23 buffer display options to set up the corresponding
5333buffer display specifiers."
5334 (progn ;; <-- reserved for with-no-warnings
5407 (let* ((buffer (window-normalize-buffer buffer-or-name)) 5335 (let* ((buffer (window-normalize-buffer buffer-or-name))
5408 (buffer-name (buffer-name buffer)) 5336 (buffer-name (buffer-name buffer))
5409 (use-pop-up-frames 5337 (pop-up-frames
5410 (or (and (eq pop-up-frames 'graphic-only) 5338 (and (boundp 'pop-up-frames)
5411 (display-graphic-p)) 5339 (or (and (eq pop-up-frames 'graphic-only)
5412 pop-up-frames)) 5340 (display-graphic-p))
5413 specifiers) 5341 pop-up-frames)))
5414 ;; `even-window-heights', unless nil or unset. 5342 specifiers args)
5415 (unless (memq even-window-heights '(nil unset)) 5343 ;; `other-window-means-other-frame'
5344 (when pop-up-frames
5345 (setq specifiers
5346 (cons (cons 'other-window-means-other-frame t) specifiers)))
5347
5348 ;; `even-window-heights'
5349 (unless (and (boundp 'even-window-heights)
5350 (not even-window-heights))
5416 (setq specifiers 5351 (setq specifiers
5417 (cons (cons 'reuse-window-even-sizes t) specifiers))) 5352 (cons (cons 'reuse-window-even-sizes t) specifiers)))
5418 5353
5419 ;; `display-buffer-mark-dedicated' 5354 ;; `display-buffer-mark-dedicated'
5420 (when display-buffer-mark-dedicated 5355 (when (and (boundp 'display-buffer-mark-dedicated)
5356 display-buffer-mark-dedicated)
5421 (setq specifiers 5357 (setq specifiers
5422 (cons (cons 'dedicate display-buffer-mark-dedicated) 5358 (cons (cons 'dedicate display-buffer-mark-dedicated)
5423 specifiers))) 5359 specifiers)))
5424 5360
5425 ;; `pop-up-window' group. Anything is added here iff 5361 ;; `pop-up-window-min-height'
5426 ;; `pop-up-windows' is neither nil nor unset. 5362 (let ((min-height
5427 (let ((pop-up-window (not (memq pop-up-windows '(nil unset)))) 5363 (if (boundp 'split-height-threshold)
5428 (fun (unless (eq split-window-preferred-function 5364 (if (numberp split-height-threshold)
5429 'split-window-sensibly) 5365 (/ split-height-threshold 2)
5430 split-window-preferred-function)) 5366 1.0)
5431 (min-height (if (numberp split-height-threshold) 5367 40)))
5432 (/ split-height-threshold 2) 5368 (setq specifiers
5433 1.0)) 5369 (cons (cons 'pop-up-window-min-height min-height)
5434 (min-width (if (numberp split-width-threshold) 5370 specifiers)))
5435 (/ split-width-threshold 2) 5371
5436 1.0))) 5372 ;; `pop-up-window-min-width'
5437 ;; Create an entry only if a default value was changed. 5373 (let ((min-width
5438 (when (or pop-up-window 5374 (if (boundp 'split-width-threshold)
5439 (not (equal split-height-threshold 80)) 5375 (if (numberp split-width-threshold)
5440 (not (equal split-width-threshold 160))) 5376 (/ split-width-threshold 2)
5441 ;; `reuse-window' (needed as fallback when popping up the new 5377 1.0)
5442 ;; window fails). 5378 80)))
5443 (setq specifiers 5379 (setq specifiers
5444 (cons (list 'reuse-window 'other nil nil) 5380 (cons (cons 'pop-up-window-min-width min-width)
5445 specifiers)) 5381 specifiers)))
5446 ;; `split-width-threshold' 5382
5447 (setq specifiers 5383 ;; `pop-up-window'
5448 (cons (cons 'pop-up-window-min-width min-width) 5384 (unless (and (boundp 'pop-up-windows) (not pop-up-windows))
5449 specifiers)) 5385 (let ((fun (when (and (boundp 'split-window-preferred-function)
5450 ;; `split-height-threshold' 5386 (not (eq split-window-preferred-function
5451 (setq specifiers 5387 'split-window-sensibly)))
5452 (cons (cons 'pop-up-window-min-height min-height) 5388 split-window-preferred-function)))
5453 specifiers))
5454 ;; `pop-up-window' 5389 ;; `pop-up-window'
5455 (setq specifiers 5390 (setq specifiers
5456 (cons (list 'pop-up-window 5391 (cons
5457 (cons 'largest fun) (cons 'lru fun)) 5392 (list 'pop-up-window (cons 'largest fun) (cons 'lru fun))
5458 specifiers)))) 5393 specifiers))))
5394
5395 ;; `pop-up-frame-function'
5396 (when (and (boundp 'pop-up-frame-function)
5397 (not (equal pop-up-frame-function
5398 '(lambda nil
5399 (make-frame pop-up-frame-alist)))))
5400 (setq specifiers
5401 (cons (cons 'pop-up-frame-function pop-up-frame-function)
5402 specifiers)))
5459 5403
5460 ;; `pop-up-frame' group. 5404 ;; `pop-up-frame-alist'
5461 (when use-pop-up-frames 5405 (when pop-up-frame-alist
5406 (setq specifiers
5407 (cons (cons 'pop-up-frame-alist pop-up-frame-alist)
5408 specifiers)))
5409
5410 ;; `pop-up-frame'
5411 (when pop-up-frames
5462 ;; `pop-up-frame-function'. If `pop-up-frame-function' uses the 5412 ;; `pop-up-frame-function'. If `pop-up-frame-function' uses the
5463 ;; now obsolete `pop-up-frame-alist' it will continue to do so. 5413 ;; now obsolete `pop-up-frame-alist' it will continue to do so.
5464 (setq specifiers
5465 (cons (cons 'pop-up-frame-function pop-up-frame-function)
5466 specifiers))
5467 ;; `pop-up-frame' 5414 ;; `pop-up-frame'
5468 (setq specifiers 5415 (setq specifiers
5416 ;; Maybe we should merge graphic-only into the following?
5469 (cons (list 'pop-up-frame t) specifiers))) 5417 (cons (list 'pop-up-frame t) specifiers)))
5470 5418
5471 ;; `pop-up-windows' and `use-pop-up-frames' both nil means means 5419 ;; `special-display'
5472 ;; we are supposed to reuse any window on the same frame (unless 5420 (when (and (boundp 'special-display-function)
5473 ;; we find one showing the same buffer already). 5421 special-display-function
5474 (unless (or pop-up-windows use-pop-up-frames) 5422 (fboundp 'special-display-p)
5475 ;; `reuse-window' showing any buffer on same frame. 5423 (setq args (special-display-p buffer-name)))
5476 (setq specifiers 5424 ;; `special-display-p' returns either t or a list of arguments
5477 (cons (list 'reuse-window nil nil nil) 5425 ;; to pass to `special-display-function'.
5478 specifiers))) 5426 (if (eq special-display-function 'special-display-popup-frame)
5479
5480 ;; `special-display-p' group.
5481 (when special-display-function
5482 ;; `special-display-p' returns either t or a list of frame
5483 ;; parameters to pass to `special-display-function'.
5484 (let ((pars (special-display-p buffer-name)))
5485 (when pars
5486 (setq specifiers 5427 (setq specifiers
5487 (cons (list 'function special-display-function 5428 (append (display-buffer-normalize-special args)
5488 (when (listp pars) pars)) 5429 specifiers))
5489 specifiers))))) 5430 (setq specifiers
5431 (cons
5432 `(function ,special-display-function ,(when (listp args) args))
5433 specifiers))))
5490 5434
5435 ;; Reuse window showing same buffer on visible or iconified frame.
5491 ;; `pop-up-frames', `display-buffer-reuse-frames' means search for 5436 ;; `pop-up-frames', `display-buffer-reuse-frames' means search for
5492 ;; a window showing the buffer on some visible or iconfied frame. 5437 ;; a window showing the buffer on some visible or iconfied frame.
5493 ;; `last-nonminibuffer-frame' set and not the same frame means 5438 ;; `last-nonminibuffer-frame' non-nil means search that frame.
5494 ;; search that frame. 5439 (let ((frames (or (and (or pop-up-frames
5495 (let ((frames (or (and (or use-pop-up-frames 5440 (and (boundp 'display-buffer-reuse-frames)
5496 display-buffer-reuse-frames 5441 display-buffer-reuse-frames)
5497 (not (last-nonminibuffer-frame))) 5442 (not (last-nonminibuffer-frame)))
5498 ;; All visible or iconfied frames. 5443 ;; All visible or iconfied frames.
5499 0) 5444 0)
5500 ;; Same frame. 5445 ;; The following usually returns the same frame
5446 ;; so we implicitly search for a window showing
5447 ;; the buffer on the same frame already.
5501 (last-nonminibuffer-frame)))) 5448 (last-nonminibuffer-frame))))
5502 (when frames 5449 (when frames
5503 (setq specifiers 5450 (setq specifiers
5504 (cons (list 'reuse-window 'other 'same frames) 5451 (cons (list 'reuse-window 'other 'same frames)
5505 specifiers)))) 5452 specifiers))))
5506 5453
5507 ;; `same-window-p' group. 5454 ;; `same-window'
5508 (when (same-window-p buffer-name) 5455 (when (and (fboundp 'same-window-p) (same-window-p buffer-name))
5509 ;; Try to reuse the same (selected) window. 5456 ;; Try to reuse the same (selected) window.
5510 (setq specifiers 5457 (setq specifiers
5511 (cons (list 'reuse-window 'same nil nil) 5458 (cons (list 'reuse-window 'same nil nil) specifiers)))
5512 specifiers)))
5513 5459
5514 ;; Prepend "reuse window on same frame if showing the buffer 5460 ;; Same window if showing this buffer already. Can be overridden
5515 ;; already" specifier. It will be overriden by the application 5461 ;; by `other-window' argument if the buffer is already shown in
5516 ;; supplied 'other-window specifier. 5462 ;; the same window.
5517 (setq specifiers (cons (list 'reuse-window nil 'same nil) 5463 (setq specifiers
5518 specifiers)) 5464 (cons (list 'reuse-window 'same 'same nil) specifiers))
5519 5465
5520 specifiers))) 5466 specifiers)))
5521 5467
5468(defun display-buffer-normalize-argument (buffer-name specifiers other-window-means-other-frame)
5469 "Normalize second argument of `display-buffer'.
5470BUFFER-NAME is the name of the buffer that shall be displayed,
5471SPECIFIERS is the second argument of `display-buffer'.
5472OTHER-WINDOW-MEANS-OTHER-FRAME non-nil means use other-frame for
5473other-window."
5474 (progn ;; <-- reserved for with-no-warnings
5475 (let (normalized entry specifier pars)
5476 (cond
5477 ((not specifiers)
5478 nil)
5479 ((listp specifiers)
5480 ;; If SPECIFIERS is a list, we assume it is a list of valid
5481 ;; specifiers.
5482 (dolist (specifier specifiers)
5483 (cond
5484 ((consp specifier)
5485 (setq normalized (cons specifier normalized)))
5486 ((eq specifier 'other-window)
5487 ;; `other-window' must be treated separately.
5488 (let ((entry (assq (if other-window-means-other-frame
5489 'other-frame
5490 'same-frame-other-window)
5491 display-buffer-macro-specifiers)))
5492 (dolist (item (cdr entry))
5493 (setq normalized (cons item normalized)))))
5494 ((symbolp specifier)
5495 ;; Might be a macro specifier, try to expand it (the cdr is a
5496 ;; list and we have to reverse it later, so do it one at a
5497 ;; time).
5498 (let ((entry (assq specifier display-buffer-macro-specifiers)))
5499 (dolist (item (cdr entry))
5500 (setq normalized (cons item normalized)))))))
5501 ;; Reverse list.
5502 (nreverse normalized))
5503 ((setq entry (assq specifiers display-buffer-macro-specifiers))
5504 ;; A macro specifier.
5505 (cdr entry))
5506 (t
5507 ;; Anything else means use another window according to the
5508 ;; non-overriding specifiers of `display-buffer-alist' and the
5509 ;; specifiers produced by `display-buffer-normalize-default'.
5510 '((other-window . t)))))))
5511
5522(defun display-buffer-normalize-alist-1 (specifiers label) 5512(defun display-buffer-normalize-alist-1 (specifiers label)
5523 "Subroutine of `display-buffer-normalize-alist'. 5513 "Subroutine of `display-buffer-normalize-alist'.
5524SPECIFIERS is a list of buffer display specfiers. LABEL is the 5514SPECIFIERS is a list of buffer display specfiers. LABEL is the
@@ -5579,9 +5569,6 @@ LABEL the corresponding argument of `display-buffer'."
5579 5569
5580 (cons list-1 list-2))) 5570 (cons list-1 list-2)))
5581 5571
5582(defvar display-buffer-normalize-options-inhibit nil
5583 "If non-nil, `display-buffer' doesn't process obsolete options.")
5584
5585(defun display-buffer-normalize-specifiers (buffer-name specifiers label) 5572(defun display-buffer-normalize-specifiers (buffer-name specifiers label)
5586 "Return normalized specifiers for a buffer matching BUFFER-NAME or LABEL. 5573 "Return normalized specifiers for a buffer matching BUFFER-NAME or LABEL.
5587BUFFER-NAME must be a string specifying a valid buffer name. 5574BUFFER-NAME must be a string specifying a valid buffer name.
@@ -5600,25 +5587,33 @@ specifiers:
5600 5587
5601- The specifiers in `display-buffer-alist' whose buffer 5588- The specifiers in `display-buffer-alist' whose buffer
5602 identifier matches BUFFER-NAME or LABEL and whose 'override 5589 identifier matches BUFFER-NAME or LABEL and whose 'override
5603 component is not set. 5590 component is not set."
5604 5591 (let* ((default (display-buffer-normalize-default buffer-name))
5605- `display-buffer-default-specifiers'." 5592 (alist (display-buffer-normalize-alist buffer-name label))
5606 (let* ((list (display-buffer-normalize-alist buffer-name label)) 5593 (other-window-means-other-frame
5607 (other-frame (cdr (assq 'other-window-means-other-frame 5594 (or (cdr (assq 'other-window-means-other-frame default))
5608 (or (car list) (cdr list)))))) 5595 (cdr (assq 'other-window-means-other-frame (cdr alist)))))
5596 (arg2 (display-buffer-normalize-argument
5597 buffer-name specifiers other-window-means-other-frame))
5598 (arg3
5599 ;; Handle special meaning of the LABEL argument of
5600 ;; `display-buffer'.
5601 (when (or (memq label '(visible 0 t)) (frame-live-p label))
5602 ;; LABEL must be one of visible (any visible frame), 0 (any
5603 ;; visible or iconfied frame), t (any frame), or a live
5604 ;; frame.
5605 `((reuse-window nil same ,label)))))
5609 (append 5606 (append
5610 ;; Overriding user specifiers. 5607 ;; Overriding user specifiers.
5611 (car list) 5608 (car alist)
5612 ;; Application specifiers. 5609 ;; Special value of third argument of display-buffer.
5613 (display-buffer-normalize-arguments 5610 arg3
5614 buffer-name specifiers label other-frame) 5611 ;; Second argument of display-buffer.
5615 ;; Emacs 23 compatibility specifiers. 5612 arg2
5616 (unless display-buffer-normalize-options-inhibit
5617 (display-buffer-normalize-options buffer-name))
5618 ;; Non-overriding user specifiers. 5613 ;; Non-overriding user specifiers.
5619 (cdr list) 5614 (cdr alist)
5620 ;; Default specifiers. 5615 ;; Default specifiers.
5621 display-buffer-default-specifiers))) 5616 default)))
5622 5617
5623;; Minibuffer-only frames should be documented better. They really 5618;; Minibuffer-only frames should be documented better. They really
5624;; deserve a separate section in the manual. Also 5619;; deserve a separate section in the manual. Also
@@ -5653,9 +5648,8 @@ For convenience, SPECIFIERS may also consist of a single buffer
5653display location specifier or t, where the latter means to 5648display location specifier or t, where the latter means to
5654display the buffer in any but the selected window. If SPECIFIERS 5649display the buffer in any but the selected window. If SPECIFIERS
5655is nil or omitted, this means to exclusively use the specifiers 5650is nil or omitted, this means to exclusively use the specifiers
5656provided by `display-buffer-alist'. If the value of the latter 5651provided by the variable `display-buffer-alist' and the function
5657is nil too, all specifiers are provided by the constant 5652`display-buffer-normalize-default'.
5658`display-buffer-default-specifiers'.
5659 5653
5660As a special case, the `reuse-window' specifier allows to specify 5654As a special case, the `reuse-window' specifier allows to specify
5661as second element an arbitrary window, as third element an 5655as second element an arbitrary window, as third element an
@@ -5707,7 +5701,7 @@ this list as arguments."
5707 ;; Don't use a minibuffer frame. 5701 ;; Don't use a minibuffer frame.
5708 (frame (display-buffer-frame)) 5702 (frame (display-buffer-frame))
5709 ;; `window' is the window we use for showing `buffer'. 5703 ;; `window' is the window we use for showing `buffer'.
5710 window specifier method) 5704 window specifier method other-window)
5711 ;; Reset this. 5705 ;; Reset this.
5712 (setq display-buffer-window nil) 5706 (setq display-buffer-window nil)
5713 (if display-buffer-function 5707 (if display-buffer-function
@@ -5723,7 +5717,7 @@ this list as arguments."
5723 (cond 5717 (cond
5724 ((eq method 'reuse-window) 5718 ((eq method 'reuse-window)
5725 (display-buffer-reuse-window 5719 (display-buffer-reuse-window
5726 buffer (cdr specifier) normalized)) 5720 buffer (cdr specifier) normalized other-window))
5727 ((eq method 'pop-up-window) 5721 ((eq method 'pop-up-window)
5728 (display-buffer-pop-up-window 5722 (display-buffer-pop-up-window
5729 buffer (cdr specifier) normalized)) 5723 buffer (cdr specifier) normalized))
@@ -5734,25 +5728,31 @@ this list as arguments."
5734 (display-buffer-in-side-window 5728 (display-buffer-in-side-window
5735 buffer (nth 1 specifier) (nth 2 specifier) normalized)) 5729 buffer (nth 1 specifier) (nth 2 specifier) normalized))
5736 ((eq method 'function) 5730 ((eq method 'function)
5737 (funcall (nth 1 specifier) buffer (nth 2 specifier)))))) 5731 (funcall (nth 1 specifier) buffer (nth 2 specifier)))
5732 ((eq method 'other-window)
5733 (setq other-window t)))))
5738 5734
5739 ;; If we don't have a window yet, try a fallback method. All 5735 ;; If we don't have a window yet, try a fallback method. All
5740 ;; specifiers have been used up by now. 5736 ;; specifiers have been used up by now. Try reusing a window
5741 (or (and (window-live-p window) window) 5737 (or (and (window-live-p window) window)
5742 ;; Try reusing a window showing BUFFER on any visible or 5738 ;; on the selected frame,
5743 ;; iconfied frame. 5739 (display-buffer-reuse-window
5744 (display-buffer-reuse-window buffer `(nil ,buffer 0)) 5740 buffer '(nil nil nil) other-window)
5745 ;; Try reusing a window not showing BUFFER on any visible or 5741 ;; showing BUFFER on any visible frame,
5746 ;; iconified frame. 5742 (display-buffer-reuse-window
5747 (display-buffer-reuse-window buffer '(nil other 0)) 5743 buffer '(nil same visible) other-window)
5748 ;; Eli says it's better to never try making a new frame. 5744 ;; not showing BUFFER on any visible frame,
5749 ;; (display-buffer-pop-up-frame buffer)
5750 ;; Try using a weakly dedicated window.
5751 (display-buffer-reuse-window 5745 (display-buffer-reuse-window
5752 buffer '(nil nil t) '((reuse-window-dedicated . weak))) 5746 buffer '(nil other visible) other-window)
5753 ;; Try using a strongly dedicated window. 5747 ;; showing BUFFER on any visible or iconified frame,
5754 (display-buffer-reuse-window 5748 (display-buffer-reuse-window
5755 buffer '(nil nil t) '((reuse-window-dedicated . t))))))) 5749 buffer '(nil same 0) other-window)
5750 ;; not showing BUFFER on any visible or iconified frame.
5751 (display-buffer-reuse-window
5752 buffer '(nil other 0) other-window)
5753 ;; If everything failed so far, try popping up a new frame
5754 ;; regardless of graphic-only restrictions.
5755 (display-buffer-pop-up-frame buffer)))))
5756 5756
5757(defsubst display-buffer-same-window (&optional buffer-or-name label) 5757(defsubst display-buffer-same-window (&optional buffer-or-name label)
5758 "Display buffer specified by BUFFER-OR-NAME in the selected window. 5758 "Display buffer specified by BUFFER-OR-NAME in the selected window.
@@ -6395,10 +6395,9 @@ that frame."
6395 ;; 'display-buffer-reuse-frames 6395 ;; 'display-buffer-reuse-frames
6396 ;; "use 2nd arg of `display-buffer' instead." "24.1") 6396 ;; "use 2nd arg of `display-buffer' instead." "24.1")
6397 6397
6398(defcustom pop-up-windows 'unset ; t 6398(defcustom pop-up-windows t
6399 "Set and non-nil means `display-buffer' should make a new window." 6399 "Non-nil means `display-buffer' should make a new window."
6400 :type 'boolean 6400 :type 'boolean
6401 :version "24.1"
6402 :group 'windows) 6401 :group 'windows)
6403;; (make-obsolete-variable 6402;; (make-obsolete-variable
6404 ;; 'pop-up-windows 6403 ;; 'pop-up-windows
@@ -6459,13 +6458,12 @@ is nil, `display-buffer' cannot split windows horizontally."
6459 ;; 'split-width-threshold 6458 ;; 'split-width-threshold
6460 ;; "use 2nd arg of `display-buffer' instead." "24.1") 6459 ;; "use 2nd arg of `display-buffer' instead." "24.1")
6461 6460
6462(defcustom even-window-heights 'unset ; t 6461(defcustom even-window-heights t
6463 "If set and non-nil `display-buffer' will try to even window heights. 6462 "If non-nil `display-buffer' will try to even window heights.
6464Otherwise `display-buffer' will leave the window configuration 6463Otherwise `display-buffer' will leave the window configuration
6465alone. Heights are evened only when `display-buffer' reuses a 6464alone. Heights are evened only when `display-buffer' chooses a
6466window that appears above or below the selected window." 6465window that appears above or below the selected window."
6467 :type 'boolean 6466 :type 'boolean
6468 :version "24.1"
6469 :group 'windows) 6467 :group 'windows)
6470;; (make-obsolete-variable 6468;; (make-obsolete-variable
6471 ;; 'even-window-heights 6469 ;; 'even-window-heights
@@ -6635,7 +6633,7 @@ value of `display-buffer-alist'."
6635 1.0))) 6633 1.0)))
6636 (list 6634 (list
6637 'pop-up-window 6635 'pop-up-window
6638 (when pop-up-windows ; unset qualifies as t 6636 (when pop-up-windows
6639 (list 6637 (list
6640 'pop-up-window 6638 'pop-up-window
6641 (cons 'largest fun) 6639 (cons 'largest fun)
@@ -6789,7 +6787,7 @@ value of `display-buffer-alist'."
6789 ;; "0" (all visible and iconified frames) is hardcoded in 6787 ;; "0" (all visible and iconified frames) is hardcoded in
6790 ;; Emacs 23. 6788 ;; Emacs 23.
6791 0)) 6789 0))
6792 (unless (memq even-window-heights '(nil unset)) 6790 (when even-window-heights
6793 (cons 'reuse-window-even-sizes t))) 6791 (cons 'reuse-window-even-sizes t)))
6794 no-custom) 6792 no-custom)
6795 6793
@@ -6798,7 +6796,7 @@ value of `display-buffer-alist'."
6798 (display-buffer-alist-add 6796 (display-buffer-alist-add
6799 nil 6797 nil
6800 (list 6798 (list
6801 (cons 'dedicated display-buffer-mark-dedicated)) 6799 (cons 'dedicate display-buffer-mark-dedicated))
6802 no-custom))) 6800 no-custom)))
6803 6801
6804 display-buffer-alist) 6802 display-buffer-alist)