>From e8a6cbfaffb91019fa9a4a9aa3cae3c7896a6ff5 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Wed, 15 Mar 2023 06:39:32 -0700 Subject: [PATCH 0/3] *** NOT A PATCH *** v5. Don't touch `standard-value'. Instead, favor a "CHANGED" state for `erc-modules'. Use a custom getter to spoof a "STANDARD" state for all module mode vars so their widgets remain dormant and only protest when disturbed. 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 | 158 ++++++++++++++++++++++++++++++++++--- lisp/erc/erc.el | 3 +- test/lisp/erc/erc-tests.el | 82 +++++++++++++++---- 4 files changed, 213 insertions(+), 31 deletions(-) Interdiff: diff --git a/lisp/erc/erc-common.el b/lisp/erc/erc-common.el index 522803b91e2..3a148dc1196 100644 --- a/lisp/erc/erc-common.el +++ b/lisp/erc/erc-common.el @@ -162,14 +162,20 @@ erc--assemble-toggle erc-modules))) `(,(if val v `(not ,v))))) (let ((erc--inside-mode-toggle-p t)) - (custom-set-variables - `(erc-modules ',(,(if val 'cons 'delq) - ',(erc--normalize-module-symbol name) - erc-modules))))) + ;; Make the widget show "CHANGED outside Customize." + ;; Ideally, it would show "SET for current session" + ;; instead, but using `customize-set-variable' here + ;; or calling `customize-mark-as-set' afterward isn't + ;; enough if `customized-value' and `standard-value' + ;; match but differ from `saved-value' because the + ;; widget will see a `standard' instead of a `set' + ;; state. And clicking "apply and save" won't update + ;; `custom-file'. See bug#12864 "Make state button + ;; interaction less confusing". + (setopt erc-modules (,(if val 'cons 'delq) + ',(erc--normalize-module-symbol name) + erc-modules)))) (setq ,mode ,val) - ;; Avoid "changed" state from `erc-update-modules' - (unless (called-interactively-p 'any) - (put ',mode 'standard-value (list ,val))) ,@body))))) ;; This is a migration helper that determines a module's `:group' @@ -203,13 +209,15 @@ erc--find-group (throw 'found found))) 'erc)) -(defun erc--custom-set-minor-mode (variable value) - (let ((name (get variable 'erc-module)) - (erc--inside-mode-toggle-p t)) - (custom-set-variables - `(erc-modules - ',(if value (cl-pushnew name erc-modules) (delq name erc-modules)))) - (custom-set-minor-mode variable value))) +(defun erc--neuter-custom-variable-state (variable) + "Lie to Customize about VARIABLE's true state. +Do so by always returning its standard value, namely nil." + ;; Make a module's global minor-mode toggle blind to Customize, so + ;; that `customize-variable-state' never sees it as "changed", + ;; regardless of its value. This snippet is + ;; `custom--standard-value' from Emacs 28+. + (cl-assert (null (eval (car (get variable 'standard-value)) t))) + nil) ;; This exists as a separate, top-level function to prevent the byte ;; compiler from warning about widget-related dependencies not being @@ -240,12 +248,16 @@ erc--prepare-custom-module-type `(let* ((name (erc--normalize-module-symbol ',name)) (fmtd (format " `%s' " name))) `(boolean - :button-face '(error custom-button) - :format "%{%t%}: %[Deprecated Toggle%] \n%d\n" - :doc ,(concat "Setting a module's minor-mode variable is " - (propertize "ineffective" 'face 'error) ".\nPlease add" - fmtd "directly to `erc-modules' instead.\nYou can do so" - " now by clicking the scary button above.") + :button-face '(custom-variable-obsolete custom-button) + :format "%{%t%}: %[Deprecated Toggle%] \n%h\n" + :documentation-property + ,(lambda (_) + (let ((hasp (memq name erc-modules))) + (concat "Setting a module's minor-mode variable is " + (propertize "ineffective" 'face 'error) + ".\nPlease " (if hasp "remove" "add") fmtd + (if hasp "from" "to") " `erc-modules' directly instead.\n" + "You can do so now by clicking the scary button above."))) :help-echo ,(lambda (_) (let ((hasp (memq name erc-modules))) (concat (if hasp "Remove" "Add") fmtd @@ -312,7 +324,7 @@ define-erc-module \n%s" name name doc)) :global ,(not local-p) :group (erc--find-group ',name ,(and alias (list 'quote alias))) - ,@(unless local-p '(:set #'erc--custom-set-minor-mode)) + ,@(unless local-p '(:get #'erc--neuter-custom-variable-state)) ,@(unless local-p `(:type ,(erc--prepare-custom-module-type name))) (if ,mode (,enable) diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el index ef742c853d6..baf6826ff97 100644 --- a/test/lisp/erc/erc-tests.el +++ b/test/lisp/erc/erc-tests.el @@ -1328,7 +1328,7 @@ define-erc-module--global Some docstring." :global t :group (erc--find-group 'mname 'malias) - :set #'erc--custom-set-minor-mode + :get #'erc--neuter-custom-variable-state :type "mname" (if erc-mname-mode (erc-mname-enable) @@ -1340,11 +1340,8 @@ define-erc-module--global (unless (or erc--inside-mode-toggle-p (memq 'mname erc-modules)) (let ((erc--inside-mode-toggle-p t)) - (custom-set-variables - `(erc-modules ',(cons 'mname erc-modules))))) + (setopt erc-modules (cons 'mname erc-modules)))) (setq erc-mname-mode t) - (unless (called-interactively-p 'any) - (put 'erc-mname-mode 'standard-value (list t))) (ignore a) (ignore b)) (defun erc-mname-disable () @@ -1353,11 +1350,8 @@ define-erc-module--global (unless (or erc--inside-mode-toggle-p (not (memq 'mname erc-modules))) (let ((erc--inside-mode-toggle-p t)) - (custom-set-variables - `(erc-modules ',(delq 'mname erc-modules))))) + (setopt erc-modules (delq 'mname erc-modules)))) (setq erc-mname-mode nil) - (unless (called-interactively-p 'any) - (put 'erc-mname-mode 'standard-value (list nil))) (ignore c) (ignore d)) (defalias 'erc-malias-mode #'erc-mname-mode) -- 2.39.2