Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to gray out "// comment" lines in Emacs?

Tags:

regex

emacs

Regular expression trouble in Emacs: how do I highlight all lines that begin with "//"?

I would like to gray out my comments in text mode but the following snippet doesn't seem to work:

(add-hook 'text-mode-hook
(lambda()
  (font-lock-add-keywords nil
  '(("^//.+"
     1 font-lock-comment-face prepend)))))

'Re-builder' indicated that this kind of expression should do the trick. What's wrong? Thanks!

like image 356
martz Avatar asked Oct 22 '11 16:10

martz


1 Answers

Okay, I figured it out. "^\\(//.*\\)$" does the job.

Sorry for possible "spam". I did google for almost two hours beforehand; regular expressions just seem to be way above my head.

like image 53
martz Avatar answered Oct 18 '22 06:10

martz