From 3dbc0cd0c08b2beea3f909655d7aa0c9091b2cd7 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 2 Oct 2012 15:48:18 +0200 Subject: [PATCH] more keywords which allow only 1 space around them --- .../python/formatter/PythonFormattingModelBuilder.java | 5 ++++- python/testData/formatter/spaceAroundKeywords.py | 1 + python/testData/formatter/spaceAroundKeywords_after.py | 1 + python/testSrc/com/jetbrains/python/PyFormatterTest.java | 4 ++++ 4 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 python/testData/formatter/spaceAroundKeywords.py create mode 100644 python/testData/formatter/spaceAroundKeywords_after.py diff --git a/python/src/com/jetbrains/python/formatter/PythonFormattingModelBuilder.java b/python/src/com/jetbrains/python/formatter/PythonFormattingModelBuilder.java index da86dc41a54b..0ac16716b9c7 100644 --- a/python/src/com/jetbrains/python/formatter/PythonFormattingModelBuilder.java +++ b/python/src/com/jetbrains/python/formatter/PythonFormattingModelBuilder.java @@ -105,9 +105,12 @@ public class PythonFormattingModelBuilder implements FormattingModelBuilderEx, C .around(BITWISE_OPERATIONS).spaceIf(commonSettings.SPACE_AROUND_BITWISE_OPERATORS) .around(EQUALITY_OPERATIONS).spaceIf(commonSettings.SPACE_AROUND_EQUALITY_OPERATORS) .around(RELATIONAL_OPERATIONS).spaceIf(commonSettings.SPACE_AROUND_RELATIONAL_OPERATORS) - .around(IN_KEYWORD).spaces(1); + .around(SINGLE_SPACE_KEYWORDS).spaces(1); } + // should be all keywords? + private static final TokenSet SINGLE_SPACE_KEYWORDS = TokenSet.create(IN_KEYWORD, AND_KEYWORD, OR_KEYWORD, IS_KEYWORD); + private static TokenSet allButLambda() { final PythonLanguage pythonLanguage = PythonLanguage.getInstance(); return TokenSet.create(IElementType.enumerate(new IElementType.Predicate() { diff --git a/python/testData/formatter/spaceAroundKeywords.py b/python/testData/formatter/spaceAroundKeywords.py new file mode 100644 index 000000000000..ef0d0922136f --- /dev/null +++ b/python/testData/formatter/spaceAroundKeywords.py @@ -0,0 +1 @@ +True and False diff --git a/python/testData/formatter/spaceAroundKeywords_after.py b/python/testData/formatter/spaceAroundKeywords_after.py new file mode 100644 index 000000000000..a61962eda0cf --- /dev/null +++ b/python/testData/formatter/spaceAroundKeywords_after.py @@ -0,0 +1 @@ +True and False diff --git a/python/testSrc/com/jetbrains/python/PyFormatterTest.java b/python/testSrc/com/jetbrains/python/PyFormatterTest.java index 0e9e2e626c45..91cae9e3a812 100644 --- a/python/testSrc/com/jetbrains/python/PyFormatterTest.java +++ b/python/testSrc/com/jetbrains/python/PyFormatterTest.java @@ -183,6 +183,10 @@ public class PyFormatterTest extends PyTestCase { doTest(); } + public void testSpaceAroundKeywords() { + doTest(); + } + public void testPsiFormatting() { // IDEA-69724 String initial = "def method_name(\n" +