如何让 Emacs fill-paragraph 处理我的 C# 模块中的内联 XML 代码文档?

发布于 2024-07-26 05:09:15 字数 2007 浏览 1 评论 0原文

这个问题类似于 获取 Emacs fill-paragraph可以很好地处理类似 javadoc 的注释,但适用于 C#。

我有这样的评论:

/// <summary>
/// Of these Colonies, and ought to fall themselves by sending a 
/// constant state of THE unanimous 
/// Declaration OF Nature and donations are legally 1.E.1.
/// </summary>
///
/// <remarks>
/// <para>
/// If you received written explanation to the phrase "Project Gutenberg" associated 
/// with which you are redistributing 
/// Project GUTENBERG you receive specific permission.
/// </para>
/// </remarks>

我希望 fill-paragraph 只填充文本,并将标记元素保留在自己单独的行上,例如,

/// <summary>
/// Of these Colonies, and ought to fall themselves by 
/// sending a constant state of THE unanimous Declaration 
/// OF Nature and donations are legally 1.E.1.
/// </summary>
///
/// <remarks>
/// <para>
/// If you received written explanation to the phrase 
/// "Project Gutenberg" associated with which you are 
/// redistributing Project GUTENBERG you receive specific 
/// permission.
/// </para>
/// </remarks>

我认为我需要设置段落开始多变的。 Ch v 告诉我它的当前值是:

"[  ]*\\(//+\\|\\**\\)[     ]*\\(@[a-zA-Z]+\\>\\|$\\)\\|^\f"

...看起来已经很毛茸茸的了。 (我讨厌 emacs 正则表达式的所有转义请求。)我认为我需要回顾一下 XML 文档元素(如)之后的第一行开始一个段落。

我现在要搞乱它,但是有人将它设置为执行内联代码文档吗?


编辑:哎呀! Emacs 正则表达式不执行后视操作! 好的,还有其他建议吗? 如何将段落的开头设置为 AFTER

之后的行 或<段落> ?

ps:上面示例中的假代码文档来自 美国独立宣言的古腾堡副本; 感谢 这个问题 技术。

This question is similar to Getting Emacs fill-paragraph to play nice with javadoc-like comments, but for C#.

I have comments like this:

/// <summary>
/// Of these Colonies, and ought to fall themselves by sending a 
/// constant state of THE unanimous 
/// Declaration OF Nature and donations are legally 1.E.1.
/// </summary>
///
/// <remarks>
/// <para>
/// If you received written explanation to the phrase "Project Gutenberg" associated 
/// with which you are redistributing 
/// Project GUTENBERG you receive specific permission.
/// </para>
/// </remarks>

And I would like fill-paragraph to fill just the text, and keep the markup elements on their own separate lines, eg,

/// <summary>
/// Of these Colonies, and ought to fall themselves by 
/// sending a constant state of THE unanimous Declaration 
/// OF Nature and donations are legally 1.E.1.
/// </summary>
///
/// <remarks>
/// <para>
/// If you received written explanation to the phrase 
/// "Project Gutenberg" associated with which you are 
/// redistributing Project GUTENBERG you receive specific 
/// permission.
/// </para>
/// </remarks>

I think that I need to set the paragraph-start variable. C-h v tells me its current value is:

"[  ]*\\(//+\\|\\**\\)[     ]*\\(@[a-zA-Z]+\\>\\|$\\)\\|^\f"

...which is already looking pretty hairy. (I hate all the escaping reqd for emacs regexps.) I think I need a look-behind to say that the first line after an XML doc element (like <remarks>) begins a paragraph.

I'm going to mess with it now, but does anyone have it set up to do inline code doc?


EDIT: Whoops! Emacs regexps don't do lookbehind! Ok, any other suggestions? How do I set the start of a paragraph to be the line AFTER <summary> or <para> ?

ps: The fake code doc in my example above comes from a Markov Chain operation on the Gutenberg copy of the US Declaration of Independence; thanks to this question for the technique.

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

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

发布评论

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

评论(1

月野兔 2024-08-02 05:09:15

尝试这个设置:

(setq paragraph-separate "[     ]*\\(//+\\|\\**\\)\\([  ]*\\| <.*>\\)$\\|^\f")

它告诉 fill-paragraph 什么分隔段落,我将其自定义为包含一个空格和一对匹配的尖括号。 这可能会让你得到你想要的。 它适用于您提供的示例。

当然,您必须在 c 模式挂钩之一中设置该变量,例如:

(add-hook 'c-mode-common-hook '(lambda () (setq paragraph-separate "...")))

Try this setting:

(setq paragraph-separate "[     ]*\\(//+\\|\\**\\)\\([  ]*\\| <.*>\\)$\\|^\f")

That tells fill-paragraph what separates paragraphs, and I customized it to include a a space and a matching pair of angle brackets. This might get you what you want. It worked for the example you provided.

Of course you'll have to set that variable in one of the c-mode hooks, like:

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