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

## Filenames and Interpreters

Many modes are designed to work with files that normally have a particular filename suffix. For example, Python source files usually have the suffix .py, so it makes sense for these files to be edited in python-mode.

Some add-ons need a line that tells Emacs to associate filenames that have a certain suffix with a particular mode. A line similar to the following

    (setq auto-mode-alist (cons '("\\.chp?$" . text-mode)auto-mode-alist))

causes any files with the suffix .chp to be automatically edited in text-mode. auto-mode-alist is a list that is automatically loaded when Emacs starts up. This list tells the editor which mode to use for files with various suffixes. A statement such as the previous example adds a new item to this internal list.

Similar to auto-mode-alist is interpreter-mode-alist. This is an internal list of command interpreters that are to be associated with executable scripts. These scripts often have the name of the interpreter in the first line, prefixed by #!. When Emacs loads a file with this type of first line, it attempts to use the major mode that is associated with the name of the interpreter, as in the following example:

    (setq interpreter-mode-alist (cons '"tash" . sh-mode)auto-mode-alist))

This line causes shell scripts that are intended for the (imaginary) tash command shell to be automatically opened in sh-mode, which is a mode that is used for all shell scripts.

The contents of either of these lists can be viewed by typing C-h v, which is a request for help with Emacs variables. When you are prompted in the minibuffer, type either auto-mode or interpreter-mode, and then press the Tab key, which completes the variable name. A Help window appears, displaying the contents of the requested list.

Any of the preceding statements can be suggested by a particular add-on mode. After you have added the needed lines to your .emacs file, reload the file as described previously. Now you can use the new mode.

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.