Subject: Re: bug#16436: feature request: select-window-hook

From: martin rudalics <[email-masked]>
Date: Tue, 14 Jan 2014 08:47:11 +0100

> I don't know whether I missed something but I can't find a hook like
 > select-window-hook in stand
 > hooks<http://www.gnu.org/software/emacs/manual/html_node/elisp/Standard-Hooks.html>,
 > and I find some other emacs user has the same issue.
 >
 > I really want to have a function as select-last-window for emacs, by now, I
 > hack it in a ugly way, and I think select-window-hook can make it better.

Try

(defvar my-window nil)
(defvar my-last-window nil)

(defun my-last-window ()
   (unless (or (window-minibuffer-p)
	      (eq (selected-window) my-window))
     (setq my-last-window my-window)
     (setq my-window (selected-window))))

(add-hook 'buffer-list-update-hook 'my-last-window)

(defun select-last-window ()
   (interactive)
   (when (and (window-live-p my-last-window)
	     (not (eq my-last-window (selected-window))))
     (select-window my-last-window)))

martin