]> git.eshelyaron.com Git - emacs.git/commitdiff
Give a warning if setopt has been used with an invalid value
authorLars Ingebrigtsen <larsi@gnus.org>
Tue, 5 Jul 2022 17:32:37 +0000 (19:32 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Tue, 5 Jul 2022 17:33:24 +0000 (19:33 +0200)
* 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
lisp/custom.el
lisp/wid-edit.el

index 1f496af7d57c44a4ac674c9a78d04121be533951..50dce5ee285f2c3561cb3bbdee62ee4189b2e5df 100644 (file)
@@ -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
index 2b7621229d9441dd95799234cac536a625ab5f17..a6e2ab351d4fd36b373a0d357ea9953465458571 100644 (file)
@@ -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
index 29b6e13bc604b04fc1a9248643b1644133e4bce5..5362618247023704e443442fc53425280f0907ec 100644 (file)
@@ -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."