问题
I'm having trouble getting my clang-format to quite cooperate with multi-line comments. I have tried:
CodePragmas: '^[^ ]'
But this still results in the following. Before formatting:
class Test
{
/* =======
* Public Functions
* ======== */
public:
};
After formatting:
class Test
{
/* =======
* Public Functions
* ======== */
public:
};
Any help would be greatly appreciated. Thanks.
回答1:
I have a slightly different comment format, but same situation. If you know the format of your block comments all use the same pattern, I think something like this will work:
CommentPragmas: '/\* =======\n((.+\n.+)+)======== \*/'
If you want to exclude all multi-line block comments, I think this will work:
CommentPragmas: '/\*(.+\n.+)+\*/'
I found that the ColumnLimit still applies to those comments, causing them to wrap in undesirable ways. Otherwise, clang-format (3.8) leaves those blocks untouched.
来源:https://stackoverflow.com/questions/36290025/disallow-clang-format-from-messing-with-comments