1 ;; From: Helmut Eller <eller.helmut@gmail.com>
2 ;; Newsgroups: gnu.emacs.help
3 ;; Date: Tue, 22 Sep 2009 11:21:31 +0200
4 ;; Message-ID: <m2tyyvcp2c.fsf@gmail.com>
5 ;; Xref: news.stanford.edu gnu.emacs.help:173250
6 ;; To: help-gnu-emacs@gnu.org
7 ;; Subject: Re: Go to Emacs-Lisp Definition
9 ;; * Nordlöw [2009-09-22 11:13+0200] writes:
11 ;; > Has anyone implemented a go to (lookup) definition of an Emacs-Lisp
12 ;; > symbol: function, variable, face, etc kind of like find-tag but using
13 ;; > Emacs own symbol database (hash-table)?
15 ;; > I know that I can achieve this in Vanilla Emacs with C-h f,v, but
16 ;; > direct jump (M-.) would be more user efficient!
18 ;; I have this in my .emacs. It's some random elisp hacking stuff.
19 ;; Pick what you need.
23 (defun elisp-disassemble (function)
24 (interactive (list (function-called-at-point)))
25 (disassemble function
))
27 (defun elisp-pp (sexp)
28 (with-output-to-temp-buffer "*Pp Eval Output*"
30 (with-current-buffer standard-output
33 (defun elisp-macroexpand (form)
34 (interactive (list (form-at-point 'sexp
)))
35 (elisp-pp (macroexpand form
)))
37 (defun elisp-macroexpand-all (form)
38 (interactive (list (form-at-point 'sexp
)))
39 (elisp-pp (cl-macroexpand-all form
)))
41 (defun elisp-push-point-marker ()
43 (cond ((featurep 'xemacs
)
45 (t (ring-insert find-tag-marker-ring
(point-marker)))))
47 (defun elisp-pop-found-function ()
49 (cond ((featurep 'xemacs
) (pop-tag-mark nil
))
52 (defun elisp-find-definition (name)
53 "Jump to the definition of the function (or variable) at point."
54 (interactive (list (thing-at-point 'symbol
)))
56 (let ((symbol (intern-soft name
))
57 (search (lambda (fun sym
)
58 (let* ((r (save-excursion (funcall fun sym
)))
62 (error "Found no definition for %s in %s"
65 (switch-to-buffer buffer
)
68 (cond ((fboundp symbol
)
69 (elisp-push-point-marker)
70 (funcall search
'find-function-noselect symbol
))
72 (elisp-push-point-marker)
73 (funcall search
'find-variable-noselect symbol
))
75 (message "Symbol not bound: %S" symbol
)))))
76 (t (message "No symbol at point"))))
78 (defun elisp-bytecompile-and-load ()
81 (error "The buffer must be saved in a file first"))
83 ;; Recompile if file or buffer has changed since last compilation.
84 (when (and (buffer-modified-p)
85 (y-or-n-p (format "save buffer %s first? " (buffer-name))))
87 (let ((filename (expand-file-name buffer-file-name
)))
89 (byte-compile-file filename t
))))
91 ;; (defvar elisp-extra-keys
92 ;; '(((kbd "C-c d") 'elisp-disassemble)
93 ;; ((kbd "C-c m") 'elisp-macroexpand)
94 ;; ((kbd "C-c M") 'elisp-macroexpand-all)
95 ;; ((kbd "C-c C-c") 'compile-defun)
96 ;; ((kbd "C-c C-k") 'elisp-bytecompile-and-load)
97 ;; ((kbd "C-c C-l") 'load-file)
98 ;; ((kbd "C-c p") 'pp-eval-last-sexp)
99 ;; ((kbd "M-.") 'elisp-find-definition)
100 ;; ((kbd "M-,") 'elisp-pop-found-function)
101 ;; ((kbd "C-c <") 'list-callers)))
103 ;; (dolist (binding elisp-extra-keys)
104 ;; (let ((key (eval (car binding))) (val (eval (cadr binding))))
105 ;; (define-key emacs-lisp-mode-map key val)
106 ;; (define-key lisp-interaction-mode-map key val)))