Previous: Older Modes, Up: CC Mode [Contents][Index]
A very brief introduction is included here on customizing CC Mode. CC Mode has many features, including useful minor modes, that are completely documented in its own manual.
CC Mode implements several different “styles” for C code (and the
other languages supported by CC Mode). If you need to change the
indentation style for CC Mode it is recommended that you first see if an
existing style meets your requirements. The style chosen will affect the
placement of language elements like braces, function declarations and
comments. You can choose a style interactively by typing C-c . and
pressing the space bar at the prompt to get a list of supported
styles. C-c . runs the function c-set-style
which applies
to all CC Mode language modes though its name might suggest otherwise. A
few of the the supported styles are listed below.
The default style in SXEmacs is “gnu” except for Java mode where it
is the “java” style (this is governed by the variable
c-default-style
).
The styles included in CC Mode all use a buffer local variable called
c-basic-offset
as the basic indentation level (this buffer local
variable is used in all CC Mode language modes though its name might
suggest otherwise). All indentation is, by default, expressed in
multiples of c-basic-offset
.
Each style defines a default value for c-basic-offset
, for the
“gnu” style sets it to 2. A very common customization scenario is
where a user wants to use an existing style but with a different basic
offset value. An easy way to do this is to set c-basic-offset
in
the language mode hook after selecting the chosen style.
For example, a user might want to follow a local coding convention of using the “k&r” style for C code with indentation in two columns multiples (instead of the five column default provided by the CC Mode “k&r” style). This can be achieved with the following code in the initialization file (see Init File)
(defun my-c-mode-hook () (c-set-style "k&r") (setq c-basic-offset 2)) (add-hook 'c-mode-hook 'my-c-mode-hook)
Most customizations for indentation in various CC modes can be
accomplished by choosing a style and then choosing value for
c-basic-offset
that meets the local coding convention. CC Mode
has a very customizable indentation engine and a furthur discussion is
really beyond the scope of this manual. See Indentation
Engine in The CC Mode Manual.
Previous: Older Modes, Up: CC Mode [Contents][Index]