You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Repository navigation
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Soft Tabs "smart" behavior is not smart when tabs are removed. #122
The Soft Tabs setting overrides (to be "smart") seem to be applied based on a check when a file is opened. However, if you replace all of the characters that induced the override, that setting remains (until the file is closed and reopened). For example, with Soft Tabs checked and a file open with some tab characters used, the editor will continue to insert tab characters based on that initial setting, even after you have replaced each of the tab characters with four spaces.
The Soft Tabs setting is (rightly) ignored when opening a file that has the opposite case. For example, after opening a file that includes tab characters, the editor will use tab characters regardless of setting. This issue only seems to pop up when an open file is changed from one to the other without being closed and reopened.
Of course, the workaround is easy enough, but it's a little bit of friction after finding a few stray tabs and removing them in the course of doing some other work.
I tried this with Python, Gfm, and Stata .do files, and saw the same behavior.
Reproduce:
Turn off Soft Tabs (I know, who would do this?).
Create a new file, indent some nonsense with tabs, and save and close it.
Turn on Soft Tabs.
Reopen the file.
Note that additional indents still use tabs (rightly).
Replace all of the tabs with four spaces.
Note that additional indents continue to use tabs (wrongly).
Sorry for not getting back to you sooner @jtkiley! This looks like a bug, wondering what @probablycorey thinks since he poked at the soft/hard tabs code recently?
I just got back from vacation (thus the delayed reply), and I'll check Textmate 2 and BBEdit. My recollection is that they just respect the setting (without the smart behavior).
So, I think the short answer for @probablycorey is that BBEdit and Textmate 2 aren't looking at tabs at the per-document level. TM2 strictly applies the setting, and BBEdit appears to have a built-in preference for spaces that is overridden when auto-indenting a line following a hard tab indented line.
Here's more on what I'm seeing:
BBEdit 10.5.10 (MAS build)
Hard tabs (BBEdit:Preferences:Editor Defaults - Auto-expand-tabs (unchecked))
If you press return at the end of an indented line, it matches the style of that line, even if it uses spaces.
Otherwise, it seems to use spaces even without the option set. That's true even is the file is opened with all hard tabs.
Soft tabs
It seems to behave the same way, even with the setting on.
It could be that it keeps some sort of per-document setting that overrides the default.
Following the Text:Entab and Text:Detab commands (changing all tabs of either type to the specified type), it still uses spaces for tabs (that aren't following indented lines), regardless of setting.
Textmate 2 (9547)
It strictly adheres to the setting (from the bottom bar), regardless of the preceding line or other tabs in the file.
So, if I replace all of the tabs with spaces, it will still auto hard tab the next line if I press return on an already-indented line.
Similarly, it will use hard tabs for manually-indented lines if set to hard tabs.
As a starting place for solutions, here's what I came up with.
I like the idea of the smart behavior. Along those lines, the easiest solution that I can think of is adding a menu command that makes the tab style consistent (and internally changes the per-document setting that is currently set on opening). Then, on subsequent opens, the existing behavior (i.e. checking the document at open) should be fine. That assumes that mixing tabs and spaces within one file is bad, so it may not hold up if there are places where that's not true.
Another option (though perhaps worse than the current behavior) would be the Textmate style, where the setting is strict. The downside is that you'll end up with mixed tabs and spaces, and that could be problematic in Python if you're mixing four spaces and hard tabs (interpreted as eight spaces). It seems like this option really intends for you to prefer one or the other and aims to prevent you from adding to the other style (assuming that you choose not to replace tabs across the whole file or project). The main benefits are that it's clearly understood and it solves the problem, but you end up giving up the flexibility that the current smart behavior allows (i.e. freely working with files with different tab settings without upsetting it or changing settings).
There's been zero activity or discussion on this issue for over 2 years so I'm going to archive it. If there are new thoughts or somebody wants to push it along please continue the discussion and we can reopen it.
Activity
izuzak commentedon May 30, 2014
Sorry for not getting back to you sooner @jtkiley! This looks like a bug, wondering what @probablycorey thinks since he poked at the soft/hard tabs code recently?
Also, this also might be related to atom/atom#1739
probablycorey commentedon May 30, 2014
I think this edge case will still exist. @jtkiley is there an existing editor that you use that handles this correctly?
jtkiley commentedon Jun 2, 2014
I just got back from vacation (thus the delayed reply), and I'll check Textmate 2 and BBEdit. My recollection is that they just respect the setting (without the smart behavior).
jtkiley commentedon Jun 2, 2014
So, I think the short answer for @probablycorey is that BBEdit and Textmate 2 aren't looking at tabs at the per-document level. TM2 strictly applies the setting, and BBEdit appears to have a built-in preference for spaces that is overridden when auto-indenting a line following a hard tab indented line.
Here's more on what I'm seeing:
jtkiley commentedon Jun 2, 2014
As a starting place for solutions, here's what I came up with.
I like the idea of the smart behavior. Along those lines, the easiest solution that I can think of is adding a menu command that makes the tab style consistent (and internally changes the per-document setting that is currently set on opening). Then, on subsequent opens, the existing behavior (i.e. checking the document at open) should be fine. That assumes that mixing tabs and spaces within one file is bad, so it may not hold up if there are places where that's not true.
Another option (though perhaps worse than the current behavior) would be the Textmate style, where the setting is strict. The downside is that you'll end up with mixed tabs and spaces, and that could be problematic in Python if you're mixing four spaces and hard tabs (interpreted as eight spaces). It seems like this option really intends for you to prefer one or the other and aims to prevent you from adding to the other style (assuming that you choose not to replace tabs across the whole file or project). The main benefits are that it's clearly understood and it solves the problem, but you end up giving up the flexibility that the current smart behavior allows (i.e. freely working with files with different tab settings without upsetting it or changing settings).
damieng commentedon Sep 30, 2016
There's been zero activity or discussion on this issue for over 2 years so I'm going to archive it. If there are new thoughts or somebody wants to push it along please continue the discussion and we can reopen it.