Skip to content

Instantly share code, notes, and snippets.

@jsvnm
Created August 30, 2012 23:30
Show Gist options
  • Save jsvnm/3544998 to your computer and use it in GitHub Desktop.
Save jsvnm/3544998 to your computer and use it in GitHub Desktop.
wanted "most recent before current"-window. get-mru-window gives current. instead of simplest, i did the most complex thing that could work. almost.
(defun windows-in-use-time-order (&optional old-to-new windows)
"Windows sorted by their `window-use-time'.
Without arguments windows on current frame ordered from most to least recent.
Optional argument OLD-TO-NEW with non-nil value reverses the order.
Optional argument WINDOWS specifies which windows to sort by use time:
- a list is assumed to contain windows and sorted
- a function is called, should return list of windows to sort
- any other value is passed to `window-list-1' as ALL-FRAMES parameter"
(sort* (cond ((and windows (listp windows)) windows)
((functionp windows) (funcall windows))
((window-list-1 nil 'nomini windows)))
(if old-to-new '< '>)
:key 'window-use-time))
;; to get the window that was used before current on, in current frame:
(nth 1 (windows-in-use-time-order))
;; in all frames:
(nth 1 (windows-in-use-time-order nil t))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment