I currently use the following custom command to navigate between windows and frames:

(defun nispio/other-window (&optional arg)
  "With prefix argument, select the next frame. Otherwise, select the next window"
  (interactive "P")
  (if arg (other-frame 1) (other-window 1)))
(global-set-key (kbd "C-\\") 'nispio/other-window)

This allows me to jump between windows with C-\ and between frames with C-u C-\. But what I would really like is a command that will let me cycle through all of the windows, regardless of the frame that the window is in. Given the following window configuration:

             Frame 1                         Frame 2
   +---------------------------+       +------------------+
   +------------+--------------+       +------------------+
   |            |              |       |                  |
   |  Window 1  |   Window 2   |       |                  |
   |            |              |       |                  |
   |            |              |       |     Window 4     |
   |            |              |       |                  |
   +------------+--------------+       |                  |
   |         Window 3          |       |                  |
   |                           |       |                  |
   +---------------------------+       +------------------+

I want a command that freely cycles between window 1 - 2 - 3 - 4 - and back to 1 again. I don't want to have to think about which frame a window belongs to in order to cycle through them. Does such a command exist?


3 Answers 3


You're almost there: other-window takes an optional second argument which, if it has the value t, says to cycle through windows on all frames. You can also use the symbol visible to consider only visible frames, or the integer 0 to consider only visible or iconified frames. So replace (other-window 1) by (other-window 1 t) or (other-window 1 'visible).

There is a wrinkle, which is that Emacs tends to defer to the operating system's windowing system's rules for selecting a frame. From the documentation of select-frame:

The selection of frame lasts until the next time the user does something to select a different frame, or until the next time this function is called. (If you are using a window system, the previously selected frame may be restored as the selected frame after return to the command loop, because it still may have the window system's input focus.)

So when the interactive command that triggered a call to other-window returns, the selected frame may be restored. To avoid this, call select-frame-set-input-focus.

(other-window 1 t)
(select-frame-set-input-focus (selected-frame))

Actually, such a command does exist: next-multiframe-window
Bind it to some key, maybe C-x o, and that's all.

By the way, previous-multiframe-window does the same thing, but cycles in the reverse order.


If you use library Icicles then C-x o (bound to multi-command icicle-other-window-or-frame) does what you describe, when you use it only for cycling. To include all windows on all visible frames, use a plain prefix arg (C-u C-x o). To include all windows on any frame (including iconified and invisible frames), use C-u C-u C-x o.

(You do not cycle by repeating this key. You use the key once, then you cycle among candidates using C-down or similar.)

You asked only for cycling, but the command lets you also (1) choose a window by name (with completion) or (2) narrow the set of windows to cycle through by filtering on their names (on the fly). Whatever windows have names that match your current minibuffer input are those that are candidates, and those you can cycle through. You can cycle through any subsequence of those, and you can do so in different orders (you can sort the candidates in different ways).

  • What is "Cycling"? Can you more info about that in the new tag's wiki? Commented Mar 27, 2015 at 19:55
  • @kaushalmodi: I added a tags wiki entry. Feel free to edit it. The point is that the general operation of cycling among the members of a sequence can apply to different kinds of objects and actions on them.
    – Drew
    Commented Mar 27, 2015 at 20:05

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.