如何控制链接方法调用的clang格式缩进?

Fra*_*dor 5 c++ indentation clang-format

我希望结果看起来像这样:

auto foo = FooBuilder()
    .WithSomething()
    .WithSomethingElse()
    .Build();
Run Code Online (Sandbox Code Playgroud)

但改为这样clang-format格式化:

auto foo = FooBuilder()
               .WithSomething()
               .WithSomethingElse()
               .Build();
Run Code Online (Sandbox Code Playgroud)

我希望链式调用相对于上一行的开始而不是相对于FooBuilder()调用缩进。我在clang-format控制此的选项中看不到任何东西。设置ContinuationIndentWidth无济于事。有任何想法吗?

Lys*_*sol 2

不幸的是,这似乎是不可能的。我发现完全影响此问题的唯一选项是ContinuationIndentWidth,正如您所说,它不会做您想要的事情。

我个人会做的是使用以下正则表达式来查找已分解的链式方法调用:

\)\s+\.

它将匹配右括号、1 个或多个空白字符(但不是 0)和一个句点。您可能没有太多这样的实例,因此您可以手动修复它们,然后禁用这些行的 clang-format ,以便将来不会再出现它:

// clang-format off

auto friggin_cool_object = SuperCoolBuilder().do_what_i_want()
    .figure()
    .out()
    .the()
    .params()
    .too();

// clang-format on
Run Code Online (Sandbox Code Playgroud)