;; Author: Artur Malabarba <emacs@endlessparentheses.com>
;; Keywords: lisp
;; Package-Requires: ((emacs "24.1") (cl-lib "0.5"))
-;; Version: 0.3
+;; Version: 0.4
;;; Commentary:
;;
(defmacro validate-setq (symbol value)
"Like `setq', but throw an error if validation fails.
VALUE is validated against SYMBOL's custom type."
- `(setq ,symbol (validate-value ,value (custom-variable-type ',symbol))))
+ `(if (boundp ',symbol)
+ (setq ,symbol (validate-value ,value (custom-variable-type ',symbol)))
+ (user-error "Trying to validate a variable that's not defined yet: `%s'.\nYou need to require the package before validating"
+ ',symbol)))
(provide 'validate)
;;; validate.el ends here