5

To open a buffer on the source code for a command definition, I usually follow a convoluted procedure something like this:

  • Guess the name of the mode from the function name
  • Guess the name of an elisp file involved in the implemention of that mode
  • Run M-x locate-library
  • Memorize the transiently-displayed path in the minibuffer
  • C-x C-f and type in the path name from memory
  • grep around for the function in the containing directory
  • Open the buffer
  • C-s and search for the function name to jump to the right line

What's the good way to do this?

  • 3
    C-h f function-name, then follow the link in the help buffer. – Dan Mar 19 '15 at 1:22
7

As @Dan said in his comment, if you know the name of the function, then just use C-h f plus the function name, to see a description of it. Then hit RET on, or click, the file-name link.

A more direct way is to use command find-function. You give it the function name and it takes you directly to its source code.

(I bind find-function-other-frame to C-x 5 F.)


This assumes that the function is loaded or autoloaded. If not then your approach of trying to grep for it is OK. But you don't need to memorize anything that is displayed transiently in the echo area (what you called the minibuffer - it shares the same screen space). Just C-x 4 b *Messages* to show the *Messages* buffer, where you can usually see the same message (and previous messages).

  • It was actually a blog posted that mentioned this hyperlink that prompted me to ask this question -- it didn't work for me (I saw no link). But now I realise the functions I tried happen not to have elisp installed on my system (only .elc files). – Croad Langshan Mar 19 '15 at 21:33
  • Re Messages -- I always find it both annoying to switch to that buffer, and mildly disconcerting to edit while it complains about having no undo information and continues to append more messages. I think I wish it would just leave the message there for me to copy. – Croad Langshan Mar 19 '15 at 21:37
  • You can advise function message to give it additional behavior. – Drew Mar 19 '15 at 21:43
5

The elisp-slime-nav package (also available through Melpa) will collapse all of those steps into a single keyboard shortcut: M-..

Install this package and put these lines in your init:

(require 'elisp-slime-nav)
(dolist (hook '(emacs-lisp-mode-hook ielm-mode-hook))
  (add-hook hook 'elisp-slime-nav-mode))
  • M-. will navigate you to the variable/function under point
  • M-, will bring you back

Check out its github page for more information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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