14

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?

Dan
  • 32,584
  • 6
  • 98
  • 168
MonsieurBanana
  • 488
  • 2
  • 7

1 Answers1

4

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.

glucas
  • 20,175
  • 1
  • 51
  • 83
  • 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. – MonsieurBanana Nov 13 '14 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 Nov 13 '14 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 Nov 13 '14 at 20:26
  • See also: http://emacs.stackexchange.com/questions/2194/how-do-i-force-a-specific-buffer-to-open-in-a-new-window – glucas Nov 14 '14 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. – MonsieurBanana Nov 16 '14 at 12:47
  • Yeah, I haven't quite sorted it out either. But seems like it should be possible! – glucas Nov 16 '14 at 16:59