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.elwith the following content:
(defun test () (cl-loop for i from 1 to 2 do (message "Looping %i." i)))
- Start Emacs 26.3 with
- Run M-:
(byte-compile-file "~/tmp/test.el"). Byte compilation works without errors.
The file is loaded and gives the message
Looping 1. Looping 2.
cl-macs is not loaded by default as the "void function" error on evaluating
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
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
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
The doc-string of
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.