I am trying to use the code from this answer: Is there a generic toggle-previous-window function?
(defun switch-to-last-window ()
(interactive)
(let ((win (get-mru-window t t t)))
(unless win (error "Last window not found."))
(let ((frame (window-frame win)))
(raise-frame frame)
(select-frame frame)
(select-window win))))
I had to add: (select-frame-set-input-focus frame)
to make it work. But with this code or just switching windows using the mouse I have the following problem. Imagine I have two frames, one with one window f1_w1
and the other with two windows f2_w1
and f2_w2
. When I switch from f1_w1
to f2_w1
there is no problem, but when on the next cycle after f2_w1
-> f1_w1
I switch from f1_w1
to f2_w2
I can see the cursor first appear on f2_w1
and then quickly jump to f2_w2
making my last visited window f2_w1
and not f1_w1
as it should be.
EDIT: as per Drew's comment below that asks for the question. I just find it surprising that Emacs can't properly track the last selected window (unless something is messed up in my configuration). It seems that get-mru-window
works as expected but switching to a window on another frame seems to be a two step operation under the bonnet, where Emacs selects the previously active window on the target frame (not the one I am switching to) and then quickly jumps to the one I am selecting. Is this behaviour unavoidable when using multiple frames?
emacs -Q
? What are the minimal steps required to reproduce it? What version of Emacs are you using?ace-window
, it tracks the windows well and it has go to the last window functionality. Works pretty well for me.ace-window
package which accomplishes this is calledaw-flip-window
(description: Switch to the window you were previously in.). The funcionality of this function is similar to the functiontab-bar-switch-to-recent-tab
defined intab-bar.el
but for windows instead of tabs.