Spyder: "Fix indentation" command has misleading name

Created on 25 Oct 2017  路  9Comments  路  Source: spyder-ide/spyder

Description

Although auto-indentation while typing does appear to work (with some caveats, which I'll get to in another issue at some point), the Fix Indentation command apparently does nothing in any situation I've yet tested it in. I select some clearly not properly indented text, and call it from the menu, but nothing ever happens. Same with not selecting anything; no result.

What steps will reproduce the problem?

  1. Write some clearly non-properly indented code, e.g.
if true:
   print("Foo")

new_list = ["foo", "123",
 "bar", "456"]
  1. Select code
  2. Click "Fix Indentation"

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

if true:
   print("Foo")

new_list = ["foo", "123",
            "bar", "456"]

The above code indented properly, or at least conformance to some sort of rhyme or reason.

Instead, nothing happens.

Please provide any additional information below

Tested on multiple machines over the past few days, but not sure if it worked before if it ever did.

Version and main components

  • Spyder Version: 3.2.4
  • Python Version: 3.6.3
  • Qt Versions: 5.6.2, PyQt5 5.6 on Windows

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 Enhancement

Most helpful comment

Thanks @csabella , that would explain it.

In that case, I would suggest, at minimum, the command be renamed to "Convert Tabs to Spaces" or similar to be less ambiguous/potentially confusing; then it makes clear exactly what it does, matches what other editors call it, and avoids sounding the same or similar to the "Fix/correct indentation" command many other editors have for doing what I described above, which is of a very different character.

Assuming there isn't some strong reason not to change it, it just looks like the name string would need to be changed here, and then the localizations updated accordingly (probably the more laborious part, I imagine...) but I've never developed a real GUI app so that's purely a guess.

At some point in the (hopefully near) future, the better fix in addition to the above would be to implement what I described on demand, piggybacking off Spyder's existing auto-indent functionality. It doesn't seem too much of a stretch in principle as the basic feature already exists, but I imagine there might be some complexities related to the multi-line (vs existing single line) nature of such a command, which could make it not trivial to implement, but I have no direct experience with the matter.

All 9 comments

@rlaverde, please take a look at this one.

Fix indentation simply converts tabs to spaces. It does not re-format the indentation of the code.

Thanks @csabella , that would explain it.

In that case, I would suggest, at minimum, the command be renamed to "Convert Tabs to Spaces" or similar to be less ambiguous/potentially confusing; then it makes clear exactly what it does, matches what other editors call it, and avoids sounding the same or similar to the "Fix/correct indentation" command many other editors have for doing what I described above, which is of a very different character.

Assuming there isn't some strong reason not to change it, it just looks like the name string would need to be changed here, and then the localizations updated accordingly (probably the more laborious part, I imagine...) but I've never developed a real GUI app so that's purely a guess.

At some point in the (hopefully near) future, the better fix in addition to the above would be to implement what I described on demand, piggybacking off Spyder's existing auto-indent functionality. It doesn't seem too much of a stretch in principle as the basic feature already exists, but I imagine there might be some complexities related to the multi-line (vs existing single line) nature of such a command, which could make it not trivial to implement, but I have no direct experience with the matter.

Fix indentation simply converts tabs to spaces. It does not re-format the indentation of the code.

Yes, this is not a bug, It's an enhancement, maybe rename the current behavior to "Replace spaces for tabs" and add the proposed functionality to "Fix indentation"

Perfect @rlaverde . I'd suggest either the above ("Convert tabs to spaces"), or, as a grammar tweak to your proposal, "Replace tabs with spaces"

If it really isn't too difficult to implement the mentioned functionality, that would be awesome, but if not then the rename would still be beneficial due to the confusion potential I discuss above.

Also, as a general note, @csabella 's #5678 is somewhat related in that it points out an actual issue with the command as originally intended, though quite distinct from this one.

Took me a while too to understand what this was doing. Indeed the name of this operation should be changed.

Perhaps also add a menu item called "Replace spaces with tabs" that does the opposite. (Should that be a feature request in another issue?)

@PanderMusubi, no, it's fine here. And indeed, we should rename that option.

@PanderMusubi If you're interested in implementing it, we'd be glad to give you pointers. Otherwise, I can go ahead with it at some point soon; I figure it shouldn't be too involved.

Thanks but I will leave this to people doing more development on Spyder.

Was this page helpful?
0 / 5 - 0 ratings