emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CC Mode - syntactical can of worms.


From: Alan Mackenzie
Subject: CC Mode - syntactical can of worms.
Date: Thu, 31 Jan 2008 11:45:46 +0000
User-agent: Mutt/1.5.9i

Hi, Emacs and CC Mode!

Following up from: address@hidden: Bug in emacs 22.1.1 (cosmetic
bug)].

This bug was in C Mode, with the following source line:

    #warning for isn't a keyword here.

This fouls up the fontification, because the syntactic fontification
recognises the apostrophe as a string opener.  It can get pretty bad -
here is a syntactically correct C function:

1   #warning for isn't a keyword here. (
2   //#warning for isnt a keyword here.
3   void foo (bar)
4   {
5   #error Brace yourself! }
6       printf ("Hello, world!\n") ; /* the famous one liner! */
7   }

The apostrophe in L1 fouls up the entire fontification.  The pseudo
brace in L5 spuriously matches the real one on L4.  The brace on L7
mismatches the pseudo parenthesis on L1.

The root of the problem is that CPP lines are allowed to mingle
syntactically with ordinary lines.  Somehow, CPP lines need to be
"commented out" from the Emacs's syntactic routines.  However, turning
# and EOL into another pair of comment delimiters is NOT the Right
Thing.

I think I need a hook function somewhere (after-change, but
before-font-lock, maybe) which should analyse the innards of CPP lines
for unbalanced string quotes or unbalanced parens/braces/brackets, or
the like.

It feels like another syntax category is wanted for such things, a kind
of "open-enclosure / close-enclosure (or close-enopener? ;-)" pair,
whose purpose is syntactically to isolate its contents from the rest of
the file.

Would anybody like to give me any ideas here?

-- 
Alan Mackenzie (Nuremberg, Germany).




reply via email to

[Prev in Thread] Current Thread [Next in Thread]