From ff42cf076741fffefc5b05058d4344233127c613 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 21 Apr 2019 19:35:27 -0400 Subject: [PATCH] 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. --- core/core-modules.el | 29 ++++++++++++++++++----------- core/core-packages.el | 31 +++++++++++++++++++------------ 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/core/core-modules.el b/core/core-modules.el index 433fcc4cb..8fb3f5c7d 100644 --- a/core/core-modules.el +++ b/core/core-modules.el @@ -409,22 +409,29 @@ to have them return non-nil (or exploit that to overwrite Doom's config)." (substring (symbol-name when) 1))) ,@body))) -(defmacro require! (category module &rest plist) - "Loads the module specified by CATEGORY (a keyword) and MODULE (a symbol)." - `(let ((module-path (doom-module-locate-path ,category ',module))) +(defmacro require! (category module &rest flags) + "Loads the CATEGORY MODULE module with FLAGS. + +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 ,category ',module - ,@(when plist - (let ((old-plist (doom-module-get category module))) - (unless (plist-member plist :flags) - (plist-put plist :flags (plist-get old-plist :flags))) - (unless (plist-member plist :path) - (plist-put plist :path (or (plist-get old-plist :path) - (doom-module-locate-path category module))))) + ,@(let ((plist (doom-module-get category module))) + (when flags + (plist-put plist :flags flags)) + (unless (plist-member plist :path) + (plist-put plist :path (doom-module-locate-path category module))) plist)) (if (directory-name-p module-path) (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) (let ((doom--stage 'config)) (load! "config" module-path :noerror))) diff --git a/core/core-packages.el b/core/core-packages.el index de4376e88..d237c0e9d 100644 --- a/core/core-packages.el +++ b/core/core-packages.el @@ -215,8 +215,7 @@ elsewhere." (not (memq ',name doom-disabled-packages))))))) (defmacro packages! (&rest packages) - "A convenience macro like `package!', but allows you to declare multiple -packages at once. + "A convenience macro for `package!' for declaring multiple packages at once. Only use this macro in a module's packages.el file." (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 collect (macroexpand `(package! ,pkg :disable t))))) -(defmacro depends-on! (module submodule &optional flags) - "Declares that this module depends on another. +(defmacro depends-on! (category module &rest flags) + "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 -loads MODULE SUBMODULE's packages.el file." +Only use this macro in a CATEGORY's packages.el file." (doom--assert-stage-p 'packages #'depends-on!) - `(let ((doom-modules ,doom-modules) - (flags ,flags)) - (when flags - (doom-module-put ,module ',submodule :flags flags)) - (load! "packages" ,(doom-module-locate-path module submodule) t))) + `(let ((desired-flags ',flags)) + (unless (doom-module-locate-path ,category ',module) + (error "The '%s %s' module is required, but doesn't exist" + ,category ',module)) + (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) ;;; core-packages.el ends here