Next: , Previous: Selecting Windows, Up: Windows

28.9 Cyclic Ordering of Windows

When you use the command C-x o (other-window) to select some other window, it moves through live windows in a specific order. For any given configuration of windows, this order never varies. It is called the cyclic ordering of windows.

The ordering is determined by a depth-first traversal of the frame's window tree, retrieving the live windows which are the leaf nodes of the tree (see Windows and Frames). If the minibuffer is active, the minibuffer window is included too. The ordering is cyclic, so the last window in the sequence is followed by the first one.

— Function: next-window &optional window minibuf all-frames

This function returns a live window, the one following window in the cyclic ordering of windows. window should be a live window; if omitted or nil, it defaults to the selected window.

The optional argument minibuf specifies whether minibuffer windows should be included in the cyclic ordering. Normally, when minibuf is nil, a minibuffer window is included only if it is currently “active”; this matches the behavior of C-x o. (Note that a minibuffer window is active as long as its minibuffer is in use; see Minibuffers).

If minibuf is t, the cyclic ordering includes all minibuffer windows. If minibuf is neither t nor nil, minibuffer windows are not included even if they are active.

The optional argument all-frames specifies which frames to consider:

If more than one frame is considered, the cyclic ordering is obtained by appending the orderings for those frames, in the same order as the list of all live frames (see Finding All Frames).

— Function: previous-window &optional window minibuf all-frames

This function returns a live window, the one preceding window in the cyclic ordering of windows. The other arguments are handled like in next-window.

— Command: other-window count &optional all-frames

This function selects a live window, one count places from the selected window in the cyclic ordering of windows. If count is a positive number, it skips count windows forwards; if count is negative, it skips −count windows backwards; if count is zero, that simply re-selects the selected window. When called interactively, count is the numeric prefix argument.

The optional argument all-frames has the same meaning as in next-window, like a nil minibuf argument to next-window.

This function does not select a window that has a non-nil no-other-window window parameter (see Window Parameters).

— Function: walk-windows fun &optional minibuf all-frames

This function calls the function fun once for each live window, with the window as the argument.

It follows the cyclic ordering of windows. The optional arguments minibuf and all-frames specify the set of windows included; these have the same arguments as in next-window. If all-frames specifies a frame, the first window walked is the first window on that frame (the one returned by frame-first-window), not necessarily the selected window.

If fun changes the window configuration by splitting or deleting windows, that does not alter the set of windows walked, which is determined prior to calling fun for the first time.

— Function: one-window-p &optional no-mini all-frames

This function returns t if the selected window is the only live window, and nil otherwise.

If the minibuffer window is active, it is normally considered (so that this function returns nil). However, if the optional argument no-mini is non-nil, the minibuffer window is ignored even if active. The optional argument all-frames has the same meaning as for next-window.

The following functions return a window which satisfies some criterion, without selecting it:

— Function: get-lru-window &optional all-frames dedicated not-selected

This function returns a live window which is heuristically the “least recently used” window. The optional argument all-frames has the same meaning as in next-window.

If any full-width windows are present, only those windows are considered. A minibuffer window is never a candidate. A dedicated window (see Dedicated Windows) is never a candidate unless the optional argument dedicated is non-nil. The selected window is never returned, unless it is the only candidate. However, if the optional argument not-selected is non-nil, this function returns nil in that case.

— Function: get-largest-window &optional all-frames dedicated not-selected

This function returns the window with the largest area (height times width). The optional argument all-frames specifies the windows to search, and has the same meaning as in next-window.

A minibuffer window is never a candidate. A dedicated window (see Dedicated Windows) is never a candidate unless the optional argument dedicated is non-nil. The selected window is not a candidate if the optional argument not-selected is non-nil. If the optional argument not-selected is non-nil and the selected window is the only candidate, this function returns nil.

If there are two candidate windows of the same size, this function prefers the one that comes first in the cyclic ordering of windows, starting from the selected window.

— Function: get-window-with-predicate predicate &optional minibuf all-frames default

This function calls the function predicate for each of the windows in the cyclic order of windows in turn, passing it the window as an argument. If the predicate returns non-nil for any window, this function stops and returns that window. If no such window is found, the return value is default (which defaults to nil).

The optional arguments minibuf and all-frames specify the windows to search, and have the same meanings as in next-window.