I have rust-mode installed on my Emacs 24.4. The tab indentation I have is 2 whitespaces, however in Rust mode it's different. I want to setup the tab indentation size for rust-mode, how can I do that?

And actually, not only for rust mode, for other languages such as Python too.


Or I think it's better for me to setup it globally regardless of the setting for each **-mode package.


1 Answer 1


In general, you can do something like this:

(add-hook '<foo>-mode-hook (lambda () (setq tab-width 4)))

If you have a single global default you prefer:

(setq-default tab-width <number you like>)
  • what's "a single global default "?
    – Oskar K.
    May 7, 2016 at 7:05
  • If you do C-h v tab-width <RET>, you'll see, "automatically becomes buffer-local when set." This means that a variable (in this case, tab-width) has a default, base value, and expects to be overwritten on a per-buffer basis. For instance: the vanilla emacs default for tab-width is 8 spaces. In my configs, I have (setq-default tab-width 4) (because 8 is silly), but then in my JavaScript configs I have a hook that sets tab-width to 2 spaces.
    – Gastove
    May 7, 2016 at 17:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.