c++ - clang-format:禁用宏的格式化?
问题描述
我使用 clang-format 作为我的代码库的自动格式化工具。但是它的一些功能让我很烦。
例如,我不希望它格式化我的宏定义,因为大多数时候,手动格式化它们会更清楚。但我不知道如何以 clang 格式禁用它。
另一个小问题是指针对齐。有时,让它左对齐很清楚,有时它是右对齐。所以我宁愿自己动手。但是从 clang-format 禁用它似乎是不可能的?
对这些问题有帮助吗?
解决方案
You can wrap your macros in
// clang-format off
#define ... \
...
// clang-format on
To escape manually editing of each file you can use the regex
search: ^([ \t]*#[ \t]*define[ \t]+.+?\\\r?\n(?:.*?\\\r?\n)*.*?\r?\n)
replace: // clang-format off\r\n$1// clang-format on\r\n
for instance, in Notepad++, Ctrl+Shift+F - "Find in Files - "Replace in Files".
To date (up to v11) there is no way to disable pointer alignment. You can either set the style, or derive the style (clang-format
will analyze a file for the most common alignment of &
and *
and will use it).
推荐阅读
- javascript - Firebase - 获取最后一个子 Javascript 的第一个值
- java - javaFx应用程序需要圆形滑块
- python - Flask Caching 文件系统缓存是否跨进程共享?
- python - 在xml,Python中使用if条件嵌套for循环
- javascript - 标准输出中的NodeJS child_process ansi
- node.js - 通过在猫鼬中不使用填充进行分组
- angular - Angular/RxJS - 延迟流直到前一个流完成
- c++ - 设置 glutBitmapCharacter() 的颜色?
- r - 使用变量名向量在 left_join 之后合并重复的变量
- file - 支持内嵌注释的文本文件类型