Last active
June 30, 2018 10:38
-
-
Save tom-seddon/2d7402c56f03a89ad2f89f3d5321c573 to your computer and use it in GitHub Desktop.
ido/imenu mashup.
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
;; Interactively invoke ido-goto-symbol in a buffer that imenu understands. | |
(defun tom/get-imenu-alist () | |
;; clean up old imenu data -- bit cheeky | |
(require 'imenu) | |
(imenu--menubar-select imenu--rescan-item) | |
(imenu--make-index-alist) | |
(let ((name-and-pos '())) | |
(cl-labels ((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 | |
(let ((c (cdr symbol))) | |
(if (overlayp c) | |
(overlay-start c) | |
c)))) | |
((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)) | |
name-and-pos)) | |
(defun ido-goto-symbol () | |
"Will update the imenu index and then use ido to select a symbol to navigate to" | |
(interactive) | |
(let* ((name-and-pos (tom/get-imenu-alist)) | |
(symbol-names (mapcar 'car name-and-pos)) | |
(selected-symbol (ido-completing-read "Symbol: " symbol-names)) | |
(position (cdr (assoc selected-symbol name-and-pos)))) | |
(when (not (null position)) | |
(remember-point-in-tag-marker-ring) | |
(goto-char position)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment