From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: eval-when-load? Date: Thu, 16 Jul 2015 19:03:28 -0400 Message-ID: References: <86fv4ohxjv.fsf@stephe-leake.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1437087841 6328 80.91.229.3 (16 Jul 2015 23:04:01 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 16 Jul 2015 23:04:01 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stephen Leake Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jul 17 01:03:52 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZFsBz-0000fg-V6 for ged-emacs-devel@m.gmane.org; Fri, 17 Jul 2015 01:03:52 +0200 Original-Received: from localhost ([::1]:42287 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZFsBz-00072h-0F for ged-emacs-devel@m.gmane.org; Thu, 16 Jul 2015 19:03:51 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36586) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZFsBm-00072Y-Tn for emacs-devel@gnu.org; Thu, 16 Jul 2015 19:03:39 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZFsBh-0005MV-Tw for emacs-devel@gnu.org; Thu, 16 Jul 2015 19:03:38 -0400 Original-Received: from smtp-pri-01.vtxnet.net ([212.147.62.135]:42293) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZFsBh-0005MP-NE for emacs-devel@gnu.org; Thu, 16 Jul 2015 19:03:33 -0400 Original-Received: from localhost (unknown [127.0.0.1]) by smtp-pri-01.vtxnet.net (VTX Services SA) with ESMTP id D256BCFD8D; Fri, 17 Jul 2015 01:03:32 +0200 (CEST) Original-Received: from smtp-pri-01.vtxnet.net ([127.0.0.1]) by localhost (smtp-pri-01.vtxnet.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YtZF4Gycu6qW; Fri, 17 Jul 2015 01:03:29 +0200 (CEST) Original-Received: from fmsmemgm.homelinux.net (dyn.83-228-180-068.dsl.vtx.ch [83.228.180.68]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-pri-01.vtxnet.net (VTX Services SA) with ESMTP id F0046CFD89; Fri, 17 Jul 2015 01:03:28 +0200 (CEST) Original-Received: by fmsmemgm.homelinux.net (Postfix, from userid 20848) id 9CEAFAE17E; Thu, 16 Jul 2015 19:03:28 -0400 (EDT) In-Reply-To: <86fv4ohxjv.fsf@stephe-leake.org> (Stephen Leake's message of "Thu, 16 Jul 2015 11:33:40 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 212.147.62.135 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:187913 Archived-At: > 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 behavior). 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. Stefan