Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If it was up to me I'd ban \t character altogether from source code and just use plain spaces - but a lot of sources, especially in C, are indented like this:

  • no indent
  • 4 spaces
  • \t
  • \t + 4 spaces
  • \t\t

TextMate has trouble with it - it has a single setting for indentation (normally 2 or 4 depending on language, 8 is rare), and meaning of \t (universally 8 if present at all).

Am I missing some setting to get it work properly?

share|improve this question
Perhaps you should clarify...WHAT does TextMate have trouble with? I have used it for over 4 years now and it usually handles tabs, soft or otherwise, better than any other editor i've found... – peelman Jul 29 '10 at 13:10
Many other editors mix tabs and spaces for indentation. So first level is 4 spaces, second is 1 tab (=> 8 spaces). In TextMate if I set tab width to 8, it will look correctly but it will indent everything to 8 not 4 when I edit it. If I set tab width to 4, I won't be even able to tell indentation levels apart. Example of file with such problems. – taw Jul 31 '10 at 1:00

That's the backwards way in which emacs inserts indentation by default (4 spaces for one level, 1 tab for two, 1 tab + 4 spaces for three, and so on). You could work around it by setting the indent to 8 spaces...but then you'll be inserting 8 spaces always (or a tab always, if you have TM set up that way). As far as I know, there's no way to handle the asinine emacs-style indentation in TextMate.

share|improve this answer
You get no argument from me that it's a horrible idea - but files indented this way are very common, surely I cannot be the first person to have this problem? – taw Jul 31 '10 at 1:02
No doubt the problem has come up (it has for me); I just don't think TextMate has a solution, short of changing all tabs to spaces or all spaces to tabs. – mipadi Jul 31 '10 at 1:37

One way is to replace tabs with spaces while you're editing:

# Replace tabs with 8 spaces in C sources
perl -lape 's/\t/        /g' -i *.c *.h;

# Now edit your files

# Replace 8 spaces with tabs
perl -lape 's/        /\t/g' -i *.c *.h

Not tested, but that's one way to go about things. This will also mess with tabs/spaces that are not at the beginning of the line, but you probably don't have any of those.

share|improve this answer
Code repositories that suffer from mixed-tabbing usually don't even do it consistently - some files use mixed tabs, others use spaces, or even mix both in one file. One thing that could work might be getting rid of tabs altogether, and some hacks for svn/git that would treat lines that differ only in tab expansion as unchanged - no idea how to do that. – taw Aug 5 '10 at 16:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .