Commit 2bd0c2e0 authored by Martin Rudalics's avatar Martin Rudalics
Browse files

(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.
parent 8f440b79
2008-06-08 Martin Rudalics <rudalics@gmx.at>
* window.el (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.
2008-06-08 Michael Albinus <michael.albinus@gmx.de> 2008-06-08 Michael Albinus <michael.albinus@gmx.de>
* uniquify.el (uniquify-get-proposed-name): Handle remote files. * uniquify.el (uniquify-get-proposed-name): Handle remote files.
......
...@@ -544,19 +544,19 @@ would be used to make a frame for that buffer. The variables ...@@ -544,19 +544,19 @@ would be used to make a frame for that buffer. The variables
`special-display-buffer-names' and `special-display-regexps' `special-display-buffer-names' and `special-display-regexps'
control this." control this."
(let (tmp) (let (tmp)
(cond (cond
((not (stringp buffer-name))) ((not (stringp buffer-name)))
;; Make sure to return t in the following two cases. ;; Make sure to return t in the following two cases.
((member buffer-name special-display-buffer-names) t) ((member buffer-name special-display-buffer-names) t)
((setq tmp (assoc buffer-name special-display-buffer-names)) (cdr tmp)) ((setq tmp (assoc buffer-name special-display-buffer-names)) (cdr tmp))
((catch 'found ((catch 'found
(dolist (regexp special-display-regexps) (dolist (regexp special-display-regexps)
(cond (cond
((stringp regexp) ((stringp regexp)
(when (string-match-p regexp buffer-name) (when (string-match-p regexp buffer-name)
(throw 'found t))) (throw 'found t)))
((and (consp regexp) (stringp (car regexp)) ((and (consp regexp) (stringp (car regexp))
(string-match-p (car regexp) buffer-name)) (string-match-p (car regexp) buffer-name))
(throw 'found (cdr regexp)))))))))) (throw 'found (cdr regexp))))))))))
(defcustom special-display-buffer-names nil (defcustom special-display-buffer-names nil
...@@ -742,32 +742,37 @@ parameters." ...@@ -742,32 +742,37 @@ parameters."
:type 'boolean :type 'boolean
:group 'windows) :group 'windows)
(defcustom split-window-preferred-function nil
"How `display-buffer' shall split windows.
Choices are `Vertically', `Horizontally', and `Sensibly' where
the latter attempts to split wide windows horizontally, narrow
ones vertically. Alternatively, you can set this to a function
called with a window as single argument to split that window in
two and return the new window."
:type '(choice
(const :tag "Vertically" nil)
(const :tag "Horizontally" horizontally)
(const :tag "Sensibly" sensibly)
(function :tag "Function"))
:version "23.1"
:group 'windows)
(defcustom split-height-threshold 80 (defcustom split-height-threshold 80
"Minimum height of window to be split vertically by `display-buffer'. "Minimum height of window to be split vertically.
If there is only one window, it can be split regardless of this." If the value is a number, `display-buffer' can split a window
only if it has at least as many lines. If the value is nil,
`display-buffer' cannot split a window vertically.
If the window is the only window on its frame, `display-buffer'
can split it regardless of this value."
:type '(choice (const nil) (number :tag "lines"))
:type 'number :type 'number
:version "23.1" :version "23.1"
:group 'windows) :group 'windows)
(defcustom split-width-threshold 160 (defcustom split-width-threshold 160
"Minimum width of window to be split horizontally by `display-buffer'. "Minimum width of window to be split horizontally.
If there is only one window, it can be split regardless of this." If the value is a number, `display-buffer' can split a window
:type 'number only if it has at least as many columns. If the value is nil,
`display-buffer' cannot split a window horizontally."
:type '(choice (const nil) (number :tag "columns"))
:version "23.1"
:group 'windows)
(defcustom split-window-preferred-function nil
"Function used by `display-buffer' to split windows.
If non-nil, a function called with a window as single argument
supposed to split that window and return the new window. If the
function returns nil the window is not split.
If nil, `display-buffer' will split the window respecting the
values of `split-height-threshold' and `split-width-threshold'."
:type '(choice (const nil) (function :tag "Function"))
:version "23.1" :version "23.1"
:group 'windows) :group 'windows)
...@@ -779,11 +784,11 @@ can be split horizontally. ...@@ -779,11 +784,11 @@ can be split horizontally.
WINDOW can be split vertically when the following conditions WINDOW can be split vertically when the following conditions
hold: hold:
- `window-size-fixed' is either nil or equals `width' for the buffer of - `window-size-fixed' is either nil or equals `width' for the
WINDOW. buffer of WINDOW.
- WINDOW is at least as high as `split-height-threshold' or it is - `split-height-threshold' is a number and WINDOW is at least as
the only window on its frame. high as `split-height-threshold'.
- When WINDOW is split evenly, the emanating windows are at least - When WINDOW is split evenly, the emanating windows are at least
`window-min-height' lines tall and can accomodate at least one `window-min-height' lines tall and can accomodate at least one
...@@ -795,7 +800,8 @@ hold: ...@@ -795,7 +800,8 @@ hold:
- `window-size-fixed' is either nil or equals `height' for the - `window-size-fixed' is either nil or equals `height' for the
buffer of WINDOW. buffer of WINDOW.
- WINDOW is at least as wide as `split-width-threshold'. - `split-width-threshold' is a number and WINDOW is at least as
wide as `split-width-threshold'.
- When WINDOW is split evenly, the emanating windows are at least - When WINDOW is split evenly, the emanating windows are at least
`window-min-width' or two (whichever is larger) columns wide." `window-min-width' or two (whichever is larger) columns wide."
...@@ -807,57 +813,60 @@ hold: ...@@ -807,57 +813,60 @@ hold:
;; and at least twice as wide as `window-min-width' and 2 (the ;; and at least twice as wide as `window-min-width' and 2 (the
;; latter value is hardcoded). ;; latter value is hardcoded).
(and (memq window-size-fixed '(nil height)) (and (memq window-size-fixed '(nil height))
;; Testing `window-full-width-p' here hardly makes any
;; sense nowadays. This can be done more intuitively by
;; setting up `split-width-threshold' appropriately.
(numberp split-width-threshold)
(>= (window-width window) (>= (window-width window)
(max split-width-threshold (max split-width-threshold
(* 2 (max window-min-width 2))))) (* 2 (max window-min-width 2)))))
;; A window can be split vertically when its height is not ;; A window can be split vertically when its height is not
;; fixed, it is at least `split-height-threshold' lines high or ;; fixed, it is at least `split-height-threshold' lines high,
;; the only window on its frame, and it is at least twice as ;; and it is at least twice as high as `window-min-height' and 2
;; high as `window-min-height' and 2 if it has a modeline or 1. ;; if it has a modeline or 1.
(and (memq window-size-fixed '(nil width)) (and (memq window-size-fixed '(nil width))
(numberp split-height-threshold)
(>= (window-height window) (>= (window-height window)
(max (if (one-window-p 'nomini) 0 split-height-threshold) (max split-height-threshold
(* 2 (max window-min-height (* 2 (max window-min-height
(if mode-line-format 2 1)))))))))) (if mode-line-format 2 1))))))))))
(defun window--try-to-split-window (window) (defun window--try-to-split-window (window)
"Split window WINDOW if it is splittable. "Split window WINDOW if it is splittable.
See `split-window-preferred-function' for how WINDOW shall be See `window--splittable-p' for how to determine whether a window
split. See `window--splittable-p' for how to determine whether a is splittable. If WINDOW can be split, return the value returned
window is splittable. If WINDOW can be split, return the value by `split-window' or `split-window-preferred-function'."
returned by `split-window' or `split-window-preferred-function'."
(when (and (window-live-p window) (when (and (window-live-p window)
;; Testing `window-full-width-p' here hardly makes any
;; sense nowadays. This can be done more intuitively by
;; setting up `split-width-threshold' appropriately.
(not (frame-parameter (window-frame window) 'unsplittable))) (not (frame-parameter (window-frame window) 'unsplittable)))
(or (and (not split-window-preferred-function) (if (functionp split-window-preferred-function)
(window--splittable-p window) ;; `split-window-preferred-function' is specified, so use it.
(split-window window)) (funcall split-window-preferred-function window)
(and (eq split-window-preferred-function 'horizontally) (or (and (window--splittable-p window)
(window--splittable-p window t) ;; Split window vertically.
(split-window window nil t)) (split-window window))
(and (eq split-window-preferred-function 'sensibly) (and (window--splittable-p window t)
;; The following naive aspect-ratio test should become ;; Split window horizontally.
;; more sensible. (split-window window nil t))
(or (and (> (window-width window) (window-height window)) (and (with-selected-window window
(window--splittable-p window t) (one-window-p 'nomini))
(split-window window nil t)) ;; If WINDOW is the only window on its frame, attempt to
(and (window--splittable-p window) ;; split it vertically disregarding the current value of
(split-window window)))) ;; `split-height-threshold'.
(and (functionp split-window-preferred-function) (let ((split-height-threshold 0))
(funcall split-window-preferred-function window))))) (window--splittable-p window)
(split-window window)))))))
(defun window--frame-usable-p (frame) (defun window--frame-usable-p (frame)
"Return frame FRAME if it can be used to display another buffer." "Return frame FRAME if it can be used to display another buffer."
(let ((window (frame-root-window frame))) (when (framep frame)
;; `frame-root-window' may be an internal window which is considered (let ((window (frame-root-window frame)))
;; "dead" by `window-live-p'. Hence if `window' is not live we ;; `frame-root-window' may be an internal window which is considered
;; implicitly know that `frame' has a visible window we can use. ;; "dead" by `window-live-p'. Hence if `window' is not live we
(when (or (not (window-live-p window)) ;; implicitly know that `frame' has a visible window we can use.
(and (not (window-minibuffer-p window)) (when (or (not (window-live-p window))
(not (window-dedicated-p window)))) (and (not (window-minibuffer-p window))
frame))) (not (window-dedicated-p window))))
frame))))
(defcustom even-window-heights t (defcustom even-window-heights t
"If non-nil `display-buffer' will try to even window heights. "If non-nil `display-buffer' will try to even window heights.
...@@ -1009,12 +1018,12 @@ consider all visible or iconified frames." ...@@ -1009,12 +1018,12 @@ consider all visible or iconified frames."
(or (window--try-to-split-window (or (window--try-to-split-window
(get-largest-window frame-to-use t)) (get-largest-window frame-to-use t))
(window--try-to-split-window (window--try-to-split-window
(get-lru-window frame-to-use t)) (get-lru-window frame-to-use t))))
(get-lru-window frame-to-use nil)))
(window--display-buffer-2 buffer window-to-use))) (window--display-buffer-2 buffer window-to-use)))
((setq window-to-use ((setq window-to-use
;; Reuse an existing window. ;; Reuse an existing window.
(or (get-buffer-window buffer 'visible) (or (get-lru-window frame-to-use)
(get-buffer-window buffer 'visible)
(get-largest-window 'visible nil) (get-largest-window 'visible nil)
(get-buffer-window buffer 0) (get-buffer-window buffer 0)
(get-largest-window 0 nil) (get-largest-window 0 nil)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment