From: Daniel Jasper Date: Wed, 23 Jan 2013 20:41:06 +0000 (+0000) Subject: Add extra indent for nested calls inside if's. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e438bac04165937036e41c321fa0d5567d1e520c;p=clang Add extra indent for nested calls inside if's. Before: if (aaaaaaaaaa( aaaaaaaaaa)) {} After: if (aaaaaaaaaa( aaaaaaaaaa)) {} git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173290 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index eb18be82b3..b16eb15318 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -604,10 +604,14 @@ private: Current.isNot(tok::comment)) State.Stack[ParenLevel].HasMultiParameterLine = true; - // Top-level spaces are exempt as that mostly leads to better results. State.Column += Spaces; - if (Spaces > 0 && ParenLevel != 0) - State.Stack[ParenLevel].LastSpace = State.Column; + if (Current.is(tok::l_paren) && Previous.is(tok::kw_if)) + // Treat the condition inside an if as if it was a second function + // parameter, i.e. let nested calls have an indent of 4. + State.Stack.back().LastSpace = State.Column + 1; // 1 is length of "(". + else if (Spaces > 0 && ParenLevel != 0) + // Top-level spaces are exempt as that mostly leads to better results. + State.Stack.back().LastSpace = State.Column; } // If we break after an {, we should also break before the corresponding }. diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index a588dbabec..d8a6ddcb68 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -928,6 +928,9 @@ TEST_F(FormatTest, BreaksDesireably) { verifyFormat("if (aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaa) ||\n" " aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaa) ||\n" " aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaa)) {\n}"); + verifyFormat("if (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n" + " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)) {\n" + "}"); verifyFormat( "aaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"