In Emacs Lisp, how to find where the symbol is defined

elisp, emacs

Solution

Some digging reveals that

(find-lisp-object-file-name object type)

Should do the trick. As an example:

(find-lisp-object-file-name 'goto-line 'function)
;; => "/usr/local/Cellar/emacs/24.3/share/emacs/24.3/lisp/simple.el"

EDIT: How I discovered this information:

First I did `C-h k C-h f` to figure out what `C-h f` is bound to. The result is `describe-function`, so let's do `C-h f describe-function` to see the source for that. I noticed that it was essentially an interactive wrapper around `describe-function-1`, so I jumped to the source for that. There's a lot of stuff in there, but the pertinent line is:

(file-name (find-lisp-object-file-name function def))

Revealing that `find-lisp-object-file-name` is the function used to do this work internally.

Problem

When I do `C-h f` or `C-h v`, Help tells me in which file the symbol is defined or where it will be autoloaded from. How can I find the same information programmatically?

Original source