Skip to content

Commit

Permalink
Merge pull request #3576 from rlaverde/fix-autoindentation-after-data…
Browse files Browse the repository at this point in the history
…-structures

Fix autoindentation after data structures.
  • Loading branch information
ccordoba12 authored Oct 22, 2016
2 parents 9434aa6 + 6ccaf87 commit c5434b4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
6 changes: 4 additions & 2 deletions spyder/widgets/sourcecode/codeeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1957,8 +1957,10 @@ def fix_indent(self, forward=True, comment_or_string=False):
break
else:
if prevtext.strip():
prevexpr = re.split(r'\(|\{|\[', prevtext)[-1]
correct_indent = len(prevtext)-len(prevexpr)
if len(re.split(r'\(|\{|\[', prevtext)) > 1:
#correct indent only if there are still opening brackets
prevexpr = re.split(r'\(|\{|\[', prevtext)[-1]
correct_indent = len(prevtext)-len(prevexpr)
else:
correct_indent = len(prevtext)

Expand Down
9 changes: 3 additions & 6 deletions spyder/widgets/sourcecode/tests/test_autoindent.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ def test_def_with_indented_comment():
text = get_indent_fix("def function():\n # Comment\n")
assert text == "def function():\n # Comment\n ", repr(text)

def test_brackets_alone():
text = get_indent_fix("def function():\n print []\n")
assert text == "def function():\n print []\n ", repr(text)

# --- Failing tests
# -----------------------------------------------------------------------------
Expand All @@ -70,11 +73,5 @@ def test_open_parenthesis():
assert text == "open_parenthesis(\n ", repr(text)


@pytest.mark.xfail
def test_brackets_alone():
text = get_indent_fix("def function():\n print []\n")
assert text == "def function():\n print []\n ", repr(text)


if __name__ == "__main__":
pytest.main()

0 comments on commit c5434b4

Please sign in to comment.