[PATCH] D52676: [clang-format] tweaked another case of lambda formatting

Oleg Smolsky via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 1 11:31:44 PDT 2018


oleg.smolsky added a comment.

In https://reviews.llvm.org/D52676#1251342, @krasimir wrote:

> Digging a bit further, seems like the behavior you're looking for could be achieved by setting the `AlignAfterOpenBracket` option to `DontAlign` or `AlwaysBreak`:
>
>   % clang-format -style='{BasedOnStyle: google, AlignAfterOpenBracket: AlwaysBreak}' test.cc
>    void f() {
>      something->Method2s(
>          1,
>          [this] {
>            Do1();
>            Do2();
>          },
>          1);
>    }
>    % clang-format -style='{BasedOnStyle: google, AlignAfterOpenBracket: DontAlign}' test.cc
>    void f() {
>      something->Method2s(1,
>          [this] {
>            Do1();
>            Do2();
>          },
>          1);
>    }
>
> Does this work for you?


This is interesting. It obviously does what I want with the lambda, but forces this:

  void f() {
    auto stub = PopulateContextHereAndHereSomethi(GetSomethingHere(),
                                                  GetSomethingElseHere());
  }

into this:

  void f() {
    auto stub = PopulateContextHereAndHereSomethi(
        GetSomethingHere(), GetSomethingElseHere());
  }

The former looks better to me and that's what Emacs does when you press Tab. I think people here at work will balk at this formatting...

> I don't think modifying the behavior as posed in this change based on the existence of multiline lambdas and the value of the `BinPackArguments` option is better than what we have now, especially when `AlignAfterOpenBracket=Align`.

Yeah, I hear you. The patch is intended to work with `AlignAfterOpenBracket=Align` and `BinPackArguments=false` and only tweaks the lambdas' placement.

How about I key the new behavior off a new value of `AlignAfterOpenBracket`, such as `AlignAfterOpenBracket=AlignExceptLambda`?


Repository:
  rC Clang

https://reviews.llvm.org/D52676





More information about the cfe-commits mailing list