Emacs: What is Minor Mode
Minor modes are like “preference” settings. Each minor mode changes emacs behavior or some way. The behavior change may be keys, or mouse behavior, or editing behavior, or visual display, or it can be anything emacs does.
Each buffer/file can have more than 1 minor modes on.
Example of Minor Modes
mouse-wheel-mode
(enable mouse wheel) [see Emacs: Mouse Config]font-lock-mode
(syntax coloring) [see Emacs Lisp: Font Lock Mode Basics]abbrev-mode
[see Emacs: Abbrev Mode by Lisp Code]delete-selection-mode
(typing overrides text selection if exist)electric-pair-mode
[see Emacs: Insert Bracket Pairs, electric-pair-mode]global-auto-revert-mode
(automatically update buffer if files changed on disk by others)subword-mode
[see Emacs: Move Cursor by camelCase, snake_case]ido-mode
[see Emacs: ido mode in emacs 27]display-line-numbers-mode
[see Emacs: Show Line Numbers]
Show Current Minor Modes

describe-mode
Alt+x describe-mode
Ctrl+h m→ list enabled minor modes of current buffer.
- minor-mode-list
- variable. Value is a list of all minor mode functions. [see Emacs: Show Variable Value]
Turn On/Off Minor Mode
Minor modes typically have a command to turn it on/off.
For example, linum-mode
is a command to turn on/off line numbers in margin.
[see Emacs: Show Line Numbers]
Global Minor Mode vs Current Buffer
- Some minor mode are global. That is, for every buffer. There is no per buffer on/off. For example,
show-paren-mode
. [see Emacs: Insert Bracket Pairs, electric-pair-mode] - Some minor mode are per buffer, For example,
linum-mode
to toggle for current buffer, andglobal-linum-mode
to toggle for all buffers. [see Emacs: Show Line Numbers]
For those per-buffer minor modes, it may not have a command to toggle on/off for all buffers. For example, auto-fill-mode
will toggle for current buffer, but no global command.
If you want to turn a minor mode globally but it doesn't have a global toggle, you have to write a hook.
[see Emacs: What is Hook]
Turn On/Off Minor Mode in Emacs Init
When calling a mode function in init file, give it a argument 1
to turn on, and 0
for off, like this:
(global-linum-mode 1)
Note: the argument to minor mode changed in emacs 23.2 [see Emacs 23.2 Features (released 2010-05)]
- Before emacs 23.2: when called in lisp code, no arg means toggle, same as when called interactively.
- After emacs 23.2: when called in lisp code, no arg will turn on. Arg of nil will also turn on.
Current State of a Minor Mode
Typically, if a mode has a command named “xyz-mode”, it also has a variable of the same name “xyz-mode”. Its value is t if the mode is on, else nil. You can check this variable for the mode's on/off state.
If you want to turn on/off a mode, call the function, not set the variable. For example:
(global-linum-mode 1) ; GOOD (setq global-linum-mode t) ; WRONG! (setq global-linum-mode 1) ; WRONG!
If you also need to check if a mode (package) is loaded, see: Emacs Lisp: Check If a function/variable is Defined