doomemacs/core/core-set.el

40 lines
1.3 KiB
EmacsLisp
Raw Normal View History

;;; 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.")
2017-02-04 21:09:33 -05:00
(defmacro def-setting! (keyword arglist &optional docstring &rest forms)
"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."
2017-02-04 21:09:33 -05:00
(declare (indent defun) (doc-string 3))
(unless (keywordp keyword)
2017-02-04 02:53:57 -05:00
(error "Not a valid property name: %s" keyword))
2017-02-04 21:09:33 -05:00
`(push (list ,keyword
:source ,(__FILE__)
:docstring ,docstring
:fn (lambda ,arglist
,docstring
,@forms))
doom-settings))
(defmacro set! (keyword &rest rest)
2017-02-04 02:53:57 -05:00
"Set an option defined by `def-setting!'. Skip if doesn't exist."
(declare (indent defun))
2017-02-04 02:53:57 -05:00
(let* ((plist (cdr (assq keyword doom-settings)))
(fn (plist-get plist :fn)))
(when (and doom-debug-mode (not fn))
(message "No setting found for %s" keyword))
(when fn
(macroexp-progn
2017-02-04 02:53:57 -05:00
(mapcar (lambda (args) `(apply #',fn ',(-list args)))
rest)))))
(provide 'core-set)
;;; core-set.el ends here