Loading the File

Once the code is in timestamp.el, we must arrange for its definitions to be available when we need them. This is done by loading the file, which causes Emacs to read and execute its contents. There are many ways to load Lisp files in Emacs: interactively, non-interactively, explicitly, implicitly, and with and without path-searching.

Finding Lisp Files

Emacs can load files based on full path names such as /usr/local/share/emacs/site-lisp/foo.el, but it is usually more convenient to use only a file's base name, foo.el, and let Emacs find it among the directories in the load path. The load path is simply a list of directories that Emacs searches for files to load, very much like the way the UNIX shell uses the environment variable PATH to find programs to execute. Emacs's load path is stored as a list of strings in the Lisp variable load-path.

When Emacs starts, load-path has an initial setting that looks something like the following example.

("/usr/local/share/emacs/19.34/site-lisp"
 "/usr/local/share/emacs/site-lisp"
 "/usr/local/share/emacs/19.34/lisp")

Directories in load-path are searched in the order they appear. To add a directory to the beginning of load-path, use

(setq load-path
      (cons "/your/directory/here"
            load-path))

in your .emacs file. To add a directory to the end, use

(setq load-path
      (append load-path
              '("/your/directory/here")))

Notice that in the first example, "/your/directory/here" appears as an ordinary string, but in the second example, it appears inside ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.