23.2 Minor Modes
A minor mode is an optional editing mode that alters the behavior of Emacs in some well-defined way. Unlike major modes, any number of minor modes can be in effect at any time. Some minor modes are buffer-local, and can be turned on (enabled) in certain buffers and off (disabled) in others. Other minor modes are global: while enabled, they affect everything you do in the Emacs session, in all buffers. Most minor modes are disabled by default, but a few are enabled by default.
Most buffer-local minor modes say in the mode line when they are
enabled, just after the major mode indicator. For example,
‘ Fill
’ in the mode line means that Auto Fill mode is enabled.
See The Mode Line.
Like major modes, each minor mode is associated with a mode
command, whose name consists of the mode name followed by
‘ -mode
’. For instance, the mode command for Auto Fill mode is
auto-fill-mode
. But unlike a major mode command, which simply
enables the mode, the mode command for a minor mode can either enable
or disable it:
-
If you invoke the mode command directly with no prefix argument (either via
M-x
, or by binding it to a key and typing that key; see Customizing Key Bindings), that toggles the minor mode. The minor mode is turned on if it was off, and turned off if it was on. -
If you invoke the mode command with a prefix argument, the minor mode is unconditionally turned off if that argument is zero or negative; otherwise, it is unconditionally turned on.
-
If the mode command is called via Lisp, the minor mode is unconditionally turned on if the argument is omitted or
nil
. This makes it easy to turn on a minor mode from a major mode’s mode hook (see Major Modes). A non-nil
argument is handled like an interactive prefix argument, as described above.
Most minor modes also have a mode variable, with the same name
as the mode command. Its value is non- nil
if the mode is
enabled, and nil
if it is disabled. In general, you should not
try to enable or disable the mode by changing the value of the mode
variable directly in Lisp; you should run the mode command instead.
However, setting the mode variable through the Customize interface
(see Easy Customization Interface) will always properly enable or disable
the mode, since Customize automatically runs the mode command for you.
The following is a list of some buffer-local minor modes:
-
Abbrev mode automatically expands text based on pre-defined abbreviation definitions. See Abbrevs.
-
Auto Fill mode inserts newlines as you type to prevent lines from becoming too long. See Filling Text.
-
Auto Save mode saves the buffer contents periodically to reduce the amount of work you can lose in case of a crash. See Auto-Saving: Protection Against Disasters.
-
Electric Quote mode automatically converts quotation marks. For example, it requotes text typed
`like this'
to text‘like this’
. You can control what kind of text it operates in, and you can disable it entirely in individual buffers. See Quotation Marks. -
Enriched mode enables editing and saving of formatted text. See Enriched Text.
-
Flyspell mode automatically highlights misspelled words. See Checking and Correcting Spelling.
-
Font-Lock mode automatically highlights certain textual units found in programs. It is enabled globally by default, but you can disable it in individual buffers. See Text Faces.
-
Display Line Numbers mode is a convenience wrapper around
display-line-numbers
, setting it using the value ofdisplay-line-numbers-type
. See Customization of Display. -
Outline minor mode provides similar facilities to the major mode called Outline 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 aG
changes it to ‘FOOGAR
’, instead of producing ‘FOOGBAR
’ as usual. In Overwrite mode, the commandC-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 mode command,overwrite-mode
, is bound to theInsert
key. -
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. -
Visual Line mode performs word wrapping, causing long lines to be wrapped at word boundaries. See Visual Line Mode.
And here are some useful global minor modes:
-
Column Number mode enables display of the current column number in the mode line. See The Mode Line.
-
Delete Selection mode causes text insertion to first delete the text in the region, if the region is active. See Operating on the Region.
-
Icomplete mode displays an indication of available completions when you are in the minibuffer and completion is active. See Fast minibuffer selection.
-
Line Number mode enables display of the current line number in the mode line. It is enabled by default. See The Mode Line.
-
Menu Bar mode gives each frame a menu bar. It is enabled by default. See Menu Bars.
-
Scroll Bar mode gives each window a scroll bar. It is enabled by default, but the scroll bar is only displayed on graphical terminals. See Scroll Bars.
-
Tool Bar mode gives each frame a tool bar. It is enabled by default, but the tool bar is only displayed on graphical terminals. See Tool Bars.
-
Tab Bar mode gives each frame a tab bar. See Tab Bars.
-
Tab Line mode gives each window a tab line. See Window Tab Line.
-
Transient Mark mode highlights the region, and makes many Emacs commands operate on the region when the mark is active. It is enabled by default. See The Mark and the Region.