emacs ido switch window/frame problem

By Xah Lee. Date: . Last updated: .

ido started to have a very annoying behavior about a year ago.

That is, if you switch buffer (ido-switch-buffer), and if the buffer already exist in another window (that is, emacs's “frame”), ido will switch you to THAT window.

it's like, oops, what? what happened? did somebody just pull the rug out of me?

very annoying. When this happens and if you don't want to work on that window, you have to close the buffer, switch back to the window you were on, then open that file again.

i don't use switch buffer often so i didn't bother to dig. Today i did, the cause is this:

ido switch buffer will use the variable ido-default-file-method. Its value determines how it would switch.

Call describe-variable to see its doc.

it says:

ido-default-file-method is a variable defined in ‘ido.el’.
Its value is ‘maybe-frame’
Original value was raise-frame

Documentation:
How to visit a new file when using ‘ido-find-file’.
Possible values:
‘selected-window’ Show new file in selected window
‘other-window’    Show new file in another window (same frame)
‘display’         Display file in another window without selecting to it
‘other-frame’     Show new file in another frame
‘maybe-frame’     If a file is visible in another frame, prompt to ask if you
                  you want to see the file in the same window of the current
                  frame or in the other frame
‘raise-frame’     If a file is visible in another frame, raise that
                  frame; otherwise, visit the file in the same window

You can customize this variable.

[back]

but doesn't work.

try:

;; (setq ido-default-file-method 'selected-window)
;; (setq ido-default-file-method 'other-window)
;; (setq ido-default-file-method 'display)
(setq ido-default-file-method 'maybe-frame)

it'll work if you try to open a file, but not when switching buffer.

i havn't digged further…, but my juice for investigating this annoyance is dry.

Solution

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

Thanks to Clément Pit-Claudel for the rescue!