Sublime Forum

Weird tab behaviour in beta 20100613

#1

So I was working on Python files and no matter how often I reloaded this Python file it kept setting tab width to 8 characters, despite my Python configuration file having:

tabSize 4 translateTabsToSpaces true

One weird thing was that it explicitly said at the bottom of the editor that it was setting tab width to 8.

I had the same happening with HTML where it did not follow my tabSize 2.

Anyone else had strange tab behaviour like this? It kept repeating despite closing and starting Sublime Text a few times. And now a day later it seems to behave again. :open_mouth:

0 Likes

#2

This behaviour is controlled by the detectIndentation setting: it tries to automatically determine the indentation settings of the file on load.

You can disable this by setting:

detectIndentation false
0 Likes

#3

I have to say that detectIndentation is a bit flawed though. Why would it set tabs to 8 spaces when the whole Python file I am editing uses 4 space indents?

0 Likes

#4

It generally works quite well. In this case, it’ll be choosing an 8 space indent because 80% of the lines are indented with a multiple of 8 spaces. Perhaps there’s an argument to be made that the threshold should be greater than 80%.

0 Likes

#5

Aha, so it doesn’t check the flow control indentation but the overall percentage of indentation present in the code. Mmm.

The problem than arises when you have small files that have to do something like this:

[code]class DoHickey(object):
def init(self):
code
code
code

def method(self, arguments):
    more code
    more code
    more code[/code]

You will quickly then trip the 8 space tab width.

0 Likes

#6

so with python we are useing 4 spaces for each indentation, but most python is two+ indentations levels.

i guess it could get confused with multiples of your desired indentation.

0 Likes

#7

It seems I’m still getting this problem with the latest beta. (Coding in Matlab, I don’t know if that makes a difference.) I also have several files where most lines are indented two levels, which trips the 80% rule, and the double indentations are interpreted as one. Maybe some special case considerations would be good, such as if >80% of the lines are indented at 2X the default indentation (or 4X, 6X, etc), and the remaining lines are >50% at 1X, 3X, 5X, etc of the default, then stick with the default!

0 Likes