mksuth mksuth - 1 year ago 74
Javascript Question

How to change the indentation width in emacs javascript mode

I'd like to use 2 spaces for my indents instead of 4. I can change the default behavior of C mode using:

(setq c-basic-offset 2)

How do I change this in javascript mode?

Answer Source

js-indent-level can be used in the default javascript-mode, which is included by default starting in emacs 23.2.

(setq js-indent-level 2)

should do what you're looking for. If you're using an older version of emacs, you may be in java-mode. I think this mode responds to c-basic-offset, however I may be wrong.