views:

360

answers:

1

Hello,

I have a question that is very similar to http://stackoverflow.com/questions/71788/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 (http://stackoverflow.com/questions/71788/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

A: 

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.

Neil
I tried adding the regular expression that you mentioned in my .emacs file, but I am still having the same issue with the second @param not being recognized as a new paragraph.I realize that fixing the paragraph-state will not solve my indentation issue, but this would be a very helpful place to start =). After writing the initial post, I realized that I should have noted that it was really a two part question:1) Recognize the @param as a new paragraph.2) Properly indent the descriptions.
DuneBug
When you are in the buffer with this file, what does `C-h v paragraph-start` return? If not the above regexp, then you may have set it globally and it may be getting overwritten by c-mode. If that is the case, then you can set this in a c-mode hook.
Neil