From f5b034154f8fa2bab0375e34143de9d462ee1232 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Fri, 1 Dec 2017 10:23:06 -0800 Subject: [PATCH] Always wrap the expanded body from use-package in (progn) --- lisp/use-package/use-package.el | 39 +++++----- test/lisp/use-package/use-package-tests.el | 83 ++++++++++++---------- 2 files changed, 65 insertions(+), 57 deletions(-) diff --git a/lisp/use-package/use-package.el b/lisp/use-package/use-package.el index 878fa673409..fe223305770 100644 --- a/lisp/use-package/use-package.el +++ b/lisp/use-package/use-package.el @@ -1760,25 +1760,25 @@ this file. Usage: (symbol-name name)) nil t))))))))) (let ((body - (macroexp-progn - (use-package-process-keywords name - (let ((args* - (use-package-sort-keywords - (if (and use-package-always-demand - (not (memq :defer args))) - (plist-put args :demand t) - args)))) - (when (and use-package-always-ensure - (plist-member args* :load-path) - (not (plist-member orig-args :ensure))) - (plist-put args* :ensure nil)) - (unless (plist-member args* :init) - (plist-put args* :init nil)) - (unless (plist-member args* :config) - (plist-put args* :config '(t))) - args*) - (and use-package-always-defer - (list :deferred t)))))) + `(progn + ,@(use-package-process-keywords name + (let ((args* + (use-package-sort-keywords + (if (and use-package-always-demand + (not (memq :defer args))) + (plist-put args :demand t) + args)))) + (when (and use-package-always-ensure + (plist-member args* :load-path) + (not (plist-member orig-args :ensure))) + (plist-put args* :ensure nil)) + (unless (plist-member args* :init) + (plist-put args* :init nil)) + (unless (plist-member args* :config) + (plist-put args* :config '(t))) + args*) + (and use-package-always-defer + (list :deferred t)))))) (when use-package-debug (display-buffer (save-current-buffer @@ -1787,6 +1787,7 @@ this file. Usage: (emacs-lisp-mode) (insert (pp-to-string body)) (current-buffer))))) + (message "body = %s" body) body)))) diff --git a/test/lisp/use-package/use-package-tests.el b/test/lisp/use-package/use-package-tests.el index 6710d48faa8..66a4af30b52 100644 --- a/test/lisp/use-package/use-package-tests.el +++ b/test/lisp/use-package/use-package-tests.el @@ -267,59 +267,59 @@ (ert-deftest use-package-test/:if () (match-expansion (use-package foo :if t) - `(if (symbol-value 't) - (progn - (require 'foo nil 'nil)))) + `(progn + (when (symbol-value 't) + (require 'foo nil 'nil)))) (match-expansion (use-package foo :if (and t t)) - `(if (and t t) - (progn - (require 'foo nil 'nil)))) + `(progn + (when (and t t) + (require 'foo nil 'nil)))) (match-expansion (use-package foo :if nil) - `(if nil - (progn - (require 'foo nil 'nil))))) + `(progn + (when nil + (require 'foo nil 'nil))))) (ert-deftest use-package-test/:when () (match-expansion (use-package foo :when t) - `(if (symbol-value 't) - (progn - (require 'foo nil 'nil)))) + `(progn + (when (symbol-value 't) + (require 'foo nil 'nil)))) (match-expansion (use-package foo :when (and t t)) - `(if (and t t) - (progn - (require 'foo nil 'nil)))) + `(progn + (when (and t t) + (require 'foo nil 'nil)))) (match-expansion (use-package foo :when nil) - `(if nil - (progn - (require 'foo nil 'nil))))) + `(progn + (when nil + (require 'foo nil 'nil))))) -(ert-deftest use-package-test/:when () +(ert-deftest use-package-test/:unless () (match-expansion (use-package foo :unless t) - `(if (symbol-value 't) - nil - (require 'foo nil 'nil))) + `(progn + (unless (symbol-value 't) + (require 'foo nil 'nil)))) (match-expansion (use-package foo :unless (and t t)) - `(if (and t t) - nil - (require 'foo nil 'nil))) + `(progn + (unless (and t t) + (require 'foo nil 'nil)))) (match-expansion (use-package foo :unless nil) - `(if nil - nil - (require 'foo nil 'nil)))) + `(progn + (unless nil + (require 'foo nil 'nil))))) ;; (ert-deftest use-package-test/:requires () ;; (should (equal (macroexpand (use-package)) @@ -446,7 +446,8 @@ (ert-deftest use-package-test/:defines () (match-expansion (use-package foo :defines bar) - `(require 'foo nil 'nil)) + `(progn + (require 'foo nil 'nil))) (let ((byte-compile-current-file t)) (match-expansion @@ -463,7 +464,8 @@ (ert-deftest use-package-test/:functions () (match-expansion (use-package foo :functions bar) - `(require 'foo nil 'nil)) + `(progn + (require 'foo nil 'nil))) (let ((byte-compile-current-file t)) (match-expansion @@ -479,13 +481,17 @@ (match-expansion (use-package foo :defer t :functions bar) - `nil) + `(progn)) - ;; jww (2017-12-01): This exposes a bug. - ;; (let ((byte-compile-current-file t)) - ;; (match-expansion - ;; (use-package foo :defer t :functions bar) - ;; `'nil)) + (let ((byte-compile-current-file t)) + (match-expansion + (use-package foo :defer t :functions bar) + `(progn + (eval-and-compile + (declare-function bar "foo") + (eval-when-compile + (with-demoted-errors "Cannot load foo: %S" nil + (load "foo" nil t))))))) (let ((byte-compile-current-file t)) (match-expansion @@ -576,8 +582,9 @@ (ert-deftest use-package-test/:after () (match-expansion (use-package foo :after bar) - `(eval-after-load 'bar - '(require 'foo nil t)))) + `(progn + (eval-after-load 'bar + '(require 'foo nil t))))) ;; (ert-deftest use-package-test/:demand () ;; (should (equal (macroexpand (use-package)) -- 2.39.2