The following code changes the background colour of lines that are composed of the repetition of the comment character for lisp-interaction-mode.

(defface special-comment '((t (:background "orange"))))

(font-lock-add-keywords 'lisp-interaction-mode
   '(("^;;+$" 0 'special-comment t)))

I then transitioned the call to use Syntax Classes (\s< for Comment Starter, \s> for Comment Ender).

(font-lock-add-keywords 'lisp-interaction-mode
   '(("^\\s<\\s<\\s<+$" 0 'special-comment t)))

But, extending this even further, fails

(font-lock-add-keywords nil
   '(("^\\s<\\s<\\s<+$" 0 'special-comment t)))

What can be done to extend this for prog-mode?

  • 1
    What have you tried?
    – db48x
    Commented Sep 10, 2022 at 19:44
  • Thank you, that is a better question. I don’t know the answer, but maybe if you read chapter 36 Syntax Tables of the Emacs Lisp Manual you will find it.
    – db48x
    Commented Sep 10, 2022 at 21:53
  • Would the related information be about Comment Starters < and Comment Enders > ?
    – Dilna
    Commented Sep 10, 2022 at 22:07
  • Correct, but note the complications for languages with two–character starters and enders, like C with /* comment */ or C++ with // comment.
    – db48x
    Commented Sep 10, 2022 at 23:31
  • For C and C++ I want to use ^///+$ pattern.
    – Dilna
    Commented Sep 10, 2022 at 23:35


Your Answer

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

Browse other questions tagged or ask your own question.