Created
January 16, 2017 05:37
-
-
Save matthew-ball/984849d85b72557c70ddfed936cce317 to your computer and use it in GitHub Desktop.
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 'imenu) | |
(defun goto-symbol (&optional symbol-list) | |
(interactive) | |
(cond | |
((not symbol-list) | |
(let (name-and-pos symbol-names position) | |
(while (progn | |
(imenu--cleanup) | |
(setq imenu--index-alist nil) | |
(goto-symbol (imenu--make-index-alist)) | |
(setq selected-symbol (ido-completing-read "Go to symbol: " symbol-names)) | |
(string= (car imenu--rescan-item) selected-symbol))) | |
(unless (and (boundp 'mark-active) mark-active) | |
(push-mark nil t nil)) | |
(setq position (cdr (assoc selected-symbol name-and-pos))) | |
(cond | |
((overlayp position) (goto-char (overlay-start position))) | |
(t(goto-char position))))) | |
((listp symbol-list) | |
(dolist (symbol symbol-list) | |
(let (name position) | |
(cond | |
((and (listp symbol) (imenu--subalist-p symbol)) (goto-symbol 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) (string= (car imenu--rescan-item) name)) | |
(add-to-list 'symbol-names name) | |
(add-to-list 'name-and-pos (cons name position)))))))) | |
(global-set-key (kbd "C-c s") #'goto-symbol) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment