Previous: Adding Styles, Up: Styles
The Emacs manual describes how you can customize certain variables on a per-file basis by including a file local variable block at the end of the file (see Local Variables in Files).
So far, you've only seen a functional interface for setting styles in CC Mode, and this can't be used here. CC Mode fills the gap by providing two variables for use in a file's local variable list. Don't use them anywhere else! These allow you to customize the style on a per-file basis:
Set this variable to a style name string in the Local Variables list. From now on, when you visit the file, CC Mode will automatically set the file's style to this one using
c-set-style.
Set this variable (in the Local Variables list) to an association list of the same format as
c-offsets-alist. From now on, when you visit the file, CC Mode will automatically institute these offsets usingc-set-offset.
Note that file style settings (i.e. c-file-style) are applied
before file offset settings
(i.e. c-file-offsets)1.
If you set any variables, including style variables, by the file local
variables mechanism, these settings take priority over all other
settings, even those in your mode hooks (see CC Hooks). If you
use c-file-style or c-file-offsets and also explicitly
set a style variable in a local variable block, the explicit setting
will take priority.
[1] Also, if either of these are set
in a file's local variable section, all the style variable values are
made local to that buffer, even if
c-style-variables-are-local-p is nil. Since this
variable is virtually always non-nil anyhow, you're unlikely to
notice this effect.