Next: Styles, Previous: CC Hooks, Up: Config Basics

### 6.2 Style Variables

The variables that CC Mode's style system control are called style variables. Note that style variables are ordinary Lisp variables, which the style system initializes; you can change their values at any time (e.g. in a hook function). The style system can also set other variables, to some extent. See Styles.

Style variables are handled specially in several ways:

- Style variables are by default buffer-local variables. However, they can instead be made global by setting `c-style-variables-are-local-p` to `nil` before CC Mode is initialized.
- The default global binding of any style variable (with two exceptions - see below) is the special symbol `set-from-style`. When the style system initializes a buffer-local copy of a style variable for a CC Mode buffer, if its global binding is still that symbol then it will be set from the current style. Otherwise it will retain its global default1. This “otherwise” happens, for example, when you've set the variable with `setq` at the top level of your `.emacs` (see Config Basics).
- The style variable `c-offsets-alist` (see c-offsets-alist) is an association list with an element for each syntactic symbol. It's handled a little differently from the other style variables. It's default global binding is the empty list `nil`, rather than `set-from-style`. Before the style system is initialized, you can add individual elements to `c-offsets-alist` by calling `c-set-offset`(see c-offsets-alist) just like you would set other style variables with `setq`. Those elements will then prevail when the style system later initializes a buffer-local copy of `c-offsets-alist`.
- The style variable `c-special-indent-hook` is also handled in a special way. Styles can only add functions to this hook, not remove them, so any global settings you put on it are always preserved2. The value you give this variable in a style definition can be either a function or a list of functions.
- The global bindings of the style variables get captured in the special `user` style when the style system is first initialized. See Built-in Styles, for details.

The style variables are:
`c-indent-comment-alist`, `c-indent-comments-syntactically-p` (see Indentation Commands);
`c-doc-comment-style` (see Doc Comments);
`c-block-comment-prefix`, `c-comment-prefix-regexp` (see Custom Filling and Breaking);
`c-hanging-braces-alist` (see Hanging Braces);
`c-hanging-colons-alist` (see Hanging Colons);
`c-hanging-semi&comma-criteria` (see Hanging Semicolons and Commas);
`c-cleanup-list` (see Clean-ups);
`c-basic-offset` (see Customizing Indentation);
`c-offsets-alist` (see c-offsets-alist);
`c-comment-only-line-offset` (see Comment Line-Up);
`c-special-indent-hook`, `c-label-minimum-indentation` (see Other Indentation);
`c-backslash-column`, `c-backslash-max-column` (see Custom Macros).

#### Footnotes

[1] This is a big change from versions of CC Mode earlier than 5.26, where such settings would get overridden by the style system unless special precautions were taken. That was changed since it was counterintuitive and confusing, especially to novice users. If your configuration depends on the old overriding behavior, you can set the variable `c-old-style-variable-behavior` to non-`nil`.

[2] This did not change in version 5.26.