From 3a5e34d67b5470aa0670d30b037d8214f2c4f8f9 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Tue, 2 Aug 2022 20:22:31 +0200 Subject: [PATCH] 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. --- early-init.el | 64 ++++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/early-init.el b/early-init.el index 8bc30d546..4335f8db1 100644 --- a/early-init.el +++ b/early-init.el @@ -132,37 +132,39 @@ ;; ;;; Bootstrap -;; Load the heart of Doom Emacs -(unless (require 'doom (expand-file-name "lisp/doom" user-emacs-directory) t) - ;; ...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))) +(let (init-file) + ;; Load the heart of Doom Emacs + (if (require 'doom (expand-file-name "lisp/doom" user-emacs-directory) t) + ;; ...and prepare for an interactive session. + (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 -;; this? Because: -;; -;; - 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 -;; you're using Doom (fyi: doom hackers or chemacs users could then use -;; $EMACSDIR as their $DOOMDIR, if they wanted). -;; - Later, 'doom sync' will dynamically generate its bootstrap file, which -;; will be important for Doom's profile system later. Until then, we'll use -;; lisp/doom-start.el. -;; - A "fallback" initfile can be trivially specified, in case the -;; 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 -;; that's less intimidating and more helpful than the broken state errors -;; would've left Emacs in, otherwise. -;; - A generated config allows for a file IO optimized startup. -(define-advice startup--load-user-init-file (:filter-args (args) init-doom) - "Initialize Doom Emacs in an interactive session." - (list (lambda () - (if (boundp 'doom-core-dir) - (expand-file-name "doom-start" doom-core-dir) - (expand-file-name "init.el" user-emacs-directory))) - (when (boundp 'doom-profiles-dir) - (lambda () - (expand-file-name "safe-mode@static/init.el" doom-profiles-dir))) - (caddr args))) + ;; We hijack Emacs' initfile resolver to inject our own entry point. Why do + ;; this? Because: + ;; + ;; - 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 + ;; you're using Doom (fyi: doom hackers or chemacs users could then use + ;; $EMACSDIR as their $DOOMDIR, if they wanted). + ;; - Later, 'doom sync' will dynamically generate its bootstrap file, which + ;; will be important for Doom's profile system later. Until then, we'll use + ;; lisp/doom-start.el. + ;; - A "fallback" initfile can be trivially specified, in case the + ;; 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 + ;; that's less intimidating and more helpful than the broken state errors + ;; would've left Emacs in, otherwise. + ;; - A generated config allows for a file IO optimized startup. + (define-advice startup--load-user-init-file (:filter-args (args) init-doom) + "Initialize Doom Emacs in an interactive session." + (list (lambda () + (or init-file + (expand-file-name "init.el" user-emacs-directory))) + (when (boundp 'doom-profiles-dir) + (lambda () + (expand-file-name "safe-mode@static/init.el" doom-profiles-dir))) + (caddr args)))) ;;; early-init.el ends here