elisp: Cyclic Window Ordering

 
 27.10 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 each frame’s
 window tree, retrieving the live windows which are the leaf nodes of the
 tree (SeeWindows 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 SeeMinibuffers).
 
      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:
 
         • ‘nil’ means to consider windows on WINDOW’s frame.  If the
           minibuffer window is considered (as specified by the MINIBUF
           argument), then frames that share the minibuffer window are
           considered too.
 
         • ‘t’ means to consider windows on all existing frames.
 
         • ‘visible’ means to consider windows on all visible frames.
 
         • 0 means to consider windows on all visible or iconified
           frames.
 
         • A frame means to consider windows on that specific frame.
 
         • Anything else means to consider windows on WINDOW’s frame, and
           no others.
 
      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 (SeeFinding 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 (SeeWindow 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.  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 (SeeDedicated 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-mru-window &optional all-frames dedicated not-selected
      This function is like ‘get-lru-window’, but it returns the most
      recently used window instead.  The meaning of the arguments is the
      same as described for ‘get-lru-window’.
 
  -- 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
      (SeeDedicated 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’.