How to customize c-doc-comment-style to use reStructuredText as documentation comment style?

65 Views Asked by At

Emacs uses c-doc-comment-style to specify the documentation comment style to use in cc-mode. I'd like to use reStructuredText, or rst, for documentation comments. There's an rst-mode for reStructuredText files, with rst-font-lock-keywords, but I can't seem to be able to connect the two.

Furthermore, I'd like to be able to use different styles for different projects, as obviously a lot of projects use gtkdoc or doxygen styles.

1

There are 1 best solutions below

1
On

cc-mode doesn't have support for reStructuredText, and I don't know any simple way to reuse rst-mode's highlighting in cc-mode. I think you'll have to write the appropriate code for cc-mode yourself.

The documentation for c-doc-comment-style has this to say:

You can also write your own doc comment fontification support to use with c-doc-comment-style: Supply a variable or function *-font-lock-keywords where * is the name you want to use in c-doc-comment-style. If it’s a variable, it’s prepended to font-lock-keywords. If it’s a function, it’s called at mode initialization and the result is prepended. [...] It is even possible, to a limited extent, to fontify constructs inside a doc comment with other faces. For an example, see pike autodoc comment style towards the end of cc-fonts-el.

You can make up a name like rstdoc for use as the value of c-doc-comment-style and implement it by defining a couple of variables. The existing definitions, as well as the regexps in rst-mode, will probably be useful as a source of examples.

Furthermore, I'd like to be able to use different styles for different projects

This one is easy. You can set c-doc-comment-style as a directory-local or file-local variable. See the commands add-dir-local-variable and add-file-local-variable.