diff options
| author | Martin Rudalics | 2008-06-08 13:02:38 +0000 |
|---|---|---|
| committer | Martin Rudalics | 2008-06-08 13:02:38 +0000 |
| commit | 2bd0c2e02fb6aa129aff58ed78ad428d77f364ce (patch) | |
| tree | 100c3ea57c64b0aef01f403f84ee79b15d2e4ef2 /lisp | |
| parent | 8f440b79a5f0f17320320384ba77655119014e60 (diff) | |
| download | emacs-2bd0c2e02fb6aa129aff58ed78ad428d77f364ce.tar.gz emacs-2bd0c2e02fb6aa129aff58ed78ad428d77f364ce.zip | |
(split-height-threshold, split-width-threshold): Add
choice nil.
(split-window-preferred-function): Allow either nil or a function.
(window--splittable-p, window--try-to-split-window): Handle
changed option values.
(window--frame-usable-p): Handle nil argument.
(display-buffer): Call get-lru-window when pop-up-windows is nil
and window can't be split.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/ChangeLog | 13 | ||||
| -rw-r--r-- | lisp/window.el | 159 |
2 files changed, 97 insertions, 75 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 3cef51e02d8..ae82adca289 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,16 @@ | |||
| 1 | 2008-06-08 Martin Rudalics <rudalics@gmx.at> | ||
| 2 | |||
| 3 | * window.el (split-height-threshold, split-width-threshold): Add | ||
| 4 | choice nil. | ||
| 5 | (split-window-preferred-function): Allow either nil or a function. | ||
| 6 | (window--splittable-p, window--try-to-split-window): Handle | ||
| 7 | changed option values. | ||
| 8 | |||
| 9 | (window--frame-usable-p): Handle nil argument. | ||
| 10 | |||
| 11 | (display-buffer): Call get-lru-window when pop-up-windows is nil | ||
| 12 | and window can't be split. | ||
| 13 | |||
| 1 | 2008-06-08 Michael Albinus <michael.albinus@gmx.de> | 14 | 2008-06-08 Michael Albinus <michael.albinus@gmx.de> |
| 2 | 15 | ||
| 3 | * uniquify.el (uniquify-get-proposed-name): Handle remote files. | 16 | * uniquify.el (uniquify-get-proposed-name): Handle remote files. |
diff --git a/lisp/window.el b/lisp/window.el index 74bcdcdaef1..74c7a366f0f 100644 --- a/lisp/window.el +++ b/lisp/window.el | |||
| @@ -544,19 +544,19 @@ would be used to make a frame for that buffer. The variables | |||
| 544 | `special-display-buffer-names' and `special-display-regexps' | 544 | `special-display-buffer-names' and `special-display-regexps' |
| 545 | control this." | 545 | control this." |
| 546 | (let (tmp) | 546 | (let (tmp) |
| 547 | (cond | 547 | (cond |
| 548 | ((not (stringp buffer-name))) | 548 | ((not (stringp buffer-name))) |
| 549 | ;; Make sure to return t in the following two cases. | 549 | ;; Make sure to return t in the following two cases. |
| 550 | ((member buffer-name special-display-buffer-names) t) | 550 | ((member buffer-name special-display-buffer-names) t) |
| 551 | ((setq tmp (assoc buffer-name special-display-buffer-names)) (cdr tmp)) | 551 | ((setq tmp (assoc buffer-name special-display-buffer-names)) (cdr tmp)) |
| 552 | ((catch 'found | 552 | ((catch 'found |
| 553 | (dolist (regexp special-display-regexps) | 553 | (dolist (regexp special-display-regexps) |
| 554 | (cond | 554 | (cond |
| 555 | ((stringp regexp) | 555 | ((stringp regexp) |
| 556 | (when (string-match-p regexp buffer-name) | 556 | (when (string-match-p regexp buffer-name) |
| 557 | (throw 'found t))) | 557 | (throw 'found t))) |
| 558 | ((and (consp regexp) (stringp (car regexp)) | 558 | ((and (consp regexp) (stringp (car regexp)) |
| 559 | (string-match-p (car regexp) buffer-name)) | 559 | (string-match-p (car regexp) buffer-name)) |
| 560 | (throw 'found (cdr regexp)))))))))) | 560 | (throw 'found (cdr regexp)))))))))) |
| 561 | 561 | ||
| 562 | (defcustom special-display-buffer-names nil | 562 | (defcustom special-display-buffer-names nil |
| @@ -742,32 +742,37 @@ parameters." | |||
| 742 | :type 'boolean | 742 | :type 'boolean |
| 743 | :group 'windows) | 743 | :group 'windows) |
| 744 | 744 | ||
| 745 | (defcustom split-window-preferred-function nil | ||
| 746 | "How `display-buffer' shall split windows. | ||
| 747 | Choices are `Vertically', `Horizontally', and `Sensibly' where | ||
| 748 | the latter attempts to split wide windows horizontally, narrow | ||
| 749 | ones vertically. Alternatively, you can set this to a function | ||
| 750 | called with a window as single argument to split that window in | ||
| 751 | two and return the new window." | ||
| 752 | :type '(choice | ||
| 753 | (const :tag "Vertically" nil) | ||
| 754 | (const :tag "Horizontally" horizontally) | ||
| 755 | (const :tag "Sensibly" sensibly) | ||
| 756 | (function :tag "Function")) | ||
| 757 | :version "23.1" | ||
| 758 | :group 'windows) | ||
| 759 | |||
| 760 | (defcustom split-height-threshold 80 | 745 | (defcustom split-height-threshold 80 |
| 761 | "Minimum height of window to be split vertically by `display-buffer'. | 746 | "Minimum height of window to be split vertically. |
| 762 | If there is only one window, it can be split regardless of this." | 747 | If the value is a number, `display-buffer' can split a window |
| 748 | only if it has at least as many lines. If the value is nil, | ||
| 749 | `display-buffer' cannot split a window vertically. | ||
| 750 | |||
| 751 | If the window is the only window on its frame, `display-buffer' | ||
| 752 | can split it regardless of this value." | ||
| 753 | :type '(choice (const nil) (number :tag "lines")) | ||
| 763 | :type 'number | 754 | :type 'number |
| 764 | :version "23.1" | 755 | :version "23.1" |
| 765 | :group 'windows) | 756 | :group 'windows) |
| 766 | 757 | ||
| 767 | (defcustom split-width-threshold 160 | 758 | (defcustom split-width-threshold 160 |
| 768 | "Minimum width of window to be split horizontally by `display-buffer'. | 759 | "Minimum width of window to be split horizontally. |
| 769 | If there is only one window, it can be split regardless of this." | 760 | If the value is a number, `display-buffer' can split a window |
| 770 | :type 'number | 761 | only if it has at least as many columns. If the value is nil, |
| 762 | `display-buffer' cannot split a window horizontally." | ||
| 763 | :type '(choice (const nil) (number :tag "columns")) | ||
| 764 | :version "23.1" | ||
| 765 | :group 'windows) | ||
| 766 | |||
| 767 | (defcustom split-window-preferred-function nil | ||
| 768 | "Function used by `display-buffer' to split windows. | ||
| 769 | If non-nil, a function called with a window as single argument | ||
| 770 | supposed to split that window and return the new window. If the | ||
| 771 | function returns nil the window is not split. | ||
| 772 | |||
| 773 | If nil, `display-buffer' will split the window respecting the | ||
| 774 | values of `split-height-threshold' and `split-width-threshold'." | ||
| 775 | :type '(choice (const nil) (function :tag "Function")) | ||
| 771 | :version "23.1" | 776 | :version "23.1" |
| 772 | :group 'windows) | 777 | :group 'windows) |
| 773 | 778 | ||
| @@ -779,11 +784,11 @@ can be split horizontally. | |||
| 779 | WINDOW can be split vertically when the following conditions | 784 | WINDOW can be split vertically when the following conditions |
| 780 | hold: | 785 | hold: |
| 781 | 786 | ||
| 782 | - `window-size-fixed' is either nil or equals `width' for the buffer of | 787 | - `window-size-fixed' is either nil or equals `width' for the |
| 783 | WINDOW. | 788 | buffer of WINDOW. |
| 784 | 789 | ||
| 785 | - WINDOW is at least as high as `split-height-threshold' or it is | 790 | - `split-height-threshold' is a number and WINDOW is at least as |
| 786 | the only window on its frame. | 791 | high as `split-height-threshold'. |
| 787 | 792 | ||
| 788 | - When WINDOW is split evenly, the emanating windows are at least | 793 | - When WINDOW is split evenly, the emanating windows are at least |
| 789 | `window-min-height' lines tall and can accomodate at least one | 794 | `window-min-height' lines tall and can accomodate at least one |
| @@ -795,7 +800,8 @@ hold: | |||
| 795 | - `window-size-fixed' is either nil or equals `height' for the | 800 | - `window-size-fixed' is either nil or equals `height' for the |
| 796 | buffer of WINDOW. | 801 | buffer of WINDOW. |
| 797 | 802 | ||
| 798 | - WINDOW is at least as wide as `split-width-threshold'. | 803 | - `split-width-threshold' is a number and WINDOW is at least as |
| 804 | wide as `split-width-threshold'. | ||
| 799 | 805 | ||
| 800 | - When WINDOW is split evenly, the emanating windows are at least | 806 | - When WINDOW is split evenly, the emanating windows are at least |
| 801 | `window-min-width' or two (whichever is larger) columns wide." | 807 | `window-min-width' or two (whichever is larger) columns wide." |
| @@ -807,57 +813,60 @@ hold: | |||
| 807 | ;; and at least twice as wide as `window-min-width' and 2 (the | 813 | ;; and at least twice as wide as `window-min-width' and 2 (the |
| 808 | ;; latter value is hardcoded). | 814 | ;; latter value is hardcoded). |
| 809 | (and (memq window-size-fixed '(nil height)) | 815 | (and (memq window-size-fixed '(nil height)) |
| 816 | ;; Testing `window-full-width-p' here hardly makes any | ||
| 817 | ;; sense nowadays. This can be done more intuitively by | ||
| 818 | ;; setting up `split-width-threshold' appropriately. | ||
| 819 | (numberp split-width-threshold) | ||
| 810 | (>= (window-width window) | 820 | (>= (window-width window) |
| 811 | (max split-width-threshold | 821 | (max split-width-threshold |
| 812 | (* 2 (max window-min-width 2))))) | 822 | (* 2 (max window-min-width 2))))) |
| 813 | ;; A window can be split vertically when its height is not | 823 | ;; A window can be split vertically when its height is not |
| 814 | ;; fixed, it is at least `split-height-threshold' lines high or | 824 | ;; fixed, it is at least `split-height-threshold' lines high, |
| 815 | ;; the only window on its frame, and it is at least twice as | 825 | ;; and it is at least twice as high as `window-min-height' and 2 |
| 816 | ;; high as `window-min-height' and 2 if it has a modeline or 1. | 826 | ;; if it has a modeline or 1. |
| 817 | (and (memq window-size-fixed '(nil width)) | 827 | (and (memq window-size-fixed '(nil width)) |
| 828 | (numberp split-height-threshold) | ||
| 818 | (>= (window-height window) | 829 | (>= (window-height window) |
| 819 | (max (if (one-window-p 'nomini) 0 split-height-threshold) | 830 | (max split-height-threshold |
| 820 | (* 2 (max window-min-height | 831 | (* 2 (max window-min-height |
| 821 | (if mode-line-format 2 1)))))))))) | 832 | (if mode-line-format 2 1)))))))))) |
| 822 | 833 | ||
| 823 | (defun window--try-to-split-window (window) | 834 | (defun window--try-to-split-window (window) |
| 824 | "Split window WINDOW if it is splittable. | 835 | "Split window WINDOW if it is splittable. |
| 825 | See `split-window-preferred-function' for how WINDOW shall be | 836 | See `window--splittable-p' for how to determine whether a window |
| 826 | split. See `window--splittable-p' for how to determine whether a | 837 | is splittable. If WINDOW can be split, return the value returned |
| 827 | window is splittable. If WINDOW can be split, return the value | 838 | by `split-window' or `split-window-preferred-function'." |
| 828 | returned by `split-window' or `split-window-preferred-function'." | ||
| 829 | (when (and (window-live-p window) | 839 | (when (and (window-live-p window) |
| 830 | ;; Testing `window-full-width-p' here hardly makes any | ||
| 831 | ;; sense nowadays. This can be done more intuitively by | ||
| 832 | ;; setting up `split-width-threshold' appropriately. | ||
| 833 | (not (frame-parameter (window-frame window) 'unsplittable))) | 840 | (not (frame-parameter (window-frame window) 'unsplittable))) |
| 834 | (or (and (not split-window-preferred-function) | 841 | (if (functionp split-window-preferred-function) |
| 835 | (window--splittable-p window) | 842 | ;; `split-window-preferred-function' is specified, so use it. |
| 836 | (split-window window)) | 843 | (funcall split-window-preferred-function window) |
| 837 | (and (eq split-window-preferred-function 'horizontally) | 844 | (or (and (window--splittable-p window) |
| 838 | (window--splittable-p window t) | 845 | ;; Split window vertically. |
| 839 | (split-window window nil t)) | 846 | (split-window window)) |
| 840 | (and (eq split-window-preferred-function 'sensibly) | 847 | (and (window--splittable-p window t) |
| 841 | ;; The following naive aspect-ratio test should become | 848 | ;; Split window horizontally. |
| 842 | ;; more sensible. | 849 | (split-window window nil t)) |
| 843 | (or (and (> (window-width window) (window-height window)) | 850 | (and (with-selected-window window |
| 844 | (window--splittable-p window t) | 851 | (one-window-p 'nomini)) |
| 845 | (split-window window nil t)) | 852 | ;; If WINDOW is the only window on its frame, attempt to |
| 846 | (and (window--splittable-p window) | 853 | ;; split it vertically disregarding the current value of |
| 847 | (split-window window)))) | 854 | ;; `split-height-threshold'. |
| 848 | (and (functionp split-window-preferred-function) | 855 | (let ((split-height-threshold 0)) |
| 849 | (funcall split-window-preferred-function window))))) | 856 | (window--splittable-p window) |
| 857 | (split-window window))))))) | ||
| 850 | 858 | ||
| 851 | (defun window--frame-usable-p (frame) | 859 | (defun window--frame-usable-p (frame) |
| 852 | "Return frame FRAME if it can be used to display another buffer." | 860 | "Return frame FRAME if it can be used to display another buffer." |
| 853 | (let ((window (frame-root-window frame))) | 861 | (when (framep frame) |
| 854 | ;; `frame-root-window' may be an internal window which is considered | 862 | (let ((window (frame-root-window frame))) |
| 855 | ;; "dead" by `window-live-p'. Hence if `window' is not live we | 863 | ;; `frame-root-window' may be an internal window which is considered |
| 856 | ;; implicitly know that `frame' has a visible window we can use. | 864 | ;; "dead" by `window-live-p'. Hence if `window' is not live we |
| 857 | (when (or (not (window-live-p window)) | 865 | ;; implicitly know that `frame' has a visible window we can use. |
| 858 | (and (not (window-minibuffer-p window)) | 866 | (when (or (not (window-live-p window)) |
| 859 | (not (window-dedicated-p window)))) | 867 | (and (not (window-minibuffer-p window)) |
| 860 | frame))) | 868 | (not (window-dedicated-p window)))) |
| 869 | frame)))) | ||
| 861 | 870 | ||
| 862 | (defcustom even-window-heights t | 871 | (defcustom even-window-heights t |
| 863 | "If non-nil `display-buffer' will try to even window heights. | 872 | "If non-nil `display-buffer' will try to even window heights. |
| @@ -1009,12 +1018,12 @@ consider all visible or iconified frames." | |||
| 1009 | (or (window--try-to-split-window | 1018 | (or (window--try-to-split-window |
| 1010 | (get-largest-window frame-to-use t)) | 1019 | (get-largest-window frame-to-use t)) |
| 1011 | (window--try-to-split-window | 1020 | (window--try-to-split-window |
| 1012 | (get-lru-window frame-to-use t)) | 1021 | (get-lru-window frame-to-use t)))) |
| 1013 | (get-lru-window frame-to-use nil))) | ||
| 1014 | (window--display-buffer-2 buffer window-to-use))) | 1022 | (window--display-buffer-2 buffer window-to-use))) |
| 1015 | ((setq window-to-use | 1023 | ((setq window-to-use |
| 1016 | ;; Reuse an existing window. | 1024 | ;; Reuse an existing window. |
| 1017 | (or (get-buffer-window buffer 'visible) | 1025 | (or (get-lru-window frame-to-use) |
| 1026 | (get-buffer-window buffer 'visible) | ||
| 1018 | (get-largest-window 'visible nil) | 1027 | (get-largest-window 'visible nil) |
| 1019 | (get-buffer-window buffer 0) | 1028 | (get-buffer-window buffer 0) |
| 1020 | (get-largest-window 0 nil) | 1029 | (get-largest-window 0 nil) |