diff --git a/python/src/com/jetbrains/python/formatter/PyBlock.java b/python/src/com/jetbrains/python/formatter/PyBlock.java index f4986f53f5a1..0e43d2eefa0d 100644 --- a/python/src/com/jetbrains/python/formatter/PyBlock.java +++ b/python/src/com/jetbrains/python/formatter/PyBlock.java @@ -184,7 +184,12 @@ public class PyBlock implements ASTBlock { else if (parentType == PyElementTypes.FROM_IMPORT_STATEMENT) { if ((childType == PyElementTypes.IMPORT_ELEMENT || childType == PyTokenTypes.RPAR) && _node.findChildByType(PyTokenTypes.LPAR) != null) { - childAlignment = getAlignmentForChildren(); + if (myContext.getPySettings().ALIGN_MULTILINE_IMPORTS) { + childAlignment = getAlignmentForChildren(); + } + else { + childIndent = Indent.getNormalIndent(); + } } } else if (parentType == PyElementTypes.KEY_VALUE_EXPRESSION) { diff --git a/python/src/com/jetbrains/python/formatter/PyCodeStyleSettings.java b/python/src/com/jetbrains/python/formatter/PyCodeStyleSettings.java index 331fa49d832e..7bacbd60e451 100644 --- a/python/src/com/jetbrains/python/formatter/PyCodeStyleSettings.java +++ b/python/src/com/jetbrains/python/formatter/PyCodeStyleSettings.java @@ -17,6 +17,7 @@ public class PyCodeStyleSettings extends CustomCodeStyleSettings { public int BLANK_LINES_AROUND_TOP_LEVEL_CLASSES_FUNCTIONS = 2; public boolean ALIGN_COLLECTIONS_AND_COMPREHENSIONS = true; + public boolean ALIGN_MULTILINE_IMPORTS = true; public PyCodeStyleSettings(CodeStyleSettings container) { super("Python", container); diff --git a/python/src/com/jetbrains/python/formatter/PyLanguageCodeStyleSettingsProvider.java b/python/src/com/jetbrains/python/formatter/PyLanguageCodeStyleSettingsProvider.java index ff82545859c1..428d9f65ac80 100644 --- a/python/src/com/jetbrains/python/formatter/PyLanguageCodeStyleSettingsProvider.java +++ b/python/src/com/jetbrains/python/formatter/PyLanguageCodeStyleSettingsProvider.java @@ -75,6 +75,8 @@ public class PyLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSettin "ALIGN_MULTILINE_PARAMETERS_IN_CALLS"); consumer.showCustomOption(PyCodeStyleSettings.class, "ALIGN_COLLECTIONS_AND_COMPREHENSIONS", "Align when multiline", "Collections and Comprehensions"); + consumer.showCustomOption(PyCodeStyleSettings.class, "ALIGN_MULTILINE_IMPORTS", "Align when multiline", + "Import Statements"); } } @@ -112,7 +114,9 @@ public class PyLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSettin " def foo(self):\n" + " pass"; @SuppressWarnings("FieldCanBeLocal") - private static String WRAP_SETTINGS_PREVIEW = "long_expression = component_one + component_two + component_three + component_four + component_five + component_six\n\n" + + private static String WRAP_SETTINGS_PREVIEW = "from foo import (bar,\n" + + " baz)\n\n" + + "long_expression = component_one + component_two + component_three + component_four + component_five + component_six\n\n" + "def xyzzy(long_parameter_1,\n" + "long_parameter_2):\n" + " pass\n\n" +