4

I want to see the source code of the function other-buffer. When I use M-x- xref-find-definitions, Emacs shows:visit tags table (default TAGS). Then I press RET, Emacs shows:File /TAGS does not exist.
What should I do if I want to see the source code?
I'm reading an introduction book and I got stuck with the expression:
(other-buffer (current-buffer) t)
This is why I want to see the source code. And this is my second day learning Emacs.

System: macOS

3
  • Are you on Linux, Mac or Windows?
    – nephewtom
    Jan 14 at 14:39
  • @nephewtom MacOS
    – Lluvio Liu
    Jan 18 at 6:13
  • Honestly, if you are an Emacs newcomer, I would not recommend starting with its C source code.
    – nephewtom
    Jan 18 at 14:02
2

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.

1

Usually the way to do that is to type M-x describe-function in the minibuffer, then enter other-buffer. That will show you a help window on the function with the documentation on that function. At the top is usually a link to the source code of the function you can click on to get there. other-buffer is implemented in the C source code though so you unless you installed emacs from source you probably can't get to it this way.

2
  • There's been discussion about always installing the C-sources precisely for this use case. Disk space is cheap after all (but the distributions would probably just strip it out again <sigh>)
    – rpluim
    Jan 14 at 10:48
  • 2
    See also M-x find-function RET.
    – Basil
    Jan 14 at 11:26

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.