aboutsummaryrefslogtreecommitdiffstats
path: root/man
diff options
context:
space:
mode:
authorAlan Mackenzie2005-12-19 22:21:41 +0000
committerAlan Mackenzie2005-12-19 22:21:41 +0000
commit108262a0facf02caba51dd23271131eb1ca7d6a5 (patch)
tree23b0478fc407e148c15bbbeae953fbd131dda52f /man
parentde64bbfaf779ed45f97bb686106bfeed1daa9ef0 (diff)
downloademacs-108262a0facf02caba51dd23271131eb1ca7d6a5.tar.gz
emacs-108262a0facf02caba51dd23271131eb1ca7d6a5.zip
Amend the file for CC Mode 5.31. In particular, relax the injunction
that all braces/parens at column zero start defuns.
Diffstat (limited to 'man')
-rw-r--r--man/programs.texi323
1 files changed, 211 insertions, 112 deletions
diff --git a/man/programs.texi b/man/programs.texi
index 6444a3a6a47..a80d3bad08a 100644
--- a/man/programs.texi
+++ b/man/programs.texi
@@ -128,17 +128,19 @@ place to set up customizations for that major mode. @xref{Hooks}.
128@node Defuns 128@node Defuns
129@section Top-Level Definitions, or Defuns 129@section Top-Level Definitions, or Defuns
130 130
131 In Emacs, a major definition at the top level in the buffer is 131 In Emacs, a major definition at the top level in the buffer,
132called a @dfn{defun}. The name comes from Lisp, but in Emacs we use 132something like a function, is called a @dfn{defun}. The name comes
133it for all languages. 133from Lisp, but in Emacs we use it for all languages.
134 134
135 In most programming language modes, Emacs assumes that a defun is 135 In many programming language modes, Emacs assumes that a defun is
136any pair of parentheses (or braces, if the language uses braces this 136any pair of parentheses (or braces, if the language uses braces this
137way) that starts at the left margin. For example, in C, the body of a 137way) that starts at the left margin. For example, in C, the body of a
138function definition is normally a defun, because the open-brace that 138function definition is a defun, usually recognized as an open-brace
139begins it is normally at the left margin. A variable's initializer 139that begins at the left margin@footnote{Alternatively, you can set up
140can also count as a defun, if the open-brace that begins the 140C Mode to recognize a defun at an opening brace at the outermost
141initializer is at the left margin. 141level. @xref{Movement Commands,,, ccmode, the CC Mode Manual}.}. A
142variable's initializer can also count as a defun, if the open-brace
143that begins the initializer is at the left margin.
142 144
143 However, some language modes provide their own code for recognizing 145 However, some language modes provide their own code for recognizing
144defuns in a way that suits the language syntax and conventions better. 146defuns in a way that suits the language syntax and conventions better.
@@ -156,14 +158,22 @@ defuns in a way that suits the language syntax and conventions better.
156 158
157@cindex open-parenthesis in leftmost column 159@cindex open-parenthesis in leftmost column
158@cindex ( in leftmost column 160@cindex ( in leftmost column
159 In most major modes, Emacs assumes that any opening delimiter found 161 Emacs assumes by default that any opening delimiter found at the
160at the left margin is the start of a top-level definition, or defun. 162left margin is the start of a top-level definition, or defun. You can
161Therefore, @strong{never put an opening delimiter at the left margin 163override this default by setting this user option:
162unless it should have that significance.} For instance, never put an 164
165@defvar open-paren-in-column-0-is-defun-start
166If this user option is set to @code{t} (the default), opening
167parentheses or braces at column zero always start defuns. When it's
168@code{nil}, defuns are found by searching for parens or braces at the
169outermost level.
170@end defvar
171
172In buffers where @code{open-paren-in-column-0-is-defun-start} is
173@code{t}, @strong{don't put an opening delimiter at the left margin
174unless it is a defun start}. For instance, never put an
163open-parenthesis at the left margin in a Lisp file unless it is the 175open-parenthesis at the left margin in a Lisp file unless it is the
164start of a top-level list. Never put an open-brace or other opening 176start of a top-level list.
165delimiter at the beginning of a line of C code unless it is at top
166level.
167 177
168 If you don't follow this convention, not only will you have trouble 178 If you don't follow this convention, not only will you have trouble
169when you explicitly use the commands for motion by defuns; other 179when you explicitly use the commands for motion by defuns; other
@@ -173,10 +183,10 @@ mode (@pxref{Font Lock}).
173 183
174 The most likely problem case is when you want an opening delimiter 184 The most likely problem case is when you want an opening delimiter
175at the start of a line inside a string. To avoid trouble, put an 185at the start of a line inside a string. To avoid trouble, put an
176escape character (@samp{\}, in C and Emacs Lisp, @samp{/} in some 186escape character (@samp{\}, in Emacs Lisp, @samp{/} in some other Lisp
177other Lisp dialects) before the opening delimiter. This will not 187dialects) before the opening delimiter. This will not affect the
178affect the contents of the string, but will prevent that opening 188contents of the string, but will prevent that opening delimiter from
179delimiter from starting a defun. Here's an example: 189starting a defun. Here's an example:
180 190
181@example 191@example
182 (insert "Foo: 192 (insert "Foo:
@@ -188,6 +198,11 @@ delimiter from starting a defun. Here's an example:
188highlights confusing opening delimiters (those that ought to be 198highlights confusing opening delimiters (those that ought to be
189quoted) in bold red. 199quoted) in bold red.
190 200
201 Some major modes, including C and related modes, set
202@code{open-paren-in-column-0-is-defun-start} buffer-locally to
203@code{nil}, thus freeing you from all these restrictions. This makes
204some commands run more slowly, though.
205
191 In the earliest days, the original Emacs found defuns by moving 206 In the earliest days, the original Emacs found defuns by moving
192upward a level of parentheses or braces until there were no more 207upward a level of parentheses or braces until there were no more
193levels to go up. This always required scanning all the way back to 208levels to go up. This always required scanning all the way back to
@@ -195,8 +210,9 @@ the beginning of the buffer, even for a small function. To speed up
195the operation, we changed Emacs to assume that any opening delimiter 210the operation, we changed Emacs to assume that any opening delimiter
196at the left margin is the start of a defun. This heuristic is nearly 211at the left margin is the start of a defun. This heuristic is nearly
197always right, and avoids the need to scan back to the beginning of the 212always right, and avoids the need to scan back to the beginning of the
198buffer. However, it mandates following the convention described 213buffer. However, now that modern computers are so powerful, this
199above. 214scanning is rarely slow enough to annoy, so we've given you a way to
215disable the heuristic.
200 216
201@node Moving by Defuns 217@node Moving by Defuns
202@subsection Moving by Defuns 218@subsection Moving by Defuns
@@ -399,13 +415,14 @@ behavior is convenient in cases where you have overridden the standard
399result of @key{TAB} because you find it unaesthetic for a particular 415result of @key{TAB} because you find it unaesthetic for a particular
400line. 416line.
401 417
402 Remember that an open-parenthesis, open-brace or other opening delimiter 418 By default, an open-parenthesis, open-brace or other opening
403at the left margin is assumed by Emacs (including the indentation routines) 419delimiter at the left margin is assumed by Emacs (including the
404to be the start of a function. Therefore, you must never have an opening 420indentation routines) to be the start of a function. This speeds up
405delimiter in column zero that is not the beginning of a function, not even 421indentation commands. If you will be editing text which contains
406inside a string. This restriction is vital for making the indentation 422opening delimiters in column zero that aren't the beginning of a
407commands fast; you must simply accept it. @xref{Left Margin Paren}, 423functions, even inside strings or comments, you must set
408for more information on this. 424@code{open-paren-in-column-0-is-defun-start}. @xref{Left Margin
425Paren}, for more information on this.
409 426
410 Normally, lines are indented with tabs and spaces. If you want Emacs 427 Normally, lines are indented with tabs and spaces. If you want Emacs
411to use spaces only, see @ref{Just Spaces}. 428to use spaces only, see @ref{Just Spaces}.
@@ -560,16 +577,16 @@ onto the indentation of the @dfn{anchor statement}.
560Select a predefined style @var{style} (@code{c-set-style}). 577Select a predefined style @var{style} (@code{c-set-style}).
561@end table 578@end table
562 579
563 A @dfn{style} is a named collection of customizations that can 580 A @dfn{style} is a named collection of customizations that can be
564be used in C mode and the related modes. Emacs comes with several 581used in C mode and the related modes. @ref{Styles,,, ccmode, The CC
582Mode Manual}, for a complete description. Emacs comes with several
565predefined styles, including @code{gnu}, @code{k&r}, @code{bsd}, 583predefined styles, including @code{gnu}, @code{k&r}, @code{bsd},
566@code{stroustrup}, @code{linux}, @code{python}, @code{java}, 584@code{stroustrup}, @code{linux}, @code{python}, @code{java},
567@code{whitesmith}, @code{ellemtel}, @code{cc-mode}, and @code{user}. 585@code{whitesmith}, @code{ellemtel}, and @code{awk}. Some of these
568Some of these styles are primarily intended for one language, but any 586styles are primarily intended for one language, but any of them can be
569of them can be used with any of the languages supported by these 587used with any of the languages supported by these modes. To find out
570modes. To find out what a style looks like, select it and reindent 588what a style looks like, select it and reindent some code, e.g., by
571some code, e.g., by typing @key{C-M-q} at the start of a function 589typing @key{C-M-q} at the start of a function definition.
572definition.
573 590
574@kindex C-c . @r{(C mode)} 591@kindex C-c . @r{(C mode)}
575@findex c-set-style 592@findex c-set-style
@@ -577,8 +594,8 @@ definition.
577.}. Specify a style name as an argument (case is not significant). 594.}. Specify a style name as an argument (case is not significant).
578This command affects the current buffer only, and it affects only 595This command affects the current buffer only, and it affects only
579future invocations of the indentation commands; it does not reindent 596future invocations of the indentation commands; it does not reindent
580the code in the buffer. To reindent the whole buffer in the new 597the code already in the buffer. To reindent the whole buffer in the
581style, you can type @kbd{C-x h C-M-\}. 598new style, you can type @kbd{C-x h C-M-\}.
582 599
583@vindex c-default-style 600@vindex c-default-style
584 You can also set the variable @code{c-default-style} to specify the 601 You can also set the variable @code{c-default-style} to specify the
@@ -589,23 +606,24 @@ example,
589 606
590@example 607@example
591(setq c-default-style 608(setq c-default-style
592 '((java-mode . "java") (other . "gnu"))) 609 '((java-mode . "java") (awk-mode . "awk") (other . "gnu")))
593@end example 610@end example
594 611
595@noindent 612@noindent
596specifies an explicit choice for Java mode, and the default @samp{gnu} 613specifies explicit choices for Java and AWK modes, and the default
597style for the other C-like modes. (These settings are actually the 614@samp{gnu} style for the other C-like modes. (These settings are
598defaults.) This variable takes effect when you select one of the 615actually the defaults.) This variable takes effect when you select
599C-like major modes; thus, if you specify a new default style for Java 616one of the C-like major modes; thus, if you specify a new default
600mode, you can make it take effect in an existing Java mode buffer by 617style for Java mode, you can make it take effect in an existing Java
601typing @kbd{M-x java-mode} there. 618mode buffer by typing @kbd{M-x java-mode} there.
602 619
603 The @code{gnu} style specifies the formatting recommended by the GNU 620 The @code{gnu} style specifies the formatting recommended by the GNU
604Project for C; it is the default, so as to encourage use of our 621Project for C; it is the default, so as to encourage use of our
605recommended style. 622recommended style.
606 623
607 @xref{Customizing Indentation,,, ccmode, the CC Mode Manual}, for 624 @xref{Indentation Engine Basics,,, ccmode, the CC Mode Manual}, and
608more information on customizing indentation for C and related modes, 625@ref{Customizing Indentation,,, ccmode, the CC Mode Manual}, for more
626information on customizing indentation for C and related modes,
609including how to override parts of an existing style and how to define 627including how to override parts of an existing style and how to define
610your own styles. 628your own styles.
611 629
@@ -708,11 +726,12 @@ would move over.
708 A somewhat random-sounding command which is nevertheless handy is 726 A somewhat random-sounding command which is nevertheless handy is
709@kbd{C-M-t} (@code{transpose-sexps}), which drags the previous 727@kbd{C-M-t} (@code{transpose-sexps}), which drags the previous
710balanced expression across the next one. An argument serves as a 728balanced expression across the next one. An argument serves as a
711repeat count, and a negative argument drags the previous balanced 729repeat count, moving the previous expression over that many following
712expression backwards across those before it (thus canceling out the 730ones. A negative argument drags the previous balanced expression
713effect of @kbd{C-M-t} with a positive argument). An argument of zero, 731backwards across those before it (thus canceling out the effect of
714rather than doing nothing, transposes the balanced expressions ending 732@kbd{C-M-t} with a positive argument). An argument of zero, rather
715at or after point and the mark. 733than doing nothing, transposes the balanced expressions ending at or
734after point and the mark.
716 735
717@kindex C-M-@@ 736@kindex C-M-@@
718@kindex C-M-@key{SPC} 737@kindex C-M-@key{SPC}
@@ -722,9 +741,9 @@ use @kbd{C-M-@@} (@code{mark-sexp}), which sets mark at the same place
722that @kbd{C-M-f} would move to. @kbd{C-M-@@} takes arguments like 741that @kbd{C-M-f} would move to. @kbd{C-M-@@} takes arguments like
723@kbd{C-M-f}. In particular, a negative argument is useful for putting 742@kbd{C-M-f}. In particular, a negative argument is useful for putting
724the mark at the beginning of the previous balanced expression. The 743the mark at the beginning of the previous balanced expression. The
725alias @kbd{C-M-@key{SPC}} is equivalent to @kbd{C-M-@@}. If you use 744alias @kbd{C-M-@key{SPC}} is equivalent to @kbd{C-M-@@}. When you
726this command repeatedly, or in Transient Mark mode whenever the mark 745repeat this command, or use it in Transient Mark mode when the mark is
727is active, it extends the region by one sexp each time. 746active, it extends the region by one sexp each time.
728 747
729 In languages that use infix operators, such as C, it is not possible 748 In languages that use infix operators, such as C, it is not possible
730to recognize all balanced expressions as such because there can be 749to recognize all balanced expressions as such because there can be
@@ -875,7 +894,7 @@ Set comment column (@code{comment-set-column}).
875@item @kbd{C-M-j} 894@item @kbd{C-M-j}
876@itemx @kbd{M-j} 895@itemx @kbd{M-j}
877Like @key{RET} followed by inserting and aligning a comment 896Like @key{RET} followed by inserting and aligning a comment
878(@code{comment-indent-new-line}). 897(@code{comment-indent-new-line}). @xref{Multi-Line Comments}.
879@item @kbd{M-x comment-region} 898@item @kbd{M-x comment-region}
880@itemx @kbd{C-c C-c} (in C-like modes) 899@itemx @kbd{C-c C-c} (in C-like modes)
881Add or remove comment delimiters on all the lines in the region. 900Add or remove comment delimiters on all the lines in the region.
@@ -948,8 +967,13 @@ and by not changing the indentation of a triple-semicolon comment at all.
948 (1+ x)) ; This line adds one. 967 (1+ x)) ; This line adds one.
949@end example 968@end example
950 969
951 In C code, a comment preceded on its line by nothing but whitespace 970 For C-like buffers, you can configure the exact effect of @kbd{M-;}
952is indented like a line of code. 971more flexibly than for most buffers by setting the user options
972@code{c-indent-comment-alist} and
973@code{c-indent-comments-syntactically-p}. For example, on a line
974ending in a closing brace, @kbd{M-;} puts the comment one space after
975the brace rather than at @code{comment-column}. For full details see
976@ref{Comment Commands,,, ccmode, The CC Mode Manual}.
953 977
954@node Multi-Line Comments 978@node Multi-Line Comments
955@subsection Multiple Lines of Comments 979@subsection Multiple Lines of Comments
@@ -958,23 +982,27 @@ is indented like a line of code.
958@kindex M-j 982@kindex M-j
959@cindex blank lines in programs 983@cindex blank lines in programs
960@findex comment-indent-new-line 984@findex comment-indent-new-line
985
961 If you are typing a comment and wish to continue it on another line, 986 If you are typing a comment and wish to continue it on another line,
962you can use the command @kbd{C-M-j} or @kbd{M-j} 987you can use the command @kbd{C-M-j} or @kbd{M-j}
963(@code{comment-indent-new-line}). This terminates the comment you are 988(@code{comment-indent-new-line}). This terminates the comment you are
964typing, creates a new blank line afterward, and begins a new comment 989typing, creates a new blank line afterward, and begins a new comment
965indented under the old one. When Auto Fill mode is on, going past the 990indented under the old one. Or, if the language syntax permits
966fill column while typing a comment causes the comment to be continued 991comments to extend beyond ends of lines, it may instead continue the
967in just this fashion. If point is not at the end of the line when you 992existing comment on the new blank line---this is controlled by the
968type the command, the text on the rest of the line becomes part of the 993setting of @code{comment-multi-line} (@pxref{Options for Comments}).
969new comment line. 994If point is not at the end of the line when you type the command, the
995text on the rest of the line becomes part of the new comment line.
996When Auto Fill mode is on, going past the fill column while typing a
997comment causes the comment to be continued in just this fashion.
970 998
971@kindex C-c C-c (C mode) 999@kindex C-c C-c (C mode)
972@findex comment-region 1000@findex comment-region
973 To turn existing lines into comment lines, use the @kbd{M-x 1001 To turn existing lines into comment lines, use the @kbd{M-x
974comment-region} command. It adds comment delimiters to the lines that start 1002comment-region} command (or type @kbd{C-c C-c} in C-like buffers). It
975in the region, thus commenting them out. With a negative argument, it 1003adds comment delimiters to the lines that start in the region, thus
976does the opposite---it deletes comment delimiters from the lines in the 1004commenting them out. With a negative argument, it does the
977region. 1005opposite---it deletes comment delimiters from the lines in the region.
978 1006
979 With a positive argument, @code{comment-region} duplicates the last 1007 With a positive argument, @code{comment-region} duplicates the last
980character of the comment start sequence it adds; the argument specifies 1008character of the comment start sequence it adds; the argument specifies
@@ -985,6 +1013,11 @@ can also affect how the comment is indented. In Lisp, for proper
985indentation, you should use an argument of two or three, if between defuns; 1013indentation, you should use an argument of two or three, if between defuns;
986if within a defun, it must be three. 1014if within a defun, it must be three.
987 1015
1016 You can configure C Mode such that when you type a @samp{/} at the
1017start of a line in a multi-line block comment, this closes the
1018comment. Enable the @code{comment-close-slash} clean-up for this.
1019@xref{Clean-ups,,, ccmode, The CC Mode Manual}.
1020
988@node Options for Comments 1021@node Options for Comments
989@subsection Options Controlling Comments 1022@subsection Options Controlling Comments
990 1023
@@ -1038,13 +1071,13 @@ can hold the actual string to insert.
1038@vindex comment-multi-line 1071@vindex comment-multi-line
1039 The variable @code{comment-multi-line} controls how @kbd{C-M-j} 1072 The variable @code{comment-multi-line} controls how @kbd{C-M-j}
1040(@code{indent-new-comment-line}) behaves when used inside a comment. 1073(@code{indent-new-comment-line}) behaves when used inside a comment.
1041Specifically, when @code{comment-multi-line} is @code{nil} (the 1074Specifically, when @code{comment-multi-line} is @code{nil}, the
1042default value), the command inserts a comment terminator, begins a new 1075command inserts a comment terminator, begins a new line, and finally
1043line, and finally inserts a comment starter. Otherwise it does not 1076inserts a comment starter. Otherwise it does not insert the
1044insert the terminator and starter, so it effectively continues the 1077terminator and starter, so it effectively continues the current
1045current comment across multiple lines. In languages that allow 1078comment across multiple lines. In languages that allow multi-line
1046multi-line comments, the choice of value for this variable is a matter 1079comments, the choice of value for this variable is a matter of taste.
1047of taste. 1080The default for this variable depends on the major mode.
1048 1081
1049@vindex comment-indent-function 1082@vindex comment-indent-function
1050 The variable @code{comment-indent-function} should contain a function 1083 The variable @code{comment-indent-function} should contain a function
@@ -1510,11 +1543,13 @@ Move point to the end of the innermost C statement or sentence; like
1510 1543
1511@item M-x c-backward-into-nomenclature 1544@item M-x c-backward-into-nomenclature
1512@findex c-backward-into-nomenclature 1545@findex c-backward-into-nomenclature
1513Move point backward to beginning of a C++ nomenclature section or word. 1546Move point backward to beginning of a C++ nomenclature section or
1514With prefix argument @var{n}, move @var{n} times. If @var{n} is 1547word. With prefix argument @var{n}, move @var{n} times. If @var{n}
1515negative, move forward. C++ nomenclature means a symbol name in the 1548is negative, move forward. C++ nomenclature means a symbol name in
1516style of NamingSymbolsWithMixedCaseAndNoUnderlines; each capital letter 1549the style of NamingSymbolsWithMixedCaseAndNoUnderlines; each capital
1517begins a section or word. 1550letter begins a section or word. Rather than this command, you might
1551well prefer the newer ``Subword Mode'', which does the same thing
1552better. @xref{Other C Commands}.
1518 1553
1519In the GNU project, we recommend using underscores to separate words 1554In the GNU project, we recommend using underscores to separate words
1520within an identifier in C or C++, rather than using case distinctions. 1555within an identifier in C or C++, rather than using case distinctions.
@@ -1529,27 +1564,47 @@ With prefix argument @var{n}, move @var{n} times.
1529@subsection Electric C Characters 1564@subsection Electric C Characters
1530 1565
1531 In C mode and related modes, certain printing characters are 1566 In C mode and related modes, certain printing characters are
1532``electric''---in addition to inserting themselves, they also reindent 1567@dfn{electric}---in addition to inserting themselves, they also
1533the current line, and optionally also insert newlines. The 1568reindent the current line, and optionally also insert newlines. The
1534``electric'' characters are @kbd{@{}, @kbd{@}}, @kbd{:}, @kbd{#}, 1569``electric'' characters are @kbd{@{}, @kbd{@}}, @kbd{:}, @kbd{#},
1535@kbd{;}, @kbd{,}, @kbd{<}, @kbd{>}, @kbd{/}, @kbd{*}, @kbd{(}, and 1570@kbd{;}, @kbd{,}, @kbd{<}, @kbd{>}, @kbd{/}, @kbd{*}, @kbd{(}, and
1536@kbd{)}. 1571@kbd{)}. @xref{Electric Keys,,, ccmode, The CC Mode Manual}.
1572
1573 You might find electric indentation inconvenient if you are editing
1574chaotically indented code. If you are new to CC Mode, you might find
1575it disconcerting. You can toggle electric action with the command
1576@kbd{C-c C-l}; when it is enabled, @samp{/l} appears in the mode line
1577after the mode name:
1537 1578
1538 Electric characters insert newlines only when the @dfn{auto-newline} 1579@table @kbd
1539feature is enabled (indicated by @samp{/a} in the mode line after the 1580@item C-c C-l
1540mode name). This feature is controlled by the variable 1581@kindex C-c C-l @r{(C mode)}
1541@code{c-auto-newline}. You can turn this feature on or off with the 1582@findex c-toggle-electric-state
1542command @kbd{C-c C-a}: 1583Toggle electric action (@code{c-toggle-electric-state}). With a
1584prefix argument, this command enables electric action if the argument
1585is positive, disables it if it is negative.
1586@end table
1587
1588 Electric characters insert newlines only when, in addition to the
1589electric state, the @dfn{auto-newline} feature is enabled (indicated
1590by @samp{/la} in the mode line after the mode name). You can turn
1591this feature on or off with the command @kbd{C-c C-a}:
1543 1592
1544@table @kbd 1593@table @kbd
1545@item C-c C-a 1594@item C-c C-a
1546@kindex C-c C-a @r{(C mode)} 1595@kindex C-c C-a @r{(C mode)}
1547@findex c-toggle-auto-state 1596@findex c-toggle-auto-newline
1548Toggle the auto-newline feature (@code{c-toggle-auto-state}). With a 1597Toggle the auto-newline feature (@code{c-toggle-auto-newline}). With a
1549prefix argument, this command turns the auto-newline feature on if the 1598prefix argument, this command turns the auto-newline feature on if the
1550argument is positive, and off if it is negative. 1599argument is positive, and off if it is negative.
1551@end table 1600@end table
1552 1601
1602 Usually the CC Mode style system (@pxref{Styles,,, ccmode, The CC
1603Mode Manual}) configures the exact circumstances in which Emacs
1604inserts auto-newlines, but you can configure this directly instead.
1605Full details are at @ref{Custom Auto-newlines,,, ccmode, The CC Mode
1606Manual}, but there is a short summary below.
1607
1553 The colon character is electric because that is appropriate for a 1608 The colon character is electric because that is appropriate for a
1554single colon. But when you want to insert a double colon in C++, the 1609single colon. But when you want to insert a double colon in C++, the
1555electric behavior of colon is inconvenient. You can insert a double 1610electric behavior of colon is inconvenient. You can insert a double
@@ -1608,13 +1663,14 @@ inserted.
1608@vindex c-cleanup-list 1663@vindex c-cleanup-list
1609 Electric characters can also delete newlines automatically when the 1664 Electric characters can also delete newlines automatically when the
1610auto-newline feature is enabled. This feature makes auto-newline more 1665auto-newline feature is enabled. This feature makes auto-newline more
1611acceptable, by deleting the newlines in the most common cases where you 1666acceptable, by deleting the newlines in the most common cases where
1612do not want them. Emacs can recognize several cases in which deleting a 1667you do not want them. Emacs can recognize several cases in which
1613newline might be desirable; by setting the variable 1668deleting a newline might be desirable; by setting the variable
1614@code{c-cleanup-list}, you can specify @emph{which} of these cases that 1669@code{c-cleanup-list}, you can specify @emph{which} of these cases
1615should happen. The variable's value is a list of symbols, each 1670that should happen. @xref{Clean-ups,,, ccmode, The CC Mode Manual}.
1616describing one case for possible deletion of a newline. Here are the 1671The variable's value is a list of symbols, each describing one case
1617meaningful symbols, and their meanings: 1672for possible deletion of a newline. Here is a summary of the
1673meaningful symbols and their meanings:
1618 1674
1619@table @code 1675@table @code
1620@item brace-catch-brace 1676@item brace-catch-brace
@@ -1648,6 +1704,13 @@ brace. Clean-up occurs when you type the semicolon.
1648Clean up commas following braces in array and aggregate 1704Clean up commas following braces in array and aggregate
1649initializers. Clean-up occurs when you type the comma. 1705initializers. Clean-up occurs when you type the comma.
1650 1706
1707@item one-line-defun
1708Remove space and newlines from a defun if this would leave it short
1709enough to fit on a single line. This is useful for AWK pattern/action
1710pairs. ``Short enough'' means not longer than the value of the user
1711option @code{c-max-one-liner-length}. Clean-up occurs when you type
1712the closing brace.
1713
1651@item scope-operator 1714@item scope-operator
1652Clean up double colons which may designate a C++ scope operator, by 1715Clean up double colons which may designate a C++ scope operator, by
1653placing the colons together. Clean-up occurs when you type the second 1716placing the colons together. Clean-up occurs when you type the second
@@ -1659,24 +1722,47 @@ whitespace.
1659@subsection Hungry Delete Feature in C 1722@subsection Hungry Delete Feature in C
1660@cindex hungry deletion (C Mode) 1723@cindex hungry deletion (C Mode)
1661 1724
1662 When the @dfn{hungry-delete} feature is enabled (indicated by 1725 If you want to delete an entire block of whitespace at point, you
1663@samp{/h} or @samp{/ah} in the mode line after the mode name), a single 1726can use @dfn{hungry deletion}. This deletes all the contiguous
1664@key{DEL} command deletes all preceding whitespace, not just one space. 1727whitespace either before point or after point in a single operation.
1665To turn this feature on or off, use @kbd{C-c C-d}: 1728@dfn{Whitespace} here includes tabs and newlines, but not comments or
1729preprocessor commands.
1666 1730
1667@table @kbd 1731@table @kbd
1732@item C-c C-@key{BS}
1733@itemx C-c @key{BS}
1734@findex c-hungry-backspace
1735@kindex C-c C-@key{BS} (C Mode)
1736@kindex C-c @key{BS} (C Mode)
1737@code{c-hungry-backspace}---Delete the entire block of whitespace
1738preceding point.
1739
1668@item C-c C-d 1740@item C-c C-d
1669@kindex C-c C-d @r{(C mode)} 1741@itemx C-c C-@key{DEL}
1670@findex c-toggle-hungry-state 1742@itemx C-c @key{DEL}
1671Toggle the hungry-delete feature (@code{c-toggle-hungry-state}). With a 1743@findex c-hungry-delete-forward
1672prefix argument, this command turns the hungry-delete feature on if the 1744@kindex C-c C-d (C Mode)
1673argument is positive, and off if it is negative. 1745@kindex C-c C-@key{DEL} (C Mode)
1746@kindex C-c @key{DEL} (C Mode)
1747@code{c-hungry-delete-forward}---Delete the entire block of whitespace
1748following point.
1749@end table
1750
1751 As an alternative to the above commands, you can enable @dfn{hungry
1752delete mode}. When this feature is enabled (indicated by @samp{/h} in
1753the mode line after the mode name), a single @key{BS} command deletes
1754all preceding whitespace, not just one space, and a single @kbd{C-c
1755C-d} (but @emph{not} @key{delete}) deletes all following whitespace.
1674 1756
1675@item C-c C-t 1757@table @kbd
1676@kindex C-c C-t @r{(C mode)} 1758@item M-x c-toggle-hungry-state
1677@findex c-toggle-auto-hungry-state 1759@findex c-toggle-hungry-state
1678Toggle the auto-newline and hungry-delete features, both at once 1760Toggle the hungry-delete feature
1679(@code{c-toggle-auto-hungry-state}). 1761(@code{c-toggle-hungry-state})@footnote{This command had the binding
1762@kbd{C-c C-d} in earlier versions of Emacs. @kbd{C-c C-d} is now
1763bound to @code{c-hungry-delete-forward}.}. With a prefix argument,
1764this command turns the hungry-delete feature on if the argument is
1765positive, and off if it is negative.
1680@end table 1766@end table
1681 1767
1682@vindex c-hungry-delete-key 1768@vindex c-hungry-delete-key
@@ -1687,6 +1773,15 @@ hungry-delete feature is enabled.
1687@subsection Other Commands for C Mode 1773@subsection Other Commands for C Mode
1688 1774
1689@table @kbd 1775@table @kbd
1776@item C-c C-w
1777@itemx M-x c-subword-mode
1778@findex c-subword-mode
1779Enable (or disable) @dfn{subword mode} - Emacs's word commands then
1780recognize upper case letters in @samp{StudlyCapsIdentifiers} as word
1781boundaries. This is indicated by the flag @samp{/w} on the mode line
1782after the mode name (e.g. @samp{C/law}). You can even use @kbd{M-x
1783c-subword-mode} in non-CC Mode buffers.
1784
1690@item M-x c-context-line-break 1785@item M-x c-context-line-break
1691@findex c-context-line-break 1786@findex c-context-line-break
1692This command inserts a line break and indents the new line in a manner 1787This command inserts a line break and indents the new line in a manner
@@ -1697,9 +1792,13 @@ it's like @kbd{M-j} (@code{c-indent-new-comment-line}).
1697 1792
1698@code{c-context-line-break} isn't bound to a key by default, but it 1793@code{c-context-line-break} isn't bound to a key by default, but it
1699needs a binding to be useful. The following code will bind it to 1794needs a binding to be useful. The following code will bind it to
1700@kbd{C-j}. 1795@kbd{C-j}. We use @code{c-initialization-hook} here to make sure
1796the keymap is loaded before we try to change it.
1797
1701@example 1798@example
1702(define-key c-mode-base-map "\C-j" 'c-context-line-break) 1799(defun my-bind-clb ()
1800 (define-key c-mode-base-map "\C-j" 'c-context-line-break))
1801(add-hook 'c-initialization-hook 'my-bind-clb)
1703@end example 1802@end example
1704 1803
1705@item C-M-h 1804@item C-M-h