Make def-setting! behave more like defmacro

set! used to aggressively evaluate its arguments (at expansion-time),
even if placed inside an after! block. This causes unavoidable errors if
those arguments use functions/variables that don't exist yet.

Fixes #112
This commit is contained in:
Henrik Lissner 2017-06-19 00:22:04 +02:00
parent 27cbd36b69
commit 928812da8a
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
12 changed files with 104 additions and 107 deletions

View file

@ -226,20 +226,21 @@ executed when called with `set!'. FORMS are not evaluated until `set!' calls it.
(declare (indent defun) (doc-string 3))
(unless (keywordp keyword)
(error "Not a valid property name: %s" keyword))
`(progn
(defun ,(intern (format "doom-setting--setter%s" keyword)) ,arglist
,docstring
,@forms)
(cl-pushnew ,keyword doom-settings)))
(let ((fn (intern (format "doom-setting--setter%s" keyword))))
`(progn
(defun ,fn ,arglist
,docstring
,@forms)
(cl-pushnew ',(cons keyword fn) doom-settings :test #'eq :key #'car))))
(defmacro set! (keyword &rest values)
"Set an option defined by `def-setting!'. Skip if doesn't exist."
(declare (indent defun))
(unless values
(error "Empty set! for %s" keyword))
(let ((fn (intern (format "doom-setting--setter%s" keyword))))
(if (functionp fn)
(apply fn (eval `(list ,@values)))
(let ((fn (cdr (assq keyword doom-settings))))
(if fn
(apply fn values)
(when doom-debug-mode
(message "No setting found for %s" keyword)))))