-
Notifications
You must be signed in to change notification settings - Fork 0
/
symbol-at-point.el
47 lines (41 loc) · 1.83 KB
/
symbol-at-point.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
(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))))))
(global-set-key (kbd "C-x C-i") 'ido-goto-symbol)
(global-set-key (kbd "C-x C-p") 'mine-goto-symbol-at-point)