Disallow Clang-Format From Messing With Comments

折月煮酒 提交于 2019-12-11 11:13:58

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!