The function other-frame cycles through the open frames in a fixed order. This can be pretty inconvenient for example when the compiling log of LaTeX comes to the front, I want to switch back to my .tex document and I have plenty of other frame opened at the same time. On the major GUIs I know the window or application switching command switch between the most recent ones (and on can access the other ones by repeating the command).

  • I realize you want the most recent, but there are functions available by Googling that work with ido, or selecting a frame by name, or selecting a frame by letter (of available options), or selecting a frame by number (of available options). That way you can go immediately to whichever frame you really want. Off hand, I don't know of a most-recent select frame function -- but if it doesn't exist, I'm sure someone will write it up.
    – lawlist
    Commented Apr 2, 2016 at 0:26

1 Answer 1


Here's some code I ended up writing to accomplish this. Add the following to your init.el file, and bind a key to my-goto-most-recent-frame:

(defvar my-recent-frames '())

(defun my-frame-record-selected ()
  "Record the currently selected frame.  Add this to the focus-in-hook."
  (let ((f (selected-frame)))
    (setq my-recent-frames (cons f (remove f my-recent-frames)))))

(add-hook 'focus-in-hook #'my-frame-record-selected)

(defun my-goto-most-recent-frame ()
  "Jump to most recently active frame before the current frame."
  (unless (null my-recent-frames)
    (select-frame-set-input-focus (car (cdr my-recent-frames)))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.