Next: , Previous: Window Sizes, Up: Windows

28.4 Resizing Windows

This section describes functions for resizing a window without changing the size of its frame. Because live windows do not overlap, these functions are meaningful only on frames that contain two or more windows: resizing a window also changes the size of a neighboring window. If there is just one window on a frame, its size cannot be changed except by resizing the frame (see Size and Position).

Except where noted, these functions also accept internal windows as arguments. Resizing an internal window causes its child windows to be resized to fit the same space.

— Function: window-resizable window delta &optional horizontal ignore

This function returns delta if the size of window can be changed vertically by delta lines. If the optional argument horizontal is non-nil, it instead returns delta if window can be resized horizontally by delta columns. It does not actually change the window size.

If window is nil, it defaults to the selected window.

A positive value of delta means to check whether the window can be enlarged by that number of lines or columns; a negative value of delta means to check whether the window can be shrunk by that many lines or columns. If delta is non-zero, a return value of 0 means that the window cannot be resized.

Normally, the variables window-min-height and window-min-width specify the smallest allowable window size. See Deleting and Rearranging Windows. However, if the optional argument ignore is non-nil, this function ignores window-min-height and window-min-width, as well as window-size-fixed. Instead, it considers the minimum-height window to be one consisting of a header (if any), a mode line, plus a text area one line tall; and a minimum-width window as one consisting of fringes, margins, and scroll bar (if any), plus a text area two columns wide.

— Function: window-resize window delta &optional horizontal ignore

This function resizes window by delta increments. If horizontal is nil, it changes the height by delta lines; otherwise, it changes the width by delta columns. A positive delta means to enlarge the window, and a negative delta means to shrink it.

If window is nil, it defaults to the selected window. If the window cannot be resized as demanded, an error is signaled.

The optional argument ignore has the same meaning as for the function window-resizable above.

The choice of which window edges this function alters depends on the values of the option window-combination-resize and the combination limits of the involved windows; in some cases, it may alter both edges. See Recombining Windows. To resize by moving only the bottom or right edge of a window, use the function adjust-window-trailing-edge, below.

— Function: adjust-window-trailing-edge window delta &optional horizontal

This function moves window's bottom edge by delta lines. If optional argument horizontal is non-nil, it instead moves the right edge by delta columns. If window is nil, it defaults to the selected window.

A positive delta moves the edge downwards or to the right; a negative delta moves it upwards or to the left. If the edge cannot be moved as far as specified by delta, this function moves it as far as possible but does not signal a error.

This function tries to resize windows adjacent to the edge that is moved. If this is not possible for some reason (e.g., if that adjacent window is fixed-size), it may resize other windows.

The following commands resize windows in more specific ways. When called interactively, they act on the selected window.

— Command: fit-window-to-buffer &optional window max-height min-height override

This command adjusts the height of window to fit the text in it. It returns non-nil if it was able to resize window, and nil otherwise. If window is omitted or nil, it defaults to the selected window. Otherwise, it should be a live window.

The optional argument max-height, if non-nil, specifies the maximum total height that this function can give window. The optional argument min-height, if non-nil, specifies the minimum total height that it can give, which overrides the variable window-min-height.

If the optional argument override is non-nil, this function ignores any size restrictions imposed by window-min-height and window-min-width.

If the option fit-frame-to-buffer is non-nil, this command may resize the frame to fit its contents.

— Command: shrink-window-if-larger-than-buffer &optional window

This command attempts to reduce window's height as much as possible while still showing its full buffer, but no less than window-min-height lines. The return value is non-nil if the window was resized, and nil otherwise. If window is omitted or nil, it defaults to the selected window. Otherwise, it should be a live window.

This command does nothing if the window is already too short to display all of its buffer, or if any of the buffer is scrolled off-screen, or if the window is the only live window in its frame.

— Command: balance-windows &optional window-or-frame

This function balances windows in a way that gives more space to full-width and/or full-height windows. If window-or-frame specifies a frame, it balances all windows on that frame. If window-or-frame specifies a window, it balances only that window and its siblings (see Windows and Frames).

— Command: balance-windows-area

This function attempts to give all windows on the selected frame approximately the same share of the screen area. Full-width or full-height windows are not given more space than other windows.

— Command: maximize-window &optional window

This function attempts to make window as large as possible, in both dimensions, without resizing its frame or deleting other windows. If window is omitted or nil, it defaults to the selected window.

— Command: minimize-window &optional window

This function attempts to make window as small as possible, in both dimensions, without deleting it or resizing its frame. If window is omitted or nil, it defaults to the selected window.