1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-05 22:20:24 -08:00

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)
This commit is contained in:
F. Jason Park 2023-05-15 00:16:00 -07:00
parent e51e43b704
commit 30fe8703e6
2 changed files with 19 additions and 9 deletions

View file

@ -289,6 +289,15 @@ instead of a `set' state, which precludes any actual saving."
(intern (file-name-base file))))
(v v)))
(defvar erc--module-toggle-prefix-arg nil
"The interpreted prefix arg of the minor-mode toggle.
Non-nil inside an ERC module's activation (or deactivation)
command, such as `erc-spelling-enable', when it's been called
indirectly via the module's minor-mode toggle, i.e.,
`erc-spelling-mode'. Nil otherwise. Its value is either the
symbol `toggle' or an integer produced by `prefix-numeric-value'.
See Info node `(elisp) Defining Minor Modes' for more.")
(defmacro define-erc-module (name alias doc enable-body disable-body
&optional local-p)
"Define a new minor mode using ERC conventions.
@ -337,9 +346,8 @@ if ARG is omitted or nil.
:group (erc--find-group ',name ,(and alias (list 'quote alias)))
,@(unless local-p `(:require ',(erc--find-feature name alias)))
,@(unless local-p `(:type ,(erc--prepare-custom-module-type name)))
(if ,mode
(,enable)
(,disable)))
(let ((erc--module-toggle-prefix-arg arg))
(if ,mode (,enable) (,disable))))
,(erc--assemble-toggle local-p name enable mode t enable-body)
,(erc--assemble-toggle local-p name disable mode nil disable-body)
,@(and-let* ((alias)