Refactor require! macro

This commit is contained in:
Henrik Lissner 2018-06-04 00:06:01 +02:00
parent b53df20dd5
commit 9ba76b60dc
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -644,29 +644,26 @@ If NOERROR is non-nil, don't throw an error if the file doesn't exist."
filename) filename)
,noerror ,(not doom-debug-mode))) ,noerror ,(not doom-debug-mode)))
(defmacro require! (module submodule &optional reload-p &rest plist) (defmacro require! (category module &rest plist)
"Loads the module specified by MODULE (a property) and SUBMODULE (a symbol). "Loads the module specified by CATEGORY (a keyword) and MODULE (a symbol)."
(let ((enabled-p (doom-module-p category module))
The module is only loaded once. If RELOAD-P is non-nil, load it again." (doom-modules (copy-hash-table doom-modules)))
(let ((enabled-p (doom-module-p module submodule))) (apply #'doom-module-set category module
(when (or (not enabled-p) plist) (mapcar #'eval plist))
(apply #'doom-module-set module submodule (let ((module-path (doom-module-locate-path category module)))
(mapcar #'eval plist))) (if (directory-name-p module-path)
(when (or reload-p (not enabled-p)) `(condition-case-unless-debug ex
(let ((module-path (doom-module-locate-path module submodule))) (let ((doom--current-module ',(cons category module)))
(if (file-directory-p module-path) (load! "init" ,module-path :noerror)
`(condition-case-unless-debug ex (let ((doom--stage 'config))
(let ((doom--current-module ',(cons module submodule))) (load! "config" ,module-path :noerror)))
(load! "init" ,module-path :noerror) ('error
(let ((doom--stage 'config)) (lwarn 'doom-modules :error
(load! "config" ,module-path :noerror))) "%s in '%s %s' -> %s"
('error (car ex) ,category ',module
(lwarn 'doom-modules :error (error-message-string ex))))
"%s in '%s %s' -> %s" (warn 'doom-modules :warning "Couldn't find module '%s %s'"
(car ex) ,module ',submodule category module)))))
(error-message-string ex))))
(warn 'doom-modules :warning "Couldn't find module '%s %s'"
module submodule))))))
(defmacro featurep! (module &optional submodule flag) (defmacro featurep! (module &optional submodule flag)
"Returns t if MODULE SUBMODULE is enabled. If FLAG is provided, returns t if "Returns t if MODULE SUBMODULE is enabled. If FLAG is provided, returns t if