2

Sometimes I open ido-find-file or ido-switch-buffer but when I find the file I want to open, I realize I want to open it in other-window. I have key bindings for ido-find-file-other-window and others, but I would like the option to open the selected ido candidate in other-window as a persistent option in ido-completion-map (bound to s-<return>). Is this possible?

2

I finally figured out a pattern that worked by advising ido-read-internal with an empty dynamic variable that would get set with a custom command bound to ido-common-completion-map.

I published the idea as a package called ido-exit-target, but here's the pattern that solves my question:

(eval-when-compile
  (defvar ido-exit-target--target))

(defun ido-exit-target-other-window ()
  "Select the current `ido' item for `other-window'. It will create one if it doesn't exist."
  (interactive)
  (setq ido-exit-target--target 'other-window)
  (ido-exit-minibuffer))

(defun ido-exit-target--switch-to-target (orig-fun &rest args)
  "Advise `ido-read-internal' on where to view the chosen selection."
  (let* (ido-exit-target--target
         (res (apply orig-fun args)))
    (when (equal ido-exit-target--target 'other-window)
      (switch-to-buffer-other-window nil))
    res))

(advice-add 'ido-read-internal :around #'ido-exit-target--switch-to-target)

(define-key ido-common-completion-map (kbd "<s-return>") #'ido-exit-target-other-window)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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