Node:Loading Files, Next:, Previous:Keymaps, Up:Emacs Initialization



16.9 Loading Files

Many people in the GNU Emacs community have written extensions to Emacs. As time goes by, these extensions are often included in new releases. For example, the Calendar and Diary packages are now part of the standard GNU Emacs.

(Calc, which I consider a vital part of Emacs, would be part of the standard distribution except that it was so large it was packaged separately and no one has changed that.)

You can use a load command to evaluate a complete file and thereby install all the functions and variables in the file into Emacs. For example:

(load "~/emacs/slowsplit")

This evaluates, i.e. loads, the slowsplit.el file or if it exists, the faster, byte compiled slowsplit.elc file from the emacs sub-directory of your home directory. The file contains the function split-window-quietly, which John Robinson wrote in 1989.

The split-window-quietly function splits a window with the minimum of redisplay. I installed it in 1989 because it worked well with the slow 1200 baud terminals I was then using. Nowadays, I only occasionally come across such a slow connection, but I continue to use the function because I like the way it leaves the bottom half of a buffer in the lower of the new windows and the top half in the upper window.

To replace the key binding for the default split-window-vertically, you must also unset that key and bind the keys to split-window-quietly, like this:

(global-unset-key "\C-x2")
(global-set-key "\C-x2" 'split-window-quietly)

If you load many extensions, as I do, then instead of specifying the exact location of the extension file, as shown above, you can specify that directory as part of Emacs' load-path. Then, when Emacs loads a file, it will search that directory as well as its default list of directories. (The default list is specified in paths.h when Emacs is built.)

The following command adds your ~/emacs directory to the existing load path:

;;; Emacs Load Path
(setq load-path (cons "~/emacs" load-path))

Incidentally, load-library is an interactive interface to the load function. The complete function looks like this:

(defun load-library (library)
  "Load the library named LIBRARY.
This is an interface to the function `load'."
  (interactive "sLoad library: ")
  (load library))

The name of the function, load-library, comes from the use of `library' as a conventional synonym for `file'. The source for the load-library command is in the files.el library.

Another interactive command that does a slightly different job is load-file. See Lisp Libraries, for information on the distinction between load-library and this command.