elisp: Selecting 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 (Basic Windows) and selects that
frame. It also makes WINDOW’s buffer (Buffers and Windows)
current and sets that buffer’s value of ‘point’ to the value of
‘window-point’ (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 (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’ (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 (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 (Cyclic Window Ordering).