Skip to content

Commit 91578fb

Browse files
committed
Search for definition after navigation
1 parent 03756fa commit 91578fb

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

helpful.el

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,6 @@ or disable if already enabled."
458458
(define-button-type 'helpful-navigate-button
459459
'action #'helpful--navigate
460460
'path nil
461-
'position nil
462461
'follow-link t
463462
'help-echo "Navigate to definition")
464463

@@ -471,21 +470,26 @@ If narrowing is in effect, widen if POS isn't in the narrowed area."
471470
(goto-char pos))
472471

473472
(defun helpful--navigate (button)
474-
"Navigate to the path this BUTTON represents."
475-
(find-file (substring-no-properties (button-get button 'path)))
476-
;; We use `get-text-property' to work around an Emacs 25 bug:
477-
;; http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=f7c4bad17d83297ee9a1b57552b1944020f23aea
478-
(-when-let (pos (get-text-property button 'position
479-
(marker-buffer button)))
473+
"Navigate to the definition."
474+
(-let* (((buf . pos)
475+
(if helpful--callable-p
476+
;; Don't use find-function-noselect because it follows aliases
477+
;; (which fails for built-in functions).
478+
(find-function-search-for-symbol
479+
helpful--sym
480+
nil
481+
(button-get button 'path))
482+
(find-variable-noselect helpful--sym))))
483+
(funcall helpful-switch-buffer-function buf)
484+
(run-hooks 'find-function-after-hook)
480485
(helpful--goto-char-widen pos)))
481486

482-
(defun helpful--navigate-button (text path &optional pos)
483-
"Return a button that opens PATH and puts point at POS."
487+
(defun helpful--navigate-button (text path)
488+
"Return a button that opens PATH and puts point at definition."
484489
(helpful--button
485490
text
486491
'helpful-navigate-button
487-
'path path
488-
'position pos))
492+
'path path))
489493

490494
(define-button-type 'helpful-buffer-button
491495
'action #'helpful--switch-to-buffer
@@ -2044,21 +2048,21 @@ OBJ may be a symbol or a compiled function object."
20442048
((helpful--kbd-macro-p sym) keyboard-macro-button)
20452049
(t "function")))
20462050
(defined
2047-
(cond
2048-
(buf
2049-
(let ((path (buffer-file-name buf)))
2050-
(if path
2051-
(format
2052-
"defined in %s"
2053-
(helpful--navigate-button
2054-
(file-name-nondirectory path) path pos))
2055-
(format "defined in buffer %s"
2056-
(helpful--buffer-button buf pos)))))
2057-
(primitive-p
2058-
"defined in C source code")
2059-
((helpful--kbd-macro-p sym) nil)
2060-
(t
2061-
"without a source file"))))
2051+
(cond
2052+
(buf
2053+
(let ((path (buffer-file-name buf)))
2054+
(if path
2055+
(format
2056+
"defined in %s"
2057+
(helpful--navigate-button
2058+
(file-name-nondirectory path) path))
2059+
(format "defined in buffer %s"
2060+
(helpful--buffer-button buf pos)))))
2061+
(primitive-p
2062+
"defined in C source code")
2063+
((helpful--kbd-macro-p sym) nil)
2064+
(t
2065+
"without a source file"))))
20622066

20632067
(s-word-wrap
20642068
70
@@ -2378,9 +2382,7 @@ state of the current symbol."
23782382
(when source-path
23792383
(helpful--navigate-button
23802384
(file-name-nondirectory source-path)
2381-
source-path
2382-
(or pos
2383-
0)))))
2385+
source-path))))
23842386
(cond
23852387
((and source-path references)
23862388
(format "References in %s:\n%s"
@@ -2481,8 +2483,7 @@ state of the current symbol."
24812483
'face 'font-lock-comment-face)
24822484
(helpful--navigate-button
24832485
(f-abbrev source-path)
2484-
source-path
2485-
pos)
2486+
source-path)
24862487
"\n"))
24872488
(primitive-p
24882489
(concat

0 commit comments

Comments
 (0)