views:

132

answers:

1

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.

+2  A: 

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 "...")))
Trey Jackson