The compile-angel Emacs package: Byte-compile and Native-compile Emacs Lisp libraries Automatically

The compile-angel Emacs package automatically byte-compiles and native-compiles Emacs Lisp libraries. It offers two global minor modes:

  • (compile-angel-on-save-mode): Compiles when an .el file is modified and saved.
  • (compile-angel-on-load-mode): Compiles an .el file before it is loaded.

These modes speed up Emacs by ensuring all libraries are byte-compiled and native-compiled. Byte-compilation reduces the overhead of loading Emacs Lisp code at runtime, while native compilation optimizes performance by generating machine code specific to your system.

NOTE: It is recommended to set load-prefer-newer to t, ensuring that Emacs loads the most recent version of byte-compiled or source files. Additionally, ensure that native compilation is enabled; this should return t: (native-comp-available-p).

What is the difference with auto-compile?

This package is an alternative to the auto-compile Emacs package. Here are the main differences:

  • Compile-angel is lightweight: The compile-angel package is lightweight, with one-third the lines of code of auto-compile.
  • Compile-angel ensures more .el files are compiled: The compile-angel package, in addition to compiling the elisp files that are loaded using load and require, also handles .el files that auto-compile misses, such as those that are deferred (e.g., with :defer t and use-package) or autoload.

(Special thanks to Jonas Bernoulli, the creator of the auto-compile package, whose work inspired the development of compile-angel. This package was created to offer a lightweight alternative to auto-compile that also compiles deferred/autoloaded .el files.)

Installation using Straight

To install compile-angel using straight.el:

  1. It if hasn’t already been done, add the straight.el bootstrap code to your init file.
  2. Add the following code at the very beginning of your Emacs init file, before anything else:
(use-package compile-angel
  :ensure t
  :straight (compile-angel
             :type git
             :host github
             :repo "jamescherti/compile-angel.el")
  :config
  (compile-angel-on-save-mode)
  (compile-angel-on-load-mode))

Links