aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2020-11-01 15:00:36 +0100
committerLars Ingebrigtsen2020-11-01 15:00:44 +0100
commit2a4b0da28c3d25f2eea17c9dc95f7a244bdf4535 (patch)
tree64edec589c630abdceb2061996094361c1e971b0
parentecec9a259b13d88fa23dde078fba99ae78ef79c7 (diff)
downloademacs-2a4b0da28c3d25f2eea17c9dc95f7a244bdf4535.tar.gz
emacs-2a4b0da28c3d25f2eea17c9dc95f7a244bdf4535.zip
Make minor mode ARG work as documented
* lisp/emacs-lisp/easy-mmode.el (easy-mmode--arg-docstring): Clarify when minor modes are switched on/off when called from lisp (bug#44341). (define-minor-mode): Make calls from Lisp switch the mode on/off as documented.
-rw-r--r--lisp/emacs-lisp/easy-mmode.el28
-rw-r--r--test/lisp/emacs-lisp/easy-mmode-tests.el21
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
87If called interactively, enable %s if ARG is positive, and 87If called interactively, toggle `%s'. If the prefix argument is
88disable it if ARG is zero or negative. If called from Lisp, 88positive, enable the mode, and if it is zero or negative, disable
89also enable the mode if ARG is omitted or nil, and toggle it 89the mode.
90if ARG is `toggle'; disable the mode otherwise. 90
91If called from Lisp, toggle the mode if if ARG is `toggle'.
92Enable the mode if ARG is nil, omitted, or is a positive number.
93All other values will disable the mode.
91 94
92The mode's hook is called both when the mode is enabled and when 95The mode's hook is called both when the mode is enabled and when
93it is disabled.") 96it 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