Unless you've compiled your Emacs you have to download the C source code separately. If you're on GNU, some distros allow downloading the source code using the package manager, which makes upgrading a bit easier. For example here's a tutorial for installing the source code on Fedora.
Once you have the source code tree in a directory, say ~/src/emacs-27.1/src
, add
(setq find-function-C-source-directory (concat "~/src/emacs-" emacs-version "/src"))
to your init.el. The (concat "~/src/emacs-" emacs-version "/src")
bit evaluates to "~/src/emacs-27.1/src"
(assuming your Emacs is version 27.1), so you don't need to update this setting when you upgrade Emacs. The variable find-function-C-source-directory
stores the directory Emacs looks into for the C source files (see C-hv find-function-C-source-directory
).
Since you're on MacOS I can't suggest anything in particular but to try
git clone https://git.savannah.gnu.org/git/emacs.git
That should get you the full source tree. Place it on a directory of your choice and set find-function-C-source-directory
, then both xref-find-definitions
and links in describe-function
/describe-variable
(C-h f
/C-h v
) and should work.