You can see what kind of tabbing is currently in use with M-x describe-variable RET c-indentation-style
(but as the documentation states, don't set this variable directly, instead use M-x c-set-style
).
The variable c-basic-offset
is what controls the tabbing in cc-mode
and its default is set-from-style
which means the tabbing will be inherited from what C style you've set with M-x set-c-style
which will let you choose from a set of built-in styles (see below) or you can create your own style. You can see how the styles are defined with M-x describe-variable RET c-style-alist
and then you can use one of those as a template with M-x c-add-style
.
- gnu - Coding style blessed by the Free Software Foundation for C code in GNU programs.
- k&r - The classic Kernighan and Ritchie style for C code.
- bsd - Also known as “Allman style” after Eric Allman.
- whitesmith - Popularized by the examples that came with Whitesmiths C, an early commercial C compiler.
- stroustrup - The classic Stroustrup style for C++ code.
- ellemtel - Popular C++ coding standards as defined by “Programming in C++, Rules and Recommendations,” Erik Nyquist and Mats Henricson, Ellemtel^1.
- linux - C coding standard for Linux (the kernel).
- python - C coding standard for Python extension modules^2.
- java - The style for editing Java code. Note that the default value for c-default-style installs this style when you enter java-mode.
- awk - The style for editing AWK code. Note that the default value for c-default-style installs this style when you enter awk-mode.
- user - This is a special style created by you. It consists of the factory defaults for all the style variables as modified by the customizations you do either with the Customization interface or by writing setqs and c-set-offsets at the top level of your .emacs file (see Config Basics). The style system creates this style as part of its initialization and doesn't modify it afterwards.
UPDATE:
Others have suggested using the tab key to insert the \t
tab character, but please don't force insertion of the tab character! As one of the creators of StackOverflow says "only a moron would use tabs to format their code". Now that's a bit harsh, but it's worth noting that even the two most giant rivals, Google and Microsoft, agree on this point (even though they recommend a different number of spaces by default).
Google says:
Use only spaces, and indent 2 spaces at a time.
Microsoft says:
Tab characters (\0x09) should not be used in code. All indentation
should be done with 4 space characters.
Also, the emacswiki has a section on Tabs are Evil.
So, go forth and untabify!