A minor mode is often appropriate for use with more than one major mode. It sometimes adds functionality that is orthogonal to that provided by the major mode. For example, font-lock (minor) mode provides syntax-sensitive highlighting; it can be used with most major modes to provide appropriate highlighting (see EnablingFontLock).
Most minor modes have a command that turns them on and off. For example:
‘delete-selection-mode’– see DeleteSelectionMode
‘auto-fill-mode’– see AutoFillMode
‘font-lock-mode’– see EnablingFontLock
‘line-number-mode’– see LineNumbers
Some do not. For example:
‘ediff-word-mode’– Part of EdiffMode
Some modes do not have a single-point of entry, but set a variable for whether they are turned on, or should be disabled.
The easiest way to define a minor mode is with the
define-minor-mode macro from
How do I check whether a given minor mode is active?
Test the value of the mode variable. Example:
(if delete-selection-mode ...)
The mode variable might not be known, so you can add this protection:
(if (boundp 'unknown-mode) (if unknown-mode) ...))
Caution: I am 99% sure of this idiom, but can someone check it and then remove this notice.
But some minor modes don’t have a variable, e.g., auto-fill-mode. – rubikitch
True. I was going to say “File a bug”, but checking the code defining
‘auto-fill-mode’ I see this comment:
(put 'auto-fill-function :minor-mode-function 'auto-fill-mode) ;; FIXME: turn into a proper minor mode. ;; Add a global minor mode version of it. (defun auto-fill-mode (&optional arg) ...
So I guess the answer is: (1) file a bug, (2) volunteer to fix the code. ;-) – DrewAdams