refactor: make early-init.el Doom's universal bootstrapper

This centralizes Doom's core startup optimizations and, as a
side-effect, reduces the runtime of bin/doom commands substantially.
This also simplifies the user story for loading Doom remotely (for batch
sessions or doomscripts).
This commit is contained in:
Henrik Lissner 2022-09-06 19:54:16 +02:00
parent 3853dff5e1
commit c05e61536e
No known key found for this signature in database
GPG key ID: B60957CA074D39A3
2 changed files with 29 additions and 28 deletions

View file

@ -74,19 +74,20 @@
;; - The user may have a noexec flag set on /tmp, so pass the exit script to
;; /bin/sh rather than executing them directly.
;; Ensure Doom runs out of this file's parent directory (or $EMACSDIR), where
;; Doom is presumably installed.
(setq user-emacs-directory
(if (getenv-internal "EMACSDIR")
(file-name-as-directory
(file-truename (getenv-internal "EMACSDIR")))
(expand-file-name
"../" (file-name-directory (file-truename load-file-name)))))
;;
;;; Sanity checks
;; Doom's core sets up everything we need; including `doom-*-dir' variables,
;; universal defaults, and autoloads for doom-*-initialize functions.
(condition-case e
(let ((load-prefer-newer t))
(load (expand-file-name
"../early-init" (file-name-directory (file-truename load-file-name)))
nil 'nomessage))
;; Prevent ugly backtraces for trivial errors
(user-error (message "Error: %s" (cadr e))
(kill-emacs 2)))
;; UX: Abort if the user is using 'doom' as root, unless ~/.emacs.d is owned by
;; root, in which case we assume the user genuinely wants root to be their
;; primary user account for Emacs.
(when (equal (user-real-uid) 0)
;; If ~/.emacs.d is owned by root, assume the user genuinely wants root to be
;; their primary user, otherwise complain.
@ -104,16 +105,6 @@
(kill-emacs 2)))
;;
;;; Load Doom's CLI framework
(require 'doom-cli (expand-file-name "lisp/doom-cli" user-emacs-directory))
;; Load $DOOMDIR/init.el, to read the user's `doom!' block, and so users can
;; customize things early, if they like.
(load! doom-module-init-file doom-user-dir t)
;;
;;; Entry point
@ -237,7 +228,12 @@ SEE ALSO:
;;
;;; Commands
;;; Load user config + commands
;; Load $DOOMDIR/init.el, to read the user's `doom!' block and give users an
;; opportunity to customize the CLI environment, if they like. Otherwise, they
;; can do so in .doomrc or .doomproject.
(load! doom-module-init-file doom-user-dir t)
(let ((dir (doom-path doom-core-dir "cli")))
;; It'd be simple to just load these files directly, but because there could