Spyder: Fix issues with incorrect auto-indentation

Created on 17 Feb 2015  Â·  30Comments  Â·  Source: spyder-ide/spyder

_From [email protected] on 2011-12-15T17:08:06Z_

This is a enhancement/feature request.

Enhancement request:

1: def parseargs():
2:    ap = argparse.ArgumentParser()
3:    ap.description('Records results from standard HPC benchmarks and '+ \
4:        'corresponding information about the enviornment and input data to '+ \
5:        'interprete the results')
6:    ap.add_argument(...)

After hitting return on line 5, spyder autoindents with 8 spaces, thus requiring the user to hit backspace or shift-tab. This should be changed to: if the last line (where return was hit) completes a statement (in this case ap.description(...)), then autoindent to the indentation level of that statement, otherwise autoindent to previous line level.

Feature request:

1: if some.condition():
2:     do_one_thing()
3: else:
4:     do_another_thing()

After hitting return on line 2 spyder indents to 4 spaces, fine so fare. Here would it be nice to just type "else:" and have spyder do the unindentation by itself. The same behavior should be implemented for "except:" and "final:".
It makes sens to check if the user had already done the unindentation, to not confuse old users with this new behavior, for example by checking if a corresponding "if ...:" or "try:" exists (this would fail with nested blocks) or by checking if backspace/shift-tab was hit just before typing the keyword.

_Original issue: http://code.google.com/p/spyderlib/issues/detail?id=887_

6–10 stars Editor Bug

Most helpful comment

magic

All 30 comments

_From [email protected] on 2011-12-29T03:49:43Z_

Another similar issue. If you press enter after the following code the cursor appears at the point that I have shown the "*"

for item in ("A", "B",
             "C", "D"):
                 *

_From [email protected] on 2012-01-07T14:02:57Z_

One more similar issue. After calling the function, pressing enter moves the cursor at the position noted by the asterisk.

def very_long_function_name(arg1, arg2, arg3, arg4, arg5):
    pass

very_long_function_name(arg1 = 1,
                        arg2 = 2,
                        arg3 = 3,
                        arg4 = 4,
                        arg5 = 5)
                        *

_From [email protected] on 2012-01-10T11:21:32Z_

Something that I find rather annoying. Let's say you write a list of lists. The cursor is noted with the asterisk. This is the initial position:

combos = [[-100, 24, 46, 23, 32],
          [-200, 43, 32, 94, 4]*]

pressing enter results correctly in:

combos = [[-100, 24, 46, 23, 32],
          [-200, 43, 32, 94, 4]
          *]

but if we return in the initial position and we insert a comma before pressing enter, then, after pressing enter, there is no identation!!!

combos = [[-100, 24, 46, 23, 32],
          [-200, 43, 32, 94, 4]_]
combos = [[-100, 24, 46, 23, 32],
          [-200, 43, 32, 94, 4],_]
combos = [[-100, 24, 46, 23, 32],
          [-200, 43, 32, 94, 4],
*]

_From pierre.raybaut on 2013-04-13T10:06:12Z_

Status: New

_From ccordoba12 on 2014-01-02T08:24:45Z_

Status: Accepted
Labels: MS-v2.3.1 Cat-Editor

_From ccordoba12 on 2014-01-02T08:30:34Z_

Steven, could you try to fix the problems reported in comments #1 and #3, now that you fixed the original one as part of PR #9?

Cc: [email protected]

_From [email protected] on 2014-01-02T16:23:26Z_

Sure, seems reasonable.

_From ccordoba12 on 2014-01-02T21:52:38Z_

Great, thanks!

Owner: [email protected]
Cc: [email protected]
Labels: -MS-v2.3.1 MS-v2.3

_From [email protected] on 2014-01-05T19:42:42Z_

The latest commit in the PR handles all cases except for the feature request to dedent else and friends. https://bitbucket.org/spyder-ide/spyderlib/pull-request/12/add-ability-to-re-trigger-docstring-while/diff

_From ccordoba12 on 2014-01-15T17:15:19Z_

This issue was updated by revision e37d15030b35 .

  • Revision 7b48707901ef tried to address issue #887 but only worked when all
    parenthesis are matched.
  • More thought has to be given to solve that issue correctly so I'm leaving it
    for later.

_From [email protected] on 2014-01-16T19:45:35Z_

I made some more modifications to PR#12 that should address all issues. https://bitbucket.org/spyder-ide/spyderlib/pull-request/12/add-ability-to-re-trigger-docstring-while/diff

_From ccordoba12 on 2014-01-16T19:53:36Z_

Thanks, I'll test them tomorrow, but I'm thinking to leave this for 2.3.1.

I'd really like to begin stabilizing things now and in my experience changes like this (which try to improve our Editor experience but are really tricky to get it right) introduce lots of side effects.

What do you think?

_From [email protected] on 2014-01-16T20:36:50Z_

I agree, I do not think you should hold up the current release for this.

_From ccordoba12 on 2014-05-04T14:47:05Z_

Labels: -MS-v2.3 MS-v2.3.1

_From ccordoba12 on 2014-08-17T18:36:04Z_

Labels: -MS-v2.3.1 MS-v2.4

_From ccordoba12 on 2015-02-03T12:15:44Z_

issue #2152 has been merged into this issue.

_From ccordoba12 on 2015-02-03T12:16:21Z_

issue #2153 has been merged into this issue.

_From ccordoba12 on 2015-02-03T12:16:56Z_

issue #2154 has been merged into this issue.

_From ccordoba12 on 2015-02-03T12:17:25Z_

issue #2155 has been merged into this issue.

_From ccordoba12 on 2015-02-03T12:18:00Z_

issue #2156 has been merged into this issue.

_From ccordoba12 on 2015-02-03T12:21:35Z_

@-cmeeren All the issues you reported have to do with this issue, i.e. Spyder failing to do proper auto-indentation.

They are valid, but I prefer to have everything consolidated in a single place :-)

_From [email protected] on 2015-02-03T23:23:12Z_

@-ccordoba12 Thanks! I know you and the rest of the team are working hard to fix issues like these. Since auto-indentation issues are something most Spyder users face every day (and have for some time, apparently!), I hope you are able to prioritize these. :-)

_From [email protected] on 2015-02-04T02:10:20Z_

I also discovered that when writing a comment and pressing Enter, the cursor is fully outdented.

To follow up on #2156 (marked dup): arguments containing parentheses intefere with auto-indentation.

_Sorry these ended up kind of blurry_

step01

step02

step03

Restarting at step 1...

step04

step05

Version and main components

  • Spyder Version: 2.3.9
  • Python Version: 3.5.2
  • Qt Versions: 4.8.7, PyQt4 (API v2) 4.11.4 on Windows

Optional dependencies

pyflakes >=0.6.0   :  1.2.3 (OK)
pep8 >=0.6         :  1.7.0 (OK)
pygments >=1.6     :  2.1.3 (OK)
IPython >=1.0      :  4.2.0 (OK)
zmq >=2.1.11       :  15.2.0 (OK)
qtconsole >=4.0    :  4.2.1 (OK)
pandas >=0.13.1    :  0.18.1 (OK)
sphinx >=0.6.6     :  1.3.1 (OK)
rope >=0.9.2       :  0.9.4-1 (OK)
jedi >=0.8.1;<0.9.0:  0.9.0 (NOK)
matplotlib >=1.0   :  1.5.1 (OK)
sympy >=0.7.3      :  1.0 (OK)
pylint >=0.25      :  None (NOK)

@blink1073 how are we performing all this logic in general?

magic

Hahahahaha

Thats why you nimrod!!! we need to make it less magical :-p

Just for reference, my #5606 is a partial duplicate of this, though up to date with the latest version and even more extensive. Setting it to track the same milestone for now...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LDONT picture LDONT  Â·  3Comments

goanpeca picture goanpeca  Â·  3Comments

hedeqing picture hedeqing  Â·  3Comments

spyder-bot picture spyder-bot  Â·  3Comments

danieltomasz picture danieltomasz  Â·  3Comments