Imagine that I have the following files in my (ridiculous) package:
;;; test1.el --- ;;; Code: (defvar test-var1) (defun test-fun1 (test) nil) (require 'test2 "./test2.el) (provide 'test1) ;;; test1.el ends here
;;; test2.el --- ;;; Code: (defun test-fun2 () (let ((test test-var1)) (test-fun1 test))) (provide 'test2) ;;; test2.el ends here
If then I run:
emacs -batch -f batch-byte-compile *.el
I get the following result:
Compiling .../test1.el... Wrote .../test1.elc Compiling .../test2.el... In test-fun2: test2.el:9:15:Warning: reference to free variable `test-var1' In end of data: test2.el:14:1:Warning: the function `test-fun1' is not known to be defined. Wrote .../test2.elc
I understand why these warnings appear, and I understand that they are only warnings. However, it would be easy to miss a typo in a function name by dismissing all warnings of this kind.
I somehow thought that adding a
(require 'test2) line in
test2.el should fix it. However, in this case I get:
Compiling .../test1.el... In toplevel form: test1.el:10:1:Error: Recursive `require' for feature `test2' Compiling .../test2.el... In toplevel form: test2.el:5:1:Error: Recursive `require' for feature `test1'
This is cryptic, because I thought that the point of
require was precisely to avoid recursive loading. I assume that
require is behaving like
load during compilation time.
What is a good (and safe) way to get rid of these warnings?
The manual gives a work-around (I post it as a better-than-nothing answer below), but ultimately, I'd like the solution to be rather automatic (not requiring me to list all functions and variables that I will need in every file).
The ideal solution would be built-in in emacs or provided with Cask. If it doesn't exist, I will take what is available of course.