Function: add-minor-mode
add-minor-mode is a byte-compiled function defined in subr.el.gz.
Signature
(add-minor-mode TOGGLE NAME &optional KEYMAP AFTER TOGGLE-FUN)
Documentation
Register a new minor mode.
This function shouldn't be used directly -- use define-minor-mode
instead (which will then call this function).
TOGGLE is a symbol that is the name of a buffer-local variable that is toggled on or off to say whether the minor mode is active or not.
NAME specifies what will appear in the mode line when the minor mode is active. NAME should be either a string starting with a space, or a symbol whose value is such a string.
Optional KEYMAP is the keymap for the minor mode that will be added
to minor-mode-map-alist.
Optional AFTER specifies that TOGGLE should be added after AFTER
in minor-mode-alist.
Optional TOGGLE-FUN is an interactive function to toggle the mode. It defaults to (and should by convention be) TOGGLE.
If TOGGLE has a non-nil :included property, an entry for the mode is included in the mode-line minor mode menu. If TOGGLE has a :menu-tag, that is used for the menu item's label.
Probably introduced at or before Emacs version 21.1.
Source Code
;; Defined in /usr/src/emacs/lisp/subr.el.gz
(defun add-minor-mode (toggle name &optional keymap after toggle-fun)
"Register a new minor mode.
This function shouldn't be used directly -- use `define-minor-mode'
instead (which will then call this function).
TOGGLE is a symbol that is the name of a buffer-local variable that
is toggled on or off to say whether the minor mode is active or not.
NAME specifies what will appear in the mode line when the minor mode
is active. NAME should be either a string starting with a space, or a
symbol whose value is such a string.
Optional KEYMAP is the keymap for the minor mode that will be added
to `minor-mode-map-alist'.
Optional AFTER specifies that TOGGLE should be added after AFTER
in `minor-mode-alist'.
Optional TOGGLE-FUN is an interactive function to toggle the mode.
It defaults to (and should by convention be) TOGGLE.
If TOGGLE has a non-nil `:included' property, an entry for the mode is
included in the mode-line minor mode menu.
If TOGGLE has a `:menu-tag', that is used for the menu item's label."
(unless (memq toggle minor-mode-list)
(push toggle minor-mode-list))
(unless toggle-fun (setq toggle-fun toggle))
(unless (eq toggle-fun toggle)
(put toggle :minor-mode-function toggle-fun))
;; Add the name to the minor-mode-alist.
(when name
(let ((existing (assq toggle minor-mode-alist)))
(if existing
(setcdr existing (list name))
(let ((tail minor-mode-alist) found)
(while (and tail (not found))
(if (eq after (caar tail))
(setq found tail)
(setq tail (cdr tail))))
(if found
(let ((rest (cdr found)))
(setcdr found nil)
(nconc found (list (list toggle name)) rest))
(push (list toggle name) minor-mode-alist))))))
;; Add the toggle to the minor-modes menu if requested.
(when (get toggle :included)
(define-key mode-line-mode-menu
(vector toggle)
(list 'menu-item
(concat
(or (get toggle :menu-tag)
(if (stringp name) name (symbol-name toggle)))
(let ((mode-name (if (symbolp name) (symbol-value name))))
(if (and (stringp mode-name) (string-match "[^ ]+" mode-name))
(concat " (" (match-string 0 mode-name) ")"))))
toggle-fun
:button (cons :toggle toggle))))
;; Add the map to the minor-mode-map-alist.
(when keymap
(let ((existing (assq toggle minor-mode-map-alist)))
(if existing
(setcdr existing keymap)
(let ((tail minor-mode-map-alist) found)
(while (and tail (not found))
(if (eq after (caar tail))
(setq found tail)
(setq tail (cdr tail))))
(if found
(let ((rest (cdr found)))
(setcdr found nil)
(nconc found (list (cons toggle keymap)) rest))
(push (cons toggle keymap) minor-mode-map-alist)))))))