使用类似Javadoc的评论获取Emacs的填充段 [英] Getting Emacs fill-paragraph to play nice with javadoc-like comments

查看:97
本文介绍了使用类似Javadoc的评论获取Emacs的填充段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我在工作中使用的APL方言编写Emacs主要模式。我已经得到
基本字体锁定工作,并且在设置了comment-start和
comment-start-skip,comment / uncomment区域和填充段也
工作之后。



但是,注释块通常包含javadoc样式注释,而i
希望使用fill-paragraph来避免使用这样的命令将
绑在一起。



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

 #这是一个评论很长,应该包装。 
#\arg参数说明
#\ret返回值说明

Mq给我:

 #这是一个很长的评论,
#应该被包装。 \arg描述
参数的数量\ret
#返回值的描述

但是我想要:

 #这是一个很长的评论,
#应该被包装。
#\arg参数说明
#\ret返回值说明

我已经尝试将段落开始和段落分隔到
适当的值,但是填充段在
注释块中仍然不起作用。如果我删除注释标记,Mq的工作原理是我想要
,所以我用于段落开始的正则表达式似乎工作。



我必须为我的主要
模式写一个自定义填充段? cc-mode有一个处理这样的情况,但它真的是
复杂,我想避免它,如果可能的话。

解决方案

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

 (setq paragraph-start^ \\s- * \ \#\\s- * \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\& > 

这里有一个具有php模式的regexp示例的页面:
http://barelyenough.org/blog/2006/10/nicer-phpdoc-comments/


I'm writing an Emacs major mode for an APL dialect I use at work. I've gotten basic font locking to work, and after setting comment-start and comment-start-skip, comment/uncomment region and fill paragraph also work.

However, comment blocks often contain javadoc style comments and i would like fill-paragraph to avoid glueing together lines starting with such commands.

If I have this (\ instead of javadoc @):

# This is a comment that is long and should be wrapped.
# \arg Description of argument
# \ret Description of return value

M-q gives me:

# This is a comment that is long and
# should be wrapped. \arg Description
# of argument \ret Description of
# return value

But I want:

# This is a comment that is long and
# should be wrapped.
# \arg Description of argument
# \ret Description of return value

I've tried setting up paragraph-start and paragraph-separate to appropriate values, but fill-paragraph still doesn't work inside a comment block. If I remove the comment markers, M-q works as I want to, so the regexp I use for paragraph-start seems to work.

Do I have to write a custom fill-paragraph for my major mode? cc-mode has one that handles cases like this, but it's really complex, I'd like to avoid it if possible.

解决方案

The problem was that the paragraph-start regexp has to match the entire line to work, including the actual comment character. The following elisp works for the example I gave:

(setq paragraph-start "^\\s-*\\#\\s-*\\\\\\(arg\\|ret\\).*$")

Here a page that has an example regexp for php-mode that does this: http://barelyenough.org/blog/2006/10/nicer-phpdoc-comments/

这篇关于使用类似Javadoc的评论获取Emacs的填充段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆