help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: How do I remove "reference to free variable" warnings on buffer-loc


From: rocky
Subject: Re: How do I remove "reference to free variable" warnings on buffer-local variables?
Date: Mon, 9 Nov 2009 09:28:33 -0800 (PST)
User-agent: G2/1.0

On Nov 9, 11:45 am, Tassilo Horn <tass...@member.fsf.org> wrote:
> rocky <ro...@gnu.org> writes:
> > I have code that uses buffer local variables. I don't want to declare
> > this variable global. So how can I remove messages of the form
> > "reference to free variable `...' " when I byte compile a file?
>
> This warning indicates, that this variable isn't defvar-ed somewhere in
> the code you are compiling.  But you can supress those like it's stated
> in the manual:
>
> ,----[ (info "(elisp)Compiler Errors") ]
> |    You can tell the compiler that a function is defined using
> | `declare-function' (*note Declaring Functions::).  Likewise, you can
> | tell the compiler that a variable is defined using `defvar' with no
> | initial value.
> |
> |    You can suppress the compiler warning for a specific use of an
> | undefined variable VARIABLE by conditionalizing its use on a `boundp'
> | test, like this:
> |
> |      (if (boundp 'VARIABLE) ...VARIABLE...)
> `----
>
> So in your case you could add something like
>
>   (or (boundp 'some-variable) (defvar some-variable))

And since this is just a compile error, I suppose I can wrap this in
an (eval-when-compile).

>
> at the top of your file.
>
> HTH,
> Tassilo

But doesn't that define the variable globally? And that's not what I
want to do.

In some respects the warning is correct - I am accessing a free
variable. But I want to access a free variable, which I also want to
ensure is only buffer local. I suppose I just want to tell the
compiler that I expect this free variable to be there so don't give me
warnings about it.



reply via email to

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