markupboy

Forcing Tab Types Per Language in TextMate

Penned on .

Personally, I’m a hard-tabs guy. I like coding with invisibles enabled, I like being able to adjust the size of my tabs on a whim and I like that I’m not bloating by markup with unnecessary white-space. Unfortunately, some languages and methodologies prefer them so I found myself stuck switching back and forth frequently.

TextMate, being one of (if not THE) best editors for OSX, has a pretty handy solution for this. You can edit a languages bundle to force the default soft tabs setting per language.

Open up the bundle editor ( Bundles -> Bundle Editor -> Show Bundle Editor), click the carrot next to your language of choice to expand that language’s bundle items and find the entry marked “Miscellaneous” . Now, you just need to append to the “shellVariables” object a quick shell variable setting -

shellVariables = (
    {
        name = 'TM_SOFT_TABS';
        value = 'no';
    },
);

If the shellVariables object doesn’t exist, don’t worry, it’s safe to just create a new one. For instance, the default CSS miscellaneous bundle preferences look like this:

{
    smartTypingPairs = (
        ( '"', '"' ),
        ( '(', ')' ),
        ( '{', '}' ),
        ( '[', ']' ),
        ( '"', '"' ),
        ( "'", "'" ),
        ( '`', '`' ),
    );
}

And the new adjusted preferences with soft tabs explicitly disabled:

{
    shellVariables = (
        {
            name = 'TM_SOFT_TABS';
            value = 'no';
        },
    );
    smartTypingPairs = (
        ( '"', '"' ),
        ( '(', ')' ),
        ( '{', '}' ),
        ( '[', ']' ),
        ( '"', '"' ),
        ( "'", "'" ),
        ( '`', '`' ),
    );
}