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:
parent
27cbd36b69
commit
928812da8a
12 changed files with 104 additions and 107 deletions
|
@ -138,16 +138,13 @@ fundamental-mode) for performance sake."
|
|||
:init
|
||||
(def-setting! :editorconfig (action value)
|
||||
":add or :remove an entry in `editorconfig-indentation-alist'."
|
||||
`(after! editorconfig
|
||||
,(cond ((eq action :add)
|
||||
`(push ',value editorconfig-indentation-alist))
|
||||
((eq action :remove)
|
||||
(unless (symbolp value)
|
||||
(error "%s is not a valid major-mode in editorconfig-indentation-alist" value))
|
||||
`(setq editorconfig-indentation-alist
|
||||
(delq (assq ',value editorconfig-indentation-alist)
|
||||
editorconfig-indentation-alist)))
|
||||
(t (error "%s is an invalid action for :editorconfig" action)))))
|
||||
(cond ((eq action :add)
|
||||
`(push ,value editorconfig-indentation-alist))
|
||||
((eq action :remove)
|
||||
`(setq editorconfig-indentation-alist
|
||||
(assq-delete-all ,value editorconfig-indentation-alist)))
|
||||
(t (error "%s is an invalid action for :editorconfig"
|
||||
action))))
|
||||
|
||||
:config
|
||||
(add-hook 'doom-init-hook #'editorconfig-mode)
|
||||
|
|
|
@ -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)))))
|
||||
|
||||
|
|
|
@ -38,9 +38,9 @@ is enabled/disabled.'")
|
|||
|
||||
(def-setting! :popup (&rest rules)
|
||||
"Prepend a new popup rule to `shackle-rules'."
|
||||
(if (cl-every #'listp rules)
|
||||
`(setq shackle-rules (nconc ',rules shackle-rules))
|
||||
`(push ',rules shackle-rules)))
|
||||
(if (cl-every #'listp (mapcar #'doom-unquote rules))
|
||||
`(setq shackle-rules (nconc (list ,@rules) shackle-rules))
|
||||
`(push (list ,@rules) shackle-rules)))
|
||||
|
||||
|
||||
;;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue