From 812ef8f98401c3fdfef00ebb2f4efd0bbc0c6041 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Bernardy Date: Wed, 19 Jul 2023 17:12:12 +0200 Subject: [PATCH] Implement :config by using a better variant of eval-when-compile With this change, `use-package p` puts in scope all the symbols declared by package p in scope of its :config block. The tradeoff is that init is slightly slower *if interpreted*. Compiling init.el gives the same runtime behaviour as previously. Fixes #1032 --- use-package-core.el | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/use-package-core.el b/use-package-core.el index bb523f6..9e0d367 100644 --- a/use-package-core.el +++ b/use-package-core.el @@ -594,6 +594,15 @@ extending any keys already present." (setq result (cons (car x) (cons (cdr x) result)))) result))) +(defmacro use-package--eval-when-compile (&rest body) + "Evaluate BODY at compile time. +When expanding the macro, evaluate (progn BODY) and substitute +the macro call by the result of the evaluation. If BODY +is (require feature), then all the symbols declared in feature +are visible to the compiler. This contrasts with standard +`eval-when-compile', which only puts *variables* in scope." + (list 'quote (eval (cons 'progn body)))) + (defun use-package-normalize-keywords (name args) (let* ((name-symbol (if (stringp name) (intern name) name)) (name-string (symbol-name name-symbol))) @@ -664,7 +673,7 @@ extending any keys already present." (plist-get args :defines)) (mapcar #'(lambda (fn) `(declare-function ,fn ,name-string)) (plist-get args :functions)) - `((eval-when-compile + `((use-package--eval-when-compile (with-demoted-errors ,(format "Cannot load %s: %%S" name-string) ,(when (eq use-package-verbose 'debug)