From 32954ecb69f0e3e3f50e7508cbdeb8c9cdc8e44d Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Mon, 18 Jun 2018 14:52:24 +0200 Subject: [PATCH] Move compile-time fix for disabled packages This fix prevented the byte-compiler from trying to load packages that were disabled or failed their :when/:unless/:if predicates. This commit moves it into doom-byte-compile, so the :no-require predicate doesn't have to run on every package in an interactive session, eating MY PRECIOUS cpu cycles. I do love my cpu cycles, yessiree. --- core/core-dispatcher.el | 15 +++++++++++++-- core/core-modules.el | 28 ++++++++-------------------- core/core.el | 1 + 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/core/core-dispatcher.el b/core/core-dispatcher.el index 491d39bc7..0ae3c0e27 100644 --- a/core/core-dispatcher.el +++ b/core/core-dispatcher.el @@ -733,8 +733,19 @@ If RECOMPILE-P is non-nil, only recompile out-of-date files." (message "Couldn't find any valid targets") (message "No targets to %scompile" (if recompile-p "re" ""))) (cl-return-from 'byte-compile)) - (condition-case ex - (let ((use-package-expand-minimally t)) + (condition-case e + (let ((use-package-defaults use-package-defaults) + (use-package-expand-minimally t)) + ;; Prevent packages from being loaded at compile time if they + ;; don't meet their own predicates. + (push (list :no-require t + (lambda (_name args) + (or (when-let* ((pred (or (plist-get args :if) + (plist-get args :when)))) + (not (eval pred t))) + (when-let* ((pred (plist-get args :unless))) + (eval pred t))))) + use-package-defaults) ;; Always compile private init file (push (expand-file-name "init.el" doom-private-dir) target-files) (push (expand-file-name "init.el" doom-emacs-dir) target-files) diff --git a/core/core-modules.el b/core/core-modules.el index 1e2cd6929..e58a48db1 100644 --- a/core/core-modules.el +++ b/core/core-modules.el @@ -179,28 +179,16 @@ non-nil, return paths of possible modules, activated or otherwise." (autoload 'use-package "use-package-core" nil nil t) +;; Adds the :after-call custom keyword to `use-package' (and consequently, +;; `def-package!'). :after-call takes a symbol or list of symbols. These symbols +;; can be functions or hook variables. +;; +;; (use-package X :after-call find-file-hook) +;; +;; This will load X on the first invokation of `find-file-hook' (then it will +;; remove itself from the hook/function). (defvar doom--deferred-packages-alist ()) (after! use-package-core - ;; Prevent packages from being loaded at compile time if they don't meet their - ;; own predicates. - (push (list :no-require t - (lambda (_name args) - (and (bound-and-true-p byte-compile-current-file) - (or (when-let* ((pred (or (plist-get args :if) - (plist-get args :when)))) - (not (eval pred t))) - (when-let* ((pred (plist-get args :unless))) - (eval pred t)))))) - use-package-defaults) - - ;; Adds the :after-call custom keyword to `use-package' (and consequently, - ;; `def-package!'). :after-call takes a symbol or list of symbols. These - ;; symbols can be functions or hook variables. - ;; - ;; (use-package X :after-call find-file-hook) - ;; - ;; This will load X on the first invokation of `find-file-hook' (then it will - ;; remove itself from the hook/function). (add-to-list 'use-package-deferring-keywords :after-call nil #'eq) (setq use-package-keywords (use-package-list-insert :after-call use-package-keywords :after)) diff --git a/core/core.el b/core/core.el index 941bc0bcc..10ed1d972 100644 --- a/core/core.el +++ b/core/core.el @@ -162,6 +162,7 @@ else (except for `window-setup-hook').") use-package-compute-statistics doom-debug-mode use-package-verbose doom-debug-mode use-package-minimum-reported-time (if doom-debug-mode 0 0.1) + use-package-expand-minimally (not noninteractive) ;; byte compilation byte-compile-verbose doom-debug-mode byte-compile-warnings '(not free-vars unresolved noruntime lexical make-local)