Index: docs/ClangFormatStyleOptions.rst =================================================================== --- docs/ClangFormatStyleOptions.rst +++ docs/ClangFormatStyleOptions.rst @@ -150,6 +150,9 @@ **AccessModifierOffset** (``int``) The extra indent or outdent of access modifiers, e.g. ``public:``. +**AdditionalIndentClassBlock** (``bool``) + If ``true``, adds an additional level of indention for class blocks. + **AlignAfterOpenBracket** (``BracketAlignmentStyle``) If ``true``, horizontally aligns arguments after an open bracket. Index: lib/Format/Format.cpp =================================================================== --- lib/Format/Format.cpp +++ lib/Format/Format.cpp @@ -313,6 +313,7 @@ } IO.mapOptional("AccessModifierOffset", Style.AccessModifierOffset); + IO.mapOptional("AdditionalIndentClassBlock", Style.AdditionalIndentClassBlock); IO.mapOptional("AlignAfterOpenBracket", Style.AlignAfterOpenBracket); IO.mapOptional("AlignConsecutiveAssignments", Style.AlignConsecutiveAssignments); @@ -621,6 +622,7 @@ FormatStyle LLVMStyle; LLVMStyle.Language = FormatStyle::LK_Cpp; LLVMStyle.AccessModifierOffset = -2; + LLVMStyle.AdditionalIndentClassBlock = false; LLVMStyle.AlignEscapedNewlines = FormatStyle::ENAS_Right; LLVMStyle.AlignAfterOpenBracket = FormatStyle::BAS_Align; LLVMStyle.AlignOperands = true; Index: lib/Format/UnwrappedLineParser.h =================================================================== --- lib/Format/UnwrappedLineParser.h +++ lib/Format/UnwrappedLineParser.h @@ -88,7 +88,7 @@ void parseFile(); void parseLevel(bool HasOpeningBrace); void parseBlock(bool MustBeDeclaration, bool AddLevel = true, - bool MunchSemi = true); + bool MunchSemi = true, bool ClassBlock = false); void parseChildBlock(); void parsePPDirective(); void parsePPDefine(); Index: lib/Format/UnwrappedLineParser.cpp =================================================================== --- lib/Format/UnwrappedLineParser.cpp +++ lib/Format/UnwrappedLineParser.cpp @@ -520,7 +520,7 @@ } void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, bool AddLevel, - bool MunchSemi) { + bool MunchSemi, bool ClassBlock) { assert(FormatTok->isOneOf(tok::l_brace, TT_MacroBlockBegin) && "'{' or macro block token expected"); const bool MacroBlock = FormatTok->is(TT_MacroBlockBegin); @@ -546,6 +546,9 @@ MustBeDeclaration); if (AddLevel) ++Line->Level; + + if (Style.AdditionalIndentClassBlock && ClassBlock) + ++Line->Level; parseLevel(/*HasOpeningBrace=*/true); if (eof()) @@ -2126,7 +2129,7 @@ addUnwrappedLine(); parseBlock(/*MustBeDeclaration=*/true, /*AddLevel=*/true, - /*MunchSemi=*/false); + /*MunchSemi=*/false, /*ClassBlock*/ true); } } // There is no addUnwrappedLine() here so that we fall through to parsing a Index: unittests/Format/CMakeLists.txt =================================================================== --- unittests/Format/CMakeLists.txt +++ unittests/Format/CMakeLists.txt @@ -5,6 +5,7 @@ add_clang_unittest(FormatTests CleanupTest.cpp FormatTest.cpp + FormatTestClassIndent.cpp FormatTestComments.cpp FormatTestJS.cpp FormatTestJava.cpp