Add core-set, def-setting! and set!; standardized settings
This commit is contained in:
parent
dbfe1f9b48
commit
194490680a
2 changed files with 51 additions and 20 deletions
36
core/core-set.el
Normal file
36
core/core-set.el
Normal file
|
@ -0,0 +1,36 @@
|
|||
;;; core-set.el
|
||||
|
||||
;; When we switch out feature modules, I don't want certain config segments to
|
||||
;; casue errors. This gives a
|
||||
|
||||
(define-key help-map "\C-s" 'doom/describe-setting)
|
||||
|
||||
(defvar doom-settings nil
|
||||
"An alist of settings, mapping setting keywords to setter functions, which can
|
||||
be a lambda or symbol.")
|
||||
|
||||
(defmacro def-setting! (keyword arglist &optional docstring &rest body)
|
||||
"Define a setting macro. Takes the same arguments as `defmacro'. This should
|
||||
return forms, which will be run when `set!' is used to call this setting."
|
||||
(declare (indent defun))
|
||||
(unless (keywordp keyword)
|
||||
(error "Not a valid property name: %s" name))
|
||||
(let ((sym (intern (format "doom--set%s" keyword))))
|
||||
(setq doom-settings (assq-delete-all keyword doom-settings))
|
||||
`(push (cons ,keyword
|
||||
(defun ,sym ,arglist
|
||||
,docstring
|
||||
,@body))
|
||||
doom-settings)))
|
||||
|
||||
(defmacro set! (keyword &rest rest)
|
||||
"Set an option defined by `doom-define-settings'. Skip if doesn't exist."
|
||||
(declare (indent defun))
|
||||
(let ((set-fn (cdr (assq keyword doom-settings))))
|
||||
(when set-fn
|
||||
(macroexp-progn
|
||||
(mapcar (lambda (&rest args) (apply set-fn args))
|
||||
rest)))))
|
||||
|
||||
(provide 'core-set)
|
||||
;;; core-set.el ends here
|
Loading…
Add table
Add a link
Reference in a new issue