Sams Teach Yourself Emacs in 24 Hours |  | ContentsIndex
Hour 24: Installing Emacs Add-Ons |  | Previous HourNext Hour
Sections in this Hour: |  |  |  |

## Installing an Add-On

Emacs is designed in such a way that new add-ons can be easily installed. Further steps are needed for you to make use of them. Various types of lines are added to the .emacs startup file, which either load an add-on for the duration of the session or make it available when it is needed.

### Location and Paths

When Emacs is first installed, an empty directory is created just for add-on modes. It's called the site-lisp directory, and its location varies depending on which operating system you use. If you install many Emacs extensions, this directory can become crowded, making it difficult to keep track of what add-ons have been installed. This is especially true when large multifile packages, such as the W3 Web browser or AucTeX, are installed. One method of organizing the files is to keep them in separate directories and tell Emacs where they are. A statement in your .emacs file such as

    (setq load-path (cons directory load-path))

causes Emacs to look for files to load in your new directory before searching the standard Emacs Lisp directories. If you prefer that Emacs search its native directories first, use the following statement instead:

    (setq load-path (append load-path (list directory)))

The first of these examples is used when a newer version of a default Emacs mode has been installed and you want it to be used instead the default mode.

### A Sample Installation

The easiest way to understand how this works is to copy one of the add-on files that is on the CD-ROM to your site-lisp directory. Cyclebuffer.el is a short file that is used here as an example (see Figure 24.1). Open the file with Emacs, and then look for the commented-out section near the top of the file.

Figure 24.1
Cyclebuffer.el commentary.

You can skip the very first part because in most cases it contains licensing information. The information that you need is normally in a section that begins with Commentary:. A brief description of the mode's purpose is usually followed by lines that are to be inserted into your .emacs file; in this case, you see the following four lines:

    (autoload 'cyclebuffer-forward "cyclebuffer" "cycle forward" t)
    (autoload 'cyclebuffer-backward "cyclebuffer" "cycle backward" t)
    (global-set-key "\M-N" 'cyclebuffer-forward)
    (global-set-key "\M-P" 'cyclebuffer-backward)

If you copy these lines directly from the file on the CD-ROM, be sure to delete the semicolons at the beginning of each line; otherwise Emacs ignores them when it is loading the .emacs file.

After you have copied the file into a directory on your load-path and added the required lines to your .emacs file, you are ready to try the new mode. Save your .emacs file, and then type M-x load-file. When you are prompted in the minibuffer, type ~/.emacs; this causes Emacs to reread the file. Next, load several files. When you type either M-P or M-N, cyclebuffer is automatically loaded and you can use the keybindings to quickly cycle through the available buffers.

Sams Teach Yourself Emacs in 24 Hours |  | ContentsIndex
Hour 24: Installing Emacs Add-Ons |  | Previous HourNext Hour
Sections in this Hour: |  |  |  |

© Copyright Macmillan USA. All rights reserved.