From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.help Subject: RE: How do I remove "reference to free variable" warnings onbuffer-local variables? Date: Mon, 9 Nov 2009 09:40:12 -0800 Message-ID: References: <87vdhjk5ph.fsf@thinkpad.tsdh.de> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1257789261 20914 80.91.229.12 (9 Nov 2009 17:54:21 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 9 Nov 2009 17:54:21 +0000 (UTC) To: "'Tassilo Horn'" , Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Nov 09 18:54:14 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 1N7YRR-0007SG-Tq for geh-help-gnu-emacs@m.gmane.org; Mon, 09 Nov 2009 18:54:14 +0100 Original-Received: from localhost ([127.0.0.1]:57888 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N7YRR-0000Nr-K3 for geh-help-gnu-emacs@m.gmane.org; Mon, 09 Nov 2009 12:54:13 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N7YFt-000737-2H for help-gnu-emacs@gnu.org; Mon, 09 Nov 2009 12:42:17 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N7YFo-00071O-2R for help-gnu-emacs@gnu.org; Mon, 09 Nov 2009 12:42:16 -0500 Original-Received: from [199.232.76.173] (port=54840 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N7YFn-00070s-QT for help-gnu-emacs@gnu.org; Mon, 09 Nov 2009 12:42:11 -0500 Original-Received: from acsinet11.oracle.com ([141.146.126.233]:30412) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1N7YFm-0007nZ-3J for help-gnu-emacs@gnu.org; Mon, 09 Nov 2009 12:42:10 -0500 Original-Received: from acsinet15.oracle.com (acsinet15.oracle.com [141.146.126.227]) by acsinet11.oracle.com (Switch-3.3.1/Switch-3.3.1) with ESMTP id nA9HgkgN002073 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 9 Nov 2009 17:42:47 GMT Original-Received: from acsmt357.oracle.com (acsmt357.oracle.com [141.146.40.157]) by acsinet15.oracle.com (Switch-3.3.1/Switch-3.3.1) with ESMTP id nA9FJKZM028507; Mon, 9 Nov 2009 17:43:36 GMT Original-Received: from abhmt018.oracle.com by acsmt358.oracle.com with ESMTP id 176788701257788412; Mon, 09 Nov 2009 11:40:12 -0600 Original-Received: from dradamslap1 (/130.35.178.194) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 09 Nov 2009 09:40:12 -0800 X-Mailer: Microsoft Office Outlook 11 In-Reply-To: <87vdhjk5ph.fsf@thinkpad.tsdh.de> Thread-Index: AcphYHmybFGo7zH9RO2r1IIhOKjAJgAAKaQg X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 X-Source-IP: acsmt357.oracle.com [141.146.40.157] X-Auth-Type: Internal IP X-CT-RefId: str=0001.0A090206.4AF85467.0129:SCFMA4539814,ss=1,fgs=0 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 1) 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:69632 Archived-At: > ,----[ (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)) > at the top of your file. I don't think so - but I'm no expert on this. `(defvar some-variable)' does not assign a value to the variable. It is used (AFAIK) only to suppress a compiler warning. As such, there is no need and no reason to put it behind `(boundp 'some-variable)'. Since it does not assign a value, there is typically also no need to take special measures for local values vs default value. Just use `(defvar some-variable)' at the top level of a file, if you want to suppress the compiler warning generally for that variable. What that passage from the manual is saying, I think, is that you can use `boundp' to suppress the warning only locally if you want, "for a specific use of an undefined variable". In the example you gave, `defvar' doesn't really constitute a "use" of the variable - or if it does, it is not a use that would cause a warning. An example of using `boundp' to suppress a warning would be `(if (boundp 'foo) foo bar)'. Here, if `foo' is not bound, no warning is issued. If `bar' is unbound, you will get the warning for `bar', since it is not protected by `boundp'. IOW, as an alternative to using `(defvar foo)', which suppresses all warnings about foo being unbound, you can use `(boundp 'foo)' to suppress the unbound warning for only a specific use of the variable. This warning suppression via `boundp' was new with Emacs 22. Again, I'm no expert on this. Others will no doubt correct me. But I'm pretty sure that the example you gave is not useful: the `boundp' test is not needed, and it doesn't do anything, since the "use" of the variable for which the warning would be suppressed here is simply `(defvar some-variable)', which doesn't issue a warning anyway.