From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Re: FW: Font-lock misfontifies foo::bar in C++ Date: Sun, 6 Aug 2006 19:08:18 +0100 Message-ID: <20060806180818.GC1245@muc.de> References: <81CCA6588E60BB42BE68BD029ED4826008C0BB56@wimex2.wim.midas-kapiti.com> Reply-To: bug-cc-mode@gnu.org NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1154884953 15497 80.91.229.2 (6 Aug 2006 17:22:33 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 6 Aug 2006 17:22:33 +0000 (UTC) Cc: bug-cc-mode@gnu.org, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Aug 06 19:22:29 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1G9mKa-00032K-KI for ged-emacs-devel@m.gmane.org; Sun, 06 Aug 2006 19:22:29 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1G9mKZ-00010y-Tl for ged-emacs-devel@m.gmane.org; Sun, 06 Aug 2006 13:22:27 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1G9mKP-00010l-Os for emacs-devel@gnu.org; Sun, 06 Aug 2006 13:22:17 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1G9mKP-00010R-B2 for emacs-devel@gnu.org; Sun, 06 Aug 2006 13:22:17 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1G9mKO-00010C-US for emacs-devel@gnu.org; Sun, 06 Aug 2006 13:22:16 -0400 Original-Received: from [193.149.48.1] (helo=mail.muc.de) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1G9mOS-0004a7-4j for emacs-devel@gnu.org; Sun, 06 Aug 2006 13:26:28 -0400 Original-Received: (qmail 13902 invoked from network); 6 Aug 2006 17:22:14 -0000 Original-Received: from acm.muc.de (HELO localhost.localdomain) (Debian-exim@193.149.49.134) by mail.muc.de with SMTP; 6 Aug 2006 17:22:14 -0000 Original-Received: from acm by localhost.localdomain with local (Exim 4.50) id 1G9n2w-0002Qd-CM; Sun, 06 Aug 2006 19:08:18 +0100 Original-To: "Marshall, Simon" Content-Disposition: inline In-Reply-To: <81CCA6588E60BB42BE68BD029ED4826008C0BB56@wimex2.wim.midas-kapiti.com> User-Agent: Mutt/1.5.9i X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:58146 Archived-At: Hi, Simon! On Tue, Jul 25, 2006 at 09:48:45AM +0100, Marshall, Simon wrote: > > > src/emacs -Q foo.cpp > > > In the foo.cpp buffer, insert the text: > > > void foo::bar() // wrong - foo in font-lock-constant-face > (otherwise ok) [ .... ] > Hi Alan, why is c-reference-face-name used for foo in this context? It > cannot be a reference, it is a type name. I emailed Martin Stjernholm, the author of the CC Mode font locking code, and asked him about this. Here is his answer: ######################################################################### [ACM]: > Martin, can you shed any light upon why "foo" in "foo::bar" is given > c-reference-face-name? Sure. "foo" doesn't get the type face since it isn't used as a type - it's used as an identifier qualifier. Note that "foo" in a "foo::bar" expression can be a namespace name too, which isn't a type at all. So, put another way: The face is not chosen from what an identifier is defined as but rather how it is used. Some examples: Example 1: foo bar; In this statement "foo" is used to specify the type of something. Hence it gets the type face. Example 2: ~foo(); This declares a destructor for the class foo. Here "foo" doesn't specify the type of anything; it's only used in a special construct to serve as the name of the destructor function. It therefore gets font-lock-function-name-face. Example 3: foo::bar "foo" doesn't specify the type of anything here either. Its use is to tell in which scope "bar" is declared. Hence it gets a face that is different from the type face. I call this use "identifier qualifier". To make this more obvious/precise, you could perhaps introduce another face name variable, say c-qualifier-face-name, and make a suitable mapping of it onto one of the existing font-lock faces. I don't think it should be mapped to the type face though, because it would be used for namespace names too. In lack of better alternatives I chose to map it as I did. (Btw, there's not necessarily a hard distinction between types and constants in all languages. Again, it's (afaik) Pike that pushes the limits in this regard. There a type name is nothing more than a class that has been assigned to a constant.) ######################################################################### [ .... ] > Simon. -- Alan.