Function: get-lru-window

get-lru-window is a byte-compiled function defined in window.el.gz.

Signature

(get-lru-window &optional ALL-FRAMES DEDICATED NOT-SELECTED NO-OTHER)

Documentation

Return the least recently used window on frames specified by ALL-FRAMES.

Return a full-width window if possible. A minibuffer window is never a candidate. A dedicated window is never a candidate unless DEDICATED is non-nil, so if all windows are dedicated, the value is nil. Avoid returning the selected window if possible. Optional argument NOT-SELECTED non-nil means never return the selected window. Optional argument NO-OTHER non-nil means to never return a window for which window-no-other-p returns non-nil.

The following non-nil values of the optional argument ALL-FRAMES have special meanings:

- t means consider all windows on all existing frames.

- visible means consider all windows on all visible frames on
  the current terminal.

- 0 (the number zero) means consider all windows on all visible
  and iconified frames on the current terminal.

- A frame means consider all windows on that frame only.

Any other value of ALL-FRAMES means consider all windows on the selected frame and no others.

View in manual

Probably introduced at or before Emacs version 19.23.

Source Code

;; Defined in /usr/src/emacs/lisp/window.el.gz
(defun get-lru-window (&optional all-frames dedicated not-selected no-other)
  "Return the least recently used window on frames specified by ALL-FRAMES.
Return a full-width window if possible.  A minibuffer window is never a
candidate.  A dedicated window is never a candidate unless DEDICATED is
non-nil, so if all windows are dedicated, the value is nil.  Avoid
returning the selected window if possible.  Optional argument
NOT-SELECTED non-nil means never return the selected window.  Optional
argument NO-OTHER non-nil means to never return a window for which
`window-no-other-p' returns non-nil.

The following non-nil values of the optional argument ALL-FRAMES
have special meanings:

- t means consider all windows on all existing frames.

- `visible' means consider all windows on all visible frames on
  the current terminal.

- 0 (the number zero) means consider all windows on all visible
  and iconified frames on the current terminal.

- A frame means consider all windows on that frame only.

Any other value of ALL-FRAMES means consider all windows on the
selected frame and no others."
  (declare (ftype (function (&optional t t t t) (or window null)))
           (side-effect-free error-free))
  (let ((windows (window-list-1 nil 'nomini all-frames))
        best-window best-time second-best-window second-best-time time)
    (dolist (window windows)
      (when (and (or dedicated (not (window-dedicated-p window)))
		 (or (not not-selected) (not (eq window (selected-window))))
                 (or (not no-other) (not (window-no-other-p window))))
	(setq time (window-use-time window))
	(if (or (eq window (selected-window))
		(not (window-full-width-p window)))
	    (when (or (not second-best-time) (< time second-best-time))
	      (setq second-best-time time)
	      (setq second-best-window window))
	  (when (or (not best-time) (< time best-time))
	    (setq best-time time)
	    (setq best-window window)))))
    (or best-window second-best-window)))