Refactor doom-initialize functions
Removes doom-module-table; which was inflexible (though more stable). It prevented you from putting your doom! block in anywhere but ~/.doom.d/init.el. It is replaced (somewhat) by (doom-modules).
This commit is contained in:
parent
7f31704815
commit
01d1a814f9
5 changed files with 61 additions and 79 deletions
|
@ -280,8 +280,6 @@
|
||||||
(let ((inhibit-message t)
|
(let ((inhibit-message t)
|
||||||
noninteractive)
|
noninteractive)
|
||||||
(load (concat user-emacs-directory "core/core.el") nil t)
|
(load (concat user-emacs-directory "core/core.el") nil t)
|
||||||
(doom-initialize t)
|
|
||||||
(doom-initialize-modules t)
|
|
||||||
(success! "Attempt to load DOOM: success! Loaded v%s" doom-version))
|
(success! "Attempt to load DOOM: success! Loaded v%s" doom-version))
|
||||||
('error
|
('error
|
||||||
(warn! "Attempt to load DOOM: failed\n %s\n"
|
(warn! "Attempt to load DOOM: failed\n %s\n"
|
||||||
|
|
|
@ -10,10 +10,8 @@
|
||||||
(defun doom-info ()
|
(defun doom-info ()
|
||||||
"Returns diagnostic information about the current Emacs session in markdown,
|
"Returns diagnostic information about the current Emacs session in markdown,
|
||||||
ready to be pasted in a bug report on github."
|
ready to be pasted in a bug report on github."
|
||||||
(doom-initialize)
|
|
||||||
(require 'vc-git)
|
(require 'vc-git)
|
||||||
(let ((default-directory doom-emacs-dir)
|
(let ((default-directory doom-emacs-dir))
|
||||||
(doom-modules (doom-module-table)))
|
|
||||||
(format
|
(format
|
||||||
(concat "- OS: %s (%s)\n"
|
(concat "- OS: %s (%s)\n"
|
||||||
"- Emacs: %s (%s)\n"
|
"- Emacs: %s (%s)\n"
|
||||||
|
|
|
@ -30,8 +30,9 @@ init.el and config.el. Then runs `doom-reload-hook'."
|
||||||
(red "There were issues!")))))
|
(red "There were issues!")))))
|
||||||
((let ((load-prefer-newer t))
|
((let ((load-prefer-newer t))
|
||||||
(doom//reload-autoloads force-p)
|
(doom//reload-autoloads force-p)
|
||||||
(doom-initialize t)
|
(doom-initialize 'force)
|
||||||
(ignore-errors (doom-initialize-modules t))
|
(with-demoted-errors "PRIVATE CONFIG ERROR: %s"
|
||||||
|
(doom-initialize-modules 'force))
|
||||||
(print! (green "%d packages reloaded" (length package-alist)))
|
(print! (green "%d packages reloaded" (length package-alist)))
|
||||||
(run-hooks 'doom-reload-hook)
|
(run-hooks 'doom-reload-hook)
|
||||||
t))))
|
t))))
|
||||||
|
@ -105,8 +106,7 @@ Emacs where to find lazy-loaded functions.
|
||||||
This should be run whenever your `doom!' block, or a module autoload file, is
|
This should be run whenever your `doom!' block, or a module autoload file, is
|
||||||
modified."
|
modified."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let ((doom-modules (doom-module-table))
|
(let ((default-directory doom-emacs-dir)
|
||||||
(default-directory doom-emacs-dir)
|
|
||||||
(targets
|
(targets
|
||||||
(file-expand-wildcards
|
(file-expand-wildcards
|
||||||
(expand-file-name "autoload/*.el" doom-core-dir))))
|
(expand-file-name "autoload/*.el" doom-core-dir))))
|
||||||
|
@ -203,7 +203,7 @@ This should be run whenever your `doom!' block or update your packages."
|
||||||
(file-exists-p doom-package-autoload-file)
|
(file-exists-p doom-package-autoload-file)
|
||||||
(not (file-newer-than-file-p package-user-dir doom-package-autoload-file))
|
(not (file-newer-than-file-p package-user-dir doom-package-autoload-file))
|
||||||
(not (ignore-errors
|
(not (ignore-errors
|
||||||
(cl-loop for key being the hash-keys of (doom-module-table)
|
(cl-loop for key being the hash-keys of (doom-modules)
|
||||||
for path = (doom-module-path (car key) (cdr key) "packages.el")
|
for path = (doom-module-path (car key) (cdr key) "packages.el")
|
||||||
if (file-newer-than-file-p path doom-package-autoload-file)
|
if (file-newer-than-file-p path doom-package-autoload-file)
|
||||||
return t))))
|
return t))))
|
||||||
|
@ -317,19 +317,17 @@ If RECOMPILE-P is non-nil, only recompile out-of-date files."
|
||||||
(message "Aborting.")
|
(message "Aborting.")
|
||||||
(cl-return-from 'byte-compile)))
|
(cl-return-from 'byte-compile)))
|
||||||
(unless recompile-p
|
(unless recompile-p
|
||||||
(doom//clean-byte-compiled-files))
|
(doom//clean-byte-compiled-files)
|
||||||
(unless targets
|
(doom//reload-autoloads))
|
||||||
(let ((inhibit-message t)
|
(let (doom-emacs-changed-p
|
||||||
doom-emacs-changed-p
|
noninteractive)
|
||||||
noninteractive)
|
;; But first we must be sure that Doom and your private config have
|
||||||
;; But first we must be sure that Doom and your private config have
|
;; been fully loaded. Which usually aren't so in an noninteractive
|
||||||
;; been fully loaded. Which usually aren't so in an noninteractive
|
;; session.
|
||||||
;; session.
|
(doom-initialize)
|
||||||
(quiet! (doom//reload-autoloads))
|
(doom-initialize-modules 'force))
|
||||||
(doom-initialize t)))
|
|
||||||
;; If no targets were supplied, then we use your module list.
|
;; If no targets were supplied, then we use your module list.
|
||||||
(unless modules
|
(unless modules
|
||||||
(doom-initialize-modules t)
|
|
||||||
(setq targets (append (list doom-core-dir)
|
(setq targets (append (list doom-core-dir)
|
||||||
(doom-module-load-path))))
|
(doom-module-load-path))))
|
||||||
;; Assemble el files we want to compile; taking into account that
|
;; Assemble el files we want to compile; taking into account that
|
||||||
|
|
|
@ -282,9 +282,10 @@ to least)."
|
||||||
;; Loads `doom-package-autoload-file', which caches `load-path',
|
;; Loads `doom-package-autoload-file', which caches `load-path',
|
||||||
;; `auto-mode-alist', `Info-directory-list', `doom-disabled-packages' and
|
;; `auto-mode-alist', `Info-directory-list', `doom-disabled-packages' and
|
||||||
;; `package-activated-list'. A big reduction in startup time.
|
;; `package-activated-list'. A big reduction in startup time.
|
||||||
(unless (doom-initialize-autoloads doom-package-autoload-file force-p)
|
(unless (or force-p
|
||||||
(unless (or force-p noninteractive)
|
(doom-initialize-autoloads doom-package-autoload-file)
|
||||||
(doom//reload-package-autoloads))))
|
noninteractive)
|
||||||
|
(doom//reload-package-autoloads)))
|
||||||
;; Initialize Doom core
|
;; Initialize Doom core
|
||||||
(unless noninteractive
|
(unless noninteractive
|
||||||
(add-hook! 'emacs-startup-hook
|
(add-hook! 'emacs-startup-hook
|
||||||
|
@ -307,9 +308,8 @@ non-nil."
|
||||||
(load (expand-file-name "init" doom-private-dir)
|
(load (expand-file-name "init" doom-private-dir)
|
||||||
'noerror 'nomessage))))
|
'noerror 'nomessage))))
|
||||||
|
|
||||||
(defun doom-initialize-autoloads (file &optional clear-p)
|
(defun doom-initialize-autoloads (file)
|
||||||
"Tries to load FILE (an autoloads file). Otherwise tries to regenerate it. If
|
"Tries to load FILE (an autoloads file)."
|
||||||
CLEAR-P is non-nil, regenerate it anyway."
|
|
||||||
(unless clear-p
|
(unless clear-p
|
||||||
(condition-case-unless-debug e
|
(condition-case-unless-debug e
|
||||||
(load (file-name-sans-extension file) 'noerror 'nomessage)
|
(load (file-name-sans-extension file) 'noerror 'nomessage)
|
||||||
|
@ -339,7 +339,7 @@ them."
|
||||||
;; `package-alist'
|
;; `package-alist'
|
||||||
(when (or force-p (not (bound-and-true-p package-alist)))
|
(when (or force-p (not (bound-and-true-p package-alist)))
|
||||||
(setq load-path doom-site-load-path)
|
(setq load-path doom-site-load-path)
|
||||||
(doom-ensure-packages-initialized t))
|
(doom-ensure-packages-initialized 'force))
|
||||||
|
|
||||||
;; `quelpa-cache'
|
;; `quelpa-cache'
|
||||||
(when (or force-p (not (bound-and-true-p quelpa-cache)))
|
(when (or force-p (not (bound-and-true-p quelpa-cache)))
|
||||||
|
@ -351,7 +351,7 @@ them."
|
||||||
(error "Could not initialize quelpa"))))
|
(error "Could not initialize quelpa"))))
|
||||||
|
|
||||||
(when (or force-p (not doom-packages))
|
(when (or force-p (not doom-packages))
|
||||||
(let ((doom-modules (doom-module-table)))
|
(let ((doom-modules (doom-modules)))
|
||||||
(setq doom-packages nil)
|
(setq doom-packages nil)
|
||||||
(cl-flet
|
(cl-flet
|
||||||
((_load
|
((_load
|
||||||
|
@ -370,11 +370,12 @@ them."
|
||||||
;; We load the private packages file twice to ensure disabled
|
;; We load the private packages file twice to ensure disabled
|
||||||
;; packages are seen ASAP, and a second time to ensure privately
|
;; packages are seen ASAP, and a second time to ensure privately
|
||||||
;; overridden packages are properly overwritten.
|
;; overridden packages are properly overwritten.
|
||||||
(_load (expand-file-name "packages.el" doom-private-dir) t)
|
(let ((private-packages (expand-file-name "packages.el" doom-private-dir)))
|
||||||
(cl-loop for key being the hash-keys of doom-modules
|
(_load private-packages t)
|
||||||
for path = (doom-module-path (car key) (cdr key) "packages.el")
|
(cl-loop for key being the hash-keys of doom-modules
|
||||||
do (let ((doom--current-module key)) (_load path t)))
|
for path = (doom-module-path (car key) (cdr key) "packages.el")
|
||||||
(_load (expand-file-name "packages.el" doom-private-dir) t))))))))
|
do (let ((doom--current-module key)) (_load path t)))
|
||||||
|
(_load private-packages t)))))))))
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
@ -468,42 +469,16 @@ This doesn't require modules to be enabled. For enabled modules us
|
||||||
(intern submodule))))))))
|
(intern submodule))))))))
|
||||||
|
|
||||||
(defun doom-module-load-path ()
|
(defun doom-module-load-path ()
|
||||||
"Returns a list of absolute file paths to activated modules."
|
"Return a list of absolute file paths to activated modules."
|
||||||
(append (cl-loop for plist being the hash-values of doom-modules
|
(append (cl-loop for plist being the hash-values of (doom-modules)
|
||||||
collect (plist-get plist :path))
|
collect (plist-get plist :path))
|
||||||
(list doom-private-dir)))
|
(list doom-private-dir)))
|
||||||
|
|
||||||
(defun doom-module-table (&optional modules)
|
(defun doom-modules (&optional refresh-p)
|
||||||
"Converts MODULES (a malformed plist) into a hash table of modules, fit for
|
"Minimally initialize `doom-modules' (a hash table) and return it."
|
||||||
`doom-modules'. If MODULES is omitted, it will fetch your module mplist from the
|
(let ((noninteractive t))
|
||||||
`doom!' block in your private init.el file."
|
(doom-initialize-modules refresh-p))
|
||||||
(let* ((doom-modules (make-hash-table :test #'equal
|
doom-modules)
|
||||||
:size (if modules (length modules) 100)
|
|
||||||
:rehash-threshold 1.0)))
|
|
||||||
(when (null modules)
|
|
||||||
(let* ((init-file (expand-file-name "init.el" doom-private-dir))
|
|
||||||
(short-init-file (abbreviate-file-name init-file)))
|
|
||||||
(if (not (file-exists-p init-file))
|
|
||||||
(error "%s doesn't exist" short-init-file)
|
|
||||||
(with-temp-buffer
|
|
||||||
(delay-mode-hooks (emacs-lisp-mode))
|
|
||||||
(insert-file-contents-literally init-file)
|
|
||||||
(when (re-search-forward "^\\s-*\\((doom! \\)" nil t)
|
|
||||||
(goto-char (match-beginning 1))
|
|
||||||
(setq modules (cdr (sexp-at-point))))))
|
|
||||||
(unless (or modules noninteractive)
|
|
||||||
(warn "Couldn't gather module list from %s" short-init-file))))
|
|
||||||
(if (eq modules t) (setq modules nil))
|
|
||||||
(let (category)
|
|
||||||
(dolist (m modules)
|
|
||||||
(cond ((keywordp m) (setq category m))
|
|
||||||
((not category) (error "No module category specified for %s" m))
|
|
||||||
((let ((module (if (listp m) (car m) m))
|
|
||||||
(flags (if (listp m) (cdr m))))
|
|
||||||
(if-let* ((path (doom-module-locate-path category module)))
|
|
||||||
(doom-module-set category module :flags flags :path path)
|
|
||||||
(message "Couldn't find the %s %s module" category module)))))))
|
|
||||||
doom-modules))
|
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
@ -588,15 +563,28 @@ The overall load order of Doom is as follows:
|
||||||
Module load order is determined by your `doom!' block. See `doom-modules-dirs'
|
Module load order is determined by your `doom!' block. See `doom-modules-dirs'
|
||||||
for a list of all recognized module trees. Order defines precedence (from most
|
for a list of all recognized module trees. Order defines precedence (from most
|
||||||
to least)."
|
to least)."
|
||||||
(let ((doom-modules (doom-module-table (or modules t)))
|
(let ((doom-modules
|
||||||
|
(make-hash-table :test #'equal
|
||||||
|
:size (if modules (length modules) 100)
|
||||||
|
:rehash-threshold 1.0))
|
||||||
|
category
|
||||||
init-forms config-forms)
|
init-forms config-forms)
|
||||||
(maphash (lambda (key plist)
|
(dolist (m modules)
|
||||||
(let ((path (plist-get plist :path)))
|
(cond ((keywordp m) (setq category m))
|
||||||
(push `(let ((doom--current-module ',key)) (load! "init" ,path t))
|
((not category) (error "No module category specified for %s" m))
|
||||||
init-forms)
|
((let* ((module (if (listp m) (car m) m))
|
||||||
(push `(let ((doom--current-module ',key)) (load! "config" ,path t))
|
(flags (if (listp m) (cdr m)))
|
||||||
config-forms)))
|
(path (doom-module-locate-path category module)))
|
||||||
doom-modules)
|
(if (not path)
|
||||||
|
(message "Couldn't find the %s %s module" category module)
|
||||||
|
(let ((key (cons category module)))
|
||||||
|
(doom-module-set category module :flags flags :path path)
|
||||||
|
(push `(let ((doom--current-module ',key))
|
||||||
|
(load! "init" ,path t))
|
||||||
|
init-forms)
|
||||||
|
(push `(let ((doom--current-module ',key))
|
||||||
|
(load! "config" ,path t))
|
||||||
|
config-forms)))))))
|
||||||
`(let (file-name-handler-alist)
|
`(let (file-name-handler-alist)
|
||||||
(setq doom-modules ',doom-modules)
|
(setq doom-modules ',doom-modules)
|
||||||
,@(nreverse init-forms)
|
,@(nreverse init-forms)
|
||||||
|
|
|
@ -120,7 +120,6 @@ else (except for `window-setup-hook').")
|
||||||
tramp-persistency-file-name (concat doom-cache-dir "tramp-persistency.el")
|
tramp-persistency-file-name (concat doom-cache-dir "tramp-persistency.el")
|
||||||
url-cache-directory (concat doom-cache-dir "url/")
|
url-cache-directory (concat doom-cache-dir "url/")
|
||||||
url-configuration-directory (concat doom-etc-dir "url/"))
|
url-configuration-directory (concat doom-etc-dir "url/"))
|
||||||
(load custom-file t t t)
|
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
@ -201,11 +200,12 @@ this, you'll get stuttering and random freezes) and resets
|
||||||
|
|
||||||
(require 'core-lib)
|
(require 'core-lib)
|
||||||
(require 'core-packages)
|
(require 'core-packages)
|
||||||
|
(when noninteractive
|
||||||
|
(require 'core-dispatcher))
|
||||||
|
|
||||||
|
(load custom-file t t t)
|
||||||
(doom-initialize noninteractive)
|
(doom-initialize noninteractive)
|
||||||
(if noninteractive
|
(doom-initialize-modules)
|
||||||
(require 'core-dispatcher)
|
|
||||||
(doom-initialize-modules))
|
|
||||||
|
|
||||||
(provide 'core)
|
(provide 'core)
|
||||||
;;; core.el ends here
|
;;; core.el ends here
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue