emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 6d8638e5e4: Give a warning if setopt has been used with an invali


From: Lars Ingebrigtsen
Subject: master 6d8638e5e4: Give a warning if setopt has been used with an invalid value
Date: Tue, 5 Jul 2022 13:33:29 -0400 (EDT)

branch: master
commit 6d8638e5e494fb0ceafffe19bbf349fff643e12d
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Give a warning if setopt has been used with an invalid value
    
    * lisp/cus-edit.el (setopt--set): Mark the variable for checking.
    
    * lisp/custom.el (custom-initialize-reset): Give a warning if the
    type is wrong (bug#56400).
    
    * lisp/wid-edit.el (widget-convert): Autoload.
---
 lisp/cus-edit.el |  1 +
 lisp/custom.el   | 10 ++++++++++
 lisp/wid-edit.el |  1 +
 3 files changed, 12 insertions(+)

diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el
index 1f496af7d5..50dce5ee28 100644
--- a/lisp/cus-edit.el
+++ b/lisp/cus-edit.el
@@ -1075,6 +1075,7 @@ plain variables.  This means that `setopt' will execute 
any
   (when-let ((type (get variable 'custom-type)))
     (unless (widget-apply (widget-convert type) :match value)
       (user-error "Value `%S' does not match type %s" value type)))
+  (put variable 'custom-check-value (list value))
   (funcall (or (get variable 'custom-set) #'set-default) variable value))
 
 ;;;###autoload
diff --git a/lisp/custom.el b/lisp/custom.el
index 2b7621229d..a6e2ab351d 100644
--- a/lisp/custom.el
+++ b/lisp/custom.el
@@ -90,6 +90,16 @@ The value is either the symbol's current value
  (as obtained using the `:get' function), if any,
 or the value in the symbol's `saved-value' property if any,
 or (last of all) the value of EXP."
+  ;; If this value has been set with `setopt' (for instance in
+  ;; ~/.emacs), we didn't necessarily know the type of the user option
+  ;; then.  So check now, and issue a warning if it's wrong.
+  (when-let ((value (get symbol 'custom-check-value))
+             (type (get symbol 'custom-type)))
+    (when (and (boundp symbol)
+               (eq (car value) (symbol-value symbol))
+               ;; Check that the type is correct.
+               (not (widget-apply (widget-convert type) :match (car value))))
+      (warn "Value `%S' for `%s' does not match type %s" value symbol type)))
   (funcall (or (get symbol 'custom-set) #'set-default-toplevel-value)
            symbol
            (condition-case nil
diff --git a/lisp/wid-edit.el b/lisp/wid-edit.el
index 29b6e13bc6..5362618247 100644
--- a/lisp/wid-edit.el
+++ b/lisp/wid-edit.el
@@ -880,6 +880,7 @@ The child is converted, using the keyword arguments ARGS."
   "Make a deep copy of WIDGET."
   (widget-apply (copy-sequence widget) :copy))
 
+;;;###autoload
 (defun widget-convert (type &rest args)
   "Convert TYPE to a widget without inserting it in the buffer.
 The optional ARGS are additional keyword arguments."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]