If you work with other on text files, you often run into the problem that one of the programmers is using tabs set to 4, another to 8 spaces. For this reason, I always save my files without tabs. In Emacs there is a command to do this “untabify-buffer”, but I usually forget to do this.
Searching the internet I found the following code at stackoverflow.com, to do it automatically as soon as you save the file.
(defun untabify-buffer ()
"Untabify current buffer"
(untabify (point-min) (point-max)))
(defun progmodes-hooks ()
"Hooks for programming modes"
(add-hook 'before-save-hook 'progmodes-write-hooks))
(defun progmodes-write-hooks ()
"Hooks which run on file write for programming modes"
(add-hook 'gams-mode-hook 'progmodes-hooks)
(add-hook 'ess-mode-hook 'progmodes-hooks)
(add-hook 'python-mode-hook 'progmodes-hooks)
You can define your own hooks for other modes.
If you would use the untabify-buffer as a common hook, you can run into problems, because every file will be untabified.