如何从条件语句开始而不是从 clang 格式的函数调用开始使用 ContinuationWidth?

问题描述 投票:0回答:1

这里有问题的代码片段:

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
的组合,但在这种情况下,这似乎不起作用。

谢谢!

clang-format
1个回答
0
投票

这完成了工作:

ContinuationIndentWidth: 4

ContinuationIndentWidth
是相对于该行默认缩进的缩进。您需要额外 4 个字符(而不是 8 个)。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.