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
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.
精彩评论