Chapter 5. Lisp Files

Up to now, most of the Emacs Lisp we’ve written has been suitable for inclusion in your .emacs file. The alternative is to put Emacs Lisp code into files separated by functionality. This requires a little more effort to set up, but has some benefits over putting everything into .emacs:

  • Code in .emacs is always executed when Emacs starts up, even if it is never needed in a given session. This makes startup time longer and consumes memory. By contrast, a separate file of Lisp code can be loaded only when and if needed.

  • Code in .emacs typically isn’t byte-compiled. Byte-compiling is the process of turning Emacs Lisp into a more efficient form that loads faster, runs faster, and uses less memory (but which, like compiled programs in other languages, contains unreadable codes that are not meant for human eyes). Byte-compiled Lisp files usually have names ending in .elc (“Emacs Lisp, compiled”), while their non-compiled counterparts usually have names ending in .el (“Emacs Lisp”).

  • Putting everything into .emacs can cause that file to balloon over time into an impossible-to-manage jumble.

The previous chapter is a good example of a set of related functions and variables that can be encapsulated in a separate Lisp file that should only be loaded when and if needed, and that calls for byte-compilation for very efficient execution.

Creating ...

Get Writing GNU Emacs Extensions now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.