Refactor def-setting!/set! implementation
The `doom-settings` variable has been removed. Setting checks are done with fboundp now, which is simpler.
This commit is contained in:
parent
385cb476ba
commit
428f1e1d07
3 changed files with 25 additions and 27 deletions
|
@ -68,13 +68,20 @@
|
||||||
|
|
||||||
Defaults to the "
|
Defaults to the "
|
||||||
(interactive
|
(interactive
|
||||||
(let ((sym (symbol-at-point)))
|
(let ((settings (cl-loop with case-fold-search = nil
|
||||||
|
for sym being the symbols of obarray
|
||||||
|
for sym-name = (symbol-name sym)
|
||||||
|
if (string-match "^doom--set\\(:.+\\)" sym-name)
|
||||||
|
collect (match-string 1 sym-name)))
|
||||||
|
(sym (symbol-at-point)))
|
||||||
(list (completing-read "Describe setting: "
|
(list (completing-read "Describe setting: "
|
||||||
(sort (mapcar #'car doom-settings) #'string-lessp)
|
(sort settings #'string-lessp)
|
||||||
nil t (if (keywordp sym) (symbol-name sym))))))
|
nil t (if (keywordp sym) (symbol-name sym))))))
|
||||||
(let ((fn (cdr (assq (intern setting) doom-settings))))
|
(or (stringp setting)
|
||||||
(unless fn
|
(signal 'wrong-type-argument (list 'stringp setting)))
|
||||||
(error "'%s' is not a valid DOOM setting" setting))
|
(let ((fn (intern-soft (format "doom--set%s" setting))))
|
||||||
|
(or (fboundp fn)
|
||||||
|
(error "'%s' is not a valid DOOM setting" setting))
|
||||||
(describe-function fn)))
|
(describe-function fn)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
|
|
|
@ -806,9 +806,6 @@ loads MODULE SUBMODULE's packages.el file."
|
||||||
;; `set!'. If a setting doesn't exist at runtime, the `set!' call is ignored and
|
;; `set!'. If a setting doesn't exist at runtime, the `set!' call is ignored and
|
||||||
;; its arguments are left unevaluated (and entirely omitted when byte-compiled).
|
;; its arguments are left unevaluated (and entirely omitted when byte-compiled).
|
||||||
|
|
||||||
(defvar doom-settings nil
|
|
||||||
"An alist mapping setting keywords to functions.")
|
|
||||||
|
|
||||||
(defmacro def-setting! (keyword arglist &optional docstring &rest forms)
|
(defmacro def-setting! (keyword arglist &optional docstring &rest forms)
|
||||||
"Define a setting. Like `defmacro', this should return a form to be executed
|
"Define a setting. Like `defmacro', this should return a form to be executed
|
||||||
when called with `set!'. FORMS are not evaluated until `set!' calls it.
|
when called with `set!'. FORMS are not evaluated until `set!' calls it.
|
||||||
|
@ -817,14 +814,10 @@ See `doom/describe-setting' for a list of available settings.
|
||||||
|
|
||||||
Do not use this for configuring Doom core."
|
Do not use this for configuring Doom core."
|
||||||
(declare (indent defun) (doc-string 3))
|
(declare (indent defun) (doc-string 3))
|
||||||
(unless (keywordp keyword)
|
(or (keywordp keyword)
|
||||||
(error "Not a valid property name: %s" keyword))
|
(signal 'wrong-type-argument (list 'keywordp keyword)))
|
||||||
(let ((fn (intern (format "doom--set%s" keyword))))
|
`(fset ',(intern (format "doom--set%s" keyword))
|
||||||
`(progn
|
(lambda ,arglist ,docstring ,@forms)))
|
||||||
(defun ,fn ,arglist
|
|
||||||
,docstring
|
|
||||||
,@forms)
|
|
||||||
(map-put doom-settings ,keyword #',fn))))
|
|
||||||
|
|
||||||
(defmacro set! (keyword &rest values)
|
(defmacro set! (keyword &rest values)
|
||||||
"Set an option defined by `def-setting!'. Skip if doesn't exist. See
|
"Set an option defined by `def-setting!'. Skip if doesn't exist. See
|
||||||
|
@ -832,13 +825,12 @@ Do not use this for configuring Doom core."
|
||||||
|
|
||||||
VALUES doesn't get evaluated if the KEYWORD setting doesn't exist."
|
VALUES doesn't get evaluated if the KEYWORD setting doesn't exist."
|
||||||
(declare (indent defun))
|
(declare (indent defun))
|
||||||
(unless values
|
(let ((fn (intern-soft (format "doom--set%s" keyword))))
|
||||||
(error "Empty set! for %s" keyword))
|
(if (and fn (fboundp fn))
|
||||||
(if-let* ((fn (cdr (assq keyword doom-settings))))
|
(apply fn values)
|
||||||
(apply fn values)
|
(when doom-debug-mode
|
||||||
(when doom-debug-mode
|
(message "No setting found for %s" keyword)
|
||||||
(message "No setting found for %s" keyword)
|
nil))))
|
||||||
nil)))
|
|
||||||
|
|
||||||
(provide 'core-packages)
|
(provide 'core-packages)
|
||||||
;;; core-packages.el ends here
|
;;; core-packages.el ends here
|
||||||
|
|
|
@ -107,11 +107,10 @@
|
||||||
|
|
||||||
(def-test! set
|
(def-test! set
|
||||||
(eval-and-compile
|
(eval-and-compile
|
||||||
(let (doom-settings)
|
(def-setting! :-test-setting (x) `(setq result ,x))
|
||||||
(def-setting! :-test-setting (x) `(setq result ,x))
|
(should (fboundp 'doom--set:-test-setting))
|
||||||
(should (assq :-test-setting doom-settings))
|
|
||||||
(let ((inhibit-message t)
|
(let ((inhibit-message t)
|
||||||
result)
|
result)
|
||||||
(set! :-test-setting t)
|
(set! :-test-setting t)
|
||||||
(should result)
|
(should result)
|
||||||
(set! :non-existant-setting (error "This shouldn't trigger"))))))
|
(set! :non-existant-setting (error "This shouldn't trigger")))))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue