]> code.delx.au - gnu-emacs-elpa/commitdiff
Add validate-setq
authorArtur Malabarba <bruce.connor.am@gmail.com>
Wed, 4 May 2016 15:26:46 +0000 (12:26 -0300)
committerArtur Malabarba <bruce.connor.am@gmail.com>
Wed, 4 May 2016 15:26:46 +0000 (12:26 -0300)
validate.el

index 8408b63c3919a16a72708dd9d27ab718b8f0955f..7dfe45b01d15d61271dc91d03a250ab57f624840 100644 (file)
@@ -5,7 +5,7 @@
 ;; Author: Artur Malabarba <emacs@endlessparentheses.com>
 ;; Keywords: lisp
 ;; Package-Requires: ((emacs "24.1") (cl-lib "0.5"))
-;; Version: 0.2
+;; Version: 0.3
 
 ;;; Commentary:
 ;;
@@ -182,5 +182,10 @@ with `validate-value'. NOERROR is passed to `validate-value'."
        (lambda (val)
          (validate-value val (custom-variable-type symbol) 'noerror))))
 
+(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))))
+
 (provide 'validate)
 ;;; validate.el ends here