Emacs c-mode fill-paragraph with Doxygen 注释

发布于 08-15 18:50 字数 1437 浏览 6 评论 0原文

我有一个与 获取非常相似的问题Emacs fill-paragraph 可以很好地处理类似 javadoc 的注释,但我不确定是否能在一年前的帖子中得到很多答案。

无论如何,我有一些 C 代码,其中有一些 Doxygen 注释,如下所示:

/**
 * Description
 *
 * @param[in,out] var1 : <Long description that needs to be wrapped.>
 * @param[in,out] var2 : <Description2>
 */

现在,当我在 emacs 中使用 Mq 时,我想要以下内容:

/**
 * Description
 *
 * @param[in,out] var1 : <Long description that needs
 *                       to be wrapped.>
 * @param[in,out] var2 : <Description2>
 */

但是,当前我得到以下内容:

/**
 * Description
 *
 * @param[in,out] var1 : <Long description that needs
 * to be wrapped.>  @param[in,out] var2 : <Description2>
 */

做一些研究,看起来我需要设置emacs 中的段落开始变量用于识别“@param”。我发现了另一个关于堆栈溢出的问题(获取 Emacs fill-paragraph 可以很好地处理类似 javadoc 的注释),它有一个示例正则表达式。我对其进行了一些修改以满足我的要求,并在“搜索”->“正则表达式转发”中对其进行了测试,它正确地突出显示了每个 @param 句子。

我使用了以下正则表达式 "^\s-*\*\s-*\(@param\).*$"

因此,我尝试将给定的正则表达式设置为我的段落开头 (在我的 .emacs 文件中添加了 elisp 语法所需的 \。当我打开一个新的 emacs 窗口并尝试 Mq 时,发生了同样的错误。我有什么遗漏的吗? Mq 在 c 模式下的使用方式是否不同?我应该检查我的 .emacs 文件中是否有可能导致错误的内容吗?任何帮助将不胜感激。

谢谢, 瑞安

I have a question that is very similar to Getting Emacs fill-paragraph to play nice with javadoc-like comments, but I wasn't sure if I would get many answers in a year old thread.

Anyhow, I have C code that has some Doxygen comments that look like the following:

/**
 * Description
 *
 * @param[in,out] var1 : <Long description that needs to be wrapped.>
 * @param[in,out] var2 : <Description2>
 */

Now, when I use M-q in emacs, I want the following:

/**
 * Description
 *
 * @param[in,out] var1 : <Long description that needs
 *                       to be wrapped.>
 * @param[in,out] var2 : <Description2>
 */

But, current I get the following:

/**
 * Description
 *
 * @param[in,out] var1 : <Long description that needs
 * to be wrapped.>  @param[in,out] var2 : <Description2>
 */

Doing some research, it looked like I needed to set the paragraph-start variable in emacs to recognize the "@param." I found another question on stack overflow (Getting Emacs fill-paragraph to play nice with javadoc-like comments), that had a sample regular expression. I modified it a bit to fit my requirements, and I tested it inside of Search->Regex Forward, and it highlighted each @param sentence correctly.

I used the following regular expression "^\s-*\*\s-*\(@param\).*$"

So, I tried setting the given regular expression as my paragraph-start (with the added \'s required for the elisp syntax) in my .emacs file. When I opened a new emacs window and tried out the M-q, the same error was occurring. Is there something I am missing? Is M-q used differently in c-mode? Should I check my .emacs file for something that may be causing an error here? Any help would be appreciated.

Thanks,
Ryan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青瓷清茶倾城歌2024-08-22 18:50:34

关于您的问题“Mq 在 c 模式中的使用是否有所不同?”,describe-key (绑定到 Ch k)是您的朋友。当使用 C 文件访问缓冲区时,输入 Ch k Mq,它会准确地告诉您 Mq 绑定到哪个函数。在本例中,它是 c-fill-paragraph,它最终使用 paragraph-start,即您在其他问题中找到的变量。

我发现用作 paragraph-start 的正则表达式会换行并将每个 @param 视为一个新段落:

"^[ ]*\\(//+\\|\\ **\\)[ ]*\\([ ]*$\\|@param\\)\\|^\f"

但是,它不会按您想要的方式缩进换行。它将使您的示例看起来像这样:

/**
 * Description
 *
 * @param[in,out] var1 : <Long description that needs
 * to be wrapped.>
 * @param[in,out] var2 : <Description2>
 */

我希望它仍然适合您。如果您弄清楚缩进,请告诉我。

Regarding your question, "Is M-q used differently in c-mode?", describe-key (bound to C-h k) is your friend. While visiting the buffer with the C file, type C-h k M-q and it will tell you exactly what function M-q is bound to. In this case, it is c-fill-paragraph, which ultimately uses paragraph-start, the variable you found in that other question.

I found that this regular expression used as paragraph-start will wrap lines and treat each @param as a new paragraph:

"^[ ]*\\(//+\\|\\**\\)[ ]*\\([ ]*$\\|@param\\)\\|^\f"

However, it will not indent the wrappedlines as you want. It will make your example look like this:

/**
 * Description
 *
 * @param[in,out] var1 : <Long description that needs
 * to be wrapped.>
 * @param[in,out] var2 : <Description2>
 */

I hope it still works better for you. Let me know if you figure out the indenting.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文