@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 Free Software Foundation, Inc.
+Copyright @copyright{} 1995-2011 Free Software Foundation, Inc.
@quotation
Permission is granted to copy, distribute and/or modify this document
-under the terms of the GNU Free Documentation License, Version 1.2 or
+under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with the Front-Cover texts being ``A GNU Manual'',
and with the Back-Cover Texts as in (a) below. A copy of the license
@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 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@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 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@comment This appears only in the Info file, not the printed manual.
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+@summarycontents
+@contents
+
@node Top, Introduction, (dir), (dir)
@comment node-name, next, previous, up
-@ifinfo
+@ifnottex
@top @ccmode{}
@ccmode{} is a GNU Emacs mode for editing files containing C, C++,
has several handy commands and some minor modes to make the editing
easier. It does not provide tools to look up and navigate between
functions, classes etc - there are other packages for that.
-@end ifinfo
+
+@insertcopying
+@end ifnottex
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
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
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
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
@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}
@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
@item
@table @asis
@item Style
+@itemx File Style@footnote{In earlier versions of @ccmode{}, a File Style setting took precedence over any other setting apart from a File Local Variable setting.}
@itemx Top-level command or ``customization interface''
@itemx Hook
-@itemx File Style
+@itemx File Local Variable setting
@end table
@end itemize
See @ref{Styles} for fuller details on using @ccmode{} styles and how
to create them.
+@item File Local Variable setting
+A @dfn{file local variable setting} is a setting which applies to an
+individual source file. You put this in a @dfn{local variables list},
+a special block at the end of the source file (@pxref{Specifying File
+Variables,,, @emacsman{}}).
+
@item File Styles
A @dfn{file style} is a rarely used variant of the ``style'' mechanism
-described above, which applies to an individual source file. To use
-it, you set certain Emacs local variables in a special block at the
-end of the source file. @xref{File Styles}.
+described above, which applies to an individual source file.
+@xref{File Styles}. You use this by setting certain special variables
+in a local variables list (@pxref{Specifying File Variables,,,
+@emacsman{}}).
@item Hooks with Styles
For ultimate flexibility, you can use hooks and styles together. For
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
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 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
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
variable is virtually always non-@code{nil} anyhow, you're unlikely to
notice this effect.}.
-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 (@pxref{CC Hooks}). If you
-use @code{c-file-style} or @code{c-file-offsets} and also explicitly
-set a style variable in a local variable block, the explicit setting
-will take priority.
-
+If you set any variable by the file local variables mechanism, that
+setting takes priority over all other settings, even those in your
+mode hooks (@pxref{CC Hooks}). Any individual setting of a variable
+will override one made through @code{c-file-style} or
+@code{c-file-offsets}.
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@node Custom Filling and Breaking, Custom Auto-newlines, Config Basics, Top
@comment node-name, next, previous, up
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
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}.
@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 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@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}.
@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 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
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 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@comment Epilogue.
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-@iftex
-@page
-@summarycontents
-@contents
-@end iftex
-
@bye
-
-@ignore
- arch-tag: c4cab162-5e57-4366-bdce-4a9db2fc97f0
-@end ignore