2

I would like to implement an interactive function that, in the "canonical" case, selects the window that was selected before the currently selected one1.

But my plan founders immediately on this question: how can my future function find out, to begin with, what the previously selected window is???


1 There are a few edge cases, e.g. when no other window was previously selected, that I won't get into.

1
  • 2
    C-h i g(elisp)Selecting windows has some information that might be helpful. Commented Aug 17, 2021 at 14:29

1 Answer 1

4

Since Emacs 27.1, the previously selected window is recorded and can be obtained with old-selected-window. The previously selected window in each frame can be obtained with frame-old-selected-window. If you want older information, you can record it with a hook in window-selection-change-functions.

In older versions of Emacs, I don't think Emacs remembers any historical information about window selections by default, and there's no hook for window selection. You would have to advise at least select-window, and quite possibly other built-in functions that change the window selection.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.