This question is motivated by a question about the "void function" error on cl-loop
in the init file.
The following test shows that (require 'cl-lib)
is not needed for byte-compilation:
Assume you have a file
~/tmp/test.el
with the following content:(defun test () (cl-loop for i from 1 to 2 do (message "Looping %i." i)))
- Start Emacs 26.3 with
emacs -Q
. - Run M-:
(byte-compile-file "~/tmp/test.el")
. Byte compilation works without errors. Run M-x
load-file
RET~/tmp/test.el
RET.
The file is loaded and gives the messageLooping 1. Looping 2.
But cl-macs
is not loaded by default as the "void function" error on evaluating cl-loop
shows.
The cl
info manual says that cl-lib.el
loads cl-loaddefs.el
. This is done by a (load "cl-loaddefs" 'noerror 'quiet)
in the code.
But in the test code above there is no (require 'cl-lib)
. How gets cl-macs
loaded at byte-compilation?
I already noted the (register-definition-prefixes "cl-macs" '("cl-"))
in loaddefs.el
.
The help string on register-definition-prefixes
just says: Register that FILE uses PREFIXES.
, which is as much as nothing.
The info manual does also not contain any information about register-definition-prefixes
.
Might it be that that command causes the autoloading at byte-compilation?
A look into register-definition-prefixes
shows that it registers the prefix in the variable definition-prefixes
.
The doc-string of definition-prefixes
says:
Hash table mapping prefixes to the files in which they're used.
This can be used to automatically fetch not-yet-loaded definitions.
More specifically, if there is a value of the form (FILES...) for
a string PREFIX it means that the FILES define variables or functions
with names that start with PREFIX.
Note that it does not imply that all definitions starting with PREFIX can
be found in those files. E.g. if prefix is "gnus-article-" there might
still be definitions of the form "gnus-article-toto-titi" in other files,
which would presumably appear in this table under another prefix such as
"gnus-" or "gnus-article-toto-".
Hm, "This can be used to automatically fetch not-yet-loaded definitions." seems to be a strong indication that register-definition-prefixes
could play a role in the autoloading of cl-macs
on byte-compiling code that contains cl-loop
. But, the doc string does not say anything definite.