这里有问题的代码片段:
int open_server_socket(Config config) {
if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &optVal,
sizeof(optVal)) < 0) { // THIS LINE
socket_error();
}
}
我需要将指示的行缩进 12 个空格而不是 16 个空格,所以它看起来像这样:
int open_server_socket(Config config) {
if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &optVal,
sizeof(optVal)) < 0) { // THIS LINE
socket_error();
}
}
我的
.clang-format
看起来像这样:
BasedOnStyle: LLVM
IndentWidth: 4
EscapedNewlineAlignmentStyle: Left
AlignAfterOpenBracket: DontAlign
AlignOperands: DontAlign
ContinuationIndentWidth: 8
ColumnLimit: 79
AllowShortIfStatementsOnASingleLine: Never
AllowShortFunctionsOnASingleLine: None
OperandAlignmentStyle: DontAlign
获得此特定配置的最佳尝试是使用
AlignAfterOpenBracket: DontAlign
和 ContinuationIndentWidth: 8
的组合,但在这种情况下,这似乎不起作用。
谢谢!
这完成了工作:
ContinuationIndentWidth: 4
ContinuationIndentWidth
是相对于该行默认缩进的缩进。您需要额外 4 个字符(而不是 8 个)。