Spyder: Shift-Tab does not remove final indent level for non 4-multiple indents (e.g. continuations)

Created on 13 Nov 2017  路  8Comments  路  Source: spyder-ide/spyder

Description

If I have the cursor on an indented line or (particularly troublesome) a block of code selected, that doesn't have indent perfectly a multiple of 4, e.g. continuation lines/blocks, Shift-Tab will not remove the last indent level of >4 spaces and instead do nothing. Instead, I must go to every line and delete the last 1-3 spaces manually, which is rather tedious and error prone and takes far more time than tapping shift-tab one more time. A relatively common case is when a block picks up an undesired indent from the block above, or I otherwise want to shift it all the way to the left quickly, and I cannot. I don't see an immediate reason why this wouldn't be the desired behavior, as it is in most (most all?) other editors and applications, but perhaps there is some use case I'm missing.

What steps will reproduce the problem?

  1. Copy a block of code with a non mod 4 = 0 indent. E.g.
       (1.2e-5, 2.0e8),
       (1.6e-5, 2.3e8),
       (1.8e-5, 1.5e7)]
  1. Select the block (or place the cursor at the beginning of a line)
  2. Hit shift-tab until it stops before the left margin

What is the expected output? What do you see instead?
For the above example
Expected:

(1.2e-5, 2.0e8),
(1.6e-5, 2.3e8),
(1.8e-5, 1.5e7)]

Actual:

   (1.2e-5, 2.0e8),
   (1.6e-5, 2.3e8),
   (1.8e-5, 1.5e7)]

Please provide any additional information below

As usual, occurred on multiple systems, installs and OS versions so clearly not specific to that.

Version and main components

  • Spyder Version: 3.2.4
  • Python Version: 3.6.3
  • Qt Versions: 5.6.2, PyQt5 5.6 on Windows 8.1 Pro x64 and Win 10 Ent x64

Dependencies

pyflakes >=0.6.0 :  1.6.0 (OK)
pycodestyle >=2.3:  2.3.1 (OK)
pygments >=2.0   :  2.2.0 (OK)
pandas >=0.13.1  :  0.20.3 (OK)
numpy >=1.7      :  1.13.3 (OK)
sphinx >=0.6.6   :  1.6.3 (OK)
rope >=0.9.4     :  0.10.5 (OK)
jedi >=0.9.0     :  0.10.2 (OK)
nbconvert >=4.0  :  5.3.1 (OK)
sympy >=0.7.3    :  1.1.1 (OK)
cython >=0.21    :  0.26.1 (OK)
qtconsole >=4.2.0:  4.3.1 (OK)
IPython >=4.0    :  6.1.0 (OK)
pylint >=0.25    :  1.7.4 (OK)

Editor Bug

Most helpful comment

@ccordoba12 Yep, can do this.

All 8 comments

Thanks for reporting. We'll take a look at this for Spyder 4.

@rlaverde, please work on this one.

Currently, Spyder just removes a fixed number of spaces indent.

I propose to change the unindent behavior to reduce the number of leading spaces to the next smaller n * indent. This way, a first unindent will automatically correct odd-number indents. This also covers the above case with n = 0.

Example: Assuming a regular indent = 4, the number of leading spaces for two consecutive unindents would be:

  • current behavior: 5 -> 1 -> 1
  • current behavior + request above: 5 -> 1 -> 0
  • my proposal: 5 -> 4 -> 0

Sounds even better, @timhoffm !

@timhoffm, do you want to work on this one?

@ccordoba12 Yep, can do this.

Sorry, not having time to work on this in the coming few weeks. If someone else wants to tackle this, you're welcome. Otherwise I'll pick this up later on.

Note: For a single line, the "unindent to next regular tab position" is a good and obvious choice. I'm not yet clear, what to do for a selection of multiple lines. Probably we should find the least indented line, determine how many spaces need to be removed to "unindent to next regular tab position" for this line and apply this unindent to all lines. Do you agree?

Sure, I think it's a good approach.

Sounds great. Thanks much for working on this.

Was this page helpful?
0 / 5 - 0 ratings