all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Syntax Highlighting Problem
@ 2009-05-03 14:28 Chris Gordon-Smith
  2009-05-05 20:00 ` Alan Mackenzie
       [not found] ` <mailman.6684.1241553645.31690.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 3+ messages in thread
From: Chris Gordon-Smith @ 2009-05-03 14:28 UTC (permalink / raw)
  To: help-gnu-emacs

I am fairly new to emacs, and am having a problem with syntax highlighting 
with C++.

Although the highlighting seems to be working overall, it behaves strangely 
with macros. 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?

-- 
Chris Gordon-Smith
London
www.simsoup.info


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Syntax Highlighting Problem
  2009-05-03 14:28 Syntax Highlighting Problem Chris Gordon-Smith
@ 2009-05-05 20:00 ` Alan Mackenzie
       [not found] ` <mailman.6684.1241553645.31690.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 3+ messages in thread
From: Alan Mackenzie @ 2009-05-05 20:00 UTC (permalink / raw)
  To: Chris Gordon-Smith; +Cc: help-gnu-emacs

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 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!

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.

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

Look forward to hearing back from you!

> -- Chris Gordon-Smith London www.simsoup.info

-- 
Alan Mackenzie (Nuremberg, Germany).




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Syntax Highlighting Problem
       [not found] ` <mailman.6684.1241553645.31690.help-gnu-emacs@gnu.org>
@ 2009-05-06 23:07   ` Chris Gordon-Smith
  0 siblings, 0 replies; 3+ messages in thread
From: Chris Gordon-Smith @ 2009-05-06 23:07 UTC (permalink / raw)
  To: help-gnu-emacs

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-05-06 23:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-03 14:28 Syntax Highlighting Problem Chris Gordon-Smith
2009-05-05 20:00 ` Alan Mackenzie
     [not found] ` <mailman.6684.1241553645.31690.help-gnu-emacs@gnu.org>
2009-05-06 23:07   ` Chris Gordon-Smith

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.