2

I want to highlight certain words to a color using highlight-regexp. The words I want to highlight are "fn", "let", "mut", etc. for rust development.

The code I have so far is this:

(add-hook 'rust-mode-hook '(lambda ()
    (highlight-regexp "\(let\|fn\|mut\)" font-lock-constant-face)))

Which does not give me any highlighting. However, when I regex for only a single word it does work:

(add-hook 'rust-mode-hook '(lambda ()
    (highlight-regexp "let" font-lock-constant-face)))

So I figure it must be something wrong with my regex. How do I regex for any of these groups?

Drew
  • 75,699
  • 9
  • 109
  • 225
Vent
  • 77
  • 4

1 Answers1

2

Inside a string, you need to double the backslashes. It makes the regexps look rather ugly, but it's something we have to live with. :-)

Sue D. Nymme
  • 1,406
  • 12
  • 13