0

Following some help provided by Tobias, I am trying to assign a font-lock-keyword-face to all text (:alpha:) to the left of an equal sign (=) in a new Tecplot major mode. I read through the regexp section of elisp.pdf and came up with [^# ][[:alpha:]] =", but this only matches the first two letters to the left of the equal sign and the equal sign. In my code:

# To ensure all the data needed is displayed, activate the surfaces of          
# each zone, and extract from the auxilary data, the number of zones            
# in the data set. This number is used throughout this macro to control         
# various operations.                                                           

$!System "echo \" \" "

$!If "|AuxDataSet:SolverName|" == "OVERFLOW"

  $!FieldMap [1-|NumZones|]  Surfaces{SurfacesToPlot = BoundaryFaces}
  $!FieldMap [1-|NumZones|]  Surfaces{IRange{Max = 0}}
  $!FieldMap [1-|NumZones|]  Surfaces{JRange{Max = 0}}
  $!FieldMap [1-|NumZones|]  Surfaces{KRange{Max = 0}}

$!Else

  $!FieldMap [1-|NumZones|]  Surfaces{SurfacesToPlot = BoundaryFaces}

$!EndIf

the "ax =" and "ot =" are getting the font. However, I do not want to include the equal sign but I do want to include the entire word, such as "Max" and "SurfaceToPlot". How do I get just the word to the left of the equal sign.

  • Please show your font-lock code as well. To exclude the = you would group part of your regexp, and then tell font-lock to use that group of the matching text. – phils Apr 30 at 23:09
0

In trying to answer your problem, I ran into M-x regex-builder, which may help you as you try to build these regular expressions.

Anyways, you've only defined 4 characters to match:

  1. something that's not a # or space
  2. something that's an :alpha:
  3. a space
  4. an equals sign

This regex will get you most of the way there: [[:alpha:]]* = as it will highlight zero or more alpha characters before a 'space' and 'equals sign'.

You may need to use precedence to make this 'match' not appear for comment lines (which is what I assume you trying to do with the [^# ] command). Unfortunately, a single regex cannot fill the need to highlight a portion of a full-line match (I don't think).

| improve this answer | |
  • Typically, you don't need to take comments into account since font-lock by default don't add a face if another one (i.e. the comment face) already is present. – Lindydancer May 30 at 20:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.