Indent (int newChildIndex) { final IElementType parentType = myNode.getElementType(); final ASTNode afterNode = getAfterNode(newChildIndex); final ASTNode lastChild = getLastNonSpaceChild(myNode, false); if (lastChild != null && lastChild.getElementType() == PyElementTypes.STATEMENT_LIST && mySubBlocks.size() >= newChildIndex) { if (afterNode == null) { return Indent.getNoneIndent(); } // handle pressing Enter after colon and before first statement in // existing statement list if (afterNode.getElementType() == PyElementTypes.STATEMENT_LIST || afterNode.getElementType() == PyTokenTypes.COLON) { return Indent.getNormalIndent(); } // handle pressing Enter after colon when there is nothing in the // statement list final ASTNode lastFirstChild = lastChild.getFirstChildNode(); if (lastFirstChild != null && lastFirstChild == lastChild.getLastChildNode() && lastFirstChild.getPsi() instanceof PsiErrorElement) { return Indent.getNormalIndent(); } } if (parentType == PyElementTypes.MATCH_STATEMENT && afterNode != null && afterNode.getElementType() == PyTokenTypes.COLON) { return Indent.getNormalIndent(); } if (afterNode != null && afterNode.getElementType() == PyElementTypes.KEY_VALUE_EXPRESSION) { final PyKeyValueExpression keyValue = (PyKeyValueExpression)afterNode.getPsi(); if (keyValue != null && keyValue.getValue() == null) { // incomplete return Indent.getContinuationIndent(); } } // constructs that imply indent for their children final PyCodeStyleSettings settings = myContext.getPySettings(); if ((parentType == PyElementTypes.PARAMETER_LIST && settings.USE_CONTINUATION_INDENT_FOR_PARAMETERS) || (parentType == PyElementTypes.ARGUMENT_LIST && settings.USE_CONTINUATION_INDENT_FOR_ARGUMENTS)) { return Indent.getContinuationIndent(); } if (ourCollectionLiteralTypes.contains(parentType) || parentType == PyElementTypes.TUPLE_EXPRESSION) { return settings.USE_CONTINUATION_INDENT_FOR_COLLECTION_AND_COMPREHENSIONS ? Indent.getContinuationIndent() : Indent.getNormalIndent(); } else if (ourListElementTypes.contains(parentType) || myNode.getPsi() instanceof PyStatementPart) { return Indent.getNormalIndent(); } if (afterNode != null) { ASTNode wsAfter = afterNode.getTreeNext(); while (wsAfter != null && wsAfter.getElementType() == TokenType.WHITE_SPACE) { if (wsAfter.getText().indexOf('\\') >= 0) { return Indent.getNormalIndent(); } wsAfter = wsAfter.getTreeNext(); } } return Indent.getNoneIndent(); }