fix: premature doom init in doom sub-profiles

Ensures that Doom doesn't prematurely initialize itself if a non-Doom
config tries to load Doom.
This commit is contained in:
Henrik Lissner 2022-08-02 20:22:31 +02:00
parent 2d53fe6123
commit 3a5e34d67b
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -132,37 +132,39 @@
;; ;;
;;; Bootstrap ;;; Bootstrap
;; Load the heart of Doom Emacs (let (init-file)
(unless (require 'doom (expand-file-name "lisp/doom" user-emacs-directory) t) ;; Load the heart of Doom Emacs
;; ...but if that fails, then this is likely not a Doom config. (if (require 'doom (expand-file-name "lisp/doom" user-emacs-directory) t)
(setq early-init-file (expand-file-name "early-init" user-emacs-directory)) ;; ...and prepare for an interactive session.
(load early-init-file t (not init-file-debug))) (setq init-file (expand-file-name "doom-start" doom-core-dir))
;; ...but if that fails, then this is likely not a Doom config.
(setq early-init-file (expand-file-name "early-init" user-emacs-directory))
(load early-init-file t (not init-file-debug)))
;; We hijack Emacs' initfile resolver to inject our own entry point. Why do ;; We hijack Emacs' initfile resolver to inject our own entry point. Why do
;; this? Because: ;; this? Because:
;; ;;
;; - It spares Emacs the effort of looking for/loading useless initfiles, like ;; - It spares Emacs the effort of looking for/loading useless initfiles, like
;; ~/.emacs and ~/_emacs. And skips ~/.emacs.d/init.el, which won't exist if ;; ~/.emacs and ~/_emacs. And skips ~/.emacs.d/init.el, which won't exist if
;; you're using Doom (fyi: doom hackers or chemacs users could then use ;; you're using Doom (fyi: doom hackers or chemacs users could then use
;; $EMACSDIR as their $DOOMDIR, if they wanted). ;; $EMACSDIR as their $DOOMDIR, if they wanted).
;; - Later, 'doom sync' will dynamically generate its bootstrap file, which ;; - Later, 'doom sync' will dynamically generate its bootstrap file, which
;; will be important for Doom's profile system later. Until then, we'll use ;; will be important for Doom's profile system later. Until then, we'll use
;; lisp/doom-start.el. ;; lisp/doom-start.el.
;; - A "fallback" initfile can be trivially specified, in case the ;; - A "fallback" initfile can be trivially specified, in case the
;; bootstrapper is missing (if the user hasn't run 'doom sync' or is a ;; bootstrapper is missing (if the user hasn't run 'doom sync' or is a
;; first-timer). This is an opportunity to display a "safe mode" environment ;; first-timer). This is an opportunity to display a "safe mode" environment
;; that's less intimidating and more helpful than the broken state errors ;; that's less intimidating and more helpful than the broken state errors
;; would've left Emacs in, otherwise. ;; would've left Emacs in, otherwise.
;; - A generated config allows for a file IO optimized startup. ;; - A generated config allows for a file IO optimized startup.
(define-advice startup--load-user-init-file (:filter-args (args) init-doom) (define-advice startup--load-user-init-file (:filter-args (args) init-doom)
"Initialize Doom Emacs in an interactive session." "Initialize Doom Emacs in an interactive session."
(list (lambda () (list (lambda ()
(if (boundp 'doom-core-dir) (or init-file
(expand-file-name "doom-start" doom-core-dir) (expand-file-name "init.el" user-emacs-directory)))
(expand-file-name "init.el" user-emacs-directory))) (when (boundp 'doom-profiles-dir)
(when (boundp 'doom-profiles-dir) (lambda ()
(lambda () (expand-file-name "safe-mode@static/init.el" doom-profiles-dir)))
(expand-file-name "safe-mode@static/init.el" doom-profiles-dir))) (caddr args))))
(caddr args)))
;;; early-init.el ends here ;;; early-init.el ends here