Next: , Previous: Recombining Windows, Up: Windows

27.9 Selecting Windows

— Function: select-window window &optional norecord

This function makes window the selected window and the window selected within its frame (see Basic Windows) and selects that frame. It also makes window's buffer (see Buffers and Windows) current and sets that buffer's value of point to the value of window-point (see Window Point) in window. window must be a live window. The return value is window.

By default, this function also moves window's buffer to the front of the buffer list (see Buffer List), and makes window the most recently selected window. However, if the optional argument norecord is non-nil, these additional actions are omitted.

This function runs buffer-list-update-hook (see Buffer List) unless norecord is non-nil. Note that applications and internal routines often temporarily select a window in order to simplify coding. As a rule, such selections (including those made by the macros save-selected-window and with-selected-window below) are not recorded thus avoiding to pollute buffer-list-update-hook. Selections that really count are those causing a visible change in the next redisplay of window's frame and should be always recorded. This also means that to run a function each time a window gets selected, putting it on buffer-list-update-hook should be the right choice.

The sequence of calls to select-window with a non-nil norecord argument determines an ordering of windows by their selection time. The function get-lru-window can be used to retrieve the least recently selected live window (see Cyclic Window Ordering).

— Macro: save-selected-window forms...

This macro records the selected frame, as well as the selected window of each frame, executes forms in sequence, then restores the earlier selected frame and windows. It also saves and restores the current buffer. It returns the value of the last form in forms.

This macro does not save or restore anything about the sizes, arrangement or contents of windows; therefore, if forms change them, the change persists. If the previously selected window of some frame is no longer live at the time of exit from forms, that frame's selected window is left alone. If the previously selected window is no longer live, then whatever window is selected at the end of forms remains selected. The current buffer is restored if and only if it is still live when exiting forms.

This macro changes neither the ordering of recently selected windows nor the buffer list.

— Macro: with-selected-window window forms...

This macro selects window, executes forms in sequence, then restores the previously selected window and current buffer. The ordering of recently selected windows and the buffer list remain unchanged unless you deliberately change them within forms; for example, by calling select-window with argument norecord nil.

This macro does not change the order of recently selected windows or the buffer list.

— Function: frame-selected-window &optional frame

This function returns the window on frame that is selected within that frame. frame should be a live frame; if omitted or nil, it defaults to the selected frame.

— Function: set-frame-selected-window frame window &optional norecord

This function makes window the window selected within the frame frame. frame should be a live frame; if nil, it defaults to the selected frame. window should be a live window; if nil, it defaults to the selected window.

If frame is the selected frame, this makes window the selected window.

If the optional argument norecord is non-nil, this function does not alter the list of most recently selected windows, nor the buffer list.

— Function: window-use-time &optional window

This functions returns the use time of window window. window must be a live window and defaults to the selected one.

The use time of a window is not really a time value, but an integer that does increase monotonically with each call of select-window with a nil norecord argument. The window with the lowest use time is usually called the least recently used window while the window with the highest use time is called the most recently used one (see Cyclic Window Ordering).