如何自定义c-doc-comment-style以使用reStructuredText作为文档注释风格?

huangapple go评论59阅读模式
英文:

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

问题

Emacs使用c-doc-comment-style来指定在cc-mode中使用的文档注释风格。我想要使用reStructuredText或rst来编写文档注释。有一个用于reStructuredText文件的rst-mode,带有rst-font-lock-keywords,但我似乎无法将它们连接起来。

此外,我希望能够在不同的项目中使用不同的风格,因为显然很多项目使用gtkdocdoxygen风格。

英文:

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

得分: 1

cc-mode不支持reStructuredText,我不知道任何简单的方法来在cc-mode中重用rst-mode的语法高亮。我认为你需要自己编写适用于cc-mode的相应代码。

关于c-doc-comment-style文档提到了以下内容:

您还可以编写自己的文档注释着色支持,以与c-doc-comment-style一起使用:提供一个名为* -font-lock-keywords的变量或函数,其中*是您想在c-doc-comment-style中使用的名称。如果它是一个变量,它将被添加到font-lock-keywords之前。如果它是一个函数,在模式初始化时将调用该函数,并将结果添加到前面。[...] 甚至可以在文档注释中使用其他样式来为构造进行着色,但有一定的限制。有关示例,请参见cc-fonts-el末尾的Pike自动文档注释样式。

您可以使用类似rstdoc的名称作为c-doc-comment-style的值,并通过定义一些变量来实现它。现有的定义以及rst-mode中的正则表达式可能会作为示例的源代码非常有用。

此外,我想能够在不同的项目中使用不同的样式。

这很容易。您可以将c-doc-comment-style设置为目录本地或文件本地变量。请参阅add-dir-local-variableadd-file-local-variable命令。

英文:

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.

huangapple
  • 本文由 发表于 2023年7月6日 21:02:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76629141.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定