Reputation: 65720
I am writing a major Emacs mode for a basic language I am implementing. I am wanting to highlight syntax for method calls where the method name is checked by [a-z][^()]*
but only when followed by ([^)])
. How would I define a regular expression which would match the first part if followed by the second part, but not highlight the second part?
Upvotes: 0
Views: 400
Reputation: 74470
Try this:
(font-lock-add-keywords 'my-mode
'(("\\(\\b[a-z][^()]*\\)([^)]*)"
1 font-lock-function-name-face t)))
The 1 says to apply the highlight to the first subexpression.
Note: I added a \\b
to make it match only when the [a-z]
begins a word (otherwise Dude()
would have the ude
highlighted), and I added a *
in the last set of parens b/c it seemed like it was missing.
I tested this in c++-mode.
Documentation for font-lock-add-keywords and other font lock things can be found here.
Upvotes: 1