I've been looking into trimming down the sets of symbols exported and imported by each C source file in Emacs, down to the list of symbols that are actually needed. This should make it easier to read the code, and to do better static analysis, and shrink Emacs a bit by removing unused cruft. The resulting analysis will need more thinking and will comprise several patches (I don't know how many yet, as I've only started turning the crank). I have found several glitches in Emacs so far. For example, font.c's functions copy-font-spec and merge-font-spec are defined via DEFUN in a strange way at the C level, so that they are not visible to Lisp. It's been that way for nearly three years, so I assume the simplest way to fix this is to rename the functions so that they don't look to the C programmer as if they're visible to Lisp. Other problems include unreachable functions and unused variables. There is a bit of technology needed to get this working, namely, we need a way to mark Lisp-visible functions either static or external at the C level. Usually they're static, but often they need to be external because other C modules call them directly. To do this, I changed DEFUN so that it generates static functions, and added a new macro DEFUE that generates external functions (i.e., DEFUE acts like the old DEFUN). I chose the name DEFUE because the "E" stands for "external", "DEFUE" is the same length as "DEFUN" (so that indenting need not change), and "DEFUE" starts with "DEFU" (so that the make-docfile need not change). But if people would prefer another identifier (DEFUNEX, say?) it'd be easy to change. Here's the key part of the first patch: --- src/lisp.h 2011-04-09 18:42:31 +0000 +++ src/lisp.h 2011-04-11 00:46:54 +0000 @@ -1804,8 +1804,12 @@ `doc' is documentation for the user. */ /* This version of DEFUN declares a function prototype with the right - arguments, so we can catch errors with maxargs at compile-time. */ -#define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc) \ + arguments, so we can catch errors with maxargs at compile-time. + DEFUN defines an internal function, and DEFUE is similar but defines a + external function, which can be used in other C-language modules. */ +#define DEFUN static DEFINE_FUNC +#define DEFUE extern DEFINE_FUNC +#define DEFINE_FUNC(lname, fnname, sname, minargs, maxargs, intspec, doc) \ Lisp_Object fnname DEFUN_ARGS_ ## maxargs ; \ DECL_ALIGN (struct Lisp_Subr, sname) = \ { PVEC_SUBR | (sizeof (struct Lisp_Subr) / sizeof (EMACS_INT)), \ @@ -2279,6 +2283,8 @@ appropriate prototype. */ #define EXFUN(fnname, maxargs) \ extern Lisp_Object fnname DEFUN_ARGS_ ## maxargs +#define INFUN(fnname, maxargs) \ + static Lisp_Object fnname DEFUN_ARGS_ ## maxargs /* Forward declarations for prototypes. */ struct window; and here's an example use of the new DEFUE macro: --- src/lread.c 2011-04-04 07:48:36 +0000 +++ src/lread.c 2011-04-11 00:41:52 +0000 @@ -681,7 +681,7 @@ return val; } -DEFUN ("read-char", Fread_char, Sread_char, 0, 3, 0, +DEFUE ("read-char", Fread_char, Sread_char, 0, 3, 0, doc: /* Read a character from the command input (keyboard or macro). It is returned as a number. If the character has modifiers, they are resolved and reflected to the I'm attaching the entire patch, gzipped, as most of it is pretty mechanical substitution of DEFUE for DEFUN. Comments, as usual, are welcome.