Refactor bootstrap process + add doom-initialize-load-path
This commit is contained in:
parent
a2ab903003
commit
02c14f560d
3 changed files with 42 additions and 51 deletions
|
@ -1,6 +1,5 @@
|
|||
;;; core-lib.el -*- lexical-binding: t; -*-
|
||||
|
||||
(require 'cl-lib)
|
||||
(require 'subr-x)
|
||||
(load "async-autoloads" nil t)
|
||||
(load "persistent-soft-autoloads" nil t)
|
||||
|
|
|
@ -51,11 +51,6 @@
|
|||
"Non-nil if doom is done initializing (once `doom-post-init-hook' is done). If
|
||||
this is nil after Emacs has started something is wrong.")
|
||||
|
||||
(defvar doom-package-init-p nil
|
||||
"If non-nil, doom's package system has been initialized (by
|
||||
`doom-initialize'). This will be nill if you byte-compile your configuration (as
|
||||
intended).")
|
||||
|
||||
(defvar doom-init-time nil
|
||||
"The time it took, in seconds, for DOOM Emacs to initialize.")
|
||||
|
||||
|
@ -136,18 +131,33 @@ are installed.
|
|||
If you byte-compile core/core.el, this function will be avoided to speed up
|
||||
startup."
|
||||
;; Called early during initialization; only use native functions!
|
||||
(when (or (not doom-package-init-p) force-p)
|
||||
(when (or force-p (not doom-init-p))
|
||||
(setq load-path doom--base-load-path
|
||||
package-activated-list nil)
|
||||
;; Ensure core folders exist
|
||||
(dolist (dir (list doom-local-dir doom-etc-dir doom-cache-dir doom-packages-dir))
|
||||
(unless (file-directory-p dir)
|
||||
(make-directory dir t)))
|
||||
;; Ensure core packages are installed
|
||||
(condition-case _ (package-initialize t)
|
||||
('error
|
||||
(package-refresh-contents)
|
||||
(setq doom--refreshed-p t)
|
||||
(package-initialize t)))
|
||||
('error (package-refresh-contents)
|
||||
(setq doom--refreshed-p t)
|
||||
(package-initialize t)))
|
||||
(let ((core-packages (cl-remove-if #'package-installed-p doom-core-packages)))
|
||||
(when core-packages
|
||||
(message "Installing core packages")
|
||||
(package-refresh-contents)
|
||||
(dolist (package core-packages)
|
||||
(let ((inhibit-message t))
|
||||
(package-install package))
|
||||
(if (package-installed-p package)
|
||||
(message "✓ Installed %s" package)
|
||||
(error "✕ Couldn't install %s" package)))
|
||||
(message "Installing core packages...done")))
|
||||
(setq doom-init-p t)))
|
||||
|
||||
(defun doom-initialize-load-path (&optional force-p)
|
||||
(when (or force-p (not doom--package-load-path))
|
||||
;; We could let `package-initialize' fill `load-path', but it does more than
|
||||
;; that alone (like load autoload files). If you want something prematurely
|
||||
;; optimizated right, ya gotta do it yourself.
|
||||
|
@ -155,23 +165,7 @@ startup."
|
|||
;; Also, in some edge cases involving package initialization during a
|
||||
;; non-interactive session, `package-initialize' fails to fill `load-path'.
|
||||
(setq doom--package-load-path (directory-files package-user-dir t "^[^.]" t)
|
||||
load-path (append load-path doom--package-load-path))
|
||||
;; Ensure core packages are installed
|
||||
(dolist (pkg doom-core-packages)
|
||||
(unless (package-installed-p pkg)
|
||||
(unless doom--refreshed-p
|
||||
(package-refresh-contents)
|
||||
(setq doom--refreshed-p t))
|
||||
(let ((inhibit-message t))
|
||||
(package-install pkg))
|
||||
(if (package-installed-p pkg)
|
||||
(message "Installed %s" pkg)
|
||||
(error "Couldn't install %s" pkg))))
|
||||
(load "quelpa" nil t)
|
||||
(load "use-package" nil t)
|
||||
(setq doom-package-init-p t)
|
||||
(unless noninteractive
|
||||
(message "Doom initialized"))))
|
||||
load-path (append doom--base-load-path doom--package-load-path))))
|
||||
|
||||
(defun doom-initialize-autoloads ()
|
||||
"Ensures that `doom-autoload-file' exists and is loaded. Otherwise run
|
||||
|
@ -186,7 +180,7 @@ startup."
|
|||
If FORCE-P is non-nil, do it even if they are.
|
||||
|
||||
This aggressively reloads core autoload files."
|
||||
(doom-initialize force-p)
|
||||
(doom-initialize-load-path force-p)
|
||||
(with-temp-buffer ; prevent buffer-local settings from propagating
|
||||
(let ((noninteractive t)
|
||||
(load-prefer-newer t)
|
||||
|
@ -313,19 +307,17 @@ MODULES is an malformed plist of modules to load."
|
|||
(doom-initialize-modules modules)
|
||||
`(let (file-name-handler-alist)
|
||||
(setq doom-modules ',doom-modules)
|
||||
|
||||
(unless noninteractive
|
||||
(message "Doom initialized")
|
||||
,@(cl-loop for (module . submodule) in (doom-module-pairs)
|
||||
for module-path = (doom-module-path module submodule)
|
||||
collect `(load! init ,module-path t) into inits
|
||||
collect `(load! config ,module-path t) into configs
|
||||
finally return (append inits configs))
|
||||
|
||||
(when (display-graphic-p)
|
||||
(require 'server)
|
||||
(unless (server-running-p)
|
||||
(server-start)))
|
||||
|
||||
(add-hook 'doom-init-hook #'doom-packages--display-benchmark t)
|
||||
(message "Doom modules initialized"))))
|
||||
|
||||
|
@ -532,7 +524,7 @@ call `doom/reload-load-path' remotely (through emacsclient)."
|
|||
(when (server-running-p)
|
||||
(server-eval-at server-name '(doom//reload-load-path))))
|
||||
(t
|
||||
(doom-initialize t)
|
||||
(doom-initialize-load-path t)
|
||||
(message "Reloaded %d packages" (length doom--package-load-path))
|
||||
(run-with-timer 1 nil #'redraw-display)
|
||||
(run-hooks 'doom-reload-hook))))
|
||||
|
@ -555,7 +547,7 @@ This should be run whenever init.el or an autoload file is modified. Running
|
|||
;; state. `doom-initialize-packages' will have side effects otherwise.
|
||||
(and (doom-packages--async-run 'doom//reload-autoloads)
|
||||
(load doom-autoload-file))
|
||||
(doom-initialize-packages)
|
||||
(doom-initialize-packages t)
|
||||
(let ((targets
|
||||
(file-expand-wildcards
|
||||
(expand-file-name "autoload/*.el" doom-core-dir))))
|
||||
|
|
34
core/core.el
34
core/core.el
|
@ -112,13 +112,14 @@ melodramatic ex-vimmer disappointed with the text-editor status quo."
|
|||
(load custom-file t t)
|
||||
|
||||
;; be quiet at startup; don't load or display anything unnecessary
|
||||
(advice-add #'display-startup-echo-area-message :override #'ignore)
|
||||
(setq inhibit-startup-message t
|
||||
inhibit-startup-echo-area-message user-login-name
|
||||
inhibit-default-init t
|
||||
initial-major-mode 'fundamental-mode
|
||||
initial-scratch-message nil
|
||||
mode-line-format nil)
|
||||
(unless noninteractive
|
||||
(advice-add #'display-startup-echo-area-message :override #'ignore)
|
||||
(setq inhibit-startup-message t
|
||||
inhibit-startup-echo-area-message user-login-name
|
||||
inhibit-default-init t
|
||||
initial-major-mode 'fundamental-mode
|
||||
initial-scratch-message nil
|
||||
mode-line-format nil))
|
||||
|
||||
;; Custom init hooks; clearer than `after-init-hook', `emacs-startup-hook', and
|
||||
;; `window-setup-hook'.
|
||||
|
@ -144,10 +145,9 @@ ability to invoke the debugger in debug mode."
|
|||
nil)
|
||||
|
||||
(defun doom|finalize ()
|
||||
(unless (or doom-init-p noninteractive)
|
||||
(unless (or (not after-init-time) noninteractive)
|
||||
(dolist (hook '(doom-init-hook doom-post-init-hook))
|
||||
(run-hook-wrapped hook #'doom-try-run-hook hook))
|
||||
(setq doom-init-p t))
|
||||
(run-hook-wrapped hook #'doom-try-run-hook hook)))
|
||||
|
||||
;; Don't keep gc-cons-threshold too high. It helps to stave off the GC while
|
||||
;; Emacs starts up, but afterwards it causes stuttering and random freezes. So
|
||||
|
@ -167,10 +167,10 @@ ability to invoke the debugger in debug mode."
|
|||
gc-cons-percentage 0.6
|
||||
file-name-handler-alist nil))
|
||||
|
||||
(require 'core-packages (concat doom-core-dir "core-packages"))
|
||||
(eval-when-compile
|
||||
(doom-initialize))
|
||||
(setq load-path (eval-when-compile load-path)
|
||||
(require 'cl-lib)
|
||||
(load (concat doom-core-dir "core-packages") nil t)
|
||||
(setq load-path (eval-when-compile (doom-initialize t)
|
||||
(doom-initialize-load-path t))
|
||||
doom--package-load-path (eval-when-compile doom--package-load-path))
|
||||
|
||||
(load! core-lib)
|
||||
|
@ -187,10 +187,10 @@ ability to invoke the debugger in debug mode."
|
|||
(load! core-popups) ; taming sudden yet inevitable windows
|
||||
(load! core-editor) ; baseline configuration for text editing
|
||||
(load! core-projects) ; making Emacs project-aware
|
||||
(load! core-keybinds))) ; centralized keybind system + which-key
|
||||
(load! core-keybinds)) ; centralized keybind system + which-key
|
||||
|
||||
(add-hook! '(emacs-startup-hook doom-reload-hook)
|
||||
#'doom|finalize)
|
||||
(add-hook! '(emacs-startup-hook doom-reload-hook)
|
||||
#'doom|finalize))
|
||||
|
||||
(provide 'core)
|
||||
;;; core.el ends here
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue