Skip to content

Instantly share code, notes, and snippets.

@nmurthy
Created August 22, 2012 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmurthy/3427972 to your computer and use it in GitHub Desktop.
Save nmurthy/3427972 to your computer and use it in GitHub Desktop.
jump to dirs in ido
;; add this shiz to your .emacs to enable jumping to different directories while ido-finding with C-t
(add-hook 'ido-setup-hook 'ido-my-keys)
(defun ido-completing-read-horiz (prompt choices &optional _predicate require-match
initial-input hist def _inherit-input-method)
"do ido-completing-read, but horizontally"
(let ((old-decorations ido-decorations)
(res ""))
(setq ido-decorations '( "{" "}" " | " " | ..." "[" "]" " [No match]" " [Matched]" " [Not readable]" " [Too big]" " [Confirm]"))
(setq res (ido-completing-read prompt choices _predicate require-match initial-input hist def _inherit-input-method))
(setq ido-decorations old-decorations)
(identity res)))
(defun my-ido-search-directories ()
"Search directory list to jump to one quickly"
(interactive)
(let* ((enable-recursive-minibuffers t)
(dirlist (remove-if (lambda (x) (string= "" x)) (split-string ido-current-directory "/")))
(chosen (ido-completing-read-horiz (concat "Choose dir (" (mapconcat 'identity dirlist ",") "): ") dirlist))
(chosen-dir-start-idx (string-match chosen ido-current-directory))
(chosen-dir-end-idx (match-end 0))
(chosen-dir (substring ido-current-directory 0 chosen-dir-end-idx)))
(when chosen-dir
(ido-set-current-directory chosen-dir)
(setq ido-exit 'refresh)
(exit-minibuffer))))
(defun ido-my-keys ()
"Add my keybindings for ido."
(define-key ido-completion-map "\C-t" 'my-ido-search-directories))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment