help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Syntax Highlighting Problem


From: Chris Gordon-Smith
Subject: Re: Syntax Highlighting Problem
Date: 6 May 2009 23:07:59 GMT
User-agent: tin/1.8.3-20070201 ("Scotasay") (UNIX) (Linux/2.6.25.5-1.1-default (i686))

Alan Mackenzie <acm@muc.de> 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 
'(("\\(\\<TRACE\\>\\>\\|\\<TRACEVAL\\>\\|\\<CREATE_OBJECT\\>\\|\\<DELETE_OBJECT\\>\\)"
 
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


reply via email to

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