要在clang-format中保留宏行连续性(''),您可以使用ContinuationIndentWidth
选项。这个选项定义了续行的缩进级别。
例如,考虑以下代码示例:
#define MACRO_WITH_CONTINUATION \
do { \
// code here \
} while (condition);
默认情况下,clang-format会将续行缩进与第一行的宏名称对齐。如果要保留连续行缩进,您可以将ContinuationIndentWidth
设置为0。
在.clang-format
文件中,添加以下行:
ContinuationIndentWidth: 0
然后运行clang-format
,您将看到续行保持与第一行的缩进级别相同:
#define MACRO_WITH_CONTINUATION \
do { \
// code here \
} while (condition);
这样,宏定义中的续行将保持与第一行的缩进级别一致。