From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: rocky Newsgroups: gmane.emacs.help 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) Organization: http://groups.google.com Message-ID: <5c3ac6a2-4aa7-4424-a34e-b274fdc81fc5@c3g2000yqd.googlegroups.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1257789153 20542 80.91.229.12 (9 Nov 2009 17:52:33 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 9 Nov 2009 17:52:33 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Nov 09 18:52:26 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1N7YPY-0006UI-NZ for geh-help-gnu-emacs@m.gmane.org; Mon, 09 Nov 2009 18:52:20 +0100 Original-Received: from localhost ([127.0.0.1]:56817 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N7YPW-0006jS-TK for geh-help-gnu-emacs@m.gmane.org; Mon, 09 Nov 2009 12:52:14 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!postnews.google.com!c3g2000yqd.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 45 Original-NNTP-Posting-Host: 66.92.120.162 Original-X-Trace: posting.google.com 1257787713 6904 127.0.0.1 (9 Nov 2009 17:28:33 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Mon, 9 Nov 2009 17:28:33 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: c3g2000yqd.googlegroups.com; posting-host=66.92.120.162; posting-account=jKjGDQoAAABKN2iauJtD3DV5oMZpXuQo User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.15) Gecko/2009102815 Ubuntu/9.04 (jaunty) Firefox/3.0.15, gzip(gfe), gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:174557 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:69631 Archived-At: On Nov 9, 11:45=A0am, Tassilo Horn wrote: > rocky 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. =A0But you can supress those like it's stated > in the manual: > > ,----[ (info "(elisp)Compiler Errors") ] > | =A0 =A0You can tell the compiler that a function is defined using > | `declare-function' (*note Declaring Functions::). =A0Likewise, you can > | tell the compiler that a variable is defined using `defvar' with no > | initial value. > | > | =A0 =A0You can suppress the compiler warning for a specific use of an > | undefined variable VARIABLE by conditionalizing its use on a `boundp' > | test, like this: > | > | =A0 =A0 =A0(if (boundp 'VARIABLE) ...VARIABLE...) > `---- > > So in your case you could add something like > > =A0 (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.