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

View file

@ -199,16 +199,9 @@
(error "No DOOMDIR was found, did you run `doom install` yet?")) (error "No DOOMDIR was found, did you run `doom install` yet?"))
(let ((indent 2)) (let ((indent 2))
;; Make sure everything is loaded ;; Make sure Doom is initialized and loaded
(require 'core-cli) (doom-initialize 'force)
(require 'core-keybinds) (doom-initialize-core)
(require 'core-ui)
(require 'core-projects)
(require 'core-editor)
(require 'core-packages)
;; ...and initialized
(doom-initialize)
(success! "Initialized Doom Emacs %s" doom-version) (success! "Initialized Doom Emacs %s" doom-version)
(doom-initialize-modules) (doom-initialize-modules)
@ -216,7 +209,6 @@
(success! "Initialized %d modules" (hash-table-count doom-modules)) (success! "Initialized %d modules" (hash-table-count doom-modules))
(warn! "Failed to load any modules. Do you have an private init.el?")) (warn! "Failed to load any modules. Do you have an private init.el?"))
(doom-ensure-straight)
(doom-initialize-packages) (doom-initialize-packages)
(success! "Initialized %d packages" (length doom-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 ;; 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. ;; fully loaded. Which usually aren't so in an noninteractive session.
(let (noninteractive) (let (noninteractive)
(doom-initialize 'force-p)) (doom-initialize 'force)
(doom-initialize-core)
(doom-initialize-modules 'force))
;; ;;
(unless target-dirs (unless target-dirs
@ -102,9 +104,10 @@ If RECOMPILE-P is non-nil, only recompile out-of-date files."
(appendq! target-dirs (appendq! target-dirs
(list doom-core-dir) (list doom-core-dir)
(nreverse (nreverse
(cl-remove-if-not (lambda (path) (file-in-directory-p path doom-emacs-dir)) (cl-remove-if-not
;; Omit `doom-private-dir', which is always first (lambda (path) (file-in-directory-p path doom-emacs-dir))
(cdr (doom-module-load-path)))))) ;; 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 ;; Assemble el files we want to compile; taking into account that MODULES
;; may be a list of MODULE/SUBMODULE strings from the command line. ;; 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 (condition-case e
(let (packages errors) (let (packages errors)
(load ,(concat doom-core-dir "core.el")) (load ,(concat doom-core-dir "core.el"))
(doom-initialize 'force-p)
(dolist (recipe ',group) (dolist (recipe ',group)
(when (straight--repository-is-available-p recipe) (when (straight--repository-is-available-p recipe)
(straight-vc-git--destructure 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 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." necessary package metadata is initialized and available for them."
(when (or force-p (not (bound-and-true-p package--initialized))) (when (or force-p (not (bound-and-true-p package--initialized)))
(doom-log "Initializing package.el")
(require 'package) (require 'package)
(package-initialize)) (package-initialize))
(when (or force-p (not doom-init-packages-p)) (when (or force-p (not doom-init-packages-p))
(doom-log "Initializing straight") (doom-log "Initializing straight")
(setq doom-init-packages-p t) (setq doom-init-packages-p t)
(unless (fboundp 'straight--reset-caches) (unless (fboundp 'straight--reset-caches)
(doom-ensure-straight)
(require 'straight)) (require 'straight))
(straight--reset-caches) (straight--reset-caches)
(mapc #'straight-use-recipes doom-core-package-sources) (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) (user-emacs-directory straight-base-dir)
(bootstrap-file (doom-path straight-base-dir "straight/repos/straight.el/straight.el")) (bootstrap-file (doom-path straight-base-dir "straight/repos/straight.el/straight.el"))
(bootstrap-version 5)) (bootstrap-version 5))
(make-directory (doom-path straight-base-dir "straight/build") 'parents)
(unless (featurep 'straight) (unless (featurep 'straight)
(unless (or (require 'staight nil t) (unless (or (require 'straight nil t)
(file-readable-p bootstrap-file)) (file-readable-p bootstrap-file))
(with-current-buffer (with-current-buffer
(url-retrieve-synchronously (url-retrieve-synchronously

View file

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

13
init.el
View file

@ -45,5 +45,16 @@
;; to skip the mtime checks on every *.elc file we load. ;; to skip the mtime checks on every *.elc file we load.
(setq load-prefer-newer noninteractive) (setq load-prefer-newer noninteractive)
;; Let 'er rip! ;; Load the heart of Doom Emacs
(require 'core (concat user-emacs-directory "core/core")) (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)