Emacs: What's Minor Mode

By Xah Lee. Date: . Last updated: .

Minor modes are like “preference” settings. Each minor mode changes emacs behavior or display in some way.

Each buffer/file can have more than 1 minor modes on.

Example of Minor Modes

Show Current Minor Modes

emacs describe-mode list minor modes
describe-modeCtrl+h m

Alt+x describe-modeCtrl+h m】→ list enabled minor modes of current buffer.

It's also stored in the variable minor-mode-list. (Alt+x describe-variable to see its 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

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's 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)]

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: Elisp: Check If a {function, variable, feature} is Defined/Loaded

Emacs Customization

  1. Emacs init file
  2. Install Packages
  3. Install Package Manually
  4. Define Keys
  5. M-x customize
  6. What's Major Mode?
  7. What's Minor Mode?
  8. Set File to Open in a Major Mode
  9. Organize Init File
  10. Byte Compile Elisp
  11. What's Hook?
  12. Environment Variables in Emacs
  13. Set Default Window Size
  14. Font Setup
  15. Set Color Theme
  16. Turn Off Auto Backup
  17. Check OS, Version, Host Name
  18. Check Defined/Loaded

If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy a nice keyboard: Best Keyboards for Emacs


Emacs Lisp