Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: More autoindentation fixes #4082

Merged
merged 9 commits into from
Feb 19, 2017
7 changes: 6 additions & 1 deletion spyder/widgets/sourcecode/codeeditor.py
Original file line number Diff line number Diff line change
@@ -2009,7 +2009,12 @@ def fix_indent(self, forward=True, comment_or_string=False):

# Hanging indent
# find out if the last one is (, {, or []})
elif re.search(r'[\(|\{|\[]\s*$', prevtext) is not None:
# only if prevtext is long that the hanging indentation
elif (re.search(r'[\(|\{|\[]\s*$', prevtext) is not None and
((self.indent_chars == '\t' and
self.tab_stop_width_spaces * 2 < len(prevtext)) or
(self.indent_chars.startswith(' ') and
len(self.indent_chars) * 2 < len(prevtext)))):
if self.indent_chars == '\t':
correct_indent += self.tab_stop_width_spaces * 2
else:
8 changes: 2 additions & 6 deletions spyder/widgets/sourcecode/tests/test_autoindent.py
Original file line number Diff line number Diff line change
@@ -155,11 +155,7 @@ def test_first_line():
"test_balanced_brackets"),
("a = (a # some comment\n", "a = (a # some comment\n ", "test_inline_comment"),
("len(a) == 1\n", "len(a) == 1\n", "test_balanced_brackets_not_ending_in_bracket"),
# Failing test,
pytest.mark.xfail(
("x = f(\n", "x = f\n ",
"test_short_open_bracket_not_hanging_indent")),
("x = f(\n", "x = f(\n ", "test_short_open_bracket_not_hanging_indent"),
])
def test_indentation_with_spaces(text_input, expected, test_text):
text = get_indent_fix(text_input)
@@ -185,7 +181,7 @@ def test_def_with_unindented_comment():
"test with indented comment"),
("def function():\n\tprint []\n", "def function():\n\tprint []\n\t",
"test brackets alone"),
("\na = {\n", "\na = {\n\t\t", "indentation after opening bracket"),
("\nsome_long_name = {\n", "\nsome_long_name = {\n\t\t", "indentation after opening bracket"),
("def function():\n", "def function():\n\t", "test simple def"),
("open_parenthesis(\n", "open_parenthesis(\n\t\t",
"open parenthesis"),