Indentation Calculation Custom C Indent Syntactic Symbols
There are two ways to customize the indentation style for the C-like 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 Syntactic Symbols, for a list of all defined syntactic symbols.
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
Set the indentation offset for syntactic symbol symbol
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, a list, or one of the following symbols:
/, 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 buffer position, if any. The function should return an integer
If the offset value is a list, its elements are processed according
to the rules above until a non-
nil value is found. That value is
then added to the total indentation in the normal manner. The primary
use for this is to combine the results of several functions.
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 Syntactic Symbols, for a list of valid syntactic symbols and their meanings.