diff options
| author | Stefan Monnier | 2000-11-03 04:26:33 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2000-11-03 04:26:33 +0000 |
| commit | 0a74e3bf900ff44e70a914b965f3c16b63a5463e (patch) | |
| tree | 04fe65280b7a9f2106ef6b7712fce3ea2b8e6394 | |
| parent | 9c887adacf57efd199e5930cb8f519de6256f583 (diff) | |
| download | emacs-0a74e3bf900ff44e70a914b965f3c16b63a5463e.tar.gz emacs-0a74e3bf900ff44e70a914b965f3c16b63a5463e.zip | |
(define-minor-mode): Remove :toggle arg.
Correctly handle the case where several :group args are supplied.
Allow :extra-args.
(easy-mmode-define-global-mode): Allow :extra-args.
Correctly handle the case where several :group args are supplied.
| -rw-r--r-- | lisp/emacs-lisp/easy-mmode.el | 57 |
1 files changed, 28 insertions, 29 deletions
diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el index a8aa499e269..4d6897fc1d5 100644 --- a/lisp/emacs-lisp/easy-mmode.el +++ b/lisp/emacs-lisp/easy-mmode.el | |||
| @@ -91,12 +91,6 @@ BODY contains code that will be executed each time the mode is (dis)activated. | |||
| 91 | :group Followed by the group name to use for any generated `defcustom'. | 91 | :group Followed by the group name to use for any generated `defcustom'. |
| 92 | :global If non-nil specifies that the minor mode is not meant to be | 92 | :global If non-nil specifies that the minor mode is not meant to be |
| 93 | buffer-local. By default, the variable is made buffer-local. | 93 | buffer-local. By default, the variable is made buffer-local. |
| 94 | :toggle If non-nil means the minor-mode function, when called with a nil | ||
| 95 | argument, will toggle the mode rather than turn it on unconditionally. | ||
| 96 | This doesn't impact the interactive behavior which is always | ||
| 97 | toggling (modulo prefix arg). | ||
| 98 | The default is (for historical reasons) to toggle, but might | ||
| 99 | be changed in the future. | ||
| 100 | :init-value Same as the INIT-VALUE argument. | 94 | :init-value Same as the INIT-VALUE argument. |
| 101 | :lighter Same as the LIGHTER argument." | 95 | :lighter Same as the LIGHTER argument." |
| 102 | ;; Allow skipping the first three args. | 96 | ;; Allow skipping the first three args. |
| @@ -112,10 +106,8 @@ BODY contains code that will be executed each time the mode is (dis)activated. | |||
| 112 | (pretty-name (easy-mmode-pretty-mode-name mode lighter)) | 106 | (pretty-name (easy-mmode-pretty-mode-name mode lighter)) |
| 113 | (globalp nil) | 107 | (globalp nil) |
| 114 | (togglep t) ;why would you ever want to toggle? | 108 | (togglep t) ;why would you ever want to toggle? |
| 115 | ;; We might as well provide a best-guess default group. | 109 | (group nil) |
| 116 | (group | 110 | (extra-args nil) |
| 117 | (list 'quote | ||
| 118 | (intern (replace-regexp-in-string "-mode\\'" "" mode-name)))) | ||
| 119 | (keymap-sym (if (and keymap (symbolp keymap)) keymap | 111 | (keymap-sym (if (and keymap (symbolp keymap)) keymap |
| 120 | (intern (concat mode-name "-map")))) | 112 | (intern (concat mode-name "-map")))) |
| 121 | (hook (intern (concat mode-name "-hook"))) | 113 | (hook (intern (concat mode-name "-hook"))) |
| @@ -128,10 +120,15 @@ BODY contains code that will be executed each time the mode is (dis)activated. | |||
| 128 | (:init-value (setq init-value (pop body))) | 120 | (:init-value (setq init-value (pop body))) |
| 129 | (:lighter (setq lighter (pop body))) | 121 | (:lighter (setq lighter (pop body))) |
| 130 | (:global (setq globalp (pop body))) | 122 | (:global (setq globalp (pop body))) |
| 131 | (:toggle (setq togglep (pop body))) | 123 | (:extra-args (setq extra-args (pop body))) |
| 132 | (:group (setq group (pop body))) | 124 | (:group (setq group (nconc group (list :group (pop body))))) |
| 133 | (t (pop body)))) | 125 | (t (pop body)))) |
| 134 | 126 | ||
| 127 | (unless group | ||
| 128 | ;; We might as well provide a best-guess default group. | ||
| 129 | (setq group | ||
| 130 | `(:group ',(intern (replace-regexp-in-string "-mode\\'" "" | ||
| 131 | mode-name))))) | ||
| 135 | ;; Add default properties to LIGHTER. | 132 | ;; Add default properties to LIGHTER. |
| 136 | (unless (or (not (stringp lighter)) (get-text-property 0 'local-map lighter) | 133 | (unless (or (not (stringp lighter)) (get-text-property 0 'local-map lighter) |
| 137 | (get-text-property 0 'keymap lighter)) | 134 | (get-text-property 0 'keymap lighter)) |
| @@ -161,7 +158,7 @@ use either \\[customize] or the function `%s'." | |||
| 161 | pretty-name mode mode) | 158 | pretty-name mode mode) |
| 162 | :set (lambda (symbol value) (funcall symbol (or value 0))) | 159 | :set (lambda (symbol value) (funcall symbol (or value 0))) |
| 163 | :initialize 'custom-initialize-default | 160 | :initialize 'custom-initialize-default |
| 164 | :group ,group | 161 | ,@group |
| 165 | :type 'boolean | 162 | :type 'boolean |
| 166 | ,@(when curfile | 163 | ,@(when curfile |
| 167 | (list | 164 | (list |
| @@ -170,15 +167,8 @@ use either \\[customize] or the function `%s'." | |||
| 170 | (intern (file-name-nondirectory | 167 | (intern (file-name-nondirectory |
| 171 | (file-name-sans-extension curfile))))))))) | 168 | (file-name-sans-extension curfile))))))))) |
| 172 | 169 | ||
| 173 | ;; The toggle's hook. Wrapped in `progn' to prevent autoloading. | ||
| 174 | (progn | ||
| 175 | (defcustom ,hook nil | ||
| 176 | ,(format "Hook run at the end of function `%s'." mode-name) | ||
| 177 | :group ,group | ||
| 178 | :type 'hook)) | ||
| 179 | |||
| 180 | ;; The actual function. | 170 | ;; The actual function. |
| 181 | (defun ,mode (&optional arg) | 171 | (defun ,mode (&optional arg ,@extra-args) |
| 182 | ,(or doc | 172 | ,(or doc |
| 183 | (format (concat "Toggle %s on or off. | 173 | (format (concat "Toggle %s on or off. |
| 184 | Interactively, with no prefix argument, toggle the mode. | 174 | Interactively, with no prefix argument, toggle the mode. |
| @@ -204,6 +194,12 @@ With zero or negative ARG turn mode off. | |||
| 204 | ;; everything up-to-here. | 194 | ;; everything up-to-here. |
| 205 | :autoload-end | 195 | :autoload-end |
| 206 | 196 | ||
| 197 | ;; The toggle's hook. | ||
| 198 | (defcustom ,hook nil | ||
| 199 | ,(format "Hook run at the end of function `%s'." mode-name) | ||
| 200 | :group ,(cadr group) | ||
| 201 | :type 'hook) | ||
| 202 | |||
| 207 | ;; Define the minor-mode keymap. | 203 | ;; Define the minor-mode keymap. |
| 208 | ,(unless (symbolp keymap) ;nil is also a symbol. | 204 | ,(unless (symbolp keymap) ;nil is also a symbol. |
| 209 | `(defvar ,keymap-sym | 205 | `(defvar ,keymap-sym |
| @@ -233,23 +229,26 @@ TURN-ON is a function that will be called with no args in every buffer | |||
| 233 | and that should try to turn MODE on if applicable for that buffer. | 229 | and that should try to turn MODE on if applicable for that buffer. |
| 234 | KEYS is a list of CL-style keyword arguments: | 230 | KEYS is a list of CL-style keyword arguments: |
| 235 | :group to specify the custom group." | 231 | :group to specify the custom group." |
| 236 | (let* ((mode-name (symbol-name mode)) | 232 | (let* ((global-mode-name (symbol-name global-mode)) |
| 237 | (global-mode-name (symbol-name global-mode)) | ||
| 238 | (pretty-name (easy-mmode-pretty-mode-name mode)) | 233 | (pretty-name (easy-mmode-pretty-mode-name mode)) |
| 239 | (pretty-global-name (easy-mmode-pretty-mode-name global-mode)) | 234 | (pretty-global-name (easy-mmode-pretty-mode-name global-mode)) |
| 240 | ;; We might as well provide a best-guess default group. | 235 | (group nil) |
| 241 | (group | 236 | (extra-args nil) |
| 242 | (list 'quote | ||
| 243 | (intern (replace-regexp-in-string "-mode\\'" "" mode-name)))) | ||
| 244 | (buffers (intern (concat global-mode-name "-buffers"))) | 237 | (buffers (intern (concat global-mode-name "-buffers"))) |
| 245 | (cmmh (intern (concat global-mode-name "-cmmh")))) | 238 | (cmmh (intern (concat global-mode-name "-cmmh")))) |
| 246 | 239 | ||
| 247 | ;; Check keys. | 240 | ;; Check keys. |
| 248 | (while (keywordp (car keys)) | 241 | (while (keywordp (car keys)) |
| 249 | (case (pop keys) | 242 | (case (pop keys) |
| 250 | (:group (setq group (pop keys))) | 243 | (:extra-args (setq extra-args (pop keys))) |
| 244 | (:group (setq group (nconc group (list :group (pop keys))))) | ||
| 251 | (t (setq keys (cdr keys))))) | 245 | (t (setq keys (cdr keys))))) |
| 252 | 246 | ||
| 247 | (unless group | ||
| 248 | ;; We might as well provide a best-guess default group. | ||
| 249 | (setq group | ||
| 250 | `(:group ',(intern (replace-regexp-in-string "-mode\\'" "" | ||
| 251 | (symbol-name mode)))))) | ||
| 253 | `(progn | 252 | `(progn |
| 254 | ;; The actual global minor-mode | 253 | ;; The actual global minor-mode |
| 255 | (define-minor-mode ,global-mode | 254 | (define-minor-mode ,global-mode |
| @@ -258,7 +257,7 @@ With prefix ARG, turn %s on if and only if ARG is positive. | |||
| 258 | %s is actually not turned on in every buffer but only in those | 257 | %s is actually not turned on in every buffer but only in those |
| 259 | in which `%s' turns it on." | 258 | in which `%s' turns it on." |
| 260 | pretty-name pretty-global-name pretty-name turn-on) | 259 | pretty-name pretty-global-name pretty-name turn-on) |
| 261 | nil nil nil :global t :group ,group | 260 | :global t :extra-args ,extra-args ,@group |
| 262 | 261 | ||
| 263 | ;; Setup hook to handle future mode changes and new buffers. | 262 | ;; Setup hook to handle future mode changes and new buffers. |
| 264 | (if ,global-mode | 263 | (if ,global-mode |