This is an archive of the discontinued LLVM Phabricator instance.

[OBSOLETE] Add a new clang-format style option ObjCBlockResetsIndent.
AbandonedPublic

Authored by yixiang on Dec 2 2016, 11:54 PM.

Details

Reviewers
djasper
Summary

Add a new clang-format style option ObjCBlockResetsIndent of type bool. It defaults to false.
When true, ObjC blocks resets indentation to that of its owner block.
The resetting behavior is often desirable, as it leaves more columns for the content of the ObjC block.

E.g. for an unformatted file test.m like this:

- (void)test {
[self callAVeryVeryVeryVeryVeryVeryLongAsyncMethodWith:@"Some param"
completionHandler:^() {
[self callAnotherLongMethodHereWith:@"param"];
}];
}

The formatted result with ObjCBlockResetsIndent=false (or omitted) is this:

// clang-format -style='{BasedOnStyle: Google, ObjCBlockResetsIndent: false}' test.m
// OR
// clang-format -style='{BasedOnStyle: Google}' test.m
- (void)test {
  [self callAVeryVeryVeryVeryVeryVeryLongAsyncMethodWith:@"Some param"
                                       completionHandler:^() {
                                         [self callAnotherLongMethodHereWith:
                                                   @"param"];
                                       }];
}

The formatted result with ObjCBlockResetsIndent=true is this:

// clang-format -style='{BasedOnStyle: Google, ObjCBlockResetsIndent: true}' test.m
- (void)test {
  [self callAVeryVeryVeryVeryVeryVeryLongAsyncMethodWith:@"Some param"
                                       completionHandler:^() {
    [self callAnotherLongMethodHereWith:@"param"];
  }];
}

Diff Detail

Event Timeline

yixiang updated this revision to Diff 80172.Dec 2 2016, 11:54 PM
yixiang retitled this revision from to Add a new clang-format style option ObjCBlockResetsIndent..
yixiang updated this object.
yixiang updated this revision to Diff 80174.Dec 3 2016, 12:02 AM
yixiang added a reviewer: djasper.
yixiang added a subscriber: cfe-commits.
yixiang updated this object.Dec 3 2016, 12:06 AM
yixiang updated this object.
yixiang updated this object.Dec 3 2016, 12:10 AM
yixiang updated this object.
yixiang updated this object.
yixiang retitled this revision from Add a new clang-format style option ObjCBlockResetsIndent. to [OBSOLETE] Add a new clang-format style option ObjCBlockResetsIndent..Dec 3 2016, 12:40 AM
yixiang abandoned this revision.Dec 3 2016, 12:42 AM

Sending as another diff using arcanist. This one doesn't have proper file context for reviewing.