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?

1 Answer 1

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. :-)

0

Your Answer

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

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