www.delorie.com/gnu/docs/emacs/cc-mode_24.html   search  
Buy the book!

CC Mode Manual

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.4.1 Built-in Styles

If you're lucky, one of CC Mode's built-in styles might be just what you're looking for. These include:

The default style in all newly created buffers is gnu, but you can change this by setting variable c-default-style. Although the user style is not the default style, any style variable settings you do with the Customization interface or on the top level in your `.emacs' file will by default override the style system, so you don't need to set c-default-style to user to see the effect of these settings.

c-default-style takes either a style name string, or an association list of major mode symbols to style names. Thus you can control exactly which default style is used for which CC Mode language mode. Here are the rules:

  1. When c-default-style is a string, it must be an existing style name as found in c-style-alist. This style is then used for all modes.

  2. When c-default-style is an association list, the current major mode is looked up to find a style name string. In this case, this style is always used exactly as specified and an error will occur if the named style does not exist.

  3. If c-default-style is an association list, but the current major mode isn't found, then the special symbol `other' is looked up. If this value is found, the associated style is used.

  4. If `other' is not found, then the `gnu' style is used.

  5. In all cases, the style described in c-default-style is installed before the language hooks are run, so you can always override this setting by including an explicit call to c-set-style in your language mode hook, or in c-mode-common-hook.

If you'd like to experiment with these built-in styles you can simply type the following in a CC Mode buffer:

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 6. Commands.

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 set c-default-style or do a 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.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003