From 5ae05b1ad34ce1baea149c7af1e9e9282f101725 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Mon, 15 May 2023 00:16:00 -0700 Subject: [PATCH 2/5] [5.6] 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'. --- lisp/erc/erc-common.el | 14 +++++++++++--- test/lisp/erc/erc-tests.el | 14 ++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/lisp/erc/erc-common.el b/lisp/erc/erc-common.el index f152a1a32d9..dd39b30c4db 100644 --- a/lisp/erc/erc-common.el +++ b/lisp/erc/erc-common.el @@ -289,6 +289,15 @@ erc--find-feature (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 @@ define-erc-module :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) diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el index 991bfa3b082..de472527bde 100644 --- a/test/lisp/erc/erc-tests.el +++ b/test/lisp/erc/erc-tests.el @@ -2175,9 +2175,10 @@ define-erc-module--global :group (erc--find-group 'mname 'malias) :require 'nil :type "mname" - (if erc-mname-mode - (erc-mname-enable) - (erc-mname-disable))) + (let ((erc--module-toggle-prefix-arg arg)) + (if erc-mname-mode + (erc-mname-enable) + (erc-mname-disable)))) (defun erc-mname-enable () "Enable ERC mname mode." @@ -2230,9 +2231,10 @@ define-erc-module--local Some docstring." :global nil :group (erc--find-group 'mname nil) - (if erc-mname-mode - (erc-mname-enable) - (erc-mname-disable))) + (let ((erc--module-toggle-prefix-arg arg)) + (if erc-mname-mode + (erc-mname-enable) + (erc-mname-disable)))) (defun erc-mname-enable (&optional ,arg-en) "Enable ERC mname mode. -- 2.40.0