Fix module load order (delay config.el load) #441

This commit is contained in:
Henrik Lissner 2018-02-28 17:11:23 -05:00
parent 589108fdb2
commit 0b2548f7b1
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 25 additions and 12 deletions

View file

@ -308,7 +308,7 @@ MODULES is an malformed plist of modules to load."
(let (init-forms config-forms module file-name-handler-alist) (let (init-forms config-forms module file-name-handler-alist)
(let ((modules-dir (let ((modules-dir
(expand-file-name "modules/" (file-name-directory (or load-file-name byte-compile-current-file))))) (expand-file-name "modules/" (file-name-directory (or load-file-name byte-compile-current-file)))))
(add-to-list 'doom-modules-dirs modules-dir) (cl-pushnew modules-dir doom-modules-dirs :test #'string=)
(dolist (m modules) (dolist (m modules)
(cond ((keywordp m) (setq module m)) (cond ((keywordp m) (setq module m))
((not module) (error "No namespace specified in `doom!' for %s" m)) ((not module) (error "No namespace specified in `doom!' for %s" m))
@ -323,8 +323,8 @@ MODULES is an malformed plist of modules to load."
(setq doom-modules ',doom-modules (setq doom-modules ',doom-modules
doom-modules-dirs ',doom-modules-dirs) doom-modules-dirs ',doom-modules-dirs)
,@(nreverse init-forms) ,@(nreverse init-forms)
(unless noninteractive (push '(lambda () ,@(nreverse config-forms))
,@(nreverse config-forms)))))) doom--delayed-modules)))))
(defmacro def-package! (name &rest plist) (defmacro def-package! (name &rest plist)
"A thin wrapper around `use-package'." "A thin wrapper around `use-package'."

View file

@ -119,6 +119,8 @@ Use this for essential functionality.")
"A list of hooks run after DOOM initialization is complete, and after "A list of hooks run after DOOM initialization is complete, and after
`doom-init-hook'. Use this for extra, non-essential functionality.") `doom-init-hook'. Use this for extra, non-essential functionality.")
(defvar doom--delayed-modules nil)
(defun doom-try-run-hook (fn hook) (defun doom-try-run-hook (fn hook)
"Runs a hook wrapped in a `condition-case-unless-debug' block; its objective "Runs a hook wrapped in a `condition-case-unless-debug' block; its objective
is to include more information in the error message, without sacrificing your is to include more information in the error message, without sacrificing your
@ -139,8 +141,8 @@ ability to invoke the debugger in debug mode."
(eval-and-compile (eval-and-compile
(defvar doom--file-name-handler-alist file-name-handler-alist) (defvar doom--file-name-handler-alist file-name-handler-alist)
(unless (or after-init-time noninteractive) (unless (or after-init-time noninteractive)
;; One of the contributors to long startup times is the garbage collector, ;; A big contributor to long startup times is the garbage collector, so we
;; so we up its memory threshold, temporarily. It is reset later in ;; up its memory threshold, temporarily and reset it later in
;; `doom|finalize'. ;; `doom|finalize'.
(setq gc-cons-threshold 402653184 (setq gc-cons-threshold 402653184
gc-cons-percentage 0.6 gc-cons-percentage 0.6
@ -156,9 +158,15 @@ ability to invoke the debugger in debug mode."
(load! core-projects) ; making Emacs project-aware (load! core-projects) ; making Emacs project-aware
(load! core-keybinds)) ; centralized keybind system + which-key (load! core-keybinds)) ; centralized keybind system + which-key
(defun doom|finalize () (defun doom|after-init ()
"Run `doom-init-hook', `doom-post-init-hook' and reset `gc-cons-threshold', "Load the config.el file of all pending modules that have been enabled by a
`gc-cons-percentage' and `file-name-handler-alist'." recent `doom!' call. This should be attached to `after-init-hook'."
(mapc #'funcall (reverse doom--delayed-modules))
(setq doom--delayed-modules nil))
(defun doom|after-startup ()
"Run `doom-init-hook' and `doom-post-init-hook', start the Emacs server, and
display the loading benchmark."
(unless (or (not after-init-time) noninteractive) (unless (or (not after-init-time) noninteractive)
(dolist (hook '(doom-init-hook doom-post-init-hook)) (dolist (hook '(doom-init-hook doom-post-init-hook))
(run-hook-wrapped hook #'doom-try-run-hook hook)) (run-hook-wrapped hook #'doom-try-run-hook hook))
@ -166,15 +174,20 @@ ability to invoke the debugger in debug mode."
(require 'server) (require 'server)
(unless (server-running-p) (unless (server-running-p)
(server-start))) (server-start)))
(message "%s" (doom-packages--benchmark))) (message "%s" (doom-packages--benchmark))))
;; If you forget to reset this, you'll get stuttering and random freezes!
(defun doom|finalize ()
"Resets garbage collection settings to reasonable defaults (if you don't do
this, you'll get stuttering and random freezes), and resets
`file-name-handler-alist'."
(setq gc-cons-threshold 16777216 (setq gc-cons-threshold 16777216
gc-cons-percentage 0.1 gc-cons-percentage 0.1
file-name-handler-alist doom--file-name-handler-alist) file-name-handler-alist doom--file-name-handler-alist)
t) t)
(add-hook! '(emacs-startup-hook doom-reload-hook) (add-hook! '(emacs-startup-hook doom-reload-hook) #'doom|finalize)
#'doom|finalize)) (add-hook 'after-init-hook #'doom|after-init)
(add-hook 'emacs-startup-hook #'doom|after-startup))
;; ;;