Refactor doom! to support nested calls #352
Isolates doom! a little more to allow for nested doom! calls.
This commit is contained in:
parent
8deea285c5
commit
3a31949483
1 changed files with 19 additions and 25 deletions
|
@ -54,7 +54,8 @@ this is nil after Emacs has started something is wrong.")
|
||||||
(defvar doom-init-time nil
|
(defvar doom-init-time nil
|
||||||
"The time it took, in seconds, for DOOM Emacs to initialize.")
|
"The time it took, in seconds, for DOOM Emacs to initialize.")
|
||||||
|
|
||||||
(defvar doom-modules ()
|
(defvar doom-modules
|
||||||
|
(make-hash-table :test #'equal :size 90 :rehash-threshold 1.0)
|
||||||
"A hash table of enabled modules. Set by `doom-initialize-modules'.")
|
"A hash table of enabled modules. Set by `doom-initialize-modules'.")
|
||||||
|
|
||||||
(defvar doom-packages ()
|
(defvar doom-packages ()
|
||||||
|
@ -200,7 +201,7 @@ This aggressively reloads core autoload files."
|
||||||
(file-relative-name file doom-emacs-dir)
|
(file-relative-name file doom-emacs-dir)
|
||||||
(error-message-string ex))))))
|
(error-message-string ex))))))
|
||||||
(when (or force-p (not doom-modules))
|
(when (or force-p (not doom-modules))
|
||||||
(setq doom-modules nil
|
(setq doom-modules (clrhash doom-modules)
|
||||||
doom-packages nil)
|
doom-packages nil)
|
||||||
(_load (concat doom-core-dir "core.el") nil 'interactive)
|
(_load (concat doom-core-dir "core.el") nil 'interactive)
|
||||||
(_load (expand-file-name "init.el" doom-emacs-dir))
|
(_load (expand-file-name "init.el" doom-emacs-dir))
|
||||||
|
@ -214,20 +215,6 @@ This aggressively reloads core autoload files."
|
||||||
for path = (doom-module-path module submodule "packages.el")
|
for path = (doom-module-path module submodule "packages.el")
|
||||||
do (_load path 'noerror))))))
|
do (_load path 'noerror))))))
|
||||||
|
|
||||||
(defun doom-initialize-modules (modules)
|
|
||||||
"Adds MODULES to `doom-modules'. MODULES must be in mplist format.
|
|
||||||
|
|
||||||
e.g '(:feature evil :lang emacs-lisp javascript java)"
|
|
||||||
(setq doom-modules (make-hash-table :test #'equal
|
|
||||||
:size (+ 5 (length modules))
|
|
||||||
:rehash-threshold 1.0))
|
|
||||||
(let (mode)
|
|
||||||
(dolist (m modules)
|
|
||||||
(cond ((keywordp m) (setq mode m))
|
|
||||||
((not mode) (error "No namespace specified on `doom!' for %s" m))
|
|
||||||
((listp m) (doom-module-enable mode (car m) (cdr m)))
|
|
||||||
(t (doom-module-enable mode m))))))
|
|
||||||
|
|
||||||
(defun doom-module-path (module submodule &optional file)
|
(defun doom-module-path (module submodule &optional file)
|
||||||
"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."
|
||||||
|
@ -305,22 +292,29 @@ include all modules, enabled or otherwise."
|
||||||
"Bootstrap DOOM Emacs.
|
"Bootstrap DOOM Emacs.
|
||||||
|
|
||||||
MODULES is an malformed plist of modules to load."
|
MODULES is an malformed plist of modules to load."
|
||||||
(doom-initialize-modules modules)
|
|
||||||
`(let (file-name-handler-alist)
|
`(let (file-name-handler-alist)
|
||||||
|
,@(let (init-forms config-forms mode)
|
||||||
|
(dolist (m modules)
|
||||||
|
(cond ((keywordp m) (setq mode m))
|
||||||
|
((not mode) (error "No namespace specified in `doom!' for %s" m))
|
||||||
|
(t
|
||||||
|
(let* ((module mode)
|
||||||
|
(submodule (if (listp m) (car m) m))
|
||||||
|
(flags (if (listp m) (cdr m)))
|
||||||
|
(path (doom-module-path module submodule)))
|
||||||
|
(doom-module-enable module submodule flags)
|
||||||
|
(push `(load! init ,path t) init-forms)
|
||||||
|
(unless noninteractive
|
||||||
|
(push `(load! config ,path t) config-forms))))))
|
||||||
|
(nconc (nreverse init-forms)
|
||||||
|
(nreverse config-forms)))
|
||||||
(setq doom-modules ',doom-modules)
|
(setq doom-modules ',doom-modules)
|
||||||
(unless noninteractive
|
(unless noninteractive
|
||||||
(message "Doom initialized")
|
|
||||||
,@(cl-loop for (module . submodule) in (doom-module-pairs)
|
|
||||||
for module-path = (doom-module-path module submodule)
|
|
||||||
collect `(load! init ,module-path t) into inits
|
|
||||||
collect `(load! config ,module-path t) into configs
|
|
||||||
finally return (append inits configs))
|
|
||||||
(when (display-graphic-p)
|
(when (display-graphic-p)
|
||||||
(require 'server)
|
(require 'server)
|
||||||
(unless (server-running-p)
|
(unless (server-running-p)
|
||||||
(server-start)))
|
(server-start)))
|
||||||
(add-hook 'doom-post-init-hook #'doom-packages--display-benchmark)
|
(add-hook 'doom-post-init-hook #'doom-packages--display-benchmark))))
|
||||||
(message "Doom modules initialized"))))
|
|
||||||
|
|
||||||
(defmacro def-package! (name &rest plist)
|
(defmacro def-package! (name &rest plist)
|
||||||
"A thin wrapper around `use-package'."
|
"A thin wrapper around `use-package'."
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue