2

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.

UPDATE:

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

Oskar K.
  • 278
  • 1
  • 7

1 Answers1

2

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>)
Gastove
  • 1,511
  • 9
  • 15
  • what's "a single global default "? – Oskar K. May 07 '16 at 07:05
  • If you do `C-h v tab-width `, 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 07 '16 at 17:14