Styles Adding Styles
If you're lucky, one of CC Mode's built-in styles might be just what you're looking for. These include:
gnu--- coding style blessed by the Free Software Foundation for C code in GNU programs. This is the default style for all newly created buffers, but you can change this by setting the variable
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 .
linux--- C coding standard for Linux development.
python--- C coding standard for Python extension modules.
java--- The style for editing Java code. Note that this style is automatically installed when you enter
user--- This is a special style for several reasons. First, if you customize CC Mode by using either the new Custom interface or by doing
setq's at the top level of your `
.emacs' file, these settings will be captured in the
userstyle. Also, all other styles implicitly inherit their settings from
userstyle. This means that for any styles you add via
c-add-style(See Adding Styles) you need only define the differences between your new style and
Note however that
user style is not the default style.
gnu is the default style for all newly created buffers, but you
can change this by setting variable
c-default-style. Be careful
if you customize CC Mode as described above; since your changes will
be captured in the
user style, you will also have to change
c-default-style to "user" to see the effect of your
If you'd like to experiment with these built-in styles you can simply type the following in a CC Mode buffer:
C-c . STYLE-NAME RET
C-c . runs the command
c-set-style. Note that all style
names are case insensitive, even the ones you define.
Setting a style in this way does not automatically re-indent your file. For commands that you can use to view the effect of your changes, see Commands.
Once you find a built-in style you like, you can make the change
permanent by adding some lisp to your `
.emacs' file. Let's say for
example that you want to use the `
ellemtel' style in all your
files. You would add this:
(defun my-c-mode-common-hook () ;; use Ellemtel style for all C like languages (c-set-style "ellemtel") ;; other customizations can go here ) (add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
Note that for BOCM compatibility, `
gnu' is the default
style, and any non-style based customizations you make (i.e. in
c-mode-common-hook in your
.emacs' file) will be based on `
gnu' style unless you do
c-set-style as the first thing in your hook. The variable
c-indentation-style always contains the buffer's current style name,
as a string.
 This document is ftp'able from
 Python is a high level scripting language with a C/C++ foreign function interface. For more information, see