Skip to content

Instantly share code, notes, and snippets.

@tom-seddon
Last active June 30, 2018 10:38
Show Gist options
  • Save tom-seddon/002bfe6c3fb0fc5871ff9ce28bf6a213 to your computer and use it in GitHub Desktop.
Save tom-seddon/002bfe6c3fb0fc5871ff9ce28bf6a213 to your computer and use it in GitHub Desktop.
DWIM find-function kind of affair.
;; Interactively invoke tom/find-definition-of-elisp-symbol with point on an elisp symbol.
(defvar tom/find-definition-of-elisp-symbol-history '())
(defvar tom/find-definition-of-elisp-symbol-old-marker nil)
(defun tom/find-definition-of-elisp-symbol-add-marker ()
(when tom/find-definition-of-elisp-symbol-old-marker
(ring-insert find-tag-marker-ring tom/find-definition-of-elisp-symbol-old-marker)
(setq tom/find-definition-of-elisp-symbol-old-marker nil)))
(defun tom/find-definition-of-elisp-symbol ()
(interactive)
(let* ((unksym (grep-tag-default))
(funsym (function-called-at-point))
(varsym (variable-at-point)))
(add-hook 'find-function-after-hook 'tom/find-definition-of-elisp-symbol-add-marker)
(setq tom/find-definition-of-elisp-symbol-old-marker (point-marker))
(cond
((equal (symbol-name funsym) unksym)
(find-function-do-it funsym nil 'switch-to-buffer))
((not (equal varsym 0))
(find-function-do-it varsym 'defvar 'switch-to-buffer)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment