comparison lisp/emacs-lisp/easy-mmode.el @ 50300:7e4e15b857f3

(define-minor-mode): Use custom-set-minor-mode. Pass unknown keyword args blindly to defcustom.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Mon, 24 Mar 2003 17:41:43 +0000
parents 0d8b17d428b5
children e0775ee7f599
comparison
equal deleted inserted replaced
50299:c17e35df0d3e 50300:7e4e15b857f3
88 88
89 BODY contains code that will be executed each time the mode is (dis)activated. 89 BODY contains code that will be executed each time the mode is (dis)activated.
90 It will be executed after any toggling but before running the hooks. 90 It will be executed after any toggling but before running the hooks.
91 Before the actual body code, you can write 91 Before the actual body code, you can write
92 keyword arguments (alternating keywords and values). 92 keyword arguments (alternating keywords and values).
93 These following keyword arguments are supported: 93 These following keyword arguments are supported (other keywords
94 will be passed to `defcustom' if the minor mode is global):
94 :group GROUP Custom group name to use in all generated `defcustom' forms. 95 :group GROUP Custom group name to use in all generated `defcustom' forms.
95 :global GLOBAL If non-nil specifies that the minor mode is not meant to be 96 :global GLOBAL If non-nil specifies that the minor mode is not meant to be
96 buffer-local, so don't make the variable MODE buffer-local. 97 buffer-local, so don't make the variable MODE buffer-local.
97 By default, the mode is buffer-local. 98 By default, the mode is buffer-local.
98 :init-value VAL Same as the INIT-VALUE argument. 99 :init-value VAL Same as the INIT-VALUE argument.
99 :lighter SPEC Same as the LIGHTER argument. 100 :lighter SPEC Same as the LIGHTER argument.
100 :require SYM Same as in `defcustom'. 101 :require SYM Same as in `defcustom'.
101 102
102 For example, you could write 103 For example, you could write
103 (define-minor-mode foo-mode \"If enabled, foo on you!\" 104 (define-minor-mode foo-mode \"If enabled, foo on you!\"
104 nil \"Foo \" foo-keymap 105 :lighter \" Foo\" :require 'foo :global t :group 'hassle :version \"27.5\"
105 :require 'foo :global t :group 'inconvenience
106 ...BODY CODE...)" 106 ...BODY CODE...)"
107 107
108 ;; Allow skipping the first three args. 108 ;; Allow skipping the first three args.
109 (cond 109 (cond
110 ((keywordp init-value) 110 ((keywordp init-value)
117 (let* ((mode-name (symbol-name mode)) 117 (let* ((mode-name (symbol-name mode))
118 (pretty-name (easy-mmode-pretty-mode-name mode lighter)) 118 (pretty-name (easy-mmode-pretty-mode-name mode lighter))
119 (globalp nil) 119 (globalp nil)
120 (group nil) 120 (group nil)
121 (extra-args nil) 121 (extra-args nil)
122 (extra-keywords nil)
122 (require t) 123 (require t)
123 (keymap-sym (if (and keymap (symbolp keymap)) keymap 124 (keymap-sym (if (and keymap (symbolp keymap)) keymap
124 (intern (concat mode-name "-map")))) 125 (intern (concat mode-name "-map"))))
125 (hook (intern (concat mode-name "-hook"))) 126 (hook (intern (concat mode-name "-hook")))
126 (hook-on (intern (concat mode-name "-on-hook"))) 127 (hook-on (intern (concat mode-name "-on-hook")))
127 (hook-off (intern (concat mode-name "-off-hook")))) 128 (hook-off (intern (concat mode-name "-off-hook")))
129 keyw)
128 130
129 ;; Check keys. 131 ;; Check keys.
130 (while (keywordp (car body)) 132 (while (keywordp (setq keyw (car body)))
131 (case (pop body) 133 (setq body (cdr body))
134 (case keyw
132 (:init-value (setq init-value (pop body))) 135 (:init-value (setq init-value (pop body)))
133 (:lighter (setq lighter (pop body))) 136 (:lighter (setq lighter (pop body)))
134 (:global (setq globalp (pop body))) 137 (:global (setq globalp (pop body)))
135 (:extra-args (setq extra-args (pop body))) 138 (:extra-args (setq extra-args (pop body)))
136 (:group (setq group (nconc group (list :group (pop body))))) 139 (:group (setq group (nconc group (list :group (pop body)))))
137 (:require (setq require (pop body))) 140 (:require (setq require (pop body)))
138 (t (pop body)))) 141 (t (push keyw extra-keywords) (push (pop body) extra-keywords))))
139 142
140 (unless group 143 (unless group
141 ;; We might as well provide a best-guess default group. 144 ;; We might as well provide a best-guess default group.
142 (setq group 145 (setq group
143 `(:group ',(or (custom-current-group) 146 `(:group ',(or (custom-current-group)
159 ,(format "Non-nil if %s is enabled. 162 ,(format "Non-nil if %s is enabled.
160 See the command `%s' for a description of this minor-mode. 163 See the command `%s' for a description of this minor-mode.
161 Setting this variable directly does not take effect; 164 Setting this variable directly does not take effect;
162 use either \\[customize] or the function `%s'." 165 use either \\[customize] or the function `%s'."
163 pretty-name mode mode) 166 pretty-name mode mode)
164 :set (lambda (symbol value) (funcall symbol (or value 0))) 167 :set 'custom-set-minor-mode
165 :initialize 'custom-initialize-default 168 :initialize 'custom-initialize-default
166 ,@group 169 ,@group
167 :type 'boolean 170 :type 'boolean
168 ,@(cond 171 ,@(cond
169 ((not (and curfile require)) nil) 172 ((not (and curfile require)) nil)
170 ((not (eq require t)) `(:require ,require)) 173 ((not (eq require t)) `(:require ,require))
171 (t `(:require 174 (t `(:require
172 ',(intern (file-name-nondirectory 175 ',(intern (file-name-nondirectory
173 (file-name-sans-extension curfile))))))))) 176 (file-name-sans-extension curfile))))))
177 ,@(nreverse extra-keywords))))
174 178
175 ;; The actual function. 179 ;; The actual function.
176 (defun ,mode (&optional arg ,@extra-args) 180 (defun ,mode (&optional arg ,@extra-args)
177 ,(or doc 181 ,(or doc
178 (format (concat "Toggle %s on or off. 182 (format (concat "Toggle %s on or off.