summaryrefslogtreecommitdiff
path: root/lisp/subr.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2000-09-29 03:23:49 +0000
committerStefan Monnier <monnier@iro.umontreal.ca>2000-09-29 03:23:49 +0000
commit0b2cf11f544cf39b7e79ca9a049027557f6921a0 (patch)
treedae144f0a794af0a3e47304df09fa4dd1a3ed345 /lisp/subr.el
parent76c64e2476b0096e0508beeb43512475ce4f8874 (diff)
downloademacs-0b2cf11f544cf39b7e79ca9a049027557f6921a0.tar.gz
(add-minor-mode): Don't eval NAME.
Don't depend on the presence of TOGGLE-FUN for any special behavior. Use if rather than cond.
Diffstat (limited to 'lisp/subr.el')
-rw-r--r--lisp/subr.el99
1 files changed, 49 insertions, 50 deletions
diff --git a/lisp/subr.el b/lisp/subr.el
index 0078709cc42..4d0cef6a087 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -1497,6 +1497,8 @@ If DIR-FLAG is non-nil, create a new empty directory instead of a file."
(defun add-minor-mode (toggle name &optional keymap after toggle-fun)
"Register a new minor mode.
+This is an XEmacs-compatibility function. Use `define-minor-mode' instead.
+
TOGGLE is a symbol which is the name of a buffer-local variable that
is toggled on or off to say whether the minor mode is active or not.
@@ -1510,64 +1512,61 @@ 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. If
-supplied, it is used to make mouse clicks on the mode-line string turn
-off the mode.
-
-If TOGGLE-FUN is supplied and 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 instead of NAME.
-
-In most cases, `define-minor-mode' should be used instead."
+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 toggle-fun (setq toggle-fun toggle))
+ ;; 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
+ (or (get toggle :menu-tag)
+ (if (stringp name) name (symbol-name toggle)))
+ toggle-fun
+ :button (cons :toggle toggle))))
+ ;; Add the name to the minor-mode-alist.
(when name
- (let ((existing (assq toggle minor-mode-alist))
- (name (if (symbolp name) (symbol-value name) name)))
- (when (functionp toggle-fun)
+ (let ((existing (assq toggle minor-mode-alist)))
+ (when (and (stringp name) (not (get-text-property 0 'local-map name)))
(setq name
(apply 'propertize name
'local-map (make-mode-line-mouse2-map toggle-fun)
(unless (get-text-property 0 'help-echo name)
(list 'help-echo
- (format "mouse-2: turn off %S" toggle)))))
- (when (get toggle :included)
- (define-key mode-line-mode-menu
- (vector toggle)
- (list 'menu-item
- (or (get toggle :menu-tag) name)
- toggle-fun
- :button (cons :toggle toggle)))))
- (cond ((null existing)
- (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))
- (setq minor-mode-alist (cons (list toggle name)
- minor-mode-alist)))))
- (t
- (setcdr existing (list name))))))
-
+ (format "mouse-2: turn off %S" toggle))))))
+ (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))
+ (setq minor-mode-alist (cons (list toggle name)
+ minor-mode-alist)))))))
+ ;; Add the map to the minor-mode-map-alist.
(when keymap
(let ((existing (assq toggle minor-mode-map-alist)))
- (cond ((null existing)
- (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))
- (setq minor-mode-map-alist (cons (cons toggle keymap)
- minor-mode-map-alist)))))
- (t
- (setcdr existing keymap))))))
+ (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))
+ (setq minor-mode-map-alist (cons (cons toggle keymap)
+ minor-mode-map-alist))))))))
;;; subr.el ends here