[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: FW: Font-lock misfontifies foo::bar in C++
From: |
Alan Mackenzie |
Subject: |
Re: FW: Font-lock misfontifies foo::bar in C++ |
Date: |
Sun, 6 Aug 2006 19:08:18 +0100 |
User-agent: |
Mutt/1.5.9i |
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.
- Re: FW: Font-lock misfontifies foo::bar in C++,
Alan Mackenzie <=