Emacs modules are dynamically-loaded libraries written in C. (They were introduced in Emacs 25.1.)
From the Emacs 25.1
Emacs can now load shared/dynamic libraries (modules). A dynamic Emacs module is a shared library that provides additional functionality for use in Emacs Lisp programs, just like a package written in Emacs Lisp would. The functions
load-file, etc. were extended to load such modules, as they do with Emacs Lisp packages. The new variable
module-file-suffixholds the system-dependent value of the file-name extension (
.soon Posix hosts) of the module files.
A module should export a C-callable function named
emacs_module_init, which Emacs will call as part of the call to
requirewhich loads the module. It should also export a symbol named
plugin_is_GPL_compatibleto indicate that its code is released under the GPL or compatible license; Emacs will refuse to load modules that don't export such a symbol.
If a module needs to call Emacs functions, it should do so through the API defined and documented in the header file
emacs-module.h. Note that any module that provides Lisp-callable functions will have to use Emacs functions such as
funcall, in order to register its functions with the Emacs Lisp interpreter.
Modules can create
user-ptrLisp objects that embed pointers to C structs defined by the module. This is useful for keeping around complex data structures created by a module, to be passed back to the module's functions. User-ptr objects can also have associated "finalizers" -- functions to be run when the object is GC'ed; this is useful for freeing any resources allocated for the underlying data structure, such as memory, open file descriptors, etc. A new predicate
user-ptrpreturns non-nil if its argument is a
Loadable modules in Emacs are an experimental feature, and subject to change in future releases. For that reason, their support is disabled by default, and must be enabled by using the
--with-modulesoption at configure time.
See also the
email@example.com thread good examples of Emacs modules?.