[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: eval-when-load?

From: Stefan Monnier
Subject: Re: eval-when-load?
Date: Thu, 16 Jul 2015 19:03:28 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

> A project I'm working on has a form like this at top level in a file:
> (defvar jde-jdhelper-singleton (jde-jdhelper nil)
>   "The JDHelper singleton instance.")
> `jde-jdhelper' can throw an error, which it does during byte-compile (it
> complains about not finding "wget").
> We want the variable defined at load time, and we want the error at load
> time, but we don't care at compile time.

I suspect there's a confusion about "compile time": the above call to
jde-jdhelper will not be executed while compiling the file that contains
this defvar.  It will only be called when the resulting .elc file is
loaded (so, as Artur says, what you ask is already the default

But I suspect the problem you see is that the above form appears in
a file which is not only byte-compiled but is also `require'd by other
files in that package, so when *those* files are byte-compiled, the call
to jde-jdhelper is indeed executed, since at that time this file is
loaded (as part of byte-compiling those other files).

Maybe you want to use

   (if t (require 'this-file))

instead of (require 'this-file) so that this-file is only loaded when
those-files are *loaded* rather than when they're byte-compiled.

Of course, the same problem can happen if those-files are themselves
`require'd by yet-other-files, in which case they may end up being
loaded during compilation of those-yet-other-files, at which point
they'll also load this-file.  In that case, you want like to again
replace (require 'that-file) with (if t (require 'that-file)) to avoid
loading those-files during byte-compilation of those-yet-other-files.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]