ido/imenu mashup.
| ;; 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