Previous: Mode Variables and Commands, Up: Major Modes [Index]
Every major mode, apart from ‘Fundamental’ mode, defines a mode hook, a customizable list of Lisp functions to run each time the mode is enabled in a buffer.
Each mode hook is named after its major mode, e.g., Fortran mode has
fortran-mode-hook
. Furthermore, all text-based major modes run
text-mode-hook
, and many programming language modes (including all those
distributed with Emacs) run prog-mode-hook
, prior to running their own mode
hooks. Hook functions can look at the value of the variable major-mode
to see
which mode is actually being entered.
Mode hooks are commonly used to enable minor modes. For example, you can put
the following lines in your init
file to enable ‘Flyspell’ minor mode in all
text-based major modes (see Spelling), and ‘ElDoc’ minor mode in Emacs Lisp
mode (see Lisp Doc):
(add-hook 'text-mode-hook 'flyspell-mode) (add-hook 'emacs-lisp-mode-hook 'eldoc-mode)