2

How can I see the code of a built-in function? I'd like to look at the code of functions such as upcase-region. I looked at the completion list that I pulled up by "find-library TAB", but the list is huge and couldn't figure out if what I'm looking for is included in it or not.

I also looked at the help of upcase-region, and it says

upcase-region is an interactive built-in function in `C source code'. 

But when I click the link `C source code', it just brings up a file selecting window with the .emacs.d folder opened, but there doesn't seem to be any file with the .c extension?

  • 1
    Did you build emacs from source yourself? If so, the link to source code should work, provided of course you haven't (re)moved the source code. I doubt that you can get what you want without building emacs from source. – Harald Hanche-Olsen Jan 17 '16 at 11:26
  • @Harald Hanche-Olsen I just downloaded the copy from emacsformacosx.com, this mean I didn't build emacs from the source, right? I'd like to use the GUI version since I can't click to move the cursor in the terminal version. But I'd also to get rid of this problem since it's recurring very often. What can I do? – stacko Jan 17 '16 at 14:10
4

It does that because you don't happen to already have a copy of the emacs source code handy; it's giving you the opportunity to go open the file yourself instead. The source is hosted on Savannah (at http://savannah.gnu.org/projects/emacs/); you can view it there or do a git clone to get a local copy.

Specifically, upcase-region is defined in casefiddle.c: http://git.savannah.gnu.org/cgit/emacs.git/tree/src/casefiddle.c#n297.

Edit: lawlist found it; you can customize the find-function-C-source-directory variable (using M-x customize-variable) to set the path where it can find the source.

  • 2
    The user may need to adjust the path in the variable find-function-C-source-directory once the source code files are placed on the local drive. – lawlist Jan 17 '16 at 16:27
  • Nice. I was reading the code in help-fns.el to try to figure out what variable it was, but it's not referenced from there. How did you find it? – db48x Jan 18 '16 at 1:01
  • I have customized just about every aspect of Emacs that I use on a regular basis, and combing through and modifying the help-related source code elisp libraries was one of the first projects that I undertook on my 3-year quest to take control of the Emacs experience. – lawlist Jan 18 '16 at 2:05

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