diff options
| -rw-r--r-- | lisp/emacs-lisp/easy-mmode.el | 28 | ||||
| -rw-r--r-- | test/lisp/emacs-lisp/easy-mmode-tests.el | 21 |
2 files changed, 40 insertions, 9 deletions
diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el index a707d204f8b..a5a971a6981 100644 --- a/lisp/emacs-lisp/easy-mmode.el +++ b/lisp/emacs-lisp/easy-mmode.el | |||
| @@ -84,10 +84,13 @@ replacing its case-insensitive matches with the literal string in LIGHTER." | |||
| 84 | (defconst easy-mmode--arg-docstring | 84 | (defconst easy-mmode--arg-docstring |
| 85 | " | 85 | " |
| 86 | 86 | ||
| 87 | If called interactively, enable %s if ARG is positive, and | 87 | If called interactively, toggle `%s'. If the prefix argument is |
| 88 | disable it if ARG is zero or negative. If called from Lisp, | 88 | positive, enable the mode, and if it is zero or negative, disable |
| 89 | also enable the mode if ARG is omitted or nil, and toggle it | 89 | the mode. |
| 90 | if ARG is `toggle'; disable the mode otherwise. | 90 | |
| 91 | If called from Lisp, toggle the mode if if ARG is `toggle'. | ||
| 92 | Enable the mode if ARG is nil, omitted, or is a positive number. | ||
| 93 | All other values will disable the mode. | ||
| 91 | 94 | ||
| 92 | The mode's hook is called both when the mode is enabled and when | 95 | The mode's hook is called both when the mode is enabled and when |
| 93 | it is disabled.") | 96 | it is disabled.") |
| @@ -301,13 +304,20 @@ or call the function `%s'.")))) | |||
| 301 | ,(easy-mmode--mode-docstring doc pretty-name keymap-sym) | 304 | ,(easy-mmode--mode-docstring doc pretty-name keymap-sym) |
| 302 | ;; Use `toggle' rather than (if ,mode 0 1) so that using | 305 | ;; Use `toggle' rather than (if ,mode 0 1) so that using |
| 303 | ;; repeat-command still does the toggling correctly. | 306 | ;; repeat-command still does the toggling correctly. |
| 304 | (interactive (list (or current-prefix-arg 'toggle))) | 307 | (interactive (list (if current-prefix-arg |
| 308 | (prefix-numeric-value current-prefix-arg) | ||
| 309 | 'toggle))) | ||
| 305 | (let ((,last-message (current-message))) | 310 | (let ((,last-message (current-message))) |
| 306 | (,@setter | 311 | (,@setter |
| 307 | (if (eq arg 'toggle) | 312 | (cond ((eq arg 'toggle) |
| 308 | (not ,getter) | 313 | (not ,getter)) |
| 309 | ;; A nil argument also means ON now. | 314 | ((and (numberp arg) |
| 310 | (> (prefix-numeric-value arg) 0))) | 315 | (> arg 0)) |
| 316 | t) | ||
| 317 | ((eq arg nil) | ||
| 318 | t) | ||
| 319 | (t | ||
| 320 | nil))) | ||
| 311 | ,@body | 321 | ,@body |
| 312 | ;; The on/off hooks are here for backward compatibility only. | 322 | ;; The on/off hooks are here for backward compatibility only. |
| 313 | (run-hooks ',hook (if ,getter ',hook-on ',hook-off)) | 323 | (run-hooks ',hook (if ,getter ',hook-on ',hook-off)) |
diff --git a/test/lisp/emacs-lisp/easy-mmode-tests.el b/test/lisp/emacs-lisp/easy-mmode-tests.el index 4d7fe9444fb..4a448200a2b 100644 --- a/test/lisp/emacs-lisp/easy-mmode-tests.el +++ b/test/lisp/emacs-lisp/easy-mmode-tests.el | |||
| @@ -44,6 +44,27 @@ | |||
| 44 | '(c-mode (not message-mode mail-mode) text-mode)) | 44 | '(c-mode (not message-mode mail-mode) text-mode)) |
| 45 | t)))) | 45 | t)))) |
| 46 | 46 | ||
| 47 | (ert-deftest easy-mmode--minor-mode () | ||
| 48 | (with-temp-buffer | ||
| 49 | (define-minor-mode test-mode "A test.") | ||
| 50 | (should (eq test-mode nil)) | ||
| 51 | (test-mode t) | ||
| 52 | (should (eq test-mode nil)) | ||
| 53 | (test-mode nil) | ||
| 54 | (should (eq test-mode t)) | ||
| 55 | (test-mode -33) | ||
| 56 | (should (eq test-mode nil)) | ||
| 57 | (test-mode 33) | ||
| 58 | (should (eq test-mode t)) | ||
| 59 | (test-mode 0) | ||
| 60 | (should (eq test-mode nil)) | ||
| 61 | (test-mode 'toggle) | ||
| 62 | (should (eq test-mode t)) | ||
| 63 | (test-mode 'toggle) | ||
| 64 | (should (eq test-mode nil)) | ||
| 65 | (test-mode "what") | ||
| 66 | (should (eq test-mode nil)))) | ||
| 67 | |||
| 47 | (provide 'easy-mmode-tests) | 68 | (provide 'easy-mmode-tests) |
| 48 | 69 | ||
| 49 | ;;; easy-mmode-tests.el ends here | 70 | ;;; easy-mmode-tests.el ends here |