unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: use.address@my.homepage.invalid (Chris Gordon-Smith)
To: help-gnu-emacs@gnu.org
Subject: Re: Syntax Highlighting Problem
Date: 6 May 2009 23:07:59 GMT	[thread overview]
Message-ID: <76ejieF1bn33kU1@mid.individual.net> (raw)
In-Reply-To: mailman.6684.1241553645.31690.help-gnu-emacs@gnu.org

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


      parent reply	other threads:[~2009-05-06 23:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=76ejieF1bn33kU1@mid.individual.net \
    --to=use.address@my.homepage.invalid \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).