I am working on a major mode for an input file format I am interested in and want to set multi-line comments with the delimiters skip and noskip like

skip larb noskip


  TYPE structured
  NXYZ 284 307 1

Using the re-builder, I came upon the following regex that highlights both single and multi-line comments


But this doesn't work to pass to the font-lock-comment-face. Only the single-line version gets its font-locked.

Is there a mode with word-delimited multi-line comments like I want, that I can borrow the right syntax from?

1 Answer 1


Rather than handle it in font-lock highlighing rules, you want to handle it at the level of syntax tables. Now syntax-tables can't directly handle such start/end markers, so you'll have to use the syntax-propertize system. E.g.

(setq-local syntax-propertize-function
    ("\\_<\\(s\\)kip\\_>" (1 "<"))
    ("\\_<noski\\(p\\)\\_>" (1 ">"))))

An important difference between font-lock rules and syntax-propertize rules is that font-lock rules can be applied "out of order" or piecemeal. More specifically, by default Emacs only applies font-lock rules to the parts of the buffer that are displayed, so if the skip in your code happens to be in a part of the buffer which was never displayed, the font-lock rules will simply miss it.

Another important difference is that font-lock rules don't naturally have state, so you either need to use one regexp which matches the multi-line element (and then try and force font-lock to always consider a large enough chunk of the buffer to see both skip and noskip at the same time) or to separately match skip, noskip, and every line between them, and to each time check whether we're still within a skip..noskip thingy.

  • Maybe say why Kris wants to handle it this way rather than that way.
    – Drew
    Commented Feb 21, 2016 at 2:05

Your Answer

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