<p>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.</p>

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

<p>If I have this (\ instead of javadoc @):</p>

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

<p>M-q gives me:</p>

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

<p>But I want:</p>

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

<p>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.</p>

<p>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. </p>

[{'answer_id': 72637, 'author': 'Allen', 'author_id': 6043, 'author_profile': 'https://Stackoverflow.com/users/6043', 'pm_score': 1, 'selected': False, 'text': "<p>There's other modes that have less complex functions used for <code>fill-paragraph-function</code>. Browsing through my install, it looks like the ones in ada-mode and make-mode are good examples.</p>\n"}, {'answer_id': 73963, 'author': 'davidavr', 'author_id': 8247, 'author_profile': 'https://Stackoverflow.com/users/8247', 'pm_score': 1, 'selected': False, 'text': '<p>What I do in these cases is open a blank line between the paragraph lines and the argument lines, then use M-q to wrap the paragraph lines, then kill the blank line between them. Not ideal, but it works and is easy enough to record in a macro if you need to repeat it.</p>\n'}, {'answer_id': 145431, 'author': 'Joakim Hårsman', 'author_id': 11978, 'author_profile': 'https://Stackoverflow.com/users/11978', 'pm_score': 3, 'selected': True, 'text': '<p>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:</p>\n\n<pre><code>(setq paragraph-start "^\\\\s-*\\\\#\\\\s-*\\\\\\\\\\\\(arg\\\\|ret\\\\).*$")\n</code></pre>\n\n<p>Here a page that has an example regexp for php-mode that does this:\n<a href="http://barelyenough.org/blog/2006/10/nicer-phpdoc-comments/" rel="nofollow noreferrer">http://barelyenough.org/blog/2006/10/nicer-phpdoc-comments/</a></p>\n'}]
['https://Stackoverflow.com/questions/71788', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11978/']