;;; validate.el --- Schema validation for Emacs-lisp -*- lexical-binding: t; -*-
-;; Copyright (C) 2016 Artur Malabarba
+;; Copyright (C) 2016 Free Software Foundation, Inc.
;; Author: Artur Malabarba <emacs@endlessparentheses.com>
;; Keywords: lisp
;; Package-Requires: ((emacs "24.1") (cl-lib "0.5"))
-;; Version: 0.1
+;; Version: 0.3
;;; Commentary:
;;
(if noerror val
(error "Variable `%s' has no custom-type." symbol)))))
+;;;###autoload
+(defun validate-mark-safe-local (symbol)
+ "Mark SYMBOL as a safe local if its custom type is obeyed."
+ (put symbol 'safe-local-variable
+ (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