Skip to content

Commit 812ef8f

Browse files
committed
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 jwiegley#1032
1 parent a6e8564 commit 812ef8f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

use-package-core.el

+10-1
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,15 @@ extending any keys already present."
594594
(setq result (cons (car x) (cons (cdr x) result))))
595595
result)))
596596

597+
(defmacro use-package--eval-when-compile (&rest body)
598+
"Evaluate BODY at compile time.
599+
When expanding the macro, evaluate (progn BODY) and substitute
600+
the macro call by the result of the evaluation. If BODY
601+
is (require feature), then all the symbols declared in feature
602+
are visible to the compiler. This contrasts with standard
603+
`eval-when-compile', which only puts *variables* in scope."
604+
(list 'quote (eval (cons 'progn body))))
605+
597606
(defun use-package-normalize-keywords (name args)
598607
(let* ((name-symbol (if (stringp name) (intern name) name))
599608
(name-string (symbol-name name-symbol)))
@@ -664,7 +673,7 @@ extending any keys already present."
664673
(plist-get args :defines))
665674
(mapcar #'(lambda (fn) `(declare-function ,fn ,name-string))
666675
(plist-get args :functions))
667-
`((eval-when-compile
676+
`((use-package--eval-when-compile
668677
(with-demoted-errors
669678
,(format "Cannot load %s: %%S" name-string)
670679
,(when (eq use-package-verbose 'debug)

0 commit comments

Comments
 (0)