forked from qt-creator/qt-creator
C++ indenter: Add special case rule for indenting enums.
So you now get enum A { a = 2, b = 3, };
This commit is contained in:
@@ -937,18 +937,23 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
|
||||
|
||||
case class_open:
|
||||
case enum_open:
|
||||
case defun_open:
|
||||
case defun_open: {
|
||||
// undo the continuation indent of the parent
|
||||
*savedIndentDepth = parentState.savedIndentDepth;
|
||||
|
||||
if (firstToken)
|
||||
bool followedByData = (!lastToken && !tokenAt(tokenIndex() + 1).isComment());
|
||||
if (firstToken || followedByData)
|
||||
*savedIndentDepth = tokenPosition;
|
||||
|
||||
*indentDepth = *savedIndentDepth;
|
||||
|
||||
if (m_indentDeclarationMembers)
|
||||
if (followedByData) {
|
||||
*indentDepth = column(tokenAt(tokenIndex() + 1).begin());
|
||||
} else if (m_indentDeclarationMembers) {
|
||||
*indentDepth += m_indentSize;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case substatement_open:
|
||||
if (firstToken) {
|
||||
|
@@ -602,6 +602,10 @@ void tst_CodeFormatter::braceList()
|
||||
<< Line(" a,")
|
||||
<< Line(" b,")
|
||||
<< Line("};")
|
||||
<< Line("enum Foo { a = 2,")
|
||||
<< Line(" a = 3,")
|
||||
<< Line(" b = 4")
|
||||
<< Line(" };")
|
||||
<< Line("void foo () {")
|
||||
<< Line(" int[] a = { foo, bar, ")
|
||||
<< Line(" car };")
|
||||
|
Reference in New Issue
Block a user