2

I'm trying to create my own major mode. So far I've been able to set all the syntax highlighting that I need, but I'm struggling with this one.

Basically I need to color any word before an equal sign. Like this:

< action name="set_button">

Like the face nxml-attribute-local-name in nxml-mode.

To do this I'm using a regular expression to find that word and then set font-lock-variable-name-face.

I've tried the following regular expressions, but they didn't work. I don't know if it's because I'm not escaping them correctly or because emacs doesn't support them.

 ("\\(\w+\\)\\(?=\s*=\\)" . font-lock-variable-name-face)
 ("\b\\(\w+\\)\b=" . font-lock-variable-name-face)

There is nothing wrong with the elisp code. When I try a more simple regex it works.

Any ideas?

Thanks

1
  • Technically, your second regexp should've worked. Even simpler: "\\w+=" would have worked (but it would also capture the equals sign. Your first regexp doesn't work because Emacs regexp doesn't implement non-capturing groups, other than that, it's fine.
    – wvxvw
    Commented Feb 23, 2015 at 15:13

1 Answer 1

2

After lots of trial and error I discovered what was wrong. I just needed to escape twice the 'w' letter Here is the final line:

 ("\\b\\(\\w+\\)\\b=" . font-lock-variable-name-face)

Looks easy now :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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