diff options
author | F. Jason Park <jp@neverwas.me> | 2023-01-14 19:08:11 -0800 |
---|---|---|
committer | F. Jason Park <jp@neverwas.me> | 2023-04-08 14:23:51 -0700 |
commit | 9c65ac73655c71a7f289d8c86ee6d7a314c32a05 (patch) | |
tree | f2e55b487e9351d26a537043207fa20d4eaba936 /test | |
parent | 0d3ccdbde441a0eed5d80d64aea429bc9a6457a3 (diff) | |
download | emacs-9c65ac73655c71a7f289d8c86ee6d7a314c32a05.tar.gz |
Warn when customizing minor-mode vars for ERC modules
* lisp/erc/erc-common.el: (erc--inside-mode-toggle-p): Add global var
to inhibit mode toggles from being run by `erc-update-modules'. It
must be non-nil inside custom-set functions for mode toggles created
by `define-erc-module'.
(erc--favor-changed-reverted-modules-state): Add new helper to show a
"SET" Custom state for `erc-modules' except when reverting to the
default value because \"STANDARD\" always takes precedence, as
explained somewhat in bug#12864.
(erc--assemble-toggle): Don't modify `erc-modules' when run from
custom-set function.
(erc--neuter-custom-variable-state): Add new function to serve as a
phony getter that deceives Customize into thinking the variable is
always set to its standard value. The justification for this is that
toggling a module's minor mode in Customize has never worked and has
only sewn confusion in new users. Without this hack, mode widgets
show a state of "CHANGED outside Customize", which alone is probably
preferable, except that they all end up toggled open, bringing them
unwanted attention and distracting the user.
(erc--tick-module-checkbox): Add helper to toggle the appropriate
checkbox in the `erc-modules' widget when a user interactively toggles
a minor-mode state variable.
(erc--prepare-custom-module-type): Create spec for minor-mode Custom
`:type', deferring various aspects until module-definition time.
(define-erc-module): Add `:get' and `:type' keywords to be passed to
`defcustom' definition for global modules.
* lisp/erc/erc.el (erc-modules): Inhibit `erc-update-modules' when run
from a minor-mode toggle's custom-set function.
* test/lisp/erc/erc-tests.el (define-erc-module--global,
define-erc-module--local): Update `erc-modules' mutations with
`erc--inside-mode-toggle-p' guard conditions. (Bug#60935.)
Diffstat (limited to 'test')
-rw-r--r-- | test/lisp/erc/erc-tests.el | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el index 45d8cae5125..b1df04841a4 100644 --- a/test/lisp/erc/erc-tests.el +++ b/test/lisp/erc/erc-tests.el @@ -1476,7 +1476,10 @@ ((ignore a) (ignore b)) ((ignore c) (ignore d))))) - (should (equal (macroexpand global-module) + (should (equal (cl-letf (((symbol-function + 'erc--prepare-custom-module-type) + #'symbol-name)) + (macroexpand global-module)) `(progn (define-minor-mode erc-mname-mode @@ -1487,6 +1490,8 @@ if ARG is omitted or nil. Some docstring" :global t :group (erc--find-group 'mname 'malias) + :get #'erc--neuter-custom-variable-state + :type "mname" (if erc-mname-mode (erc-mname-enable) (erc-mname-disable))) @@ -1494,14 +1499,22 @@ Some docstring" (defun erc-mname-enable () "Enable ERC mname mode." (interactive) - (cl-pushnew 'mname erc-modules) + (unless (or erc--inside-mode-toggle-p + (memq 'mname erc-modules)) + (let ((erc--inside-mode-toggle-p t)) + (erc--favor-changed-reverted-modules-state + 'mname #'cons))) (setq erc-mname-mode t) (ignore a) (ignore b)) (defun erc-mname-disable () "Disable ERC mname mode." (interactive) - (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)) + (erc--favor-changed-reverted-modules-state + 'mname #'delq))) (setq erc-mname-mode nil) (ignore c) (ignore d)) |