Refactor doom init process

- Refactors doom-initialize
- Moves doom-initialize-modules call to init.el, to more easily isolate
  it during unit testing.
This commit is contained in:
Henrik Lissner 2019-08-23 20:33:30 -04:00
parent 465122320d
commit 8ac1e1a781
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
7 changed files with 53 additions and 48 deletions

View file

@ -79,9 +79,12 @@
(error "%s does not exist" emacs-dir))
;; Bootstrap Doom
(load (expand-file-name "init" emacs-dir)
(load (expand-file-name "core/core.el" emacs-dir)
nil 'nomessage)
(doom-initialize 'force-p)
(doom-initialize-modules)
(cond ((not noninteractive)
(doom-run-all-startup-hooks-h))
((and (not (cdr args))
@ -90,9 +93,9 @@
((not args)
(print! (error "No command detected.\n"))
(usage))
((let ((default-directory emacs-dir))
(setq argv nil
noninteractive 'doom)
((require 'core-cli)
(let ((default-directory emacs-dir))
(setq argv nil)
(condition-case e
(doom-dispatch (car args) (cdr args))
(user-error

View file

@ -199,16 +199,9 @@
(error "No DOOMDIR was found, did you run `doom install` yet?"))
(let ((indent 2))
;; Make sure everything is loaded
(require 'core-cli)
(require 'core-keybinds)
(require 'core-ui)
(require 'core-projects)
(require 'core-editor)
(require 'core-packages)
;; ...and initialized
(doom-initialize)
;; Make sure Doom is initialized and loaded
(doom-initialize 'force)
(doom-initialize-core)
(success! "Initialized Doom Emacs %s" doom-version)
(doom-initialize-modules)
@ -216,7 +209,6 @@
(success! "Initialized %d modules" (hash-table-count doom-modules))
(warn! "Failed to load any modules. Do you have an private init.el?"))
(doom-ensure-straight)
(doom-initialize-packages)
(success! "Initialized %d packages" (length doom-packages))

View file

@ -93,7 +93,9 @@ If RECOMPILE-P is non-nil, only recompile out-of-date files."
;; But first we must be sure that Doom and your private config have been
;; fully loaded. Which usually aren't so in an noninteractive session.
(let (noninteractive)
(doom-initialize 'force-p))
(doom-initialize 'force)
(doom-initialize-core)
(doom-initialize-modules 'force))
;;
(unless target-dirs
@ -102,9 +104,10 @@ If RECOMPILE-P is non-nil, only recompile out-of-date files."
(appendq! target-dirs
(list doom-core-dir)
(nreverse
(cl-remove-if-not (lambda (path) (file-in-directory-p path doom-emacs-dir))
;; Omit `doom-private-dir', which is always first
(cdr (doom-module-load-path))))))
(cl-remove-if-not
(lambda (path) (file-in-directory-p path doom-emacs-dir))
;; Omit `doom-private-dir', which is always first
(cdr (doom-module-load-path))))))
;; Assemble el files we want to compile; taking into account that MODULES
;; may be a list of MODULE/SUBMODULE strings from the command line.

View file

@ -147,6 +147,7 @@ a list of packages that will be installed."
(condition-case e
(let (packages errors)
(load ,(concat doom-core-dir "core.el"))
(doom-initialize 'force-p)
(dolist (recipe ',group)
(when (straight--repository-is-available-p recipe)
(straight-vc-git--destructure recipe

View file

@ -135,12 +135,14 @@ This ensure `doom-packages' is populated, if isn't aren't already. Use this
before any of straight's or Doom's package management's API to ensure all the
necessary package metadata is initialized and available for them."
(when (or force-p (not (bound-and-true-p package--initialized)))
(doom-log "Initializing package.el")
(require 'package)
(package-initialize))
(when (or force-p (not doom-init-packages-p))
(doom-log "Initializing straight")
(setq doom-init-packages-p t)
(unless (fboundp 'straight--reset-caches)
(doom-ensure-straight)
(require 'straight))
(straight--reset-caches)
(mapc #'straight-use-recipes doom-core-package-sources)
@ -181,8 +183,9 @@ necessary package metadata is initialized and available for them."
(user-emacs-directory straight-base-dir)
(bootstrap-file (doom-path straight-base-dir "straight/repos/straight.el/straight.el"))
(bootstrap-version 5))
(make-directory (doom-path straight-base-dir "straight/build") 'parents)
(unless (featurep 'straight)
(unless (or (require 'staight nil t)
(unless (or (require 'straight nil t)
(file-readable-p bootstrap-file))
(with-current-buffer
(url-retrieve-synchronously

View file

@ -117,6 +117,9 @@ users).")
;;
;;; Emacs core configuration
;; Ensure `doom-core-dir' is in `load-path'
(push doom-core-dir load-path)
;; Reduce debug output, well, unless we've asked for it.
(setq debug-on-error doom-debug-mode
jka-compr-verbose doom-debug-mode)
@ -470,6 +473,13 @@ to least)."
(require 'core-lib)
(require 'core-modules)
;; Load shell environment, optionally generated from 'doom env'
(when (and (or (display-graphic-p)
(daemonp))
(file-exists-p doom-env-file))
(doom-load-envvars-file doom-env-file))
(let (;; `doom-autoload-file' tells Emacs where to load all its functions
;; from. This includes everything in core/autoload/*.el and autoload
;; files in enabled modules.
@ -494,9 +504,8 @@ to least)."
;; Eagerly load these libraries because this module may be loaded in a session
;; that hasn't been fully initialized (where autoloads files haven't been
;; generated or `load-path' populated).
(let ((default-directory doom-core-dir))
(mapc (doom-rpartial #'load 'noerror 'nomessage)
(file-expand-wildcards "autoload/*.el")))
(mapc (doom-rpartial #'load 'noerror 'nomessage)
(file-expand-wildcards (concat doom-core-dir "autoload/*.el")))
;; Create all our core directories to quell file errors
(dolist (dir (list doom-local-dir
@ -509,7 +518,6 @@ to least)."
;; Ensure the package management system (and straight) are ready for
;; action (and all core packages/repos are installed)
(require 'core-packages)
(doom-ensure-straight)
(doom-initialize-packages force-p))
(unless (or (and core-autoloads-p pkg-autoloads-p)
@ -519,30 +527,14 @@ to least)."
(message "Your Doom core autoloads file is missing"))
(unless pkg-autoloads-p
(message "Your package autoloads file is missing"))
(user-error "Run `bin/doom refresh' to generate them")))
(user-error "Run `bin/doom refresh' to generate them")))))
;; Load shell environment, optionally generated from 'doom env'
(if noninteractive
(require 'core-cli)
(when (file-exists-p doom-env-file)
(doom-load-envvars-file doom-env-file))
(add-hook 'window-setup-hook #'doom-display-benchmark-h)
(require 'core-keybinds)
(require 'core-ui)
(require 'core-projects)
(require 'core-editor)
(when (cdr command-line-args)
(add-to-list 'command-switch-alist
(cons "--restore" #'doom-restore-session-handler))))))
;;
;;; Bootstrap Doom
(doom-initialize noninteractive)
(doom-initialize-modules)
(defun doom-initialize-core ()
"Load Doom's core files for an interactive session."
(require 'core-keybinds)
(require 'core-ui)
(require 'core-projects)
(require 'core-editor))
(provide 'core)
;;; core.el ends here

13
init.el
View file

@ -45,5 +45,16 @@
;; to skip the mtime checks on every *.elc file we load.
(setq load-prefer-newer noninteractive)
;; Let 'er rip!
;; Load the heart of Doom Emacs
(require 'core (concat user-emacs-directory "core/core"))
;; And let 'er rip!
(unless noninteractive
(add-hook 'window-setup-hook #'doom-display-benchmark-h)
(when (cdr command-line-args)
(add-to-list 'command-switch-alist
(cons "--restore" #'doom-restore-session-handler))))
(doom-initialize)
(doom-initialize-core)
(doom-initialize-modules)