(* 2 (max window-min-height
(if mode-line-format 2 1))))))))))
-(defun split-window-sensibly (window)
+(defun split-window-sensibly (&optional window)
"Split WINDOW in a way suitable for `display-buffer'.
+WINDOW defaults to the currently selected window.
If `split-height-threshold' specifies an integer, WINDOW is at
least `split-height-threshold' lines tall and can be split
vertically, split WINDOW into two windows one above the other and
Have a look at the function `window-splittable-p' if you want to
know how `split-window-sensibly' determines whether WINDOW can be
split."
- (or (and (window-splittable-p window)
- ;; Split window vertically.
- (with-selected-window window
- (split-window-below)))
- (and (window-splittable-p window t)
- ;; Split window horizontally.
- (with-selected-window window
- (split-window-right)))
- (and (eq window (frame-root-window (window-frame window)))
- (not (window-minibuffer-p window))
- ;; If WINDOW is the only window on its frame and is not the
- ;; minibuffer window, try to split it vertically disregarding
- ;; the value of `split-height-threshold'.
- (let ((split-height-threshold 0))
- (when (window-splittable-p window)
- (with-selected-window window
- (split-window-below)))))))
+ (let ((window (or window (selected-window))))
+ (or (and (window-splittable-p window)
+ ;; Split window vertically.
+ (with-selected-window window
+ (split-window-below)))
+ (and (window-splittable-p window t)
+ ;; Split window horizontally.
+ (with-selected-window window
+ (split-window-right)))
+ (and (eq window (frame-root-window (window-frame window)))
+ (not (window-minibuffer-p window))
+ ;; If WINDOW is the only window on its frame and is not the
+ ;; minibuffer window, try to split it vertically disregarding
+ ;; the value of `split-height-threshold'.
+ (let ((split-height-threshold 0))
+ (when (window-splittable-p window)
+ (with-selected-window window
+ (split-window-below))))))))
(defun window--try-to-split-window (window)
"Try to split WINDOW.