I am trying to define another comment style, similar to what we can do with modify-syntax-entry:

(modify-syntax-entry ?/ ". 124b")
(modify-syntax-entry ?* ". 23")
(modify-syntax-entry ?\n "> b")

However, the comment has to be as follows:

`comment("This is my comment!")`

I have tried using regex:

(defconst my-comment-macro-regexp
   (rx "`comment(\"" (zero-or-more anything) "\")`"))

(defconst my-font-lock-keywords
   (cons my-comment-macro-regexp 'font-lock-comment-face)))

But this doesn't work as the string highlighting on the inside of the macro takes precedence over this font style.

  • 1
    Did you mean to include the backticks in the "this is my comment" bit? The four-space indent already marks it as a code block; the backticks do inline code. I think you do, but wanted to clarify because we have Markdown syntax and emacs lisp syntax possibly clashing here...
    – Dan Drake
    Commented Oct 2, 2023 at 11:13
  • 1
    @DanDrake yep, the single backticks are to be included. Thanks for confirming. Commented Oct 2, 2023 at 20:58

1 Answer 1


I had to override the string matching:

(defconst my-font-lock-keywords
   (list my-comment-macro-regexp 0 'font-lock-comment-face t)))

You can read a good explanation on why this works here: [1].

See also: [2], [3].

Your Answer

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

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