From c8020d8c1c4329dd8468a7d1486a67ce68b8b30c Mon Sep 17 00:00:00 2001 From: Peter Vingelmann Date: Mon, 19 Sep 2016 23:03:41 +0200 Subject: [PATCH] Use symmetric layout for the closing bracket in template argument lists --- src/ASBeautifier.cpp | 47 +++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/src/ASBeautifier.cpp b/src/ASBeautifier.cpp index 6793e74..ea84ee8 100644 --- a/src/ASBeautifier.cpp +++ b/src/ASBeautifier.cpp @@ -2127,21 +2127,6 @@ void ASBeautifier::computePreliminaryIndentation() } } - if (isInTemplate || isInTemplateInstantiation) - { - // Use symmetrical layout for closing brace in template argument list: - // - // template - // < - // class Argument - // > - if (lineFirstChar == '>' && !lineStartsInComment) - { - if (!inStatementIndentStack->empty()) - spaceIndentCount -= inStatementIndentStack->back(); - } - } - if (isInClassInitializer || isInEnumTypeID) { indentCount += classInitializerIndents; @@ -2611,6 +2596,20 @@ void ASBeautifier::parseCurrentLine(const string& line) else if (ch == '>') { popLastInStatementIndent(); + // Immediately reduce spaceIndentCount if the line starts + // with '>' to get a symmetrical layout: + // + // template + // < + // class Argument + // > + if (lineFirstChar == '>' && !lineStartsInComment) + { + if (!inStatementIndentStack->empty()) + spaceIndentCount = inStatementIndentStack->back(); + else + spaceIndentCount = 0; + } if (--templateDepth <= 0) { ch = ';'; @@ -2635,7 +2634,9 @@ void ASBeautifier::parseCurrentLine(const string& line) if (isInTemplateInstantiation) { inStatementIndentStackSizeStack->push_back(inStatementIndentStack->size()); - registerInStatementIndent(line, i, spaceIndentCount, tabIncrementIn, 0, true); + // Always add one indent, i.e. do not try to align + registerInStatementIndent(line, line.length() - 1, + spaceIndentCount, tabIncrementIn, 0, true); isInStatement = true; } } @@ -2645,6 +2646,20 @@ void ASBeautifier::parseCurrentLine(const string& line) && !inStatementIndentStackSizeStack->empty()) { popLastInStatementIndent(); + // Immediately reduce spaceIndentCount if the line starts + // with '>' to get a symmetrical layout: + // + // template_function< + // Argument1, + // Argument2 + // > + if (lineFirstChar == '>' && !lineStartsInComment) + { + if (!inStatementIndentStack->empty()) + spaceIndentCount = inStatementIndentStack->back(); + else + spaceIndentCount = 0; + } } if (--templateDepth <= 0) {