diff --git a/bin/doom b/bin/doom index e731f621b..08e4f469d 100755 --- a/bin/doom +++ b/bin/doom @@ -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 diff --git a/bin/doom-doctor b/bin/doom-doctor index b7ff2a605..595fa795f 100755 --- a/bin/doom-doctor +++ b/bin/doom-doctor @@ -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)) diff --git a/core/cli/byte-compile.el b/core/cli/byte-compile.el index be3cb52bb..40fff8b81 100644 --- a/core/cli/byte-compile.el +++ b/core/cli/byte-compile.el @@ -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. diff --git a/core/cli/packages.el b/core/cli/packages.el index 067426634..6137cf60b 100644 --- a/core/cli/packages.el +++ b/core/cli/packages.el @@ -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 diff --git a/core/core-packages.el b/core/core-packages.el index a2ffd9939..fe18dacbb 100644 --- a/core/core-packages.el +++ b/core/core-packages.el @@ -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 diff --git a/core/core.el b/core/core.el index 1038233c2..710df7a87 100644 --- a/core/core.el +++ b/core/core.el @@ -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 diff --git a/init.el b/init.el index 36ab1ff04..ae47337b6 100644 --- a/init.el +++ b/init.el @@ -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)