[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master b0d761be0f9 08/14: Restore module var toggles in ERC's Custom buf
From: |
F. Jason Park |
Subject: |
master b0d761be0f9 08/14: Restore module var toggles in ERC's Custom buffers |
Date: |
Fri, 5 May 2023 20:30:49 -0400 (EDT) |
branch: master
commit b0d761be0f9b0180566d7cde1ef2eea33402dd4e
Author: F. Jason Park <jp@neverwas.me>
Commit: F. Jason Park <jp@neverwas.me>
Restore module var toggles in ERC's Custom buffers
* lisp/erc/erc-common.el (erc--neuter-custom-variable-state): Remove
function. ERC famously toggles global minor-mode vars during normal
operations, which adds noise to its customization buffers because
`customize-variable-state' always sees an activated module's mode
variable as having "CHANGED". To suppress this annoyance, a
workaround was employed that used a dishonest `:get' function to
simply return the "saved value," when present. While this improved
the Customize experience, it also misled users, which likely wasn't
justified.
(erc--make-show-me-widget): Add helper to avoid forward declarations.
(erc--prepare-custom-module-type): Don't deprive users of a working
minor-mode toggle.
(erc--find-feature): New function to guess the feature of a module's
containing library.
(define-erc-module): Remove `:get' keyword. Specify `:require'
instead, whose value may be nil. Users who currently have mode vars
in their `custom-file' won't be impacted by this addition because
those `custom-set-variables' entries will still lack a REQUEST list
and hence won't incur a startup penalty. And new users intent on
using the toggle will hopefully do so with the knowledge they're
opting in to requiring ERC on startup, which is not the case if they
follow the recommended practice of using `erc-modules' instead.
(erc-with-server-buffer): Inline `erc-server-buffer'.
* test/lisp/erc/erc-tests.el (erc-process-input-line): Use helper.
(define-erc-module--global): Change expected expansion. (Bug#60935)
---
lisp/erc/erc-common.el | 76 ++++++++++++++++++++++++++++------------------
test/lisp/erc/erc-tests.el | 7 ++---
2 files changed, 49 insertions(+), 34 deletions(-)
diff --git a/lisp/erc/erc-common.el b/lisp/erc/erc-common.el
index 6c015c71ff9..708cdb0c422 100644
--- a/lisp/erc/erc-common.el
+++ b/lisp/erc/erc-common.el
@@ -32,6 +32,7 @@
(defvar erc-dbuf)
(defvar erc-log-p)
(defvar erc-modules)
+(defvar erc-server-process)
(defvar erc-server-users)
(defvar erc-session-server)
@@ -40,6 +41,9 @@
(declare-function erc-server-buffer "erc" nil)
(declare-function widget-apply-action "wid-edit" (widget &optional event))
(declare-function widget-at "wid-edit" (&optional pos))
+(declare-function widget-create-child-and-convert "wid-edit"
+ (parent type &rest args))
+(declare-function widget-default-format-handler "wid-edit" (widget escape))
(declare-function widget-get-sibling "wid-edit" (widget))
(declare-function widget-move "wid-edit" (arg &optional suppress-echo))
(declare-function widget-type "wid-edit" (widget))
@@ -195,16 +199,6 @@ instead of a `set' state, which precludes any actual
saving."
(throw 'found found)))
'erc))
-(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
;; loaded at runtime.
@@ -230,25 +224,42 @@ Do so by always returning its standard value, namely nil."
(substitute-command-keys "\\[Custom-set]")
(substitute-command-keys "\\[Custom-save]"))))
+;; This stands apart to avoid needing forward declarations for
+;; `wid-edit' functions in every file requiring `erc-common'.
+(defun erc--make-show-me-widget (widget escape &rest plist)
+ (if (eq escape ?i)
+ (apply #'widget-create-child-and-convert widget 'push-button plist)
+ (widget-default-format-handler widget escape)))
+
(defun erc--prepare-custom-module-type (name)
`(let* ((name (erc--normalize-module-symbol ',name))
(fmtd (format " `%s' " name)))
`(boolean
- :button-face '(custom-variable-obsolete custom-button)
- :format "%{%t%}: %[Deprecated Toggle%] \n%h\n"
+ :format "%{%t%}: %i %[Deprecated Toggle%] %v \n%h\n"
+ :format-handler
+ ,(lambda (widget escape)
+ (erc--make-show-me-widget
+ widget escape
+ :button-face '(custom-variable-obsolete custom-button)
+ :tag "Show Me"
+ :action (apply-partially #'erc--tick-module-checkbox name)
+ :help-echo (lambda (_)
+ (let ((hasp (memq name erc-modules)))
+ (concat (if hasp "Remove" "Add") fmtd
+ (if hasp "from" "to")
+ " `erc-modules'.")))))
+ :action widget-toggle-action
: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
- (if hasp "from" "to") " `erc-modules'.")))
- :action ,(apply-partially #'erc--tick-module-checkbox name))))
+ (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 "
+ (propertize "Show Me" 'face 'custom-variable-obsolete)
+ " above."))))))
(defun erc--fill-module-docstring (&rest strings)
(with-temp-buffer
@@ -264,6 +275,12 @@ Do so by always returning its standard value, namely nil."
(goto-char (point-min))
(nth 3 (read (current-buffer)))))
+(defmacro erc--find-feature (name alias)
+ `(pcase (erc--find-group ',name ,(and alias (list 'quote alias)))
+ ('erc (and-let* ((file (or (macroexp-file-name) buffer-file-name)))
+ (intern (file-name-base file))))
+ (v v)))
+
(defmacro define-erc-module (name alias doc enable-body disable-body
&optional local-p)
"Define a new minor mode using ERC conventions.
@@ -310,7 +327,7 @@ if ARG is omitted or nil.
\n%s" name name doc))
:global ,(not local-p)
:group (erc--find-group ',name ,(and alias (list 'quote alias)))
- ,@(unless local-p '(:get #'erc--neuter-custom-variable-state))
+ ,@(unless local-p `(:require ',(erc--find-feature name alias)))
,@(unless local-p `(:type ,(erc--prepare-custom-module-type name)))
(if ,mode
(,enable)
@@ -371,12 +388,13 @@ If no server buffer exists, return nil."
(not (cdr body))
(special-variable-p (car body))))
(buffer (make-symbol "buffer")))
- `(let ((,buffer (erc-server-buffer)))
- (when (buffer-live-p ,buffer)
- ,(if varp
- `(buffer-local-value ',(car body) ,buffer)
- `(with-current-buffer ,buffer
- ,@body))))))
+ `(when-let* (((processp erc-server-process))
+ (,buffer (process-buffer erc-server-process))
+ ((buffer-live-p ,buffer)))
+ ,(if varp
+ `(buffer-local-value ',(car body) ,buffer)
+ `(with-current-buffer ,buffer
+ ,@body)))))
(defmacro erc-with-all-buffers-of-server (process pred &rest forms)
"Execute FORMS in all buffers which have same process as this server.
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index 5aaf7e499e3..bafe418f0cd 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -1289,15 +1289,12 @@
(erc-default-recipients '("#chan"))
calls)
(with-temp-buffer
+ (erc-tests--set-fake-server-process "sleep" "1")
(cl-letf (((symbol-function 'erc-cmd-MSG)
(lambda (line)
(push line calls)
(should erc--called-as-input-p)
(funcall orig-erc-cmd-MSG line)))
- ((symbol-function 'erc-server-buffer)
- (lambda () (current-buffer)))
- ((symbol-function 'erc-server-process-alive)
- (lambda () t))
((symbol-function 'erc-server-send-queue)
#'ignore))
@@ -2018,7 +2015,7 @@ ARG is omitted or nil.
Some docstring."
:global t
:group (erc--find-group 'mname 'malias)
- :get #'erc--neuter-custom-variable-state
+ :require 'nil
:type "mname"
(if erc-mname-mode
(erc-mname-enable)
- master updated (1ef219e220c -> ba44b481844), F. Jason Park, 2023/05/05
- master c9f1ad2a870 01/14: Revive option erc-query-on-unjoined-chan-privmsg, F. Jason Park, 2023/05/05
- master 8654cea5843 02/14: Move ERC's buffer-display tests to separate file, F. Jason Park, 2023/05/05
- master 5de90fa9611 03/14: Extend erc-interactive-display to cover /JOINs, F. Jason Park, 2023/05/05
- master 9e1a5a389ed 04/14: Ignore erc-reconnect-display after a timeout, F. Jason Park, 2023/05/05
- master 90a9c7b7b59 05/14: Actually define erc-default-server-functions, F. Jason Park, 2023/05/05
- master b0d761be0f9 08/14: Restore module var toggles in ERC's Custom buffers,
F. Jason Park <=
- master 2e18ba6302f 07/14: Simplify erc-button movement commands, F. Jason Park, 2023/05/05
- master 2641dfd4b43 06/14: Add erc-timestamp property to invisible messages, F. Jason Park, 2023/05/05
- master 16306567706 09/14: Don't send multiline commands as messages in ERC, F. Jason Park, 2023/05/05
- master 35dd1ade7f1 11/14: Preprocess prompt input linewise in ERC, F. Jason Park, 2023/05/05
- master ba44b481844 14/14: Add interface for finding users in erc-server-PRIVMSG, F. Jason Park, 2023/05/05
- master 3a5a6fce957 10/14: Redo line splitting for outgoing messages in ERC, F. Jason Park, 2023/05/05
- master 5adda2f4683 12/14: Revise FORM-as-function interface in erc-button-alist, F. Jason Park, 2023/05/05
- master d141f7149b6 13/14: Improve erc-button--modify-nick-function interface, F. Jason Park, 2023/05/05