>From 23b193168c03c9d36307986f87f2789cafae9b41 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Thu, 16 Feb 2023 22:51:42 -0800 Subject: [PATCH 0/3] *** NOT A PATCH *** *** BLURB HERE *** F. Jason Park (3): [5.6] Don't associate ERC modules with undefined groups [5.6] Warn when setting minor-mode vars for ERC modules [5.6] Fill doc strings for ERC modules. lisp/erc/erc-capab.el | 1 + lisp/erc/erc-common.el | 143 +++++++++++++++++++++++++++++++++---- lisp/erc/erc.el | 3 +- test/lisp/erc/erc-tests.el | 84 +++++++++++++++++----- 4 files changed, 200 insertions(+), 31 deletions(-) Interdiff: diff --git a/lisp/erc/erc-common.el b/lisp/erc/erc-common.el index cc278428d5d..6d09ac25a0a 100644 --- a/lisp/erc/erc-common.el +++ b/lisp/erc/erc-common.el @@ -130,13 +130,14 @@ erc--normalize-module-symbol (or (cdr (assq symbol erc--module-name-migrations)) symbol)) (defvar erc--inside-mode-toggle-p nil - "Non-nil when a mode toggle is updating module membership. -This serves as a flag to inhibit the mutual recursion that -otherwise occurs between an ERC-defined minor-mode function, such + "Non-nil when a module's mode toggle is updating module membership. +This serves as a flag to inhibit the mutual recursion that would +otherwise occur between an ERC-defined minor-mode function, such as `erc-services-mode', and the custom-set function for `erc-modules'. For historical reasons, the latter calls `erc-update-modules', which, in turn, enables the minor-mode -functions for all member modules.") +functions for all member modules. Also non-nil when a mode's +widget runs its set function.") (defun erc--assemble-toggle (localp name ablsym mode val body) (let ((arg (make-symbol "arg"))) @@ -155,23 +156,29 @@ erc--assemble-toggle (,ablsym)) (setq ,mode ,val) ,@body))) - `((unless erc--inside-mode-toggle-p - ,(if val - `(cl-pushnew ',(erc--normalize-module-symbol name) - erc-modules) - `(setq erc-modules - (delq ',(erc--normalize-module-symbol name) - erc-modules)))) + ;; No need for `default-value', etc. because a buffer-local + ;; `erc-modules' only influences the next session and + ;; doesn't survive the major-mode reset that soon follows. + `((unless + (or erc--inside-mode-toggle-p + ,@(let ((v `(memq ',(erc--normalize-module-symbol name) + erc-modules))) + `(,(if val v `(not ,v))))) + (let ((erc--inside-mode-toggle-p t)) + (customize-set-variable + 'erc-modules (,(if val 'cons 'delq) + ',(erc--normalize-module-symbol name) + erc-modules)))) (setq ,mode ,val) ,@body))))) ;; This is a migration helper that determines a module's `:group' ;; keyword argument from its name or alias. A (global) module's minor -;; mode variable will appear under the group's Custom menu. Like +;; mode variable appears under the group's Custom menu. Like ;; `erc--normalize-module-symbol', it must run when the module's ;; definition (rather than that of `define-erc-module') is expanded. -;; For corner cases where this fails and where the catch-all of `erc' -;; is inappropriate, (global) modules can declare a top-level +;; For corner cases in which this fails or the catch-all of `erc' is +;; more inappropriate, (global) modules can declare a top-level ;; ;; (put 'foo 'erc-group 'erc-bar) ;; diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el index e5db78ef2e1..8e41d428ce9 100644 --- a/test/lisp/erc/erc-tests.el +++ b/test/lisp/erc/erc-tests.el @@ -1337,16 +1337,22 @@ define-erc-module--global (defun erc-mname-enable () "Enable ERC mname mode." (interactive) - (unless erc--inside-mode-toggle-p - (cl-pushnew 'mname erc-modules)) + (unless (or erc--inside-mode-toggle-p + (memq 'mname erc-modules)) + (let ((erc--inside-mode-toggle-p t)) + (customize-set-variable + 'erc-modules (cons 'mname erc-modules)))) (setq erc-mname-mode t) (ignore a) (ignore b)) (defun erc-mname-disable () "Disable ERC mname mode." (interactive) - (unless erc--inside-mode-toggle-p - (setq erc-modules (delq 'mname erc-modules))) + (unless (or erc--inside-mode-toggle-p + (not (memq 'mname erc-modules))) + (let ((erc--inside-mode-toggle-p t)) + (customize-set-variable + 'erc-modules (delq 'mname erc-modules)))) (setq erc-mname-mode nil) (ignore c) (ignore d)) -- 2.39.1