+;;;###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))))
+