I would like to have an .emacs setting so that tabs are always formed by consecutive spaces. Preferably in each possible mode. In other editors it never seemed a problem, but in .emacs I'm a bit stuck with the tabs I'm afraid.
Asked
Active
Viewed 1.3k times
2 Answers
57
add this in your .emacs:
(setq-default indent-tabs-mode nil)
or you can define a before-save-hook that eliminate hard tabs

dfa
- 114,442
- 31
- 189
- 228
-
I don't know who voted you down, it works fine for me, at least in textmode, other modes I haven't tried. Tx. – Peter Jun 18 '09 at 14:21
-
It would be great to have the exact syntax for the `before-save-hook`, please & thanks – Reb.Cabin Feb 14 '18 at 17:59
39
Also of use, M-x untabify
, which will convert all the tabs into spaces in the current region. You can use this to get rid of the existing tabs in files you've edited before you had the indent-tabs-mode
set properly.
C-x h (M-x mark-whole-buffer)
M-x untabify

Trey Jackson
- 73,529
- 11
- 197
- 229
-
+1 for usefull indeed,(although I used that exact combination of commands already :-)) – Peter Jun 18 '09 at 15:46
-
5@dfa, that might not be a good idea. For example if you are editing make file :) – Jesper.Reenberg Nov 30 '11 at 20:26
-
I'm doing this in `ruby-mode`/`rspec-mode` and emacs is still converting some of my spaces to tabs.. – nnyby Jan 14 '14 at 23:59
-
3Nevermind -- I got around this with an "untabify on save" hook -- http://www.emacswiki.org/emacs/UntabifyUponSave – nnyby Jan 15 '14 at 00:10