Windows 10, Emacs 25.1. Path to Emacs: d:\Programs\emacs

I write on Elisp. And very ofter I want by any key press go to Emacs lisp function. E.g. Here snippet of my elisp file:

(setq line (buffer-substring (point) (point-at-eol)))

I want when cursor is over function "buffer-substring" and press some key combination go to source file of this function. When I try M-. It's not jump to source file, but prompt me.

Here screenshot:

enter image description here

How I can do this?

  • 1
    Did you try M-.? This should work in recent Emacs out of the box. If this doesn't, then you could M-h f and then from the help buffer press RET on the file name which defined the function.
    – wvxvw
    Commented Aug 1, 2017 at 11:27
  • Yes, but it prompt me "Emacs C source dir". What is this?
    – Alex
    Commented Aug 1, 2017 at 11:34
  • buffer-substring is a c function and you have to specify the source directory with (setq find-function-C-source-directory "/path/to/c-source")
    – bertfred
    Commented Aug 1, 2017 at 12:11
  • This means the function was defined in C, rather than Emacs Lisp. If you have C sources of Emacs, you can set them as bertfred showed. Normally, if you build Emacs yourself, this variable is already set.
    – wvxvw
    Commented Aug 1, 2017 at 13:05
  • 1
    I try another function "delete-directory" and because it's a Elisp function it's success jump to source file (files.el). OK. But I not have C sources of Emacs functions (Windows 10). So where I can dowlnload C sources of Emacs functions?
    – Alex
    Commented Aug 1, 2017 at 13:12

1 Answer 1


xref-find-definitions is normally the function you'd use, and by default, it is bound to M-.. xref package provides generic means of locating and navigating source files. But how it handles this depends on the backend associated with the major mode of the buffer you are editing. Emacs Lisp mode does provide a backend: elisp--xref-backend function. But I'm not sure when exactly was it added. I think it wasn't there, at least not by default in Emacs 24 and older.

If you don't have Emacs Lisp backend for xref, then you can use Emacs' interactive help to locate the functions' source: move the point to the function's name (otherwise you will be able to answer the prompt with the name of the function you want to locate the source of), and press C-h f. This will display a help buffer with the function's description. You can then move the point to the file name; pressing RET on the file name will bring up the buffer with the contents of the file and move the point to the function's definition.

Elisp functions can be defined in several ways, sometimes source location may not be available, or it will require extra work. One such example is a function defined in C sources. As point out by bertfred, in order to locate a function in C source code, Emacs needs to know where it is located, i.e. the variable find-function-C-source-directory must be set to the location of the Emacs source. If you don't have the C source, you can download it from https://github.com/emacs-mirror/emacs or the official GNU site: http://ftpmirror.gnu.org/emacs/


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.