When I switch buffers, emacs will switch to an existing frame if the buffer is already opened there.

I found how to prevent that when switching with ido using :

(setq ido-default-buffer-method 'selected-window)

But it's not enough : for exemple if there's a lisp error emacs will automatically switch to the buffer *Backtrace*, and will switch frames if it's already open.

Is there a way to prevent completely emacs from switching to an existent frame?

1 Answer 1


There does not appear to be an option for this.

The function to find a buffer does allow you to specify whether to look in all frames or only in the current frame:

(get-buffer-window &optional BUFFER-OR-NAME ALL-FRAMES)

However, the implementation of switch-to-buffer passes 0 for the ALL-FRAMES argument, which means it will look in all frames.

I suppose you could use :around advice with get-buffer-window to replace that argument, if you truly wanted to globally prevent this behavior... but I suspect that would break other things.

  • That's what I feared. I might try the add-advice around get-buffer-window, but I'm not too fond of advising widely used functions. Commented Nov 13, 2014 at 19:17
  • Yeah, seems likely to cause trouble. You might want to check out the popwin package as a way of dealing with special buffers -- not sure if that plus the ido config you already found might be sufficient.
    – glucas
    Commented Nov 13, 2014 at 19:26
  • 1
    Actually, I may have missed the boat here. You should take a look at the Emacs manual sections on 'Choosing Window' and 'Display Action Functions'. In particular, the use of inhibit-switch-frame seems useful. (I have not had a chance to experiment with these options yet.)
    – glucas
    Commented Nov 13, 2014 at 20:26
  • See also: emacs.stackexchange.com/questions/2194/…
    – glucas
    Commented Nov 14, 2014 at 14:48
  • Thanks, that SE thread is very helpful. The documentation for display-buffer and display-buffer-alist makes my head hurt, but it's only a question of time until I find a solution. Commented Nov 16, 2014 at 12:47

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.