From: John Wiegley Date: Mon, 4 Dec 2017 19:05:11 +0000 (-0800) Subject: Ensure that :commands always declare-function at compile time X-Git-Tag: emacs-29.0.90~1306^2~15^2~156^2~5 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=101dc9793bfd7ac0d9f2ec1f857bf1cef54ca679;p=emacs.git Ensure that :commands always declare-function at compile time --- diff --git a/up-core.el b/up-core.el index deaead24e85..d1732c3b2a2 100644 --- a/up-core.el +++ b/up-core.el @@ -1147,20 +1147,20 @@ deferred until the prefix key sequence is pressed." (defun use-package-handler/:commands (name keyword arg rest state) (use-package-concat - (unless (plist-get state :demand) - ;; Since we deferring load, establish any necessary autoloads, and also - ;; keep the byte-compiler happy. - (let ((name-string (use-package-as-string name))) - (cl-mapcan - #'(lambda (command) - (when (symbolp command) - (append + ;; Since we deferring load, establish any necessary autoloads, and also + ;; keep the byte-compiler happy. + (let ((name-string (use-package-as-string name))) + (cl-mapcan + #'(lambda (command) + (when (symbolp command) + (append + (unless (plist-get state :demand) `((unless (fboundp ',command) - (autoload #',command ,name-string nil t))) - (when (bound-and-true-p byte-compile-current-file) - `((eval-when-compile - (declare-function ,command ,name-string))))))) - (delete-dups arg)))) + (autoload #',command ,name-string nil t)))) + (when (bound-and-true-p byte-compile-current-file) + `((eval-when-compile + (declare-function ,command ,name-string))))))) + (delete-dups arg))) (use-package-process-keywords name rest state))) ;;;; :defer diff --git a/up-tests.el b/up-tests.el index c23d706c32c..3bcc340eaca 100644 --- a/up-tests.el +++ b/up-tests.el @@ -676,6 +676,52 @@ (autoload #'bar "foo" nil t)) (bar)))) +(ert-deftest use-package-test/:commands-5 () + (match-expansion + (use-package gnus-harvest + :load-path "lisp/gnus-harvest" + :commands gnus-harvest-install + :demand t + :config + (if (featurep 'message-x) + (gnus-harvest-install 'message-x) + (gnus-harvest-install))) + `(progn + (eval-and-compile + (add-to-list 'load-path "/Users/johnw/.emacs.d/lisp/gnus-harvest")) + (require 'gnus-harvest nil nil) + (if (featurep 'message-x) + (gnus-harvest-install 'message-x) + (gnus-harvest-install)) + t))) + +(ert-deftest use-package-test/:commands-6 () + (let ((byte-compile-current-file t)) + (match-expansion + (use-package gnus-harvest + :load-path "lisp/gnus-harvest" + :commands gnus-harvest-install + :demand t + :config + (if (featurep 'message-x) + (gnus-harvest-install 'message-x) + (gnus-harvest-install))) + `(progn + (eval-and-compile + (add-to-list 'load-path "/Users/johnw/.emacs.d/lisp/gnus-harvest")) + (eval-and-compile + (eval-when-compile + (with-demoted-errors "Cannot load gnus-harvest: %S" nil + (load "gnus-harvest" nil t)))) + (eval-when-compile + (declare-function gnus-harvest-install "gnus-harvest")) + (require 'gnus-harvest nil nil) + (if + (featurep 'message-x) + (gnus-harvest-install 'message-x) + (gnus-harvest-install)) + t)))) + (ert-deftest use-package-test/:defines-1 () (match-expansion (use-package foo :defines bar)