(window-left-child window)
(window-top-child window)))
-(defun window-combinations (window &optional horizontal)
+(defun window-combinations (window &optional horizontal ignore-fixed)
"Return largest number of windows vertically arranged within WINDOW.
WINDOW must be a valid window and defaults to the selected one.
If HORIZONTAL is non-nil, return the largest number of
-windows horizontally arranged within WINDOW."
+windows horizontally arranged within WINDOW.
+
+Optional argument IGNORE-FIXED, if non-nil, means to ignore
+fixed-size windows in the calculation."
(setq window (window-normalize-window window))
(cond
((window-live-p window)
(let ((child (window-child window))
(count 0))
(while child
- (setq count
- (+ (window-combinations child horizontal)
- count))
+ (unless (and ignore-fixed (window-size-fixed-p child horizontal))
+ (setq count
+ (+ (window-combinations child horizontal ignore-fixed)
+ count)))
(setq child (window-right child)))
count))
(t
(let ((child (window-child window))
(count 1))
(while child
- (setq count
- (max (window-combinations child horizontal)
- count))
+ (unless (and ignore-fixed (window-size-fixed-p child horizontal))
+ (setq count
+ (max (window-combinations child horizontal ignore-fixed)
+ count)))
(setq child (window-right child)))
count))))
;; If a window doesn't show BUFFER, unrecord BUFFER in it.
(unrecord-window-buffer window buffer)))))
\f
+(defun window--combination-resizable (parent &optional horizontal)
+ "Return number of pixels recoverable from height of window PARENT.
+PARENT must be a vertical (horizontal if HORIZONTAL is non-nil)
+window combination. The return value is the sum of the pixel
+heights of all non-fixed height child windows of PARENT divided
+by their number plus 1. If HORIZONTAL is non-nil, return the sum
+of the pixel widths of all non-fixed width child windows of
+PARENT divided by their number plus 1."
+ (let ((sibling (window-child parent))
+ (number 0)
+ (size 0))
+ (while sibling
+ (unless (window-size-fixed-p sibling horizontal)
+ (setq number (1+ number))
+ (setq size (+ (window-size sibling horizontal t) size)))
+ (setq sibling (window-next-sibling sibling)))
+ (/ size (1+ number))))
+
(defun split-window (&optional window size side pixelwise)
"Make a new window adjacent to WINDOW.
WINDOW must be a valid window and defaults to the selected one.
;; average size of a window in its combination.
(max (min (- parent-pixel-size
(window-min-size parent horizontal nil t))
- (/ parent-pixel-size
- (1+ (window-combinations parent horizontal))))
+ (window--combination-resizable parent horizontal))
(window-min-pixel-size))
;; Else try to give the new window half the size
;; of WINDOW (plus an eventual odd pixel).
(pixel-size (/ (float new-pixel-size)
(if new-parent old-pixel-size parent-pixel-size)))
(new-parent 0.5)
- (resize (/ 1.0 (1+ (window-combinations parent horizontal))))
+ (resize (/ 1.0 (1+ (window-combinations parent horizontal t))))
(t (/ (window-normal-size window horizontal) 2.0))))
(if resize