An Emacs buffer must be in exactly one major mode. It might also be in one or more minor modes that provide additional functionality.
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 LineNumbersSome do not. For example:
‘adaptive-fill-mode’‘auto-hscroll-mode’‘indent-tabs-mode’‘shift-select-mode’‘ediff-word-mode’ – Part of EdiffModeSome modes do not have a single-point of entry, but set a variable for whether they are turned on, or should be disabled.
‘isearch-mode’‘tramp-mode’The easiest way to define a minor mode is with the define-minor-mode macro from easy-mmode.el.
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