unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Avoiding 'reference to free variable' warnings while splitting elisp source files
@ 2013-03-23 16:08 Joe Riel
  0 siblings, 0 replies; 5+ messages in thread
From: Joe Riel @ 2013-03-23 16:08 UTC (permalink / raw)
  To: Help GNU Emacs

Is there a sane way to split the source of an elisp file
while avoiding the 'reference to free variable' warnings
when byte-compiling?

The problem arises when a variable defined in one file
is used in another.   How does one avoid those errors?
I have half a dozen source files that are all required
by one package.  A variable may be used in several files
(generally it is used mainly in one file, which is where
it is defined (with defvar), but, must be used in another.
I've tried adding 

(eval-when-compile
  (require 'other-source-file))

to avoid the error; that sort of works, but not
when two files each uses a variable defined in the other.

There has to be a better way.



-- 
Joe Riel




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Avoiding 'reference to free variable' warnings while splitting elisp source files
       [not found] <mailman.22711.1364054888.855.help-gnu-emacs@gnu.org>
@ 2013-03-23 16:11 ` Jay Belanger
  2013-03-23 16:19   ` Pascal J. Bourguignon
  0 siblings, 1 reply; 5+ messages in thread
From: Jay Belanger @ 2013-03-23 16:11 UTC (permalink / raw)
  To: help-gnu-emacs


> Is there a sane way to split the source of an elisp file
> while avoiding the 'reference to free variable' warnings
> when byte-compiling?
>
> The problem arises when a variable defined in one file
> is used in another.   How does one avoid those errors?

You can put
(defvar variable-name)
in the other file.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Avoiding 'reference to free variable' warnings while splitting elisp source files
  2013-03-23 16:11 ` Avoiding 'reference to free variable' warnings while splitting elisp source files Jay Belanger
@ 2013-03-23 16:19   ` Pascal J. Bourguignon
  2013-03-23 16:51     ` Jay Belanger
  0 siblings, 1 reply; 5+ messages in thread
From: Pascal J. Bourguignon @ 2013-03-23 16:19 UTC (permalink / raw)
  To: help-gnu-emacs

Jay Belanger <jay.p.belanger@gmail.com> writes:

>> Is there a sane way to split the source of an elisp file
>> while avoiding the 'reference to free variable' warnings
>> when byte-compiling?
>>
>> The problem arises when a variable defined in one file
>> is used in another.   How does one avoid those errors?
>
> You can put
> (defvar variable-name)
> in the other file.

Nope.  Because then the initialization depends on the order of loading
the files.

You can put the defvar in a variable.el file that is required by all the
others.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Avoiding 'reference to free variable' warnings while splitting elisp source files
  2013-03-23 16:19   ` Pascal J. Bourguignon
@ 2013-03-23 16:51     ` Jay Belanger
  2013-03-23 16:59       ` Pascal J. Bourguignon
  0 siblings, 1 reply; 5+ messages in thread
From: Jay Belanger @ 2013-03-23 16:51 UTC (permalink / raw)
  To: help-gnu-emacs


>>> Is there a sane way to split the source of an elisp file
>>> while avoiding the 'reference to free variable' warnings
>>> when byte-compiling?
>>>
>>> The problem arises when a variable defined in one file
>>> is used in another.   How does one avoid those errors?
>>
>> You can put
>> (defvar variable-name)
>> in the other file.
>
> Nope.  Because then the initialization depends on the order of loading
> the files.

If there is no initial value in the defvar, then the only thing the
defvar does is quiet the compiler.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Avoiding 'reference to free variable' warnings while splitting elisp source files
  2013-03-23 16:51     ` Jay Belanger
@ 2013-03-23 16:59       ` Pascal J. Bourguignon
  0 siblings, 0 replies; 5+ messages in thread
From: Pascal J. Bourguignon @ 2013-03-23 16:59 UTC (permalink / raw)
  To: help-gnu-emacs

Jay Belanger <jay.p.belanger@gmail.com> writes:

>>>> Is there a sane way to split the source of an elisp file
>>>> while avoiding the 'reference to free variable' warnings
>>>> when byte-compiling?
>>>>
>>>> The problem arises when a variable defined in one file
>>>> is used in another.   How does one avoid those errors?
>>>
>>> You can put
>>> (defvar variable-name)
>>> in the other file.
>>
>> Nope.  Because then the initialization depends on the order of loading
>> the files.
>
> If there is no initial value in the defvar, then the only thing the
> defvar does is quiet the compiler.

Right.  I was confused.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-03-23 16:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.22711.1364054888.855.help-gnu-emacs@gnu.org>
2013-03-23 16:11 ` Avoiding 'reference to free variable' warnings while splitting elisp source files Jay Belanger
2013-03-23 16:19   ` Pascal J. Bourguignon
2013-03-23 16:51     ` Jay Belanger
2013-03-23 16:59       ` Pascal J. Bourguignon
2013-03-23 16:08 Joe Riel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).