1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-27 07:37:33 +00:00

Ensure that :commands always declare-function at compile time

This commit is contained in:
John Wiegley 2017-12-04 11:05:11 -08:00
parent fe85f246b0
commit 101dc9793b
2 changed files with 59 additions and 13 deletions

View File

@ -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

View File

@ -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)