让Emacs填充段落与javadoc类似的注释很好玩

Joa*_*man 11 emacs elisp

我正在为我在工作中使用的APL方言编写一个Emacs主要模式.我已经获得了基本的字体锁定功能,在设置了comment-start和comment-start-skip之后,注释/取消注释区域和填充段落也起作用.

但是,注释块通常包含javadoc样式注释,我想填充段落,以避免从这些命令开始粘合行.

如果我有这个(\而不是javadoc @):

# This is a comment that is long and should be wrapped.
# \arg Description of argument
# \ret Description of return value
Run Code Online (Sandbox Code Playgroud)

Mq给了我:

# This is a comment that is long and
# should be wrapped. \arg Description
# of argument \ret Description of
# return value
Run Code Online (Sandbox Code Playgroud)

但我想要:

# This is a comment that is long and
# should be wrapped.
# \arg Description of argument
# \ret Description of return value
Run Code Online (Sandbox Code Playgroud)

我已经尝试将paragraph-start和paragraph-separate设置为适当的值,但fill-paragraph仍然在注释块中不起作用.如果我删除注释标记,Mq按我想要的方式工作,所以我用于段落启动的正则表达式似乎有效.

我是否必须为主要模式编写自定义填充段?cc模式有一个处理这样的情况,但它真的很复杂,我想尽可能避免它.

Joa*_*man 4

问题是段落开始正则表达式必须匹配整行才能工作,包括实际的注释字符。以下 elisp 适用于我给出的示例:

(setq paragraph-start "^\\s-*\\#\\s-*\\\\\\(arg\\|ret\\).*$")
Run Code Online (Sandbox Code Playgroud)

这里有一个 php-mode 的示例正则表达式的页面,可以执行此操作: http://barelyenough.org/blog/2006/10/nicer-phpdoc-comments/