Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs c-mode fill-paragraph with Doxygen Comments

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

like image 592
DuneBug Avatar asked Dec 29 '09 00:12

DuneBug


People also ask

How to keep paragraphs filled in Emacs minor-mode?

An emacs minor-mode for keeping paragraphs filled in both comments and prose. Each time a space is inserted the current paragraph is refilled. C-q space or just-one-space (usually bound to M-space) can be used to insert a space without filling the paragraph.

Which symbols are supported by Doxy comment styles?

#symbol uses stricter matching ( [a-zA-Z0-9_\.\:]+ ). Doxy comment styles /** … */, /*! … */, /// … are supported. HTML tags also supported (from javadoc).

How do I create a Doxygen template in Visual Studio?

cd /path/to/a/project/, and generate a template config file by doxygen -s -g doxygen.conf (Omit -s to generate it with detailed comments). Tweak the file by specifying input and output directories, and set HAVE_DOT and CALL_GRAPH to YES.

How do I enable aggressive fill-paragraph mode?

to enable aggressive-fill-paragraph-mode only in specified major modes. You can customise which keys trigger a fill with the afp-fill-keys variable, by default both and . are used. There seems to be little consensus between different major modes on what exactly fill-paragraph should fill.


1 Answers

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.

like image 175
Neil Avatar answered Nov 15 '22 08:11

Neil