6

Emacs supports syntax flags for 1- and 2-characters comment delimiters. Can it be made to recognize and properly highlight 3-characters delimiters?

For example:

In Emacs Lisp:
    ;;; Headings

In C#:
    /// XML Comment

In Java:
    /** Javadoc comment */

In Coq:
    (** Codoc comment (nestable with (* ... *) and (** ... *)) *)
Clément
  • 3,924
  • 1
  • 22
  • 37

2 Answers2

10

AFAIK the example you give are actually 2-char comment delimiters, except that depending on the 3rd character, these comments are treated in different ways (but always as comments in the sense that the semantics of the code is unaffected).

So, the support offered by Emacs's syntax tables should be sufficient in most cirsumstances. If you want to highlight them differently, you can use font-lock-syntactic-face-function so as to return different faces for those different comments (typically by looking at the chracters after (nth 8 state) to recognize which kind of element is being processed).

Stefan
  • 26,154
  • 3
  • 46
  • 84
3

Take a look at the docs for syntax-propertize-function also. That's used for scanning a buffer and applying syntax categories programmatically, rather than using the syntax table.

This Stack Overflow answer has a couple examples.