question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

various issues when trying to work on code that uses tabs

See original GitHub issue

These are small, separate, but related issues so I’ll lump them into one GitHub issue for now. If you would like me to split them off into two issues, let me know.

  • Tab to space conversion is prompted every time the user continues an indent
  • Tabs are one character but treated as two indents semantically

Tab to space conversion is prompted every time the user continues an indent

Problem steps

  1. Paste the following code which uses tabs:
for x in range(3):
	print(x + 1)
    for y in range(3):
  1. When prompted, choose not to replace tabs with spaces.
  2. Press enter at the end of line 2.
  3. Press enter on the last line (now line 4)

Expected behavior

At step 3, \n\t is inserted is inserted. At step 4, \n\t\t is inserted.

Actual behavior

  • At step 3, the user is prompted to replace tabs with spaces. If they decide not to, \n\t is inserted.
  • At step 4, the user is prompted to replace tabs with spaces. If they decide not to, \n\t\t is inserted.

Remarks

This seems to be the editor trying to maintain consistency with the existing code, per the user’s preference, while also forgetting that the user already decided not to convert tabs to spaces before in the same file. Suggested fix: recording somewhere (in memory or in a config file) that the user would prefer to keep tabs on paste. Alternative fix: warn when pasting tabs, and convert them to spaces no matter what.

While the intention is perhaps to discourage the use of tabs, this behavior comes off as heavy handed, to the point of actively being user-hostile. Tabs are discouraged by Thonny because the language discourages them, but Python also requires consistent indentation. Syntax takes precedence over style, so if it’s not inconsistent behavior, it would seem to be inconsistent rationale.

Tabs are one character but treated as two indents semantically

Problem steps

  1. Manually insert a tab character, using a clipboard or an IME.
  2. When prompted, press “no” to not replace tabs with 4 spaces.
  3. Press backspace on the tab character.
  4. Note that the tab character is rendered as two indents, which is inconsistent with the behavior of replacing tab keypresses with one indent.
  5. Save the file.

Expected behavior

The entire tab character is deleted and the file is empty.

Actual behavior

Step (2) inserts one tab character, but since it’s rendered as two “indents”, pressing backspace turns it into one indent, and the file contains one tab character.

Remarks

Render a tab character as one indent (4 character widths / one tabstop). If you really want to distinguish them, display an indent marker, like this: screenshot of some python code in the Mousepad editor, with "show whitespace" enabled. Tab characters are displayed as an arrow pointing into a line.

Notes

I don’t want to start a flame war here =)

I respect the position of being opinionated for simplicity and for the sake of guiding beginners towards Good Practice and therefore not supporting tabs for indentation. However, I think it should be possible and not cumbersome for a beginner to contribute to codebases that already use tabs. If that use-case is out of scope for this project, feel free to close this issue. I am willing to try to fix these issues, if all contributors would rather not touch The Character That Shall Not Be Named.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
aivarannamaacommented, Oct 27, 2020

Actually I don’t have strong feelings about tab. It was just easier to ignore them, because using tabs for indentation in Tkinter’s Text widget is not really straightforward (#982). I’ve now learned that several users want or need to use tabs (#656, #505, #869, #599, #548).

I’d be really glad if you could sort out any of the issues mentioned here!

0reactions
aivarannamaacommented, Nov 10, 2020

I guess it’s done now. I added comments about what I did under #599. Please reopen if you think there is something more to be done.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Indent using tabs by default · Issue #156304 · microsoft/vscode
I'm talking about cases where you want to use the tab-stop feature of tabs, eg. tables, goto labels, command line programs that use...
Read more >
VSCode Extension to fix inconsistent tab issue of Python [closed]
You can fix the tab inconsistency by converting all indentation to tab or spaces. If you open the "Show All Commands" tab, (...
Read more >
Why Programmers Who Use Spaces Instead of Tabs Make ...
David Robinson, the data scientist who performed this study found that programmers using space over tabs made an average of 9 percent more...
Read more >
Never use hard tabs - Open Source Hacker
Reasons not to use hard tabs​​ Thus, hard tabs may break source code readability and editability if there is more than a single...
Read more >
Tabs and indents settings does not work
Hello,. I have a problem with tab and indents settings. In settings->codestyle->php->tabs&indents I have set tab character for indent.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found