aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorF. Jason Park2023-05-15 00:16:00 -0700
committerF. Jason Park2023-07-13 18:45:31 -0700
commit30fe8703e60d0b756c19f52a6758889600b7b396 (patch)
tree8a7fd1fb2abf09b7145bce1e0108c89033219476
parente51e43b7046b56c58310854182a1d589ee4c770c (diff)
downloademacs-30fe8703e60d0b756c19f52a6758889600b7b396.tar.gz
emacs-30fe8703e60d0b756c19f52a6758889600b7b396.zip
Allow ERC's module toggles access to the prefix arg
* lisp/erc/erc-common.el (erc--module-toggle-prefix-arg): Add internal variable for preserving the `arg' passed to a module's minor-mode toggle, which was previously discarded. Doing this lets modules that are more interactive in nature overload their mode toggles with alternate behaviors. (define-erc-module): Bind `erc--module-toggle-prefix-arg' to the `arg' parameter, which is normally defined inside a `define-minor-mode' body form. * test/lisp/erc/erc-tests.el (define-erc-module--global, define-erc-module--local): Expect activation body to be wrapped by a let form binding `erc--module-toggle-prefix-arg'. (Bug#63595)
-rw-r--r--lisp/erc/erc-common.el14
-rw-r--r--test/lisp/erc/erc-tests.el14
2 files changed, 19 insertions, 9 deletions
diff --git a/lisp/erc/erc-common.el b/lisp/erc/erc-common.el
index 7bd549abfc1..08c11d518a8 100644
--- a/lisp/erc/erc-common.el
+++ b/lisp/erc/erc-common.el
@@ -289,6 +289,15 @@ instead of a `set' state, which precludes any actual saving."
289 (intern (file-name-base file)))) 289 (intern (file-name-base file))))
290 (v v))) 290 (v v)))
291 291
292(defvar erc--module-toggle-prefix-arg nil
293 "The interpreted prefix arg of the minor-mode toggle.
294Non-nil inside an ERC module's activation (or deactivation)
295command, such as `erc-spelling-enable', when it's been called
296indirectly via the module's minor-mode toggle, i.e.,
297`erc-spelling-mode'. Nil otherwise. Its value is either the
298symbol `toggle' or an integer produced by `prefix-numeric-value'.
299See Info node `(elisp) Defining Minor Modes' for more.")
300
292(defmacro define-erc-module (name alias doc enable-body disable-body 301(defmacro define-erc-module (name alias doc enable-body disable-body
293 &optional local-p) 302 &optional local-p)
294 "Define a new minor mode using ERC conventions. 303 "Define a new minor mode using ERC conventions.
@@ -337,9 +346,8 @@ if ARG is omitted or nil.
337 :group (erc--find-group ',name ,(and alias (list 'quote alias))) 346 :group (erc--find-group ',name ,(and alias (list 'quote alias)))
338 ,@(unless local-p `(:require ',(erc--find-feature name alias))) 347 ,@(unless local-p `(:require ',(erc--find-feature name alias)))
339 ,@(unless local-p `(:type ,(erc--prepare-custom-module-type name))) 348 ,@(unless local-p `(:type ,(erc--prepare-custom-module-type name)))
340 (if ,mode 349 (let ((erc--module-toggle-prefix-arg arg))
341 (,enable) 350 (if ,mode (,enable) (,disable))))
342 (,disable)))
343 ,(erc--assemble-toggle local-p name enable mode t enable-body) 351 ,(erc--assemble-toggle local-p name enable mode t enable-body)
344 ,(erc--assemble-toggle local-p name disable mode nil disable-body) 352 ,(erc--assemble-toggle local-p name disable mode nil disable-body)
345 ,@(and-let* ((alias) 353 ,@(and-let* ((alias)
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index 3f36e7c94f6..cc69641fb0b 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -2204,9 +2204,10 @@ Some docstring."
2204 :group (erc--find-group 'mname 'malias) 2204 :group (erc--find-group 'mname 'malias)
2205 :require 'nil 2205 :require 'nil
2206 :type "mname" 2206 :type "mname"
2207 (if erc-mname-mode 2207 (let ((erc--module-toggle-prefix-arg arg))
2208 (erc-mname-enable) 2208 (if erc-mname-mode
2209 (erc-mname-disable))) 2209 (erc-mname-enable)
2210 (erc-mname-disable))))
2210 2211
2211 (defun erc-mname-enable () 2212 (defun erc-mname-enable ()
2212 "Enable ERC mname mode." 2213 "Enable ERC mname mode."
@@ -2259,9 +2260,10 @@ ARG is omitted or nil.
2259Some docstring." 2260Some docstring."
2260 :global nil 2261 :global nil
2261 :group (erc--find-group 'mname nil) 2262 :group (erc--find-group 'mname nil)
2262 (if erc-mname-mode 2263 (let ((erc--module-toggle-prefix-arg arg))
2263 (erc-mname-enable) 2264 (if erc-mname-mode
2264 (erc-mname-disable))) 2265 (erc-mname-enable)
2266 (erc-mname-disable))))
2265 2267
2266 (defun erc-mname-enable (&optional ,arg-en) 2268 (defun erc-mname-enable (&optional ,arg-en)
2267 "Enable ERC mname mode. 2269 "Enable ERC mname mode.