Refactor doom--module out of featurep! workflow
Fixes a 'featurep! not used properly' error that occurs during byte compilation.
This commit is contained in:
parent
a2367866ec
commit
42e7f56a1f
1 changed files with 15 additions and 13 deletions
|
@ -90,7 +90,6 @@ missing) and shouldn't be deleted.")
|
||||||
"A backup of `load-path' before it was altered by `doom-initialize'. Used as a
|
"A backup of `load-path' before it was altered by `doom-initialize'. Used as a
|
||||||
base by `doom!' and for calculating how many packages exist.")
|
base by `doom!' and for calculating how many packages exist.")
|
||||||
|
|
||||||
(defvar doom--module nil)
|
|
||||||
(defvar doom--refresh-p nil)
|
(defvar doom--refresh-p nil)
|
||||||
|
|
||||||
(setq load-prefer-newer (or noninteractive doom-debug-mode)
|
(setq load-prefer-newer (or noninteractive doom-debug-mode)
|
||||||
|
@ -219,9 +218,7 @@ This aggressively reloads core autoload files."
|
||||||
(funcall load-fn (expand-file-name "packages.el" doom-core-dir))
|
(funcall load-fn (expand-file-name "packages.el" doom-core-dir))
|
||||||
(cl-loop for (module . submodule) in (doom--module-pairs)
|
(cl-loop for (module . submodule) in (doom--module-pairs)
|
||||||
for path = (doom-module-path module submodule "packages.el")
|
for path = (doom-module-path module submodule "packages.el")
|
||||||
do
|
do (funcall load-fn path t)))))
|
||||||
(let ((doom--module (cons module submodule)))
|
|
||||||
(funcall load-fn path t))))))
|
|
||||||
|
|
||||||
(defun doom-initialize-modules (modules)
|
(defun doom-initialize-modules (modules)
|
||||||
"Adds MODULES to `doom-modules'. MODULES must be in mplist format.
|
"Adds MODULES to `doom-modules'. MODULES must be in mplist format.
|
||||||
|
@ -252,6 +249,12 @@ This aggressively reloads core autoload files."
|
||||||
(expand-file-name (concat module "/" submodule "/" file)
|
(expand-file-name (concat module "/" submodule "/" file)
|
||||||
doom-modules-dir))
|
doom-modules-dir))
|
||||||
|
|
||||||
|
(defun doom-module-from-path (path)
|
||||||
|
"Get module cons cell (MODULE . SUBMODULE) for PATH, if possible."
|
||||||
|
(when (string-match (concat doom-modules-dir "\\([^/]+\\)/\\([^/]+\\)/") path)
|
||||||
|
(cons (intern (concat ":" (match-string 1 path)))
|
||||||
|
(intern (match-string 2 path)))))
|
||||||
|
|
||||||
(defun doom-module-flags (module submodule)
|
(defun doom-module-flags (module submodule)
|
||||||
"Returns a list of flags provided for MODULE SUBMODULE."
|
"Returns a list of flags provided for MODULE SUBMODULE."
|
||||||
(and (hash-table-p doom-modules)
|
(and (hash-table-p doom-modules)
|
||||||
|
@ -288,8 +291,6 @@ added, if the file exists."
|
||||||
if (file-exists-p path)
|
if (file-exists-p path)
|
||||||
collect path))
|
collect path))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(defun doom--display-benchmark ()
|
(defun doom--display-benchmark ()
|
||||||
(message "Loaded %s packages in %.03fs"
|
(message "Loaded %s packages in %.03fs"
|
||||||
;; Certainly imprecise, especially where custom additions to
|
;; Certainly imprecise, especially where custom additions to
|
||||||
|
@ -406,8 +407,7 @@ The module is only loaded once. If RELOAD-P is non-nil, load it again."
|
||||||
(unless loaded-p
|
(unless loaded-p
|
||||||
(doom-module-enable module submodule flags))
|
(doom-module-enable module submodule flags))
|
||||||
`(condition-case-unless-debug ex
|
`(condition-case-unless-debug ex
|
||||||
(let ((doom--module ',(cons module submodule)))
|
(load! config ,(doom-module-path module submodule) t)
|
||||||
(load! config ,(doom-module-path module submodule) t))
|
|
||||||
('error
|
('error
|
||||||
(lwarn 'doom-modules :error
|
(lwarn 'doom-modules :error
|
||||||
"%s in '%s %s' -> %s"
|
"%s in '%s %s' -> %s"
|
||||||
|
@ -418,11 +418,13 @@ The module is only loaded once. If RELOAD-P is non-nil, load it again."
|
||||||
"A convenience macro wrapper for `doom-module-loaded-p'. It is evaluated at
|
"A convenience macro wrapper for `doom-module-loaded-p'. It is evaluated at
|
||||||
compile-time/macro-expansion time."
|
compile-time/macro-expansion time."
|
||||||
(unless submodule
|
(unless submodule
|
||||||
(unless doom--module
|
(let* ((path (or load-file-name byte-compile-current-file))
|
||||||
(error "featurep! was used incorrectly (doom--module wasn't unset)"))
|
(module-pair (doom-module-from-path path)))
|
||||||
|
(unless module-pair
|
||||||
|
(error "featurep! couldn't detect what module I'm in! (in %s)" path))
|
||||||
(setq flag module
|
(setq flag module
|
||||||
module (car doom--module)
|
module (car module-pair)
|
||||||
submodule (cdr doom--module)))
|
submodule (cdr module-pair))))
|
||||||
(if flag
|
(if flag
|
||||||
(and (memq flag (doom-module-flags module submodule)) t)
|
(and (memq flag (doom-module-flags module submodule)) t)
|
||||||
(doom-module-loaded-p module submodule)))
|
(doom-module-loaded-p module submodule)))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue