Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force clang-format to respect doxygen block comments

Tags:

clang-format

I use long block C-style Doxygen comments in my C/C++ code. This is style #4 listed on http://www.doxygen.nl/manual/docblocks.html and looks like this (running out to 80 characters)...

/**************************************************************************//**
* \file
* \date   2017-01-02
* \author Alex Hogen
******************************************************************************/

If I run clang-format on this, it inserts a single space between the two forward slashes, so it looks all goofy like this....

/**************************************************************************/ /**
* \file
* \date   2017-01-02
* \author Alex Hogen
******************************************************************************/
  • I have SpacesBeforeTrailingComments set to 2, so that can't be the problem.
  • Tried CommentPragmas regex \/\*+\/\/\*+.
  • Tried CommentPragmas regex /\*(.+\n.+)+\*/
  • I've tried setting ReflowComments to false

... but none of those things have worked.

I understand there are two comments in this block, but I can't find any clang-format parameter addressing block comments on the same line. How can I stop clang-format from inserting this space?

And I don't want to solve this by disabling clang-format for every Doxygen comment block. That seems ridiculous.

Any good suggestions? :-)

like image 267
ahogen Avatar asked Dec 29 '17 02:12

ahogen


1 Answers

In your .clang-format file:

CommentPragmas:  '^\\.+'

This will make it not format comment line that starts with a backslash followed by a word. This works even though there is an asterisk before the doxygen comment because clang-format automatically ignores asterisks and whitespace at the beginning of every comment line.

like image 92
CoolOppo Avatar answered Oct 26 '22 16:10

CoolOppo