(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
(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
"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."