aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2011-07-01 09:42:55 +0000
committerAlan Mackenzie2011-07-01 09:42:55 +0000
commit847ccf7c88ee51274282fc4f72e1bb626792dba1 (patch)
treeed95fe6a6bdec4c0d35d92849ff60353e6e716f3
parent0949d2b6ba1027bce991b2f3f7a4ce92b7adf620 (diff)
downloademacs-847ccf7c88ee51274282fc4f72e1bb626792dba1.tar.gz
emacs-847ccf7c88ee51274282fc4f72e1bb626792dba1.zip
cc-mode.texi (Guessing the Style): New page.
(Styles): Add a short introduction to above.
-rw-r--r--doc/misc/ChangeLog5
-rw-r--r--doc/misc/cc-mode.texi150
2 files changed, 143 insertions, 12 deletions
diff --git a/doc/misc/ChangeLog b/doc/misc/ChangeLog
index 2e0e28e9827..583bdb411bb 100644
--- a/doc/misc/ChangeLog
+++ b/doc/misc/ChangeLog
@@ -1,3 +1,8 @@
12011-07-01 Alan Mackenzie <acm@muc.de>
2
3 * cc-mode.texi (Guessing the Style): New page.
4 (Styles): Add a short introduction to above.
5
12011-06-28 Deniz Dogan <deniz@dogan.se> 62011-06-28 Deniz Dogan <deniz@dogan.se>
2 7
3 * rcirc.texi (Configuration): Bug-fix: 8 * rcirc.texi (Configuration): Bug-fix:
diff --git a/doc/misc/cc-mode.texi b/doc/misc/cc-mode.texi
index 9ae9abd5e1a..a9339162666 100644
--- a/doc/misc/cc-mode.texi
+++ b/doc/misc/cc-mode.texi
@@ -287,10 +287,11 @@ Configuration Basics
287 287
288Styles 288Styles
289 289
290* Built-in Styles:: 290* Built-in Styles::
291* Choosing a Style:: 291* Choosing a Style::
292* Adding Styles:: 292* Adding Styles::
293* File Styles:: 293* Guessing the Style::
294* File Styles::
294 295
295Customizing Auto-newlines 296Customizing Auto-newlines
296 297
@@ -2511,14 +2512,18 @@ groupings of customizations called @dfn{styles}, associate a single name
2511for any particular style, and pretty easily start editing new or 2512for any particular style, and pretty easily start editing new or
2512existing code using these styles. 2513existing code using these styles.
2513 2514
2515As an alternative to writing a style definition yourself, you can have
2516@ccmode{} @dfn{guess} (at least part of) your style by looking at an
2517already formatted piece of your code, @ref{Guessing the Style}.
2518
2514@menu 2519@menu
2515* Built-in Styles:: 2520* Built-in Styles::
2516* Choosing a Style:: 2521* Choosing a Style::
2517* Adding Styles:: 2522* Adding Styles::
2518* File Styles:: 2523* Guessing the Style::
2524* File Styles::
2519@end menu 2525@end menu
2520 2526
2521
2522@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 2527@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2523@node Built-in Styles, Choosing a Style, Styles, Styles 2528@node Built-in Styles, Choosing a Style, Styles, Styles
2524@comment node-name, next, previous, up 2529@comment node-name, next, previous, up
@@ -2653,9 +2658,8 @@ This variable always contains the buffer's current style name, as a
2653string. 2658string.
2654@end defvar 2659@end defvar
2655 2660
2656
2657@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 2661@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2658@node Adding Styles, File Styles, Choosing a Style, Styles 2662@node Adding Styles, Guessing the Style, Choosing a Style, Styles
2659@comment node-name, next, previous, up 2663@comment node-name, next, previous, up
2660@subsection Adding and Amending Styles 2664@subsection Adding and Amending Styles
2661@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 2665@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -2742,9 +2746,131 @@ This is the variable that holds the definitions for the styles. It
2742should not be changed directly; use @code{c-add-style} instead. 2746should not be changed directly; use @code{c-add-style} instead.
2743@end defvar 2747@end defvar
2744 2748
2749@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2750@node Guessing the Style, File Styles, Adding Styles, Styles
2751@comment node-name, next, previous, up
2752@subsection Guessing the Style
2753@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2754
2755Instead of specifying a style, you can get @ccmode{} to @dfn{guess}
2756your style by examining an already formatted code buffer. @ccmode{}
2757then determines the ''most frequent'' offset (@pxref{c-offsets-alist})
2758for each of the syntactic symbols (@pxref{Indentation Engine Basics})
2759encountered in the buffer, and the ''most frequent'' value of
2760c-basic-offset (@pxref{Customizing Indentation}), then merges the
2761current style with these ''guesses'' to form a new style. This
2762combined style is known as the @dfn{guessed style}.
2763
2764To do this, call @code{c-guess} (or one of the other 5 guessing
2765commands) on your sample buffer. The analysis of your code may take
2766some time.
2767
2768You can then set the guessed style in any @ccmode{} buffer with
2769@code{c-guess-install}. You can display the style with
2770@code{c-guess-view}, and preserve it by copying it into your
2771@file{.emacs} for future use, preferably after editing it.
2772
2773@table @asis
2774@item @kbd{M-x c-guess-no-install}
2775@itemx @kbd{M-x c-guess-buffer-no-install}
2776@itemx @kbd{M-x c-guess-region-no-install}
2777@findex c-guess-no-install
2778@findex c-guess-buffer-no-install
2779@findex c-guess-region-no-install
2780@findex guess-no-install (c-)
2781@findex guess-buffer-no-install (c-)
2782@findex guess-region-no-install (c-)
2783These commands analyze a part of the current buffer and guess the
2784style from it.
2785
2786The part of the buffer examined is either the region
2787(@code{c-guess-region-no-install}), the entire buffer
2788(@code{c-guess-buffer-no-install}), or the first
2789@code{c-guess-region-max} bytes (@code{c-guess-no-install}).
2790
2791Each of these commands can be given an optional prefix argument. This
2792instructs @ccmode{} to combine the new guesses with the current
2793guesses before forming the guessed style.
2794@end table
2795
2796@table @asis
2797@item @kbd{M-x c-guess}
2798@itemx @kbd{M-x c-guess-buffer}
2799@itemx @kbd{M-x c-guess-region}
2800@findex c-guess
2801@findex c-guess-buffer
2802@findex c-guess-region
2803@findex guess (c-)
2804@findex guess-buffer (c-)
2805@findex guess-region (c-)
2806These commands analyze a part of the current buffer, guess the style
2807from it, then install the guessed style on the buffer. The guessed
2808style is given a name based on the buffer's absolute file name, and
2809you can then set this style on any @ccmode{} buffer with @kbd{C-c .}.
2810
2811The part of the buffer examined is either the region
2812(@code{c-guess-region}), the entire buffer (@code{c-guess-buffer}), or
2813the first @code{c-guess-region-max} bytes (@code{c-guess}).
2814
2815Each of these commands can be given an optional prefix argument. This
2816instructs @ccmode{} to combine the new guesses with the current
2817guesses before forming the guessed style.
2818@end table
2819
2820@defopt c-guess-region-max
2821@vindex guess-region-max (c-)
2822This variable, default 50000, is the size in bytes of the buffer
2823portion examined by c-guess and c-guess-no-install. If set to
2824@code{nil}, the entire buffer is examined.
2825@end defopt
2826
2827@defopt c-guess-offset-threshold
2828@vindex guess-offset-threshold (c-)
2829This variable, default 10, is the maximum offset, either outwards or
2830inwards, which will be taken into account by the analysis process.
2831Any offset bigger than this will be ignored. For no limit, set this
2832variable to a large number.
2833@end defopt
2834
2835@table @asis
2836@item @kbd{M-x c-guess-install}
2837@findex c-guess-install
2838@findex guess-install (c-)
2839
2840Set the current buffer's style to the guessed style. This prompts you
2841to enter an optional new style name to give to the guessed style. By
2842default, this name is based on the buffer's absolute file name. You
2843can then use this style like any other.
2844
2845@item @kbd{M-x c-guess-view}
2846@findex c-guess-view
2847@findex guess-view (c-)
2848Display the most recently guessed style in a temporary buffer. This
2849display is in the form of a @code{c-add-style} form (@pxref{Adding
2850Styles}) which can be easily copied to your @file{.emacs}. You will
2851probably want to edit it first.
2852
2853The display of the guessed style contains these elements:
2854
2855@table @asis
2856@item Placeholder Name
2857You should replace this with a style name of your own.
2858@item Parent Style
2859The style current when the guessing began, from which the guessed
2860style inherits (@pxref{Config Basics}) the settings which weren't
2861guessed.
2862@item Guessed Offsets
2863These are the core result of the guessing process. Each of them is
2864marked by a comment.
2865@item Inherited Offsets
2866These are syntactic offsets which have been taken over from the parent
2867style. To avoid possible future conflicts, you should remove either
2868these offsets or the parent style name.
2869@end table
2870@end table
2745 2871
2746@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 2872@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2747@node File Styles, , Adding Styles, Styles 2873@node File Styles, , Guessing the Style, Styles
2748@comment node-name, next, previous, up 2874@comment node-name, next, previous, up
2749@subsection File Styles 2875@subsection File Styles
2750@cindex styles, file local 2876@cindex styles, file local