Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

frame-list returns a list of references for live Emacs frames. How does one get a reference for the current Emacs frame? I have been unable to find an appropriate function. Current could be either (1) the Emacs frame that has focus (one or zero references) or (2) the Emacs frame that last had focus.

I'm presently looking to use (1) under w32, but for didactic purposes I'm interested in both and whether there are any caveats for focus tracking in Emacs.

share|improve this question
How about selected-frame? – glucas Jan 10 at 21:36
Yes; that's the synonym I was looking for! My apropos-command searches were coming up empty :-\ – ebpa Jan 10 at 21:41
Use M-x apropos, not apropos-command (frame functions are generally not commands). – Drew Jan 10 at 23:20
Interesting. That explains why I usually don't get useful information from C-h a (apropos-command). I primarily rely on describe-function and describe-variable narrowed with helm. Now that I know of apropos I'm going to bind that to C-h a! Thanks for pointing that out, @Drew. – ebpa Jan 10 at 23:31
@ebpa: If you're using Helm, you may also be interested in helm-apropos, which jams sources for all of the different symbol types (variable, function, etc.) into one Helm command. That's what I use on C-h a. – Aaron Harris Jan 11 at 22:50
up vote 3 down vote accepted

You can use selected-frame and selected-window to get the current frame and window. Also see the focus-in-hook an focus-out-hook hooks (new in Emacs 24.4) if you want to take some action when a frame gains or loses focus.

share|improve this answer
I gather that since you mention focus-in-hook there isn't any tracking of frame focus? The command description for select-frame has a "NORECORD" parameter which only mentions recently selected windows and buffers which supports that. – ebpa Jan 10 at 21:51
The buffer list order is updated when you switch buffers. I believe select-frame also calls select-window, which changes the current buffer. NORECORD is used to temporarily switch to another frame/window/buffer without changing the buffer list order. I don't think a separate ordered history is maintained for frames or windows. See also get-mru-window, which finds the most recently selected window by looking at the window-use-time, rather than by querying some ordered list. – glucas Jan 10 at 22:10
See also select-frame-set-input-focus. The selected-frame does not necessarily have the input focus. – Drew Jan 10 at 23:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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