Sams Teach Yourself Emacs in 24 Hours |  | ContentsIndex
Hour 3: Getting Started with Emacs |  | Previous HourNext Hour
Sections in this Hour: |  |

## Modes

When you edit an HTML file, your way of working will be much different from the way you work when you write a C program. One could, in fact, develop two different editors, one for writing C programs and one for writing HTML documents. These two editors would present much duplicate work, because they'd have many similar functions. An alternative is to write one editor that can be customized in two different ways, one for writing HTML documents and one for writing C programs. This editor would have the advantage that you would be familiar with it; for example, you would have to learn only one way for searching. You might think that there exists only one way to do these things, but you are wrong. Look at some of your favorite applications and think about it.

The Emacs way of doing this is to offer major and minor editing modes for different files and programs. For example, one major mode exists for editing HTML files, and another for editing C programs. There are many different editing modes, such as cc-mode (for C and C++ programs), emacs-lisp-mode (for Emacs Lisp), and latex-mode (for LaTeX documents).

### Major Modes

Exactly one major mode is enabled at a time for a given buffer. That is, the major mode is local for each buffer, and every buffer is always in a given major mode. The major mode might contain different configurations. Most of them include the following:

- Specialized keybindings-- Many major modes redefine the meanings of the Tab and Return keys, but other keys can also be redefined. To get a list of keybindings for the major mode, press C-h m (describe-mode) when it is enabled.

- Specialized functions-- These are often available with C-c as a prefix (that is, type C-c and another key to get to the function). To see which bindings exists for the C-c prefix, press C-c C-h.

- Adding functions to menus-- Some major modes create a menu entry for the major mode functions.

- Configuration of variables-- Many different variables can be configured by the major mode. Examples of these include

> Comment characters--These are used by functions that comment out a region, for example.

> Outline regular expression--This is used by the outline library, which makes it possible to get an outline of the buffer.

> Fontification descriptions--This is a set of variables that describe how a buffer can be colorized to make it a bit more readable.

To enable a major mode, simply press M-x and type its name. You can specify which major mode should be loaded when a file is read, depending on the name of the file. This is done by configuring the variable auto-mode-alist (See Hour 22, "Learning Lisp Basics," for a description of this.)

To disable one major mode, you have to enable another one. If no major mode seems appropriate then you can enable the major mode called fundamental-mode, which is a major mode without any specialization.

### Minor Modes

Emacs has taken the customization grouping one step farther and developed a concept called minor modes. A minor mode is a set of customization options or functions that makes Emacs behave in a certain way. Any number of minor modes can be enabled at a time (this includes zero). Some minor modes are local to buffers, while others affect all of Emacs. The following list contains a few examples of some of the minor modes in Emacs:

- font-lock-mode (local for a buffer)

This mode enables fontifications of special constructs. Examples of this are hyperlinks in HTML files or keywords in C files. See Hour 12, "Visible Editing Utilities," for a description of this minor mode.

- outline-minor-mode (local for a buffer)

This mode adds functions to show an outline of a buffer that is hiding lines which are not header lines. See Hour 15 for a description of this minor mode.

- auto-fill-mode (local for a buffer)

This mode makes Emacs break your lines at a given column. See Hour 12 for a description of this mode.

- overwrite-mode (local for a buffer)

In overwrite mode, typed-in characters replace existing text on a one-for-one basis, rather than push it to the right. (Override mode can be toggled using the Insert key.)

- flyspell-mode (local for a buffer)

This mode enables on-the-fly spell checking. See Hour 11, "Editing Utilities," for a description of this mode.

- mouse-avoidance-mode (affect all buffers)

When this mode is enabled, the mouse cursor moves if it gets too close to point. Try it out; it's quite funny and can be useful to some people.

- resize-minibuffer-mode (affect all buffers)

When this mode is enabled, the minibuffer automatically resizes if the text shown in it fills more than one line.

- icomplete-mode (affect all buffers)

When this mode is enabled and you press M-x, available completions are listed as you type.

To enable or disable a minor mode, simply press M-x and type its name. Minor modes can also be turned on together with a major mode (that is, whenever the given major mode is loaded, the minor mode is loaded too). To learn how to do that, please refer to Hour 24, "Installing Emacs Add-Ons."

Sams Teach Yourself Emacs in 24 Hours |  | ContentsIndex
Hour 3: Getting Started with Emacs |  | Previous HourNext Hour
Sections in this Hour: |  |

© Copyright Macmillan USA. All rights reserved.