Refactor to revolve module tree roots around doom! calls
Any module can now use a doom! call to declare a module tree root. This means that if you have a doom! block in ~/.emacs.d/modules/lang/org/init.el, then you can have submodules in ~/.emacs.d/modules/lang/org/modules/MODULE/SUBMODULE if you wanted to for some reason. This is only really truly useful for private modules. A doom! block in ~/.doom.d/init.el will recognize and enable modules in ~/.doom.d/modules/.
This commit is contained in:
parent
d04a1fa940
commit
bae226b94f
3 changed files with 32 additions and 30 deletions
|
@ -185,7 +185,8 @@ it anyway."
|
||||||
|
|
||||||
(defun doom-initialize-packages (&optional force-p load-p)
|
(defun doom-initialize-packages (&optional force-p load-p)
|
||||||
"Crawls across your emacs.d to fill `doom-modules' (from init.el) and
|
"Crawls across your emacs.d to fill `doom-modules' (from init.el) and
|
||||||
`doom-packages' (from packages.el files), if they aren't set already.
|
`doom-packages' (from packages.el files), if they aren't set already. Also runs
|
||||||
|
every enabled module's init.el.
|
||||||
|
|
||||||
If FORCE-P is non-nil, do it even if they are.
|
If FORCE-P is non-nil, do it even if they are.
|
||||||
|
|
||||||
|
@ -218,23 +219,25 @@ This aggressively reloads core autoload files."
|
||||||
(_load (expand-file-name "packages.el" doom-core-dir))
|
(_load (expand-file-name "packages.el" doom-core-dir))
|
||||||
(cl-loop for key being the hash-keys of doom-modules
|
(cl-loop for key being the hash-keys of doom-modules
|
||||||
if (doom-module-path (car key) (cdr key) "packages.el")
|
if (doom-module-path (car key) (cdr key) "packages.el")
|
||||||
do (doom-module-load-file (car key) (cdr key) it))
|
do (let ((doom--current-module key)) (_load it)))
|
||||||
(cl-loop for dir in doom-psuedo-module-dirs
|
(cl-loop for dir in doom-psuedo-module-dirs
|
||||||
for path = (expand-file-name "packages.el" dir)
|
for path = (expand-file-name "packages.el" dir)
|
||||||
if (file-exists-p path)
|
if (file-exists-p path)
|
||||||
do (_load path))))))
|
do (_load path))))))
|
||||||
|
|
||||||
(defun doom-module-path (module submodule &optional file)
|
(defun doom-module-path (module submodule &optional file root)
|
||||||
"Get the full path to a module: e.g. :lang emacs-lisp maps to
|
"Get the full path to a module: e.g. :lang emacs-lisp maps to
|
||||||
~/.emacs.d/modules/lang/emacs-lisp/ and will append FILE if non-nil."
|
~/.emacs.d/modules/lang/emacs-lisp/ and will append FILE if non-nil."
|
||||||
(when (keywordp module)
|
(when (keywordp module)
|
||||||
(setq module (substring (symbol-name module) 1)))
|
(setq module (substring (symbol-name module) 1)))
|
||||||
(when (symbolp submodule)
|
(when (symbolp submodule)
|
||||||
(setq submodule (symbol-name submodule)))
|
(setq submodule (symbol-name submodule)))
|
||||||
(cl-loop for default-directory in doom-modules-dirs
|
(if root
|
||||||
for path = (concat module "/" submodule "/" file)
|
(expand-file-name (concat "modules/" module "/" submodule "/" file) root)
|
||||||
if (file-exists-p path)
|
(cl-loop for default-directory in doom-modules-dirs
|
||||||
return (expand-file-name path)))
|
for path = (concat module "/" submodule "/" file)
|
||||||
|
if (file-exists-p path)
|
||||||
|
return (expand-file-name path))))
|
||||||
|
|
||||||
(defun doom-module-from-path (&optional path)
|
(defun doom-module-from-path (&optional path)
|
||||||
"Get module cons cell (MODULE . SUBMODULE) for PATH, if possible."
|
"Get module cons cell (MODULE . SUBMODULE) for PATH, if possible."
|
||||||
|
@ -281,13 +284,6 @@ Used by `require!' and `depends-on!'."
|
||||||
'(t))
|
'(t))
|
||||||
doom-modules)))
|
doom-modules)))
|
||||||
|
|
||||||
(defun doom-module-load-file (module submodule file &optional path)
|
|
||||||
"Load FILE in MODULE/SUBMODULE. If PATH is specified, look for FILE in PATH."
|
|
||||||
(unless (or path (file-name-absolute-p file))
|
|
||||||
(setq path (doom-module-path module submodule file)))
|
|
||||||
(let ((doom--current-module (cons module submodule)))
|
|
||||||
(load (expand-file-name file path) :noerror (not doom-debug-mode))))
|
|
||||||
|
|
||||||
(defun doom-packages--display-benchmark ()
|
(defun doom-packages--display-benchmark ()
|
||||||
(message "Doom loaded %s packages across %d modules in %.03fs"
|
(message "Doom loaded %s packages across %d modules in %.03fs"
|
||||||
;; Certainly imprecise, especially where custom additions to
|
;; Certainly imprecise, especially where custom additions to
|
||||||
|
@ -309,17 +305,21 @@ Used by `require!' and `depends-on!'."
|
||||||
|
|
||||||
MODULES is an malformed plist of modules to load."
|
MODULES is an malformed plist of modules to load."
|
||||||
(let (init-forms config-forms module file-name-handler-alist)
|
(let (init-forms config-forms module file-name-handler-alist)
|
||||||
(dolist (m modules)
|
(let ((modules-dir (file-name-directory (or load-file-name byte-compile-current-file))))
|
||||||
(cond ((keywordp m) (setq module m))
|
(add-to-list 'doom-modules-dirs (expand-file-name "modules/" modules-dir))
|
||||||
((not module) (error "No namespace specified in `doom!' for %s" m))
|
(dolist (m modules)
|
||||||
((let ((submodule (if (listp m) (car m) m))
|
(cond ((keywordp m) (setq module m))
|
||||||
(flags (if (listp m) (cdr m))))
|
((not module) (error "No namespace specified in `doom!' for %s" m))
|
||||||
(doom-module-enable module submodule flags)
|
((let ((submodule (if (listp m) (car m) m))
|
||||||
(let ((path (doom-module-path module submodule)))
|
(flags (if (listp m) (cdr m))))
|
||||||
(push `(doom-module-load-file ,module ',submodule "init" ,path) init-forms)
|
(doom-module-enable module submodule flags)
|
||||||
(push `(doom-module-load-file ,module ',submodule "config" ,path) config-forms))))))
|
(let ((path (doom-module-path module submodule nil modules-dir))
|
||||||
|
(mod `(doom--current-module ',(cons module submodule))))
|
||||||
|
(push `(let (,mod) (load! init ,path t)) init-forms)
|
||||||
|
(push `(let (,mod) (load! config ,path t)) config-forms)))))))
|
||||||
`(let (file-name-handler-alist)
|
`(let (file-name-handler-alist)
|
||||||
(setq doom-modules ',doom-modules)
|
(setq doom-modules ',doom-modules
|
||||||
|
doom-modules-dirs ',doom-modules-dirs)
|
||||||
,@(nreverse init-forms)
|
,@(nreverse init-forms)
|
||||||
(unless noninteractive
|
(unless noninteractive
|
||||||
,@(nreverse config-forms)))))
|
,@(nreverse config-forms)))))
|
||||||
|
@ -403,9 +403,11 @@ The module is only loaded once. If RELOAD-P is non-nil, load it again."
|
||||||
(doom-module-enable module submodule flags))
|
(doom-module-enable module submodule flags))
|
||||||
(if (file-directory-p module-path)
|
(if (file-directory-p module-path)
|
||||||
`(condition-case-unless-debug ex
|
`(condition-case-unless-debug ex
|
||||||
(progn
|
(let ((doom--current-module (cons module submodule)))
|
||||||
(doom-module-load-file ,module ',submodule "init" ,module-path)
|
(load ,(doom-module-path module submodule "init")
|
||||||
(doom-module-load-file ,module ',submodule "config" ,module-path))
|
:noerror (not doom-debug-mode))
|
||||||
|
(load ,(doom-module-path module submodule "config")
|
||||||
|
:noerror (not doom-debug-mode)))
|
||||||
('error
|
('error
|
||||||
(lwarn 'doom-modules :error
|
(lwarn 'doom-modules :error
|
||||||
"%s in '%s %s' -> %s"
|
"%s in '%s %s' -> %s"
|
||||||
|
|
|
@ -34,7 +34,7 @@ line or use --debug-init to enable this.")
|
||||||
(defvar doom-modules-dir (concat doom-emacs-dir "modules/")
|
(defvar doom-modules-dir (concat doom-emacs-dir "modules/")
|
||||||
"The main directory where Doom modules are stored.")
|
"The main directory where Doom modules are stored.")
|
||||||
|
|
||||||
(defvar doom-modules-dirs (list doom-modules-dir)
|
(defvar doom-modules-dirs nil
|
||||||
"A list of module root directories. Order determines priority.")
|
"A list of module root directories. Order determines priority.")
|
||||||
|
|
||||||
(defvar doom-local-dir (concat doom-emacs-dir ".local/")
|
(defvar doom-local-dir (concat doom-emacs-dir ".local/")
|
||||||
|
|
|
@ -8,9 +8,9 @@
|
||||||
Doom Emacs.")
|
Doom Emacs.")
|
||||||
|
|
||||||
;; Ensure `doom//reload-autoloads', `doom//byte-compile' and
|
;; Ensure `doom//reload-autoloads', `doom//byte-compile' and
|
||||||
;; `doom-initialize-packages' all include this module in their operations.
|
;; `doom-initialize-packages' will treat `+private-config-path' as the root of
|
||||||
|
;; this module.
|
||||||
(add-to-list 'doom-psuedo-module-dirs +private-config-path)
|
(add-to-list 'doom-psuedo-module-dirs +private-config-path)
|
||||||
(add-to-list 'doom-modules-dirs (expand-file-name "modules/" +private-config-path))
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
(load (expand-file-name "init.el" +private-config-path)
|
(load (expand-file-name "init.el" +private-config-path)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue