From: Martin Rudalics Date: Wed, 6 Mar 2019 09:11:08 +0000 (+0100) Subject: Fix handling of 'window-combination-resize' with fixed-size windows X-Git-Tag: emacs-27.0.90~3468 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=b079cfa8461ba890285268962715eef07a10eae3;p=emacs.git Fix handling of 'window-combination-resize' with fixed-size windows * lisp/window.el (window-combinations): New optional argument IGNORE-FIXED. (window--combination-resizable): New function. (split-window): Fix handling of 'window-combination-resize' in the presence of fixed-size windows. --- diff --git a/lisp/window.el b/lisp/window.el index 9566429627d..98cdf98cda5 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -509,11 +509,14 @@ child if WINDOW is a horizontal combination." (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) @@ -527,9 +530,10 @@ windows horizontally arranged within 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 @@ -538,9 +542,10 @@ windows horizontally arranged within WINDOW." (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)))) @@ -4905,6 +4910,24 @@ showing BUFFER-OR-NAME." ;; If a window doesn't show BUFFER, unrecord BUFFER in it. (unrecord-window-buffer window buffer))))) +(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. @@ -5042,8 +5065,7 @@ frame. The selected window is not changed by this function." ;; 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). @@ -5128,7 +5150,7 @@ frame. The selected window is not changed by this function." (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