-
-
Save priyadarshan/2637561 to your computer and use it in GitHub Desktop.
ido-imenu as used in Emacs Rocks #10
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
(require 'thingatpt) | |
(require 'imenu) | |
(defun mine-goto-symbol-at-point () | |
"Will navigate to the symbol at the current point of the cursor" | |
(interactive) | |
(ido-goto-symbol (thing-at-point 'symbol))) | |
(defun ido-goto-symbol (&optional a-symbol) | |
"Will update the imenu index and then use ido to select a symbol to navigate to" | |
(interactive) | |
(imenu--make-index-alist) | |
(let ((name-and-pos '()) | |
(symbol-names '())) | |
(flet ((addsymbols (symbol-list) | |
(when (listp symbol-list) | |
(dolist (symbol symbol-list) | |
(let ((name nil) (position nil)) | |
(cond | |
((and (listp symbol) (imenu--subalist-p symbol)) | |
(addsymbols symbol)) | |
((listp symbol) | |
(setq name (car symbol)) | |
(setq position (cdr symbol))) | |
((stringp symbol) | |
(setq name symbol) | |
(setq position (get-text-property 1 'org-imenu-marker symbol)))) | |
(unless (or (null position) (null name)) | |
(add-to-list 'symbol-names name) | |
(add-to-list 'name-and-pos (cons name position)))))))) | |
(addsymbols imenu--index-alist)) | |
(let* ((selected-symbol | |
(if (null a-symbol) | |
(ido-completing-read "Symbol? " symbol-names) | |
a-symbol)) | |
(position (cdr (assoc selected-symbol name-and-pos)))) | |
(cond | |
((overlayp position) | |
(goto-char (overlay-start position))) | |
(t | |
(goto-char position)))))) | |
;; optionally bind these to key chords | |
(global-set-key "\C-cs" 'ido-goto-symbol) | |
(global-set-key "\C-cp" 'mine-goto-symbol-at-point) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As updated by developernotes to allow for you to conditionally pass in a symbol for it to navigate to, specifically the symbol at point. Think of it like a go to definition within the file. It uses thingatpt.