Subject: 24.0.50; Provide a hook run when a window is selected

From: Štěpán Němec <[email-masked]>
Date: Fri, 12 Nov 2010 01:14:59 +0100

Severity: wishlist

The subject line says it all: could we get a `window-selected-hook' or
`window-selected-functions' or something?

Use case: I wanted to make myself a command to select the last selected
window (i.e., repeating the command would toggle between two windows).

After some head-scratching, the best I could come up with is this:

(defun .goto-mru-window ()
  (interactive)
  (select-window (frame-parameter nil '.last-selected-window)))

(defadvice select-window (before .save-selected-window activate)
  (set-frame-parameter nil '.last-selected-window (selected-window)))

...which seems to work most of the time, but using an advice doesn't
feel that great, esp. with C functions.

  Štěpán