55

I tried to edit my init file. Is there any possible way to quickly jump into function definition of other .el file that has already loaded/required ?

I remember doing this once, but don't remember how...

4 Answers 4

64

M-x find-function RET (function name) RET

I find that C-h C-f makes a good keybinding for find-function (given that C-h f is bound by default to describe-function)

(global-set-key (kbd "C-h C-f") 'find-function)

5
  • This only works for functions that have been loaded, or one that is set up for auto loading. Nov 19, 2010 at 16:42
  • Indeed, but it seemed like the best answer given that the question was specifically about loaded elisp functions, and it doesn't require the extra step of generating a TAGS file.
    – phils
    Nov 20, 2010 at 0:11
  • 2
    I just had this exact question, thanks much. I also discovered that there's also find-function-at-point (in emacs 23, at least). I bound this to C-h C-f and it works great! Jun 6, 2011 at 14:01
  • 2
    Some similarly useful functions are: find-function-on-key, find-variable, and find-library.
    – phils
    Oct 2, 2011 at 12:16
  • If you don't want to have this as a global hotkey, but in emacs-lisp major modes only: (add-hook 'emacs-lisp-mode-hook (lambda () (local-set-key (kbd "M-.") 'find-function-at-point)))
    – hraban
    Nov 16, 2020 at 16:22
10

As of emacs-25.1, there's a new generic function xref-find-definitions. The xref built-in package provides a generic framework for navigating definitions in code. Probably, it'd take some time for every mode to adjust custom functions for this framework, but, at the very least, emacs-lisp-mode already ported.

3
  • 1
    Awesome! There was no inverse of find-function-at-point AFAIK which really annoyed me. Now it works the way I want! (The inverse of xref-find-definitions is xref-pop-marker-stack) Mar 4, 2018 at 21:10
  • unfortunately it wont work with tags files generated from .el.gz files.
    – RichieHH
    Apr 4, 2021 at 10:35
  • @RichieHH are you sure ctags/etags support indexing .el.gz files? Out of curiosity I just made a single derectory with an arbitrary elisp file add-log.el.tar.gz, and when I do ctags -eR . and etags add-log.el.tar.gz, the resulting TAGS file has no definitions.
    – Hi-Angel
    Apr 4, 2021 at 11:00
5

etags [options] file1 file2 ... and then, from inside emacs, do M-. to visit the tag. To go the the next occurrence of the tag, do M-,.

1
  • 2
    You probably meant M-. there :) Not M-x .
    – VitoshKa
    Nov 19, 2010 at 6:41
4

find-function is the way to go. An alternative is to use C-h f, then click the file name in buffer *Help*.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.