Function: window-resize

window-resize is a byte-compiled function defined in window.el.gz.

Signature

(window-resize WINDOW DELTA &optional HORIZONTAL IGNORE PIXELWISE)

Documentation

Resize WINDOW vertically by DELTA lines.

WINDOW can be an arbitrary window and defaults to the selected one. An attempt to resize the root window of a frame will raise an error though.

DELTA a positive number means WINDOW shall be enlarged by DELTA lines. DELTA negative means WINDOW shall be shrunk by -DELTA lines.

Optional argument HORIZONTAL non-nil means resize WINDOW horizontally by DELTA columns. In this case a positive DELTA means enlarge WINDOW by DELTA columns. DELTA negative means WINDOW shall be shrunk by -DELTA columns.

Optional argument IGNORE, if non-nil, means to ignore restraints induced by fixed size windows or the values of the variables window-min-height and window-min-width. The following values have special meanings: safe means that in addition live windows are allowed to get as small as window-safe-min-height lines and window-safe-min-width columns. preserved means to ignore only restrictions induced by window-preserve-size. If IGNORE is a window, then ignore restrictions for that window only.

Optional argument PIXELWISE non-nil means resize WINDOW by DELTA pixels.

This function resizes other windows proportionally and never deletes any windows. If you want to move only the low (right) edge of WINDOW consider using adjust-window-trailing-edge instead.

View in manual

Probably introduced at or before Emacs version 24.1.

Source Code

;; Defined in /usr/src/emacs/lisp/window.el.gz
(defun window-resize (window delta &optional horizontal ignore pixelwise)
  "Resize WINDOW vertically by DELTA lines.
WINDOW can be an arbitrary window and defaults to the selected
one.  An attempt to resize the root window of a frame will raise
an error though.

DELTA a positive number means WINDOW shall be enlarged by DELTA
lines.  DELTA negative means WINDOW shall be shrunk by -DELTA
lines.

Optional argument HORIZONTAL non-nil means resize WINDOW
horizontally by DELTA columns.  In this case a positive DELTA
means enlarge WINDOW by DELTA columns.  DELTA negative means
WINDOW shall be shrunk by -DELTA columns.

Optional argument IGNORE, if non-nil, means to ignore restraints
induced by fixed size windows or the values of the variables
`window-min-height' and `window-min-width'.  The following values
have special meanings: `safe' means that in addition live windows
are allowed to get as small as `window-safe-min-height' lines and
`window-safe-min-width' columns.  `preserved' means to ignore
only restrictions induced by `window-preserve-size'.  If IGNORE
is a window, then ignore restrictions for that window only.

Optional argument PIXELWISE non-nil means resize WINDOW by DELTA
pixels.

This function resizes other windows proportionally and never
deletes any windows.  If you want to move only the low (right)
edge of WINDOW consider using `adjust-window-trailing-edge'
instead."
  (setq window (window-normalize-window window))
  (let* ((frame (window-frame window))
	 (minibuffer-window (minibuffer-window frame))
	 sibling)
    (setq delta (window--size-to-pixel
		 window delta horizontal pixelwise t))
    (cond
     ((eq window (frame-root-window frame))
      (error "Cannot resize the root window of a frame"))
     ((window-minibuffer-p window)
      (if horizontal
	  (error "Cannot resize minibuffer window horizontally")
	(window--resize-mini-window window delta)))
     ((and (not horizontal)
	   (window-full-height-p window)
	   (eq (window-frame minibuffer-window) frame)
	   (or (not resize-mini-windows)
	       (eq minibuffer-window (active-minibuffer-window))))
      ;; If WINDOW is full height and either `resize-mini-windows' is
      ;; nil or the minibuffer window is active, resize the minibuffer
      ;; window.
      (window--resize-mini-window minibuffer-window (- delta)))
     ((or (window--resizable-p
	   window delta horizontal ignore nil nil nil t)
	  (and (not ignore)
	       (setq ignore 'preserved)
	       (window--resizable-p
		window delta horizontal ignore nil nil nil t)))
      (window--resize-reset frame horizontal)
      (window--resize-this-window window delta horizontal ignore t)
      (if (and (not (eq window-combination-resize t))
	       (window-combined-p window horizontal)
	       (setq sibling (or (window-right window) (window-left window)))
	       (window-sizable-p
		sibling (- delta) horizontal ignore t))
	  ;; If window-combination-resize is nil, WINDOW is part of an
	  ;; iso-combination, and WINDOW's neighboring right or left
	  ;; sibling can be resized as requested, resize that sibling.
	  (let ((normal-delta
		 (/ (float delta)
		    (window-size (window-parent window) horizontal t))))
	    (window--resize-this-window sibling (- delta) horizontal nil t)
	    (set-window-new-normal
	     window (+ (window-normal-size window horizontal)
		       normal-delta))
	    (set-window-new-normal
	     sibling (- (window-normal-size sibling horizontal)
			normal-delta)))
	;; Otherwise, resize all other windows in the same combination.
	(window--resize-siblings window delta horizontal ignore))
      (when (window--resize-apply-p frame horizontal)
	(if (window-resize-apply frame horizontal)
	    (window--pixel-to-total frame horizontal)
	  (error "Failed to apply resizing %s" window))))
     (t
      (error "Cannot resize window %s" window)))))