diff options
| author | Stefan Monnier | 2000-11-01 23:31:59 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2000-11-01 23:31:59 +0000 |
| commit | bff5341176b5d940e1944eb84b4880ff924eefab (patch) | |
| tree | ffd187b79a8d604886f0cf1ddce870f667474fcb | |
| parent | 5de1f63dd9132efc8ab837ebe493ace420611739 (diff) | |
| download | emacs-bff5341176b5d940e1944eb84b4880ff924eefab.tar.gz emacs-bff5341176b5d940e1944eb84b4880ff924eefab.zip | |
(define-minor-mode):
Revert the latest changes.
Allow the three positional arguments to be skipped and replaced
by keyword arguments.
Add a :toggle argument to determine whether a nil arg means toggle
or means turn-on. The default is unchanged.
Add a call to force-mode-line-update.
| -rw-r--r-- | lisp/ChangeLog | 10 | ||||
| -rw-r--r-- | lisp/emacs-lisp/easy-mmode.el | 108 |
2 files changed, 54 insertions, 64 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 187bd3636a6..71384deb48d 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,13 @@ | |||
| 1 | 2000-11-01 Stefan Monnier <monnier@cs.yale.edu> | ||
| 2 | |||
| 3 | * emacs-lisp/easy-mmode.el (define-minor-mode): | ||
| 4 | Revert the latest changes. | ||
| 5 | Allow the three positional arguments to be skipped and replaced | ||
| 6 | by keyword arguments. | ||
| 7 | Add a :toggle argument to determine whether a nil arg means toggle | ||
| 8 | or means turn-on. The default is unchanged. | ||
| 9 | Add a call to force-mode-line-update. | ||
| 10 | |||
| 1 | 2000-11-01 Dave Love <fx@gnu.org> | 11 | 2000-11-01 Dave Love <fx@gnu.org> |
| 2 | 12 | ||
| 3 | * emacs-lisp/elp.el (elp-restore-function): Remove autoload | 13 | * emacs-lisp/elp.el (elp-restore-function): Remove autoload |
diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el index cc2e7525f26..a8aa499e269 100644 --- a/lisp/emacs-lisp/easy-mmode.el +++ b/lisp/emacs-lisp/easy-mmode.el | |||
| @@ -72,39 +72,46 @@ If provided LIGHTER will be used to help choose capitalization." | |||
| 72 | (defmacro define-minor-mode (mode doc &optional init-value lighter keymap &rest body) | 72 | (defmacro define-minor-mode (mode doc &optional init-value lighter keymap &rest body) |
| 73 | "Define a new minor mode MODE. | 73 | "Define a new minor mode MODE. |
| 74 | This function defines the associated control variable MODE, keymap MODE-map, | 74 | This function defines the associated control variable MODE, keymap MODE-map, |
| 75 | toggle command MODE, and hook MODE-hook. If MODE is buffer-local, then | 75 | toggle command MODE, and hook MODE-hook. |
| 76 | turn-on-MODE and turn-off-MODE commands are also generated for use in hooks, | ||
| 77 | and an optional global-MODE mode may also be generated. | ||
| 78 | 76 | ||
| 79 | DOC is the documentation for the mode toggle command. | 77 | DOC is the documentation for the mode toggle command. |
| 80 | Optional INIT-VALUE is the initial value of the mode's variable. | 78 | Optional INIT-VALUE is the initial value of the mode's variable. |
| 81 | Optional LIGHTER is displayed in the modeline when the mode is on. | 79 | Optional LIGHTER is displayed in the modeline when the mode is on. |
| 82 | Optional KEYMAP is the default (defvar) keymap bound to the mode keymap. | 80 | Optional KEYMAP is the default (defvar) keymap bound to the mode keymap. |
| 83 | If it is a list, it is passed to `easy-mmode-define-keymap' | 81 | If it is a list, it is passed to `easy-mmode-define-keymap' |
| 84 | in order to build a valid keymap. | 82 | in order to build a valid keymap. It's generally better to use |
| 83 | a separate MODE-map variable than to use this argument. | ||
| 84 | The above three arguments can be skipped if keyword arguments are | ||
| 85 | used (see below). | ||
| 86 | |||
| 85 | BODY contains code that will be executed each time the mode is (dis)activated. | 87 | BODY contains code that will be executed each time the mode is (dis)activated. |
| 86 | It will be executed after any toggling but before running the hooks. | 88 | It will be executed after any toggling but before running the hooks. |
| 87 | BODY can start with a list of CL-style keys specifying additional arguments. | 89 | BODY can start with a list of CL-style keys specifying additional arguments. |
| 88 | Currently three such keyword arguments are supported: | 90 | The following keyword arguments are supported: |
| 89 | :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'. |
| 90 | :global, followed by a value, which -- | 92 | :global If non-nil specifies that the minor mode is not meant to be |
| 91 | If `t' specifies that the minor mode is not meant to be | 93 | buffer-local. By default, the variable is made buffer-local. |
| 92 | 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 |
| 93 | If non-nil, but not `t' (for instance, `:global optionally'), then | 95 | argument, will toggle the mode rather than turn it on unconditionally. |
| 94 | specifies that the minor mode should be buffer-local, but that a | 96 | This doesn't impact the interactive behavior which is always |
| 95 | corresponding `global-MODE' function should also be added, which can | 97 | toggling (modulo prefix arg). |
| 96 | be used to turn on MODE in every buffer. | 98 | The default is (for historical reasons) to toggle, but might |
| 97 | :conditional-turn-on, followed by a function-name which turns on MODE | 99 | be changed in the future. |
| 98 | only when applicable to the current buffer. This is used in | 100 | :init-value Same as the INIT-VALUE argument. |
| 99 | conjunction with any `global-MODE' function (see :global above) when | 101 | :lighter Same as the LIGHTER argument." |
| 100 | turning on the buffer-local minor mode. By default, any generated | 102 | ;; Allow skipping the first three args. |
| 101 | `global-MODE' function unconditionally turns on the minor mode in | 103 | (cond |
| 102 | every new buffer." | 104 | ((keywordp init-value) |
| 105 | (setq body (list* init-value lighter keymap body) | ||
| 106 | init-value nil lighter nil keymap nil)) | ||
| 107 | ((keywordp lighter) | ||
| 108 | (setq body (list* lighter keymap body) lighter nil keymap nil)) | ||
| 109 | ((keywordp keymap) (push keymap body) (setq keymap nil))) | ||
| 110 | |||
| 103 | (let* ((mode-name (symbol-name mode)) | 111 | (let* ((mode-name (symbol-name mode)) |
| 104 | (pretty-name (easy-mmode-pretty-mode-name mode lighter)) | 112 | (pretty-name (easy-mmode-pretty-mode-name mode lighter)) |
| 105 | (globalp nil) | 113 | (globalp nil) |
| 106 | (define-global-mode-p nil) | 114 | (togglep t) ;why would you ever want to toggle? |
| 107 | (conditional-turn-on nil) | ||
| 108 | ;; We might as well provide a best-guess default group. | 115 | ;; We might as well provide a best-guess default group. |
| 109 | (group | 116 | (group |
| 110 | (list 'quote | 117 | (list 'quote |
| @@ -115,21 +122,15 @@ BODY contains code that will be executed each time the mode is (dis)activated. | |||
| 115 | (hook-on (intern (concat mode-name "-on-hook"))) | 122 | (hook-on (intern (concat mode-name "-on-hook"))) |
| 116 | (hook-off (intern (concat mode-name "-off-hook")))) | 123 | (hook-off (intern (concat mode-name "-off-hook")))) |
| 117 | 124 | ||
| 118 | ;; FIXME: compatibility that should be removed. | ||
| 119 | (when (and (consp init-value) (eq (car init-value) 'global)) | ||
| 120 | (setq init-value (cdr init-value) globalp t)) | ||
| 121 | |||
| 122 | ;; Check keys. | 125 | ;; Check keys. |
| 123 | (while (keywordp (car body)) | 126 | (while (keywordp (car body)) |
| 124 | (case (pop body) | 127 | (case (pop body) |
| 128 | (:init-value (setq init-value (pop body))) | ||
| 129 | (:lighter (setq lighter (pop body))) | ||
| 125 | (:global (setq globalp (pop body))) | 130 | (:global (setq globalp (pop body))) |
| 131 | (:toggle (setq togglep (pop body))) | ||
| 126 | (:group (setq group (pop body))) | 132 | (:group (setq group (pop body))) |
| 127 | (:conditional-turn-on (setq conditional-turn-on (pop body))) | 133 | (t (pop body)))) |
| 128 | (t (setq body (cdr body))))) | ||
| 129 | |||
| 130 | (when (and globalp (not (eq globalp t))) | ||
| 131 | (setq globalp nil) | ||
| 132 | (setq define-global-mode-p t)) | ||
| 133 | 134 | ||
| 134 | ;; Add default properties to LIGHTER. | 135 | ;; Add default properties to LIGHTER. |
| 135 | (unless (or (not (stringp lighter)) (get-text-property 0 'local-map lighter) | 136 | (unless (or (not (stringp lighter)) (get-text-property 0 'local-map lighter) |
| @@ -153,10 +154,11 @@ Use the function `%s' to change this variable." pretty-name mode)) | |||
| 153 | byte-compile-current-file) | 154 | byte-compile-current-file) |
| 154 | load-file-name))) | 155 | load-file-name))) |
| 155 | `(defcustom ,mode ,init-value | 156 | `(defcustom ,mode ,init-value |
| 156 | ,(format "Toggle %s. | 157 | ,(format "Toggle %s on or off. |
| 158 | See the command `%s' for a description of this minor-mode. | ||
| 157 | Setting this variable directly does not take effect; | 159 | Setting this variable directly does not take effect; |
| 158 | use either \\[customize] or the function `%s'." | 160 | use either \\[customize] or the function `%s'." |
| 159 | pretty-name mode) | 161 | pretty-name mode mode) |
| 160 | :set (lambda (symbol value) (funcall symbol (or value 0))) | 162 | :set (lambda (symbol value) (funcall symbol (or value 0))) |
| 161 | :initialize 'custom-initialize-default | 163 | :initialize 'custom-initialize-default |
| 162 | :group ,group | 164 | :group ,group |
| @@ -178,15 +180,16 @@ use either \\[customize] or the function `%s'." | |||
| 178 | ;; The actual function. | 180 | ;; The actual function. |
| 179 | (defun ,mode (&optional arg) | 181 | (defun ,mode (&optional arg) |
| 180 | ,(or doc | 182 | ,(or doc |
| 181 | (format "With no argument, toggle %s. | 183 | (format (concat "Toggle %s on or off. |
| 182 | With universal prefix ARG turn mode on. | 184 | Interactively, with no prefix argument, toggle the mode. |
| 185 | With universal prefix ARG " (unless togglep "(or if ARG is nil) ") "turn mode on. | ||
| 183 | With zero or negative ARG turn mode off. | 186 | With zero or negative ARG turn mode off. |
| 184 | \\{%s}" pretty-name keymap-sym)) | 187 | \\{%s}") pretty-name keymap-sym)) |
| 185 | (interactive "P") | 188 | (interactive (list (or current-prefix-arg (if ,mode 0 1)))) |
| 186 | (setq ,mode | 189 | (setq ,mode |
| 187 | (if arg | 190 | (if arg |
| 188 | (> (prefix-numeric-value arg) 0) | 191 | (> (prefix-numeric-value arg) 0) |
| 189 | (not ,mode))) | 192 | ,(if togglep `(not ,mode) t))) |
| 190 | ,@body | 193 | ,@body |
| 191 | ;; The on/off hooks are here for backward compatibility only. | 194 | ;; The on/off hooks are here for backward compatibility only. |
| 192 | (run-hooks ',hook (if ,mode ',hook-on ',hook-off)) | 195 | (run-hooks ',hook (if ,mode ',hook-on ',hook-off)) |
| @@ -194,32 +197,9 @@ With zero or negative ARG turn mode off. | |||
| 194 | (if (interactive-p) | 197 | (if (interactive-p) |
| 195 | (message ,(format "%s %%sabled" pretty-name) | 198 | (message ,(format "%s %%sabled" pretty-name) |
| 196 | (if ,mode "en" "dis"))) | 199 | (if ,mode "en" "dis"))) |
| 200 | (force-mode-line-update) | ||
| 197 | ,mode) | 201 | ,mode) |
| 198 | 202 | ||
| 199 | ,(unless globalp | ||
| 200 | (let ((turn-on (intern (concat "turn-on-" mode-name))) | ||
| 201 | (turn-off (intern (concat "turn-off-" mode-name)))) | ||
| 202 | `(progn | ||
| 203 | (defun ,turn-on () | ||
| 204 | ,(format "Turn on %s. | ||
| 205 | |||
| 206 | This function is designed to be added to hooks, for example: | ||
| 207 | (add-hook 'text-mode-hook '%s)" | ||
| 208 | pretty-name | ||
| 209 | turn-on) | ||
| 210 | (interactive) | ||
| 211 | (,mode t)) | ||
| 212 | (defun ,turn-off () | ||
| 213 | ,(format "Turn off %s." pretty-name) | ||
| 214 | (interactive) | ||
| 215 | (,mode -1)) | ||
| 216 | ,(when define-global-mode-p | ||
| 217 | `(easy-mmode-define-global-mode | ||
| 218 | ,(intern (concat "global-" mode-name)) | ||
| 219 | ,mode | ||
| 220 | ,(or conditional-turn-on turn-on) | ||
| 221 | :group ,group))))) | ||
| 222 | |||
| 223 | ;; Autoloading an easy-mmode-define-minor-mode autoloads | 203 | ;; Autoloading an easy-mmode-define-minor-mode autoloads |
| 224 | ;; everything up-to-here. | 204 | ;; everything up-to-here. |
| 225 | :autoload-end | 205 | :autoload-end |
| @@ -237,7 +217,7 @@ This function is designed to be added to hooks, for example: | |||
| 237 | ,(if keymap keymap-sym | 217 | ,(if keymap keymap-sym |
| 238 | `(if (boundp ',keymap-sym) | 218 | `(if (boundp ',keymap-sym) |
| 239 | (symbol-value ',keymap-sym)))) | 219 | (symbol-value ',keymap-sym)))) |
| 240 | 220 | ||
| 241 | ;; If the mode is global, call the function according to the default. | 221 | ;; If the mode is global, call the function according to the default. |
| 242 | ,(if globalp `(if ,mode (,mode 1)))))) | 222 | ,(if globalp `(if ,mode (,mode 1)))))) |
| 243 | 223 | ||
| @@ -248,7 +228,7 @@ This function is designed to be added to hooks, for example: | |||
| 248 | ;;;###autoload | 228 | ;;;###autoload |
| 249 | (defmacro easy-mmode-define-global-mode (global-mode mode turn-on | 229 | (defmacro easy-mmode-define-global-mode (global-mode mode turn-on |
| 250 | &rest keys) | 230 | &rest keys) |
| 251 | "Make GLOBAL-MODE out of the MODE buffer-local minor mode. | 231 | "Make GLOBAL-MODE out of the buffer-local minor MODE. |
| 252 | TURN-ON is a function that will be called with no args in every buffer | 232 | TURN-ON is a function that will be called with no args in every buffer |
| 253 | and that should try to turn MODE on if applicable for that buffer. | 233 | and that should try to turn MODE on if applicable for that buffer. |
| 254 | KEYS is a list of CL-style keyword arguments: | 234 | KEYS is a list of CL-style keyword arguments: |