jtokoph / auto-detect-indentation

Auto detect indentation of files in Atom
MIT License
39 stars 6 forks source link

Auto indent detecting tab width of 12 #2

Closed beeftornado closed 10 years ago

beeftornado commented 10 years ago

I have a python file that when I open, the tab size is detected to be a width of 12 and it should be 4.

jtokoph commented 10 years ago

Does the first line with leading space contain 12 spaces?

beeftornado commented 10 years ago

I did a little digging and found the cause to be an extended conditional clause that was broken up to multiple lines and occurs before any indented code blocks.

# ... comments and imports ...

if hasattr(cfg,
           'debug') and cfg.debug:
############ (12)

# ... rest of code with functions and things ...

I can fix this by just unindenting the continuation, but many coders' style is to line up the continuation with the clauses before it.

jtokoph commented 10 years ago

I'll have to make this a little more intelligent by searching all lines for leading spaces and using the smallest length of leading spaces. I think I was a bit naive to think scanning the whole file wasn't necessary.

beeftornado commented 10 years ago

Heh, it surprisingly works in most cases though.

You might be able to build off this logic http://stackoverflow.com/a/7113875/276125

jtokoph commented 10 years ago

Let me know if it works for you. Added a test based on your sample code, so you should be good to go.

beeftornado commented 10 years ago

Thanks, looks good.