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 ((modules-dir
(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)
(cond ((keywordp m) (setq module 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
doom-modules-dirs ',doom-modules-dirs)
,@(nreverse init-forms)
(unless noninteractive
,@(nreverse config-forms))))))
(push '(lambda () ,@(nreverse config-forms))
doom--delayed-modules)))))
(defmacro def-package! (name &rest plist)
"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
`doom-init-hook'. Use this for extra, non-essential functionality.")
(defvar doom--delayed-modules nil)
(defun doom-try-run-hook (fn hook)
"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
@ -139,8 +141,8 @@ ability to invoke the debugger in debug mode."
(eval-and-compile
(defvar doom--file-name-handler-alist file-name-handler-alist)
(unless (or after-init-time noninteractive)
;; One of the contributors to long startup times is the garbage collector,
;; so we up its memory threshold, temporarily. It is reset later in
;; A big contributor to long startup times is the garbage collector, so we
;; up its memory threshold, temporarily and reset it later in
;; `doom|finalize'.
(setq gc-cons-threshold 402653184
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-keybinds)) ; centralized keybind system + which-key
(defun doom|finalize ()
"Run `doom-init-hook', `doom-post-init-hook' and reset `gc-cons-threshold',
`gc-cons-percentage' and `file-name-handler-alist'."
(defun doom|after-init ()
"Load the config.el file of all pending modules that have been enabled by a
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)
(dolist (hook '(doom-init-hook doom-post-init-hook))
(run-hook-wrapped hook #'doom-try-run-hook hook))
@ -166,15 +174,20 @@ ability to invoke the debugger in debug mode."
(require 'server)
(unless (server-running-p)
(server-start)))
(message "%s" (doom-packages--benchmark)))
;; If you forget to reset this, you'll get stuttering and random freezes!
(message "%s" (doom-packages--benchmark))))
(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
gc-cons-percentage 0.1
file-name-handler-alist doom--file-name-handler-alist)
t)
(add-hook! '(emacs-startup-hook doom-reload-hook)
#'doom|finalize))
(add-hook! '(emacs-startup-hook doom-reload-hook) #'doom|finalize)
(add-hook 'after-init-hook #'doom|after-init)
(add-hook 'emacs-startup-hook #'doom|after-startup))
;;