Rewrite require! and change depends-on!
depends-on! was changed to no longer load a specified module's packages.el, but to preform a module-enabled assertion. It emits an error if the linked module isn't (or specified flags aren't) enabled.
This commit is contained in:
parent
03b76e1789
commit
ff42cf0767
2 changed files with 37 additions and 23 deletions
|
@ -409,22 +409,29 @@ to have them return non-nil (or exploit that to overwrite Doom's config)."
|
||||||
(substring (symbol-name when) 1)))
|
(substring (symbol-name when) 1)))
|
||||||
,@body)))
|
,@body)))
|
||||||
|
|
||||||
(defmacro require! (category module &rest plist)
|
(defmacro require! (category module &rest flags)
|
||||||
"Loads the module specified by CATEGORY (a keyword) and MODULE (a symbol)."
|
"Loads the CATEGORY MODULE module with FLAGS.
|
||||||
`(let ((module-path (doom-module-locate-path ,category ',module)))
|
|
||||||
|
CATEGORY is a keyword, MODULE is a symbol and FLAGS are symbols.
|
||||||
|
|
||||||
|
(require! :lang php +lsp)
|
||||||
|
|
||||||
|
This is for testing and internal use. This is not the correct way to enable a
|
||||||
|
module."
|
||||||
|
`(let ((doom-modules ,doom-modules)
|
||||||
|
(module-path (doom-module-locate-path ,category ',module)))
|
||||||
(doom-module-set
|
(doom-module-set
|
||||||
,category ',module
|
,category ',module
|
||||||
,@(when plist
|
,@(let ((plist (doom-module-get category module)))
|
||||||
(let ((old-plist (doom-module-get category module)))
|
(when flags
|
||||||
(unless (plist-member plist :flags)
|
(plist-put plist :flags flags))
|
||||||
(plist-put plist :flags (plist-get old-plist :flags)))
|
|
||||||
(unless (plist-member plist :path)
|
(unless (plist-member plist :path)
|
||||||
(plist-put plist :path (or (plist-get old-plist :path)
|
(plist-put plist :path (doom-module-locate-path category module)))
|
||||||
(doom-module-locate-path category module)))))
|
|
||||||
plist))
|
plist))
|
||||||
(if (directory-name-p module-path)
|
(if (directory-name-p module-path)
|
||||||
(condition-case-unless-debug ex
|
(condition-case-unless-debug ex
|
||||||
(let ((doom--current-module ',(cons category module)))
|
(let ((doom--current-module ',(cons category module))
|
||||||
|
(doom--current-flags ',flags))
|
||||||
(load! "init" module-path :noerror)
|
(load! "init" module-path :noerror)
|
||||||
(let ((doom--stage 'config))
|
(let ((doom--stage 'config))
|
||||||
(load! "config" module-path :noerror)))
|
(load! "config" module-path :noerror)))
|
||||||
|
|
|
@ -215,8 +215,7 @@ elsewhere."
|
||||||
(not (memq ',name doom-disabled-packages)))))))
|
(not (memq ',name doom-disabled-packages)))))))
|
||||||
|
|
||||||
(defmacro packages! (&rest packages)
|
(defmacro packages! (&rest packages)
|
||||||
"A convenience macro like `package!', but allows you to declare multiple
|
"A convenience macro for `package!' for declaring multiple packages at once.
|
||||||
packages at once.
|
|
||||||
|
|
||||||
Only use this macro in a module's packages.el file."
|
Only use this macro in a module's packages.el file."
|
||||||
(doom--assert-stage-p 'packages #'packages!)
|
(doom--assert-stage-p 'packages #'packages!)
|
||||||
|
@ -234,19 +233,27 @@ Only use this macro in a module's packages.el file."
|
||||||
(cl-loop for pkg in packages
|
(cl-loop for pkg in packages
|
||||||
collect (macroexpand `(package! ,pkg :disable t)))))
|
collect (macroexpand `(package! ,pkg :disable t)))))
|
||||||
|
|
||||||
(defmacro depends-on! (module submodule &optional flags)
|
(defmacro depends-on! (category module &rest flags)
|
||||||
"Declares that this module depends on another.
|
"Declares that this CATEGORY depends on another.
|
||||||
|
|
||||||
Only use this macro in a module's packages.el file.
|
Emits a warning if CATEGORY MODULE isn't enabled, or is enabled without FLAGS.
|
||||||
|
|
||||||
MODULE is a keyword, and SUBMODULE is a symbol. Under the hood, this simply
|
Only use this macro in a CATEGORY's packages.el file."
|
||||||
loads MODULE SUBMODULE's packages.el file."
|
|
||||||
(doom--assert-stage-p 'packages #'depends-on!)
|
(doom--assert-stage-p 'packages #'depends-on!)
|
||||||
`(let ((doom-modules ,doom-modules)
|
`(let ((desired-flags ',flags))
|
||||||
(flags ,flags))
|
(unless (doom-module-locate-path ,category ',module)
|
||||||
(when flags
|
(error "The '%s %s' module is required, but doesn't exist"
|
||||||
(doom-module-put ,module ',submodule :flags flags))
|
,category ',module))
|
||||||
(load! "packages" ,(doom-module-locate-path module submodule) t)))
|
(unless (doom-module-p ,category ',module)
|
||||||
|
(error "The '%s %s' module is required, but disabled"
|
||||||
|
,category ',module))
|
||||||
|
(let ((flags (doom-module-get ,category ',module :flags)))
|
||||||
|
(when (and desired-flags
|
||||||
|
(/= (length (cl-intersection flags desired-flags))
|
||||||
|
(length desired-flags)))
|
||||||
|
(error "The '%s %s' module is missing the required %S flag(s)"
|
||||||
|
,category ',module
|
||||||
|
(cl-set-difference desired-flags flags))))))
|
||||||
|
|
||||||
(provide 'core-packages)
|
(provide 'core-packages)
|
||||||
;;; core-packages.el ends here
|
;;; core-packages.el ends here
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue