ccmode: Style Variables
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. 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 default(1). This “otherwise” happens, for
example, when you’ve set the variable with ‘setq’ at the top level
of your ‘.emacs’ (Config Basics).
• The style variable ‘c-offsets-alist’ (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’ (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
preserved(2). 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.
Built-in Styles, for details.
The style variables are:
Indentation Commands::);
‘c-doc-comment-style’ (Doc Comments);
Filling and Breaking::);
‘c-hanging-braces-alist’ (Hanging Braces);
‘c-hanging-colons-alist’ (Hanging Colons);
‘c-hanging-semi&comma-criteria’ (Hanging Semicolons and Commas);
‘c-cleanup-list’ (Clean-ups);
‘c-basic-offset’ (Customizing Indentation);
‘c-offsets-alist’ (c-offsets-alist);
‘c-comment-only-line-offset’ (Comment Line-Up);
Indentation::);
‘c-backslash-column’, ‘c-backslash-max-column’ (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.