Home Download Buy Blog Forum Support

translateTabsToSpaces and tabSize not affecting Python

translateTabsToSpaces and tabSize not affecting Python

Postby edanm on Thu May 13, 2010 4:30 pm

I have these two settings in my User File Type.sublime-options:

tabSize 4
translateTabsToSpaces false

But they don't seem to do much good on Python files (they work fine on javscript and html files).

That is to say, I always get spaces instead of tabs, and changing the tabSize to different settings isn't affecting the .py files at all.

EDIT: Apparently this only happens in some Python files. I'm still not sure which ones or why. If it helps, the name of one of the files is "views.py" (although a different file, also called "views.py", seems to work fine).
Last edited by edanm on Thu May 13, 2010 8:08 pm, edited 1 time in total.
edanm
 
Posts: 131
Joined: Thu Mar 04, 2010 11:05 pm

Re: [BUG] translateTabsToSpaces and tabSize not affection Python

Postby adzenith on Thu May 13, 2010 5:09 pm

This may be caused by an option in Default File preferences:
Code: Select all
# Set to false to disable detection of tabs vs. spaces on load
detectIndentation true

Sublime might be (incorrectly?) guessing that you're using spaces to indent.

Other than that, you might have spaces turned on in your Python file options.

Or it could just be a bug in Sublime.
adzenith
 
Posts: 1217
Joined: Mon Oct 19, 2009 9:12 pm

Re: [BUG] translateTabsToSpaces and tabSize not affection Python

Postby edanm on Thu May 13, 2010 5:31 pm

Ah yes, that did the trick. That was driving me crazy! Thanks a lot.
It actually guessed it correctly (about 2/3rds of the file is spaces, 1/3rd tabs). I just didn't know this setting exists.

While we're on the subject, is there any command to convert tabs to spaces in the entire file / selected regions and vice versa?
edanm
 
Posts: 131
Joined: Thu Mar 04, 2010 11:05 pm

Re: [BUG] translateTabsToSpaces and tabSize not affection Python

Postby guillermooo on Thu May 13, 2010 7:02 pm

Not that I know of. The TextButcher plugin was conceived to solve this scenario, though. I haven't updated it in a while, but the basic operation you need is included by default if I remember correctly.
guillermooo
 
Posts: 729
Joined: Thu Jul 23, 2009 9:06 am

Re: [BUG] translateTabsToSpaces and tabSize not affection Python

Postby edanm on Thu May 13, 2010 7:55 pm

Where can I find that plugin? (I seem to be asking that a lot lately ;)
edanm
 
Posts: 131
Joined: Thu Mar 04, 2010 11:05 pm

Re: translateTabsToSpaces and tabSize not affecting Python

Postby guillermooo on Thu May 13, 2010 8:39 pm

http://bitbucket.org/guillermooo/textbutcher

It's very basic, but it should do the trick for you.

Alternatively, if you're familiar with Powershell, you could use PowershellUtils too to filter the region(s) and issue mkh to save the command to disk for subsequent uses.

It would look something like so:
Code: Select all
$_ -replace "( ){4}","`t"


In both cases, be sure to keep an eye on translatedTabsToSpaces! Otherwise replacing from spaces to tabs won't have any effect (or so did I notice in my testing). You can use yet another plugin to control this setting file by file: SublimeModelines.

Hope it helps!
guillermooo
 
Posts: 729
Joined: Thu Jul 23, 2009 9:06 am

Re: translateTabsToSpaces and tabSize not affecting Python

Postby gpfsmurf on Thu May 13, 2010 10:01 pm

textbutcher is empty, did you synchronize your changes?

Note that you can also use sublime's find & replace function: Ctrl+H, look for "( ){4}", replace by "\t"
gpfsmurf
 
Posts: 211
Joined: Mon Jun 23, 2008 6:31 pm

Re: translateTabsToSpaces and tabSize not affecting Python

Postby guillermooo on Fri May 14, 2010 8:38 am

Oops, it looks like I didn't! Sorry about that.

Anyway, it's just a convenient way of storing a s&r action like the one gpfsmurf 's pointed out and give it a name.

Then you open a quick panel, type this name in, press enter, and the action's applied to all selected regions. The actions db is saved to a file, so you won't have to type that pattern again. It can also set options, etc.

I'll make sure to commit the code later today.
guillermooo
 
Posts: 729
Joined: Thu Jul 23, 2009 9:06 am


Return to Technical Support

Who is online

Users browsing this forum: Google [Bot] and 14 guests