Next: File Styles, Previous: Adding Styles, Up: Styles
Instead of specifying a style, you can get CC Mode to guess your style by examining an already formatted code buffer. CC Mode then determines the ”most frequent” offset (see c-offsets-alist) for each of the syntactic symbols (see Indentation Engine Basics) encountered in the buffer, and the ”most frequent” value of c-basic-offset (see Customizing Indentation), then merges the current style with these ”guesses” to form a new style. This combined style is known as the guessed style.
To do this, call c-guess (or one of the other 5 guessing
commands) on your sample buffer. The analysis of your code may take
some time.
You can then set the guessed style in any CC Mode buffer with
c-guess-install. You can display the style with
c-guess-view, and preserve it by copying it into your
.emacs for future use, preferably after editing it.
The part of the buffer examined is either the region
(c-guess-region-no-install), the entire buffer
(c-guess-buffer-no-install), or the first
c-guess-region-max bytes (c-guess-no-install).
Each of these commands can be given an optional prefix argument. This instructs CC Mode to combine the new guesses with the current guesses before forming the guessed style.
The part of the buffer examined is either the region
(c-guess-region), the entire buffer (c-guess-buffer), or
the first c-guess-region-max bytes (c-guess).
Each of these commands can be given an optional prefix argument. This instructs CC Mode to combine the new guesses with the current guesses before forming the guessed style.
This variable, default 50000, is the size in bytes of the buffer portion examined by c-guess and c-guess-no-install. If set to
nil, the entire buffer is examined.
This variable, default 10, is the maximum offset, either outwards or inwards, which will be taken into account by the analysis process. Any offset bigger than this will be ignored. For no limit, set this variable to a large number.
c-add-style form (see Adding Styles) which can be easily copied to your .emacs. You will
probably want to edit it first.
The display of the guessed style contains these elements: