Refactor doom-initialize-packages

Make it reinitialize more if FORCE-P is provided or doom-init-packages-p
is nil.
This commit is contained in:
Henrik Lissner 2019-08-28 16:46:39 -04:00
parent ccaf92b0d3
commit 75fe17950e
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -134,11 +134,13 @@ If FORCE-P is non-nil, do it anyway.
This ensure `doom-packages' is populated, if isn't aren't already. Use this 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 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." necessary package metadata is initialized and available for them."
(unless doom-init-packages-p
(setq force-p t))
(when (or force-p (not (bound-and-true-p package--initialized))) (when (or force-p (not (bound-and-true-p package--initialized)))
(doom-log "Initializing package.el") (doom-log "Initializing package.el")
(require 'package) (require 'package)
(package-initialize)) (package-initialize))
(when (or force-p (not doom-init-packages-p)) (when (or force-p (not doom-packages))
(doom-log "Initializing straight") (doom-log "Initializing straight")
(setq doom-init-packages-p t) (setq doom-init-packages-p t)
(unless (fboundp 'straight--reset-caches) (unless (fboundp 'straight--reset-caches)
@ -154,11 +156,7 @@ necessary package metadata is initialized and available for them."
:no-byte-compile t)) :no-byte-compile t))
(mapc #'straight-use-package doom-core-packages) (mapc #'straight-use-package doom-core-packages)
(when noninteractive (when noninteractive
(add-hook 'kill-emacs-hook #'doom--finalize-straight)) (add-hook 'kill-emacs-hook #'doom--finalize-straight)))
(dolist (package (straight--directory-files (straight--build-dir)))
(cl-pushnew (directory-file-name (straight--build-dir package))
load-path)))
(when (or force-p (not doom-packages))
(doom-log "Initializing doom-packages") (doom-log "Initializing doom-packages")
(setq doom-disabled-packages nil (setq doom-disabled-packages nil
doom-packages (doom-package-list)) doom-packages (doom-package-list))
@ -173,7 +171,7 @@ necessary package metadata is initialized and available for them."
(if-let (recipe (plist-get plist :recipe)) (if-let (recipe (plist-get plist :recipe))
(let ((plist (straight-recipes-retrieve pkg))) (let ((plist (straight-recipes-retrieve pkg)))
`(,pkg ,@(doom-plist-merge recipe (cdr plist)))) `(,pkg ,@(doom-plist-merge recipe (cdr plist))))
pkg)))))) pkg)))))
(defun doom-ensure-straight () (defun doom-ensure-straight ()
"Ensure `straight' is installed and was compiled with this version of Emacs." "Ensure `straight' is installed and was compiled with this version of Emacs."