Created
July 28, 2010 03:17
-
-
Save timcharper/493269 to your computer and use it in GitHub Desktop.
Invoke any command using ido in other window / split window, deciding after the fact instead of before
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; This makes ido-find-file-other-window, | |
;; ido-switch-buffer-other-window, et. al obsolete. It’s a much better | |
;; abstraction, and I believe it should become apart of ido mode, | |
;; because any command that uses ido-completing-read can benefit from | |
;; it without any additional effort, including textmate.el’s | |
;; textmate-goto-symbol. | |
(require 'ido) | |
(defun split-window-vertically-and-switch () | |
(interactive) | |
(split-window-vertically) | |
(other-window 1)) | |
(defun split-window-horizontally-and-switch () | |
(interactive) | |
(split-window-horizontally) | |
(other-window 1)) | |
(defun ido-invoke-in-other-window () | |
"signals ido mode to switch to (or create) another window after exiting" | |
(interactive) | |
(setq ido-exit-minibuffer-target-window 'other) | |
(ido-exit-minibuffer)) | |
(defun ido-invoke-in-horizontal-split () | |
"signals ido mode to split horizontally and switch after exiting" | |
(interactive) | |
(setq ido-exit-minibuffer-target-window 'horizontal) | |
(ido-exit-minibuffer)) | |
(defun ido-invoke-in-vertical-split () | |
"signals ido mode to split vertically and switch after exiting" | |
(interactive) | |
(setq ido-exit-minibuffer-target-window 'vertical) | |
(ido-exit-minibuffer)) | |
(defun ido-invoke-in-new-frame () | |
"signals ido mode to create a new frame after exiting" | |
(interactive) | |
(setq ido-exit-minibuffer-target-window 'frame) | |
(ido-exit-minibuffer)) | |
(defadvice ido-read-internal (around ido-read-internal-with-minibuffer-other-window activate) | |
(let* (ido-exit-minibuffer-target-window | |
(this-buffer (current-buffer)) | |
(result ad-do-it)) | |
(cond | |
((equal ido-exit-minibuffer-target-window 'other) | |
(if (= 1 (count-windows)) | |
(split-window-horizontally-and-switch) | |
(other-window 1))) | |
((equal ido-exit-minibuffer-target-window 'horizontal) | |
(split-window-horizontally-and-switch)) | |
((equal ido-exit-minibuffer-target-window 'vertical) | |
(split-window-vertically-and-switch)) | |
((equal ido-exit-minibuffer-target-window 'frame) | |
(make-frame))) | |
(switch-to-buffer this-buffer) ;; why? Some ido commands, such as textmate.el's textmate-goto-symbol don't switch the current buffer | |
result)) | |
(defadvice ido-init-completion-maps (after ido-init-completion-maps-with-other-window-keys activate) | |
(mapcar (lambda (map) | |
(define-key map (kbd "C-o") 'ido-invoke-in-other-window) | |
(define-key map (kbd "C-2") 'ido-invoke-in-vertical-split) | |
(define-key map (kbd "C-3") 'ido-invoke-in-horizontal-split) | |
(define-key map (kbd "C-4") 'ido-invoke-in-other-window) | |
(define-key map (kbd "C-5") 'ido-invoke-in-new-frame)) | |
(list ido-buffer-completion-map | |
ido-common-completion-map | |
ido-file-completion-map | |
ido-file-dir-completion-map))) |
I also would like to get it in MELPA. @timcharper or @zakame would post it any time soon?
@erreina sure, I can try to make mine available. For the meantime, if you're on use-package with quelpa, you can do this:
(use-package ido-other-window
:quelpa (ido-other-window :fetcher github :repo "zakame/ido-other-window"))
If @timcharper prefers, I can also post my changes as a PR to his repo, and prepare a MELPA recipe (pretty much like that quelpa quip above.)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
LOL I realized @timcharper already has it though I made my own (with just a minor change to make splitting to other-window smarter.) Still, the package is missing from MELPA (I don't recall it ever being there, unless
git log
lies...)