From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: use.address@my.homepage.invalid (Chris Gordon-Smith) Newsgroups: gmane.emacs.help Subject: Re: Syntax Highlighting Problem Date: 6 May 2009 23:07:59 GMT Organization: SimSoup Message-ID: <76ejieF1bn33kU1@mid.individual.net> References: <765o0pF1baiftU1@mid.individual.net> NNTP-Posting-Host: lo.gmane.org X-Trace: ger.gmane.org 1241672711 19535 80.91.229.12 (7 May 2009 05:05:11 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 7 May 2009 05:05:11 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu May 07 07:04:59 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 1M1vmm-0005Xk-TC for geh-help-gnu-emacs@m.gmane.org; Thu, 07 May 2009 07:04:45 +0200 Original-Received: from localhost ([127.0.0.1]:41156 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M1vmm-0003eZ-D9 for geh-help-gnu-emacs@m.gmane.org; Thu, 07 May 2009 01:04:44 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 116 Original-X-Trace: individual.net zPjR+vE+e8A/XVKUiDjNGwu5P6Vfy2olu9NnVZxvXlf9LCauB7 X-Orig-Path: not-for-mail Cancel-Lock: sha1:7+b5YXtZswlsHRX07qA3W34B7bs= User-Agent: tin/1.8.3-20070201 ("Scotasay") (UNIX) (Linux/2.6.25.5-1.1-default (i686)) Original-Xref: news.stanford.edu gnu.emacs.help:168943 X-Mailman-Approved-At: Thu, 07 May 2009 01:04:20 -0400 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:64213 Archived-At: Alan Mackenzie wrote: Nullo Alan. Thanks for this. Further comments below. > Hi, Chris, > > On Sun, May 03, 2009 at 02:28:41PM +0000, Chris Gordon-Smith wrote: >> I am fairly new to emacs, and am having a problem with syntax >> highlighting with C++. > > Yes. C++ is an utter horror of a language, impossible to parse > syntactically in the general case; so CC Mode sometimes has to guess > what's going on, and sometimes gets it wrong. > >> Although the highlighting seems to be working overall, it behaves >> strangely with macros. > > OK, macros are a problem in any C and C++ (and Objective C), because > they can expand to anything. If you can, it's best to write macros so > that they "look like normal code". > I keep my macros very simple, so that shouldn't be a problem. >> I have a trace utility that can log entry and exit to each function. >> To enable the utility for a function, I invoke a macro at the start of >> the function like this: > >> TRACE > >> The odd thing is that the highlighting of the macro call is not consistent; >> sometimes it is in one colour, sometimes in another colour. > >> Can anyone help? > > OK, lets have some version numbers, please. Do M-x emacs-version and > M-x c-version (where M-x means "press x whilst holding down the alt > key"). Thanks! Using cc-mode version 5.31.5 > > Second thing, could you post a sample of source which displays the > anomaly, please - the smaller the better (5 - 20 lines is usually enough > for this). That way, I can reproduce the problem and hopefully debug > it. See below. I've cut it down as much as possible, so it doesn't make much sense any more, although I believe its still valid C++ > > Next, what are the "faces" (i.e. colours) which get put onto the > various occurrences of TRACE? To see this, put point (the cursor) at > the pertinent places and type C-u C-x =. (Where the "." is not what you > type, is a full stop at the end of my sentence.) In the results window > at the bottom, you should see something like: > > There are text properties here: > face font-lock-variable-name-face > I've added this information below as 'comments' > Look forward to hearing back from you! The following seems to work. Any comments? ;; Highlighting for special macros used on the SimSoup project (font-lock-add-keywords 'c++-mode '(("\\(\\\\>\\|\\\\|\\\\|\\\\)" 1 font-lock-preprocessor-face t))) Here is the code sample // Cut down example to demonstrate syntax highlighting problem. #include "globldef.h" #include "Library_Headers.h" #include "MolType_Joiner.h" #include "Molecule_Type.h" #include "Atom_Type.h" #include "MolType_Struct.h" #include "Bond_Types.h" #include "Chemistry.h" bool MolType_Joiner::Allow_Construction_Reactants(const Molecule_Type& Reactant1, const Molecule_Type& Reactant2) { TRACE // default face if (((Reactant1.Get_Identifier() - Reactant2.Get_Identifier()) % 50) == 0) { } } //---------------------------------------------------------------------------------------------------------------- bool MolType_Joiner::Clash(const MolType_Struct::BoardSpec_T& MoveBoard, const MolType_Struct::BoardSpec_T& StaticBoard, const int X_Offset, const int Y_Offset) { TRACE // font-lock-type-face using namespace MolType_Struct; const int X_Scan_Max = MoveBoard.Get_Width() + 1; const int Y_Scan_Max = MoveBoard.Get_Height() + 1; for (int X_MoveBd = -1; X_MoveBd < X_Scan_Max; ++X_MoveBd) { int x = x + 1; // silly code for the example } return false; } -- Chris Gordon-Smith London www.simsoup.info