Sublime Forum

Tab width changing automatically for 1 file

#1

I’m seeing a weird issue in build 3131, and I can’t put my finger on why it’s occurring. I have one Python file in my project that, when I open it in Sublime, results in the tab spacing being set to 2 spaces. All other Python files in this project open with a tab spacing of 4 spaces (which I prefer).

If I open the problematic file, change the spacing to 4, close the file, and reopen it, the tab spacing gets set back to 2 spaces. Changing the file (and saving it) makes no difference.

Does anyone have any idea why one particular file should result in the tab spacing being set to something different? Could there be a file-specific setting somewhere? Is there a way I can force all Python files to open with a tab spacing of 4 spaces?

0 Likes

#2

Do you have the detect_indentation setting enabled? It defaults to being turned on, so if you haven’t specifically disabled it there could be something about that particular file that causes the indent level to be incorrectly detected as two spaces instead of four.

    // Set to false to disable detection of tabs vs. spaces on load
    "detect_indentation": true,

If this is indeed the case, you can solve the problem by turning the option off so that the values set in translate_tabs_to_spaces and tab_size that you’ve specifically set are always used.

For the curious, the code that determines the indent automatically is in Default/detect_indentation.py, which might also allow you determine what it is about your file that’s tripping it up.

2 Likes

#3

Thanks for the pointer to that script. I ran it manually against the file that was complaining, and that was indeed the issue. I’ve adjusted my code slightly to avoid the problem, though I’m sure disabling detect_indentation would also work.

1 Like