featurep!: refactor & fix three-arg usecase

Now (featurep! :category module +flag) will work properly check for
+flag rather than just returning t if :category module were enabled.

Also update variables to match category-module nomenclature.
This commit is contained in:
Henrik Lissner 2018-07-30 23:53:05 +02:00
parent 70e0280db3
commit 9570670eb1
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -356,9 +356,9 @@ to have them return non-nil (or exploit that to overwrite Doom's config)."
(warn 'doom-modules :warning "Couldn't find module '%s %s'" (warn 'doom-modules :warning "Couldn't find module '%s %s'"
,category ',module)))) ,category ',module))))
(defmacro featurep! (module &optional submodule flag) (defmacro featurep! (category &optional module flag)
"Returns t if MODULE SUBMODULE is enabled. If FLAG is provided, returns t if "Returns t if CATEGORY MODULE is enabled. If FLAG is provided, returns t if
MODULE SUBMODULE has FLAG enabled. CATEGORY MODULE has FLAG enabled.
(featurep! :config default) (featurep! :config default)
@ -367,16 +367,17 @@ Module FLAGs are set in your config's `doom!' block, typically in
:config (default +flag1 -flag2) :config (default +flag1 -flag2)
When this macro is used from inside a module, MODULE and SUBMODULE can be When this macro is used from inside a module, CATEGORY and MODULE can be
omitted. eg. (featurep! +flag1)" omitted. eg. (featurep! +flag1)"
(and (cond (submodule (doom-module-p module submodule)) (and (cond (flag (memq flag (doom-module-get category module :flags)))
(doom--current-flags (memq module doom--current-flags)) (module (doom-module-p category module))
(doom--current-flags (memq category doom--current-flags))
((let ((module-pair ((let ((module-pair
(or doom--current-module (or doom--current-module
(doom-module-from-path (FILE!))))) (doom-module-from-path (FILE!)))))
(unless module-pair (unless module-pair
(error "featurep! couldn't detect what module its in! (in %s)" (FILE!))) (error "featurep! couldn't detect what module its in! (in %s)" (FILE!)))
(memq module (doom-module-get (car module-pair) (cdr module-pair) :flags))))) (memq category (doom-module-get (car module-pair) (cdr module-pair) :flags)))))
t)) t))