57.1 Minor Modes
Minor modes are optional features which you can turn on or off. For
example, Auto Fill mode is a minor mode in which <SPC> breaks lines
between words as you type. All the minor modes are independent of each
other and of the selected major mode. Most minor modes say in the mode
line when they are on; for example, ‘Fill’ in the mode line means
that Auto Fill mode is on.
Append -mode
to the name of a minor mode to get the name of a
command that turns the mode on or off. Thus, the command to
enable or disable Auto Fill mode is called auto-fill-mode
. These
commands are usually invoked with M-x, but you can bind keys to them
if you wish. With no argument, the function turns the mode on if it was
off and off if it was on. This is known as toggling. A positive
argument always turns the mode on, and an explicit zero argument or a
negative argument always turns it off.
Some minor modes are global: while enabled, they affect everything
you do in the Emacs session, in all buffers. Other minor modes are
buffer-local; they apply only to the current buffer, so you can enable
the mode in certain buffers and not others.
For most minor modes, the command name is also the name of a
variable. The variable's value is non-nil
if the mode is
enabled and nil
if it is disabled. Some minor-mode commands
work by just setting the variable. For example, the command
abbrev-mode
works by setting the value of abbrev-mode
as
a variable; it is this variable that directly turns Abbrev mode on and
off. You can directly set the variable's value instead of calling the
mode function. For other minor modes, you need to either set the
variable through the Customize interface or call the mode function to
correctly enable or disable the mode. To check which of these two
possibilities applies to a given minor mode, use C-h v to ask
for documentation on the variable name.
For minor mode commands that work by just setting the minor mode
variable, that variable provides a good way for Lisp programs to turn
minor modes on and off; it is also useful in a file's local variables
list (see File Variables). But please think twice before setting
minor modes with a local variables list, because most minor modes are
a matter of user preference—other users editing the same file might
not want the same minor modes you prefer.
The most useful buffer-local minor modes include Abbrev mode, Auto
Fill mode, Auto Save mode, Font-Lock mode, Glasses mode, ISO Accents
mode, Outline minor mode, Overwrite mode, and Binary Overwrite mode.
Abbrev mode allows you to define abbreviations that automatically expand
as you type them. For example, ‘amd’ might expand to ‘abbrev
mode’. See Abbrevs, for full information.
Auto Fill mode allows you to enter filled text without breaking lines
explicitly. Emacs inserts newlines as necessary to prevent lines from
becoming too long. See Filling.
Auto Save mode causes the contents of a buffer to be saved
periodically to reduce the amount of work you can lose in case of a
system crash. See Auto Save.
Enriched mode enables editing and saving of formatted text.
See Formatted Text.
Flyspell mode automatically highlights misspelled words.
See Spelling.
Font-Lock mode automatically highlights certain textual units found in
programs, such as comments, strings, and function names being defined.
This requires a window system that can display multiple fonts.
See Faces.
ISO Accents mode makes the characters ‘`’, ‘'’, ‘"’,
‘^’, ‘/’ and ‘~’ combine with the following letter, to
produce an accented letter in the ISO Latin-1 character set. The
newer and more general feature of input methods more or less
supersedes ISO Accents mode. See Single-Byte Character Support.
Outline minor mode provides the same facilities as the major mode
called Outline mode; but since it is a minor mode instead, you can
combine it with any major mode. See Outline Mode.
Overwrite mode causes ordinary printing characters to replace existing
text instead of shoving it to the right. For example, if point is in
front of the ‘B’ in ‘FOOBAR’, then in Overwrite mode typing a
G changes it to ‘FOOGAR’, instead of producing ‘FOOGBAR’
as usual. In Overwrite mode, the command C-q inserts the next
character whatever it may be, even if it is a digit—this gives you a
way to insert a character instead of replacing an existing character.
The command overwrite-mode
is an exception to the rule that
commands which toggle minor modes are normally not bound to keys: it is
bound to the <INSERT> function key. This is because many other
programs bind <INSERT> to similar functions.
Binary Overwrite mode is a variant of Overwrite mode for editing
binary files; it treats newlines and tabs like other characters, so that
they overwrite other characters and can be overwritten by them.
In Binary Overwrite mode, digits after C-q specify an
octal character code, as usual.
Here are some useful minor modes that normally apply to all buffers
at once. Since Line Number mode and Transient Mark mode can be
enabled or disabled just by setting the value of the minor mode
variable, you can set them differently for particular buffers,
by explicitly making the corresponding variable local in those
buffers. See Locals.
Icomplete mode displays an indication of available completions when
you are in the minibuffer and completion is active. See Completion Options.
Line Number mode enables continuous display in the mode line of the
line number of point, and Column Number mode enables display of the
column number. See Mode Line.
Scroll Bar mode gives each window a scroll bar (see Scroll Bars).
Menu Bar mode gives each frame a menu bar (see Menu Bars). Both of
these modes are enabled by default when you use the X Window System.
In Transient Mark mode, every change in the buffer contents
“deactivates” the mark, so that commands that operate on the region
will get an error. This means you must either set the mark, or
explicitly “reactivate” it, before each command that uses the region.
The advantage of Transient Mark mode is that Emacs can display the
region highlighted. See Mark.