1

I'm currently writing a major-mode for Emacs and am trying to figure out how to get syntax highlighting to work. My major-mode is for a lisp-like language that looks like this:

[= a 3]
[= [double x] [* x 2]]
[double a]

Basically, what I'm trying to do is write a regular expression to match all words preceded by [ but not the [ itself to highlight function calls. I've done some googling and have found that emacs does not support regexp look-behind, so how would I do this?

Drew
  • 29,895
  • 7
  • 74
  • 104
Ajay Tatachar
  • 383
  • 3
  • 16

1 Answers1

2

You can specify the number of the regex group you want to highlight. So, you could construct a regex to capture the [ plus the following function name and then only highlight the function's name by specifying the first capture group, eg.

(defvar my-mode-font-lock-keywords
  '(("\\[\\s-*\\([^\][:space:]]+\\)" (1 font-lock-function-name-face))))

(define-derived-mode my-mode prog-mode "MyMode"
  (setq-local font-lock-defaults '(my-mode-font-lock-keywords)))
Rorschach
  • 31,301
  • 5
  • 78
  • 129