Emacs has a feature where it can automatically convert leading spaces to tabs. This is controlled by the indent-tabs-mode variable. I find mixing tabs and spaces extremely annoying as graphical diff tools will often display a tab and an equivalent number of spaces differently. Therefore I like to disable this behaviour. However, the obvious solution doesn’t work.
(setq indent-tabs-mode nil)
The documentation explains the reason
I’m surprised it works like this. Fortunately, there is a simple fix:
(customize-set-variable 'indent-tabs-mode nil)
If it wasn’t a customizable variable1 you might use something similar to the following.
(add-hook 'first-change-hook (lambda () (setq indent-tabs-mode nil)))
(setq-default ...) looks like a better solution. Thanks to Ron for the tip.
(setq-default 'indent-tabs-mode nil)
1. Is this even possible for a variable that automatically becomes buffer-local when set?