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." non-nil."
(when (or force-p (not doom-init-modules-p)) (when (or force-p (not doom-init-modules-p))
(setq doom-init-modules-p t) (setq doom-init-modules-p t)
(when doom-private-dir
(condition-case e (load! "init" doom-private-dir t)
(load (expand-file-name "init" doom-private-dir) (maphash (lambda (key plist)
'noerror 'nomessage) (let ((doom--current-module key)
((debug doom-error) (signal (car e) (cdr e))) (doom--current-flags (plist-get plist :flags)))
((debug error) (signal 'doom-private-error (list "init.el" e))))))) (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." "Minimally initialize `doom-modules' (a hash table) and return it."
(or (unless refresh-p doom-modules) (or (unless refresh-p doom-modules)
(let ((noninteractive t) (let ((noninteractive t)
(doom-modules
(make-hash-table :test #'equal
:size 20
:rehash-threshold 1.0))
doom-init-modules-p) doom-init-modules-p)
(message "Initializing modules") (message "Initializing modules")
(doom-initialize-modules t) (load! "init" doom-private-dir t)
(unless doom-modules
(setq doom-modules
(make-hash-table :test #'equal
:size 20
:rehash-threshold 1.0)))
doom-modules))) doom-modules)))
@ -260,50 +269,33 @@ The overall load order of Doom is as follows:
Module load order is determined by your `doom!' block. See `doom-modules-dirs' 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 for a list of all recognized module trees. Order defines precedence (from most
to least)." to least)."
(let ((doom-modules (unless doom-modules
(make-hash-table :test #'equal (setq doom-modules
:size (if modules (length modules) 100) (make-hash-table :test #'equal
:rehash-threshold 1.0)) :size (if modules (length modules) 100)
category init-forms config-forms) :rehash-threshold 1.0)))
(let (category m)
(while modules (while modules
(let ((m (pop modules))) (setq m (pop modules))
(cond ((keywordp m) (setq category m)) (cond ((keywordp m) (setq category m))
((not category) (error "No module category specified for %s" m)) ((not category) (error "No module category specified for %s" m))
((catch 'doom-modules ((catch 'doom-modules
(let* ((module (if (listp m) (car m) m)) (let* ((module (if (listp m) (car m) m))
(flags (if (listp m) (cdr m)))) (flags (if (listp m) (cdr m))))
(when-let* ((new (assoc (list category module) doom-obsolete-modules))) (when-let* ((new (assoc (list category module) doom-obsolete-modules)))
(let ((newkeys (cdr new))) (let ((newkeys (cdr new)))
(if (null newkeys) (if (null newkeys)
(message "Warning: the %s module is deprecated" key) (message "Warning: the %s module is deprecated" key)
(message "Warning: the %s module is deprecated. Use %s instead." (message "Warning: the %s module is deprecated. Use %s instead."
(list category module) newkeys) (list category module) newkeys)
(push category modules) (push category modules)
(dolist (key newkeys) (dolist (key newkeys)
(setq modules (append key modules))) (setq modules (append key modules)))
(throw 'doom-modules t)))) (throw 'doom-modules t))))
(let ((path (doom-module-locate-path category module))) (if-let* ((path (doom-module-locate-path category module)))
(if (not path) (doom-module-set category module :flags flags :path path)
(message "Warning: couldn't find the %s %s module" category module) (message "Warning: couldn't find the %s %s module" category module)))))))
(let ((key (cons category module))) `(setq doom-modules ',doom-modules)))
(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)))))))
(defvar doom-disabled-packages) (defvar doom-disabled-packages)
(defmacro def-package! (name &rest plist) (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 ;; Core libraries aren't fully loaded in a noninteractive session, so we
;; reload it with `noninteractive' set to nil to force them to. ;; reload it with `noninteractive' set to nil to force them to.
(quiet! (doom-reload-autoloads)) (quiet! (doom-reload-autoloads))
(doom-initialize t t) (doom-initialize 'force t)
(doom-initialize-modules 'force)
(let ((target-paths (let ((target-paths
;; Convert targets into a list of string paths, pointing to the root ;; Convert targets into a list of string paths, pointing to the root
;; directory of modules ;; 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 (or doom-init-time
(setq doom-init-time (float-time (time-subtract (current-time) before-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 () (defun doom|run-all-startup-hooks ()
"Run all startup Emacs hooks. Meant to be executed after starting Emacs with "Run all startup Emacs hooks. Meant to be executed after starting Emacs with
-q or -Q, for example: -q or -Q, for example:
@ -372,8 +368,8 @@ to least)."
(require 'core-os) (require 'core-os)
(when (or force-load-core-p (not noninteractive)) (when (or force-load-core-p (not noninteractive))
(add-hook! 'emacs-startup-hook (add-hook 'emacs-startup-hook #'doom|display-benchmark)
#'(doom|post-init doom|display-benchmark))
(require 'core-ui) (require 'core-ui)
(require 'core-editor) (require 'core-editor)
(require 'core-projects) (require 'core-projects)