Tab length / indentation not working as expected


#1

Hello. I have Tab Length in settings set to ‘Default:2’, and using two different .js files, one of them is behaving as expected with the indentation lines occurring every 2 spaces. However, on a second js file the indentations and tab result in 4 spaces. I tried setting Tab Type to soft, hard, and auto, without any changes. Any suggestions how to fix or why this is occurring?
Thanks.


#2

Atom will do its best to detect and maintain the formatting of any file that you open in it. Sometimes it gets it wrong because it only inspects the first few lines to make its determination. Another reason why it may be getting it “wrong” is because the file is detected as some other language for which you’ve set four spaces as the indentation. Double-check the grammar indicator on the right side of the status bar.


#3

Thanks @leedohm, adjusting the first few lines to with manual spaces did indeed do the trick, and now everything reverted back to normal 2 space tabs. The grammar indicator does show JavaScript on the right side, but I only checked it after I manually adjusted the spaces, so I’m unsure if it thought it was something different. Also - to the left of the language type I see that there is a setting for the # of spaces. Good to know for the future.

Cheers.


#4

Manually adjusting the whitespace isn’t going to change the grammar detected (or at least shouldn’t :scream:), I was just tossing that one in just in case my first theory wasn’t correct :grinning: