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)
(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.
I wish someone had told me about Custom a lot sooner! Perhaps this will help another mere mortal like me 😉
Then, choose “Programming,” and then “Languages,” and then select a language/mode to customize. Edit the options as you see fit. When done, choose either “Save for current session” or “Save for future sessions.”
If you’re using js2-mode (which is more powerful IMHO), then the command is:
(setq-default js2-basic-offset 2)
You might also want to set emacs to use spaces instead of tabs
(setq-default indent-tabs-mode nil)
So if you are using the same lisp-mode you can change it by running
You can also use
js- [TAB] shows a list of options). Then change the
Js Indent Level as wanted and click
[State:] and save.
It’s also available in the package manager (
M-x package-list-packages) through Melpa or Marmalade.
If you want to change it on a per-file basis, put this at the top of your file:
// -*- mode: js; js-indent-level: 2; -*-