views:

102

answers:

2

Background:

I'm primarily a Javascript developer. Espresso mode rocks.

I work on a team where other people touch my code (and I theirs). Different folks have different preferences for tab width. I like mine at four, a coworker likes his at two.

JSLint complains if you mix tabs and spaces (yes, I realize you can turn it off - but it helps keep me sane).

I'm staring at my buffer in whitespace-mode, and can clearly see that when I newline and tab, it inserts a bunch of tabs and then.. four spaces.

How can I prevent this behavior? The only whitespace before the first visible character of a line should be tabs...

+2  A: 

You need to adjust a couple settings in your emacs configuration.

(setq tab-width 4)        ;; set your desired tab width
(setq indent-tabs-mode t) ;; use tabs for indentation

You may also need to adjust the indentation offset in your javascript mode so that each indent is a multiple of your tab width (for C-based modes it's called c-basic-offset).

Dave Bacher
A: 

I find that this subject tends to catch people out in Emacs. I recommend doing some extra reading, even if Dave's answer covers everything for Espresso mode.

phils