Doing Tabs In Emacs

2006-10-25

As you may know I like using the emacs editor (I use vi too - so please no wars). In general I love the key bindings and the elegant power built into the editor. One of the things that bothers me about it though is it tries to help too much when I hit tab. When I press the tab key, I want a tab. That’s why it’s the tab key.

I don’t want spaces that pretend to be tabs, and I don’t want a combination of spaces and tab characters that supposedly line up my code better; I just want a tab. To be a bit cynical, when I press the letter t, does it produce “tee” in the editor; no, it just makes a “t” - because it’s the t key.

I’ve always just kind of sighed and kept going in the past, but I decided to try to find a way to make emacs add a tab when I press the tab key. After a bit of searching, I found a few commands you can add to your ~/.emacs or ~/Library/Preferences/Aquamacs Emacs/customizations.el file to get a tab to be a tab:

The default tab width on emacs is 8 (which is huge), so this sets it to 4. If you prefer a different size change the last 2 commands to reflect the different size.

One draw back to this is you lose auto indent. My lisp skills are more-or-less zero, so if anyone knows how to do “get the indention of the previous line and add that to the beginning of a new line” in emacspeak I’d love to know how to do that. While that’s not the most optimal indention scheme, it works 90% of the time for me.