From 2a4b0da28c3d25f2eea17c9dc95f7a244bdf4535 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Sun, 1 Nov 2020 15:00:36 +0100 Subject: 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. --- lisp/emacs-lisp/easy-mmode.el | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'lisp/emacs-lisp/easy-mmode.el') 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." (defconst easy-mmode--arg-docstring " -If called interactively, enable %s if ARG is positive, and -disable it if ARG is zero or negative. If called from Lisp, -also enable the mode if ARG is omitted or nil, and toggle it -if ARG is `toggle'; disable the mode otherwise. +If called interactively, toggle `%s'. If the prefix argument is +positive, enable the mode, and if it is zero or negative, disable +the mode. + +If called from Lisp, toggle the mode if if ARG is `toggle'. +Enable the mode if ARG is nil, omitted, or is a positive number. +All other values will disable the mode. The mode's hook is called both when the mode is enabled and when it is disabled.") @@ -301,13 +304,20 @@ or call the function `%s'.")))) ,(easy-mmode--mode-docstring doc pretty-name keymap-sym) ;; Use `toggle' rather than (if ,mode 0 1) so that using ;; repeat-command still does the toggling correctly. - (interactive (list (or current-prefix-arg 'toggle))) + (interactive (list (if current-prefix-arg + (prefix-numeric-value current-prefix-arg) + 'toggle))) (let ((,last-message (current-message))) (,@setter - (if (eq arg 'toggle) - (not ,getter) - ;; A nil argument also means ON now. - (> (prefix-numeric-value arg) 0))) + (cond ((eq arg 'toggle) + (not ,getter)) + ((and (numberp arg) + (> arg 0)) + t) + ((eq arg nil) + t) + (t + nil))) ,@body ;; The on/off hooks are here for backward compatibility only. (run-hooks ',hook (if ,getter ',hook-on ',hook-off)) -- cgit v1.2.3 From 8761c155e43c08428054677c75781e312a728667 Mon Sep 17 00:00:00 2001 From: Glenn Morris Date: Sun, 1 Nov 2020 09:39:44 -0800 Subject: * lisp/emacs-lisp/easy-mmode.el (easy-mmode--arg-docstring): Doc typo. --- lisp/emacs-lisp/easy-mmode.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp/emacs-lisp/easy-mmode.el') diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el index a5a971a6981..77f10e61c6c 100644 --- a/lisp/emacs-lisp/easy-mmode.el +++ b/lisp/emacs-lisp/easy-mmode.el @@ -88,7 +88,7 @@ If called interactively, toggle `%s'. If the prefix argument is positive, enable the mode, and if it is zero or negative, disable the mode. -If called from Lisp, toggle the mode if if ARG is `toggle'. +If called from Lisp, toggle the mode if ARG is `toggle'. Enable the mode if ARG is nil, omitted, or is a positive number. All other values will disable the mode. -- cgit v1.2.3 From 5cea77af41b59ba6f6386264812c36ec31ba2efc Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Mon, 2 Nov 2020 10:17:08 +0100 Subject: Partially revert previous define-minor-mode change * lisp/emacs-lisp/easy-mmode.el (easy-mmode--arg-docstring): Only document the values we want to support, not the ones we actually support. (define-minor-mode): Partially revert to previous behaviour. --- lisp/emacs-lisp/easy-mmode.el | 10 ++++------ test/lisp/emacs-lisp/easy-mmode-tests.el | 10 ++-------- 2 files changed, 6 insertions(+), 14 deletions(-) (limited to 'lisp/emacs-lisp/easy-mmode.el') diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el index 77f10e61c6c..261f2508af7 100644 --- a/lisp/emacs-lisp/easy-mmode.el +++ b/lisp/emacs-lisp/easy-mmode.el @@ -90,7 +90,7 @@ the mode. If called from Lisp, toggle the mode if ARG is `toggle'. Enable the mode if ARG is nil, omitted, or is a positive number. -All other values will disable the mode. +Disable the mode if ARG is a negative number. The mode's hook is called both when the mode is enabled and when it is disabled.") @@ -312,12 +312,10 @@ or call the function `%s'.")))) (cond ((eq arg 'toggle) (not ,getter)) ((and (numberp arg) - (> arg 0)) - t) - ((eq arg nil) - t) + (< arg 1)) + nil) (t - nil))) + t))) ,@body ;; The on/off hooks are here for backward compatibility only. (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 4a448200a2b..c05379e4415 100644 --- a/test/lisp/emacs-lisp/easy-mmode-tests.el +++ b/test/lisp/emacs-lisp/easy-mmode-tests.el @@ -48,22 +48,16 @@ (with-temp-buffer (define-minor-mode test-mode "A test.") (should (eq test-mode nil)) - (test-mode t) - (should (eq test-mode nil)) (test-mode nil) (should (eq test-mode t)) (test-mode -33) (should (eq test-mode nil)) (test-mode 33) (should (eq test-mode t)) - (test-mode 0) - (should (eq test-mode nil)) - (test-mode 'toggle) - (should (eq test-mode t)) (test-mode 'toggle) (should (eq test-mode nil)) - (test-mode "what") - (should (eq test-mode nil)))) + (test-mode 'toggle) + (should (eq test-mode t)))) (provide 'easy-mmode-tests) -- cgit v1.2.3