Refactor module load process

doom! no longer loads modules, it only sets
doom-modules (incrementally).

Instead, modules are loaded by doom-initialize-modules (which makes more
sense).
This commit is contained in:
Henrik Lissner 2018-08-08 21:45:07 +02:00
parent f88a97177c
commit 6eafdd7c62
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
3 changed files with 51 additions and 62 deletions

View file

@ -38,12 +38,22 @@ session of Dooming. Will noop if used more than once, unless FORCE-P is
non-nil."
(when (or force-p (not doom-init-modules-p))
(setq doom-init-modules-p t)
(when doom-private-dir
(condition-case e
(load (expand-file-name "init" doom-private-dir)
'noerror 'nomessage)
((debug doom-error) (signal (car e) (cdr e)))
((debug error) (signal 'doom-private-error (list "init.el" e)))))))
(load! "init" doom-private-dir t)
(maphash (lambda (key plist)
(let ((doom--current-module key)
(doom--current-flags (plist-get plist :flags)))
(load! "init" (plist-get plist :path) t)))
doom-modules)
(run-hook-wrapped 'doom-init-hook #'doom-try-run-hook)
(unless noninteractive
(maphash (lambda (key plist)
(let ((doom--current-module key)
(doom--current-flags (plist-get plist :flags)))
(load! "config" (plist-get plist :path) t)))
doom-modules)
(load! "config" doom-private-dir t)
(run-hook-wrapped 'doom-post-init-hook #'doom-try-run-hook))))
;;
@ -159,14 +169,13 @@ non-nil, return paths of possible modules, activated or otherwise."
"Minimally initialize `doom-modules' (a hash table) and return it."
(or (unless refresh-p doom-modules)
(let ((noninteractive t)
doom-init-modules-p)
(message "Initializing modules")
(doom-initialize-modules t)
(unless doom-modules
(setq doom-modules
(doom-modules
(make-hash-table :test #'equal
:size 20
:rehash-threshold 1.0)))
:rehash-threshold 1.0))
doom-init-modules-p)
(message "Initializing modules")
(load! "init" doom-private-dir t)
doom-modules)))
@ -260,13 +269,14 @@ The overall load order of Doom is as follows:
Module load order is determined by your `doom!' block. See `doom-modules-dirs'
for a list of all recognized module trees. Order defines precedence (from most
to least)."
(let ((doom-modules
(unless doom-modules
(setq doom-modules
(make-hash-table :test #'equal
:size (if modules (length modules) 100)
:rehash-threshold 1.0))
category init-forms config-forms)
:rehash-threshold 1.0)))
(let (category m)
(while modules
(let ((m (pop modules)))
(setq m (pop modules))
(cond ((keywordp m) (setq category m))
((not category) (error "No module category specified for %s" m))
((catch 'doom-modules
@ -282,28 +292,10 @@ to least)."
(dolist (key newkeys)
(setq modules (append key modules)))
(throw 'doom-modules t))))
(let ((path (doom-module-locate-path category module)))
(if (not path)
(message "Warning: couldn't find the %s %s module" category module)
(let ((key (cons category module)))
(if-let* ((path (doom-module-locate-path category module)))
(doom-module-set category module :flags flags :path path)
(push `(let ((doom--current-module ',key)
(doom--current-flags ',flags))
(load! "init" ,path t))
init-forms)
(push `(let ((doom--current-module ',key)
(doom--current-flags ',flags))
(load! "config" ,path t))
config-forms))))))))))
`(let (file-name-handler-alist)
(setq doom-modules ',doom-modules)
,@(nreverse init-forms)
(run-hook-wrapped 'doom-init-hook #'doom-try-run-hook)
(unless noninteractive
(let ((doom--stage 'config))
,@(nreverse config-forms)
(when doom-private-dir
(load! "config" doom-private-dir t)))))))
(message "Warning: couldn't find the %s %s module" category module)))))))
`(setq doom-modules ',doom-modules)))
(defvar doom-disabled-packages)
(defmacro def-package! (name &rest plist)

View file

@ -9,7 +9,8 @@ If neither is available, run all tests in all enabled modules."
;; Core libraries aren't fully loaded in a noninteractive session, so we
;; reload it with `noninteractive' set to nil to force them to.
(quiet! (doom-reload-autoloads))
(doom-initialize t t)
(doom-initialize 'force t)
(doom-initialize-modules 'force)
(let ((target-paths
;; Convert targets into a list of string paths, pointing to the root
;; directory of modules

View file

@ -295,10 +295,6 @@ If RETURN-P, return the message as a string instead of displaying it."
(or doom-init-time
(setq doom-init-time (float-time (time-subtract (current-time) before-init-time))))))
(defun doom|post-init ()
"Run `doom-post-init-hook'. That's all."
(run-hook-wrapped 'doom-post-init-hook #'doom-try-run-hook))
(defun doom|run-all-startup-hooks ()
"Run all startup Emacs hooks. Meant to be executed after starting Emacs with
-q or -Q, for example:
@ -372,8 +368,8 @@ to least)."
(require 'core-os)
(when (or force-load-core-p (not noninteractive))
(add-hook! 'emacs-startup-hook
#'(doom|post-init doom|display-benchmark))
(add-hook 'emacs-startup-hook #'doom|display-benchmark)
(require 'core-ui)
(require 'core-editor)
(require 'core-projects)