Emacs Spaces Not Tabs

Why You Should Use Spaces Not Tabs

Tabs are not handled the same way by all text editors. The length of a tab varies. If you use tabs, you often end with some spaces and some tabs. If somebody opens your file in different text editor to the one you used, the tabs may be displayed in a different size. The indentation will differ and will result in confusion.

So, stick to spaces and forget the tabs.

How Many Spaces?

Use 4 spaces, its just right. 2 spaces is too few. 8 is too many.

2 spaces are harder to see. 8 spaces can cause the code to run off the screen.

Most text editors can convert tabs to spaces. Set the indentation to 4 spaces.


Emacs Spaces Not Tabs

To setup Emacs to insert 4 spaces when you hit the tab key, add this to your .emacs file:

(setq-default indent-tabs-mode nil);
(setq default-tab-width 4);

Save the .emacs file and re-start Emacs to for changes to take effect.