]> code.delx.au - gnu-emacs/blobdiff - doc/misc/cc-mode.texi
Merge from trunk.
[gnu-emacs] / doc / misc / cc-mode.texi
index 6b72c69e05b83b44fd66dbbf6462c2d5febf9c41..a9339162666d38ece461a6f9a1c9c94cd624c031 100644 (file)
@@ -159,8 +159,7 @@ CC Mode
 @copying
 This manual is for CC Mode in Emacs.
 
-Copyright @copyright{} 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010  Free Software Foundation, Inc.
+Copyright @copyright{} 1995-2011  Free Software Foundation, Inc.
 
 @quotation
 Permission is granted to copy, distribute and/or modify this document
@@ -178,10 +177,10 @@ developing GNU and promoting software freedom.''
 
 @comment Info directory entry for use by install-info. The indentation
 @comment here is by request from the FSF folks.
-@dircategory Emacs
+@dircategory Emacs editing modes
 @direntry
-* CC Mode: (ccmode).    Emacs mode for editing C, C++, Objective-C,
-                        Java, Pike, AWK, and CORBA IDL code.
+* CC Mode: (ccmode).            Emacs mode for editing C, C++, Objective-C,
+                                Java, Pike, AWK, and CORBA IDL code.
 @end direntry
 
 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -201,9 +200,8 @@ developing GNU and promoting software freedom.''
 @vskip 0pt plus 1filll
 @insertcopying
 
-This manual was generated from cc-mode.texi, which can be downloaded
-from
-@url{http://cvs.savannah.gnu.org/viewcvs/emacs/emacs/doc/misc/cc-mode.texi}.
+This manual was generated from cc-mode.texi, which is distributed with Emacs,
+or can be downloaded from @url{http://savannah.gnu.org/projects/emacs/}.
 @end titlepage
 
 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -289,10 +287,11 @@ Configuration Basics
 
 Styles
 
-* Built-in Styles::
-* Choosing a Style::
-* Adding Styles::
-* File Styles::
+* Built-in Styles::             
+* Choosing a Style::            
+* Adding Styles::               
+* Guessing the Style::          
+* File Styles::                 
 
 Customizing Auto-newlines
 
@@ -312,19 +311,19 @@ Indentation Engine Basics
 
 Syntactic Symbols
 
-* Function Symbols::
-* Class Symbols::
-* Conditional Construct Symbols::
-* Switch Statement Symbols::
-* Brace List Symbols::
-* External Scope Symbols::
-* Paren List Symbols::
-* Literal Symbols::
-* Multiline Macro Symbols::
-* Objective-C Method Symbols::
-* Anonymous Class Symbol::
-* Statement Block Symbols::
-* K&R Symbols::
+* Function Symbols::            
+* Class Symbols::               
+* Conditional Construct Symbols::  
+* Switch Statement Symbols::    
+* Brace List Symbols::          
+* External Scope Symbols::      
+* Paren List Symbols::          
+* Literal Symbols::             
+* Multiline Macro Symbols::     
+* Objective-C Method Symbols::  
+* Java Symbols::
+* Statement Block Symbols::     
+* K&R Symbols::                 
 
 Customizing Indentation
 
@@ -1012,7 +1011,7 @@ capitalized word.  With prefix argument @var{n}, move @var{n} times.
 If @var{n} is negative, move in the opposite direction.
 
 Note that these two commands have been superseded by
-@code{c-subword-mode}, which you should use instead.  @xref{Subword
+@code{subword-mode}, which you should use instead.  @xref{Subword
 Movement}.  They might be removed from a future release of @ccmode{}.
 @end table
 
@@ -1194,10 +1193,9 @@ Toggle hungry-delete minor mode.
 @findex toggle-auto-hungry-state (c-)
 Toggle both auto-newline and hungry delete minor modes.
 
-@item @kbd{C-c C-w} (@code{M-x c-subword-mode})
+@item @kbd{C-c C-w} (@code{M-x subword-mode})
 @kindex C-c C-w
-@findex c-subword-mode
-@findex subword-mode (c-)
+@findex subword-mode
 Toggle subword mode.
 
 @item @kbd{M-x c-toggle-syntactic-indentation}
@@ -1694,11 +1692,11 @@ mode turn on automatically, put the following code in your
 
 @example
 (add-hook 'c-mode-common-hook
-          (lambda () (c-subword-mode 1)))
+          (lambda () (subword-mode 1)))
 @end example
 
-As a bonus, you can also use @code{c-subword-mode} in non-@ccmode{}
-buffers by typing @kbd{M-x c-subword-mode}.
+As a bonus, you can also use @code{subword-mode} in non-@ccmode{}
+buffers by typing @kbd{M-x subword-mode}.
 
 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 @node    Other Commands,  , Subword Movement, Commands
@@ -2514,14 +2512,18 @@ groupings of customizations called @dfn{styles}, associate a single name
 for any particular style, and pretty easily start editing new or
 existing code using these styles.
 
+As an alternative to writing a style definition yourself, you can have
+@ccmode{} @dfn{guess} (at least part of) your style by looking at an
+already formatted piece of your code, @ref{Guessing the Style}.
+
 @menu
-* Built-in Styles::
-* Choosing a Style::
-* Adding Styles::
-* File Styles::
+* Built-in Styles::             
+* Choosing a Style::            
+* Adding Styles::               
+* Guessing the Style::          
+* File Styles::                 
 @end menu
 
-
 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 @node    Built-in Styles, Choosing a Style, Styles, Styles
 @comment node-name, next, previous, up
@@ -2656,9 +2658,8 @@ This variable always contains the buffer's current style name, as a
 string.
 @end defvar
 
-
 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-@node    Adding Styles, File Styles, Choosing a Style, Styles
+@node    Adding Styles, Guessing the Style, Choosing a Style, Styles
 @comment node-name, next, previous, up
 @subsection Adding and Amending Styles
 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -2745,9 +2746,131 @@ This is the variable that holds the definitions for the styles.  It
 should not be changed directly; use @code{c-add-style} instead.
 @end defvar
 
+@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+@node    Guessing the Style, File Styles, Adding Styles, Styles
+@comment node-name, next, previous, up
+@subsection Guessing the Style
+@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+Instead of specifying a style, you can get @ccmode{} to @dfn{guess}
+your style by examining an already formatted code buffer.  @ccmode{}
+then determines the ''most frequent'' offset (@pxref{c-offsets-alist})
+for each of the syntactic symbols (@pxref{Indentation Engine Basics})
+encountered in the buffer, and the ''most frequent'' value of
+c-basic-offset (@pxref{Customizing Indentation}), then merges the
+current style with these ''guesses'' to form a new style.  This
+combined style is known as the @dfn{guessed style}.
+
+To do this, call @code{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 @ccmode{} buffer with
+@code{c-guess-install}.  You can display the style with
+@code{c-guess-view}, and preserve it by copying it into your
+@file{.emacs} for future use, preferably after editing it.
+
+@table @asis
+@item @kbd{M-x c-guess-no-install}
+@itemx @kbd{M-x c-guess-buffer-no-install}
+@itemx @kbd{M-x c-guess-region-no-install}
+@findex c-guess-no-install
+@findex c-guess-buffer-no-install
+@findex c-guess-region-no-install
+@findex guess-no-install (c-)
+@findex guess-buffer-no-install (c-)
+@findex guess-region-no-install (c-)
+These commands analyze a part of the current buffer and guess the
+style from it.
+
+The part of the buffer examined is either the region
+(@code{c-guess-region-no-install}), the entire buffer
+(@code{c-guess-buffer-no-install}), or the first
+@code{c-guess-region-max} bytes (@code{c-guess-no-install}).
+
+Each of these commands can be given an optional prefix argument.  This
+instructs @ccmode{} to combine the new guesses with the current
+guesses before forming the guessed style.
+@end table
+
+@table @asis
+@item @kbd{M-x c-guess}
+@itemx @kbd{M-x c-guess-buffer}
+@itemx @kbd{M-x c-guess-region}
+@findex c-guess
+@findex c-guess-buffer
+@findex c-guess-region
+@findex guess (c-)
+@findex guess-buffer (c-)
+@findex guess-region (c-)
+These commands analyze a part of the current buffer, guess the style
+from it, then install the guessed style on the buffer.  The guessed
+style is given a name based on the buffer's absolute file name, and
+you can then set this style on any @ccmode{} buffer with @kbd{C-c .}.
+
+The part of the buffer examined is either the region
+(@code{c-guess-region}), the entire buffer (@code{c-guess-buffer}), or
+the first @code{c-guess-region-max} bytes (@code{c-guess}).
+
+Each of these commands can be given an optional prefix argument.  This
+instructs @ccmode{} to combine the new guesses with the current
+guesses before forming the guessed style.
+@end table
+
+@defopt c-guess-region-max
+@vindex guess-region-max (c-)
+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
+@code{nil}, the entire buffer is examined.
+@end defopt
+
+@defopt c-guess-offset-threshold
+@vindex guess-offset-threshold (c-)
+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.
+@end defopt
+
+@table @asis
+@item  @kbd{M-x c-guess-install}
+@findex c-guess-install
+@findex guess-install (c-)
+
+Set the current buffer's style to the guessed style.  This prompts you
+to enter an optional new style name to give to the guessed style.  By
+default, this name is based on the buffer's absolute file name.  You
+can then use this style like any other.
+
+@item  @kbd{M-x c-guess-view}
+@findex c-guess-view
+@findex guess-view (c-)
+Display the most recently guessed style in a temporary buffer.  This
+display is in the form of a @code{c-add-style} form (@pxref{Adding
+Styles}) which can be easily copied to your @file{.emacs}.  You will
+probably want to edit it first.
+
+The display of the guessed style contains these elements:
+
+@table @asis
+@item Placeholder Name
+You should replace this with a style name of your own.
+@item Parent Style
+The style current when the guessing began, from which the guessed
+style inherits (@pxref{Config Basics}) the settings which weren't
+guessed.
+@item Guessed Offsets
+These are the core result of the guessing process.  Each of them is
+marked by a comment.
+@item Inherited Offsets
+These are syntactic offsets which have been taken over from the parent
+style.  To avoid possible future conflicts, you should remove either
+these offsets or the parent style name.
+@end table
+@end table
 
 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-@node    File Styles,  , Adding Styles, Styles
+@node    File Styles,  , Guessing the Style, Styles
 @comment node-name, next, previous, up
 @subsection File Styles
 @cindex styles, file local
@@ -3972,6 +4095,9 @@ The first line in a ``topmost'' definition.  @ref{Function Symbols}.
 Topmost definition continuation lines.  This is only used in the parts
 that aren't covered by other symbols such as @code{func-decl-cont} and
 @code{knr-argdecl}.  @ref{Function Symbols}.
+@item annotation-top-cont
+Topmost definition continuation lines where all previous items are
+annotations.  @ref{Java Symbols}.
 @item member-init-intro
 First line in a member initialization list.  @ref{Class Symbols}.
 @item member-init-cont
@@ -4000,6 +4126,9 @@ with an open brace.  @ref{Brace List Symbols}.
 A statement.  @ref{Function Symbols}.
 @item statement-cont
 A continuation of a statement.  @ref{Function Symbols}.
+@item annotation-var-cont
+A continuation of a statement where all previous items are
+annotations.  @ref{Java Symbols}.
 @item statement-block-intro
 The first line in a new statement block.  @ref{Conditional Construct
 Symbols}.
@@ -4113,23 +4242,23 @@ Symbols}.
 @item inexpr-class
 A class definition inside an expression.  This is used for anonymous
 classes in Java.  It's also used for anonymous array initializers in
-Java.  @ref{Anonymous Class Symbol}.
+Java.  @ref{Java Symbols}.
 @end table
 
 @menu
-* Function Symbols::
-* Class Symbols::
-* Conditional Construct Symbols::
-* Switch Statement Symbols::
-* Brace List Symbols::
-* External Scope Symbols::
-* Paren List Symbols::
-* Literal Symbols::
-* Multiline Macro Symbols::
-* Objective-C Method Symbols::
-* Anonymous Class Symbol::
-* Statement Block Symbols::
-* K&R Symbols::
+* Function Symbols::            
+* Class Symbols::               
+* Conditional Construct Symbols::  
+* Switch Statement Symbols::    
+* Brace List Symbols::          
+* External Scope Symbols::      
+* Paren List Symbols::          
+* Literal Symbols::             
+* Multiline Macro Symbols::     
+* Objective-C Method Symbols::  
+* Java Symbols::
+* Statement Block Symbols::     
+* K&R Symbols::                 
 @end menu
 
 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -4234,7 +4363,7 @@ Hitting @kbd{C-c C-s} on line 5 shows the following analysis:
 
 @noindent
 The primary syntactic symbol for this line is @code{access-label} as
-this a label keyword that specifies access protection in C++.  However,
+this is a label keyword that specifies access protection in C++.  However,
 because this line is also a top-level construct inside a class
 definition, the analysis actually shows two syntactic symbols.  The
 other syntactic symbol assigned to this line is @code{inclass}.
@@ -4741,7 +4870,7 @@ macros.}.
 @xref{Custom Macros}, for more info about the treatment of macros.
 
 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-@node    Objective-C Method Symbols, Anonymous Class Symbol, Multiline Macro Symbols, Syntactic Symbols
+@node    Objective-C Method Symbols, Java Symbols, Multiline Macro Symbols, Syntactic Symbols
 @comment node-name, next, previous, up
 @subsection Objective-C Method Symbols
 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -4768,34 +4897,45 @@ assigned @code{objc-method-args-cont} syntax.  Lines 5 and 6 are both
 assigned @code{objc-method-call-cont} syntax.
 
 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-@node    Anonymous Class Symbol, Statement Block Symbols, Objective-C Method Symbols, Syntactic Symbols
+@node    Java Symbols, Statement Block Symbols, Objective-C Method Symbols, Syntactic Symbols
 @comment node-name, next, previous, up
-@subsection Anonymous Class Symbol (Java)
+@subsection Java Symbols
 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
 Java has a concept of anonymous classes which can look something like
 this:
 
 @example
- 1: public void watch(Observable o) @{
- 2:     o.addObserver(new Observer() @{
- 3:             public void update(Observable o, Object arg) @{
- 4:                 history.addElement(arg);
- 5:             @}
- 6:         @});
- 7: @}
+ 1:  @@Test
+ 2:  public void watch(Observable o) @{
+ 3:      @@NonNull
+ 4:      Observer obs = new Observer() @{
+ 5:          public void update(Observable o, Object arg) @{
+ 6:              history.addElement(arg);
+ 7:          @}
+ 8:      @};
+ 9:      o.addObserver(obs);
+ 10: @}
 @end example
 
 @ssindex inexpr-class
 The brace following the @code{new} operator opens the anonymous class.
-Lines 3 and 6 are assigned the @code{inexpr-class} syntax, besides the
+Lines 5 and 8 are assigned the @code{inexpr-class} syntax, besides the
 @code{inclass} symbol used in normal classes.  Thus, the class will be
 indented just like a normal class, with the added indentation given to
 @code{inexpr-class}.  An @code{inexpr-class} syntactic element doesn't
 have an anchor position.
 
+@ssindex annotation-top-cont
+@ssindex annotation-var-cont
+Line 2 is assigned the @code{annotation-top-cont} syntax, due to it being a
+continuation of a topmost introduction with an annotation symbol preceding
+the current line.  Similarly, line 4 is assigned the @code{annotation-var-cont}
+syntax due to it being a continuation of a variable declaration where preceding
+the declaration is an annotation.
+
 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-@node    Statement Block Symbols, K&R Symbols, Anonymous Class Symbol, Syntactic Symbols
+@node    Statement Block Symbols, K&R Symbols, Java Symbols, Syntactic Symbols
 @comment node-name, next, previous, up
 @subsection Statement Block Symbols
 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -6998,7 +7138,3 @@ Since most @ccmode{} variables are prepended with the string
 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
 @bye
-
-@ignore
-   arch-tag: c4cab162-5e57-4366-bdce-4a9db2fc97f0
-@end ignore