Go to the first, previous, next, last section, table of contents.


Changing Indentation Style

There are two ways to customize the indentation style for the C modes. First, you can select one of several predefined styles, each of which specifies offsets for all the syntactic symbols. For more flexibility, you can customize the handling of individual syntactic symbols. See section Syntactic Symbols, for a list of all defined syntactic symbols.

M-x c-set-style RET style RET
Select predefined indentation style style. Type ? when entering style to see a list of supported styles; to find out what a style looks like, select it and reindent some C code.
C-c C-o symbol RET offset RET
Set the indentation offset for syntactic symbol symbol (c-set-offset). The second argument offset specifies the new indentation offset.

The c-offsets-alist variable controls the amount of indentation to give to each syntactic symbol. Its value is an association list, and each element of the list has the form (syntactic-symbol . offset). By changing the offsets for various syntactic symbols, you can customize indentation in fine detail. To change this alist, use c-set-offset (see below).

Each offset value in c-offsets-alist can be an integer, a function or variable name, or one of the following symbols: +, -, ++, or --, indicating positive or negative multiples of the variable c-basic-offset. Thus, if you want to change the levels of indentation to be 3 spaces instead of 2 spaces, set c-basic-offset to 3.

Using a function as the offset value provides the ultimate flexibility in customizing indentation. The function is called with a single argument containing the cons of the syntactic symbol and the relative indent point. The function should return an integer offset.

The command C-c C-o (c-set-offset) is the easiest way to set offsets, both interactively or in your `~/.emacs' file. First specify the syntactic symbol, then the offset you want. See section Syntactic Symbols, for a list of valid syntactic symbols and their meanings.


Go to the first, previous, next, last section, table of contents.