Index: docs/ClangFormatStyleOptions.rst =================================================================== --- docs/ClangFormatStyleOptions.rst +++ docs/ClangFormatStyleOptions.rst @@ -618,6 +618,9 @@ **ObjCBlockIndentWidth** (``unsigned``) The number of characters to use for indentation of ObjC blocks. +**ObjCBlockResetsIndent** (``bool``) + Whether ObjC blocks resets the indent to that of its owner block. + **ObjCSpaceAfterProperty** (``bool``) Add a space after ``@property`` in Objective-C, i.e. use ``@property (readonly)`` instead of ``@property(readonly)``. Index: include/clang/Format/Format.h =================================================================== --- include/clang/Format/Format.h +++ include/clang/Format/Format.h @@ -500,6 +500,9 @@ /// \brief The number of characters to use for indentation of ObjC blocks. unsigned ObjCBlockIndentWidth; + /// \brief Whether ObjC blocks resets the indent to that of its owner block. + bool ObjCBlockResetsIndent = false; + /// \brief Add a space after ``@property`` in Objective-C, i.e. use /// ``@property (readonly)`` instead of ``@property(readonly)``. bool ObjCSpaceAfterProperty; Index: lib/Format/ContinuationIndenter.cpp =================================================================== --- lib/Format/ContinuationIndenter.cpp +++ lib/Format/ContinuationIndenter.cpp @@ -1037,6 +1037,13 @@ } void ContinuationIndenter::moveStateToNewBlock(LineState &State) { + // For ObjC blocks, reset the indent to that of the owner block if the style + // tells us to do so. + if (Style.ObjCBlockResetsIndent && State.NextToken->is(TT_ObjCBlockLBrace)) { + State.Stack.back().Indent = State.Stack.front().Indent; + State.Stack.back().NestedBlockIndent = + State.Stack.front().NestedBlockIndent; + } unsigned NestedBlockIndent = State.Stack.back().NestedBlockIndent; // ObjC block sometimes follow special indentation rules. unsigned NewIndent = Index: lib/Format/Format.cpp =================================================================== --- lib/Format/Format.cpp +++ lib/Format/Format.cpp @@ -322,6 +322,7 @@ IO.mapOptional("MaxEmptyLinesToKeep", Style.MaxEmptyLinesToKeep); IO.mapOptional("NamespaceIndentation", Style.NamespaceIndentation); IO.mapOptional("ObjCBlockIndentWidth", Style.ObjCBlockIndentWidth); + IO.mapOptional("ObjCBlockResetsIndent", Style.ObjCBlockResetsIndent); IO.mapOptional("ObjCSpaceAfterProperty", Style.ObjCSpaceAfterProperty); IO.mapOptional("ObjCSpaceBeforeProtocolList", Style.ObjCSpaceBeforeProtocolList);