diff options
| author | Martin Rudalics | 2011-06-13 10:21:09 +0200 |
|---|---|---|
| committer | Martin Rudalics | 2011-06-13 10:21:09 +0200 |
| commit | 9481c00201c52494d5119cecd4c267bfd0c5d19e (patch) | |
| tree | 1c8dc241b87b7f926b09cffe0401b6e578e2e830 | |
| parent | 873e858a931f3af4b318473e052fb7acd35f7b53 (diff) | |
| download | emacs-9481c00201c52494d5119cecd4c267bfd0c5d19e.tar.gz emacs-9481c00201c52494d5119cecd4c267bfd0c5d19e.zip | |
Install new buffer display functions and variables.
* window.el (display-buffer-function): Rewrite doc-string.
(display-buffer-window, display-buffer-alist): New variables.
(display-buffer-split-specifiers)
(display-buffer-side-specifiers)
(display-buffer-macro-specifiers): New constants.
(display-buffer-even-window-sizes, display-buffer-set-height)
(display-buffer-set-width, display-buffer-select-window)
(display-buffer-in-window, display-buffer-reuse-window)
(display-buffer-split-window-1, display-buffer-split-window)
(display-buffer-split-atom-window, display-buffer-pop-up-window)
(display-buffer-pop-up-frame, display-buffer-pop-up-side-window)
(display-buffer-in-side-window, normalize-buffer-to-display)
(display-buffer-normalize-specifiers-1)
(display-buffer-normalize-specifiers-2)
(display-buffer-normalize-specifiers, display-buffer-frame): New
functions.
(display-buffer): Major rewrite.
(display-buffer-other-window, display-buffer-other-frame)
(pop-to-buffer, switch-to-buffer-other-window)
(switch-to-buffer-other-frame): Rewrite.
(display-buffer-same-window, display-buffer-same-frame)
(display-buffer-same-frame-other-window)
(pop-to-buffer-same-window, pop-to-buffer-same-frame)
(pop-to-buffer-other-window)
(pop-to-buffer-same-frame-other-window)
(pop-to-buffer-other-frame, switch-to-buffer-same-frame)
(switch-to-buffer-other-window-same-frame): New functions.
(same-window-p, special-display-p): Rewrite disabling warnings.
Make obsolete.
(pop-up-frames, display-buffer-reuse-frames, pop-up-windows)
(display-buffer-mark-dedicated): Initialize to symbol 'unset.
Make obsolete
(same-window-buffer-names, same-window-regexps)
(special-display-frame-alist, special-display-popup-frame)
(special-display-function, special-display-buffer-names)
(special-display-regexps, pop-up-frame-alist)
(pop-up-frame-function, split-window-preferred-function)
(split-height-threshold, split-width-threshold)
(even-window-heights): Make obsolete.
| -rw-r--r-- | lisp/ChangeLog | 42 | ||||
| -rw-r--r-- | lisp/window.el | 3130 |
2 files changed, 2641 insertions, 531 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 6f7afeb2af3..9ab4270f870 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,45 @@ | |||
| 1 | 2011-06-13 Martin Rudalics <rudalics@gmx.at> | ||
| 2 | |||
| 3 | * window.el (display-buffer-function): Rewrite doc-string. | ||
| 4 | (display-buffer-window, display-buffer-alist): New variables. | ||
| 5 | (display-buffer-split-specifiers) | ||
| 6 | (display-buffer-side-specifiers) | ||
| 7 | (display-buffer-macro-specifiers): New constants. | ||
| 8 | (display-buffer-even-window-sizes, display-buffer-set-height) | ||
| 9 | (display-buffer-set-width, display-buffer-select-window) | ||
| 10 | (display-buffer-in-window, display-buffer-reuse-window) | ||
| 11 | (display-buffer-split-window-1, display-buffer-split-window) | ||
| 12 | (display-buffer-split-atom-window, display-buffer-pop-up-window) | ||
| 13 | (display-buffer-pop-up-frame, display-buffer-pop-up-side-window) | ||
| 14 | (display-buffer-in-side-window, normalize-buffer-to-display) | ||
| 15 | (display-buffer-normalize-specifiers-1) | ||
| 16 | (display-buffer-normalize-specifiers-2) | ||
| 17 | (display-buffer-normalize-specifiers, display-buffer-frame): New | ||
| 18 | functions. | ||
| 19 | (display-buffer): Major rewrite. | ||
| 20 | (display-buffer-other-window, display-buffer-other-frame) | ||
| 21 | (pop-to-buffer, switch-to-buffer-other-window) | ||
| 22 | (switch-to-buffer-other-frame): Rewrite. | ||
| 23 | (display-buffer-same-window, display-buffer-same-frame) | ||
| 24 | (display-buffer-same-frame-other-window) | ||
| 25 | (pop-to-buffer-same-window, pop-to-buffer-same-frame) | ||
| 26 | (pop-to-buffer-other-window) | ||
| 27 | (pop-to-buffer-same-frame-other-window) | ||
| 28 | (pop-to-buffer-other-frame, switch-to-buffer-same-frame) | ||
| 29 | (switch-to-buffer-other-window-same-frame): New functions. | ||
| 30 | (same-window-p, special-display-p): Rewrite disabling warnings. | ||
| 31 | Make obsolete. | ||
| 32 | (pop-up-frames, display-buffer-reuse-frames, pop-up-windows) | ||
| 33 | (display-buffer-mark-dedicated): Initialize to symbol 'unset. | ||
| 34 | Make obsolete | ||
| 35 | (same-window-buffer-names, same-window-regexps) | ||
| 36 | (special-display-frame-alist, special-display-popup-frame) | ||
| 37 | (special-display-function, special-display-buffer-names) | ||
| 38 | (special-display-regexps, pop-up-frame-alist) | ||
| 39 | (pop-up-frame-function, split-window-preferred-function) | ||
| 40 | (split-height-threshold, split-width-threshold) | ||
| 41 | (even-window-heights): Make obsolete. | ||
| 42 | |||
| 1 | 2011-06-12 Glenn Morris <rgm@gnu.org> | 43 | 2011-06-12 Glenn Morris <rgm@gnu.org> |
| 2 | 44 | ||
| 3 | * term/xterm.el (terminal-init-xterm): `version' may be nil. (Bug#8838) | 45 | * term/xterm.el (terminal-init-xterm): `version' may be nil. (Bug#8838) |
diff --git a/lisp/window.el b/lisp/window.el index 94ac9143efd..cad4e15507d 100644 --- a/lisp/window.el +++ b/lisp/window.el | |||
| @@ -3455,19 +3455,2266 @@ specific buffers." | |||
| 3455 | )) | 3455 | )) |
| 3456 | 3456 | ||
| 3457 | 3457 | ||
| 3458 | |||
| 3459 | (defconst display-buffer-default-specifiers | ||
| 3460 | '((reuse-window nil same visible) | ||
| 3461 | (pop-up-window (largest . nil) (lru . nil)) | ||
| 3462 | (pop-up-frame) | ||
| 3463 | (pop-up-frame-alist | ||
| 3464 | (height . 24) (width . 80) (unsplittable . t)) | ||
| 3465 | (reuse-window nil other visible) | ||
| 3466 | (reuse-window-even-sizes . t)) | ||
| 3467 | "Buffer display default specifiers. | ||
| 3468 | The value specified here is used when no other specifiers have | ||
| 3469 | been specified by the user or the application. Consult the | ||
| 3470 | documentation of `display-buffer-alist' for a description of | ||
| 3471 | buffer display specifiers.") | ||
| 3472 | |||
| 3473 | (defconst display-buffer-macro-specifiers | ||
| 3474 | '((same-window | ||
| 3475 | ;; Use the same window. | ||
| 3476 | (reuse-window same nil nil)) | ||
| 3477 | (same-frame | ||
| 3478 | ;; Avoid other frames. | ||
| 3479 | (reuse-window nil same nil) | ||
| 3480 | (pop-up-window (largest . nil) (lru . nil)) | ||
| 3481 | (reuse-window nil other nil)) | ||
| 3482 | (other-window | ||
| 3483 | ;; Avoid selected window. | ||
| 3484 | (reuse-window other same visible) | ||
| 3485 | (pop-up-window (largest . nil) (lru . nil)) | ||
| 3486 | (pop-up-frame) | ||
| 3487 | (reuse-window other other visible)) | ||
| 3488 | (same-frame-other-window | ||
| 3489 | ;; Avoid other frames and selected window. | ||
| 3490 | (reuse-window other same nil) | ||
| 3491 | (pop-up-window (largest . nil) (lru . nil)) | ||
| 3492 | (reuse-window other other nil)) | ||
| 3493 | (other-frame | ||
| 3494 | ;; Avoid selected frame. | ||
| 3495 | (reuse-window nil same other) | ||
| 3496 | (pop-up-frame) | ||
| 3497 | (reuse-window nil other other)) | ||
| 3498 | (default | ||
| 3499 | ;; The default specifiers. | ||
| 3500 | display-buffer-default-specifiers)) | ||
| 3501 | "Buffer display macro specifiers.") | ||
| 3502 | |||
| 3503 | (defcustom display-buffer-alist | ||
| 3504 | '((((regexp . ".*")) | ||
| 3505 | reuse-window (reuse-window nil same visible) | ||
| 3506 | pop-up-window | ||
| 3507 | (pop-up-window (largest . nil) (lru . nil)) | ||
| 3508 | pop-up-frame | ||
| 3509 | (pop-up-frame) | ||
| 3510 | reuse-window (reuse-window nil other visible) | ||
| 3511 | (reuse-window-even-sizes . t))) | ||
| 3512 | "List associating buffer identifiers with display specifiers. | ||
| 3513 | The car of each element of this list is built from a set of cons | ||
| 3514 | cells called buffer identifiers. `display-buffer' shows a buffer | ||
| 3515 | according to the display specifiers in the element's cdr | ||
| 3516 | \(elements are true lists) if at least one of the identifiers | ||
| 3517 | matches the first or third argument of `display-buffer'. Such a | ||
| 3518 | match occurs in one of the following three cases: | ||
| 3519 | |||
| 3520 | - The car of the buffer identifier is the symbol `name' and its | ||
| 3521 | cdr is a string equalling the name of the buffer specified by | ||
| 3522 | the first \(BUFFER-OR-NAME) argument of `display-buffer'. | ||
| 3523 | |||
| 3524 | - The car is the symbol `regexp' and the cdr is a regular | ||
| 3525 | expression matching the name of the buffer specified by the | ||
| 3526 | first \(BUFFER-OR-NAME) argument of `display-buffer'. | ||
| 3527 | |||
| 3528 | - The car is the symbol `label' and the cdr is a symbol equalling | ||
| 3529 | the third \(LABEL) argument of `display-buffer'. | ||
| 3530 | |||
| 3531 | Display specifiers are either symbols, cons cells, or lists. | ||
| 3532 | Five specifiers have been reserved to indicate the basic method | ||
| 3533 | for displaying the buffer: `reuse-window', `pop-up-window', | ||
| 3534 | `pop-up-frame', `use-side-window', and `fun-with-args'. | ||
| 3535 | |||
| 3536 | A list whose car is the symbol `reuse-window' indicates that an | ||
| 3537 | existing window shall be reused for displaying the buffer. The | ||
| 3538 | second element of this list specifies the window to use and can | ||
| 3539 | be one of the following symbols: | ||
| 3540 | |||
| 3541 | nil stands for any window. | ||
| 3542 | |||
| 3543 | `same' stands for the selected window. | ||
| 3544 | |||
| 3545 | `other' stands for any but the selected window. | ||
| 3546 | |||
| 3547 | The third element specifies whether the buffer shown in a window | ||
| 3548 | that shall be reused must be the same buffer that shall be | ||
| 3549 | displayed or another buffer and can be one of the following: | ||
| 3550 | |||
| 3551 | nil means to not care about the window's buffer. | ||
| 3552 | |||
| 3553 | `same' means the window must show the buffer already. | ||
| 3554 | |||
| 3555 | `other' means the window must not show the buffer yet. | ||
| 3556 | |||
| 3557 | The fourth element specifies the set of frames to search for a | ||
| 3558 | suitable window and can be one of the following: | ||
| 3559 | |||
| 3560 | nil to reuse a window on the selected frame. | ||
| 3561 | |||
| 3562 | `visible' to search visible frames on the current terminal. | ||
| 3563 | |||
| 3564 | `other' stands for any visible frame but the selected one. | ||
| 3565 | |||
| 3566 | 0 \(the number zero) to search visible and iconified frames on | ||
| 3567 | the current terminal. | ||
| 3568 | |||
| 3569 | t to search arbitrary frames including invisible ones. | ||
| 3570 | |||
| 3571 | If more than one window fits the constraints imposed by these | ||
| 3572 | elements, the least recently used candidate is chosen. A side | ||
| 3573 | window is never reused unless it already shows the buffer. | ||
| 3574 | |||
| 3575 | The following two specifiers are useful when the method equals | ||
| 3576 | `reuse-window': | ||
| 3577 | |||
| 3578 | - A cons cell whose car is the symbol `reuse-window-even-sizes' | ||
| 3579 | and whose cdr is non-nil means to even out the sizes of a | ||
| 3580 | reused window and the selected window provided they (1) appear | ||
| 3581 | adjacent to each other and (2) the selected window is larger | ||
| 3582 | than the window chosen. If the cdr is nil, this means that the | ||
| 3583 | window sizes are left alone. | ||
| 3584 | |||
| 3585 | - A cons cell whose car is the symbol `reuse-window-dedicated' | ||
| 3586 | and whose cdr is non-nil means that a window can be reused even | ||
| 3587 | if it's weakly dedicated to its buffer. If the cdr is t, a | ||
| 3588 | strongly dedicated window can be reused to show the buffer. | ||
| 3589 | Any other non-nil value means only weakly dedicated windows can | ||
| 3590 | be reused. If the cdr is nil, dedicated windows are not | ||
| 3591 | reused. | ||
| 3592 | |||
| 3593 | This specifier should be used in emergency cases only since | ||
| 3594 | windows are usually made dedicated in order to prevent | ||
| 3595 | `display-buffer' from reusing them. | ||
| 3596 | |||
| 3597 | A list whose car is the symbol `pop-up-window' and whose cdr is | ||
| 3598 | built from cons cells representing window/side tuples indicates | ||
| 3599 | that a new window shall be made for displaying the buffer on the | ||
| 3600 | selected frame. | ||
| 3601 | |||
| 3602 | Window/side tuples are cons cells. The car of such a tuple | ||
| 3603 | identifies the window that shall be split. Possible values are | ||
| 3604 | `largest', `lru', `selected', and `root' to split the largest, | ||
| 3605 | least recently used, selected or root window of the selected | ||
| 3606 | frame. | ||
| 3607 | |||
| 3608 | If the frame has side windows, these values do allow to split | ||
| 3609 | only the selected frame's main window or one of its subwindows. | ||
| 3610 | Setting the car to one of `left', `top', `right' and `bottom' | ||
| 3611 | splits the corresponding side window, provided such a window | ||
| 3612 | exists. | ||
| 3613 | |||
| 3614 | The cdr of each pair specifies on which side of the window to | ||
| 3615 | split the new window shall appear and can be one of `below', | ||
| 3616 | `right', `above', or `left' with the obvious meanings. If the | ||
| 3617 | cdr is nil, the window is split in a fashion suitable for its | ||
| 3618 | current dimensions. If the cdr specifies a function, that | ||
| 3619 | function is called with one argument - the window to split. The | ||
| 3620 | function is supposed to split that window and return the new | ||
| 3621 | window. | ||
| 3622 | |||
| 3623 | `display-buffer' scans these tuples until it can either produce a | ||
| 3624 | suitable window or fails. The default value for | ||
| 3625 | `display-buffer-alist' contains the tuples \(largest . nil) and | ||
| 3626 | \(lru . nil) in order to split the largest window first and, if | ||
| 3627 | that fails, the least recently used one. | ||
| 3628 | |||
| 3629 | The following specifiers are useful if the method specifier is | ||
| 3630 | `pop-up-window'. | ||
| 3631 | |||
| 3632 | - A cons cell whose car is the symbol `pop-up-window-min-height' | ||
| 3633 | specifiies the minimum height of the new window. If the cdr is | ||
| 3634 | an integer number, it specifies the minimum number of lines of | ||
| 3635 | the window. A floating point number gives the minimum fraction | ||
| 3636 | of the window height with respect to the height of the frame's | ||
| 3637 | root window. A new window is created only if it can be made at | ||
| 3638 | least as high as specified by the number. If the cdr is nil, | ||
| 3639 | this means to use the value of `window-min-height'. | ||
| 3640 | |||
| 3641 | - A cons cell whose car is the symbol `pop-up-window-min-width' | ||
| 3642 | specifies the minimum width of the new window. If the cdr is | ||
| 3643 | an integer number, it specifies the minimum number of columns | ||
| 3644 | of the window. A floating point number gives the minimum | ||
| 3645 | fraction of the window width with respect to the width of the | ||
| 3646 | frame's root window. A new window is created only if it can be | ||
| 3647 | made at least as wide as specified by the number. If the cdr | ||
| 3648 | is nil, this means to use the value of `window-min-width'. | ||
| 3649 | |||
| 3650 | - A cons cell whose car is `pop-up-window-set-height' with | ||
| 3651 | the following interpretations for the cdr: | ||
| 3652 | |||
| 3653 | - nil means leave the height of the new window alone. | ||
| 3654 | |||
| 3655 | - A number specifies the desired height of the new window. An | ||
| 3656 | integer number specifies the number of lines of the window. | ||
| 3657 | A floating point number gives the fraction of the window | ||
| 3658 | height with respect to the height of the frame's root window. | ||
| 3659 | |||
| 3660 | - If the cdr specifies a function, that function is called with | ||
| 3661 | one argument - the new window. The function is supposed to | ||
| 3662 | adjust the height of the window; its return value is ignored. | ||
| 3663 | Suitable functions are `shrink-window-if-larger-than-buffer' | ||
| 3664 | and `fit-window-to-buffer'. | ||
| 3665 | |||
| 3666 | - A cons cell whose car equals `pop-up-window-set-width' with | ||
| 3667 | the following interpretations for the cdr: | ||
| 3668 | |||
| 3669 | - nil means leave the width of the new window alone. | ||
| 3670 | |||
| 3671 | - A number specifies the desired width of the new window. An | ||
| 3672 | integer number specifies the number of columns of the window. | ||
| 3673 | A floating point number gives the fraction of the window | ||
| 3674 | width with respect to the width of the frame's root window. | ||
| 3675 | |||
| 3676 | - If the cdr specifies a function, that function is called with | ||
| 3677 | one argument - the new window. The function is supposed to | ||
| 3678 | adjust the width of the window; its return value is ignored. | ||
| 3679 | |||
| 3680 | Observe that specifying `pop-up-window-set-height' or | ||
| 3681 | `pop-up-window-set-width' may override restrictions given by | ||
| 3682 | the `pop-up-window-min-height' and `pop-up-window-min-width' | ||
| 3683 | specifiers. | ||
| 3684 | |||
| 3685 | - A cons cell whose car is `pop-up-window-split-unsplittable' and | ||
| 3686 | whose cdr is non-nil allows to make a new window on an | ||
| 3687 | unsplittable frame. If the cdr is nil, unsplittable frames are | ||
| 3688 | not split. This specifier should be used in special cases only | ||
| 3689 | since frames are usually made unsplittable in order to prevent | ||
| 3690 | `display-buffer' from splitting them. | ||
| 3691 | |||
| 3692 | A list whose car is the symbol `pop-up-frame' specifies that a | ||
| 3693 | new frame shall be made for displaying the buffer. The second | ||
| 3694 | element, if non-nil, allows popping up a new frame on graphic | ||
| 3695 | displays only. | ||
| 3696 | |||
| 3697 | The following specifiers are useful if the method specifier is | ||
| 3698 | `pop-up-frame'. | ||
| 3699 | |||
| 3700 | - A list whose car is the symbol `pop-up-frame-function' together | ||
| 3701 | with a valid function as cdr specifies the function for | ||
| 3702 | creating a new frame. If the cdr is nil, the default function | ||
| 3703 | `make-frame' is called. The function is called with the | ||
| 3704 | parameters and values provided by the specifier described next. | ||
| 3705 | |||
| 3706 | - A list whose car is the symbol `pop-up-frame-alist' followed by | ||
| 3707 | an arbitrary number of frame parameter/value tuples, each given | ||
| 3708 | as a cons cell, specifies the parameters passed to the pop-up | ||
| 3709 | frame function. | ||
| 3710 | |||
| 3711 | A list of three elements whose car is the symbol | ||
| 3712 | `use-side-window' specifies that the buffer shall be displayed in | ||
| 3713 | a side window of the selected frame. The second element denotes | ||
| 3714 | the side of the frame where the window appears or shall be made. | ||
| 3715 | The third element denotes the slot used by the window. If a side | ||
| 3716 | window with the specified slot exists already, that window is | ||
| 3717 | reused. If no such window exists it is created. | ||
| 3718 | |||
| 3719 | The following specifiers are useful in connection with the | ||
| 3720 | `use-side-window' method specifier: `reuse-window-dedicated', | ||
| 3721 | `pop-up-window-min-height', `pop-up-window-min-width', | ||
| 3722 | `pop-up-window-set-height' and `pop-up-window-set-width'. | ||
| 3723 | |||
| 3724 | A list whose car is the symbol `fun-with-args' specifies that the | ||
| 3725 | function specified in the second element of the list is | ||
| 3726 | responsible for displaying the buffer. `display-buffer' calls | ||
| 3727 | this function with the buffer as first argument and the remaining | ||
| 3728 | elements of the list as second argument. | ||
| 3729 | |||
| 3730 | The function should choose or create a window, display the buffer | ||
| 3731 | in it, and return the window. It is also responsible for giving | ||
| 3732 | the variable `display-buffer-window' and the `quit-restore' | ||
| 3733 | parameter of the window used a meaningful value. | ||
| 3734 | |||
| 3735 | Within the body of this function avoid calling `display-buffer' | ||
| 3736 | with the same buffer as argument since this may lead to endless | ||
| 3737 | recursion. | ||
| 3738 | |||
| 3739 | Instead of supplying basic method specifiers, it's sometimes more | ||
| 3740 | convenient to use macro specifiers. They provide some commonly | ||
| 3741 | used display methods but do not support the fine control provided | ||
| 3742 | by the basic method specifiers. Macro specifiers are symbols. | ||
| 3743 | The following macro specifiers are provided: | ||
| 3744 | |||
| 3745 | `same-window' to display the buffer in the selected window. | ||
| 3746 | |||
| 3747 | `same-frame' to display the buffer on the selected frame. | ||
| 3748 | |||
| 3749 | `other-window' to display the buffer in any window but the | ||
| 3750 | selected one. | ||
| 3751 | |||
| 3752 | `same-frame-other-window' as `other-window' but stay on the | ||
| 3753 | selected frame. | ||
| 3754 | |||
| 3755 | `other-frame' to display the buffer on another visible | ||
| 3756 | frame. | ||
| 3757 | |||
| 3758 | `default' to use the default value of `display-buffer-alist'. | ||
| 3759 | |||
| 3760 | One specifier is useful with any method specifier: A list whose | ||
| 3761 | car is the symbol `dedicate' and whose cdr is non-nil will | ||
| 3762 | dedicate the window to its buffer. The following values are | ||
| 3763 | supported: | ||
| 3764 | |||
| 3765 | - nil to not dedicate the window to the buffer. | ||
| 3766 | |||
| 3767 | - `weak' to weakly dedicate the window to the buffer. | ||
| 3768 | |||
| 3769 | - t to strongly dedicate the window to the buffer. | ||
| 3770 | |||
| 3771 | Usually, applications are free to override the specifiers of | ||
| 3772 | `display-buffer-alist' by passing their own specifiers as second | ||
| 3773 | argument of `display-buffer'. For every `display-buffer-alist' | ||
| 3774 | entry you can, however, add a cons cell whose car is the symbol | ||
| 3775 | `override' and whose cdr is non-nil, to explicitly override any | ||
| 3776 | value supplied by the application. | ||
| 3777 | |||
| 3778 | Overriding specifiers supplied by the calling application is, in | ||
| 3779 | general, not advisable. It permits, for example, to change the | ||
| 3780 | semantics of a function like `display-buffer-other-window' by | ||
| 3781 | using the location specifiers `same-window' or `other-frame'." | ||
| 3782 | :risky t | ||
| 3783 | :type | ||
| 3784 | '(repeat | ||
| 3785 | :offset 9 | ||
| 3786 | ;; Associations of buffer identifiers and display specifiers. | ||
| 3787 | (list | ||
| 3788 | :format "%v" | ||
| 3789 | ;; Buffer identifiers. | ||
| 3790 | (repeat | ||
| 3791 | :tag "Buffer identifiers" | ||
| 3792 | (choice | ||
| 3793 | :tag "Identifier" | ||
| 3794 | :format "%[%t%] %v" :size 15 | ||
| 3795 | (cons | ||
| 3796 | :tag "Name" | ||
| 3797 | :format "%v" | ||
| 3798 | :help-echo "A buffer name." | ||
| 3799 | (const :format "" name) | ||
| 3800 | (string :format "Name: %v\n" :size 32)) | ||
| 3801 | (cons | ||
| 3802 | :tag "Regexp" | ||
| 3803 | :format "%v" | ||
| 3804 | :help-echo "A regular expression matching buffer names." | ||
| 3805 | (const :format "" regexp) | ||
| 3806 | (string :format "Regexp: %v\n" :size 32)) | ||
| 3807 | (cons | ||
| 3808 | :tag "Label" | ||
| 3809 | :format "%v" | ||
| 3810 | :help-echo "A symbol equalling the buffer display label." | ||
| 3811 | (const :format "" symbol) | ||
| 3812 | (symbol :format "Label: %v\n" :size 32)))) | ||
| 3813 | |||
| 3814 | ;; Display specifiers. | ||
| 3815 | (repeat | ||
| 3816 | :offset 9 | ||
| 3817 | :tag "Display specifiers" | ||
| 3818 | :inline t | ||
| 3819 | (list | ||
| 3820 | :inline t | ||
| 3821 | :format "%v" | ||
| 3822 | (choice | ||
| 3823 | :tag "Method" | ||
| 3824 | :value (reuse-window | ||
| 3825 | (reuse-window nil same nil) | ||
| 3826 | (reuse-window-even-sizes . t)) | ||
| 3827 | :inline t | ||
| 3828 | :help-echo "Method for displaying the buffer." | ||
| 3829 | :format "%[Method%] %v" :size 15 | ||
| 3830 | |||
| 3831 | ;; Reuse window specifiers. | ||
| 3832 | (list | ||
| 3833 | :tag "Reuse window" | ||
| 3834 | :value (reuse-window | ||
| 3835 | (reuse-window nil same nil) | ||
| 3836 | (reuse-window-even-sizes . t)) | ||
| 3837 | :format "%t\n%v" | ||
| 3838 | :inline t | ||
| 3839 | ;; For customization purposes only. | ||
| 3840 | (const :format "" reuse-window) | ||
| 3841 | (set | ||
| 3842 | :format "%v" | ||
| 3843 | :inline t | ||
| 3844 | ;; The window to reuse. | ||
| 3845 | (list | ||
| 3846 | :format "%v\n" | ||
| 3847 | (const :format "" reuse-window) | ||
| 3848 | ;; The window type. | ||
| 3849 | (choice | ||
| 3850 | :tag "Window" | ||
| 3851 | :help-echo "Window to reuse." | ||
| 3852 | :value nil | ||
| 3853 | :format "%[Window%] %v" :size 15 | ||
| 3854 | (const :tag "Any" :format "%t" nil) | ||
| 3855 | (const :tag "Selected only" :format "%t" same) | ||
| 3856 | (const :tag "Any but selected" :format "%t" other)) | ||
| 3857 | ;; The window's buffer. | ||
| 3858 | (choice | ||
| 3859 | :tag "Buffer" | ||
| 3860 | :help-echo "Buffer shown by reused window." | ||
| 3861 | :value t | ||
| 3862 | :format " %[Buffer%] %v" :size 15 | ||
| 3863 | (const :tag "Any buffer" :format "%t" nil) | ||
| 3864 | (const :tag "Same buffer" :format "%t" same) | ||
| 3865 | (const :tag "Other buffer" :format "%t" other)) | ||
| 3866 | ;; The window's frame. | ||
| 3867 | (choice | ||
| 3868 | :help-echo "Frame to search for a window to reuse." | ||
| 3869 | :tag "Frame" | ||
| 3870 | :value nil | ||
| 3871 | :format " %[Frame%] %v" :size 15 | ||
| 3872 | (const :tag "Selected frame only" :format "%t" nil) | ||
| 3873 | (const :tag "Visible frames" :format "%t" visible) | ||
| 3874 | (const :tag "Visible but unselected" :format "%t" other) | ||
| 3875 | (const :tag "Visible and iconified" :format "%t" 0) | ||
| 3876 | (const :tag "Any frame" :format "%t" t))) | ||
| 3877 | ;; Whether window sizes should be evened out. | ||
| 3878 | (cons | ||
| 3879 | :format "%v\n" | ||
| 3880 | :tag "Even window sizes" | ||
| 3881 | (const :format "" reuse-window-even-sizes) | ||
| 3882 | (choice | ||
| 3883 | :tag "Even window sizes" | ||
| 3884 | :help-echo "Whether to even sizes of selected and reused window." | ||
| 3885 | :value t | ||
| 3886 | :format "%[Even window sizes%] %v" :size 15 | ||
| 3887 | (const :tag "Off" :format "%t" nil) | ||
| 3888 | (const :tag "Even window sizes" :format "%t" t))) | ||
| 3889 | ;; Whether to reuse a dedicated window | ||
| 3890 | (cons | ||
| 3891 | :format "%v\n" | ||
| 3892 | (const :format "" reuse-window-dedicated) | ||
| 3893 | (choice | ||
| 3894 | :tag "Reuse dedicated window" :value nil | ||
| 3895 | :help-echo "Reuse a window even if it is dedicated to its buffer." | ||
| 3896 | :format "%[Reuse dedicated window%] %v" :size 15 | ||
| 3897 | (const :tag "Off" :format "%t" nil) | ||
| 3898 | (const :tag "Reuse weakly dedicated windows" :format "%t" weak) | ||
| 3899 | (const :tag "Reuse any dedicated window" :format "%t" t))))) | ||
| 3900 | |||
| 3901 | ;; Pop-up window specifiers. | ||
| 3902 | (list | ||
| 3903 | :tag "Pop-up window" | ||
| 3904 | :value (pop-up-window (pop-up-window (largest . nil) (lru . nil))) | ||
| 3905 | :format "%t\n%v" | ||
| 3906 | :inline t | ||
| 3907 | (const :format "" pop-up-window) | ||
| 3908 | (set | ||
| 3909 | :format "%v" | ||
| 3910 | :inline t | ||
| 3911 | ;; Pop-up window list. | ||
| 3912 | (list | ||
| 3913 | :format "%v" | ||
| 3914 | :value (pop-up-window (largest . nil) (lru . nil)) | ||
| 3915 | (const :format "" pop-up-window) | ||
| 3916 | (repeat | ||
| 3917 | :tag "Window / Side tuples" | ||
| 3918 | :inline t | ||
| 3919 | (cons | ||
| 3920 | :format "%v\n" | ||
| 3921 | (choice | ||
| 3922 | :tag "Window" | ||
| 3923 | :help-echo "The window to split." | ||
| 3924 | :value largest | ||
| 3925 | :format "%[Window%] %v" | ||
| 3926 | (const :tag "Largest" :format "%t" largest) | ||
| 3927 | (const :tag "Least recently used" :format "%t" lru) | ||
| 3928 | (const :tag "Selected" :format "%t" selected) | ||
| 3929 | (const :tag "Root" :format "%t" root) | ||
| 3930 | (const :tag "Left" :format "%t" left) | ||
| 3931 | (const :tag "Top" :format "%t" top) | ||
| 3932 | (const :tag "Right" :format "%t" right) | ||
| 3933 | (const :tag "Bottom" :format "%t" bottom)) | ||
| 3934 | (choice | ||
| 3935 | :tag "Side" | ||
| 3936 | :help-echo "The position of the new window with respect to the window to split." | ||
| 3937 | :value nil | ||
| 3938 | :format " %[Side%] %v" | ||
| 3939 | (const :tag "Dynamic" :format "%t" nil) | ||
| 3940 | (const :tag "Below" :format "%t" below) | ||
| 3941 | (const :tag "Right" :format "%t" right) | ||
| 3942 | (const :tag "Above" :format "%t" above) | ||
| 3943 | (const :tag "Left" :format "%t" left) | ||
| 3944 | (function | ||
| 3945 | :tag "Function" :format "%v" :size 25))))) | ||
| 3946 | ;; Minimum height of pop-up windows. | ||
| 3947 | (cons | ||
| 3948 | :format "%v\n" | ||
| 3949 | (const :format "" pop-up-window-min-height) | ||
| 3950 | (choice | ||
| 3951 | :help-echo "Minimum height of popped-up window." | ||
| 3952 | :format "%[Minimum height%] %v" | ||
| 3953 | (const :tag "Default" :format "%t" :value nil) | ||
| 3954 | (integer :tag "Number of lines" :value 12 :size 5) | ||
| 3955 | (float :tag "Fraction of frame height" :value .25 :size 5))) | ||
| 3956 | ;; Minimum width of pop-up windows. | ||
| 3957 | (cons | ||
| 3958 | :format "%v\n" | ||
| 3959 | (const :format "" pop-up-window-min-width) | ||
| 3960 | (choice | ||
| 3961 | :help-echo "Minimum width of popped-up window." | ||
| 3962 | :format "%[Minimum width%] %v" | ||
| 3963 | (const :tag "Default" :format "%t" :value nil) | ||
| 3964 | (integer :tag "Number of columns" :value 12 :size 5) | ||
| 3965 | (float :tag "Fraction of frame width" :value .25 :size 5))) | ||
| 3966 | ;; Desired height of pop-up windows. | ||
| 3967 | (cons | ||
| 3968 | :format "%v\n" | ||
| 3969 | (const :format "" pop-up-window-set-height) | ||
| 3970 | (choice | ||
| 3971 | :help-echo "Desired height of popped-up window." | ||
| 3972 | :format "%[Desired height%] %v" | ||
| 3973 | (const :tag "Default" :format "%t" :value nil) | ||
| 3974 | (integer :tag "Number of lines" :value 12 :size 5) | ||
| 3975 | (float :tag "Fraction of frame height" :value .25 :size 5) | ||
| 3976 | (function :tag "Function" :size 25))) | ||
| 3977 | ;; Desired width of pop-up windows. | ||
| 3978 | (cons | ||
| 3979 | :format "%v\n" | ||
| 3980 | (const :format "" pop-up-window-set-width) | ||
| 3981 | (choice | ||
| 3982 | :help-echo "Desired width of popped-up window." | ||
| 3983 | :format "%[Desired width%] %v" | ||
| 3984 | (const :tag "Default" :format "%t" :value nil) | ||
| 3985 | (integer :tag "Number of column" :value 12 :size 5) | ||
| 3986 | (float :tag "Fraction of frame width" :value .25 :size 5) | ||
| 3987 | (function :tag "Function" :size 25))) | ||
| 3988 | ;; Split unsplittable frames. | ||
| 3989 | (cons | ||
| 3990 | :format "%v\n" | ||
| 3991 | (const :format "" pop-up-window-unsplittable) | ||
| 3992 | (choice | ||
| 3993 | :help-echo "Allow popping up a window on \"unsplittable\" frames." | ||
| 3994 | :format "%[Split unsplittable frame%] %v" | ||
| 3995 | (const :tag "Off" :format "%t" nil) | ||
| 3996 | (const :tag "Allow" :format "%t" t))))) | ||
| 3997 | |||
| 3998 | ;; Pop-up frame specifiers. | ||
| 3999 | (list | ||
| 4000 | :tag "Pop-up frame" | ||
| 4001 | :value (pop-up-frame | ||
| 4002 | (pop-up-frame) | ||
| 4003 | (pop-up-frame-alist | ||
| 4004 | (height . 24) (width . 80) (unsplittable . t))) | ||
| 4005 | :format "%t\n%v" | ||
| 4006 | :inline t | ||
| 4007 | (const :format "" pop-up-frame) | ||
| 4008 | (set | ||
| 4009 | :format "%v" | ||
| 4010 | :inline t | ||
| 4011 | ;; Pop-up frame. | ||
| 4012 | (list | ||
| 4013 | :tag "Pop-up a new frame" | ||
| 4014 | :value (pop-up-frame) | ||
| 4015 | :format "%v" | ||
| 4016 | (const :format "" pop-up-frame) | ||
| 4017 | (choice | ||
| 4018 | :tag "Pop-up a new frame" | ||
| 4019 | :help-echo "Whether to pop-up a new frame on a display." | ||
| 4020 | :format "%[Display%] %v\n" :size 15 | ||
| 4021 | (const :tag "On any display" :format "%t" nil) | ||
| 4022 | (const :tag "On graphic displays only" :format "%t" t))) | ||
| 4023 | ;; Pop-up frame function. | ||
| 4024 | (cons | ||
| 4025 | :format "%v\n" | ||
| 4026 | (const :format "" pop-up-frame-function) | ||
| 4027 | (choice | ||
| 4028 | :tag "Pop-up frame function" | ||
| 4029 | :value nil | ||
| 4030 | :help-echo "Function to use to pop-up a new frame." | ||
| 4031 | :format "%[Function%] %v" :size 15 | ||
| 4032 | (const :tag "Default" :format "%t" nil) | ||
| 4033 | (function | ||
| 4034 | :value make-frame | ||
| 4035 | :format "%t: %v" | ||
| 4036 | :size 25))) | ||
| 4037 | ;; Pop-up frame alist. | ||
| 4038 | (list | ||
| 4039 | :format "%v" | ||
| 4040 | (const :format "" pop-up-frame-alist) | ||
| 4041 | (repeat | ||
| 4042 | :tag "Parameter / Value tuples" | ||
| 4043 | :inline t | ||
| 4044 | (cons | ||
| 4045 | :format "%v\n" | ||
| 4046 | (symbol | ||
| 4047 | :tag "Parameter" | ||
| 4048 | :format "Parameter: %v" | ||
| 4049 | :size 16) | ||
| 4050 | (sexp | ||
| 4051 | :tag "Value" | ||
| 4052 | :format " Value: %v" | ||
| 4053 | :size 8)))))) | ||
| 4054 | |||
| 4055 | ;; Use side-window specifiers. | ||
| 4056 | (list | ||
| 4057 | :tag "Use side-window" | ||
| 4058 | :value (use-side-window (use-side-window bottom 0)) | ||
| 4059 | :format "%t\n%v" | ||
| 4060 | :inline t | ||
| 4061 | ;; For customization purposes only. | ||
| 4062 | (const :format "" use-side-window) | ||
| 4063 | (set | ||
| 4064 | :format "%v" | ||
| 4065 | :inline t | ||
| 4066 | ;; Side and slot. | ||
| 4067 | (list | ||
| 4068 | :format "%v\n" | ||
| 4069 | :value (use-side-window bottom 0) | ||
| 4070 | (const :format "" use-side-window) | ||
| 4071 | ;; The side. | ||
| 4072 | (choice | ||
| 4073 | :tag "Side" | ||
| 4074 | :help-echo "Side of frame." | ||
| 4075 | :value bottom | ||
| 4076 | :format "%[Side%] %v" :size 15 | ||
| 4077 | (const :tag "Left" :format "%t" left) | ||
| 4078 | (const :tag "Top" :format "%t" top) | ||
| 4079 | (const :tag "Right" :format "%t" right) | ||
| 4080 | (const :tag "Bottom" :format "%t" bottom)) | ||
| 4081 | ;; The slot | ||
| 4082 | (number | ||
| 4083 | :tag "Slot" | ||
| 4084 | :help-echo "The slot (an arbitrary number, where 0 stands for the center slot)." | ||
| 4085 | :value 0 | ||
| 4086 | :format " Slot: %v" :size 8)) | ||
| 4087 | ;; Whether to reuse a dedicated side window | ||
| 4088 | (cons | ||
| 4089 | :format "%v\n" | ||
| 4090 | (const :format "" reuse-window-dedicated) | ||
| 4091 | (choice | ||
| 4092 | :tag "Reuse dedicated side window" :value nil | ||
| 4093 | :help-echo "Reuse a side window even if it is dedicated to its buffer." | ||
| 4094 | :format "%[Reuse dedicated side window%] %v" :size 15 | ||
| 4095 | (const :tag "Off" :format "%t" nil) | ||
| 4096 | (const :tag "Reuse weakly dedicated side windows" :format "%t" weak) | ||
| 4097 | (const :tag "Reuse any dedicated side window" :format "%t" t))) | ||
| 4098 | ;; Minimum height of pop-up side windows. | ||
| 4099 | (cons | ||
| 4100 | :format "%v\n" | ||
| 4101 | (const :format "" pop-up-window-min-height) | ||
| 4102 | (choice | ||
| 4103 | :help-echo "Minimum height of popped-up side window." | ||
| 4104 | :format "%[Minimum height%] %v" | ||
| 4105 | (const :tag "Default" :format "%t" :value nil) | ||
| 4106 | (integer :tag "Number of lines" :value 12 :size 5) | ||
| 4107 | (float :tag "Fraction of frame height" :value .25 :size 5))) | ||
| 4108 | ;; Minimum width of pop-up windows. | ||
| 4109 | (cons | ||
| 4110 | :format "%v\n" | ||
| 4111 | (const :format "" pop-up-window-min-width) | ||
| 4112 | (choice | ||
| 4113 | :help-echo "Minimum width of popped-up side window." | ||
| 4114 | :format "%[Minimum width%] %v" | ||
| 4115 | (const :tag "Default" :format "%t" :value nil) | ||
| 4116 | (integer :tag "Number of columns" :value 12 :size 5) | ||
| 4117 | (float :tag "Fraction of frame width" :value .25 :size 5))) | ||
| 4118 | ;; Desired height of pop-up windows. | ||
| 4119 | (cons | ||
| 4120 | :format "%v\n" | ||
| 4121 | (const :format "" pop-up-window-set-height) | ||
| 4122 | (choice | ||
| 4123 | :help-echo "Desired height of popped-up side window." | ||
| 4124 | :format "%[Desired height%] %v" | ||
| 4125 | (const :tag "Default" :format "%t" :value nil) | ||
| 4126 | (integer :tag "Number of lines" :value 12 :size 5) | ||
| 4127 | (float :tag "Fraction of frame height" :value .25 :size 5) | ||
| 4128 | (function :tag "Function" :size 25))) | ||
| 4129 | ;; Desired width of pop-up windows. | ||
| 4130 | (cons | ||
| 4131 | :format "%v\n" | ||
| 4132 | (const :format "" pop-up-window-set-width) | ||
| 4133 | (choice | ||
| 4134 | :help-echo "Desired width of popped-up side window." | ||
| 4135 | :format "%[Desired width%] %v" | ||
| 4136 | (const :tag "Default" :format "%t" :value nil) | ||
| 4137 | (integer :tag "Number of column" :value 12 :size 5) | ||
| 4138 | (float :tag "Fraction of frame width" :value .25 :size 5) | ||
| 4139 | (function :tag "Function" :size 25))))) | ||
| 4140 | |||
| 4141 | ;; Function with argument specifiers. | ||
| 4142 | (list | ||
| 4143 | :tag "Function with arguments" | ||
| 4144 | :value (fun-with-args (fun-with-args 'ignore)) | ||
| 4145 | :format "%t\n%v" | ||
| 4146 | :inline t | ||
| 4147 | ;; For customization purposes only. | ||
| 4148 | (const :format "" fun-with-args) | ||
| 4149 | (set | ||
| 4150 | :format "%v" | ||
| 4151 | :inline t | ||
| 4152 | (list | ||
| 4153 | :format "%v" | ||
| 4154 | :value (fun-with-args 'ignore) | ||
| 4155 | (const :format "" fun-with-args) | ||
| 4156 | (function :tag "Function" :format "%t: %v\n" :size 25) | ||
| 4157 | (list | ||
| 4158 | :format "%v" | ||
| 4159 | (repeat | ||
| 4160 | :tag "Arguments" | ||
| 4161 | :inline t | ||
| 4162 | (sexp | ||
| 4163 | :format "%v\n" | ||
| 4164 | :size 16)))))) | ||
| 4165 | |||
| 4166 | ;; Macro specifiers. | ||
| 4167 | (list | ||
| 4168 | :tag "Same frame only" | ||
| 4169 | :format "%t%v" | ||
| 4170 | :inline t | ||
| 4171 | (const :format "\n" same-frame)) | ||
| 4172 | (list | ||
| 4173 | :tag "Other window" | ||
| 4174 | :format "%t%v" | ||
| 4175 | :inline t | ||
| 4176 | (const :format "\n" other-window)) | ||
| 4177 | (list | ||
| 4178 | :tag "Same frame other window" | ||
| 4179 | :format "%t%v" | ||
| 4180 | :inline t | ||
| 4181 | (const :format "\n" same-frame-other-window)) | ||
| 4182 | (list | ||
| 4183 | :tag "Other frame only" | ||
| 4184 | :format "%t%v" | ||
| 4185 | :inline t | ||
| 4186 | (const :format "\n" other-frame)) | ||
| 4187 | (list | ||
| 4188 | :tag "Default" | ||
| 4189 | :format "%t%v" | ||
| 4190 | :inline t | ||
| 4191 | (const :format "\n" default))))) | ||
| 4192 | |||
| 4193 | (set | ||
| 4194 | :format "%v" | ||
| 4195 | :inline t | ||
| 4196 | ;; Dedicate window to buffer. | ||
| 4197 | (cons | ||
| 4198 | :format "%v" | ||
| 4199 | (const :format "" dedicate) | ||
| 4200 | (choice | ||
| 4201 | :help-echo "Mark window as dedicated to its buffer." | ||
| 4202 | :format "%[Dedicate window to buffer%] %v\n" :size 15 | ||
| 4203 | (const :tag "Off" :format "%t" nil) | ||
| 4204 | (const :tag "Weak" :format "%t" weak) | ||
| 4205 | (const :tag "Strong" :format "%t" t))) | ||
| 4206 | ;; No other window. | ||
| 4207 | (cons | ||
| 4208 | :format "%v" | ||
| 4209 | (const :format "" no-other-window) | ||
| 4210 | (choice | ||
| 4211 | :help-echo "Whether `other-window' shall ignore the window." | ||
| 4212 | :format "%[No other window%] %v\n" :size 15 | ||
| 4213 | (const :tag "Off" :format "%t" nil) | ||
| 4214 | (const :tag "Ignore" :format "%t" t))) | ||
| 4215 | ;; Overriding. | ||
| 4216 | (cons | ||
| 4217 | :format "%v\n" | ||
| 4218 | (const :format "" override) | ||
| 4219 | (choice | ||
| 4220 | :help-echo "Override application supplied specifiers." | ||
| 4221 | :format "%[Override%] %v" | ||
| 4222 | (const :tag "Off" :format "%t" nil) | ||
| 4223 | (const :tag "Override" :format "%t" t)))))) | ||
| 4224 | :group 'windows | ||
| 4225 | :group 'frames) | ||
| 4226 | |||
| 3458 | (defcustom display-buffer-function nil | 4227 | (defcustom display-buffer-function nil |
| 3459 | "If non-nil, function to call to handle `display-buffer'. | 4228 | "If non-nil, function to call to display a buffer. |
| 3460 | It will receive two args, the buffer and a flag which if non-nil | 4229 | `display-buffer' calls this function with two arguments, the |
| 3461 | means that the currently selected window is not acceptable. It | 4230 | buffer to display and a list of buffer display specifiers, see |
| 3462 | should choose or create a window, display the specified buffer in | 4231 | `display-buffer-alist'. |
| 3463 | it, and return the window. | 4232 | |
| 3464 | 4233 | The function is supposed to choose or create a window, display | |
| 3465 | Commands such as `switch-to-buffer-other-window' and | 4234 | the specified buffer in it, and return the window. It is also |
| 3466 | `find-file-other-window' work using this function." | 4235 | responsible for giving the variable `display-buffer-window' and |
| 4236 | the `quit-restore' parameter of the window used a meaningful | ||
| 4237 | value. | ||
| 4238 | |||
| 4239 | The function specified here overrides all specifiers of the | ||
| 4240 | variable `display-buffer-alist' any specifiers passed to | ||
| 4241 | `display-buffer'. | ||
| 4242 | |||
| 4243 | If you call `display-buffer' within the body of the function, | ||
| 4244 | bind the value of `display-buffer-function' to nil around that | ||
| 4245 | call to avoid that the function recursively calls itself." | ||
| 3467 | :type '(choice | 4246 | :type '(choice |
| 3468 | (const nil) | 4247 | (const nil) |
| 3469 | (function :tag "function")) | 4248 | (function :tag "Function")) |
| 4249 | :group 'windows) | ||
| 4250 | |||
| 4251 | ;; The following is a global variable which is used externally (by | ||
| 4252 | ;; help.el) to (1) know which window was used for displaying a buffer | ||
| 4253 | ;; and (2) whether the window was new or reused. | ||
| 4254 | (defvar display-buffer-window nil | ||
| 4255 | "Window used by `display-buffer' and related information. | ||
| 4256 | After `display-buffer' displays a buffer in some window this | ||
| 4257 | variable is a cons cell whose car denotes the window used to | ||
| 4258 | display the buffer. The cdr is supposed to be one of the symbols | ||
| 4259 | `reuse-buffer-window', `reuse-other-window', `new-window' or | ||
| 4260 | `new-frame'. | ||
| 4261 | |||
| 4262 | If the buffer display location specifier is one of 'same-window, | ||
| 4263 | 'same-frame, or 'other-frame, the `display-buffer' routines | ||
| 4264 | assign the value of this variable. If the location specifier is | ||
| 4265 | a function, that function becomes responsible for assigning a | ||
| 4266 | meaningful value to this variable. See the functions | ||
| 4267 | `display-buffer-reuse-window', `display-buffer-pop-up-window' and | ||
| 4268 | `display-buffer-pop-up-frame' for how this can be done.") | ||
| 4269 | |||
| 4270 | (defun display-buffer-even-window-sizes (window specifiers) | ||
| 4271 | "Even sizes of WINDOW and selected window according to SPECIFIERS. | ||
| 4272 | SPECIFIERS must be a list of buffer display specifiers, see the | ||
| 4273 | documentation of `display-buffer-alist' for a description. | ||
| 4274 | |||
| 4275 | Sizes are evened out if and only if WINDOW and the selected | ||
| 4276 | window appear next to each other and the selected window is | ||
| 4277 | larger than WINDOW." | ||
| 4278 | (cond | ||
| 4279 | ((or (not (cdr (assq 'reuse-window-even-sizes specifiers))) | ||
| 4280 | ;; Don't resize minibuffer windows. | ||
| 4281 | (window-minibuffer-p) | ||
| 4282 | ;; WINDOW must be adjacent to the selected one. | ||
| 4283 | (not (or (eq window (window-prev)) | ||
| 4284 | (eq window (window-next)))))) | ||
| 4285 | ((and (window-iso-combined-p window) | ||
| 4286 | ;; Resize iff the selected window is higher than WINDOW. | ||
| 4287 | (> (window-total-height) (window-total-height window))) | ||
| 4288 | ;; Don't throw an error if we can't even window heights for | ||
| 4289 | ;; whatever reason. In any case, enlarging the selected window | ||
| 4290 | ;; might fail anyway if there are other windows above or below | ||
| 4291 | ;; WINDOW and the selected one. But for a simple two windows | ||
| 4292 | ;; configuration the present behavior is good enough so why care? | ||
| 4293 | (ignore-errors | ||
| 4294 | (resize-window | ||
| 4295 | window (/ (- (window-total-height) (window-total-height window)) | ||
| 4296 | 2)))) | ||
| 4297 | ((and (window-iso-combined-p window t) | ||
| 4298 | ;; Resize iff the selected window is wider than WINDOW. | ||
| 4299 | (> (window-total-width) (window-total-width window))) | ||
| 4300 | ;; Don't throw an error if we can't even window widths, see | ||
| 4301 | ;; comment above. | ||
| 4302 | (ignore-errors | ||
| 4303 | (resize-window | ||
| 4304 | window (/ (- (window-total-width) (window-total-width window)) | ||
| 4305 | 2) t))))) | ||
| 4306 | |||
| 4307 | (defun display-buffer-set-height (window specifiers) | ||
| 4308 | "Adjust height of WINDOW according to SPECIFIERS. | ||
| 4309 | SPECIFIERS must be a list of buffer display specifiers, see the | ||
| 4310 | documentation of `display-buffer-alist' for a description." | ||
| 4311 | (let ((set-height (cdr (assq 'pop-up-window-set-height specifiers)))) | ||
| 4312 | (cond | ||
| 4313 | ((numberp set-height) | ||
| 4314 | (let* ((height (if (integerp set-height) | ||
| 4315 | set-height | ||
| 4316 | (round | ||
| 4317 | (* (window-total-size (frame-root-window window)) | ||
| 4318 | set-height)))) | ||
| 4319 | (delta (- height (window-total-size window)))) | ||
| 4320 | (when (and (window-resizable-p window delta nil 'safe) | ||
| 4321 | (window-iso-combined-p window)) | ||
| 4322 | (resize-window window delta nil 'safe)))) | ||
| 4323 | ((functionp set-height) | ||
| 4324 | (ignore-errors (funcall set-height window)))))) | ||
| 4325 | |||
| 4326 | (defun display-buffer-set-width (window specifiers) | ||
| 4327 | "Adjust width of WINDOW according to SPECIFIERS. | ||
| 4328 | SPECIFIERS must be a list of buffer display specifiers, see the | ||
| 4329 | documentation of `display-buffer-alist' for a description." | ||
| 4330 | (let ((set-width (cdr (assq 'pop-up-window-set-width specifiers)))) | ||
| 4331 | (cond | ||
| 4332 | ((numberp set-width) | ||
| 4333 | (let* ((width (if (integerp set-width) | ||
| 4334 | set-width | ||
| 4335 | (round | ||
| 4336 | (* (window-total-size (frame-root-window window) t) | ||
| 4337 | set-width)))) | ||
| 4338 | (delta (- width (window-total-size window t)))) | ||
| 4339 | (when (and (window-resizable-p window delta t 'safe) | ||
| 4340 | (window-iso-combined-p window t)) | ||
| 4341 | (resize-window window delta t 'safe)))) | ||
| 4342 | ((functionp set-width) | ||
| 4343 | (ignore-errors (funcall set-width window)))))) | ||
| 4344 | |||
| 4345 | ;; We have to work around the deficiency that the command loop does not | ||
| 4346 | ;; preserve the selected window when it is on a frame that hasn't been | ||
| 4347 | ;; raised or given input focus. So we have to (1) select the window | ||
| 4348 | ;; used for displaying a buffer and (2) raise its frame if necessary, | ||
| 4349 | ;; thus defeating one primary principle of `display-buffer' namely to | ||
| 4350 | ;; _not_ select the window chosen for displaying the buffer :-( | ||
| 4351 | (defun display-buffer-select-window (window &optional norecord) | ||
| 4352 | "Select WINDOW and raise its frame if necessary." | ||
| 4353 | (let ((old-frame (selected-frame)) | ||
| 4354 | (new-frame (window-frame window))) | ||
| 4355 | ;; Select WINDOW _before_ raising the frame to assure that the mouse | ||
| 4356 | ;; cursor moves into the correct window. | ||
| 4357 | (select-window window norecord) | ||
| 4358 | (unless (eq old-frame new-frame) | ||
| 4359 | (select-frame-set-input-focus new-frame)))) | ||
| 4360 | |||
| 4361 | (defun display-buffer-in-window (buffer window specifiers) | ||
| 4362 | "Display BUFFER in WINDOW and raise its frame if needed. | ||
| 4363 | WINDOW must be a live window and defaults to the selected one. | ||
| 4364 | Return WINDOW. | ||
| 4365 | |||
| 4366 | SPECIFIERS must be a list of buffer display specifiers, see the | ||
| 4367 | documentation of `display-buffer-alist' for a description." | ||
| 4368 | (setq buffer (normalize-live-buffer buffer)) | ||
| 4369 | (setq window (normalize-live-window window)) | ||
| 4370 | (let* ((old-frame (selected-frame)) | ||
| 4371 | (new-frame (window-frame window)) | ||
| 4372 | (dedicated (cdr (assq 'dedicated specifiers))) | ||
| 4373 | (no-other-window (cdr (assq 'no-other-window specifiers)))) | ||
| 4374 | ;; Show BUFFER in WINDOW. | ||
| 4375 | (set-window-dedicated-p window nil) | ||
| 4376 | (set-window-buffer window buffer) | ||
| 4377 | (when dedicated | ||
| 4378 | (set-window-dedicated-p window dedicated)) | ||
| 4379 | (when no-other-window | ||
| 4380 | (set-window-parameter window 'no-other-window t)) | ||
| 4381 | (unless (eq old-frame new-frame) | ||
| 4382 | (display-buffer-select-window window)) | ||
| 4383 | ;; Return window. | ||
| 4384 | window)) | ||
| 4385 | |||
| 4386 | (defun display-buffer-reuse-window (buffer method &optional specifiers) | ||
| 4387 | "Display BUFFER in an existing window. | ||
| 4388 | METHOD must be a list in the form of the cdr of a `reuse-window' | ||
| 4389 | buffer display specifier, see `display-buffer-alist' for an | ||
| 4390 | explanation. The first element must specifiy the window to use, | ||
| 4391 | and can be either nil, `same', `other', or a live window. The | ||
| 4392 | second element must specify the window's buffer and can be either | ||
| 4393 | nil, `same', `other', or a live buffer. The third element is the | ||
| 4394 | frame to use - either nil, 0, `visible', `other', t, or a live | ||
| 4395 | frame. | ||
| 4396 | |||
| 4397 | Optional argument SPECIFIERS must be a list of valid display | ||
| 4398 | specifiers. Return the window chosen to display BUFFER, nil if | ||
| 4399 | none was found." | ||
| 4400 | (let* ((method-window (nth 0 method)) | ||
| 4401 | (method-buffer (nth 1 method)) | ||
| 4402 | (method-frame (nth 2 method)) | ||
| 4403 | (reuse-dedicated (assq 'reuse-window-dedicated specifiers)) | ||
| 4404 | windows other-frame dedicated time best-window best-time) | ||
| 4405 | (when (eq method-frame 'other) | ||
| 4406 | ;; `other' is not handled by `window-list-1'. | ||
| 4407 | (setq other-frame t) | ||
| 4408 | (setq method-frame t)) | ||
| 4409 | (dolist (window (window-list-1 nil 'nomini method-frame)) | ||
| 4410 | (let ((window-buffer (window-buffer window))) | ||
| 4411 | (when (and (not (window-minibuffer-p window)) | ||
| 4412 | ;; Don't reuse a side window. | ||
| 4413 | (or (not (eq (window-parameter window 'window-side) 'side)) | ||
| 4414 | (eq window-buffer buffer)) | ||
| 4415 | (or (not method-window) | ||
| 4416 | (and (eq method-window 'same) | ||
| 4417 | (eq window (selected-window))) | ||
| 4418 | (and (eq method-window 'other) | ||
| 4419 | (not (eq window (selected-window)))) | ||
| 4420 | ;; Special case for applications that specifiy | ||
| 4421 | ;; the window explicitly. | ||
| 4422 | (eq method-window window)) | ||
| 4423 | (or (not method-buffer) | ||
| 4424 | (and (eq method-buffer 'same) | ||
| 4425 | (eq window-buffer buffer)) | ||
| 4426 | (and (eq method-buffer 'other) | ||
| 4427 | (not (eq window-buffer buffer))) | ||
| 4428 | ;; Special case for applications that specifiy | ||
| 4429 | ;; the window's buffer explicitly. | ||
| 4430 | (eq method-buffer window-buffer)) | ||
| 4431 | (or (not other-frame) | ||
| 4432 | (not (eq (window-frame window) (selected-frame)))) | ||
| 4433 | ;; Handle dedicatedness. | ||
| 4434 | (or (eq window-buffer buffer) | ||
| 4435 | ;; The window does not show the same buffer. | ||
| 4436 | (not (setq dedicated (window-dedicated-p window))) | ||
| 4437 | ;; If the window is weakly dedicated to its | ||
| 4438 | ;; buffer, reuse-dedicated must be non-nil. | ||
| 4439 | (and (not (eq dedicated t)) reuse-dedicated) | ||
| 4440 | ;; If the window is strongly dedicated to its | ||
| 4441 | ;; buffer, reuse-dedicated must be t. | ||
| 4442 | (eq reuse-dedicated t))) | ||
| 4443 | (setq windows (cons window windows))))) | ||
| 4444 | |||
| 4445 | (if (eq method-buffer 'same) | ||
| 4446 | ;; When reusing a window on the same buffer use the lru one. | ||
| 4447 | (dolist (window windows) | ||
| 4448 | (setq time (window-use-time window)) | ||
| 4449 | (when (or (not best-window) (< time best-time)) | ||
| 4450 | (setq best-window window) | ||
| 4451 | (setq best-time time))) | ||
| 4452 | ;; Otherwise, sort windows according to their use-time. | ||
| 4453 | (setq windows | ||
| 4454 | (sort windows | ||
| 4455 | #'(lambda (window-1 window-2) | ||
| 4456 | (<= (window-use-time window-1) | ||
| 4457 | (window-use-time window-2))))) | ||
| 4458 | (setq best-window | ||
| 4459 | ;; Try to get a full-width window (this is silly and can | ||
| 4460 | ;; get us to another frame but let's ignore these issues | ||
| 4461 | ;; for the moment). | ||
| 4462 | (catch 'found | ||
| 4463 | (dolist (window windows) | ||
| 4464 | (when (window-full-width-p window) | ||
| 4465 | (throw 'found window))) | ||
| 4466 | ;; If there's no full-width window return the lru window. | ||
| 4467 | (car windows)))) | ||
| 4468 | |||
| 4469 | (when best-window | ||
| 4470 | (display-buffer-even-window-sizes best-window specifiers) | ||
| 4471 | ;; Never change the quit-restore parameter of a window here. | ||
| 4472 | (if (eq (window-buffer best-window) buffer) | ||
| 4473 | (setq display-buffer-window | ||
| 4474 | (cons best-window 'reuse-buffer-window)) | ||
| 4475 | (setq display-buffer-window | ||
| 4476 | (cons best-window 'reuse-other-window)) | ||
| 4477 | (unless (window-parameter best-window 'quit-restore) | ||
| 4478 | ;; Don't overwrite an existing quit-restore entry. | ||
| 4479 | (set-window-parameter | ||
| 4480 | best-window 'quit-restore | ||
| 4481 | (list (window-buffer best-window) (window-start best-window) | ||
| 4482 | (window-point best-window) buffer | ||
| 4483 | (window-total-size best-window) (selected-window))))) | ||
| 4484 | |||
| 4485 | (display-buffer-in-window buffer best-window specifiers)))) | ||
| 4486 | |||
| 4487 | (defconst display-buffer-split-specifiers '(largest lru selected root left top right bottom) | ||
| 4488 | "List of symbols identifying window that shall be split.") | ||
| 4489 | |||
| 4490 | (defconst display-buffer-side-specifiers '(below right above left nil) | ||
| 4491 | "List of symbols identifying side of split-off window.") | ||
| 4492 | |||
| 4493 | (defun display-buffer-split-window-1 (window side min-size) | ||
| 4494 | "Subroutine of `display-buffer-split-window'." | ||
| 4495 | (let* ((horizontal (memq side '(left right))) | ||
| 4496 | (parent (window-parent window)) | ||
| 4497 | (resize (and window-splits (window-iso-combined-p window horizontal))) | ||
| 4498 | (old-size | ||
| 4499 | ;; We either resize WINDOW or its parent. | ||
| 4500 | (window-total-size (if resize parent window) horizontal)) | ||
| 4501 | new-size) | ||
| 4502 | ;; We don't call split-window-vertically/-horizontally any more | ||
| 4503 | ;; here. If for some reason it's needed we can always do so | ||
| 4504 | ;; (provided we give it an optional SIDE argument). | ||
| 4505 | (cond | ||
| 4506 | (resize | ||
| 4507 | ;; When we resize a combination, the new window must be at least | ||
| 4508 | ;; MIN-SIZE large after the split. | ||
| 4509 | (setq new-size | ||
| 4510 | (max min-size | ||
| 4511 | (min (- old-size (window-min-size parent horizontal)) | ||
| 4512 | (/ old-size | ||
| 4513 | ;; Try to make the size of the new window | ||
| 4514 | ;; proportional to the number of iso-arranged | ||
| 4515 | ;; windows in the combination. | ||
| 4516 | (1+ (window-iso-combinations parent horizontal)))))) | ||
| 4517 | (when (window-sizable-p parent (- new-size) horizontal) | ||
| 4518 | (split-window window (- new-size) side))) | ||
| 4519 | ((window-live-p window) | ||
| 4520 | (setq new-size (/ old-size 2)) | ||
| 4521 | ;; When WINDOW is live, the old _and_ the new window must be at | ||
| 4522 | ;; least MIN-SIZE large after the split. | ||
| 4523 | (when (and (>= new-size min-size) | ||
| 4524 | (window-sizable-p window (- new-size) horizontal)) | ||
| 4525 | ;; Do an even split to make Stepan happy. | ||
| 4526 | (split-window window nil side))) | ||
| 4527 | (t | ||
| 4528 | ;; When WINDOW is internal, the new window must be at least | ||
| 4529 | ;; MIN-SIZE large after the split. | ||
| 4530 | (setq new-size | ||
| 4531 | (max min-size | ||
| 4532 | (/ old-size | ||
| 4533 | ;; Try to make the size of the new window | ||
| 4534 | ;; proportional to the number of iso-arranged | ||
| 4535 | ;; subwindows of WINDOW. | ||
| 4536 | (1+ (window-iso-combinations window horizontal))))) | ||
| 4537 | (when (window-sizable-p window (- new-size) horizontal) | ||
| 4538 | (split-window window (- new-size) side)))))) | ||
| 4539 | |||
| 4540 | (defun display-buffer-split-window (window &optional side specifiers) | ||
| 4541 | "Split WINDOW in a way suitable for `display-buffer'. | ||
| 4542 | Optional argument SIDE must be a side specifier \(one of the | ||
| 4543 | symbols below, right, above, left, or nil). SPECIFIERS must be a | ||
| 4544 | list of buffer display specifiers, see the documentation of | ||
| 4545 | `display-buffer-alist' for a description. | ||
| 4546 | |||
| 4547 | Return the new window, nil if it could not be created." | ||
| 4548 | (let ((min-height (cdr (assq 'pop-up-window-min-height specifiers))) | ||
| 4549 | (min-width (cdr (assq 'pop-up-window-min-width specifiers))) | ||
| 4550 | size) | ||
| 4551 | ;; Normalize min-height and min-width, we might need both. | ||
| 4552 | (setq min-height | ||
| 4553 | ;; If min-height is specified, it can be as small as | ||
| 4554 | ;; `window-safe-min-height'. | ||
| 4555 | (cond | ||
| 4556 | ((and (integerp min-height) | ||
| 4557 | (>= min-height window-safe-min-height)) | ||
| 4558 | min-height) | ||
| 4559 | ((and (floatp min-height) | ||
| 4560 | (<= min-height 1) | ||
| 4561 | (let* ((root-height (window-total-height | ||
| 4562 | (frame-root-window | ||
| 4563 | (window-frame window)))) | ||
| 4564 | (height (round (* min-height root-height)))) | ||
| 4565 | (when (>= height window-safe-min-height) | ||
| 4566 | height)))) | ||
| 4567 | (t window-min-height))) | ||
| 4568 | (setq min-width | ||
| 4569 | ;; If min-width is specified, it can be as small as | ||
| 4570 | ;; `window-safe-min-width'. | ||
| 4571 | (cond | ||
| 4572 | ((and (integerp min-width) | ||
| 4573 | (>= min-width window-safe-min-width)) | ||
| 4574 | min-width) | ||
| 4575 | ((and (floatp min-width) | ||
| 4576 | (<= min-width 1) | ||
| 4577 | (let* ((root-width (window-total-width | ||
| 4578 | (frame-root-window | ||
| 4579 | (window-frame window)))) | ||
| 4580 | (width (round (* min-width root-width)))) | ||
| 4581 | (when (>= width window-safe-min-width) | ||
| 4582 | width)))) | ||
| 4583 | (t window-min-width))) | ||
| 4584 | |||
| 4585 | (or (and (memq side '(nil above below)) | ||
| 4586 | (display-buffer-split-window-1 | ||
| 4587 | window (or side 'below) min-height)) | ||
| 4588 | ;; If SIDE is nil and vertical splitting failed, we try again | ||
| 4589 | ;; splitting horizontally this time. | ||
| 4590 | (and (memq side '(nil left right)) | ||
| 4591 | (display-buffer-split-window-1 | ||
| 4592 | window (or side 'right) min-width)) | ||
| 4593 | ;; If WINDOW is live and the root window of its frame, try once | ||
| 4594 | ;; more splitting vertically, disregarding the min-height | ||
| 4595 | ;; specifier this time and using `window-min-height' instead. | ||
| 4596 | (and (memq side '(nil above below)) | ||
| 4597 | (<= window-min-height min-height) | ||
| 4598 | (window-live-p window) | ||
| 4599 | (eq window (frame-root-window window)) | ||
| 4600 | (display-buffer-split-window-1 | ||
| 4601 | window (or side 'below) window-min-height))))) | ||
| 4602 | |||
| 4603 | (defun display-buffer-split-atom-window (window &optional side nest specifiers) | ||
| 4604 | "Make WINDOW part of an atomic window." | ||
| 4605 | (let ((ignore-window-parameters t) | ||
| 4606 | (window-nest t) | ||
| 4607 | (selected-window (selected-window)) | ||
| 4608 | root new new-parent) | ||
| 4609 | |||
| 4610 | ;; We are in an atomic window. | ||
| 4611 | (when (and (window-parameter window 'window-atom) (not nest)) | ||
| 4612 | ;; Split the root window. | ||
| 4613 | (setq window (window-atom-root window))) | ||
| 4614 | |||
| 4615 | (when (setq new (display-buffer-split-window window side specifiers)) | ||
| 4616 | (setq new-parent (window-parent window)) | ||
| 4617 | ;; WINDOW is or becomes atomic. | ||
| 4618 | (unless (window-parameter window 'window-atom) | ||
| 4619 | (walk-window-subtree | ||
| 4620 | (lambda (window) | ||
| 4621 | (set-window-parameter window 'window-atom t)) | ||
| 4622 | window t)) | ||
| 4623 | ;; New window and any new parent get their window-atom parameter | ||
| 4624 | ;; set too. | ||
| 4625 | (set-window-parameter new 'window-atom t) | ||
| 4626 | (set-window-parameter new-parent 'window-atom t) | ||
| 4627 | new))) | ||
| 4628 | |||
| 4629 | (defun display-buffer-pop-up-window (buffer methods &optional specifiers) | ||
| 4630 | "Display BUFFER in a new window. | ||
| 4631 | Return the window displaying BUFFER, nil if popping up the window | ||
| 4632 | failed. METHODS must be a list of window/side tuples like those | ||
| 4633 | forming the cdr of the `pop-up-window' buffer display specifier. | ||
| 4634 | As a special case, the car of such a tuple can be also a live | ||
| 4635 | window. | ||
| 4636 | |||
| 4637 | Optional argument SPECIFIERS must be a list of buffer display | ||
| 4638 | specifiers, see the doc-string of `display-buffer-alist' for a | ||
| 4639 | description." | ||
| 4640 | (let* ((frame (display-buffer-frame)) | ||
| 4641 | (selected-window (frame-selected-window frame)) | ||
| 4642 | window side atomic) | ||
| 4643 | (unless (and (cdr (assq 'unsplittable (frame-parameters frame))) | ||
| 4644 | ;; Don't split an unsplittable frame unless | ||
| 4645 | ;; SPECIFIERS allow it. | ||
| 4646 | (not (cdr (assq 'split-unsplittable-frame specifiers)))) | ||
| 4647 | (catch 'done | ||
| 4648 | (dolist (method methods) | ||
| 4649 | (setq window (car method)) | ||
| 4650 | (setq side (cdr method)) | ||
| 4651 | (and (setq window | ||
| 4652 | (cond | ||
| 4653 | ((eq window 'largest) | ||
| 4654 | (get-largest-window frame t)) | ||
| 4655 | ((eq window 'lru) | ||
| 4656 | (get-lru-window frame t)) | ||
| 4657 | ((eq window 'selected) | ||
| 4658 | (frame-selected-window frame)) | ||
| 4659 | ((eq window 'root) | ||
| 4660 | ;; If there are side windows, split the main | ||
| 4661 | ;; window else the frame root window. | ||
| 4662 | (or (window-with-parameter 'window-side 'none nil t) | ||
| 4663 | (frame-root-window frame))) | ||
| 4664 | ((memq window window-sides) | ||
| 4665 | ;; This should gets us the "root" side | ||
| 4666 | ;; window if there exists more than one. | ||
| 4667 | (window-with-parameter 'window-side window nil t)) | ||
| 4668 | ((windowp window) | ||
| 4669 | ;; A window, directly specified. | ||
| 4670 | window))) | ||
| 4671 | ;; The window must be on the selected frame, | ||
| 4672 | (eq (window-frame window) frame) | ||
| 4673 | ;; and must be neither a minibuffer window, | ||
| 4674 | (not (window-minibuffer-p window)) | ||
| 4675 | ;; nor a side window. | ||
| 4676 | (not (eq (window-parameter window 'window-side) 'side)) | ||
| 4677 | (setq window | ||
| 4678 | (cond | ||
| 4679 | ((memq side display-buffer-side-specifiers) | ||
| 4680 | (if (and (window-buffer window) | ||
| 4681 | (setq atomic (cdr (assq 'atomic specifiers)))) | ||
| 4682 | (display-buffer-split-atom-window | ||
| 4683 | window side (eq atomic 'nest) specifiers) | ||
| 4684 | (display-buffer-split-window window side specifiers))) | ||
| 4685 | ((functionp side) | ||
| 4686 | (ignore-errors | ||
| 4687 | ;; Don't pass any specifiers to this function. | ||
| 4688 | (funcall side window))))) | ||
| 4689 | (throw 'done window)))) | ||
| 4690 | |||
| 4691 | (when window | ||
| 4692 | ;; Adjust sizes if asked for. | ||
| 4693 | (display-buffer-set-height window specifiers) | ||
| 4694 | (display-buffer-set-width window specifiers) | ||
| 4695 | (set-window-parameter | ||
| 4696 | window 'quit-restore (list 'new-window buffer selected-window)) | ||
| 4697 | (setq display-buffer-window (cons window 'new-window)) | ||
| 4698 | (display-buffer-in-window buffer window specifiers) | ||
| 4699 | (set-window-prev-buffers window nil) | ||
| 4700 | window)))) | ||
| 4701 | |||
| 4702 | (defun display-buffer-pop-up-frame (buffer &optional graphic-only specifiers) | ||
| 4703 | "Make a new frame for displaying BUFFER. | ||
| 4704 | Return the window displaying BUFFER if creating the new frame was | ||
| 4705 | successful, nil otherwise. Optional argument GRAPHIC-ONLY | ||
| 4706 | non-nil means to make a new frame on graphic displays only. | ||
| 4707 | |||
| 4708 | SPECIFIERS must be a list of buffer display specifiers, see the | ||
| 4709 | documentation of `display-buffer-alist' for a description." | ||
| 4710 | (unless (and graphic-only (not (display-graphic-p))) | ||
| 4711 | (let* ((selected-window (selected-window)) | ||
| 4712 | (function (or (cdr (assq 'pop-up-frame-function specifiers)) | ||
| 4713 | 'make-frame)) | ||
| 4714 | (parameters | ||
| 4715 | (when (symbolp function) | ||
| 4716 | (cdr (assq 'pop-up-frame-alist specifiers)))) | ||
| 4717 | (frame | ||
| 4718 | (if (symbolp function) | ||
| 4719 | (funcall function parameters) | ||
| 4720 | (funcall function)))) | ||
| 4721 | (when frame | ||
| 4722 | (let ((window (frame-selected-window frame))) | ||
| 4723 | (set-window-parameter | ||
| 4724 | window 'quit-restore (list 'new-frame buffer selected-window)) | ||
| 4725 | (setq display-buffer-window (cons window 'new-frame)) | ||
| 4726 | (display-buffer-in-window buffer window specifiers)))))) | ||
| 4727 | |||
| 4728 | (defun display-buffer-pop-up-side-window (buffer side slot &optional specifiers) | ||
| 4729 | "Display BUFFER in a new window on SIDE of the selected frame. | ||
| 4730 | SLOT specifies the slot to use. SPECIFIERS must be a list of | ||
| 4731 | buffer display specifiers. | ||
| 4732 | |||
| 4733 | Return the window displaying BUFFER, nil if popping up the window | ||
| 4734 | failed." | ||
| 4735 | (let* ((root (frame-root-window)) | ||
| 4736 | (main (window-with-parameter 'window-side 'none nil t)) | ||
| 4737 | (left-or-right (memq side '(left right))) | ||
| 4738 | (main-or-root | ||
| 4739 | (if (and main | ||
| 4740 | (or (and left-or-right (not window-sides-vertical)) | ||
| 4741 | (and (not left-or-right) window-sides-vertical))) | ||
| 4742 | main | ||
| 4743 | root)) | ||
| 4744 | (selected-window (selected-window)) | ||
| 4745 | (on-side (cond | ||
| 4746 | ((eq side 'top) 'above) | ||
| 4747 | ((eq side 'bottom) 'below) | ||
| 4748 | (t side))) | ||
| 4749 | (window | ||
| 4750 | (display-buffer-split-window main-or-root on-side specifiers)) | ||
| 4751 | fun) | ||
| 4752 | (when window | ||
| 4753 | (unless main | ||
| 4754 | (walk-window-subtree | ||
| 4755 | (lambda (window) | ||
| 4756 | ;; Make all main-or-root subwindows main windows. | ||
| 4757 | (set-window-parameter window 'window-side 'none)) | ||
| 4758 | main-or-root t)) | ||
| 4759 | ;; Make sure that parent's window-side is nil. | ||
| 4760 | (set-window-parameter (window-parent window) 'window-side nil) | ||
| 4761 | ;; Initialize side. | ||
| 4762 | (set-window-parameter window 'window-side side) | ||
| 4763 | ;; Adjust sizes if asked for. | ||
| 4764 | (display-buffer-set-height window specifiers) | ||
| 4765 | (display-buffer-set-width window specifiers) | ||
| 4766 | ;; Set window parameters. | ||
| 4767 | (set-window-parameter | ||
| 4768 | window 'quit-restore (list 'new-window buffer selected-window)) | ||
| 4769 | (setq display-buffer-window (cons window 'new-window)) | ||
| 4770 | (set-window-parameter window 'window-slot slot) | ||
| 4771 | (display-buffer-in-window buffer window specifiers) | ||
| 4772 | (set-window-prev-buffers window nil) | ||
| 4773 | window))) | ||
| 4774 | |||
| 4775 | (defun display-buffer-in-side-window (buffer side &optional slot specifiers) | ||
| 4776 | "Display BUFFER in a window on SIDE of the selected frame. | ||
| 4777 | SLOT, if non-nil, specifies the window slot where to display the | ||
| 4778 | BUFFER. SLOT zero or nil means use the central slot on SIDE. | ||
| 4779 | SLOT negative means use a slot preceding the central window. | ||
| 4780 | SLOT positive means use a slot following the central window. | ||
| 4781 | |||
| 4782 | SPECIFIERS must be a list of buffer display specifiers." | ||
| 4783 | (unless (memq side window-sides) | ||
| 4784 | (error "Invalid side %s specified" side)) | ||
| 4785 | (let* ((major (window-with-parameter 'window-side side nil t)) | ||
| 4786 | ;; `major' is the major window on SIDE, `windows' the life | ||
| 4787 | ;; windows on SIDE. | ||
| 4788 | (windows (when major (windows-with-parameter 'window-side side))) | ||
| 4789 | (slots (when major (window-child-count major))) | ||
| 4790 | (max-slots | ||
| 4791 | (nth (cond | ||
| 4792 | ((eq side 'left) 0) | ||
| 4793 | ((eq side 'top) 1) | ||
| 4794 | ((eq side 'right) 2) | ||
| 4795 | ((eq side 'bottom) 3)) | ||
| 4796 | window-sides-slots)) | ||
| 4797 | (selected-window (selected-window)) | ||
| 4798 | window this-window this-slot prev-window next-window | ||
| 4799 | best-window best-slot abs-slot) | ||
| 4800 | |||
| 4801 | (unless (numberp slot) | ||
| 4802 | (setq slot 0)) | ||
| 4803 | (if (not windows) | ||
| 4804 | ;; No suitable side window exists, make one. | ||
| 4805 | (display-buffer-pop-up-side-window buffer side slot specifiers) | ||
| 4806 | ;; Scan windows on SIDE. | ||
| 4807 | (catch 'found | ||
| 4808 | (dolist (window windows) | ||
| 4809 | (setq this-slot (window-parameter window 'window-slot)) | ||
| 4810 | (cond | ||
| 4811 | ((not (numberp this-slot))) | ||
| 4812 | ((and (= this-slot slot) | ||
| 4813 | ;; Dedicatedness check. | ||
| 4814 | (or (not (window-dedicated-p window)) | ||
| 4815 | (assq 'reuse-window-dedicated specifiers))) | ||
| 4816 | ;; Window with matching SLOT, use it. | ||
| 4817 | (setq this-window window) | ||
| 4818 | (throw 'found t)) | ||
| 4819 | (t | ||
| 4820 | (setq abs-slot (abs (- (abs slot) (abs this-slot)))) | ||
| 4821 | (unless (and best-slot (<= best-slot abs-slot)) | ||
| 4822 | (setq best-window window) | ||
| 4823 | (setq best-slot abs-slot)) | ||
| 4824 | (cond | ||
| 4825 | ((<= this-slot slot) | ||
| 4826 | (setq prev-window window)) | ||
| 4827 | ((not next-window) | ||
| 4828 | (setq next-window window))))))) | ||
| 4829 | |||
| 4830 | ;; `this-window' is the first window with the same SLOT. | ||
| 4831 | ;; `prev-window' is the window with the largest slot < SLOT. A new | ||
| 4832 | ;; window will be created after it. | ||
| 4833 | ;; `next-window' is the window with the smallest slot > SLOT. A new | ||
| 4834 | ;; window will be created before it. | ||
| 4835 | ;; `best-window' is the window with the smallest absolute difference | ||
| 4836 | ;; of its slot and SLOT. | ||
| 4837 | (or (and this-window | ||
| 4838 | ;; Reuse this window. | ||
| 4839 | (prog1 | ||
| 4840 | (setq window this-window) | ||
| 4841 | (if (eq (window-buffer window) buffer) | ||
| 4842 | (setq display-buffer-window | ||
| 4843 | (cons window 'reuse-buffer-window)) | ||
| 4844 | (setq display-buffer-window | ||
| 4845 | (cons window 'reuse-other-window)) | ||
| 4846 | (unless (window-parameter window 'quit-restore) | ||
| 4847 | ;; Don't overwrite an existing quit-restore entry. | ||
| 4848 | (set-window-parameter | ||
| 4849 | window 'quit-restore | ||
| 4850 | (list (window-buffer window) (window-start window) | ||
| 4851 | (window-point window) buffer | ||
| 4852 | (window-total-size window) (selected-window))))))) | ||
| 4853 | (and (or (not max-slots) (< slots max-slots)) | ||
| 4854 | (or (and next-window | ||
| 4855 | ;; Make new window before next-window. | ||
| 4856 | (let ((next-side | ||
| 4857 | (if (memq side '(left right)) 'above 'left))) | ||
| 4858 | (setq window (display-buffer-split-window | ||
| 4859 | next-window next-side specifiers)))) | ||
| 4860 | (and prev-window | ||
| 4861 | ;; Make new window after prev-window. | ||
| 4862 | (let ((prev-side | ||
| 4863 | (if (memq side '(left right)) 'below 'right))) | ||
| 4864 | (setq window (display-buffer-split-window | ||
| 4865 | prev-window prev-side specifiers))))) | ||
| 4866 | (progn | ||
| 4867 | (display-buffer-set-height window specifiers) | ||
| 4868 | (display-buffer-set-width window specifiers) | ||
| 4869 | (set-window-parameter | ||
| 4870 | window 'quit-restore | ||
| 4871 | (list 'new-window buffer selected-window)) | ||
| 4872 | (setq display-buffer-window (cons window 'new-window)) | ||
| 4873 | window)) | ||
| 4874 | (and best-window | ||
| 4875 | (setq window best-window) | ||
| 4876 | ;; Reuse best window (the window nearest to SLOT). | ||
| 4877 | (if (eq (window-buffer window) buffer) | ||
| 4878 | (setq display-buffer-window | ||
| 4879 | (cons window 'reuse-buffer-window)) | ||
| 4880 | (setq display-buffer-window | ||
| 4881 | (cons window 'reuse-other-window)) | ||
| 4882 | |||
| 4883 | (unless (window-parameter window 'quit-restore) | ||
| 4884 | ;; Don't overwrite an existing quit-restore entry. | ||
| 4885 | (set-window-parameter | ||
| 4886 | window 'quit-restore | ||
| 4887 | (list (window-buffer window) (window-start window) | ||
| 4888 | (window-point window) buffer | ||
| 4889 | (window-total-size window) (selected-window))))) | ||
| 4890 | window)) | ||
| 4891 | |||
| 4892 | (when window | ||
| 4893 | (unless (window-parameter window 'window-slot) | ||
| 4894 | ;; Don't change exisiting slot value. | ||
| 4895 | (set-window-parameter window 'window-slot slot)) | ||
| 4896 | (display-buffer-in-window buffer window specifiers))))) | ||
| 4897 | |||
| 4898 | (defun normalize-buffer-to-display (buffer-or-name) | ||
| 4899 | "Normalize BUFFER-OR-NAME argument for buffer display functions. | ||
| 4900 | If BUFFER-OR-NAME is nil, return the curent buffer. Else, if a | ||
| 4901 | buffer specified by BUFFER-OR-NAME exists, return that buffer. | ||
| 4902 | If no such buffer exists, create a buffer with the name | ||
| 4903 | BUFFER-OR-NAME and return that buffer." | ||
| 4904 | (if buffer-or-name | ||
| 4905 | (or (get-buffer buffer-or-name) | ||
| 4906 | (let ((buffer (get-buffer-create buffer-or-name))) | ||
| 4907 | (set-buffer-major-mode buffer) | ||
| 4908 | buffer)) | ||
| 4909 | (current-buffer))) | ||
| 4910 | |||
| 4911 | (defun display-buffer-normalize-specifiers-1 (specifiers) | ||
| 4912 | "Subroutine of `display-buffer-normalize-specifiers'. | ||
| 4913 | SPECIFIERS is the SPECIFIERS argument of `display-buffer'." | ||
| 4914 | (let (normalized) | ||
| 4915 | (cond | ||
| 4916 | ((listp specifiers) | ||
| 4917 | (dolist (specifier specifiers) | ||
| 4918 | (cond | ||
| 4919 | ((consp specifier) | ||
| 4920 | (setq normalized (cons specifier normalized))) | ||
| 4921 | ((symbolp specifier) | ||
| 4922 | ;; Might be a macro specifier, try to expand it (the cdr is a | ||
| 4923 | ;; list and we have to reverse it later, so do it one at a | ||
| 4924 | ;; time). | ||
| 4925 | (let ((entry (assq specifier display-buffer-macro-specifiers))) | ||
| 4926 | (dolist (item (cdr entry)) | ||
| 4927 | (setq normalized (cons item normalized))))))) | ||
| 4928 | ;; Reverse list. | ||
| 4929 | (setq normalized (nreverse normalized))) | ||
| 4930 | ;; The two cases below must come from the SPECIFIERS argument of | ||
| 4931 | ;; `display-buffer'. | ||
| 4932 | ((eq specifiers 't) | ||
| 4933 | ;; Historically t means "other window". Eventually we should get | ||
| 4934 | ;; rid of this. | ||
| 4935 | (setq normalized | ||
| 4936 | (cdr (assq 'other-window display-buffer-macro-specifiers)) | ||
| 4937 | normalized)) | ||
| 4938 | ((symbolp specifiers) | ||
| 4939 | ;; We allow scalar specifiers in calls of `display-buffer'. | ||
| 4940 | (let ((entry (assq specifiers display-buffer-macro-specifiers))) | ||
| 4941 | (when entry (setq normalized (cdr entry)))))) | ||
| 4942 | |||
| 4943 | normalized)) | ||
| 4944 | |||
| 4945 | (defun display-buffer-normalize-specifiers-2 (&optional buffer-or-name) | ||
| 4946 | "Subroutine of `display-buffer-normalize-specifiers'. | ||
| 4947 | BUFFER-OR-NAME is the buffer to display. This routine provides a | ||
| 4948 | compatibility layer for the now obsolete Emacs 23 buffer display | ||
| 4949 | options." | ||
| 4950 | (let* ((buffer (normalize-live-buffer buffer-or-name)) | ||
| 4951 | (buffer-name (buffer-name buffer)) | ||
| 4952 | specifiers) | ||
| 4953 | ;; Disable warnings, there are too many obsolete options here. | ||
| 4954 | (with-no-warnings | ||
| 4955 | ;; `display-buffer-mark-dedicated' | ||
| 4956 | (unless (memq display-buffer-mark-dedicated '(nil unset)) | ||
| 4957 | (setq specifiers | ||
| 4958 | (cons (cons 'dedicate display-buffer-mark-dedicated) | ||
| 4959 | specifiers))) | ||
| 4960 | |||
| 4961 | ;; `pop-up-window' group. Anything is added here iff | ||
| 4962 | ;; `pop-up-windows' is neither nil nor unset. | ||
| 4963 | (let ((pop-up-window (not (memq pop-up-windows '(nil unset)))) | ||
| 4964 | (fun (unless (eq split-window-preferred-function | ||
| 4965 | 'split-window-sensibly) | ||
| 4966 | split-window-preferred-function)) | ||
| 4967 | (min-height (if (numberp split-height-threshold) | ||
| 4968 | (/ split-height-threshold 2) | ||
| 4969 | 1.0)) | ||
| 4970 | (min-width (if (numberp split-width-threshold) | ||
| 4971 | (/ split-width-threshold 2) | ||
| 4972 | 1.0))) | ||
| 4973 | (when pop-up-window | ||
| 4974 | ;; `split-height-threshold' | ||
| 4975 | (setq specifiers | ||
| 4976 | (cons (cons 'pop-up-window-min-height min-height) | ||
| 4977 | specifiers)) | ||
| 4978 | ;; `split-width-threshold' | ||
| 4979 | (setq specifiers | ||
| 4980 | (cons (cons 'pop-up-window-min-width min-width) | ||
| 4981 | specifiers)) | ||
| 4982 | ;; `pop-up-window' | ||
| 4983 | (setq specifiers | ||
| 4984 | (cons (list 'pop-up-window | ||
| 4985 | (cons 'largest fun) (cons 'lru fun)) | ||
| 4986 | specifiers)))) | ||
| 4987 | |||
| 4988 | ;; `pop-up-frame' group. Anything is added here iff | ||
| 4989 | ;; `pop-up-frames' is neither nil nor unset (we ignore the problem | ||
| 4990 | ;; that callers usually don't care about graphic-only). | ||
| 4991 | (unless (memq pop-up-frames '(nil unset)) | ||
| 4992 | ;; `pop-up-frame-function'. If `pop-up-frame-function' uses the | ||
| 4993 | ;; now obsolete `pop-up-frame-alist' it will continue to do so. | ||
| 4994 | (setq specifiers | ||
| 4995 | (cons (cons 'pop-up-frame-function pop-up-frame-function) | ||
| 4996 | specifiers)) | ||
| 4997 | ;; `pop-up-frame' | ||
| 4998 | (setq specifiers | ||
| 4999 | (cons (list 'pop-up-frame pop-up-frames) specifiers))) | ||
| 5000 | |||
| 5001 | ;; `special-display-regexps' | ||
| 5002 | (dolist (entry special-display-regexps) | ||
| 5003 | (cond | ||
| 5004 | ((stringp entry) | ||
| 5005 | ;; Plain string. | ||
| 5006 | (when (string-match-p entry buffer-name) | ||
| 5007 | (setq specifiers | ||
| 5008 | (cons | ||
| 5009 | (list 'fun-with-args special-display-function | ||
| 5010 | special-display-frame-alist) | ||
| 5011 | specifiers)))) | ||
| 5012 | ((consp entry) | ||
| 5013 | (let ((name (car entry)) | ||
| 5014 | (rest (cdr entry))) | ||
| 5015 | (cond | ||
| 5016 | ((not (string-match-p name buffer-name))) | ||
| 5017 | ((functionp (car rest)) | ||
| 5018 | ;; A function. | ||
| 5019 | (setq specifiers | ||
| 5020 | (cons (list 'fun-with-args (car rest) (cadr rest)) | ||
| 5021 | specifiers))) | ||
| 5022 | ((listp rest) | ||
| 5023 | ;; A list of parameters. | ||
| 5024 | (cond | ||
| 5025 | ((assq 'same-window rest) | ||
| 5026 | (setq specifiers | ||
| 5027 | (cons (list 'reuse-window 'same) specifiers)) | ||
| 5028 | (setq specifiers | ||
| 5029 | (cons (list 'reuse-window-dedicated 'weak) | ||
| 5030 | specifiers))) | ||
| 5031 | ((assq 'same-frame rest) | ||
| 5032 | (setq specifiers | ||
| 5033 | (setq specifiers | ||
| 5034 | (cons (list 'same-frame) specifiers)))) | ||
| 5035 | (t | ||
| 5036 | (setq specifiers | ||
| 5037 | (cons (list 'fun-with-args special-display-function | ||
| 5038 | special-display-frame-alist) | ||
| 5039 | specifiers)))))))))) | ||
| 5040 | |||
| 5041 | ;; `special-display-buffer-names' | ||
| 5042 | (dolist (entry special-display-buffer-names) | ||
| 5043 | (cond | ||
| 5044 | ((stringp entry) | ||
| 5045 | ;; Plain string. | ||
| 5046 | (when (string-equal entry buffer-name) | ||
| 5047 | (setq specifiers | ||
| 5048 | (cons | ||
| 5049 | (list 'fun-with-args special-display-function | ||
| 5050 | special-display-frame-alist) | ||
| 5051 | specifiers)))) | ||
| 5052 | ((consp entry) | ||
| 5053 | (let ((name (car entry)) | ||
| 5054 | (rest (cdr entry))) | ||
| 5055 | (cond | ||
| 5056 | ((not (string-equal name buffer-name))) | ||
| 5057 | ((functionp (car rest)) | ||
| 5058 | ;; A function. | ||
| 5059 | (setq specifiers | ||
| 5060 | (cons (list 'fun-with-args (car rest) (cadr rest)) | ||
| 5061 | specifiers))) | ||
| 5062 | ((listp rest) | ||
| 5063 | ;; A list of parameters. | ||
| 5064 | (cond | ||
| 5065 | ((assq 'same-window rest) | ||
| 5066 | (setq specifiers | ||
| 5067 | (cons (list 'reuse-window 'same) specifiers)) | ||
| 5068 | (setq specifiers | ||
| 5069 | (cons (list 'reuse-window-dedicated 'weak) | ||
| 5070 | specifiers))) | ||
| 5071 | ((assq 'same-frame rest) | ||
| 5072 | (setq specifiers | ||
| 5073 | (setq specifiers | ||
| 5074 | (cons (list 'same-frame) specifiers)))) | ||
| 5075 | (t | ||
| 5076 | (setq specifiers | ||
| 5077 | (cons (list 'fun-with-args special-display-function | ||
| 5078 | special-display-frame-alist) | ||
| 5079 | specifiers)))))))))) | ||
| 5080 | |||
| 5081 | ;; `same-window-regexps' | ||
| 5082 | (dolist (entry same-window-regexps) | ||
| 5083 | (cond | ||
| 5084 | ((stringp entry) | ||
| 5085 | (when (string-match-p entry buffer-name) | ||
| 5086 | (setq specifiers | ||
| 5087 | (cons (list 'reuse-window 'same) specifiers)))) | ||
| 5088 | ((consp entry) | ||
| 5089 | (when (string-match-p (car entry) buffer-name) | ||
| 5090 | (setq specifiers | ||
| 5091 | (cons (list 'reuse-window 'same) specifiers)))))) | ||
| 5092 | |||
| 5093 | ;; `same-window-buffer-names' | ||
| 5094 | (dolist (entry same-window-buffer-names) | ||
| 5095 | (cond | ||
| 5096 | ((stringp entry) | ||
| 5097 | (when (string-equal entry buffer-name) | ||
| 5098 | (setq specifiers | ||
| 5099 | (cons (list 'reuse-window 'same) specifiers)))) | ||
| 5100 | ((consp entry) | ||
| 5101 | (when (string-equal (car entry) buffer-name) | ||
| 5102 | (setq specifiers | ||
| 5103 | (cons (list 'reuse-window 'same) specifiers)))))) | ||
| 5104 | |||
| 5105 | ;; `pop-up-windows' and `pop-up-frames' nil means means we | ||
| 5106 | ;; are supposed to reuse any window (unless we find one showing | ||
| 5107 | ;; the same buffer already). | ||
| 5108 | |||
| 5109 | ;; This clause is needed because Emacs 23 options can be used to | ||
| 5110 | ;; suppress a certain behavior while `display-buffer-alist' can be | ||
| 5111 | ;; only used to enforce some behavior. | ||
| 5112 | (when (and (not pop-up-windows) (memq pop-up-frames '(nil unset))) | ||
| 5113 | ;; `even-window-heights' | ||
| 5114 | (when even-window-heights | ||
| 5115 | (setq specifiers | ||
| 5116 | (cons (cons 'reuse-window-even-sizes t) specifiers))) | ||
| 5117 | ;; `reuse-window' showing any buffer on same frame. | ||
| 5118 | (setq specifiers | ||
| 5119 | (cons (list 'reuse-window nil nil nil) | ||
| 5120 | specifiers))) | ||
| 5121 | |||
| 5122 | ;; `display-buffer-reuse-frames' or `pop-up-frames' set means we | ||
| 5123 | ;; are supposed to reuse a window showing the same buffer. | ||
| 5124 | (unless (and (memq display-buffer-reuse-frames '(nil unset)) | ||
| 5125 | (memq pop-up-frames '(nil unset))) | ||
| 5126 | ;; `even-window-heights' | ||
| 5127 | (when even-window-heights | ||
| 5128 | (setq specifiers | ||
| 5129 | (cons (cons 'reuse-window-even-sizes t) specifiers))) | ||
| 5130 | ;; `reuse-window' showing same buffer on visible frame. | ||
| 5131 | (setq specifiers | ||
| 5132 | (cons (list 'reuse-window nil 'same 0) | ||
| 5133 | specifiers))) | ||
| 5134 | |||
| 5135 | specifiers))) | ||
| 5136 | |||
| 5137 | (defun display-buffer-normalize-specifiers (buffer-name specifiers label) | ||
| 5138 | "Return normalized specifiers for a buffer matching BUFFER-NAME or LABEL. | ||
| 5139 | BUFFER-NAME must be a string specifying a valid buffer name. | ||
| 5140 | SPECIFIERS and LABEL are the homonymous arguments of | ||
| 5141 | `display-buffer'. | ||
| 5142 | |||
| 5143 | The method for displaying the buffer specified by BUFFER-NAME or | ||
| 5144 | LABEL is established by appending the following four lists of | ||
| 5145 | specifiers: | ||
| 5146 | |||
| 5147 | - The specifiers in `display-buffer-alist' whose buffer | ||
| 5148 | identifier matches BUFFER-NAME or LABEL and whose 'override | ||
| 5149 | component is set. | ||
| 5150 | |||
| 5151 | - SPECIFIERS. | ||
| 5152 | |||
| 5153 | - The specifiers in `display-buffer-alist' whose buffer | ||
| 5154 | identifier matches BUFFER-NAME or LABEL and whose 'override | ||
| 5155 | component is not set. | ||
| 5156 | |||
| 5157 | - `display-buffer-default-specifiers'." | ||
| 5158 | (let (list-1 list-2) | ||
| 5159 | (dolist (entry display-buffer-alist) | ||
| 5160 | (when (and (listp entry) | ||
| 5161 | (catch 'match | ||
| 5162 | (dolist (id (car entry)) | ||
| 5163 | (when (consp id) | ||
| 5164 | (let ((type (car id)) | ||
| 5165 | (value (cdr id))) | ||
| 5166 | (when (or (and (eq type 'name) (stringp value) | ||
| 5167 | (equal value buffer-name)) | ||
| 5168 | (and (eq type 'regexp) (stringp value) | ||
| 5169 | (string-match-p value buffer-name)) | ||
| 5170 | (and (eq type 'label) (eq value label))) | ||
| 5171 | (throw 'match t))))))) | ||
| 5172 | (let* ((raw (cdr entry)) | ||
| 5173 | (normalized (display-buffer-normalize-specifiers-1 raw))) | ||
| 5174 | (if (assq 'override raw) | ||
| 5175 | (setq list-1 | ||
| 5176 | (if list-1 | ||
| 5177 | (append list-1 normalized) | ||
| 5178 | normalized)) | ||
| 5179 | (setq list-2 | ||
| 5180 | (if list-2 | ||
| 5181 | (append list-2 normalized) | ||
| 5182 | normalized)))))) | ||
| 5183 | |||
| 5184 | (append | ||
| 5185 | ;; Overriding user specifiers. | ||
| 5186 | list-1 | ||
| 5187 | ;; Application specifiers. | ||
| 5188 | (display-buffer-normalize-specifiers-1 specifiers) | ||
| 5189 | ;; Emacs 23 compatibility specifiers. | ||
| 5190 | (display-buffer-normalize-specifiers-2 buffer-name) | ||
| 5191 | ;; Non-overriding user specifiers. | ||
| 5192 | list-2 | ||
| 5193 | ;; Default specifiers. | ||
| 5194 | display-buffer-default-specifiers))) | ||
| 5195 | |||
| 5196 | ;; Minibuffer-only frames should be documented better. They really | ||
| 5197 | ;; deserve a separate section in the manual. Also | ||
| 5198 | ;; `last-nonminibuffer-frame' is nowhere documented in the manual. | ||
| 5199 | (defun display-buffer-frame (&optional frame) | ||
| 5200 | "Return FRAME if it is live and not a minibuffer-only frame. | ||
| 5201 | Return the value of `last-nonminibuffer-frame' otherwise." | ||
| 5202 | (setq frame (normalize-live-frame frame)) | ||
| 5203 | (if (and (frame-live-p frame) | ||
| 5204 | ;; A not very nice way to get that information. | ||
| 5205 | (not (window-minibuffer-p (frame-root-window frame)))) | ||
| 5206 | frame | ||
| 5207 | (last-nonminibuffer-frame))) | ||
| 5208 | |||
| 5209 | (defun display-buffer (&optional buffer-or-name specifiers label) | ||
| 5210 | "Make the buffer specified by BUFFER-OR-NAME appear in some window. | ||
| 5211 | Optional argument BUFFER-OR-NAME may be a buffer, a string \(a | ||
| 5212 | buffer name), or nil. If BUFFER-OR-NAME is a string not naming | ||
| 5213 | an existent buffer, create a buffer with that name. If | ||
| 5214 | BUFFER-OR-NAME is nil or omitted, display the current buffer. | ||
| 5215 | Interactively, prompt for the buffer name using the minibuffer. | ||
| 5216 | |||
| 5217 | Return the window chosen to display the buffer or nil if no such | ||
| 5218 | window is found. Do not change the selected window unless the | ||
| 5219 | buffer is shown on a different frame than the selected one. | ||
| 5220 | |||
| 5221 | Optional argument SPECIFIERS must be a list of buffer display | ||
| 5222 | specifiers, see the documentation of `display-buffer-alist' for a | ||
| 5223 | description. | ||
| 5224 | |||
| 5225 | For convenience, SPECIFIERS may also consist of a single buffer | ||
| 5226 | display location specifier or t, where the latter means to | ||
| 5227 | display the buffer in any but the selected window. If SPECIFIERS | ||
| 5228 | is nil or omitted, this means to exclusively use the specifiers | ||
| 5229 | provided by `display-buffer-alist'. If the value of the latter | ||
| 5230 | is nil too, all specifiers are provided by the constant | ||
| 5231 | `display-buffer-default-specifiers'. | ||
| 5232 | |||
| 5233 | As a special case, the `reuse-window' specifier allows to specify | ||
| 5234 | as second element an arbitrary window, as third element an | ||
| 5235 | arbitrary buffer, and as fourth element an arbitrary frame. As | ||
| 5236 | first element of a window/side pair of the `pop-up-window' | ||
| 5237 | specifier you can specifiy an arbitrary window. | ||
| 5238 | |||
| 5239 | The optional third argument LABEL, if non-nil, must be a symbol | ||
| 5240 | specifiying the buffer display label. Applications should set | ||
| 5241 | this when the buffer shall be displayed in some special way but | ||
| 5242 | BUFFER-OR-NAME does not identify the buffer as special. Typical | ||
| 5243 | buffers that fit into this category are those whose names are | ||
| 5244 | derived from the name of the file they are visiting. A user can | ||
| 5245 | override SPECIFIERS by adding an entry to `display-buffer-alist' | ||
| 5246 | whose car contains LABEL and whose cdr specifies the preferred | ||
| 5247 | alternative display method. | ||
| 5248 | |||
| 5249 | The method to display the buffer is derived by combining the | ||
| 5250 | values of `display-buffer-alist' and SPECIFIERS. Highest | ||
| 5251 | priority is given to overriding elements of | ||
| 5252 | `display-buffer-alist'. Next come the elements specified by | ||
| 5253 | SPECIFIERS, followed by the non-overriding elements of | ||
| 5254 | `display-buffer-alist'. | ||
| 5255 | |||
| 5256 | The result must be a list of valid buffer display specifiers. If | ||
| 5257 | `display-buffer-function' is non-nil, call it with the buffer and | ||
| 5258 | this list as arguments." | ||
| 5259 | (interactive "BDisplay buffer:\nP") | ||
| 5260 | (let* ((buffer (normalize-buffer-to-display buffer-or-name)) | ||
| 5261 | (buffer-name (buffer-name buffer)) | ||
| 5262 | (specifiers | ||
| 5263 | ;; Normalize specifiers. | ||
| 5264 | (display-buffer-normalize-specifiers buffer-name specifiers label)) | ||
| 5265 | ;; Don't use a minibuffer frame. | ||
| 5266 | (frame (display-buffer-frame)) | ||
| 5267 | ;; `window' is the window we use for showing `buffer'. | ||
| 5268 | window specifier method) | ||
| 5269 | ;; Reset this. | ||
| 5270 | (setq display-buffer-window nil) | ||
| 5271 | (if display-buffer-function | ||
| 5272 | ;; Let `display-buffer-function' do the job. | ||
| 5273 | (funcall display-buffer-function buffer specifiers) | ||
| 5274 | ;; Retrieve the next location specifier while there a specifiers | ||
| 5275 | ;; left and we don't have a valid window. | ||
| 5276 | (while (and specifiers (not (window-live-p window))) | ||
| 5277 | (setq specifier (car specifiers)) | ||
| 5278 | (setq specifiers (cdr specifiers)) | ||
| 5279 | (setq method (car specifier)) | ||
| 5280 | (setq window | ||
| 5281 | (cond | ||
| 5282 | ((eq method 'reuse-window) | ||
| 5283 | (display-buffer-reuse-window | ||
| 5284 | buffer (cdr specifier) specifiers)) | ||
| 5285 | ((eq method 'pop-up-window) | ||
| 5286 | (display-buffer-pop-up-window | ||
| 5287 | buffer (cdr specifier) specifiers)) | ||
| 5288 | ((eq method 'pop-up-frame) | ||
| 5289 | (display-buffer-pop-up-frame | ||
| 5290 | buffer (cdr specifier) specifiers)) | ||
| 5291 | ((eq method 'use-side-window) | ||
| 5292 | (display-buffer-in-side-window | ||
| 5293 | buffer (nth 1 specifier) (nth 2 specifier) specifiers)) | ||
| 5294 | ((eq method 'fun-with-args) | ||
| 5295 | (apply (cadr specifier) buffer (cddr specifier)))))) | ||
| 5296 | |||
| 5297 | ;; If we don't have a window yet, try a fallback method. All | ||
| 5298 | ;; specifiers have been used up by now. | ||
| 5299 | (or (and (window-live-p window) window) | ||
| 5300 | ;; Try reusing a window showing BUFFER on any visible or | ||
| 5301 | ;; iconfied frame. | ||
| 5302 | (display-buffer-reuse-window buffer '(nil buffer 0)) | ||
| 5303 | ;; Try reusing a window not showing BUFFER on any visible or | ||
| 5304 | ;; iconified frame. | ||
| 5305 | (display-buffer-reuse-window buffer '(nil other 0)) | ||
| 5306 | ;; Try making a new frame. | ||
| 5307 | (display-buffer-pop-up-frame buffer) | ||
| 5308 | ;; Try using weakly dedicated windows. | ||
| 5309 | (display-buffer-reuse-window | ||
| 5310 | buffer '(nil nil t) '((reuse-window-dedicated . weak))) | ||
| 5311 | ;; Try using strongly dedicated windows. | ||
| 5312 | (display-buffer-reuse-window | ||
| 5313 | buffer '(nil nil t) '((reuse-window-dedicated . t))))))) | ||
| 5314 | |||
| 5315 | (defsubst display-buffer-same-window (&optional buffer-or-name label) | ||
| 5316 | "Display buffer specified by BUFFER-OR-NAME in the selected window. | ||
| 5317 | Another window will be used only if the buffer can't be shown in | ||
| 5318 | the selected window, usually because it is dedicated to another | ||
| 5319 | buffer. Optional argument BUFFER-OR-NAME and LABEL are as for | ||
| 5320 | `display-buffer'." | ||
| 5321 | (interactive "BDisplay buffer in same window:\nP") | ||
| 5322 | (display-buffer buffer-or-name 'same-window label)) | ||
| 5323 | |||
| 5324 | (defsubst display-buffer-same-frame (&optional buffer-or-name label) | ||
| 5325 | "Display buffer specified by BUFFER-OR-NAME in a window on the same frame. | ||
| 5326 | Another frame will be used only if there is no other choice. | ||
| 5327 | Optional argument BUFFER-OR-NAME and LABEL are as for | ||
| 5328 | `display-buffer'." | ||
| 5329 | (interactive "BDisplay buffer on same frame:\nP") | ||
| 5330 | (display-buffer buffer-or-name 'same-frame label)) | ||
| 5331 | |||
| 5332 | (defsubst display-buffer-other-window (&optional buffer-or-name label) | ||
| 5333 | "Display buffer specified by BUFFER-OR-NAME in another window. | ||
| 5334 | The selected window will be used only if there is no other | ||
| 5335 | choice. Windows on the selected frame are preferred to windows | ||
| 5336 | on other frames. Optional argument BUFFER-OR-NAME and LABEL are as | ||
| 5337 | for `display-buffer'." | ||
| 5338 | (interactive "BDisplay buffer in another window:\nP") | ||
| 5339 | (display-buffer buffer-or-name 'other-window label)) | ||
| 5340 | |||
| 5341 | (defun display-buffer-same-frame-other-window (&optional buffer-or-name label) | ||
| 5342 | "Display buffer specified by BUFFER-OR-NAME in another window on the same frame. | ||
| 5343 | The selected window or another frame will be used only if there | ||
| 5344 | is no other choice. Optional argument BUFFER-OR-NAME and LABEL are | ||
| 5345 | as for `display-buffer'." | ||
| 5346 | (interactive "BDisplay buffer in another window on same frame:\nP") | ||
| 5347 | (display-buffer buffer-or-name 'same-frame-other-window label)) | ||
| 5348 | |||
| 5349 | (defun display-buffer-other-frame (&optional buffer-or-name label) | ||
| 5350 | "Display buffer specified by BUFFER-OR-NAME on another frame. | ||
| 5351 | The selected frame will be used only if there is no other choice. | ||
| 5352 | Optional argument BUFFER-OR-NAME and LABEL are as for | ||
| 5353 | `display-buffer'. | ||
| 5354 | |||
| 5355 | If this command uses another frame, it will also select that frame." | ||
| 5356 | (interactive "BDisplay buffer in other frame: ") | ||
| 5357 | (display-buffer buffer-or-name 'other-frame label)) | ||
| 5358 | |||
| 5359 | (defun pop-to-buffer (&optional buffer-or-name specifiers norecord label) | ||
| 5360 | "Display buffer specified by BUFFER-OR-NAME and select the window used. | ||
| 5361 | Optional argument BUFFER-OR-NAME may be a buffer, a string \(a | ||
| 5362 | buffer name), or nil. If BUFFER-OR-NAME is a string not naming | ||
| 5363 | an existent buffer, create a buffer with that name. If | ||
| 5364 | BUFFER-OR-NAME is nil or omitted, display the current buffer. | ||
| 5365 | Interactively, prompt for the buffer name using the minibuffer. | ||
| 5366 | |||
| 5367 | Optional second argument SPECIFIERS must be a list of buffer | ||
| 5368 | display specifiers, a single location specifier, `t' which means | ||
| 5369 | the latter means to display the buffer in any but the selected | ||
| 5370 | window, or nil which means to exclusively apply the specifiers | ||
| 5371 | customized by the user. | ||
| 5372 | |||
| 5373 | Optional argument NORECORD non-nil means do not put the buffer | ||
| 5374 | specified by BUFFER-OR-NAME at the front of the buffer list and | ||
| 5375 | do not make the window displaying it the most recently selected | ||
| 5376 | one. | ||
| 5377 | |||
| 5378 | The optional argument LABEL, if non-nil, is a symbol specifying the | ||
| 5379 | display purpose. Applications should set this when the buffer | ||
| 5380 | shall be displayed in a special way but BUFFER-OR-NAME does not | ||
| 5381 | identify the buffer as special. Buffers that typically fit into | ||
| 5382 | this category are those whose names have been derived from the | ||
| 5383 | name of the file they are visiting. | ||
| 5384 | |||
| 5385 | Return the buffer specified by BUFFER-OR-NAME or nil if | ||
| 5386 | displaying the buffer failed. | ||
| 5387 | |||
| 5388 | This uses the function `display-buffer' as a subroutine; see the | ||
| 5389 | documentations of `display-buffer' and `display-buffer-alist' for | ||
| 5390 | additional information." | ||
| 5391 | (interactive "BPop to buffer:\nP") | ||
| 5392 | (let ((buffer (normalize-buffer-to-display buffer-or-name)) | ||
| 5393 | window) | ||
| 5394 | (set-buffer buffer) | ||
| 5395 | (when (setq window (display-buffer buffer specifiers label)) | ||
| 5396 | (select-window window norecord) | ||
| 5397 | buffer))) | ||
| 5398 | |||
| 5399 | (defsubst pop-to-buffer-same-window (&optional buffer-or-name norecord label) | ||
| 5400 | "Pop to buffer specified by BUFFER-OR-NAME in the selected window. | ||
| 5401 | Another window will be used only if the buffer can't be shown in | ||
| 5402 | the selected window, usually because it is dedicated to another | ||
| 5403 | buffer. Optional arguments BUFFER-OR-NAME, NORECORD and LABEL are | ||
| 5404 | as for `pop-to-buffer'." | ||
| 5405 | (interactive "BPop to buffer in selected window:\nP") | ||
| 5406 | (pop-to-buffer buffer-or-name 'same-window norecord label)) | ||
| 5407 | |||
| 5408 | (defsubst pop-to-buffer-same-frame (&optional buffer-or-name norecord label) | ||
| 5409 | "Pop to buffer specified by BUFFER-OR-NAME in a window on the selected frame. | ||
| 5410 | Another frame will be used only if there is no other choice. | ||
| 5411 | Optional arguments BUFFER-OR-NAME, NORECORD and LABEL are as for | ||
| 5412 | `pop-to-buffer'." | ||
| 5413 | (interactive "BPop to buffer on same frame:\nP") | ||
| 5414 | (pop-to-buffer buffer-or-name 'same-frame norecord label)) | ||
| 5415 | |||
| 5416 | (defsubst pop-to-buffer-other-window (&optional buffer-or-name norecord label) | ||
| 5417 | "Pop to buffer specified by BUFFER-OR-NAME in another window. | ||
| 5418 | The selected window will be used only if there is no other | ||
| 5419 | choice. Windows on the selected frame are preferred to windows | ||
| 5420 | on other frames. Optional arguments BUFFER-OR-NAME, NORECORD and | ||
| 5421 | LABEL are as for `pop-to-buffer'." | ||
| 5422 | (interactive "BPop to buffer in another window:\nP") | ||
| 5423 | (pop-to-buffer buffer-or-name 'other-window norecord)) | ||
| 5424 | |||
| 5425 | (defsubst pop-to-buffer-same-frame-other-window (&optional buffer-or-name norecord label) | ||
| 5426 | "Pop to buffer specified by BUFFER-OR-NAME in another window on the selected frame. | ||
| 5427 | The selected window or another frame will be used only if there | ||
| 5428 | is no other choice. Optional arguments BUFFER-OR-NAME, NORECORD | ||
| 5429 | and LABEL are as for `pop-to-buffer'." | ||
| 5430 | (interactive "BPop to buffer in another window on same frame:\nP") | ||
| 5431 | (pop-to-buffer buffer-or-name 'same-frame-other-window norecord label)) | ||
| 5432 | |||
| 5433 | (defsubst pop-to-buffer-other-frame (&optional buffer-or-name norecord label) | ||
| 5434 | "Pop to buffer specified by BUFFER-OR-NAME on another frame. | ||
| 5435 | The selected frame will be used only if there's no other choice. | ||
| 5436 | Optional arguments BUFFER-OR-NAME, NORECORD and LABEL are as for | ||
| 5437 | `pop-to-buffer'." | ||
| 5438 | (interactive "BPop to buffer on another frame:\nP") | ||
| 5439 | (pop-to-buffer buffer-or-name 'other-frame norecord label)) | ||
| 5440 | |||
| 5441 | (defun read-buffer-to-switch (prompt) | ||
| 5442 | "Read the name of a buffer to switch to, prompting with PROMPT. | ||
| 5443 | Return the neame of the buffer as a string. | ||
| 5444 | |||
| 5445 | This function is intended for the `switch-to-buffer' family of | ||
| 5446 | commands since these need to omit the name of the current buffer | ||
| 5447 | from the list of completions and default values." | ||
| 5448 | (let ((rbts-completion-table (internal-complete-buffer-except))) | ||
| 5449 | (minibuffer-with-setup-hook | ||
| 5450 | (lambda () | ||
| 5451 | (setq minibuffer-completion-table rbts-completion-table) | ||
| 5452 | ;; Since rbts-completion-table is built dynamically, we | ||
| 5453 | ;; can't just add it to the default value of | ||
| 5454 | ;; icomplete-with-completion-tables, so we add it | ||
| 5455 | ;; here manually. | ||
| 5456 | (if (and (boundp 'icomplete-with-completion-tables) | ||
| 5457 | (listp icomplete-with-completion-tables)) | ||
| 5458 | (set (make-local-variable 'icomplete-with-completion-tables) | ||
| 5459 | (cons rbts-completion-table | ||
| 5460 | icomplete-with-completion-tables)))) | ||
| 5461 | (read-buffer prompt (other-buffer (current-buffer)) | ||
| 5462 | (confirm-nonexistent-file-or-buffer))))) | ||
| 5463 | |||
| 5464 | (defun normalize-buffer-to-switch-to (buffer-or-name) | ||
| 5465 | "Normalize BUFFER-OR-NAME argument of buffer switching functions. | ||
| 5466 | If BUFFER-OR-NAME is nil, return the buffer returned by | ||
| 5467 | `other-buffer'. Else, if a buffer specified by BUFFER-OR-NAME | ||
| 5468 | exists, return that buffer. If no such buffer exists, create a | ||
| 5469 | buffer with the name BUFFER-OR-NAME and return that buffer." | ||
| 5470 | (if buffer-or-name | ||
| 5471 | (or (get-buffer buffer-or-name) | ||
| 5472 | (let ((buffer (get-buffer-create buffer-or-name))) | ||
| 5473 | (set-buffer-major-mode buffer) | ||
| 5474 | buffer)) | ||
| 5475 | (other-buffer))) | ||
| 5476 | |||
| 5477 | (defun switch-to-buffer (buffer-or-name &optional norecord) | ||
| 5478 | "Switch to buffer BUFFER-OR-NAME in the selected window. | ||
| 5479 | If called interactively, prompt for the buffer name using the | ||
| 5480 | minibuffer. The variable `confirm-nonexistent-file-or-buffer' | ||
| 5481 | determines whether to request confirmation before creating a new | ||
| 5482 | buffer. | ||
| 5483 | |||
| 5484 | BUFFER-OR-NAME may be a buffer, a string \(a buffer name), or | ||
| 5485 | nil. If BUFFER-OR-NAME is a string that does not identify an | ||
| 5486 | existing buffer, create a buffer with that name. If | ||
| 5487 | BUFFER-OR-NAME is nil, switch to the buffer returned by | ||
| 5488 | `other-buffer'. | ||
| 5489 | |||
| 5490 | Optional argument NORECORD non-nil means do not put the buffer | ||
| 5491 | specified by BUFFER-OR-NAME at the front of the buffer list and | ||
| 5492 | do not make the window displaying it the most recently selected | ||
| 5493 | one. Return the buffer switched to. | ||
| 5494 | |||
| 5495 | This function is intended for interactive use only. Lisp | ||
| 5496 | functions should call `pop-to-buffer-same-window' instead." | ||
| 5497 | (interactive | ||
| 5498 | (list (read-buffer-to-switch "Switch to buffer: "))) | ||
| 5499 | (let ((buffer (normalize-buffer-to-switch-to buffer-or-name))) | ||
| 5500 | (if (and (or (window-minibuffer-p) (eq (window-dedicated-p) t)) | ||
| 5501 | (not (eq buffer (window-buffer)))) | ||
| 5502 | ;; Cannot switch to another buffer in a minibuffer or strongly | ||
| 5503 | ;; dedicated window that does not show the buffer already. Call | ||
| 5504 | ;; `pop-to-buffer' instead. | ||
| 5505 | (pop-to-buffer buffer 'same-window norecord) | ||
| 5506 | (unless (eq buffer (window-buffer)) | ||
| 5507 | ;; I'm not sure why we should NOT call `set-window-buffer' here, | ||
| 5508 | ;; but let's keep things as they are (otherwise we could always | ||
| 5509 | ;; call `pop-to-buffer-same-window' here). | ||
| 5510 | (set-window-buffer nil buffer)) | ||
| 5511 | (unless norecord | ||
| 5512 | (select-window (selected-window))) | ||
| 5513 | (set-buffer buffer)))) | ||
| 5514 | |||
| 5515 | (defun switch-to-buffer-same-frame (buffer-or-name &optional norecord) | ||
| 5516 | "Switch to buffer BUFFER-OR-NAME in a window on the selected frame. | ||
| 5517 | Another frame will be used only if there is no other choice. | ||
| 5518 | Optional arguments BUFFER-OR-NAME and NORECORD have the same | ||
| 5519 | meaning as for `switch-to-buffer'. | ||
| 5520 | |||
| 5521 | This function is intended for interactive use only. Lisp | ||
| 5522 | functions should call `pop-to-buffer-same-frame' instead." | ||
| 5523 | (interactive | ||
| 5524 | (list (read-buffer-to-switch "Switch to buffer in other window: "))) | ||
| 5525 | (let ((buffer (normalize-buffer-to-switch-to buffer-or-name))) | ||
| 5526 | (pop-to-buffer buffer 'same-frame norecord))) | ||
| 5527 | |||
| 5528 | (defun switch-to-buffer-other-window (buffer-or-name &optional norecord) | ||
| 5529 | "Switch to buffer BUFFER-OR-NAME in another window. | ||
| 5530 | The selected window will be used only if there is no other | ||
| 5531 | choice. Windows on the selected frame are preferred to windows | ||
| 5532 | on other frames. Optional arguments BUFFER-OR-NAME and NORECORD | ||
| 5533 | have the same meaning as for `switch-to-buffer'. | ||
| 5534 | |||
| 5535 | This function is intended for interactive use only. Lisp | ||
| 5536 | functions should call `pop-to-buffer-other-window' instead." | ||
| 5537 | (interactive | ||
| 5538 | (list (read-buffer-to-switch "Switch to buffer in other window: "))) | ||
| 5539 | (let ((buffer (normalize-buffer-to-switch-to buffer-or-name))) | ||
| 5540 | (pop-to-buffer buffer 'other-window norecord))) | ||
| 5541 | |||
| 5542 | (defun switch-to-buffer-other-window-same-frame (buffer-or-name &optional norecord) | ||
| 5543 | "Switch to buffer BUFFER-OR-NAME in another window on the selected frame. | ||
| 5544 | The selected window or another frame will be used only if there | ||
| 5545 | is no other choice. Optional arguments BUFFER-OR-NAME and | ||
| 5546 | NORECORD have the same meaning as for `switch-to-buffer'. | ||
| 5547 | |||
| 5548 | This function is intended for interactive use only. Lisp | ||
| 5549 | functions should call `pop-to-buffer-other-window-same-frame' | ||
| 5550 | instead." | ||
| 5551 | (interactive | ||
| 5552 | (list (read-buffer-to-switch "Switch to buffer in other window: "))) | ||
| 5553 | (let ((buffer (normalize-buffer-to-switch-to buffer-or-name))) | ||
| 5554 | (pop-to-buffer buffer 'same-frame-other-window norecord))) | ||
| 5555 | |||
| 5556 | (defun switch-to-buffer-other-frame (buffer-or-name &optional norecord) | ||
| 5557 | "Switch to buffer BUFFER-OR-NAME on another frame. | ||
| 5558 | The same frame will be used only if there is no other choice. | ||
| 5559 | Optional arguments BUFFER-OR-NAME and NORECORD have the same | ||
| 5560 | meaning as for `switch-to-buffer'. | ||
| 5561 | |||
| 5562 | This function is intended for interactive use only. Lisp | ||
| 5563 | functions should call `pop-to-buffer-other-frame' instead." | ||
| 5564 | (interactive | ||
| 5565 | (list (read-buffer-to-switch "Switch to buffer in other frame: "))) | ||
| 5566 | (let ((buffer (normalize-buffer-to-switch-to buffer-or-name))) | ||
| 5567 | (pop-to-buffer buffer 'other-frame norecord))) | ||
| 5568 | |||
| 5569 | ;;; Obsolete definitions of `display-buffer' below. | ||
| 5570 | (defcustom same-window-buffer-names nil | ||
| 5571 | "List of names of buffers that should appear in the \"same\" window. | ||
| 5572 | `display-buffer' and `pop-to-buffer' show a buffer whose name is | ||
| 5573 | on this list in the selected rather than some other window. | ||
| 5574 | |||
| 5575 | An element of this list can be a cons cell instead of just a | ||
| 5576 | string. In that case, the cell's car must be a string specifying | ||
| 5577 | the buffer name. This is for compatibility with | ||
| 5578 | `special-display-buffer-names'; the cdr of the cons cell is | ||
| 5579 | ignored. | ||
| 5580 | |||
| 5581 | See also `same-window-regexps'." | ||
| 5582 | :type '(repeat (string :format "%v")) | ||
| 5583 | :group 'windows) | ||
| 5584 | (make-obsolete-variable | ||
| 5585 | 'same-window-buffer-names | ||
| 5586 | "use `display-buffer-alist' or 2nd arg of `display-buffer' instead." "24.1") | ||
| 5587 | |||
| 5588 | (defcustom same-window-regexps nil | ||
| 5589 | "List of regexps saying which buffers should appear in the \"same\" window. | ||
| 5590 | `display-buffer' and `pop-to-buffer' show a buffer whose name | ||
| 5591 | matches a regexp on this list in the selected rather than some | ||
| 5592 | other window. | ||
| 5593 | |||
| 5594 | An element of this list can be a cons cell instead of just a | ||
| 5595 | string. In that case, the cell's car must be a regexp matching | ||
| 5596 | the buffer name. This is for compatibility with | ||
| 5597 | `special-display-regexps'; the cdr of the cons cell is ignored. | ||
| 5598 | |||
| 5599 | See also `same-window-buffer-names'." | ||
| 5600 | :type '(repeat (regexp :format "%v")) | ||
| 3470 | :group 'windows) | 5601 | :group 'windows) |
| 5602 | (make-obsolete-variable | ||
| 5603 | 'same-window-regexps | ||
| 5604 | "use `display-buffer-alist' or 2nd arg of `display-buffer' instead." "24.1") | ||
| 5605 | |||
| 5606 | (defun same-window-p (buffer-name) | ||
| 5607 | "Return non-nil if a buffer named BUFFER-NAME would be shown in the \"same\" window. | ||
| 5608 | This function returns non-nil if `display-buffer' or | ||
| 5609 | `pop-to-buffer' would show a buffer named BUFFER-NAME in the | ||
| 5610 | selected rather than \(as usual\) some other window. See | ||
| 5611 | `same-window-buffer-names' and `same-window-regexps'." | ||
| 5612 | (let ((buffer-names (with-no-warnings special-display-buffer-names)) | ||
| 5613 | (regexps (with-no-warnings special-display-regexps))) | ||
| 5614 | (cond | ||
| 5615 | ((not (stringp buffer-name))) | ||
| 5616 | ;; The elements of `same-window-buffer-names' can be buffer | ||
| 5617 | ;; names or cons cells whose cars are buffer names. | ||
| 5618 | ((member buffer-name buffer-names)) | ||
| 5619 | ((assoc buffer-name buffer-names)) | ||
| 5620 | ((catch 'found | ||
| 5621 | (dolist (regexp regexps) | ||
| 5622 | ;; The elements of `same-window-regexps' can be regexps | ||
| 5623 | ;; or cons cells whose cars are regexps. | ||
| 5624 | (when (or (and (stringp regexp) | ||
| 5625 | (string-match regexp buffer-name)) | ||
| 5626 | (and (consp regexp) (stringp (car regexp)) | ||
| 5627 | (string-match-p (car regexp) buffer-name))) | ||
| 5628 | (throw 'found t)))))))) | ||
| 5629 | (make-obsolete | ||
| 5630 | 'same-window-p "pass argument to buffer display function instead." "24.1") | ||
| 5631 | |||
| 5632 | (defcustom special-display-frame-alist | ||
| 5633 | '((height . 14) (width . 80) (unsplittable . t)) | ||
| 5634 | "Alist of parameters for special frames. | ||
| 5635 | Special frames are used for buffers whose names are listed in | ||
| 5636 | `special-display-buffer-names' and for buffers whose names match | ||
| 5637 | one of the regular expressions in `special-display-regexps'. | ||
| 5638 | |||
| 5639 | This variable can be set in your init file, like this: | ||
| 5640 | |||
| 5641 | (setq special-display-frame-alist '((width . 80) (height . 20))) | ||
| 5642 | |||
| 5643 | These supersede the values given in `default-frame-alist'." | ||
| 5644 | :type '(repeat (cons :format "%v" | ||
| 5645 | (symbol :tag "Parameter") | ||
| 5646 | (sexp :tag "Value"))) | ||
| 5647 | :group 'frames) | ||
| 5648 | (make-obsolete-variable | ||
| 5649 | 'special-display-frame-alist | ||
| 5650 | "use `display-buffer-alist' or 2nd arg of `display-buffer' instead." "24.1") | ||
| 5651 | |||
| 5652 | (defun special-display-popup-frame (buffer &optional args) | ||
| 5653 | "Display BUFFER in a special frame and return the window chosen. | ||
| 5654 | If BUFFER is already displayed in a visible or iconified frame, | ||
| 5655 | raise that frame. Otherwise, display BUFFER in a way as | ||
| 5656 | specified by optional argument ARGS. | ||
| 5657 | |||
| 5658 | If ARGS is an alist, use it as a list of frame parameters. If | ||
| 5659 | these parameters contain \(same-window . t), display BUFFER in | ||
| 5660 | the selected window. If they contain \(same-frame . t), display | ||
| 5661 | BUFFER in a window on the selected frame. | ||
| 5662 | |||
| 5663 | If ARGS is a list whose car is a symbol, use (car ARGS) as a | ||
| 5664 | function to do the work. Pass it BUFFER as first argument, | ||
| 5665 | and (cdr ARGS) as second." | ||
| 5666 | (if (and args (symbolp (car args))) | ||
| 5667 | (apply (car args) buffer (cdr args)) | ||
| 5668 | (let ((window (get-buffer-window buffer 0))) | ||
| 5669 | (or | ||
| 5670 | ;; If we have a window already, make it visible. | ||
| 5671 | (when window | ||
| 5672 | (let ((frame (window-frame window))) | ||
| 5673 | (make-frame-visible frame) | ||
| 5674 | (raise-frame frame) | ||
| 5675 | window)) | ||
| 5676 | ;; Reuse the current window if the user requested it. | ||
| 5677 | (when (cdr (assq 'same-window args)) | ||
| 5678 | (display-buffer-reuse-window | ||
| 5679 | buffer '(same nil nil) '((reuse-dedicated . 'weak)))) | ||
| 5680 | ;; Stay on the same frame if requested. | ||
| 5681 | (when (or (cdr (assq 'same-frame args)) | ||
| 5682 | (cdr (assq 'same-window args))) | ||
| 5683 | (or (display-buffer-pop-up-window | ||
| 5684 | buffer '((largest . nil) (lru . nil))) | ||
| 5685 | (display-buffer-reuse-window | ||
| 5686 | buffer '(nil nil nil)))) | ||
| 5687 | ;; If no window yet, make one in a new frame. | ||
| 5688 | (let ((frame | ||
| 5689 | (with-current-buffer buffer | ||
| 5690 | (make-frame | ||
| 5691 | (append args (with-no-warnings | ||
| 5692 | special-display-frame-alist)))))) | ||
| 5693 | (set-window-buffer (frame-selected-window frame) buffer) | ||
| 5694 | (set-window-dedicated-p (frame-selected-window frame) t) | ||
| 5695 | (frame-selected-window frame)))))) | ||
| 5696 | (make-obsolete | ||
| 5697 | 'special-display-popup-frame | ||
| 5698 | "use `display-buffer-alist' or 2nd arg of `display-buffer' instead." "24.1") | ||
| 5699 | |||
| 5700 | (defcustom special-display-function 'special-display-popup-frame | ||
| 5701 | "Function to call for displaying special buffers. | ||
| 5702 | This function is called with two arguments - the buffer and, | ||
| 5703 | optionally, a list - and should return a window displaying that | ||
| 5704 | buffer. The default value usually makes a separate frame for the | ||
| 5705 | buffer using `special-display-frame-alist' to specify the frame | ||
| 5706 | parameters. See the definition of `special-display-popup-frame' | ||
| 5707 | for how to specify such a function. | ||
| 5708 | |||
| 5709 | A buffer is special when its name is either listed in | ||
| 5710 | `special-display-buffer-names' or matches a regexp in | ||
| 5711 | `special-display-regexps'." | ||
| 5712 | :type 'function | ||
| 5713 | :group 'windows | ||
| 5714 | :group 'frames) | ||
| 5715 | (make-obsolete-variable | ||
| 5716 | 'special-display-function | ||
| 5717 | "use `display-buffer-alist' or 2nd arg of `display-buffer' instead." "24.1") | ||
| 3471 | 5718 | ||
| 3472 | (defcustom special-display-buffer-names nil | 5719 | (defcustom special-display-buffer-names nil |
| 3473 | "List of names of buffers that should be displayed specially. | 5720 | "List of names of buffers that should be displayed specially. |
| @@ -3532,6 +5779,9 @@ See also `special-display-regexps'." | |||
| 3532 | (repeat :tag "Arguments" (sexp))))) | 5779 | (repeat :tag "Arguments" (sexp))))) |
| 3533 | :group 'windows | 5780 | :group 'windows |
| 3534 | :group 'frames) | 5781 | :group 'frames) |
| 5782 | (make-obsolete-variable | ||
| 5783 | 'special-display-buffer-names | ||
| 5784 | "use `display-buffer-alist' or 2nd arg of `display-buffer' instead." "24.1") | ||
| 3535 | 5785 | ||
| 3536 | ;;;###autoload | 5786 | ;;;###autoload |
| 3537 | (put 'special-display-buffer-names 'risky-local-variable t) | 5787 | (put 'special-display-buffer-names 'risky-local-variable t) |
| @@ -3600,6 +5850,9 @@ See also `special-display-buffer-names'." | |||
| 3600 | (repeat :tag "Arguments" (sexp))))) | 5850 | (repeat :tag "Arguments" (sexp))))) |
| 3601 | :group 'windows | 5851 | :group 'windows |
| 3602 | :group 'frames) | 5852 | :group 'frames) |
| 5853 | (make-obsolete-variable | ||
| 5854 | 'special-display-regexps | ||
| 5855 | "use `display-buffer-alist' or 2nd arg of `display-buffer' instead." "24.1") | ||
| 3603 | 5856 | ||
| 3604 | (defun special-display-p (buffer-name) | 5857 | (defun special-display-p (buffer-name) |
| 3605 | "Return non-nil if a buffer named BUFFER-NAME gets a special frame. | 5858 | "Return non-nil if a buffer named BUFFER-NAME gets a special frame. |
| @@ -3609,15 +5862,17 @@ matching BUFFER-NAME. If `special-display-buffer-names' or | |||
| 3609 | `special-display-regexps' contain a list entry whose car equals | 5862 | `special-display-regexps' contain a list entry whose car equals |
| 3610 | or matches BUFFER-NAME, the return value is the cdr of that | 5863 | or matches BUFFER-NAME, the return value is the cdr of that |
| 3611 | entry." | 5864 | entry." |
| 3612 | (let (tmp) | 5865 | (let ((buffer-names (with-no-warnings special-display-buffer-names)) |
| 5866 | (regexps (with-no-warnings special-display-regexps)) | ||
| 5867 | tmp) | ||
| 3613 | (cond | 5868 | (cond |
| 3614 | ((not (stringp buffer-name))) | 5869 | ((not (stringp buffer-name))) |
| 3615 | ((member buffer-name special-display-buffer-names) | 5870 | ((member buffer-name buffer-names) |
| 3616 | t) | 5871 | t) |
| 3617 | ((setq tmp (assoc buffer-name special-display-buffer-names)) | 5872 | ((setq tmp (assoc buffer-name buffer-names)) |
| 3618 | (cdr tmp)) | 5873 | (cdr tmp)) |
| 3619 | ((catch 'found | 5874 | ((catch 'found |
| 3620 | (dolist (regexp special-display-regexps) | 5875 | (dolist (regexp regexps) |
| 3621 | (cond | 5876 | (cond |
| 3622 | ((stringp regexp) | 5877 | ((stringp regexp) |
| 3623 | (when (string-match-p regexp buffer-name) | 5878 | (when (string-match-p regexp buffer-name) |
| @@ -3625,117 +5880,101 @@ entry." | |||
| 3625 | ((and (consp regexp) (stringp (car regexp)) | 5880 | ((and (consp regexp) (stringp (car regexp)) |
| 3626 | (string-match-p (car regexp) buffer-name)) | 5881 | (string-match-p (car regexp) buffer-name)) |
| 3627 | (throw 'found (cdr regexp)))))))))) | 5882 | (throw 'found (cdr regexp)))))))))) |
| 3628 | 5883 | (make-obsolete | |
| 3629 | (defcustom special-display-function 'special-display-popup-frame | 5884 | 'special-display-p |
| 3630 | "Function to call for displaying special buffers. | 5885 | "pass argument to buffer display function instead." "24.1") |
| 3631 | This function is called with two arguments - the buffer and, | 5886 | |
| 3632 | optionally, a list - and should return a window displaying that | 5887 | (defcustom pop-up-frame-alist nil |
| 3633 | buffer. The default value usually makes a separate frame for the | 5888 | "Alist of parameters for automatically generated new frames. |
| 3634 | buffer using `special-display-frame-alist' to specify the frame | 5889 | You can set this in your init file; for example, |
| 3635 | parameters. See the definition of `special-display-popup-frame' | 5890 | |
| 3636 | for how to specify such a function. | 5891 | (setq pop-up-frame-alist '((width . 80) (height . 20))) |
| 3637 | 5892 | ||
| 3638 | A buffer is special when its name is either listed in | 5893 | If non-nil, the value you specify here is used by the default |
| 3639 | `special-display-buffer-names' or matches a regexp in | 5894 | `pop-up-frame-function' for the creation of new frames. |
| 3640 | `special-display-regexps'." | 5895 | |
| 5896 | Since `pop-up-frame-function' is used by `display-buffer' for | ||
| 5897 | making new frames, any value specified here by default affects | ||
| 5898 | the automatic generation of new frames via `display-buffer' and | ||
| 5899 | all functions based on it. The behavior of `make-frame' is not | ||
| 5900 | affected by this variable." | ||
| 5901 | :type '(repeat (cons :format "%v" | ||
| 5902 | (symbol :tag "Parameter") | ||
| 5903 | (sexp :tag "Value"))) | ||
| 5904 | :group 'frames) | ||
| 5905 | (make-obsolete-variable | ||
| 5906 | 'pop-up-frame-alist | ||
| 5907 | "use `display-buffer-alist' or 2nd arg of `display-buffer' instead." "24.1") | ||
| 5908 | |||
| 5909 | (defcustom pop-up-frame-function | ||
| 5910 | (lambda () (make-frame pop-up-frame-alist)) | ||
| 5911 | "Function used by `display-buffer' for creating a new frame. | ||
| 5912 | This function is called with no arguments and should return a new | ||
| 5913 | frame. The default value calls `make-frame' with the argument | ||
| 5914 | `pop-up-frame-alist'." | ||
| 3641 | :type 'function | 5915 | :type 'function |
| 3642 | :group 'frames) | 5916 | :group 'frames) |
| 5917 | (make-obsolete-variable | ||
| 5918 | 'pop-up-frame-function | ||
| 5919 | "use `display-buffer-alist' or 2nd arg of `display-buffer' instead." "24.1") | ||
| 3643 | 5920 | ||
| 3644 | (defcustom same-window-buffer-names nil | 5921 | (defcustom pop-up-frames 'unset ; nil |
| 3645 | "List of names of buffers that should appear in the \"same\" window. | ||
| 3646 | `display-buffer' and `pop-to-buffer' show a buffer whose name is | ||
| 3647 | on this list in the selected rather than some other window. | ||
| 3648 | |||
| 3649 | An element of this list can be a cons cell instead of just a | ||
| 3650 | string. In that case, the cell's car must be a string specifying | ||
| 3651 | the buffer name. This is for compatibility with | ||
| 3652 | `special-display-buffer-names'; the cdr of the cons cell is | ||
| 3653 | ignored. | ||
| 3654 | |||
| 3655 | See also `same-window-regexps'." | ||
| 3656 | :type '(repeat (string :format "%v")) | ||
| 3657 | :group 'windows) | ||
| 3658 | |||
| 3659 | (defcustom same-window-regexps nil | ||
| 3660 | "List of regexps saying which buffers should appear in the \"same\" window. | ||
| 3661 | `display-buffer' and `pop-to-buffer' show a buffer whose name | ||
| 3662 | matches a regexp on this list in the selected rather than some | ||
| 3663 | other window. | ||
| 3664 | |||
| 3665 | An element of this list can be a cons cell instead of just a | ||
| 3666 | string. In that case, the cell's car must be a regexp matching | ||
| 3667 | the buffer name. This is for compatibility with | ||
| 3668 | `special-display-regexps'; the cdr of the cons cell is ignored. | ||
| 3669 | |||
| 3670 | See also `same-window-buffer-names'." | ||
| 3671 | :type '(repeat (regexp :format "%v")) | ||
| 3672 | :group 'windows) | ||
| 3673 | |||
| 3674 | (defun same-window-p (buffer-name) | ||
| 3675 | "Return non-nil if a buffer named BUFFER-NAME would be shown in the \"same\" window. | ||
| 3676 | This function returns non-nil if `display-buffer' or | ||
| 3677 | `pop-to-buffer' would show a buffer named BUFFER-NAME in the | ||
| 3678 | selected rather than \(as usual\) some other window. See | ||
| 3679 | `same-window-buffer-names' and `same-window-regexps'." | ||
| 3680 | (cond | ||
| 3681 | ((not (stringp buffer-name))) | ||
| 3682 | ;; The elements of `same-window-buffer-names' can be buffer | ||
| 3683 | ;; names or cons cells whose cars are buffer names. | ||
| 3684 | ((member buffer-name same-window-buffer-names)) | ||
| 3685 | ((assoc buffer-name same-window-buffer-names)) | ||
| 3686 | ((catch 'found | ||
| 3687 | (dolist (regexp same-window-regexps) | ||
| 3688 | ;; The elements of `same-window-regexps' can be regexps | ||
| 3689 | ;; or cons cells whose cars are regexps. | ||
| 3690 | (when (or (and (stringp regexp) | ||
| 3691 | (string-match regexp buffer-name)) | ||
| 3692 | (and (consp regexp) (stringp (car regexp)) | ||
| 3693 | (string-match-p (car regexp) buffer-name))) | ||
| 3694 | (throw 'found t))))))) | ||
| 3695 | |||
| 3696 | (defcustom pop-up-frames nil | ||
| 3697 | "Whether `display-buffer' should make a separate frame. | 5922 | "Whether `display-buffer' should make a separate frame. |
| 3698 | If nil, never make a separate frame. | 5923 | If nil, never make a separate frame. |
| 3699 | If the value is `graphic-only', make a separate frame | 5924 | If the value is `graphic-only', make a separate frame |
| 3700 | on graphic displays only. | 5925 | on graphic displays only. |
| 5926 | If this is the symbol unset, the option was not set and is | ||
| 5927 | ignored. | ||
| 3701 | Any other non-nil value means always make a separate frame." | 5928 | Any other non-nil value means always make a separate frame." |
| 3702 | :type '(choice | 5929 | :type '(choice |
| 5930 | (const :tag "Unset" unset) | ||
| 3703 | (const :tag "Never" nil) | 5931 | (const :tag "Never" nil) |
| 3704 | (const :tag "On graphic displays only" graphic-only) | 5932 | (const :tag "On graphic displays only" graphic-only) |
| 3705 | (const :tag "Always" t)) | 5933 | (const :tag "Always" t)) |
| 3706 | :group 'windows) | 5934 | :version "24.1" |
| 5935 | :group 'windows | ||
| 5936 | :group 'frames) | ||
| 5937 | (make-obsolete-variable | ||
| 5938 | 'pop-up-frames | ||
| 5939 | "use `display-buffer-alist' or 2nd arg of `display-buffer' instead." "24.1") | ||
| 3707 | 5940 | ||
| 3708 | (defcustom display-buffer-reuse-frames nil | 5941 | (defcustom display-buffer-reuse-frames 'unset ; nil |
| 3709 | "Non-nil means `display-buffer' should reuse frames. | 5942 | "Set and non-nil means `display-buffer' should reuse frames. |
| 3710 | If the buffer in question is already displayed in a frame, raise | 5943 | If the buffer in question is already displayed in a frame, raise |
| 3711 | that frame." | 5944 | that frame." |
| 3712 | :type 'boolean | 5945 | :type 'boolean |
| 3713 | :version "21.1" | 5946 | :version "24.1" |
| 3714 | :group 'windows) | 5947 | :group 'windows |
| 5948 | :group 'frames) | ||
| 5949 | (make-obsolete-variable | ||
| 5950 | 'display-buffer-reuse-frames | ||
| 5951 | "use `display-buffer-alist' or 2nd arg of `display-buffer' instead." "24.1") | ||
| 3715 | 5952 | ||
| 3716 | (defcustom pop-up-windows t | 5953 | (defcustom pop-up-windows 'unset ; t |
| 3717 | "Non-nil means `display-buffer' should make a new window." | 5954 | "Set and non-nil means `display-buffer' should make a new window." |
| 3718 | :type 'boolean | 5955 | :type 'boolean |
| 5956 | :version "24.1" | ||
| 3719 | :group 'windows) | 5957 | :group 'windows) |
| 5958 | (make-obsolete-variable | ||
| 5959 | 'pop-up-windows | ||
| 5960 | "use `display-buffer-alist' or 2nd arg of `display-buffer' instead." "24.1") | ||
| 3720 | 5961 | ||
| 3721 | (defcustom split-window-preferred-function 'split-window-sensibly | 5962 | (defcustom split-window-preferred-function 'split-window-sensibly |
| 3722 | "Function called by `display-buffer' routines to split a window. | 5963 | "Function called by `display-buffer' to split a window. |
| 3723 | This function is called with a window as single argument and is | 5964 | This function is called with a window as single argument and is |
| 3724 | supposed to split that window and return the new window. If the | 5965 | supposed to split that window and return the new window. If the |
| 3725 | window can (or shall) not be split, it is supposed to return nil. | 5966 | window can (or shall) not be split, it is supposed to return nil. |
| 5967 | |||
| 3726 | The default is to call the function `split-window-sensibly' which | 5968 | The default is to call the function `split-window-sensibly' which |
| 3727 | tries to split the window in a way which seems most suitable. | 5969 | tries to split the window in a way which seems most suitable. |
| 3728 | You can customize the options `split-height-threshold' and/or | 5970 | You can customize the options `split-height-threshold' and/or |
| 3729 | `split-width-threshold' in order to have `split-window-sensibly' | 5971 | `split-width-threshold' in order to have `split-window-sensibly' |
| 3730 | prefer either vertical or horizontal splitting. | 5972 | prefer either vertical or horizontal splitting. |
| 3731 | 5973 | ||
| 3732 | If you set this to any other function, bear in mind that the | 5974 | If you set this to any other function, bear in mind that |
| 3733 | `display-buffer' routines may call this function two times. The | 5975 | `display-buffer' may call that function repeatedly; the option |
| 3734 | argument of the first call is the largest window on its frame. | 5976 | `pop-up-windows' controls which windows may become the argument |
| 3735 | If that call fails to return a live window, the function is | 5977 | of this function. |
| 3736 | called again with the least recently used window as argument. If | ||
| 3737 | that call fails too, `display-buffer' will use an existing window | ||
| 3738 | to display its buffer. | ||
| 3739 | 5978 | ||
| 3740 | The window selected at the time `display-buffer' was invoked is | 5979 | The window selected at the time `display-buffer' was invoked is |
| 3741 | still selected when this function is called. Hence you can | 5980 | still selected when this function is called. Hence you can |
| @@ -3745,28 +5984,55 @@ not want to split the selected window." | |||
| 3745 | :type 'function | 5984 | :type 'function |
| 3746 | :version "23.1" | 5985 | :version "23.1" |
| 3747 | :group 'windows) | 5986 | :group 'windows) |
| 5987 | (make-obsolete-variable | ||
| 5988 | 'split-window-preferred-function | ||
| 5989 | "use `display-buffer-alist' or 2nd arg of `display-buffer' instead." "24.1") | ||
| 3748 | 5990 | ||
| 3749 | (defcustom split-height-threshold 80 | 5991 | (defcustom split-height-threshold 80 |
| 3750 | "Minimum height for splitting windows sensibly. | 5992 | "Minimum height for splitting a window to display a buffer. |
| 3751 | If this is an integer, `split-window-sensibly' may split a window | 5993 | If this is an integer, `display-buffer' can split a window |
| 3752 | vertically only if it has at least this many lines. If this is | 5994 | vertically only if it has at least this many lines. If this is |
| 3753 | nil, `split-window-sensibly' is not allowed to split a window | 5995 | nil, `display-buffer' does not split windows vertically. If a |
| 3754 | vertically. If, however, a window is the only window on its | 5996 | window is the only window on its frame, `display-buffer' may |
| 3755 | frame, `split-window-sensibly' may split it vertically | 5997 | split it vertically disregarding the value of this variable." |
| 3756 | disregarding the value of this variable." | ||
| 3757 | :type '(choice (const nil) (integer :tag "lines")) | 5998 | :type '(choice (const nil) (integer :tag "lines")) |
| 3758 | :version "23.1" | 5999 | :version "23.1" |
| 3759 | :group 'windows) | 6000 | :group 'windows) |
| 6001 | (make-obsolete-variable | ||
| 6002 | 'split-height-threshold | ||
| 6003 | "use `display-buffer-alist' or 2nd arg of `display-buffer' instead." "24.1") | ||
| 3760 | 6004 | ||
| 3761 | (defcustom split-width-threshold 160 | 6005 | (defcustom split-width-threshold 160 |
| 3762 | "Minimum width for splitting windows sensibly. | 6006 | "Minimum width for splitting a window to display a buffer. |
| 3763 | If this is an integer, `split-window-sensibly' may split a window | 6007 | If this is an integer, `display-buffer' can split a window |
| 3764 | horizontally only if it has at least this many columns. If this | 6008 | horizontally only if it has at least this many columns. If this |
| 3765 | is nil, `split-window-sensibly' is not allowed to split a window | 6009 | is nil, `display-buffer' cannot split windows horizontally." |
| 3766 | horizontally." | ||
| 3767 | :type '(choice (const nil) (integer :tag "columns")) | 6010 | :type '(choice (const nil) (integer :tag "columns")) |
| 3768 | :version "23.1" | 6011 | :version "23.1" |
| 3769 | :group 'windows) | 6012 | :group 'windows) |
| 6013 | (make-obsolete-variable | ||
| 6014 | 'split-width-threshold | ||
| 6015 | "use `display-buffer-alist' or 2nd arg of `display-buffer' instead." "24.1") | ||
| 6016 | |||
| 6017 | (defcustom even-window-heights t | ||
| 6018 | "If non-nil `display-buffer' will try to even window heights. | ||
| 6019 | Otherwise `display-buffer' will leave the window configuration | ||
| 6020 | alone. Heights are evened only when `display-buffer' reuses a | ||
| 6021 | window that appears above or below the selected window." | ||
| 6022 | :type 'boolean | ||
| 6023 | :version "23.1" | ||
| 6024 | :group 'windows) | ||
| 6025 | (make-obsolete-variable | ||
| 6026 | 'even-window-heights | ||
| 6027 | "use `display-buffer-alist' or 2nd arg of `display-buffer' instead." "24.1") | ||
| 6028 | |||
| 6029 | (defvar display-buffer-mark-dedicated 'unset ; nil | ||
| 6030 | "Set and non-nil means `display-buffer' marks the windows it creates as dedicated. | ||
| 6031 | The actual non-nil value of this variable will be copied to the | ||
| 6032 | `window-dedicated-p' flag.") | ||
| 6033 | (make-obsolete-variable | ||
| 6034 | 'display-buffer-mark-dedicated | ||
| 6035 | "use `display-buffer-alist' or 2nd arg of `display-buffer' instead." "24.1") | ||
| 3770 | 6036 | ||
| 3771 | (defun window-splittable-p (window &optional horizontal) | 6037 | (defun window-splittable-p (window &optional horizontal) |
| 3772 | "Return non-nil if `split-window-sensibly' may split WINDOW. | 6038 | "Return non-nil if `split-window-sensibly' may split WINDOW. |
| @@ -3817,6 +6083,8 @@ hold: | |||
| 3817 | (max split-height-threshold | 6083 | (max split-height-threshold |
| 3818 | (* 2 (max window-min-height | 6084 | (* 2 (max window-min-height |
| 3819 | (if mode-line-format 2 1)))))))))) | 6085 | (if mode-line-format 2 1)))))))))) |
| 6086 | (make-obsolete | ||
| 6087 | 'window-splittable-p "use 2nd arg of `display-buffer' instead." "24.1") | ||
| 3820 | 6088 | ||
| 3821 | (defun split-window-sensibly (window) | 6089 | (defun split-window-sensibly (window) |
| 3822 | "Split WINDOW in a way suitable for `display-buffer'. | 6090 | "Split WINDOW in a way suitable for `display-buffer'. |
| @@ -3849,11 +6117,11 @@ more likely to occur. | |||
| 3849 | Have a look at the function `window-splittable-p' if you want to | 6117 | Have a look at the function `window-splittable-p' if you want to |
| 3850 | know how `split-window-sensibly' determines whether WINDOW can be | 6118 | know how `split-window-sensibly' determines whether WINDOW can be |
| 3851 | split." | 6119 | split." |
| 3852 | (or (and (window-splittable-p window) | 6120 | (or (and (with-no-warnings (window-splittable-p window)) |
| 3853 | ;; Split window vertically. | 6121 | ;; Split window vertically. |
| 3854 | (with-selected-window window | 6122 | (with-selected-window window |
| 3855 | (split-window-vertically))) | 6123 | (split-window-vertically))) |
| 3856 | (and (window-splittable-p window t) | 6124 | (and (with-no-warnings (window-splittable-p window t)) |
| 3857 | ;; Split window horizontally. | 6125 | ;; Split window horizontally. |
| 3858 | (with-selected-window window | 6126 | (with-selected-window window |
| 3859 | (split-window-horizontally))) | 6127 | (split-window-horizontally))) |
| @@ -3863,433 +6131,233 @@ split." | |||
| 3863 | ;; minibuffer window, try to split it vertically disregarding | 6131 | ;; minibuffer window, try to split it vertically disregarding |
| 3864 | ;; the value of `split-height-threshold'. | 6132 | ;; the value of `split-height-threshold'. |
| 3865 | (let ((split-height-threshold 0)) | 6133 | (let ((split-height-threshold 0)) |
| 3866 | (when (window-splittable-p window) | 6134 | (when (with-no-warnings (window-splittable-p window)) |
| 3867 | (with-selected-window window | 6135 | (with-selected-window window |
| 3868 | (split-window-vertically))))))) | 6136 | (split-window-vertically))))))) |
| 3869 | 6137 | (make-obsolete | |
| 3870 | (defun window--try-to-split-window (window) | 6138 | 'split-window-sensibly "use 2nd arg of `display-buffer' instead." "24.1") |
| 3871 | "Try to split WINDOW. | 6139 | |
| 3872 | Return value returned by `split-window-preferred-function' if it | 6140 | ;; Functions for converting Emacs 23 buffer display options to buffer |
| 3873 | represents a live window, nil otherwise." | 6141 | ;; display specifiers. |
| 3874 | (and (window-live-p window) | 6142 | (defun display-buffer-alist-add (identifiers specifiers &optional no-custom) |
| 3875 | (not (frame-parameter (window-frame window) 'unsplittable)) | 6143 | "Helper function for `display-buffer-alist-set'." |
| 3876 | (let ((new-window | 6144 | (unless identifiers |
| 3877 | ;; Since `split-window-preferred-function' might | 6145 | (setq identifiers '((regexp . ".*")))) |
| 3878 | ;; throw an error use `condition-case'. | 6146 | (unless (atom specifiers) |
| 3879 | (condition-case nil | 6147 | (setq specifiers (delq nil specifiers))) |
| 3880 | (funcall split-window-preferred-function window) | 6148 | |
| 3881 | (error nil)))) | 6149 | (if no-custom |
| 3882 | (and (window-live-p new-window) new-window)))) | 6150 | (setq display-buffer-alist |
| 3883 | 6151 | (cons (cons identifiers specifiers) display-buffer-alist)) | |
| 3884 | (defun window--frame-usable-p (frame) | 6152 | (customize-set-variable |
| 3885 | "Return FRAME if it can be used to display a buffer." | 6153 | 'display-buffer-alist |
| 3886 | (when (frame-live-p frame) | 6154 | (cons (cons identifiers specifiers) display-buffer-alist)))) |
| 3887 | (let ((window (frame-root-window frame))) | 6155 | |
| 3888 | ;; `frame-root-window' may be an internal window which is considered | 6156 | (defun display-buffer-alist-set (&optional no-custom add) |
| 3889 | ;; "dead" by `window-live-p'. Hence if `window' is not live we | 6157 | "Set `display-buffer-alist' from Emacs 23 buffer display options. |
| 3890 | ;; implicitly know that `frame' has a visible window we can use. | 6158 | Optional argument NO-CUSTOM nil means use `customize-set-variable' |
| 3891 | (unless (and (window-live-p window) | 6159 | to set the value of `display-buffer-alist'. NO-CUSTOM non-nil |
| 3892 | (or (window-minibuffer-p window) | 6160 | means to use `setq' instead. |
| 3893 | ;; If the window is soft-dedicated, the frame is usable. | 6161 | |
| 3894 | ;; Actually, even if the window is really dedicated, | 6162 | Optional argument ADD nil means to replace the actual value of |
| 3895 | ;; the frame is still usable by splitting it. | 6163 | `display-buffer-alist' with the value calculated here. ADD |
| 3896 | ;; At least Emacs-22 allowed it, and it is desirable | 6164 | non-nil means prepend the value calculated here to the current |
| 3897 | ;; when displaying same-frame windows. | 6165 | value of `display-buffer-alist'." |
| 3898 | nil ; (eq t (window-dedicated-p window)) | 6166 | (unless add |
| 3899 | )) | 6167 | (if no-custom |
| 3900 | frame)))) | 6168 | (setq display-buffer-alist nil) |
| 3901 | 6169 | (customize-set-variable 'display-buffer-alist nil))) | |
| 3902 | (defcustom even-window-heights t | 6170 | |
| 3903 | "If non-nil `display-buffer' will try to even window heights. | 6171 | ;; Disable warnings, there are too many obsolete options here. |
| 3904 | Otherwise `display-buffer' will leave the window configuration | 6172 | (with-no-warnings |
| 3905 | alone. Heights are evened only when `display-buffer' chooses a | 6173 | ;; `pop-up-windows' |
| 3906 | window that appears above or below the selected window." | 6174 | (display-buffer-alist-add |
| 3907 | :type 'boolean | 6175 | nil |
| 3908 | :group 'windows) | 6176 | (let ((fun (unless (eq split-window-preferred-function |
| 3909 | 6177 | 'split-window-sensibly) | |
| 3910 | (defun window--even-window-heights (window) | 6178 | ;; `split-window-sensibly' has been merged into the |
| 3911 | "Even heights of WINDOW and selected window. | 6179 | ;; `display-buffer-split-window' code as `nil'. |
| 3912 | Do this only if these windows are vertically adjacent to each | 6180 | split-window-preferred-function)) |
| 3913 | other, `even-window-heights' is non-nil, and the selected window | 6181 | (min-height |
| 3914 | is higher than WINDOW." | 6182 | (if (numberp split-height-threshold) |
| 3915 | (when (and even-window-heights | 6183 | (/ split-height-threshold 2) |
| 3916 | (not (eq window (selected-window))) | 6184 | ;; Undocumented hack. |
| 3917 | ;; Don't resize minibuffer windows. | 6185 | 1.0)) |
| 3918 | (not (window-minibuffer-p (selected-window))) | 6186 | (min-width |
| 3919 | (> (window-height (selected-window)) (window-height window)) | 6187 | (if (numberp split-width-threshold) |
| 3920 | (eq (window-frame window) (window-frame (selected-window))) | 6188 | (/ split-width-threshold 2) |
| 3921 | (let ((sel-edges (window-edges (selected-window))) | 6189 | ;; Undocumented hack. |
| 3922 | (win-edges (window-edges window))) | 6190 | 1.0))) |
| 3923 | (and (= (nth 0 sel-edges) (nth 0 win-edges)) | 6191 | (list |
| 3924 | (= (nth 2 sel-edges) (nth 2 win-edges)) | 6192 | 'pop-up-window |
| 3925 | (or (= (nth 1 sel-edges) (nth 3 win-edges)) | 6193 | (when pop-up-windows ; unset qualifies as t |
| 3926 | (= (nth 3 sel-edges) (nth 1 win-edges)))))) | 6194 | (list |
| 3927 | (let ((window-min-height 1)) | 6195 | 'pop-up-window |
| 3928 | ;; Don't throw an error if we can't even window heights for | 6196 | (cons 'largest fun) |
| 3929 | ;; whatever reason. | 6197 | (cons 'lru fun))) |
| 3930 | (condition-case nil | 6198 | (cons 'pop-up-window-min-height min-height) |
| 3931 | (enlarge-window (/ (- (window-height window) (window-height)) 2)) | 6199 | (cons 'pop-up-window-min-width min-width))) |
| 3932 | (error nil))))) | 6200 | no-custom) |
| 3933 | 6201 | ||
| 3934 | (defun window--display-buffer-1 (window) | 6202 | ;; `pop-up-frames' |
| 3935 | "Raise the frame containing WINDOW. | 6203 | (display-buffer-alist-add |
| 3936 | Do not raise the selected frame. Return WINDOW." | 6204 | nil |
| 3937 | (let* ((frame (window-frame window)) | 6205 | (list |
| 3938 | (visible (frame-visible-p frame))) | 6206 | 'pop-up-frame |
| 3939 | (unless (or (not visible) | 6207 | (unless (memq pop-up-frames '(nil unset)) |
| 3940 | ;; Assume the selected frame is already visible enough. | 6208 | (list 'pop-up-frame pop-up-frames)) |
| 3941 | (eq frame (selected-frame)) | 6209 | (when pop-up-frame-function |
| 3942 | ;; Assume the frame from which we invoked the minibuffer | 6210 | (cons 'pop-up-frame-function pop-up-frame-function)) |
| 3943 | ;; is visible. | 6211 | (when pop-up-frame-alist |
| 3944 | (and (minibuffer-window-active-p (selected-window)) | 6212 | (cons 'pop-up-frame-alist pop-up-frame-alist))) |
| 3945 | (eq frame (window-frame (minibuffer-selected-window))))) | 6213 | no-custom) |
| 3946 | (raise-frame frame)) | 6214 | |
| 3947 | window)) | 6215 | ;; `special-display-regexps' |
| 3948 | 6216 | (dolist (entry special-display-regexps) | |
| 3949 | (defun window--display-buffer-2 (buffer window &optional dedicated) | 6217 | (cond |
| 3950 | "Display BUFFER in WINDOW and make its frame visible. | 6218 | ((stringp entry) |
| 3951 | Set `window-dedicated-p' to DEDICATED if non-nil. | 6219 | ;; Plain string. |
| 3952 | Return WINDOW." | 6220 | (display-buffer-alist-add |
| 3953 | (when (and (buffer-live-p buffer) (window-live-p window)) | 6221 | `((regexp . ,entry)) |
| 3954 | (set-window-buffer window buffer) | 6222 | (list |
| 3955 | (when dedicated | 6223 | 'fun-with-args |
| 3956 | (set-window-dedicated-p window dedicated)) | 6224 | (list 'fun-with-args special-display-function |
| 3957 | (window--display-buffer-1 window))) | 6225 | special-display-frame-alist)) |
| 3958 | 6226 | no-custom)) | |
| 3959 | (defvar display-buffer-mark-dedicated nil | 6227 | ((consp entry) |
| 3960 | "If non-nil, `display-buffer' marks the windows it creates as dedicated. | 6228 | (let ((name (car entry)) |
| 3961 | The actual non-nil value of this variable will be copied to the | 6229 | (rest (cdr entry))) |
| 3962 | `window-dedicated-p' flag.") | 6230 | (cond |
| 3963 | 6231 | ((functionp (car rest)) | |
| 3964 | (defun display-buffer (buffer-or-name &optional not-this-window frame) | 6232 | ;; A function. |
| 3965 | "Make buffer BUFFER-OR-NAME appear in some window but don't select it. | 6233 | (display-buffer-alist-add |
| 3966 | BUFFER-OR-NAME must be a buffer or the name of an existing | 6234 | `((name . ,name)) |
| 3967 | buffer. Return the window chosen to display BUFFER-OR-NAME or | 6235 | (list |
| 3968 | nil if no such window is found. | 6236 | 'fun-with-args |
| 3969 | 6237 | ;; Weary. | |
| 3970 | Optional argument NOT-THIS-WINDOW non-nil means display the | 6238 | (list 'fun-with-args (car rest) (cadr rest))) |
| 3971 | buffer in a window other than the selected one, even if it is | 6239 | no-custom)) |
| 3972 | already displayed in the selected window. | 6240 | ((listp rest) |
| 3973 | 6241 | ;; A list of parameters. | |
| 3974 | Optional argument FRAME specifies which frames to investigate | 6242 | (cond |
| 3975 | when the specified buffer is already displayed. If the buffer is | 6243 | ((assq 'same-window rest) |
| 3976 | already displayed in some window on one of these frames simply | 6244 | (display-buffer-alist-add |
| 3977 | return that window. Possible values of FRAME are: | 6245 | `((name . ,name)) |
| 3978 | 6246 | (list 'reuse-window | |
| 3979 | `visible' - consider windows on all visible frames on the current | 6247 | (list 'reuse-window 'same) |
| 3980 | terminal. | 6248 | (list 'reuse-window-dedicated 'weak)) |
| 3981 | 6249 | no-custom)) | |
| 3982 | 0 - consider windows on all visible or iconified frames on the | 6250 | ((assq 'same-frame rest) |
| 3983 | current terminal. | 6251 | (display-buffer-alist-add |
| 3984 | 6252 | `((name . ,name)) (list 'same-frame) no-custom)) | |
| 3985 | t - consider windows on all frames. | 6253 | (t |
| 3986 | 6254 | (display-buffer-alist-add | |
| 3987 | A specific frame - consider windows on that frame only. | 6255 | `((name . ,name)) |
| 3988 | 6256 | (list | |
| 3989 | nil - consider windows on the selected frame \(actually the | 6257 | 'fun-with-args |
| 3990 | last non-minibuffer frame\) only. If, however, either | 6258 | (list 'fun-with-args special-display-function |
| 3991 | `display-buffer-reuse-frames' or `pop-up-frames' is non-nil | 6259 | special-display-frame-alist)) |
| 3992 | \(non-nil and not graphic-only on a text-only terminal), | 6260 | no-custom))))))))) |
| 3993 | consider all visible or iconified frames on the current terminal." | 6261 | |
| 3994 | (interactive "BDisplay buffer:\nP") | 6262 | ;; `special-display-buffer-names' |
| 3995 | (let* ((can-use-selected-window | 6263 | (dolist (entry special-display-buffer-names) |
| 3996 | ;; The selected window is usable unless either NOT-THIS-WINDOW | 6264 | (cond |
| 3997 | ;; is non-nil, it is dedicated to its buffer, or it is the | 6265 | ((stringp entry) |
| 3998 | ;; `minibuffer-window'. | 6266 | ;; Plain string. |
| 3999 | (not (or not-this-window | 6267 | (display-buffer-alist-add |
| 4000 | (window-dedicated-p (selected-window)) | 6268 | `((name . ,entry)) |
| 4001 | (window-minibuffer-p)))) | 6269 | (list |
| 4002 | (buffer (if (bufferp buffer-or-name) | 6270 | 'fun-with-args |
| 4003 | buffer-or-name | 6271 | (list 'fun-with-args special-display-function |
| 4004 | (get-buffer buffer-or-name))) | 6272 | special-display-frame-alist)) |
| 4005 | (name-of-buffer (buffer-name buffer)) | 6273 | no-custom)) |
| 4006 | ;; On text-only terminals do not pop up a new frame when | 6274 | ((consp entry) |
| 4007 | ;; `pop-up-frames' equals graphic-only. | 6275 | (let ((name (car entry)) |
| 4008 | (use-pop-up-frames (if (eq pop-up-frames 'graphic-only) | 6276 | (rest (cdr entry))) |
| 4009 | (display-graphic-p) | 6277 | (cond |
| 4010 | pop-up-frames)) | 6278 | ((functionp (car rest)) |
| 4011 | ;; `frame-to-use' is the frame where to show `buffer' - either | 6279 | ;; A function. |
| 4012 | ;; the selected frame or the last nonminibuffer frame. | 6280 | (display-buffer-alist-add |
| 4013 | (frame-to-use | 6281 | `((name . ,name)) |
| 4014 | (or (window--frame-usable-p (selected-frame)) | 6282 | (list |
| 4015 | (window--frame-usable-p (last-nonminibuffer-frame)))) | 6283 | 'fun-with-args |
| 4016 | ;; `window-to-use' is the window we use for showing `buffer'. | 6284 | ;; Weary. |
| 4017 | window-to-use) | 6285 | (list 'fun-with-args (car rest) (cadr rest))) |
| 4018 | (cond | 6286 | no-custom)) |
| 4019 | ((not (buffer-live-p buffer)) | 6287 | ((listp rest) |
| 4020 | (error "No such buffer %s" buffer)) | 6288 | ;; A list of parameters. |
| 4021 | (display-buffer-function | 6289 | (cond |
| 4022 | ;; Let `display-buffer-function' do the job. | 6290 | ((assq 'same-window rest) |
| 4023 | (funcall display-buffer-function buffer not-this-window)) | 6291 | (display-buffer-alist-add |
| 4024 | ((and (not not-this-window) | 6292 | `((name . ,name)) |
| 4025 | (eq (window-buffer (selected-window)) buffer)) | 6293 | (list 'reuse-window |
| 4026 | ;; The selected window already displays BUFFER and | 6294 | (list 'reuse-window 'same) |
| 4027 | ;; `not-this-window' is nil, so use it. | 6295 | (list 'reuse-window-dedicated 'weak)) |
| 4028 | (window--display-buffer-1 (selected-window))) | 6296 | no-custom)) |
| 4029 | ((and can-use-selected-window (same-window-p name-of-buffer)) | 6297 | ((assq 'same-frame rest) |
| 4030 | ;; If the buffer's name tells us to use the selected window do so. | 6298 | (display-buffer-alist-add |
| 4031 | (window--display-buffer-2 buffer (selected-window))) | 6299 | `((name . ,name)) (list 'same-frame) no-custom)) |
| 4032 | ((let ((frames (or frame | 6300 | (t |
| 4033 | (and (or use-pop-up-frames | 6301 | (display-buffer-alist-add |
| 4034 | display-buffer-reuse-frames | 6302 | `((name . ,name)) |
| 4035 | (not (last-nonminibuffer-frame))) | 6303 | (list |
| 4036 | 0) | 6304 | 'fun-with-args |
| 4037 | (last-nonminibuffer-frame)))) | 6305 | (list 'fun-with-args special-display-function |
| 4038 | (setq window-to-use | 6306 | special-display-frame-alist)) |
| 4039 | (catch 'found | 6307 | no-custom))))))))) |
| 4040 | ;; Search frames for a window displaying BUFFER. Return | 6308 | |
| 4041 | ;; the selected window only if we are allowed to do so. | 6309 | ;; `same-window-regexps' |
| 4042 | (dolist (window (get-buffer-window-list buffer 'nomini frames)) | 6310 | (dolist (entry same-window-regexps) |
| 4043 | (when (or can-use-selected-window | 6311 | (cond |
| 4044 | (not (eq (selected-window) window))) | 6312 | ((stringp entry) |
| 4045 | (throw 'found window)))))) | 6313 | (display-buffer-alist-add |
| 4046 | ;; The buffer is already displayed in some window; use that. | 6314 | `((regexp . ,entry)) |
| 4047 | (window--display-buffer-1 window-to-use)) | 6315 | (list 'reuse-window (list 'reuse-window 'same)) |
| 4048 | ((and special-display-function | 6316 | no-custom)) |
| 4049 | ;; `special-display-p' returns either t or a list of frame | 6317 | ((consp entry) |
| 4050 | ;; parameters to pass to `special-display-function'. | 6318 | (display-buffer-alist-add |
| 4051 | (let ((pars (special-display-p name-of-buffer))) | 6319 | `((regexp . ,(car entry))) |
| 4052 | (when pars | 6320 | (list 'reuse-window (list 'reuse-window 'same)) |
| 4053 | (funcall special-display-function | 6321 | no-custom)))) |
| 4054 | buffer (if (listp pars) pars)))))) | 6322 | |
| 4055 | ((or use-pop-up-frames (not frame-to-use)) | 6323 | ;; `same-window-buffer-names' |
| 4056 | ;; We want or need a new frame. | 6324 | (dolist (entry same-window-buffer-names) |
| 4057 | (let ((win (frame-selected-window (funcall pop-up-frame-function)))) | 6325 | (cond |
| 4058 | (window--display-buffer-2 buffer win display-buffer-mark-dedicated))) | 6326 | ((stringp entry) |
| 4059 | ((and pop-up-windows | 6327 | (display-buffer-alist-add |
| 4060 | ;; Make a new window. | 6328 | `((name . ,entry)) |
| 4061 | (or (not (frame-parameter frame-to-use 'unsplittable)) | 6329 | (list 'reuse-window (list 'reuse-window 'same)) |
| 4062 | ;; If the selected frame cannot be split look at | 6330 | no-custom)) |
| 4063 | ;; `last-nonminibuffer-frame'. | 6331 | ((consp entry) |
| 4064 | (and (eq frame-to-use (selected-frame)) | 6332 | (display-buffer-alist-add |
| 4065 | (setq frame-to-use (last-nonminibuffer-frame)) | 6333 | `((name . ,(car entry))) |
| 4066 | (window--frame-usable-p frame-to-use) | 6334 | (list 'reuse-window (list 'reuse-window 'same)) |
| 4067 | (not (frame-parameter frame-to-use 'unsplittable)))) | 6335 | no-custom)))) |
| 4068 | ;; Attempt to split largest or least recently used window. | 6336 | |
| 4069 | (setq window-to-use | 6337 | ;; `reuse-window' |
| 4070 | (or (window--try-to-split-window | 6338 | (display-buffer-alist-add |
| 4071 | (get-largest-window frame-to-use t)) | 6339 | nil |
| 4072 | (window--try-to-split-window | 6340 | (list |
| 4073 | (get-lru-window frame-to-use t))))) | 6341 | 'reuse-window |
| 4074 | (window--display-buffer-2 buffer window-to-use | 6342 | (list 'reuse-window nil 'same |
| 4075 | display-buffer-mark-dedicated)) | 6343 | (unless (and (memq display-buffer-reuse-frames '(nil unset)) |
| 4076 | ((let ((window-to-undedicate | 6344 | (memq pop-up-frames '(nil unset))) |
| 4077 | ;; When NOT-THIS-WINDOW is non-nil, temporarily dedicate | 6345 | ;; "0" (all visible and iconified frames) is hardcoded in |
| 4078 | ;; the selected window to its buffer, to avoid that some of | 6346 | ;; Emacs 23. |
| 4079 | ;; the `get-' routines below choose it. (Bug#1415) | 6347 | 0)) |
| 4080 | (and not-this-window (not (window-dedicated-p)) | 6348 | (when even-window-heights |
| 4081 | (set-window-dedicated-p (selected-window) t) | 6349 | (cons 'reuse-window-even-sizes t))) |
| 4082 | (selected-window)))) | 6350 | no-custom) |
| 4083 | (unwind-protect | 6351 | |
| 4084 | (setq window-to-use | 6352 | ;; `display-buffer-mark-dedicated' |
| 4085 | ;; Reuse an existing window. | 6353 | (unless (memq display-buffer-mark-dedicated '(nil unset)) |
| 4086 | (or (get-lru-window frame-to-use) | 6354 | (display-buffer-alist-add |
| 4087 | (let ((window (get-buffer-window buffer 'visible))) | 6355 | nil |
| 4088 | (unless (and not-this-window | 6356 | (list |
| 4089 | (eq window (selected-window))) | 6357 | (cons 'dedicated display-buffer-mark-dedicated)) |
| 4090 | window)) | 6358 | no-custom))) |
| 4091 | (get-largest-window 'visible) | 6359 | |
| 4092 | (let ((window (get-buffer-window buffer 0))) | 6360 | display-buffer-alist) |
| 4093 | (unless (and not-this-window | ||
| 4094 | (eq window (selected-window))) | ||
| 4095 | window)) | ||
| 4096 | (get-largest-window 0) | ||
| 4097 | (frame-selected-window (funcall pop-up-frame-function)))) | ||
| 4098 | (when (window-live-p window-to-undedicate) | ||
| 4099 | ;; Restore dedicated status of selected window. | ||
| 4100 | (set-window-dedicated-p window-to-undedicate nil)))) | ||
| 4101 | (window--even-window-heights window-to-use) | ||
| 4102 | (window--display-buffer-2 buffer window-to-use))))) | ||
| 4103 | |||
| 4104 | (defun display-buffer-other-frame (buffer) | ||
| 4105 | "Display buffer BUFFER in another frame. | ||
| 4106 | This uses the function `display-buffer' as a subroutine; see | ||
| 4107 | its documentation for additional customization information." | ||
| 4108 | (interactive "BDisplay buffer in other frame: ") | ||
| 4109 | (let ((pop-up-frames t) | ||
| 4110 | same-window-buffer-names same-window-regexps | ||
| 4111 | ;;(old-window (selected-window)) | ||
| 4112 | new-window) | ||
| 4113 | (setq new-window (display-buffer buffer t)) | ||
| 4114 | ;; This may have been here in order to prevent the new frame from hiding | ||
| 4115 | ;; the old frame. But it does more harm than good. | ||
| 4116 | ;; Maybe we should call `raise-window' on the old-frame instead? --Stef | ||
| 4117 | ;;(lower-frame (window-frame new-window)) | ||
| 4118 | |||
| 4119 | ;; This may have been here in order to make sure the old-frame gets the | ||
| 4120 | ;; focus. But not only can it cause an annoying flicker, with some | ||
| 4121 | ;; window-managers it just makes the window invisible, with no easy | ||
| 4122 | ;; way to recover it. --Stef | ||
| 4123 | ;;(make-frame-invisible (window-frame old-window)) | ||
| 4124 | ;;(make-frame-visible (window-frame old-window)) | ||
| 4125 | )) | ||
| 4126 | |||
| 4127 | (defun pop-to-buffer (buffer-or-name &optional other-window norecord) | ||
| 4128 | "Select buffer BUFFER-OR-NAME in some window, preferably a different one. | ||
| 4129 | BUFFER-OR-NAME may be a buffer, a string \(a buffer name), or | ||
| 4130 | nil. If BUFFER-OR-NAME is a string not naming an existent | ||
| 4131 | buffer, create a buffer with that name. If BUFFER-OR-NAME is | ||
| 4132 | nil, choose some other buffer. | ||
| 4133 | |||
| 4134 | If `pop-up-windows' is non-nil, windows can be split to display | ||
| 4135 | the buffer. If optional second arg OTHER-WINDOW is non-nil, | ||
| 4136 | insist on finding another window even if the specified buffer is | ||
| 4137 | already visible in the selected window, and ignore | ||
| 4138 | `same-window-regexps' and `same-window-buffer-names'. | ||
| 4139 | |||
| 4140 | If the window to show BUFFER-OR-NAME is not on the selected | ||
| 4141 | frame, raise that window's frame and give it input focus. | ||
| 4142 | |||
| 4143 | This function returns the buffer it switched to. This uses the | ||
| 4144 | function `display-buffer' as a subroutine; see the documentation | ||
| 4145 | of `display-buffer' for additional customization information. | ||
| 4146 | |||
| 4147 | Optional third arg NORECORD non-nil means do not put this buffer | ||
| 4148 | at the front of the list of recently selected ones." | ||
| 4149 | (let ((buffer | ||
| 4150 | ;; FIXME: This behavior is carried over from the previous C version | ||
| 4151 | ;; of pop-to-buffer, but really we should use just | ||
| 4152 | ;; `get-buffer' here. | ||
| 4153 | (if (null buffer-or-name) (other-buffer (current-buffer)) | ||
| 4154 | (or (get-buffer buffer-or-name) | ||
| 4155 | (let ((buf (get-buffer-create buffer-or-name))) | ||
| 4156 | (set-buffer-major-mode buf) | ||
| 4157 | buf)))) | ||
| 4158 | (old-frame (selected-frame)) | ||
| 4159 | new-window new-frame) | ||
| 4160 | (set-buffer buffer) | ||
| 4161 | (setq new-window (display-buffer buffer other-window)) | ||
| 4162 | (select-window new-window norecord) | ||
| 4163 | (setq new-frame (window-frame new-window)) | ||
| 4164 | (unless (eq new-frame old-frame) | ||
| 4165 | ;; `display-buffer' has chosen another frame, make sure it gets | ||
| 4166 | ;; input focus and is risen. | ||
| 4167 | (select-frame-set-input-focus new-frame)) | ||
| 4168 | buffer)) | ||
| 4169 | |||
| 4170 | (defun read-buffer-to-switch (prompt) | ||
| 4171 | "Read the name of a buffer to switch to, prompting with PROMPT. | ||
| 4172 | Return the neame of the buffer as a string. | ||
| 4173 | |||
| 4174 | This function is intended for the `switch-to-buffer' family of | ||
| 4175 | commands since these need to omit the name of the current buffer | ||
| 4176 | from the list of completions and default values." | ||
| 4177 | (let ((rbts-completion-table (internal-complete-buffer-except))) | ||
| 4178 | (minibuffer-with-setup-hook | ||
| 4179 | (lambda () | ||
| 4180 | (setq minibuffer-completion-table rbts-completion-table) | ||
| 4181 | ;; Since rbts-completion-table is built dynamically, we | ||
| 4182 | ;; can't just add it to the default value of | ||
| 4183 | ;; icomplete-with-completion-tables, so we add it | ||
| 4184 | ;; here manually. | ||
| 4185 | (if (and (boundp 'icomplete-with-completion-tables) | ||
| 4186 | (listp icomplete-with-completion-tables)) | ||
| 4187 | (set (make-local-variable 'icomplete-with-completion-tables) | ||
| 4188 | (cons rbts-completion-table | ||
| 4189 | icomplete-with-completion-tables)))) | ||
| 4190 | (read-buffer prompt (other-buffer (current-buffer)) | ||
| 4191 | (confirm-nonexistent-file-or-buffer))))) | ||
| 4192 | |||
| 4193 | (defun normalize-buffer-to-switch-to (buffer-or-name) | ||
| 4194 | "Normalize BUFFER-OR-NAME argument of buffer switching functions. | ||
| 4195 | If BUFFER-OR-NAME is nil, return the buffer returned by | ||
| 4196 | `other-buffer'. Else, if a buffer specified by BUFFER-OR-NAME | ||
| 4197 | exists, return that buffer. If no such buffer exists, create a | ||
| 4198 | buffer with the name BUFFER-OR-NAME and return that buffer." | ||
| 4199 | (if buffer-or-name | ||
| 4200 | (or (get-buffer buffer-or-name) | ||
| 4201 | (let ((buffer (get-buffer-create buffer-or-name))) | ||
| 4202 | (set-buffer-major-mode buffer) | ||
| 4203 | buffer)) | ||
| 4204 | (other-buffer))) | ||
| 4205 | |||
| 4206 | (defun switch-to-buffer (buffer-or-name &optional norecord) | ||
| 4207 | "Switch to buffer BUFFER-OR-NAME in the selected window. | ||
| 4208 | If called interactively, prompt for the buffer name using the | ||
| 4209 | minibuffer. The variable `confirm-nonexistent-file-or-buffer' | ||
| 4210 | determines whether to request confirmation before creating a new | ||
| 4211 | buffer. | ||
| 4212 | |||
| 4213 | BUFFER-OR-NAME may be a buffer, a string \(a buffer name), or | ||
| 4214 | nil. If BUFFER-OR-NAME is a string that does not identify an | ||
| 4215 | existing buffer, create a buffer with that name. If | ||
| 4216 | BUFFER-OR-NAME is nil, switch to the buffer returned by | ||
| 4217 | `other-buffer'. | ||
| 4218 | |||
| 4219 | Optional argument NORECORD non-nil means do not put the buffer | ||
| 4220 | specified by BUFFER-OR-NAME at the front of the buffer list and | ||
| 4221 | do not make the window displaying it the most recently selected | ||
| 4222 | one. Return the buffer switched to. | ||
| 4223 | |||
| 4224 | This function is intended for interactive use only. Lisp | ||
| 4225 | functions should call `pop-to-buffer-same-window' instead." | ||
| 4226 | (interactive | ||
| 4227 | (list (read-buffer-to-switch "Switch to buffer: "))) | ||
| 4228 | (let ((buffer (normalize-buffer-to-switch-to buffer-or-name))) | ||
| 4229 | (if (and (or (window-minibuffer-p) (eq (window-dedicated-p) t)) | ||
| 4230 | (not (eq buffer (window-buffer)))) | ||
| 4231 | ;; Cannot switch to another buffer in a minibuffer or strongly | ||
| 4232 | ;; dedicated window that does not show the buffer already. Call | ||
| 4233 | ;; `pop-to-buffer' instead. | ||
| 4234 | (pop-to-buffer buffer nil norecord) | ||
| 4235 | (unless (eq buffer (window-buffer)) | ||
| 4236 | ;; I'm not sure why we should NOT call `set-window-buffer' here, | ||
| 4237 | ;; but let's keep things as they are (otherwise we could always | ||
| 4238 | ;; call `pop-to-buffer-same-window' here). | ||
| 4239 | (set-window-buffer nil buffer)) | ||
| 4240 | (unless norecord | ||
| 4241 | (select-window (selected-window))) | ||
| 4242 | (set-buffer buffer)))) | ||
| 4243 | |||
| 4244 | (defun switch-to-buffer-other-window (buffer-or-name &optional norecord) | ||
| 4245 | "Select the buffer specified by BUFFER-OR-NAME in another window. | ||
| 4246 | BUFFER-OR-NAME may be a buffer, a string \(a buffer name), or | ||
| 4247 | nil. Return the buffer switched to. | ||
| 4248 | |||
| 4249 | If called interactively, prompt for the buffer name using the | ||
| 4250 | minibuffer. The variable `confirm-nonexistent-file-or-buffer' | ||
| 4251 | determines whether to request confirmation before creating a new | ||
| 4252 | buffer. | ||
| 4253 | |||
| 4254 | If BUFFER-OR-NAME is a string and does not identify an existing | ||
| 4255 | buffer, create a new buffer with that name. If BUFFER-OR-NAME is | ||
| 4256 | nil, switch to the buffer returned by `other-buffer'. | ||
| 4257 | |||
| 4258 | Optional second argument NORECORD non-nil means do not put this | ||
| 4259 | buffer at the front of the list of recently selected ones. | ||
| 4260 | |||
| 4261 | This uses the function `display-buffer' as a subroutine; see its | ||
| 4262 | documentation for additional customization information." | ||
| 4263 | (interactive | ||
| 4264 | (list (read-buffer-to-switch "Switch to buffer in other window: "))) | ||
| 4265 | (let ((pop-up-windows t) | ||
| 4266 | same-window-buffer-names same-window-regexps) | ||
| 4267 | (pop-to-buffer buffer-or-name t norecord))) | ||
| 4268 | |||
| 4269 | (defun switch-to-buffer-other-frame (buffer-or-name &optional norecord) | ||
| 4270 | "Switch to buffer BUFFER-OR-NAME in another frame. | ||
| 4271 | BUFFER-OR-NAME may be a buffer, a string \(a buffer name), or | ||
| 4272 | nil. Return the buffer switched to. | ||
| 4273 | |||
| 4274 | If called interactively, prompt for the buffer name using the | ||
| 4275 | minibuffer. The variable `confirm-nonexistent-file-or-buffer' | ||
| 4276 | determines whether to request confirmation before creating a new | ||
| 4277 | buffer. | ||
| 4278 | |||
| 4279 | If BUFFER-OR-NAME is a string and does not identify an existing | ||
| 4280 | buffer, create a new buffer with that name. If BUFFER-OR-NAME is | ||
| 4281 | nil, switch to the buffer returned by `other-buffer'. | ||
| 4282 | |||
| 4283 | Optional second arg NORECORD non-nil means do not put this | ||
| 4284 | buffer at the front of the list of recently selected ones. | ||
| 4285 | |||
| 4286 | This uses the function `display-buffer' as a subroutine; see its | ||
| 4287 | documentation for additional customization information." | ||
| 4288 | (interactive | ||
| 4289 | (list (read-buffer-to-switch "Switch to buffer in other frame: "))) | ||
| 4290 | (let ((pop-up-frames t) | ||
| 4291 | same-window-buffer-names same-window-regexps) | ||
| 4292 | (pop-to-buffer buffer-or-name t norecord))) | ||
| 4293 | 6361 | ||
| 4294 | (defun set-window-text-height (window height) | 6362 | (defun set-window-text-height (window height) |
| 4295 | "Set the height in lines of the text display area of WINDOW to HEIGHT. | 6363 | "Set the height in lines of the text display area of WINDOW to HEIGHT. |