0

Is there a list somewhere or a command that can be run to output all the functions that have been implemented in C?

zcaudate
  • 637
  • 4
  • 14
  • I think the easiest way is to clone the Emacs repo, cd to it and say `find lib lib-src lwlib nt oldXmenu src -type f -name '*.c' | xargs grep DEFUN`. I don't know of a native Emacs way. – NickD Dec 19 '20 at 03:02
  • I use the built-in `etags` utility to index the C functions and such so that I can easily jump to them when tinkering with the C code base. The `etags` utility has command line flags/options to control how the database is created. Perhaps you can have a look at the available configuration lines are and create a database containing *just* the functions that are available to the end user; e.g., defined with `defun` in C. Here is a link to creating the tags table: https://www.gnu.org/software/emacs/manual/html_node/emacs/Create-Tags-Table.html – lawlist Dec 19 '20 at 03:37
  • I'm happy to accept any of these as answers. – zcaudate Dec 19 '20 at 03:53
  • @wasamasa's answer should be considered definitive I think: the source-based answers above will probably require some trimming. E.g. on my (GNU Linux) system, the `find` based answer finds 139 entries that are not in the `mapatoms` list: some of them because they are only relevant to a different OS (`w32-*`, `msdos-*`), some of them because of configure options (e.g. my emacs is not built with `xwidget` support), some of them because of conditionally-compiled stuff (probably all the rest: that's 54 entries that I have not checked individually). – NickD Dec 19 '20 at 10:54
  • It depends what you're looking for. I've used the same approach to discover functions/variables in Emacs and it found symbols I've used in the current code as well, so I've had to filter these out. Another problem is that it relies upon what happens to be defined currently, if there was something like a subr defined in an optionally loaded module, that wouldn't be picked up before loading it up. – wasamasa Dec 19 '20 at 13:33

1 Answers1

5

You can use mapatoms to iterate over all known symbols and inspect their properties. A built-in function satisfies both symbol-function and the value of that satisfies subrp:

(let (subrs)
  (mapatoms (lambda (sym)
              (when (and (symbol-function sym)
                         (subrp (symbol-function sym)))
                (push sym subrs))))
  subrs) ;=> (charset-id-internal memory-use-counts string-make-unibyte % * + - / set-window-new-pixel minibuffer-contents-no-properties get-unused-category < ...)
wasamasa
  • 21,803
  • 1
  • 65
  • 97