ccmode: Adding Styles

 
 6.3.3 Adding and Amending Styles
 --------------------------------
 
 If none of the built-in styles is appropriate, you’ll probably want to
 create a new “style definition”, possibly based on an existing style.
 To do this, put the new style’s settings into a list with the following
 format; the list can then be passed as an argument to the function
 ‘c-add-style’.  You can see an example of a style definition in See
 Sample Init File.
 
 Structure of a Style Definition List
      ([BASE-STYLE] [(VARIABLE .  VALUE) ...])
 
      Optional BASE-STYLE, if present, must be a string which is the name
      of the “base style” from which this style inherits.  At most one
      BASE-STYLE is allowed in a style definition.  If BASE-STYLE is not
      specified, the style inherits from the table of factory default
      values(1) instead.  All styles eventually inherit from this
      internal table.  Style loops generate errors.  The list of
      pre-existing styles can be seen in SeeBuilt-in Styles.
 
      The dotted pairs (VARIABLE .  VALUE) each consist of a variable and
      the value it is to be set to when the style is later activated.(2)
      The variable can be either a CC Mode style variable or an arbitrary
      Emacs variable.  In the latter case, it is _not_ made buffer-local
      by the CC Mode style system.
 
      Two variables are treated specially in the dotted pair list:
 
      ‘c-offsets-alist’
           The value is in turn a list of dotted pairs of the form
 
                (SYNTACTIC-SYMBOL . OFFSET)
 
           as described in Seec-offsets-alist.  These are passed to
           ‘c-set-offset’ so there is no need to set every syntactic
           symbol in your style, only those that are different from the
           inherited style.
 
      ‘c-special-indent-hook’
           The value is added to ‘c-special-indent-hook’ using
           ‘add-hook’, so any functions already on it are kept.  If the
           value is a list, each element of the list is added with
           ‘add-hook’.
 
    Styles are kept in the ‘c-style-alist’ variable, but you should never
 modify this variable directly.  Instead, CC Mode provides the function
 ‘c-add-style’ for this purpose.
 
  -- Function: c-add-style stylename description &optional set-p
      Add or update a style called STYLENAME, a string.  DESCRIPTION is
      the new style definition in the form described above.  If STYLENAME
      already exists in ‘c-style-alist’ then it is replaced by
      DESCRIPTION.  (Note, this replacement is total.  The old style is
      _not_ merged into the new one.)  Otherwise, a new style is added.
 
      If the optional SET-P is non-‘nil’ then the new style is applied to
      the current buffer as well.  The use of this facility is deprecated
      and it might be removed from CC Mode in a future release.  You
      should use ‘c-set-style’ instead.
 
      The sample ‘.emacs’ file provides a concrete example of how a new
      style can be added and automatically set.  SeeSample Init
      File.
 
  -- Variable: c-style-alist
      This is the variable that holds the definitions for the styles.  It
      should not be changed directly; use ‘c-add-style’ instead.
 
    ---------- Footnotes ----------
 
    (1) This table is stored internally in the variable c-fallback-style.
 
    (2) Note that if the variable has been given a value by the
 Customization interface or a ‘setq’ at the top level of your ‘.emacs’,
 this value will override the one the style system tries to give it.
 SeeConfig Basics.