aboutsummaryrefslogtreecommitdiffstats
path: root/doc/misc/cc-mode.texi
diff options
context:
space:
mode:
Diffstat (limited to 'doc/misc/cc-mode.texi')
-rw-r--r--doc/misc/cc-mode.texi195
1 files changed, 150 insertions, 45 deletions
diff --git a/doc/misc/cc-mode.texi b/doc/misc/cc-mode.texi
index a9339162666..1a192123c3e 100644
--- a/doc/misc/cc-mode.texi
+++ b/doc/misc/cc-mode.texi
@@ -147,10 +147,7 @@ CC Mode
147@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 147@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
148 148
149@comment Define an index for syntactic symbols. 149@comment Define an index for syntactic symbols.
150@ifnottex @c In texi2dvi, the @defindex would create an empty cc-mode.ss
151 @c For Info, unlike tex, @syncodeindex needs a matching @defindex.
152@defindex ss 150@defindex ss
153@end ifnottex
154 151
155@comment Combine key, syntactic symbol and concept indices into one. 152@comment Combine key, syntactic symbol and concept indices into one.
156@syncodeindex ss cp 153@syncodeindex ss cp
@@ -159,7 +156,7 @@ CC Mode
159@copying 156@copying
160This manual is for CC Mode in Emacs. 157This manual is for CC Mode in Emacs.
161 158
162Copyright @copyright{} 1995-2011 Free Software Foundation, Inc. 159Copyright @copyright{} 1995-2012 Free Software Foundation, Inc.
163 160
164@quotation 161@quotation
165Permission is granted to copy, distribute and/or modify this document 162Permission is granted to copy, distribute and/or modify this document
@@ -190,7 +187,7 @@ developing GNU and promoting software freedom.''
190@titlepage 187@titlepage
191@sp 10 188@sp 10
192 189
193@center @titlefont{CC Mode 5.31} 190@center @titlefont{CC Mode 5.32}
194@sp 2 191@sp 2
195@center @subtitlefont{A GNU Emacs mode for editing C and C-like languages} 192@center @subtitlefont{A GNU Emacs mode for editing C and C-like languages}
196@sp 2 193@sp 2
@@ -287,11 +284,11 @@ Configuration Basics
287 284
288Styles 285Styles
289 286
290* Built-in Styles:: 287* Built-in Styles::
291* Choosing a Style:: 288* Choosing a Style::
292* Adding Styles:: 289* Adding Styles::
293* Guessing the Style:: 290* Guessing the Style::
294* File Styles:: 291* File Styles::
295 292
296Customizing Auto-newlines 293Customizing Auto-newlines
297 294
@@ -311,19 +308,19 @@ Indentation Engine Basics
311 308
312Syntactic Symbols 309Syntactic Symbols
313 310
314* Function Symbols:: 311* Function Symbols::
315* Class Symbols:: 312* Class Symbols::
316* Conditional Construct Symbols:: 313* Conditional Construct Symbols::
317* Switch Statement Symbols:: 314* Switch Statement Symbols::
318* Brace List Symbols:: 315* Brace List Symbols::
319* External Scope Symbols:: 316* External Scope Symbols::
320* Paren List Symbols:: 317* Paren List Symbols::
321* Literal Symbols:: 318* Literal Symbols::
322* Multiline Macro Symbols:: 319* Multiline Macro Symbols::
323* Objective-C Method Symbols:: 320* Objective-C Method Symbols::
324* Java Symbols:: 321* Java Symbols::
325* Statement Block Symbols:: 322* Statement Block Symbols::
326* K&R Symbols:: 323* K&R Symbols::
327 324
328Customizing Indentation 325Customizing Indentation
329 326
@@ -341,6 +338,11 @@ Line-Up Functions
341* Comment Line-Up:: 338* Comment Line-Up::
342* Misc Line-Up:: 339* Misc Line-Up::
343 340
341Customizing Macros
342
343* Macro Backslashes::
344* Macros with ;::
345
344@end detailmenu 346@end detailmenu
345@end menu 347@end menu
346 348
@@ -373,7 +375,7 @@ was added in version 5.30.
373 375
374This manual describes @ccmode{} 376This manual describes @ccmode{}
375@comment The following line must appear on its own, so that the 377@comment The following line must appear on its own, so that the
376version 5.31. 378version 5.32.
377@comment Release.py script can update the version number automatically 379@comment Release.py script can update the version number automatically
378 380
379@ccmode{} supports the editing of K&R and ANSI C, C++, Objective-C, 381@ccmode{} supports the editing of K&R and ANSI C, C++, Objective-C,
@@ -655,6 +657,10 @@ expression, to some statements, or perhaps to whole functions, the
655syntactic recognition can be wrong. @ccmode{} manages to figure it 657syntactic recognition can be wrong. @ccmode{} manages to figure it
656out correctly most of the time, though. 658out correctly most of the time, though.
657 659
660Some macros, when invoked, ''have their own semicolon''. To get the
661next line indented correctly, rather than as a continuation line,
662@xref{Macros with ;}.
663
658Reindenting large sections of code can take a long time. When 664Reindenting large sections of code can take a long time. When
659@ccmode{} reindents a region of code, it is essentially equivalent to 665@ccmode{} reindents a region of code, it is essentially equivalent to
660hitting @key{TAB} on every line of the region. 666hitting @key{TAB} on every line of the region.
@@ -882,6 +888,8 @@ lines.
882@itemx @kbd{C-M-e} (@code{c-end-of-defun}) 888@itemx @kbd{C-M-e} (@code{c-end-of-defun})
883@findex c-beginning-of-defun 889@findex c-beginning-of-defun
884@findex c-end-of-defun 890@findex c-end-of-defun
891@vindex c-defun-tactic
892@vindex defun-tactic (c-)
885 893
886Move to the beginning or end of the current or next function. Other 894Move to the beginning or end of the current or next function. Other
887constructs (such as a structs or classes) which have a brace block 895constructs (such as a structs or classes) which have a brace block
@@ -895,6 +903,15 @@ commands try to leave point at the beginning of a line near the actual
895start or end of the function. This occasionally causes point not to 903start or end of the function. This occasionally causes point not to
896move at all. 904move at all.
897 905
906By default, these commands will recognize functions contained within a
907@dfn{declaration scope} such as a C++ @code{class} or @code{namespace}
908construct, should the point start inside it. If @ccmode fails to find
909function beginnings or ends inside the current declaration scope, it
910will search the enclosing scopes. If you want @ccmode to recognize
911functions only at the top level@footnote{this was @ccmode{}'s
912behavior prior to version 5.32.}, set @code{c-defun-tactic} to
913@code{t}.
914
898These functions are analogous to the Emacs built-in commands 915These functions are analogous to the Emacs built-in commands
899@code{beginning-of-defun} and @code{end-of-defun}, except they 916@code{beginning-of-defun} and @code{end-of-defun}, except they
900eliminate the constraint that the top-level opening brace of the defun 917eliminate the constraint that the top-level opening brace of the defun
@@ -1153,7 +1170,7 @@ Full details on how these minor modes work are at @ref{Electric Keys},
1153and @ref{Indentation Engine Basics}. 1170and @ref{Indentation Engine Basics}.
1154 1171
1155You can toggle each of these minor modes on and off, and you can 1172You can toggle each of these minor modes on and off, and you can
1156configure @ccmode{} so that it starts up with your favourite 1173configure @ccmode{} so that it starts up with your favorite
1157combination of them (@pxref{Sample .emacs File}). By default, when 1174combination of them (@pxref{Sample .emacs File}). By default, when
1158you initialize a buffer, electric mode and syntactic-indentation mode 1175you initialize a buffer, electric mode and syntactic-indentation mode
1159are enabled but the other two modes are disabled. 1176are enabled but the other two modes are disabled.
@@ -2140,7 +2157,7 @@ A space between the function name and opening parenthesis when calling
2140a user function. The last character of the function name and the 2157a user function. The last character of the function name and the
2141opening parenthesis are highlighted. This font-locking rule will 2158opening parenthesis are highlighted. This font-locking rule will
2142spuriously highlight a valid concatenation expression where an 2159spuriously highlight a valid concatenation expression where an
2143identifier precedes a parenthesised expression. Unfortunately. 2160identifier precedes a parenthesized expression. Unfortunately.
2144 2161
2145@item 2162@item
2146Whitespace following the @samp{\} in what otherwise looks like an 2163Whitespace following the @samp{\} in what otherwise looks like an
@@ -2180,7 +2197,7 @@ method, ``Top-level commands or the customization interface''.
2180 2197
2181If you make conflicting settings in several of these ways, the way 2198If you make conflicting settings in several of these ways, the way
2182that takes precedence is the one that appears latest in this list: 2199that takes precedence is the one that appears latest in this list:
2183@itemize @asis 2200@itemize @w{}
2184@item 2201@item
2185@table @asis 2202@table @asis
2186@item Style 2203@item Style
@@ -2517,11 +2534,11 @@ As an alternative to writing a style definition yourself, you can have
2517already formatted piece of your code, @ref{Guessing the Style}. 2534already formatted piece of your code, @ref{Guessing the Style}.
2518 2535
2519@menu 2536@menu
2520* Built-in Styles:: 2537* Built-in Styles::
2521* Choosing a Style:: 2538* Choosing a Style::
2522* Adding Styles:: 2539* Adding Styles::
2523* Guessing the Style:: 2540* Guessing the Style::
2524* File Styles:: 2541* File Styles::
2525@end menu 2542@end menu
2526 2543
2527@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 2544@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -4246,19 +4263,19 @@ Java. @ref{Java Symbols}.
4246@end table 4263@end table
4247 4264
4248@menu 4265@menu
4249* Function Symbols:: 4266* Function Symbols::
4250* Class Symbols:: 4267* Class Symbols::
4251* Conditional Construct Symbols:: 4268* Conditional Construct Symbols::
4252* Switch Statement Symbols:: 4269* Switch Statement Symbols::
4253* Brace List Symbols:: 4270* Brace List Symbols::
4254* External Scope Symbols:: 4271* External Scope Symbols::
4255* Paren List Symbols:: 4272* Paren List Symbols::
4256* Literal Symbols:: 4273* Literal Symbols::
4257* Multiline Macro Symbols:: 4274* Multiline Macro Symbols::
4258* Objective-C Method Symbols:: 4275* Objective-C Method Symbols::
4259* Java Symbols:: 4276* Java Symbols::
4260* Statement Block Symbols:: 4277* Statement Block Symbols::
4261* K&R Symbols:: 4278* K&R Symbols::
4262@end menu 4279@end menu
4263 4280
4264@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 4281@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -6550,6 +6567,9 @@ custom line-up function associated with it.
6550@section Other Special Indentations 6567@section Other Special Indentations
6551@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 6568@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6552 6569
6570To configure macros which you invoke without a terminating @samp{;},
6571see @xref{Macros with ;}.
6572
6553Here are the remaining odds and ends regarding indentation: 6573Here are the remaining odds and ends regarding indentation:
6554 6574
6555@defopt c-label-minimum-indentation 6575@defopt c-label-minimum-indentation
@@ -6601,6 +6621,13 @@ functions to this hook, not remove them. @xref{Style Variables}.
6601@cindex preprocessor directives 6621@cindex preprocessor directives
6602@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 6622@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6603 6623
6624Preprocessor macros in C, C++, and Objective C (introduced by
6625@code{#define}) have a syntax different from the main language---for
6626example, a macro declaration is not terminated by a semicolon, and if
6627it is more than a line long, line breaks in it must be escaped with
6628backslashes. @ccmode{} has some commands to manipulate these, see
6629@ref{Macro Backslashes}.
6630
6604Normally, the lines in a multi-line macro are indented relative to 6631Normally, the lines in a multi-line macro are indented relative to
6605each other as though they were code. You can suppress this behavior 6632each other as though they were code. You can suppress this behavior
6606by setting the following user option: 6633by setting the following user option:
@@ -6612,6 +6639,28 @@ is @code{nil}, all lines inside macro definitions are analyzed as
6612@code{cpp-macro-cont}. 6639@code{cpp-macro-cont}.
6613@end defopt 6640@end defopt
6614 6641
6642Because a macro can expand into anything at all, near where one is
6643invoked @ccmode{} can only indent and fontify code heuristically.
6644Sometimes it gets it wrong. Usually you should try to design your
6645macros so that they ''look like ordinary code'' when you invoke them.
6646However, one situation is so common that @ccmode{} handles it
6647specially: that is when certain macros needn't (or mustn't) be
6648followed by a @samp{;}. You need to configure @ccmode{} to handle
6649these macros properly, see @ref{Macros with ;}.
6650
6651@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6652@menu
6653* Macro Backslashes::
6654* Macros with ;::
6655@end menu
6656
6657@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6658@node Macro Backslashes, Macros with ;, Custom Macros, Custom Macros
6659@comment node-name, next, previous, up
6660@section Customizing Macro Backslashes
6661@cindex @code{#define}
6662@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6663
6615@ccmode{} provides some tools to help keep the line continuation 6664@ccmode{} provides some tools to help keep the line continuation
6616backslashes in macros neat and tidy. Their precise action is 6665backslashes in macros neat and tidy. Their precise action is
6617customized with these variables: 6666customized with these variables:
@@ -6654,6 +6703,62 @@ get aligned only when you explicitly invoke the command
6654@end defopt 6703@end defopt
6655 6704
6656@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 6705@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6706@node Macros with ;, , Macro Backslashes, Custom Macros
6707@comment node-name, next, previous, up
6708@section Macros with semicolons
6709@cindex macros with semicolons
6710@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6711Macros which needn't (or mustn't) be followed by a semicolon when you
6712invoke them, @dfn{macros with semicolons}, are very common. These can
6713cause @ccmode{} to parse the next line wrongly as a
6714@code{statement-cont} (@pxref{Function Symbols}) and thus mis-indent
6715it.
6716
6717You can prevent this by specifying which macros have semicolons. It
6718doesn't matter whether or not such a macro has a parameter list:
6719
6720@defopt c-macro-names-with-semicolon
6721@vindex macro-names-with-semicolon (c-)
6722This buffer-local variable specifies which macros have semicolons.
6723After setting its value, you need to call
6724@code{c-make-macro-with-semi-re} for it to take effect. It should be
6725set to one of these values:
6726
6727@table @asis
6728@item nil
6729There are no macros with semicolons.
6730@item a list of strings
6731Each string is the name of a macro with a semicolon. Only valid
6732@code{#define} names are allowed here. For example, to set the
6733default value, you could write the following into your @file{.emacs}:
6734
6735@example
6736(setq c-macro-names-with-semicolon
6737 '("Q_OBJECT" "Q_PROPERTY" "Q_DECLARE" "Q_ENUMS"))
6738@end example
6739
6740@item a regular expression
6741This matches each symbol which is a macro with a semicolon. It must
6742not match any string which isn't a valid @code{#define} name. For
6743example:
6744
6745@example
6746(setq c-macro-names-with-semicolon
6747 "\\<\\(CLEAN_UP_AND_RETURN\\|Q_[[:upper:]]+\\)\\>")
6748@end example
6749@end table
6750@end defopt
6751
6752@defun c-make-macro-with-semi-re
6753@findex make-macro-with-semi-re (c-)
6754Call this (non-interactive) function, which sets internal variables,
6755each time you change the value of
6756@code{c-macro-names-with-semicolon}. It takes no arguments, and its
6757return value has no meaning. This function is called by @ccmode{}'s
6758initialization code.
6759@end defun
6760
6761@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6657@node Odds and Ends, Sample .emacs File, Custom Macros, Top 6762@node Odds and Ends, Sample .emacs File, Custom Macros, Top
6658@comment node-name, next, previous, up 6763@comment node-name, next, previous, up
6659@chapter Odds and Ends 6764@chapter Odds and Ends
@@ -6837,7 +6942,7 @@ circumstances, can locate the top-most opening brace much more quickly than
6837styles where these braces are hung (e.g. most JDK-derived Java styles), 6942styles where these braces are hung (e.g. most JDK-derived Java styles),
6838this hack can improve performance of the core syntax parsing routines 6943this hack can improve performance of the core syntax parsing routines
6839from 3 to 60 times. However, for styles which @emph{do} conform to 6944from 3 to 60 times. However, for styles which @emph{do} conform to
6840Emacs' recommended style of putting top-level braces in column zero, 6945Emacs's recommended style of putting top-level braces in column zero,
6841this hack can degrade performance by about as much. Thus this variable 6946this hack can degrade performance by about as much. Thus this variable
6842is set to @code{nil} by default, since the Emacs-friendly styles should 6947is set to @code{nil} by default, since the Emacs-friendly styles should
6843be more common (and encouraged!). Note that this variable has no effect 6948be more common (and encouraged!). Note that this variable has no effect
@@ -6948,7 +7053,7 @@ Set the variable @code{c-basic-offset}. @xref{Getting Started}.
6948@kindex C-j 7053@kindex C-j
6949@emph{Why doesn't the @kbd{RET} key indent the new line?} 7054@emph{Why doesn't the @kbd{RET} key indent the new line?}
6950 7055
6951Emacs' convention is that @kbd{RET} just adds a newline, and that 7056Emacs's convention is that @kbd{RET} just adds a newline, and that
6952@kbd{C-j} adds a newline and indents it. You can make @kbd{RET} do this 7057@kbd{C-j} adds a newline and indents it. You can make @kbd{RET} do this
6953too by adding this to your @code{c-initialization-hook}: 7058too by adding this to your @code{c-initialization-hook}:
6954 7059