<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">On 13 Dec 2015, at 20:15, Daniel Jasper <<a href="mailto:djasper@google.com" class="">djasper@google.com</a>> wrote:</div><div class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><br class=""><div class="gmail_extra"><br class=""><div class="gmail_quote">On Sun, Dec 13, 2015 at 6:53 PM, Yavuz Nuzumlalı <span dir="ltr" class=""><<a href="mailto:manuyavuz@gmail.com" target="_blank" class="">manuyavuz@gmail.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class=""><div class="h5"><div style="white-space:pre-wrap" class=""></div><div dir="auto" style="word-wrap:break-word" class="">Thanks for the response Daniel,<div class=""><br class=""></div><div class="">Could you guide me on where can I look inside clang-format implementation to see how clang-format currently handles lambdas in other languages, so that I may try to implement the same functionality for Objective-C case?</div></div></div></div></blockquote><div class=""><br class=""></div><div class="">Not really, it is all in ContinuationIndenter.cpp. However, this is among the most complex code of clang-format and giving you details on how to do this probably would take me longer than looking at this myself. If you still want to try and take a look, feel free. I am happy to answer any specific questions you might have.</div><div class=""> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class=""><div class="h5"><div dir="auto" style="word-wrap:break-word" class=""><div class=""><br class=""></div><div class="">Besides that, I have one more question, which is somewhat related to topic.</div><div class=""><br class=""></div><div class="">When I try to use clang-format to format the following simple code:<br class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">- (void)asdf {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="white-space:pre-wrap" class=""> </span>[UIView animateasdfasdf:0 animations:^{ }];</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="white-space:pre-wrap" class="">       </span>[UIView animations:^{ } done:YES];</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="white-space:pre-wrap" class="">        </span>[UIView animations:^{ } completion:^{ }];</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="white-space:pre-wrap" class=""> </span>[UIView testasdfasdfsd:YES animations:^{ } completion:^{ }];</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="white-space:pre-wrap" class="">      </span>[UIView animations:^{ } tessd:YES completion:^{ }];</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">}</div></div><div class=""><br class=""></div><div class="">Output is the following:<br class=""><br class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><div style="margin:0px;line-height:normal" class="">- (void)asdf {</div><div style="margin:0px;line-height:normal" class="">  [UIView animateasdfasdf:0</div><div style="margin:0px;line-height:normal" class="">               animations:^{</div><div style="margin:0px;line-height:normal" class="">               }];</div><div style="margin:0px;line-height:normal" class="">  [UIView animations:^{</div><div style="margin:0px;line-height:normal" class="">  }</div><div style="margin:0px;line-height:normal" class="">                done:YES];</div><div style="margin:0px;line-height:normal" class="">  [UIView animations:^{</div><div style="margin:0px;line-height:normal" class="">  }</div><div style="margin:0px;line-height:normal" class="">      completion:^{</div><div style="margin:0px;line-height:normal" class="">      }];</div><div style="margin:0px;line-height:normal" class="">  [UIView testasdfasdfsd:YES</div><div style="margin:0px;line-height:normal" class="">      animations:^{</div><div style="margin:0px;line-height:normal" class="">      }</div><div style="margin:0px;line-height:normal" class="">      completion:^{</div><div style="margin:0px;line-height:normal" class="">      }];</div><div style="margin:0px;line-height:normal" class="">  [UIView animations:^{</div><div style="margin:0px;line-height:normal" class="">  }</div><div style="margin:0px;line-height:normal" class="">      tessd:YES</div><div style="margin:0px;line-height:normal" class="">      completion:^{</div><div style="margin:0px;line-height:normal" class="">      }];</div><div style="margin:0px;line-height:normal" class="">}</div></div><span class=""><div class=""><span class=""><br class=""></span></div></span></div></div></div></div><div dir="auto" style="word-wrap:break-word" class=""><div class=""><div class="h5"><div class=""><span class="">I think clang-format somehow decides to not use colon alignment but align using `</span>ContinuationIndentWidth` where there are more than one block parameters.</div><div class=""><span class="">Is this an intended behavior? Seems like a bug to me.</span></div></div></div></div></blockquote><div class=""><br class=""></div><div class="">It is intentional. Column alignment with more than one internal block doesn't really work. And this is also explicitly written in Google's style guide: <a href="https://google.github.io/styleguide/objcguide.xml#Blocks" class="">https://google.github.io/styleguide/objcguide.xml#Blocks</a></div><div class=""><br class=""></div><div class="">Independent of that some of you examples look like there are still other bugs in there.</div><div class=""><br class=""></div></div></div></div></div></blockquote>I carefully read the google style guide, and behavior about multiple inline blocks seems reasonable now. <div class="">However, I still feel it's not fully consistent because of the third method call example above. </div><div class="">I think that case should have something like the following format in order to be consistent across the code:</div><div class=""><br class=""></div><div class=""><div style="font-family: Menlo; font-size: 11px; margin: 0px; line-height: normal;" class="">[UIView </div><div style="font-family: Menlo; font-size: 11px; margin: 0px; line-height: normal;" class="">    animations:^{</div><div style="font-family: Menlo; font-size: 11px; margin: 0px; line-height: normal;" class="">    }</div><div style="font-family: Menlo; font-size: 11px; margin: 0px; line-height: normal;" class="">    completion:^{</div><div style="font-family: Menlo; font-size: 11px; margin: 0px; line-height: normal;" class="">    }];</div></div><div class=""><div class=""><div class=""><div class=""><br class=""></div><div class="">Also there is another case in which formatting messes completely:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">  [UIView animateWithDuration:123 delay:123 usingSpringWithDamping:123 initialSpringVelocity:123 options:123 animations:^{ } completion:^(BOOL finished){ }];</div></div><div class=""><br class=""></div><div class="">becomes this:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">  [UIView animateWithDuration:123</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">      delay:123</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">      usingSpringWithDamping:123</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">      initialSpringVelocity:123</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">      options:123</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">      animations:^{</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">      }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">      completion:^(BOOL finished){</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">      }];</div></div><div class=""><br class=""></div><div class="">Is this (cancelling colon alignment also for non-block parameters ) also intentional? </div><div class="">If so, I understand that clang-format will apply standard `ContinuationIndentWidth` value whenever a method call includes more than one inline blocks.</div><div class=""><br class=""></div><div class="">I question this scenario too much because the above code is a frequent code block to animate views on screen, and having a consistent behavior is important in order to use clang-format’s automatic formatting without any hesitancy </div><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="auto" style="word-wrap:break-word" class=""><div class=""><span class="">PS : I'm using the <span class=""></span>default LLVM configuration for the above case.</span></div></div><span class="im"><div dir="auto" style="word-wrap:break-word" class=""><div class=""><span class=""><blockquote type="cite" class="">On 13 Dec 2015, at 16:42, Daniel Jasper <<a class="">djasper@google.com</a>> wrote:<br class=""><br class=""></blockquote></span></div></div></span><div class=""><div class="h5"><div dir="auto" style="word-wrap:break-word" class=""><div class=""><span class=""><blockquote type="cite" class="">Nope, this behavior isn't currently implemented. I agree that it might make sense, as it is similar to how clang-format treats lambdas at the end of several other parameters.<br class=""><br class="">On Fri, Dec 11, 2015 at 4:08 PM, Yavuz Nuzumlalı <<a class="">cfe-dev@lists.llvm.org</a>> wrote:<br class="">Hi everyone,<br class=""><br class="">I'm experiencing a problem with clang-format for my code.<br class=""><br class="">I'm using ColumnLimit as 120. When I write some code like this:<br class=""><br class="">[self testMethod:15 withBlock:^{<br class=""><span style="white-space:pre-wrap" class="">     </span>NSLog(@"asdfasdf");<br class=""><span style="white-space:pre-wrap" class="">   </span>NSLog(@"asdfasdf");<br class=""><span style="white-space:pre-wrap" class="">   </span>NSLog(@"asdfasdf");<br class=""><span style="white-space:pre-wrap" class="">   </span>NSLog(@"asdfasdf");<br class="">}];<br class=""><br class="">This code would be converted to this by clang-format:<br class=""><br class="">[self testMethod:15<br class="">       withBlock:^{<br class=""><span style="white-space:pre-wrap" class="">   </span>       NSLog(@"asdfasdf");<br class=""><span style="white-space:pre-wrap" class="">        </span>       NSLog(@"asdfasdf");<br class=""><span style="white-space:pre-wrap" class="">        </span>       NSLog(@"asdfasdf");<br class=""><span style="white-space:pre-wrap" class="">        </span>       NSLog(@"asdfasdf");<br class=""><span style="white-space:pre-wrap" class="">        </span>   }];<br class=""><br class="">That seems wrong to me because the method call before block variable actually fits in width of 120. I guess this is because clang-format behaves above code as a single method call and assumes it as one line. But I really want to not split the method like this because it feels weird.<br class=""><br class="">Is there a way to accomplish this with current system?<br class=""><br class="">I put my configuration file as an attachment.<br class=""><br class="">Best<br class=""><br class=""><br class="">_______________________________________________<br class="">cfe-dev mailing list<br class=""><a class="">cfe-dev@lists.llvm.org</a><br class=""><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br class=""><br class=""><br class=""></blockquote></span></div></div>
</div></div></blockquote></div><br class=""></div></div>
</div></blockquote></div></div></div></div></body></html>