[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
Re: How do I remove "reference to free variable" warnings on buffer-local variables?
Mon, 9 Nov 2009 09:28:33 -0800 (PST)
On Nov 9, 11:45 am, Tassilo Horn <address@hidden> wrote:
> rocky <address@hidden> 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
> at the top of your file.
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.