Refactor initialization; allow package! to universally disable packages

No need for def-package-hook! for disable packages anymore, you can do
it from package! in packages.el files.
This commit is contained in:
Henrik Lissner 2018-03-26 02:57:34 -04:00
parent ebf276c6e7
commit 21a23228f2
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
3 changed files with 47 additions and 43 deletions

View file

@ -1,10 +1,5 @@
;;; core-lib.el -*- lexical-binding: t; -*- ;;; core-lib.el -*- lexical-binding: t; -*-
(let ((load-path doom-site-load-path))
(require 'subr-x)
(require 'cl-lib)
(require 'map))
(eval-and-compile (eval-and-compile
(unless EMACS26+ (unless EMACS26+
(with-no-warnings (with-no-warnings

View file

@ -143,6 +143,10 @@ FORCE-P is non-nil, do it anyway.
3. Loads your autoloads file in `doom-autoload-file', 3. Loads your autoloads file in `doom-autoload-file',
4. Builds and caches `load-path' and `Info-directory-list' in `doom-packages-file'" 4. Builds and caches `load-path' and `Info-directory-list' in `doom-packages-file'"
;; Called early during initialization; only use native (and cl-lib) functions! ;; Called early during initialization; only use native (and cl-lib) functions!
(let ((load-path doom-site-load-path))
(require 'subr-x)
(require 'cl-lib)
(require 'map))
(when (or force-p (not doom-init-p)) (when (or force-p (not doom-init-p))
(unless (load doom-autoload-file t t t) (unless (load doom-autoload-file t t t)
(unless noninteractive (unless noninteractive
@ -173,11 +177,13 @@ FORCE-P is non-nil, do it anyway.
(message "✓ Installed %s" package) (message "✓ Installed %s" package)
(error "✕ Couldn't install %s" package))) (error "✕ Couldn't install %s" package)))
(message "Installing core packages...done"))) (message "Installing core packages...done")))
(cl-pushnew doom-core-dir load-path :test #'string=)
(unless noninteractive (unless noninteractive
(with-temp-buffer (with-temp-buffer
(cl-pushnew doom-core-dir load-path :test #'string=) (doom-initialize-packages 'internal)
(prin1 `(setq load-path ',load-path (prin1 `(setq load-path ',load-path
Info-directory-list ',Info-directory-list) Info-directory-list ',Info-directory-list
doom-disabled-packages ',doom-disabled-packages)
(current-buffer)) (current-buffer))
(write-file doom-packages-file)))) (write-file doom-packages-file))))
(setq doom-init-p t))) (setq doom-init-p t)))
@ -202,7 +208,7 @@ populated.
This reads modules' packages.el files, runs `package-initialize', and This reads modules' packages.el files, runs `package-initialize', and
initializes quelpa, if they haven't already. If FORCE-P is non-nil, do it initializes quelpa, if they haven't already. If FORCE-P is non-nil, do it
anyway. anyway. If FORCE-P is 'internal, only (re)populate `doom-packages'.
Use this before any of package.el, quelpa or Doom's package management's API to Use this before any of package.el, quelpa or Doom's package management's API to
ensure all the necessary package metadata is initialized and available for ensure all the necessary package metadata is initialized and available for
@ -225,10 +231,6 @@ them."
;; the current session, but if you change an packages.el file in a module, ;; the current session, but if you change an packages.el file in a module,
;; there's no non-trivial way to detect that, so we give you a way to ;; there's no non-trivial way to detect that, so we give you a way to
;; reload only doom-packages. ;; reload only doom-packages.
(when (eq force-p 'internal)
(setq force-p nil
doom-packages nil))
;; `doom-packages' ;; `doom-packages'
(when (or force-p (not doom-packages)) (when (or force-p (not doom-packages))
(setq doom-packages nil) (setq doom-packages nil)
@ -243,14 +245,14 @@ them."
do (_load path))) do (_load path)))
;; `package-alist' ;; `package-alist'
(when (or force-p (not (bound-and-true-p package-alist))) (when (or (eq force-p t) (not (bound-and-true-p package-alist)))
(setq load-path doom-site-load-path) (setq load-path doom-site-load-path)
(require 'package) (require 'package)
(setq package-activated-list nil) (setq package-activated-list nil)
(package-initialize)) (package-initialize))
;; `quelpa-cache' ;; `quelpa-cache'
(when (or force-p (not (bound-and-true-p quelpa-cache))) (when (or (eq force-p t) (not (bound-and-true-p quelpa-cache)))
(require 'quelpa) (require 'quelpa)
(setq quelpa-initialized-p nil) (setq quelpa-initialized-p nil)
(or (quelpa-setup-p) (or (quelpa-setup-p)
@ -410,8 +412,8 @@ WARNING: If :pre-init or :pre-config hooks return nil, the original
to have them return non-nil (or exploit that to overwrite Doom's config)." to have them return non-nil (or exploit that to overwrite Doom's config)."
(declare (indent defun)) (declare (indent defun))
(cond ((eq when :disable) (cond ((eq when :disable)
(push package doom-disabled-packages) (message "Using :disable with `def-package-hook!' is deprecated. Use :disable in `package!' instead.")
nil) (ignore (push package doom-disabled-packages)))
((memq when '(:pre-init :post-init :pre-config :post-config)) ((memq when '(:pre-init :post-init :pre-config :post-config))
`(progn `(progn
(setq use-package-inject-hooks t) (setq use-package-inject-hooks t)
@ -510,7 +512,7 @@ This macro is declarative and does not load nor install packages. It is used to
populate `doom-packages' with metadata about the packages Doom needs to keep populate `doom-packages' with metadata about the packages Doom needs to keep
track of. track of.
Only use this macro in a module's packages.el file. Only use this macro in a module's init.el or packages.el file.
Accepts the following properties: Accepts the following properties:
@ -519,11 +521,16 @@ Accepts the following properties:
from external sources. from external sources.
:pin ARCHIVE-NAME Instructs ELPA to only look for this package in :pin ARCHIVE-NAME Instructs ELPA to only look for this package in
ARCHIVE-NAME. e.g. \"org\". Ignored if RECIPE is present. ARCHIVE-NAME. e.g. \"org\". Ignored if RECIPE is present.
:ignore FORM Do not install this package if FORM is non-nil. :disable BOOL Do not install this package AND disable its `def-package!' blocks.
:freeze FORM Do not update this package if FORM is non-nil." :freeze FORM Do not update this package if FORM is non-nil."
(declare (indent defun)) (declare (indent defun))
(unless (memq name doom-disabled-packages) (cond ((memq name doom-disabled-packages) nil)
(let* ((old-plist (assq name doom-packages)) ((let ((disable (plist-get plist :disable)))
(and disable (eval disable)))
(push name doom-disabled-packages)
(setq doom-packages (map-delete doom-packages name))
nil)
((let* ((old-plist (assq name doom-packages))
(pkg-recipe (or (plist-get plist :recipe) (pkg-recipe (or (plist-get plist :recipe)
(and old-plist (plist-get old-plist :recipe)))) (and old-plist (plist-get old-plist :recipe))))
(pkg-pin (or (plist-get plist :pin) (pkg-pin (or (plist-get plist :pin)
@ -533,12 +540,13 @@ Accepts the following properties:
(plist-put plist :recipe (cons name pkg-recipe))) (plist-put plist :recipe (cons name pkg-recipe)))
(when pkg-pin (when pkg-pin
(plist-put plist :pin nil))) (plist-put plist :pin nil)))
(dolist (prop '(:ignore :freeze)) (let ((val (plist-get plist :freeze)))
(when-let* ((val (plist-get plist prop))) (when val
(plist-put plist prop (eval val)))) (plist-put plist :freeze (eval val))))
`(progn `(progn
,(if (and pkg-pin t) `(map-put package-pinned-packages ',name ,pkg-pin)) ,(when (and pkg-pin t)
(map-put doom-packages ',name ',plist))))) `(map-put package-pinned-packages ',name ,pkg-pin))
(map-put doom-packages ',name ',plist))))))
(defmacro depends-on! (module submodule &optional flags) (defmacro depends-on! (module submodule &optional flags)
"Declares that this module depends on another. "Declares that this module depends on another.

View file

@ -164,6 +164,7 @@ ability to invoke the debugger in debug mode."
display the loading benchmark." display the loading benchmark."
(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))
(run-hooks 'doom-finalize-hook)
(unless noninteractive (unless noninteractive
(when (display-graphic-p) (when (display-graphic-p)
(require 'server) (require 'server)
@ -180,8 +181,8 @@ this, you'll get stuttering and random freezes), and resets
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) #'doom|finalize) (add-hook 'emacs-startup-hook #'doom|after-init)
(add-hook 'emacs-startup-hook #'doom|after-init)) (add-hook! '(doom-finalize-hook doom-reload-hook) #'doom|finalize))
;; ;;