I'm a bit confused about setting indentation for different modes in Emacs.
- It seems you have to explicitly set indentation for each mode
- Some modes use
setq-default
, some usesetq
and some useadd-hook
- Indentation variables are inconsistently named
My question:
Is there a single indentation variable I can set that all modes inherit as a default?
If not, is there a shorter and more correct way to set up my indentation than listed below?
(setq-default tab-width 2)
(setq-default sh-basic-offset 2)
(setq-default sh-indentation 2) ;; workaround for bug in 25.3.1
(setq c-basic-offset 2
css-indent-offset 2
js-indent-level 2)
(add-hook 'php-mode-hook '(lambda ()
(setq c-basic-offset 2)))
(add-hook 'ess-mode-hook '(lambda ()
(setq ess-indent-offset 2)))
(setq-default c-basic-offset 2)
and then not need to set it in the hook. The general answer is "no", as wasamasa has already written.c-basic-offset
per buffer.prog-mode
hook that tries multiple variable names and sets whichever one looks like the indentation setting, but that's a hacky way to go about it.