<div dir="ltr">It looks like the formatting for my e-mail may have been stripped. If that's the case it should be possible to copy-paste the different lambdas into clang-format with --style='{LambdaBodyIndentation: OuterScope}'.<div><br></div><div>The last lambda of what I'm trying to get to can be found here: <a href="https://pastebin.com/eSGJnubw">https://pastebin.com/eSGJnubw</a><br><div><br class="gmail-Apple-interchange-newline"></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Sep 15, 2021 at 4:22 PM Vitali Lovich <<a href="mailto:vlovich@gmail.com">vlovich@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi, I've observed a few defects in LambdaBodyIndentation. I know I implemented this but I'm also not familiar with the codebase & I've spent some time without any forward progress investigating the issues. If anyone could be so kind as to help me figure out the  problem I'd be very grateful.<div><br></div><div>The issue seems to be related to this logic here in UnwrappedLineFormatter.cpp line ~831</div><div><div style="color:rgb(0,0,0);font-family:"Droid Sans Mono",monospace,monospace,"Droid Sans Fallback";font-size:14px;line-height:19px;white-space:pre-wrap"><div>      <span style="color:rgb(0,0,255)">if</span> (Style.LambdaBodyIndentation == FormatStyle::LBI_OuterScope &&</div><div>          P.NestedBlockIndent == P.LastSpace) {</div><div></div></div></div><div><br></div><div>This is how the snippet gets formatted if there are return types:</div><div><br></div><div><div style="color:rgb(0,0,0);font-family:"Droid Sans Mono",monospace,monospace,"Droid Sans Fallback";font-size:14px;line-height:19px;white-space:pre-wrap"><div><span style="color:rgb(0,0,255)">return</span> someFunction(</div><div>    []() {</div><div>  someCode();</div><div>  <span style="color:rgb(0,0,255)">return</span> someOtherFunction(</div><div>      []() -><span style="color:rgb(0,0,255)"> </span>{</div><div>        someMoreCode();</div><div>        someMoreCode();</div><div>      },</div><div>      [] -><span style="color:rgb(0,0,255)"> </span>{</div><div>        someErrorHandlingCode();</div><div>        someErrorHandlingCode();</div><div>      });</div><div>    },</div><div>    [] -><span style="color:rgb(0,0,255)"> </span>{</div><div>      someErrorHandlingCode();</div><div>      someErrorHandlingCode();</div><div>    });</div><br></div></div><div>If I elide the return type on the lambdas I get:</div><div><div style="color:rgb(0,0,0);font-family:"Droid Sans Mono",monospace,monospace,"Droid Sans Fallback";font-size:14px;line-height:19px;white-space:pre-wrap"><div><span style="color:rgb(0,0,255)">return</span> someFunction(</div><div>    []() {</div><div>  someCode();</div><div>  <span style="color:rgb(0,0,255)">return</span> someOtherFunction(</div><div>      []() {</div><div>    someMoreCode();</div><div>    someMoreCode();</div><div>      },</div><div>      [] {</div><div>    someErrorHandlingCode();</div><div>    someErrorHandlingCode();</div><div>  });</div><div>    },</div><div>    [] {</div><div>  someErrorHandlingCode();</div><div>  someErrorHandlingCode();</div><div>});</div></div><div style="color:rgb(0,0,0);font-family:"Droid Sans Mono",monospace,monospace,"Droid Sans Fallback";font-size:14px;line-height:19px;white-space:pre-wrap"><br></div>This is closer but still not quite what I want. The desired formatting should look like:</div><div><div style="line-height:19px"><div style="color:rgb(0,0,0);font-family:"Droid Sans Mono",monospace,monospace,"Droid Sans Fallback";font-size:14px;white-space:pre-wrap"><span style="color:rgb(0,0,255)">return</span> someFunction(</div><div style="color:rgb(0,0,0);font-family:"Droid Sans Mono",monospace,monospace,"Droid Sans Fallback";font-size:14px;white-space:pre-wrap">    []() {</div><div style="color:rgb(0,0,0);font-family:"Droid Sans Mono",monospace,monospace,"Droid Sans Fallback";font-size:14px;white-space:pre-wrap">  someCode();</div><div style="color:rgb(0,0,0);font-family:"Droid Sans Mono",monospace,monospace,"Droid Sans Fallback";font-size:14px;white-space:pre-wrap">  <span style="color:rgb(0,0,255)">return</span> someOtherFunction(</div><div style="color:rgb(0,0,0);font-family:"Droid Sans Mono",monospace,monospace,"Droid Sans Fallback";font-size:14px;white-space:pre-wrap">      []() {</div><div style="color:rgb(0,0,0);font-family:"Droid Sans Mono",monospace,monospace,"Droid Sans Fallback";font-size:14px;white-space:pre-wrap">    someMoreCode();</div><div style="color:rgb(0,0,0);font-family:"Droid Sans Mono",monospace,monospace,"Droid Sans Fallback";font-size:14px;white-space:pre-wrap">    someMoreCode();</div><div style="color:rgb(0,0,0);font-family:"Droid Sans Mono",monospace,monospace,"Droid Sans Fallback";font-size:14px;white-space:pre-wrap">  },</div><div style="color:rgb(0,0,0);font-family:"Droid Sans Mono",monospace,monospace,"Droid Sans Fallback";font-size:14px;white-space:pre-wrap">      [] {</div><div style="color:rgb(0,0,0);font-family:"Droid Sans Mono",monospace,monospace,"Droid Sans Fallback";font-size:14px;white-space:pre-wrap">    someErrorHandlingCode();</div><div style="color:rgb(0,0,0);font-family:"Droid Sans Mono",monospace,monospace,"Droid Sans Fallback";font-size:14px;white-space:pre-wrap">    someErrorHandlingCode();</div><div style="color:rgb(0,0,0);font-family:"Droid Sans Mono",monospace,monospace,"Droid Sans Fallback";font-size:14px;white-space:pre-wrap">  });</div><div style="color:rgb(0,0,0);font-family:"Droid Sans Mono",monospace,monospace,"Droid Sans Fallback";font-size:14px;white-space:pre-wrap">},</div><div style="color:rgb(0,0,0);font-family:"Droid Sans Mono",monospace,monospace,"Droid Sans Fallback";font-size:14px;white-space:pre-wrap">    [] {</div><div style="color:rgb(0,0,0);font-family:"Droid Sans Mono",monospace,monospace,"Droid Sans Fallback";font-size:14px;white-space:pre-wrap">  someErrorHandlingCode();</div><div style="color:rgb(0,0,0);font-family:"Droid Sans Mono",monospace,monospace,"Droid Sans Fallback";font-size:14px;white-space:pre-wrap">  someErrorHandlingCode();</div><div style="color:rgb(0,0,0);font-family:"Droid Sans Mono",monospace,monospace,"Droid Sans Fallback";font-size:14px;white-space:pre-wrap">});</div><div style="color:rgb(0,0,0);font-family:"Droid Sans Mono",monospace,monospace,"Droid Sans Fallback";font-size:14px;white-space:pre-wrap"><br></div><div style="color:rgb(0,0,0);font-family:"Droid Sans Mono",monospace,monospace,"Droid Sans Fallback";font-size:14px;white-space:pre-wrap"><span style="color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;font-size:small;white-space:normal">Actually I'd prefer the lambda be inline with the preceding lines if line width permits but I'm not sure why it seems to always be put on a new line:<br></span><div style="line-height:19px"><div><span style="color:rgb(0,0,255)">return</span> someFunction([]() {</div><div>  someCode();</div><div>  <span style="color:rgb(0,0,255)">return</span> someOtherFunction(</div><div>      []() {</div><div>    someMoreCode();</div><div>    someMoreCode();</div><div>  }, [] {</div><div>    someErrorHandlingCode();</div><div>    someErrorHandlingCode();</div><div>  });</div><div>}, [] {</div><div>  someErrorHandlingCode();</div><div>  someErrorHandlingCode();</div><div>});</div><br></div><span style="color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;font-size:small;white-space:normal">Probably unrelated to my changes though as stock clang format appears to put it on a newline & I can't figure out how. In theory setting </span><span style="font-family:Arial,Helvetica,sans-serif;font-size:small;color:rgb(34,34,34)">BeforeLambdaBody: false should do it according to the docs but it doesn't seem to</span><span style="color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;font-size:small;white-space:normal">.</span></div><div style="color:rgb(0,0,0);font-family:"Droid Sans Mono",monospace,monospace,"Droid Sans Fallback";font-size:14px;white-space:pre-wrap"><span style="color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;font-size:small;white-space:normal"><br></span></div><div>Thanks for any tips/pointers,</div><div>Vitali</div></div></div></div>
</blockquote></div>