Function: balance-windows

balance-windows is an interactive and byte-compiled function defined in window.el.gz.

Signature

(balance-windows &optional WINDOW-OR-FRAME)

Documentation

Balance the sizes of windows shown on the selected frame.

When called from Lisp, WINDOW-OR-FRAME is optional and defaults to the selected frame. If WINDOW-OR-FRAME denotes a frame, balance the sizes of all windows of that frame's root window (which excludes the mini-window). If WINDOW-OR-FRAME denotes a window, recursively balance the sizes of all child windows of that window.

View in manual

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/window.el.gz
(defun balance-windows (&optional window-or-frame)
  "Balance the sizes of windows shown on the selected frame.
When called from Lisp, WINDOW-OR-FRAME is optional and defaults to the
selected frame.
If WINDOW-OR-FRAME denotes a frame, balance the sizes of all
windows of that frame's root window (which excludes the mini-window).
If WINDOW-OR-FRAME denotes a window, recursively balance the sizes
of all child windows of that window."
  (interactive)
  (let* ((window
	  (cond
	   ((or (not window-or-frame)
		(frame-live-p window-or-frame))
	    (frame-root-window window-or-frame))
	   ((or (window-live-p window-or-frame)
		(window-child window-or-frame))
	    window-or-frame)
	   (t
	    (error "Not a window or frame %s" window-or-frame))))
	 (frame (window-frame window)))
    ;; Balance vertically.
    (window--resize-reset (window-frame window))
    (balance-windows-1 window)
    (when (window--resize-apply-p frame)
      (window-resize-apply frame)
      (window--pixel-to-total frame))
    ;; Balance horizontally.
    (window--resize-reset (window-frame window) t)
    (balance-windows-1 window t)
    (when (window--resize-apply-p frame t)
      (window-resize-apply frame t)
      (window--pixel-to-total frame t))))