I can read the documentation, so I'm not asking for a cut-n-paste of that.
I'm trying to understand the motivation for this function.
When would I want to use it?
Thanks.
I can read the documentation, so I'm not asking for a cut-n-paste of that.
I'm trying to understand the motivation for this function.
When would I want to use it?
Thanks.
The documentation in the Emacs lisp manual does have some example situations that seem to answer your question (as opposed to the doc string).
From looking at the Emacs source code, eval-and-compile
is used to quiet the compiler, to make macros/functions available during compilation (and evaluation), or to make feature/version specific variants of macros/functions available during compilation.
One usage I found helpful to see was in ezimage.el
. In there, an if
statement was put inside the eval-and-compile
to conditionally define macros depending on whether the package was compiled/eval'ed in Emacs or XEmacs, and additionally whether a particular feature was present. By wrapping that conditional inside the eval-and-compile
you enable the appropriate macro usage during compilation. A similar situation can be found in mwheel.el
.
Similarly, if you want to define a function via fset
and have it available during compilation, you need to have the call to fset
wrapped with eval-and-compile
because otherwise the symbol -> function association isn't available until the file is evaluated (because compilation of a call to fset
just optimizes the assignment, it doesn't actually do the assignment). Why would you want this assignment during compilation? To quiet the compiler. Note: this is just my re-wording of what is in the elisp documentation.
I did notice a lot of uses in Emacs code which just wrapped calls to require
, which sounds redundant when you read the documentation. I'm at a loss as to how to explain those.