Allow mixing of tabs and spaces if an explicit tabstop size is set #4303
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
“CoffeeScript just counts tabs and counts spaces -- you can't possibly expect it to guess how wide your text editor is configured to visually show tab characters.”
But, what if you could tell CoffeeScript how wide a tab stop is? Following the Robustness principle I think it would be great if you could instruct CoffeeScript to treat indentation just as it is visually. This of course requires cooperation of the editor / environment or explicit configuration by the user, making this an opt-in feature (we can do this).
I’ve read the discussions about tabs/spaces in a couple of issues and have seen that the sentiment generally is to not allow mixing, although it’s currently not enforced. However, while CoffeeScript is a really nice language to learn to program, the requirement to carefully manage your whitespace is quite unfriendly. The current behavior, where a tab is equivalent to a space in width is imho a poor choice: no editor is configured like that. (Python 2’s behavior of having a tabstop width of 8 makes a bit more sense).
The implementation in this pull request is mostly a ‘proof of concept’, to show what I’m talking about. Having this option would make parsing dependent on a specific option, meaning that some files won’t parse unless the exact right size is passed. A better way to do it (albeit still breaking backwards compatibility) might be to have it set via modeline at the start of the file.
I’m interested to hear from the maintainers and the community if anybody thinks pursuing a feature like this has merit.