Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent emacs from mixing tabs and spaces?

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...

like image 211
warfangle Avatar asked Aug 27 '10 16:08

warfangle


1 Answers

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).

like image 87
Dave Bacher Avatar answered Oct 22 '22 22:10

Dave Bacher