[PATCH] D27382: Add a new clang-format style option ObjCBlockResetsIndent.
Sean Lu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Dec 3 00:02:52 PST 2016
yixiang added a reviewer: djasper.
yixiang added a subscriber: cfe-commits.
yixiang updated this revision to Diff 80174.
https://reviews.llvm.org/D27382
Files:
docs/ClangFormatStyleOptions.rst
include/clang/Format/Format.h
lib/Format/ContinuationIndenter.cpp
lib/Format/Format.cpp
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);
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: 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: 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)``.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27382.80174.patch
Type: text/x-patch
Size: 2614 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161203/c916f4ae/attachment.bin>
More information about the cfe-commits
mailing list