comparison man/cc-mode.texi @ 32:e04119814345 r19-15b99

Import from CVS: tag r19-15b99
author cvs
date Mon, 13 Aug 2007 08:52:56 +0200
parents ac2d302a0011
children 131b0175ea99
comparison
equal deleted inserted replaced
31:b9328a10c56c 32:e04119814345
1 \input texinfo @c -*- texinfo -*- 1 \input texinfo
2 2
3 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 3 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
4 @comment %**start of header (This is for running Texinfo on a region) 4 @comment %**start of header (This is for running Texinfo on a region)
5 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 5 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6 6
7 @setfilename ../info/cc-mode.info 7 @setfilename cc-mode.info
8 @settitle CC-MODE Version 4 Documentation 8 @settitle CC MODE Version 4 Documentation
9 @footnotestyle end 9 @footnotestyle end
10 10
11 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 11 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12 @comment @setchapternewpage odd !! we don't want blank pages !! 12 @comment @setchapternewpage odd !! we don't want blank pages !!
13 @comment %**end of header (This is for running Texinfo on a region) 13 @comment %**end of header (This is for running Texinfo on a region)
15 15
16 16
17 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 17 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
18 @comment 18 @comment
19 @comment texinfo manual for @file{cc-mode.el} version 4 19 @comment texinfo manual for @file{cc-mode.el} version 4
20 @comment manual version: 2.55 20 @comment manual version: 2.66
21 @comment generated from the original README file by Krishna Padmasola 21 @comment generated from the original README file by Krishna Padmasola
22 @comment <krishna@earth-gw.njit.edu> 22 @comment <krishna@earth-gw.njit.edu>
23 @comment 23 @comment
24 @comment Barry A. Warsaw <bwarsaw@cnri.reston.va.us> 24 @comment Barry A. Warsaw <bwarsaw@cnri.reston.va.us>
25 @comment Last modification: 1996/08/21 19:29:16 25 @comment Last modification: 1997/03/07 23:36:14
26 @comment 26 @comment
27 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 27 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
28 28
29 29
30 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 30 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
46 46
47 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 47 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
48 @comment The title is printed in a large font. 48 @comment The title is printed in a large font.
49 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 49 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
50 50
51 @center @titlefont{CC-MODE Version 4} 51 @center @titlefont{CC Mode Version 4}
52 @sp 2 52 @sp 2
53 @center A GNU Emacs mode for editing C, C++, Objective-C, and Java code. 53 @center A GNU Emacs mode for editing C, C++, Objective-C, and Java code.
54 @center (manual revision: 2.55) 54 @center (manual revision: 2.66)
55 @sp 2 55 @sp 2
56 @center Barry A. Warsaw 56 @center Barry A. Warsaw
57 57
58 58
59 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 59 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
87 * Commands:: 87 * Commands::
88 * Customizing Indentation:: 88 * Customizing Indentation::
89 * Syntactic Symbols:: 89 * Syntactic Symbols::
90 * Performance Issues:: 90 * Performance Issues::
91 * Frequently Asked Questions:: 91 * Frequently Asked Questions::
92 * Getting the latest cc-mode release:: 92 * Getting the latest CC Mode release::
93 * Sample .emacs File:: 93 * Sample .emacs File::
94 * Limitations and Known Bugs:: 94 * Limitations and Known Bugs::
95 * Mailing Lists and Submitting Bug Reports:: 95 * Mailing Lists and Submitting Bug Reports::
96 * Concept Index:: 96 * Concept Index::
97 * Command Index:: Command Index 97 * Command Index:: Command Index
105 @node Introduction, Getting Connected, Top, Top 105 @node Introduction, Getting Connected, Top, Top
106 @comment node-name, next, previous, up 106 @comment node-name, next, previous, up
107 @chapter Introduction 107 @chapter Introduction
108 @cindex Introduction 108 @cindex Introduction
109 109
110 @macro ccmode
111 CC Mode
112 @end macro
113
110 @cindex BOCM 114 @cindex BOCM
111 Welcome to @code{cc-mode}, version 4. This is a GNU Emacs mode for 115 Welcome to @ccmode{}, version 4. This is a GNU Emacs mode for
112 editing files containing C, C++, Objective-C, and Java code. 116 editing files containing C, C++, Objective-C, and Java code.
113 This incarnation of the mode is descendant from @file{c-mode.el} (also 117 This incarnation of the mode is descendant from @file{c-mode.el} (also
114 called "Boring Old C Mode" or BOCM @code{:-)}, and @file{c++-mode.el} 118 called "Boring Old C Mode" or BOCM @code{:-)}, and @file{c++-mode.el}
115 version 2, which I have been maintaining since 1992. @code{cc-mode} 119 version 2, which I have been maintaining since 1992. @ccmode{}
116 represents a significant milestone in the mode's life. It has been 120 represents a significant milestone in the mode's life. It has been
117 fully merged back with Emacs 19's @file{c-mode.el}. Also a new, more 121 fully merged back with Emacs 19's @file{c-mode.el}. Also a new, more
118 intuitive and flexible mechanism for controlling indentation has been 122 intuitive and flexible mechanism for controlling indentation has been
119 developed. 123 developed.
120 124
121 @code{cc-mode} version 4 supports the editing of K&R and ANSI C, 125 @ccmode{} version 4 supports the editing of K&R and ANSI C, @dfn{ARM}
122 @dfn{ARM} @footnote{i.e. ``The Annotated C++ Reference Manual'', by 126 @footnote{``The Annotated C++ Reference Manual'', by Ellis and
123 Ellis and Stroustrup.} C++, Objective-C, and Java files. In this way, 127 Stroustrup.} C++, Objective-C, and Java files. In this way, you can
124 you can easily set up consistent coding styles for use in editing all C, 128 easily set up consistent coding styles for use in editing all C, C++,
125 C++, Objective-C, and Java programs. @code{cc-mode} does @emph{not} 129 Objective-C, and Java programs. @ccmode{} does @emph{not} handle
126 handle font-locking (a.k.a. syntax coloring, keyword highlighting) or 130 font-locking (a.k.a. syntax coloring, keyword highlighting) or anything
127 anything of that nature, for any of the 4 modes. Those are handled by 131 of that nature, for any of the 4 modes. Those are handled by other
128 other Emacs packages. 132 Emacs packages.
129 133
130 This manual will describe the following: 134 This manual will describe the following:
131 135
132 @itemize @bullet 136 @itemize @bullet
133 @item 137 @item
134 How to get started using @code{cc-mode}. 138 How to get started using @ccmode{}.
135 139
136 @item 140 @item
137 How the new indentation engine works. 141 How the new indentation engine works.
138 142
139 @item 143 @item
140 How to customize the new indentation engine. 144 How to customize the new indentation engine.
141 145
142 @end itemize 146 @end itemize
143 147
144 Note that the name of this file is @file{cc-mode.el}, and I'll often 148 Note that the name of this package is ``@ccmode{}''. The main file for
145 refer to the package as @code{cc-mode}, but there really is no top level 149 @ccmode{} is @file{cc-mode.el}, but other files are included in the
146 @code{cc-mode} entry point. I call it @code{cc-mode} simply to 150 @ccmode{} distribution. There is no top level @code{cc-mode} entry
147 differentiate it from @file{c-mode.el}. All of the variables, commands, 151 point. All of the variables, commands, and functions in @ccmode{} are
148 and functions in @code{cc-mode} are prefixed with 152 prefixed with @code{c-@var{<thing>}}, and @code{c-mode},
149 @code{c-@var{<thing>}}, and @code{c-mode}, @code{c++-mode}, 153 @code{c++-mode}, @code{objc-mode}, and @code{java-mode} entry points are
150 @code{objc-mode}, and @code{java-mode} entry points are provided. This 154 provided. This file is intended to be a replacement for
151 file is intended to be a replacement for @file{c-mode.el} and 155 @file{c-mode.el} and @file{c++-mode.el}.
152 @file{c++-mode.el}.
153 156
154 @findex c-version 157 @findex c-version
155 The major version number was incremented to 4 with the addition of 158 The major version number was incremented to 4 with the addition of
156 @code{objc-mode}. To find the minor revision number of this release, use 159 @code{objc-mode}. To find the minor revision number of this release, use
157 @kbd{M-x c-version RET}. 160 @kbd{M-x c-version RET}.
158 161
159 As of this writing (20-Aug-1996), both Emacs 19.33 and XEmacs 19.14 are 162 As of this writing (27-Feb-1997), Emacs 19.34, XEmacs 19.14, and XEmacs
160 distributed with @code{cc-mode}, however neither have the very latest 163 20.0 are all distributed with @ccmode{}, but they may not have the
161 version. In all likelihood, Emacs 19.34 and XEmacs 19.15 will contain 164 latest releases. You may therefore, want to upgrade your copy of
162 the latest version of @code{cc-mode}. You may therefore, want to 165 @ccmode{}. See @ref{Getting the latest CC Mode release}.
163 upgrade your copy of @code{cc-mode}. See @ref{Getting the latest
164 cc-mode release}.
165 166
166 @cindex @file{cc-compat.el} file 167 @cindex @file{cc-compat.el} file
167 This distribution also contains a file called @file{cc-compat.el} which 168 This distribution also contains a file called @file{cc-compat.el} which
168 should ease your transition from BOCM to @code{cc-mode}. It currently 169 should ease your transition from BOCM to @ccmode{}. It currently
169 comes unguaranteed and unsupported, but this may change for future 170 comes unguaranteed and unsupported, but this may change for future
170 versions. If you have a BOCM configuration you are really happy with, 171 versions. If you have a BOCM configuration you are really happy with,
171 and want to postpone learning how to configure @code{cc-mode}, take a 172 and want to postpone learning how to configure @ccmode{}, take a
172 look at that file. It maps BOCM configuration variables to 173 look at that file. It maps BOCM configuration variables to
173 @code{cc-mode}'s new indentation model. 174 @ccmode{}'s new indentation model.
174 175
175 A special word of thanks goes to Krishna Padmasola for his work in 176 A special word of thanks goes to Krishna Padmasola for his work in
176 converting the original @file{README} file to texinfo format. 177 converting the original @file{README} file to texinfo format.
177 178
178 179
183 @chapter Getting Connected 184 @chapter Getting Connected
184 @cindex Getting Connected 185 @cindex Getting Connected
185 186
186 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 187 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
187 188
188 @file{cc-mode.el} works well with the 2 main branches of Emacs 19: 189 @file{cc-mode.el} works well with the three main branches of Emacs:
189 XEmacs, maintained by @code{xemacs.org} and the Emacs 19 maintained by 190 XEmacs 19 and XEmacs 20, both maintained by @code{xemacs.org}, and Emacs
190 the Free Software Foundation. Emacs 19 users will want to use Emacs 191 19 maintained by the Free Software Foundation. Emacs users will want to
191 version 19.21 or better, XEmacs users will want 19.6 or better. Earlier 192 use version 19.21 or better, XEmacs users will want 19.6 or better.
192 versions of these Emacsen have deficiencies and/or bugs which will 193 Earlier versions of these Emacsen have deficiencies and/or bugs which
193 adversely affect the performance and usability of @code{cc-mode}. You 194 will adversely affect the performance and usability of @ccmode{}. You
194 are better off just getting the latest version of Emacs or XEmacs. 195 are better off just getting the latest version of Emacs or XEmacs.
195 196
196 @cindex @file{cc-mode-18.el} file 197 @cindex @file{cc-mode-18.el} file
197 @file{cc-mode.el} will work with Emacs 18 if you use the 198 @file{cc-mode.el} will work with Emacs 18 if you use the
198 @file{cc-mode-18.el} compatibility file, but only moderately well. A 199 @file{cc-mode-18.el} compatibility file, but only moderately well. A
199 word of warning though, @emph{Emacs 18 lacks some fundamental 200 word of warning though, @emph{Emacs 18 lacks some fundamental
200 functionality and ultimately, using Emacs 18 is a losing 201 functionality and ultimately, using Emacs 18 is a losing
201 battle}. Hence @code{cc-mode} under Emacs 18 is no longer supported and 202 battle}. Hence @ccmode{} under Emacs 18 is no longer supported and
202 it is highly recommended that you upgrade to Emacs 19. If you use 203 it is highly recommended that you upgrade to Emacs 19. If you use
203 @code{cc-mode} under Emacs 18, you're on your own. With @code{cc-mode} 204 @ccmode{} under Emacs 18, you're on your own. With @ccmode{}
204 version 5, Emacs 18 support will be dropped altogether. 205 version 5, Emacs 18 support will be dropped altogether.
205 206
206 Note that as of XEmacs 19.13 and Emacs 19.30, your Emacs already comes 207 Note that as of XEmacs 19.13 and Emacs 19.30, your Emacs already comes
207 with @code{cc-mode} version 4 preconfigured for your use. You should be 208 with @ccmode{} version 4 preconfigured for your use. You should be
208 able to safely skip the rest of the setup information in this chapter, 209 able to safely skip the rest of the setup information in this chapter,
209 unless you want to install the latest version of @code{cc-mode} into one 210 unless you want to install the latest version of @ccmode{} into one
210 of these Emacsen. 211 of these Emacsen.
211 212
212 @cindex @file{.emacs} file 213 @cindex .emacs file
213 The first thing you will want to do is put @file{cc-mode.el} somewhere 214 The first thing you will want to do is put @file{cc-mode.el} somewhere
214 on your @code{load-path} so Emacs can find it. Do a @kbd{C-h v 215 on your @code{load-path} so Emacs can find it. Do a @kbd{C-h v
215 load-path RET} to see all the directories Emacs looks at when loading a 216 load-path RET} to see all the directories Emacs looks at when loading a
216 file. If none of these directories are appropriate, create a new 217 file. If none of these directories are appropriate, create a new
217 directory and add it to your @code{load-path}: 218 directory and add it to your @code{load-path}:
251 M-x byte-compile-file RET ~/mylisp/cc-mode.el RET 252 M-x byte-compile-file RET ~/mylisp/cc-mode.el RET
252 253
253 @end example 254 @end example
254 255
255 If you are running a version of Emacs or XEmacs that comes with 256 If you are running a version of Emacs or XEmacs that comes with
256 @code{cc-mode} by default, you can simply add the following to your 257 @ccmode{} by default, you can simply add the following to your
257 @file{.emacs} file in order to upgrade to the latest version of 258 @file{.emacs} file in order to upgrade to the latest version of
258 @code{cc-mode}: 259 @ccmode{}:
259 @example 260 @example
260 261
261 (load "cc-mode") 262 (load "cc-mode")
262 263
263 @end example 264 @end example
281 282
282 @end group 283 @end group
283 @end example 284 @end example
284 285
285 After those lines you will want to add the following autoloads to your 286 After those lines you will want to add the following autoloads to your
286 @file{.emacs} file so that @code{cc-mode} gets loaded at the right time: 287 @file{.emacs} file so that @ccmode{} gets loaded at the right time:
287 @example 288 @example
288 @group 289 @group
289 290
290 (autoload 'c++-mode "cc-mode" "C++ Editing Mode" t) 291 (autoload 'c++-mode "cc-mode" "C++ Editing Mode" t)
291 (autoload 'c-mode "cc-mode" "C Editing Mode" t) 292 (autoload 'c-mode "cc-mode" "C Editing Mode" t)
293 (autoload 'java-mode "cc-mode" "Java Editing Mode" t) 294 (autoload 'java-mode "cc-mode" "Java Editing Mode" t)
294 295
295 @end group 296 @end group
296 @end example 297 @end example
297 298
298 Alternatively, if you want to make sure @code{cc-mode} is loaded when 299 Alternatively, if you want to make sure @ccmode{} is loaded when
299 Emacs starts up, you could use this line instead of the autoloads 300 Emacs starts up, you could use this line instead of the autoloads
300 above: 301 above:
301 @example 302 @example
302 303
303 (require 'cc-mode) 304 (require 'cc-mode)
333 @code{auto-mode-alist}, but it won't hurt to put them on there again. 334 @code{auto-mode-alist}, but it won't hurt to put them on there again.
334 335
335 That's all you need --- I know, I know, it sounds like a lot @code{:-)}, 336 That's all you need --- I know, I know, it sounds like a lot @code{:-)},
336 but after you've done all this, you should only need to quit and restart 337 but after you've done all this, you should only need to quit and restart
337 Emacs. The next time you visit a C, C++, Objective-C, or Java file you 338 Emacs. The next time you visit a C, C++, Objective-C, or Java file you
338 should be using @code{cc-mode}. You can check this easily by hitting 339 should be using @ccmode{}. You can check this easily by hitting
339 @kbd{M-x c-version RET} in the @code{c-mode}, @code{c++-mode}, or 340 @kbd{M-x c-version RET}; you should see this message in the echo area:
340 @code{objc-mode} buffer. You should see this message in the echo area: 341 @example
341 @example 342
342 343 Using CC Mode version 4.@var{xxx}
343 Using @code{cc-mode} version 4.@var{xxx} 344
344 345 @end example
345 Where @var{xxx} is the latest release minor number. 346
346 347 @noindent
347 @end example 348 where @var{xxx} is the latest minor release number.
349
348 350
349 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 351 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
350 @node New Indentation Engine, Minor Modes, Getting Connected, Top 352 @node New Indentation Engine, Minor Modes, Getting Connected, Top
351 @comment node-name, next, previous,up 353 @comment node-name, next, previous, up
352 354
353 @chapter New Indentation Engine 355 @chapter New Indentation Engine
354 @cindex New Indentation Engine 356 @cindex New Indentation Engine
355 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 357 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
356 358
357 @code{cc-mode} has a new indentation engine, providing a simplified, yet 359 @ccmode{} has a new indentation engine, providing a simplified, yet
358 flexible and general mechanism for customizing indentation. It breaks 360 flexible and general mechanism for customizing indentation. It separates
359 indentation calculation into two steps. First, for the line of code being 361 indentation calculation into two steps: first, @ccmode{} analyzes the
360 indented, @code{cc-mode} analyzes what kind of language construct it's 362 line of code being indented to determine the kind of language construct
361 looking at, then it applies user defined offsets to the current line 363 it's looking at, then it applies user defined offsets to the current
362 based on this analysis. 364 line based on this analysis.
363 365
364 This section will briefly cover how indentation is calculated in 366 This section will briefly cover how indentation is calculated in
365 @code{cc-mode}. It is important to understand the indentation model 367 @ccmode{}. It is important to understand the indentation model
366 being used so that you will know how to customize @code{cc-mode} for 368 being used so that you will know how to customize @ccmode{} for
367 your personal coding style. 369 your personal coding style.
368 370
369 @menu 371 @menu
370 * Syntactic Analysis:: 372 * Syntactic Analysis::
371 * Indentation Calculation:: 373 * Indentation Calculation::
384 @cindex relative buffer position 386 @cindex relative buffer position
385 @cindex syntactic symbol 387 @cindex syntactic symbol
386 @cindex syntactic component 388 @cindex syntactic component
387 @cindex syntactic component list 389 @cindex syntactic component list
388 @cindex relative buffer position 390 @cindex relative buffer position
389 The first thing @code{cc-mode} does when indenting a line of code, is to 391 The first thing @ccmode{} does when indenting a line of code, is to
390 analyze the line, determining the @dfn{syntactic component list} of the 392 analyze the line, determining the @dfn{syntactic component list} of the
391 construct on that line. A @dfn{syntactic component} consists of a pair 393 construct on that line. A @dfn{syntactic component} consists of a pair
392 of information (in lisp parlance, a @emph{cons cell}), where the first 394 of information (in lisp parlance, a @emph{cons cell}), where the first
393 part is a @dfn{syntactic symbol}, and the second part is a @dfn{relative 395 part is a @dfn{syntactic symbol}, and the second part is a @dfn{relative
394 buffer position}. Syntactic symbols describe elements of C code 396 buffer position}. Syntactic symbols describe elements of C code
403 405
404 Conceptually, a line of C code is always indented relative to the 406 Conceptually, a line of C code is always indented relative to the
405 indentation of some line higher up in the buffer. This is represented 407 indentation of some line higher up in the buffer. This is represented
406 by the relative buffer position in the syntactic component. 408 by the relative buffer position in the syntactic component.
407 409
408 It might help to see an example. Suppose we had the following code as 410 Here is an example. Suppose we had the following code as the only thing
409 the only thing in a @code{c++-mode} buffer @footnote{The line numbers in 411 in a @code{c++-mode} buffer @footnote{The line numbers in this and
410 this and future examples don't actually appear in the buffer, of course!}: 412 future examples don't actually appear in the buffer, of course!}:
411 @example 413 @example
412 @group 414 @group
413 415
414 1: void swap( int& a, int& b ) 416 1: void swap( int& a, int& b )
415 2: @{ 417 2: @{
437 439
438 @end example 440 @end example
439 441
440 This tells us that the line is a statement and it is indented relative 442 This tells us that the line is a statement and it is indented relative
441 to buffer position 35, which happens to be the @samp{i} in @code{int} on 443 to buffer position 35, which happens to be the @samp{i} in @code{int} on
442 line 3. If you were to move Point to line 3 and hit @kbd{C-c C-s}, you 444 line 3. If you were to move point to line 3 and hit @kbd{C-c C-s}, you
443 would see: 445 would see:
444 @example 446 @example
445 447
446 ((defun-block-intro . 29)) 448 ((defun-block-intro . 29))
447 449
477 479
478 @cindex substatement 480 @cindex substatement
479 @cindex substatment block 481 @cindex substatment block
480 @noindent 482 @noindent
481 which tells us that this is a brace that @emph{opens} a substatement 483 which tells us that this is a brace that @emph{opens} a substatement
482 block. @footnote{A @dfn{substatement} indicates the line after an 484 block. @footnote{A @dfn{substatement} indicates the line after a
483 @code{if}, @code{else}, @code{while}, @code{do}, @code{switch}, or 485 conditional statement, such as @code{if}, @code{else}, @code{while},
484 @code{for} statement, and a @dfn{substatement block} is a brace block 486 @code{do}, @code{switch}, or @code{for} in C. A @dfn{substatement
485 following one of those constructs.} 487 block} is a brace block following one of those conditionals.}
486 488
487 @cindex comment only line 489 @cindex comment only line
488 Syntactic component lists can contain more than one component, and 490 Syntactic component lists can contain more than one component, and
489 individual syntactic components need not have relative buffer positions. 491 individual syntactic components need not have relative buffer positions.
490 The most common example of this is a line that contains a @dfn{comment 492 The most common example of this is a line that contains a @dfn{comment
535 First, the syntactic symbols are looked up in the @code{c-offsets-alist} 537 First, the syntactic symbols are looked up in the @code{c-offsets-alist}
536 variable, which is an association list of syntactic symbols and the 538 variable, which is an association list of syntactic symbols and the
537 offsets to apply for those symbols. These offsets are added to a 539 offsets to apply for those symbols. These offsets are added to a
538 running total. 540 running total.
539 541
540 Second, if the component has a relative buffer position, @code{cc-mode} 542 Second, if the component has a relative buffer position, @ccmode{}
541 adds the column number of that position to the running total. By adding 543 adds the column number of that position to the running total. By adding
542 up the offsets and columns for every syntactic component on the list, 544 up the offsets and columns for every syntactic component on the list,
543 the final total indentation for the current line is computed. 545 the final total indentation for the current line is computed.
544 546
545 Let's use our two code examples above to see how this works. Here is 547 Let's use our two code examples above to see how this works. Here is
556 558
557 @end group 559 @end group
558 @end example 560 @end example
559 561
560 @kindex TAB 562 @kindex TAB
561 Let's say Point is on line 3 and we hit the @key{TAB} key to re-indent 563 Let's say point is on line 3 and we hit the @key{TAB} key to re-indent
562 the line. Remember that the syntactic component list for that 564 the line. Remember that the syntactic component list for that
563 line is: 565 line is:
564 @example 566 @example
565 567
566 ((defun-block-intro . 29)) 568 ((defun-block-intro . 29))
567 569
568 @end example 570 @end example
569 571
570 @noindent 572 @noindent
571 @code{cc-mode} looks up @code{defun-block-intro} in the 573 @ccmode{} looks up @code{defun-block-intro} in the
572 @code{c-offsets-alist} variable. Let's say it finds the value @samp{4}; 574 @code{c-offsets-alist} variable. Let's say it finds the value @samp{4};
573 it adds this to the running total (initialized to zero), yielding a 575 it adds this to the running total (initialized to zero), yielding a
574 running total indentation of 4 spaces. 576 running total indentation of 4 spaces.
575 577
576 Next @code{cc-mode} goes to buffer position 29 and asks for the current 578 Next @ccmode{} goes to buffer position 29 and asks for the current
577 column. This brace is in column zero, so @code{cc-mode} 579 column. This brace is in column zero, so @ccmode{}
578 adds @samp{0} to the running total. Since there is only one syntactic 580 adds @samp{0} to the running total. Since there is only one syntactic
579 component on the list for this line, indentation calculation is 581 component on the list for this line, indentation calculation is
580 complete, and the total indentation for the line 582 complete, and the total indentation for the line
581 is 4 spaces. 583 is 4 spaces.
582 584
603 605
604 ((substatement-open . 46)) 606 ((substatement-open . 46))
605 607
606 @end example 608 @end example
607 609
608 Here, @code{cc-mode} first looks up the @code{substatement-open} symbol 610 Here, @ccmode{} first looks up the @code{substatement-open} symbol
609 in @code{c-offsets-alist}. Let's say it finds the value @samp{4}. This 611 in @code{c-offsets-alist}. Let's say it finds the value @samp{4}. This
610 yields a running total of 4. @code{cc-mode} then goes to 612 yields a running total of 4. @ccmode{} then goes to
611 buffer position 46, which is the @samp{i} in @code{if} on line 3. This 613 buffer position 46, which is the @samp{i} in @code{if} on line 3. This
612 character is in the fourth column on that line so adding this to the 614 character is in the fourth column on that line so adding this to the
613 running total yields an indentation for the line of 8 spaces. 615 running total yields an indentation for the line of 8 spaces.
614 616
615 Simple, huh? 617 Simple, huh?
620 being used. 622 being used.
621 623
622 @vindex c-echo-syntactic-information-p 624 @vindex c-echo-syntactic-information-p
623 @vindex echo-syntactic-information-p (c-) 625 @vindex echo-syntactic-information-p (c-)
624 @cindex TAB 626 @cindex TAB
625 To help you configure @code{cc-mode}, you can set the variable 627 As you configure @ccmode{}, you might want to set the variable
626 @code{c-echo-syntactic-information-p} to non-@code{nil} so that the 628 @code{c-echo-syntactic-information-p} to non-@code{nil} so that the
627 syntactic component list and calculated offset will always be echoed in 629 syntactic component list and calculated offset will always be echoed in
628 the minibuffer when you hit @kbd{TAB}. 630 the minibuffer when you hit @kbd{TAB}.
629 631
630 632
634 636
635 @chapter Minor Modes 637 @chapter Minor Modes
636 @cindex Minor Modes 638 @cindex Minor Modes
637 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 639 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
638 640
639 @code{cc-mode} contains two minor-mode-like features that you should 641 @ccmode{} contains two minor-mode-like features that you should
640 find useful while you enter new C code. The first is called 642 find useful while you enter new C code. The first is called
641 @dfn{auto-newline} mode, and the second is called @dfn{hungry-delete} 643 @dfn{auto-newline} mode, and the second is called @dfn{hungry-delete}
642 mode. These minor modes can be toggled on and off independently, and 644 mode. These minor modes can be toggled on and off independently, and
643 @code{cc-mode} can be configured so that it starts up with any 645 @ccmode{} can be configured so that it starts up with any
644 combination of these minor modes. By default, both of these minor modes 646 combination of these minor modes. By default, both of these minor modes
645 are turned off. 647 are turned off.
646 648
647 The state of the minor modes is always reflected in the minor mode list 649 The state of the minor modes is always reflected in the minor mode list
648 on the modeline of the @code{cc-mode} buffer. When auto-newline mode is 650 on the modeline of the @ccmode{} buffer. When auto-newline mode is
649 enabled, you will see @samp{C/a} on the mode line @footnote{Remember 651 enabled, you will see @samp{C/a} on the mode line @footnote{Remember
650 that the @samp{C} could be replaced with @samp{C++}, @samp{ObjC}, or 652 that the @samp{C} could be replaced with @samp{C++}, @samp{ObjC}, or
651 @samp{Java}.}. When hungry delete mode is enabled you would see 653 @samp{Java}.}. When hungry delete mode is enabled you would see
652 @samp{C/h} and when both modes are enabled, you'd see @samp{C/ah}. 654 @samp{C/h} and when both modes are enabled, you'd see @samp{C/ah}.
653 655
658 @findex c-toggle-auto-state 660 @findex c-toggle-auto-state
659 @findex c-toggle-auto-hungry-state 661 @findex c-toggle-auto-hungry-state
660 @findex toggle-hungry-state (c-) 662 @findex toggle-hungry-state (c-)
661 @findex toggle-auto-state (c-) 663 @findex toggle-auto-state (c-)
662 @findex toggle-auto-hungry-state (c-) 664 @findex toggle-auto-hungry-state (c-)
663 @code{cc-mode} provides keybindings which allow you to toggle the minor 665 @ccmode{} provides keybindings which allow you to toggle the minor
664 modes on the fly while editing code. To toggle just the auto-newline 666 modes on the fly while editing code. To toggle just the auto-newline
665 state, hit @kbd{C-c C-a} (@code{c-toggle-auto-state}). When you do 667 state, hit @kbd{C-c C-a} (@code{c-toggle-auto-state}). When you do
666 this, you should see the @samp{a} indicator either appear or disappear 668 this, you should see the @samp{a} indicator either appear or disappear
667 on the modeline. Similarly, to toggle just the hungry-delete state, use 669 on the modeline. Similarly, to toggle just the hungry-delete state, use
668 @kbd{C-c C-d} (@code{c-toggle-hungry-state}), and to toggle both states, 670 @kbd{C-c C-d} (@code{c-toggle-hungry-state}), and to toggle both states,
678 So for example, if you wanted to enable both auto-newline and 680 So for example, if you wanted to enable both auto-newline and
679 hungry-delete for all your C file editing, you could add the following 681 hungry-delete for all your C file editing, you could add the following
680 to your @file{.emacs} file: 682 to your @file{.emacs} file:
681 @example 683 @example
682 684
683 (add-hook 'c-mode-common-hook '(lambda () (c-toggle-auto-hungry-state 1))) 685 (add-hook 'c-mode-common-hook
686 '(lambda () (c-toggle-auto-hungry-state 1)))
684 687
685 @end example 688 @end example
686 689
687 690
688 @cindex electric characters 691 @cindex electric characters
715 718
716 @cindex literal 719 @cindex literal
717 @cindex syntactic whitespace 720 @cindex syntactic whitespace
718 @item 721 @item
719 The character was not typed inside of a literal @footnote{A 722 The character was not typed inside of a literal @footnote{A
720 @dfn{literal} is defined in @code{cc-mode} as any comment, 723 @dfn{literal} is defined as any comment, string, or cpp macro
721 string, or cpp macro definition. These constructs are also known as 724 definition. These constructs are also known as @dfn{syntactic
722 @dfn{syntactic whitespace} since they are usually ignored when scanning 725 whitespace} since they are usually ignored when scanning C code.}.
723 C code.}.
724 726
725 @item 727 @item
726 @kindex C-u 728 @kindex C-u
727 No numeric argument was supplied to the command (i.e. it was typed as 729 No numeric argument was supplied to the command (i.e. it was typed as
728 normal, with no @kbd{C-u} prefix). 730 normal, with no @kbd{C-u} prefix).
729 731
730 @end itemize 732 @end itemize
731 733
732 Certain other conditions may apply on a language specific basis. For 734 @findex c-enable-//-in-c-mode
735 @findex enable-//-in-c-mode (c-)
736 Some characters are electric in some languages, and not in others. For
733 example, the second slash (@kbd{/}) of a C++ style line comment is 737 example, the second slash (@kbd{/}) of a C++ style line comment is
734 electric in @code{c++-mode}, @code{objc-mode}, and @code{java-mode}, but 738 electric in @code{c++-mode}, @code{objc-mode}, and @code{java-mode}, but
735 not in @code{c-mode}. 739 not in @code{c-mode}@footnote{Ordinarily, @samp{//} does not introduce a
740 comment in @code{c-mode}. However, if you call the function
741 @code{c-enable-//-in-c-mode}, @code{c-mode} will recognize C++ style
742 line comments. Note however that this is a global change which will
743 affect all your @code{c-mode} buffers.}.
736 744
737 745
738 @menu 746 @menu
739 * Hanging Braces:: 747 * Hanging Braces::
740 * Hanging Colons:: 748 * Hanging Colons::
803 is called an @var{ACTION} which can be either a function or a list. 811 is called an @var{ACTION} which can be either a function or a list.
804 @xref{Custom Brace and Colon Hanging} for a more detailed discussion of 812 @xref{Custom Brace and Colon Hanging} for a more detailed discussion of
805 using a function as a brace hanging @var{ACTION}. 813 using a function as a brace hanging @var{ACTION}.
806 814
807 When the @var{ACTION} is a list, it can contain any combination of the 815 When the @var{ACTION} is a list, it can contain any combination of the
808 symbols @code{before} and @code{after}, directing @code{cc-mode} where to 816 symbols @code{before} and @code{after}, directing @ccmode{} where to
809 put newlines in relationship to the brace being inserted. Thus, if the 817 put newlines in relationship to the brace being inserted. Thus, if the
810 list contains only the symbol @code{after}, then the brace is said to 818 list contains only the symbol @code{after}, then the brace is said to
811 @dfn{hang} on the right side of the line, as in: 819 @dfn{hang} on the right side of the line, as in:
812 @example 820 @example
813 @group 821 @group
845 right side, and allow subsequent text to follow on the same line as the 853 right side, and allow subsequent text to follow on the same line as the
846 brace. Also, @code{substatement-open} and @code{extern-lang-open} 854 brace. Also, @code{substatement-open} and @code{extern-lang-open}
847 braces should hang on the right side, but subsequent text should follow 855 braces should hang on the right side, but subsequent text should follow
848 on the next line. Here, in the @code{block-close} entry, you also see 856 on the next line. Here, in the @code{block-close} entry, you also see
849 an example of using a function as an @var{ACTION}. 857 an example of using a function as an @var{ACTION}.
858
859 A word of caution: it is not a good idea to hang top-level construct
860 introducing braces, such as @code{class-open} or @code{defun-open}.
861 Emacs makes an assumption that such braces will always appear in column
862 zero, hanging such braces can introduce performance problems.
863 @xref{Performance Issues} for more information.
850 864
851 865
852 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 866 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
853 @node Hanging Colons, Hanging Semi-colons and commas, Hanging Braces, Auto-newline insertion 867 @node Hanging Colons, Hanging Semi-colons and commas, Hanging Braces, Auto-newline insertion
854 @comment node-name, next, previous,up 868 @comment node-name, next, previous,up
870 884
871 @cindex clean-ups 885 @cindex clean-ups
872 In C++, double-colons are used as a scope operator but because these 886 In C++, double-colons are used as a scope operator but because these
873 colons always appear right next to each other, newlines before and after 887 colons always appear right next to each other, newlines before and after
874 them are controlled by a different mechanism, called @dfn{clean-ups} in 888 them are controlled by a different mechanism, called @dfn{clean-ups} in
875 @code{cc-mode}. @xref{Clean-ups} for details. 889 @ccmode{}. @xref{Clean-ups} for details.
876 890
877 891
878 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 892 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
879 @node Hanging Semi-colons and commas, Other electric commands, Hanging Colons, Auto-newline insertion 893 @node Hanging Semi-colons and commas, Other electric commands, Hanging Colons, Auto-newline insertion
880 @comment node-name, next, previous,up 894 @comment node-name, next, previous,up
881 895
882 @subsection Hanging Semi-colons and commas 896 @subsection Hanging Semi-colons and commas
883 @cindex Hanging Semi-colons and commas 897 @cindex Hanging Semi-colons and commas
884 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 898 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
885 899
886 Semicolons and commas are also electric in @code{cc-mode}, but since 900 Semicolons and commas are also electric in @ccmode{}, but since
887 these characters do not correspond directly to syntactic symbols, a 901 these characters do not correspond directly to syntactic symbols, a
888 different mechanism is used to determine whether newlines should be 902 different mechanism is used to determine whether newlines should be
889 automatically inserted after these characters. @xref{Customizing 903 automatically inserted after these characters. @xref{Customizing
890 Semi-colons and Commas} for details. 904 Semi-colons and Commas} for details.
891 905
969 enabled. Clean-ups are used however to adjust code ``after-the-fact'', 983 enabled. Clean-ups are used however to adjust code ``after-the-fact'',
970 i.e. to eliminate some whitespace that isn't inserted by electric 984 i.e. to eliminate some whitespace that isn't inserted by electric
971 commands, or whitespace that contains intervening constructs. 985 commands, or whitespace that contains intervening constructs.
972 986
973 @cindex literal 987 @cindex literal
974 You can configure @code{cc-mode}'s clean-ups by setting the variable 988 You can configure @ccmode{}'s clean-ups by setting the variable
975 @code{c-cleanup-list}, which is a list of clean-up symbols. By default, 989 @code{c-cleanup-list}, which is a list of clean-up symbols. By default,
976 @code{cc-mode} cleans up only the @code{scope-operator} construct, which 990 @ccmode{} cleans up only the @code{scope-operator} construct, which
977 is necessary for proper C++ support. Note that clean-ups are only 991 is necessary for proper C++ support. Note that clean-ups are only
978 performed when the construct does not occur within a literal (see 992 performed when the construct does not occur within a literal (see
979 @ref{Auto-newline insertion}), and when there is nothing but whitespace 993 @ref{Auto-newline insertion}), and when there is nothing but whitespace
980 appearing between the individual components of the construct. 994 appearing between the individual components of the construct.
981 995
982 @vindex c-cleanup-list 996 @vindex c-cleanup-list
983 @vindex cleanup-list (c-) 997 @vindex cleanup-list (c-)
984 There are currently only five specific constructs that @code{cc-mode} 998 There are currently only five specific constructs that @ccmode{}
985 can clean up, as indicated by these symbols: 999 can clean up, as indicated by these symbols:
986 1000
987 @itemize @bullet 1001 @itemize @bullet
988 @item 1002 @item
989 @code{brace-else-brace} --- cleans up @samp{@} else @{} constructs by 1003 @code{brace-else-brace} --- cleans up @samp{@} else @{} constructs by
1016 1030
1017 @end group 1031 @end group
1018 @end example 1032 @end example
1019 1033
1020 @item 1034 @item
1035 @code{brace-elseif-brace} --- similar to the @code{brace-else-brace}
1036 clean-up, but cleans up @samp{@} else if (...)@{} constructs. For
1037 example:
1038 @example
1039 @group
1040
1041 void spam(int i)
1042 @{
1043 if( i==7 )
1044 @{
1045 dosomething();
1046 @}
1047 else if( i==3 ) @{
1048
1049 @end group
1050 @end example
1051 @noindent
1052 appears like this after the open brace is typed:
1053 @example
1054 @group
1055
1056 void spam(int i)
1057 @{
1058 if( i==7 ) @{
1059 dosomething();
1060 @} else if( i==3 ) @{
1061
1062 @end group
1063 @end example
1064
1065 @item
1021 @code{empty-defun-braces} --- cleans up braces following a top-level 1066 @code{empty-defun-braces} --- cleans up braces following a top-level
1022 function or class definition that contains no body. Clean up occurs 1067 function or class definition that contains no body. Clean up occurs
1023 when the closing brace is typed. Thus the following: 1068 when the closing brace is typed. Thus the following:
1024 @example 1069 @example
1025 @group 1070 @group
1107 @findex c-electric-delete 1152 @findex c-electric-delete
1108 @findex electric-delete (c-) 1153 @findex electric-delete (c-)
1109 @vindex c-delete-function 1154 @vindex c-delete-function
1110 @vindex delete-function (c-) 1155 @vindex delete-function (c-)
1111 @cindex literal 1156 @cindex literal
1112 By default, @code{cc-mode} actually runs the command 1157 By default, @ccmode{} actually runs the command
1113 @code{c-electric-delete} when you hit @kbd{DEL}. When this command is 1158 @code{c-electric-delete} when you hit @kbd{DEL}. When this command is
1114 used to delete a single character (i.e. when it is called interactively 1159 used to delete a single character (i.e. when it is called interactively
1115 with no numeric argument), it really runs the function contained in the 1160 with no numeric argument), it really runs the function contained in the
1116 variable @code{c-delete-function}. This function is called with a 1161 variable @code{c-delete-function}. This function is called with a
1117 single argument, which is the number of characters to delete. 1162 single argument, which is the number of characters to delete.
1140 1185
1141 @section Indentation Commands 1186 @section Indentation Commands
1142 @cindex Indentation Commands 1187 @cindex Indentation Commands
1143 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 1188 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1144 1189
1145 @findex c-set-style
1146 @findex set-style (c-)
1147 Various commands are provided which allow you to conveniently re-indent 1190 Various commands are provided which allow you to conveniently re-indent
1148 C constructs. There are several things to 1191 C constructs. There are several things to
1149 note about these indentation commands. First, when you 1192 note about these indentation commands. First, when you
1150 change your programming style, either interactively or through some 1193 change your programming style, either interactively or through some
1151 other means, your file does @emph{not} automatically get re-indented. 1194 other means, your file does @emph{not} automatically get re-indented.
1155 @cindex c-hanging- functions 1198 @cindex c-hanging- functions
1156 @findex c-hanging-braces-alist 1199 @findex c-hanging-braces-alist
1157 @findex hanging-braces-alist (c-) 1200 @findex hanging-braces-alist (c-)
1158 Second, changing some variables have no effect on existing code, even 1201 Second, changing some variables have no effect on existing code, even
1159 when you do re-indent. For example, the @code{c-hanging-*} variables 1202 when you do re-indent. For example, the @code{c-hanging-*} variables
1160 and @code{c-cleanup-list} only affect new code as it is typed in. So 1203 and @code{c-cleanup-list} only affect new code as it is typed in
1161 for example, changing @code{c-hanging-braces-alist} and re-indenting the 1204 on-the-fly, so changing @code{c-hanging-braces-alist} and re-indenting
1162 buffer will not adjust placement of braces already in the file. 1205 the buffer will not adjust placement of braces already in the file.
1163 1206
1164 @vindex c-progress-interval 1207 @vindex c-progress-interval
1165 @vindex progress-interval (c-) 1208 @vindex progress-interval (c-)
1166 Third, re-indenting large portions of code is currently rather 1209 Third, re-indenting large portions of code is currently rather
1167 inefficient. Improvements have been made since previous releases of 1210 inefficient. Improvements have been made since previous releases of
1168 @code{cc-mode}, and much more radical improvements are planned, but for 1211 @ccmode{}, and much more radical improvements are planned, but for now
1169 now you need to be aware of this @footnote{In particular, I have had 1212 you need to be aware of this @footnote{In particular, I have had people
1170 people complain about the speed that @code{cc-mode} re-indents 1213 complain about the speed with which @code{lex(1)} output is re-indented.
1171 @code{lex(1)} output. Lex, yacc, and other code generators usually 1214 Lex, yacc, and other code generators usually output some pretty
1172 output some pretty perversely formatted code. @emph{Don't} try to 1215 perversely formatted code. @emph{Don't} try to indent this stuff!}.
1173 indent this stuff with @code{cc-mode}!}. Some provision has been made 1216 Some provision has been made to at least inform you as to the progress
1174 to at least inform you as to the progress of the re-indentation. The 1217 of the re-indentation. The variable @code{c-progress-interval} controls
1175 variable @code{c-progress-interval} controls how often a progress 1218 how often a progress message is displayed. Set this variable to
1176 message is displayed. Set this variable to @code{nil} to inhibit 1219 @code{nil} to inhibit progress messages. Note that this feature only
1177 progress messages. Note that this feature only works with Emacs 19. 1220 works with Emacs 19 and beyond.
1178 1221
1179 Also, except as noted below, re-indentation is always driven by the 1222 Also, except as noted below, re-indentation is always driven by the
1180 same mechanisms that control on-the-fly indentation of code. @xref{New 1223 same mechanisms that control on-the-fly indentation of code. @xref{New
1181 Indentation Engine} for details. 1224 Indentation Engine} for details.
1182 1225
1192 @findex tab-to-tab-stop 1235 @findex tab-to-tab-stop
1193 To indent a single line of code, use @kbd{TAB} 1236 To indent a single line of code, use @kbd{TAB}
1194 (@code{c-indent-command}). The behavior of this command is controlled 1237 (@code{c-indent-command}). The behavior of this command is controlled
1195 by the variable @code{c-tab-always-indent}. When this variable is 1238 by the variable @code{c-tab-always-indent}. When this variable is
1196 @code{t}, @kbd{TAB} always just indents the current line. When 1239 @code{t}, @kbd{TAB} always just indents the current line. When
1197 @code{nil}, the line is indented only if Point is at the left margin, or 1240 @code{nil}, the line is indented only if point is at the left margin, or
1198 on or before the first non-whitespace character on the line, otherwise 1241 on or before the first non-whitespace character on the line, otherwise
1199 @emph{something else happens}@footnote{Actually what happens is that the 1242 @emph{something else happens}@footnote{Actually what happens is that the
1200 function stored in the variable @code{c-insert-tab-function} is called. 1243 function stored in @code{c-insert-tab-function} is called.
1201 Normally this just inserts a real tab character, or the equivalent 1244 Normally this just inserts a real tab character, or the equivalent
1202 number of spaces, depending on the setting of the variable 1245 number of spaces, depending on the setting of the variable
1203 @code{indent-tabs-mode}. If you preferred, you could set 1246 @code{indent-tabs-mode}. If you preferred, you could set
1204 @code{c-insert-tab-function} to @code{tab-to-tab-stop} for example.}. 1247 @code{c-insert-tab-function} to @code{tab-to-tab-stop} for example.}.
1205 If the value of @code{c-tab-always-indent} is something other than 1248 If the value of @code{c-tab-always-indent} is something other than
1206 @code{t} or @code{nil} (e.g. @code{'other}), then a real tab 1249 @code{t} or @code{nil} (e.g. @code{'other}), then a real tab
1207 character@footnote{The caveat about @code{indent-tabs-mode} in the 1250 character@footnote{The caveat about @code{indent-tabs-mode} in the
1208 previous footnote also applies here.} is inserted only when Point is 1251 previous footnote also applies here.} is inserted only when point is
1209 inside a literal (see @ref{Auto-newline insertion}), otherwise the line 1252 inside a literal (see @ref{Auto-newline insertion}), otherwise the line
1210 is indented. 1253 is indented.
1211 1254
1212 @kindex M-C-q 1255 @kindex M-C-q
1213 @findex c-indent-exp 1256 @findex c-indent-exp
1214 @findex indent-exp (c-) 1257 @findex indent-exp (c-)
1215 To indent an entire balanced brace or parenthesis expression, use 1258 To indent an entire balanced brace or parenthesis expression, use
1216 @kbd{M-C-q} (@code{c-indent-exp}). Note that Point should be on 1259 @kbd{M-C-q} (@code{c-indent-exp}). Note that point should be on
1217 the opening brace or parenthesis of the expression you want to indent. 1260 the opening brace or parenthesis of the expression you want to indent.
1218 1261
1219 @kindex C-c C-q 1262 @kindex C-c C-q
1220 @findex c-indent-defun 1263 @findex c-indent-defun
1221 @findex indent-defun (c-) 1264 @findex indent-defun (c-)
1222 Another very convenient keystroke is @kbd{C-c C-q} 1265 Another very convenient keystroke is @kbd{C-c C-q}
1223 (@code{c-indent-defun}) when re-indents the entire top-level function or 1266 (@code{c-indent-defun}) when re-indents the entire top-level function or
1224 class definition that encompases Point. It leaves Point at the 1267 class definition that encompases point. It leaves point at the
1225 same position within the buffer. 1268 same position within the buffer.
1226 1269
1227 @kindex M-C-\ 1270 @kindex M-C-\
1228 @findex indent-region 1271 @findex indent-region
1229 To indent any arbitrary region of code, use @kbd{M-C-\} 1272 To indent any arbitrary region of code, use @kbd{M-C-\}
1230 (@code{indent-region}). This is a standard Emacs command, specially 1273 (@code{indent-region}). This is a standard Emacs command, specially
1231 tailored for C code in a @code{cc-mode} buffer. Note that of course, 1274 tailored for C code in a @ccmode{} buffer. Note that of course,
1232 Point and Mark must delineate the region you 1275 point and mark must delineate the region you
1233 want to indent. 1276 want to indent.
1234 1277
1235 @kindex M-C-h 1278 @kindex M-C-h
1236 @findex c-mark-function 1279 @findex c-mark-function
1237 @findex mark-function (c-) 1280 @findex mark-function (c-)
1245 1288
1246 @section Other Commands 1289 @section Other Commands
1247 @cindex Other Commands 1290 @cindex Other Commands
1248 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 1291 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1249 1292
1250 @code{cc-mode} contains other useful command for moving around in C 1293 @ccmode{} contains other useful command for moving around in C
1251 code. 1294 code.
1252 1295
1253 @table @code 1296 @table @code
1254 @item C-c C-u (c-up-conditional) 1297 @item C-c C-u (c-up-conditional)
1255 @kindex C-c C-u 1298 @kindex C-c C-u
1256 @findex c-up-conditional 1299 @findex c-up-conditional
1257 @findex up-conditional (c-) 1300 @findex up-conditional (c-)
1258 Move Point back to the containing preprocessor conditional, leaving the 1301 Move point back to the containing preprocessor conditional, leaving the
1259 Mark behind. A prefix argument acts as a repeat count. With a negative 1302 mark behind. A prefix argument acts as a repeat count. With a negative
1260 argument, move Point forward to the end of the containing 1303 argument, move point forward to the end of the containing
1261 preprocessor conditional. When going backwards, @code{#elif} is treated 1304 preprocessor conditional. When going backwards, @code{#elif} is treated
1262 like @code{#else} followed by @code{#if}. When going forwards, 1305 like @code{#else} followed by @code{#if}. When going forwards,
1263 @code{#elif} is ignored.@refill 1306 @code{#elif} is ignored.@refill
1264 1307
1265 @item C-c C-p (c-backward-conditional) 1308 @item C-c C-p (c-backward-conditional)
1266 @kindex C-c C-p 1309 @kindex C-c C-p
1267 @findex c-backward-conditional 1310 @findex c-backward-conditional
1268 @findex backward-conditional (c-) 1311 @findex backward-conditional (c-)
1269 Move Point back over a preprocessor conditional, leaving Mark 1312 Move point back over a preprocessor conditional, leaving the mark
1270 behind. A prefix argument acts as a repeat count. With a negative 1313 behind. A prefix argument acts as a repeat count. With a negative
1271 argument, move forward. 1314 argument, move forward.
1272 1315
1273 @item C-c C-n (c-forward-conditional) 1316 @item C-c C-n (c-forward-conditional)
1274 @kindex C-c C-n 1317 @kindex C-c C-n
1275 @findex c-forward-conditional 1318 @findex c-forward-conditional
1276 @findex forward-conditional (c-) 1319 @findex forward-conditional (c-)
1277 Move Point forward across a preprocessor conditional, leaving Mark 1320 Move point forward across a preprocessor conditional, leaving the mark
1278 behind. A prefix argument acts as a repeat count. With a negative 1321 behind. A prefix argument acts as a repeat count. With a negative
1279 argument, move backward. 1322 argument, move backward.
1280 1323
1281 @item M-a (c-beginning-of-statement) 1324 @item M-a (c-beginning-of-statement)
1282 @kindex ESC a 1325 @kindex ESC a
1283 @findex c-beginning-of-statement 1326 @findex c-beginning-of-statement
1284 @findex beginning-of-statement (c-) 1327 @findex beginning-of-statement (c-)
1285 Move Point to the beginning of the innermost C statement. If Point is 1328 Move point to the beginning of the innermost C statement. If point is
1286 already at the beginning of a statement, it moves to the beginning of 1329 already at the beginning of a statement, it moves to the beginning of
1287 the preceding statement. With prefix argument @var{n}, move back 1330 the preceding statement. With prefix argument @var{n}, move back
1288 @var{n} @minus{} 1 statements. 1331 @var{n} @minus{} 1 statements.
1289 1332
1290 If Point is within a string or comment, or next to a comment (only 1333 If point is within a string or comment, or at the end of a comment, this
1291 whitespace between them), this command moves by sentences instead of 1334 command moves by sentences instead of statements.
1292 statements. 1335
1293 1336 When called from a program, this function takes three optional
1294 When called from a program, this function takes two optional arguments: 1337 arguments: the numeric prefix argument, a buffer position limit (don't
1295 the numeric prefix argument, and a buffer position limit (don't move 1338 move back before that place), and a flag to indicate whether movement
1296 back before that place). 1339 should be by statements (if @code{t}) or sentence (if non-@code{nil}).
1297 1340
1298 @item M-e (c-end-of-statement) 1341 @item M-e (c-end-of-statement)
1299 @kindex ESC e 1342 @kindex ESC e
1300 @findex c-end-of-statement 1343 @findex c-end-of-statement
1301 @findex end-of-statement (c-) 1344 @findex end-of-statement (c-)
1302 Move Point to the end of the innermost C statement. If Point is at the 1345 Move point to the end of the innermost C statement. If point is at the
1303 end of a statement, move to the end of the next statement. With prefix 1346 end of a statement, move to the end of the next statement. With prefix
1304 argument @var{n}, move forward @var{n} @minus{} 1 statements. 1347 argument @var{n}, move forward @var{n} @minus{} 1 statements.
1305 1348
1306 If Point is within a string or comment, or next to a comment (only 1349 If point is within a string or comment, or at the end of a comment, this
1307 whitespace between them), this command moves by sentences instead of 1350 command moves by sentences instead of statements.
1308 statements. 1351
1309 1352 When called from a program, this function takes three optional
1310 When called from a program, this function takes two optional arguments: 1353 arguments: the numeric prefix argument, a buffer position limit (don't
1311 the numeric prefix argument, and a buffer position limit (don't move 1354 move back before that place), and a flag to indicate whether movement
1312 past that place). 1355 should be by statements (if @code{t}) or sentence (if non-@code{nil}).
1313 1356
1314 @item M-x c-forward-into-nomenclature 1357 @item M-x c-forward-into-nomenclature
1315 @findex c-forward-into-nomenclature 1358 @findex c-forward-into-nomenclature
1316 @findex forward-into-nomenclature (c-) 1359 @findex forward-into-nomenclature (c-)
1317 A popular programming style, especially for object-oriented languages 1360 A popular programming style, especially for object-oriented languages
1318 such as C++ is to write symbols in a mixed case format, where the first 1361 such as C++ is to write symbols in a mixed case format, where the first
1319 letter of each word is capitalized, and not separated by underscores. 1362 letter of each word is capitalized, and not separated by underscores.
1320 E.g. @samp{SymbolsWithMixedCaseAndNoUnderlines}. 1363 E.g. @samp{SymbolsWithMixedCaseAndNoUnderlines}.
1321 1364
1322 This command moves Point forward to end of a C++ nomenclature 1365 This command moves point forward to end of a C++ nomenclature
1323 section or word. With prefix argument @var{n}, move @var{n} times. 1366 section or word. With prefix argument @var{n}, move @var{n} times.
1324 1367
1325 @item M-x c-backward-into-nomenclature 1368 @item M-x c-backward-into-nomenclature
1326 @findex c-backward-into-nomenclature 1369 @findex c-backward-into-nomenclature
1327 @findex backward-into-nomenclature (c-) 1370 @findex backward-into-nomenclature (c-)
1328 Move Point backward to beginning of a C++ nomenclature 1371 Move point backward to beginning of a C++ nomenclature
1329 section or word. With prefix argument @var{n}, move @var{n} times. If 1372 section or word. With prefix argument @var{n}, move @var{n} times. If
1330 @var{n} is negative, move forward. 1373 @var{n} is negative, move forward.
1331 1374
1332 @kindex C-c : 1375 @kindex C-c :
1333 @findex c-scope-operator 1376 @findex c-scope-operator
1335 @item C-c : (c-scope-operator) 1378 @item C-c : (c-scope-operator)
1336 In C++, it is also sometimes desirable to insert the double-colon scope 1379 In C++, it is also sometimes desirable to insert the double-colon scope
1337 operator without performing the electric behavior of colon insertion. 1380 operator without performing the electric behavior of colon insertion.
1338 @kbd{C-c :} does just this. 1381 @kbd{C-c :} does just this.
1339 1382
1383 @item M-q (fill-paragraph)
1384 @kindex ESC q
1385 @findex fill-paragraph
1386 @vindex c-hanging-comment-starter-p
1387 @vindex c-hanging-comment-ender-p
1388 @vindex hanging-comment-starter-p (c-)
1389 @vindex hanging-comment-ender-p (c-)
1390 The command is used to fill a block style (C) or line style (C++)
1391 comment, in much the same way that text in the various text modes can be
1392 filled. You should never attempt to fill non-comment code sections;
1393 you'll end up with garbage! Two variables control how C style block
1394 comments are filled, specifically how the comment start and end
1395 delimiters are handled.
1396
1397 The variable @code{c-hanging-comment-starter-p} controls whether comment
1398 start delimiters which appear on a line by themselves, end up on a line
1399 by themselves after the fill. When the value is @code{nil}, the comment
1400 starter will remain on its own line@footnote{It will not be placed on a
1401 separate line if it is not already on a separate line.}. Otherwise,
1402 text on the next line will be put on the same line as the comment
1403 starter. This is called @dfn{hanging} because the following text hangs
1404 on the line with the comment starter.
1405
1406 The variable @code{c-hanging-comment-ender-p} controls the analogous
1407 behavior for the block comment end delimiter. When the value is
1408 @code{nil}, the comment ender will remain on its own line after the
1409 file@footnote{The same caveat as above holds true.}. Otherwise, the
1410 comment end delimiter will be placed at the end of the previous line.
1411
1340 @end table 1412 @end table
1341 1413
1342 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 1414 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1343 @node Customizing Indentation, Syntactic Symbols, Commands, Top 1415 @node Customizing Indentation, Syntactic Symbols, Commands, Top
1344 @comment node-name, next, previous,up 1416 @comment node-name, next, previous,up
1345 1417
1346 @chapter Customizing Indentation 1418 @chapter Customizing Indentation
1347 @cindex Customizing Indentation 1419 @cindex Customizing Indentation
1348 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 1420 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1349 1421
1422 @vindex c-offsets-alist
1423 @vindex offsets-alist (c-)
1350 @cindex c-set-offset 1424 @cindex c-set-offset
1351 @cindex set-offset (c-) 1425 @cindex set-offset (c-)
1426 The variable @code{c-offsets-alist} contains the mappings between
1427 syntactic symbols and the offsets to apply for those symbols. You
1428 should never modify this variable directly though. Use the function
1429 @code{c-set-offset} instead (see below for details).
1430
1352 The @code{c-offsets-alist} variable is where you customize all your 1431 The @code{c-offsets-alist} variable is where you customize all your
1353 indentations. You simply need to decide what additional offset you want 1432 indentations. You simply need to decide what additional offset you want
1354 to add for every syntactic symbol. You can use the command @kbd{C-c 1433 to add for every syntactic symbol. You can use the command @kbd{C-c
1355 C-o} (@code{c-set-offset}) as the way to set offsets, both interactively 1434 C-o} (@code{c-set-offset}) as the way to set offsets, both interactively
1356 and from your mode hook. Also, you can set up @emph{styles} of 1435 and from your mode hook. Also, you can set up @emph{styles} of
1361 1440
1362 @cindex c-basic-offset 1441 @cindex c-basic-offset
1363 @cindex basic-offset (c-) 1442 @cindex basic-offset (c-)
1364 As mentioned previously, the variable @code{c-offsets-alist} is an 1443 As mentioned previously, the variable @code{c-offsets-alist} is an
1365 association list of syntactic symbols and the offsets to be applied for 1444 association list of syntactic symbols and the offsets to be applied for
1366 those symbols. In fact, these offset values can be any of an integer, 1445 those symbols. In fact, these offset values can be any of an integer, a
1367 a function or variable name, or one of the following symbols: @code{+}, 1446 function or lambda expression, a variable name, or one of the following
1368 @code{-}, @code{++}, @code{--}, @code{*}, or @code{/}. These symbols 1447 symbols: @code{+}, @code{-}, @code{++}, @code{--}, @code{*}, or
1369 describe offset in multiples of the value of the variable 1448 @code{/}. These symbols describe offset in multiples of the value of
1370 @code{c-basic-offset}. By defining a style's indentation in terms of 1449 the variable @code{c-basic-offset}. By defining a style's indentation
1371 this fundamental variable, you can change the amount of whitespace given 1450 in terms of this fundamental variable, you can change the amount of
1372 to an indentation level while leaving the same relationship between 1451 whitespace given to an indentation level while leaving the same
1373 levels. Here are the values that the special 1452 relationship between levels. Here are the values that the special
1374 symbols correspond to: 1453 symbols correspond to:
1375 1454
1376 @table @code 1455 @table @code
1377 1456
1378 @item + 1457 @item +
1388 @item / 1467 @item /
1389 @code{c-basic-offset} times -0.5 1468 @code{c-basic-offset} times -0.5
1390 1469
1391 @end table 1470 @end table
1392 1471
1472 @vindex c-style-variables-are-local-p
1473 @vindex style-variables-are-local-p (c-)
1393 @noindent 1474 @noindent
1394 So, for example, because most of the default offsets are defined in 1475 So, for example, because most of the default offsets are defined in
1395 terms of @code{+}, @code{-}, and @code{0}, if you like the general 1476 terms of @code{+}, @code{-}, and @code{0}, if you like the general
1396 indentation style, but you use 4 spaces instead of 2 spaces per level, 1477 indentation style, but you use 4 spaces instead of 2 spaces per level,
1397 you can probably achieve your style just by changing 1478 you can probably achieve your style just by changing
1398 @code{c-basic-offset} like so (in your @file{.emacs} file)@footnote{The 1479 @code{c-basic-offset} like so (in your @file{.emacs} file)@footnote{The
1399 reason you need to use @code{setq-default} instead of @code{setq} is 1480 reason you need to use @code{setq-default} instead of @code{setq} is
1400 that @code{c-basic-offset} is a buffer local variable, as are most of 1481 that @code{c-basic-offset} is a buffer local variable, as are most
1401 the @code{cc-mode} configuration variables. If you were to put this 1482 configuration variables. If you were to put this code in, e.g. your
1402 code in, e.g. your @code{c-mode-common-hook} function, you could use 1483 @code{c-mode-common-hook} function, you could use @code{setq}.
1403 @code{setq}.}: 1484 Alternatively, you can keep these variables global by setting
1485 @code{c-style-variables-are-local-p} to @code{nil}, but you must do this
1486 before @code{cc-mode.el} is loaded into your Emacs session.}:
1404 @example 1487 @example
1405 1488
1406 (setq-default c-basic-offset 4) 1489 (setq-default c-basic-offset 4)
1407 1490
1408 @end example 1491 @end example
1519 (@code{c-set-offset}). This prompts you for the syntactic symbol to 1602 (@code{c-set-offset}). This prompts you for the syntactic symbol to
1520 change, providing a reasonable default. In this case, the default is 1603 change, providing a reasonable default. In this case, the default is
1521 @code{substatement-open}, which is just the syntactic symbol we want to 1604 @code{substatement-open}, which is just the syntactic symbol we want to
1522 change! 1605 change!
1523 1606
1524 After you hit return, @code{cc-mode} will then prompt you for the new 1607 After you hit return, @ccmode{} will then prompt you for the new
1525 offset value, with the old value as the default. The default in this 1608 offset value, with the old value as the default. The default in this
1526 case is @samp{+}, but we want no extra indentation so enter 1609 case is @samp{+}, but we want no extra indentation so enter
1527 @samp{0} and @kbd{RET}. This will associate the offset 0 with the 1610 @samp{0} and @kbd{RET}. This will associate the offset 0 with the
1528 syntactic symbol @code{substatement-open} in the @code{c-offsets-alist} 1611 syntactic symbol @code{substatement-open} in the @code{c-offsets-alist}
1529 variable. 1612 variable.
1559 1642
1560 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 1643 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1561 @node Permanent Customization, Styles, Interactive Customization, Customizing Indentation 1644 @node Permanent Customization, Styles, Interactive Customization, Customizing Indentation
1562 @comment node-name, next, previous,up 1645 @comment node-name, next, previous,up
1563 1646
1564 @section Permanent Indentation 1647 @section Permanent Customization
1565 @cindex Permanent Indentation 1648 @cindex Permanent Customization
1566 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 1649 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1567 1650
1568 @vindex c-mode-common-hook 1651 @vindex c-mode-common-hook
1569 @vindex c-mode-hook 1652 @vindex c-mode-hook
1570 @vindex c++-mode-hook 1653 @vindex c++-mode-hook
1571 @vindex objc-mode-hook 1654 @vindex objc-mode-hook
1572 @vindex java-mode-hook 1655 @vindex java-mode-hook
1573 @cindex hooks 1656 @cindex hooks
1574 To make this change permanent, you need to add some lisp code to your 1657 To make this change permanent, you need to add some lisp code to your
1575 @file{.emacs} file. @code{cc-mode} provides several hooks that you can 1658 @file{.emacs} file. @ccmode{} provides several hooks that you can
1576 use to customize the mode according to your coding style. Each language 1659 use to customize the mode according to your coding style. Each language
1577 mode has its own hook, adhering to standard to Emacs major mode 1660 mode has its own hook, adhering to standard Emacs major mode
1578 conventions. There is also one general hook: 1661 conventions. There is also one general hook:
1579 1662
1580 @itemize @bullet 1663 @itemize @bullet
1581 1664
1582 @item 1665 @item
1604 @code{java-mode-hook}. You need to be aware of this so any style 1687 @code{java-mode-hook}. You need to be aware of this so any style
1605 settings in @code{c-mode-common-hook} doesn't clobber your Java style.}. 1688 settings in @code{c-mode-common-hook} doesn't clobber your Java style.}.
1606 1689
1607 Here's a simplified example of what you can add to your @file{.emacs} 1690 Here's a simplified example of what you can add to your @file{.emacs}
1608 file to make the changes described in the previous section 1691 file to make the changes described in the previous section
1609 (@ref{Interactive Customization}) more permanent. See the Emacs 1692 (@ref{Interactive Customization}) more permanent. See the Emacs manuals
1610 manuals for more information on customizing Emacs via hooks. 1693 for more information on customizing Emacs via hooks. @xref{Sample
1611 @xref{Sample .emacs File} for a more complete sample @file{.emacs} file. 1694 .emacs File} for a more complete sample @file{.emacs} file.
1612 @footnote{The use of @code{add-hook} in this example only works for 1695 @footnote{The use of @code{add-hook} in this example only works for
1613 Emacs 19. Workarounds are available if you are using Emacs 18.} 1696 Emacs 19 and beyond. Workarounds are available if you are using Emacs
1697 18.}
1614 @example 1698 @example
1615 @group 1699 @group
1616 1700
1617 (defun my-c-mode-common-hook () 1701 (defun my-c-mode-common-hook ()
1618 ;; my customizations for all of c-mode, c++-mode, objc-mode, java-mode 1702 ;; my customizations for all of c-mode, c++-mode, objc-mode, java-mode
1640 and consistent styles. For example, their organization might impose a 1724 and consistent styles. For example, their organization might impose a
1641 ``blessed'' style that all its programmers must conform to. Similarly, 1725 ``blessed'' style that all its programmers must conform to. Similarly,
1642 people who work on GNU software will have to use the GNU coding style on 1726 people who work on GNU software will have to use the GNU coding style on
1643 C code. Some shops are more lenient, allowing some variety of coding 1727 C code. Some shops are more lenient, allowing some variety of coding
1644 styles, and as programmers come and go, there could be a number of 1728 styles, and as programmers come and go, there could be a number of
1645 styles in use. For this reason, @code{cc-mode} makes it convenient for 1729 styles in use. For this reason, @ccmode{} makes it convenient for
1646 you to set up logical groupings of customizations called @dfn{styles}, 1730 you to set up logical groupings of customizations called @dfn{styles},
1647 associate a single name for any particular style, and pretty easily 1731 associate a single name for any particular style, and pretty easily
1648 start editing new or existing code using these styles. This section 1732 start editing new or existing code using these styles. This section
1649 describes how to set up styles and how to edit your C code using styles. 1733 describes how to set up styles and how to edit your C code using styles.
1650 1734
1661 1745
1662 @subsection Built-in Styles 1746 @subsection Built-in Styles
1663 @cindex Built-in Styles 1747 @cindex Built-in Styles
1664 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 1748 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1665 1749
1666 If you're lucky, one of @code{cc-mode}'s built-in styles might be just 1750 If you're lucky, one of @ccmode{}'s built-in styles might be just
1667 what you're looking for. Some of the most common C and C++ styles are 1751 what you're looking for. These include:
1668 already built-in. These include:
1669 1752
1670 @itemize @bullet 1753 @itemize @bullet
1671 @item 1754 @item
1672 @cindex GNU style 1755 @cindex GNU style
1673 @code{gnu} --- coding style blessed by the Free Software Foundation 1756 @code{gnu} --- coding style blessed by the Free Software Foundation
1696 ``Programming in C++, Rules and Recommendations'', Erik Nyquist and Mats 1779 ``Programming in C++, Rules and Recommendations'', Erik Nyquist and Mats
1697 Henricson, Ellemtel @footnote{This document is ftp'able from 1780 Henricson, Ellemtel @footnote{This document is ftp'able from
1698 @code{euagate.eua.ericsson.se}}. 1781 @code{euagate.eua.ericsson.se}}.
1699 1782
1700 @item 1783 @item
1784 @cindex Linux style
1785 @code{linux} --- C coding standard for Linux development.
1786
1787 @item
1788 @cindex Python style
1789 @code{python} --- C coding standard for Python extension
1790 modules@footnote{Python is a high level scripting language with a C/C++
1791 foreign function interface. For more information, see
1792 @code{<http://www.python.org/>}.}.
1793
1794 @item
1701 @cindex Java style 1795 @cindex Java style
1702 @cindex java-mode 1796 @cindex java-mode
1703 @code{java} --- The style for editing Java code. Note that this style is 1797 @code{java} --- The style for editing Java code. Note that this style is
1704 automatically installed when you enter @code{java-mode}. 1798 automatically installed when you enter @code{java-mode}.
1705 1799
1706 @end itemize 1800 @end itemize
1707 1801
1708 @findex c-set-style 1802 @findex c-set-style
1709 @findex set-style (c-) 1803 @findex set-style (c-)
1804 @kindex C-c .
1710 If you'd like to experiment with these built-in styles you can simply 1805 If you'd like to experiment with these built-in styles you can simply
1711 type the following in a @code{cc-mode} buffer: 1806 type the following in a @ccmode{} buffer:
1712 @example 1807 @example
1713 @group 1808 @group
1714 1809
1715 @kbd{M-x c-set-style RET @var{STYLE-NAME} RET} 1810 @kbd{C-c . @var{STYLE-NAME} RET}
1716 1811
1717 @end group 1812 @end group
1718 @end example 1813 @end example
1719 @noindent 1814 @noindent
1720 Note that all style names are case insensitive, even the ones you define. 1815 @kbd{C-c .} runs the command @code{c-set-style}. Note that all style
1816 names are case insensitive, even the ones you define.
1721 1817
1722 Setting a style in this way does @emph{not} automatically re-indent your 1818 Setting a style in this way does @emph{not} automatically re-indent your
1723 file. For commands that you can use to view the effect of your changes, 1819 file. For commands that you can use to view the effect of your changes,
1724 see @ref{Commands}. 1820 see @ref{Commands}.
1725 1821
1726 Once you find a built-in style you like, you can make the change 1822 Once you find a built-in style you like, you can make the change
1727 permanent by adding a call to your @file{.emacs} file. Let's say for 1823 permanent by adding some lisp to your @file{.emacs} file. Let's say for
1728 example that you want to use the @samp{ellemtel} style in all your 1824 example that you want to use the @samp{ellemtel} style in all your
1729 files. You would add this: 1825 files. You would add this:
1730 @example 1826 @example
1731 @group 1827 @group
1732 1828
1738 (add-hook 'c-mode-common-hook 'my-c-mode-common-hook) 1834 (add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
1739 1835
1740 @end group 1836 @end group
1741 @end example 1837 @end example
1742 1838
1839 @cindex cc-mode style
1743 There is one other special style you can use, called @samp{cc-mode} 1840 There is one other special style you can use, called @samp{cc-mode}
1744 style. This style is special because all other styles implicitly 1841 style. This style is special because all other styles implicitly
1745 inherit from it; in other words, whenever you set a style, 1842 inherit from it; in other words, whenever you set a style,
1746 @samp{cc-mode} is applied before the one you selected. This means 1843 @samp{cc-mode} is applied before the one you selected. This means
1747 your style need only define the differences between it and 1844 your style need only define the differences between it and
1748 @samp{cc-mode} style. 1845 @samp{cc-mode} style.
1749 1846
1847 Note @emph{you should never change any of the default styles}.
1848 Instead, it's better to add a new style using @code{c-add-style}
1849 (@xref{Adding Styles}). This is especially true for @code{cc-mode} and
1850 @code{java} styles.
1851
1852 @vindex c-indentation-style
1853 @vindex indentation-style (c-)
1750 Note that for BOCM compatibility, @samp{gnu} is the default 1854 Note that for BOCM compatibility, @samp{gnu} is the default
1751 style, and any non-style based customizations you make (i.e. in 1855 style, and any non-style based customizations you make (i.e. in
1752 @code{c-mode-common-hook} in your 1856 @code{c-mode-common-hook} in your
1753 @file{.emacs} file) will be based on @samp{gnu} style unless you do 1857 @file{.emacs} file) will be based on @samp{gnu} style unless you do
1754 a @code{c-set-style} as the first thing in your hook. 1858 a @code{c-set-style} as the first thing in your hook. The variable
1859 @code{c-indentation-style} always contains the buffer's current style name,
1860 as a string.
1755 1861
1756 1862
1757 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 1863 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1758 @node Adding Styles, File Styles, Built-in Styles, Styles 1864 @node Adding Styles, File Styles, Built-in Styles, Styles
1759 @comment node-name, next, previous,up 1865 @comment node-name, next, previous,up
1767 @findex c-add-style 1873 @findex c-add-style
1768 @findex add-style (c-) 1874 @findex add-style (c-)
1769 If none of the built-in styles is appropriate, you'll probably want to 1875 If none of the built-in styles is appropriate, you'll probably want to
1770 add a new @dfn{style definition}. Styles are kept in the 1876 add a new @dfn{style definition}. Styles are kept in the
1771 @code{c-style-alist} variable, but you should never modify this variable 1877 @code{c-style-alist} variable, but you should never modify this variable
1772 directly. Instead, @code{cc-mode} provides the function 1878 directly. Instead, @ccmode{} provides the function
1773 @code{c-add-style} that you can use to easily add new styles or change 1879 @code{c-add-style} that you can use to easily add new styles or change
1774 existing styles. This function takes two arguments, a @var{stylename} 1880 existing styles. This function takes two arguments, a @var{stylename}
1775 string, and an association list @var{description} of style 1881 string, and an association list @var{description} of style
1776 customizations. If @var{stylename} is not already in 1882 customizations. If @var{stylename} is not already in
1777 @code{c-style-alist}, the new style is added, otherwise the style is 1883 @code{c-style-alist}, the new style is added, otherwise the style is
1793 1899
1794 @cindex local variables 1900 @cindex local variables
1795 The Emacs manual describes how you can customize certain variables on a 1901 The Emacs manual describes how you can customize certain variables on a
1796 per-file basis by including a @dfn{Local Variable} block at the end of 1902 per-file basis by including a @dfn{Local Variable} block at the end of
1797 the file. So far, you've only seen a functional interface to 1903 the file. So far, you've only seen a functional interface to
1798 @code{cc-mode}, which is highly inconvenient for use in a Local Variable 1904 @ccmode{}, which is highly inconvenient for use in a Local Variable
1799 block. @code{cc-mode} provides two variables that make it easier for 1905 block. @ccmode{} provides two variables that make it easier for
1800 you to customize your style on a per-file basis. 1906 you to customize your style on a per-file basis.
1801 1907
1802 @vindex c-file-style 1908 @vindex c-file-style
1803 @vindex file-style (c-) 1909 @vindex file-style (c-)
1804 @vindex c-file-offsets 1910 @vindex c-file-offsets
1805 @vindex file-offsets (c-) 1911 @vindex file-offsets (c-)
1806 1912
1807 The variable @code{c-file-style} can be set to a style name string. 1913 The variable @code{c-file-style} can be set to a style name string.
1808 When the file is visited, @code{cc-mode} will automatically set the 1914 When the file is visited, @ccmode{} will automatically set the
1809 file's style to this style using @code{c-set-style}. 1915 file's style to this style using @code{c-set-style}.
1810 1916
1811 @vindex c-offsets-alist 1917 @vindex c-offsets-alist
1812 @vindex offsets-alist (c-) 1918 @vindex offsets-alist (c-)
1813 @findex c-set-offset 1919 @findex c-set-offset
1814 @findex set-offset (c-) 1920 @findex set-offset (c-)
1815 Another variable, @code{c-file-offsets}, takes an association list 1921 Another variable, @code{c-file-offsets}, takes an association list
1816 similar to what is allowed in @code{c-offsets-alist}. When the file is 1922 similar to what is allowed in @code{c-offsets-alist}. When the file is
1817 visited, @code{cc-mode} will automatically institute these offets using 1923 visited, @ccmode{} will automatically institute these offets using
1818 @code{c-set-offset}. 1924 @code{c-set-offset}.
1819 1925
1820 Note that file style settings (i.e. @code{c-file-style}) are applied 1926 Note that file style settings (i.e. @code{c-file-style}) are applied
1821 before file offset settings (i.e. @code{c-file-offsets})@footnote{File 1927 before file offset settings (i.e. @code{c-file-offsets})@footnote{File
1822 styles are only supported since XEmacs 19.12 and Emacs 19.29. They work 1928 styles have only been supported since XEmacs 19.12 and Emacs 19.29.
1823 via the standard Emacs hook variable @code{hack-local-variables-hook}.}. 1929 They work via the standard Emacs hook variable
1930 @code{hack-local-variables-hook}. Older Emacsen lack this hook, so file
1931 styles can't be used with them.}.
1824 1932
1825 1933
1826 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 1934 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1827 @node Advanced Customizations, , Styles, Customizing Indentation 1935 @node Advanced Customizations, , Styles, Customizing Indentation
1828 @comment node-name, next, previous,up 1936 @comment node-name, next, previous,up
1833 1941
1834 @vindex c-style-alist 1942 @vindex c-style-alist
1835 @vindex style-alist (c-) 1943 @vindex style-alist (c-)
1836 @vindex c-basic-offset 1944 @vindex c-basic-offset
1837 @vindex basic-offset (c-) 1945 @vindex basic-offset (c-)
1838 For most users, @code{cc-mode} will support their coding styles with 1946 For most users, @ccmode{} will support their coding styles with
1839 very little need for more advanced customizations. Usually, one of the 1947 very little need for more advanced customizations. Usually, one of the
1840 standard styles defined in @code{c-style-alist} will do the trick. At 1948 standard styles defined in @code{c-style-alist} will do the trick. At
1841 most, perhaps one of the syntactic symbol offsets will need to be 1949 most, perhaps one of the syntactic symbol offsets will need to be
1842 tweaked slightly, or maybe @code{c-basic-offset} will need to be 1950 tweaked slightly, or maybe @code{c-basic-offset} will need to be
1843 changed. However, some styles require a more flexible framework for 1951 changed. However, some styles require a more flexible framework for
1844 customization, and one of the real strengths of @code{cc-mode} is that 1952 customization, and one of the real strengths of @ccmode{} is that
1845 the syntactic analysis model provides just such a framework. This allows 1953 the syntactic analysis model provides just such a framework. This allows
1846 you to implement special indentation calculations for situations not 1954 you to implement custom indentation calculations for situations not
1847 handled by the mode directly. 1955 handled by the mode directly.
1956
1957 @vindex c-style-variables-are-local-p
1958 @vindex style-variables-are-local-p
1959 Note that the style controlling variables can either have global values,
1960 or can be buffer local (e.g. different in every buffer). If all the C
1961 files you edit tend to have the same style, you might want to keep the
1962 variables global. If you tend to edit files with many different styles,
1963 you will have to make the variables buffer local. The variable
1964 @code{c-style-variables-are-local-p} controls this.
1965
1966 When @code{c-style-variables-are-local-p} is non-nil, then the style
1967 variables will have a different settable value for each buffer,
1968 otherwise all buffers will share the same values. This variable only
1969 takes effect when @ccmode{} is loaded into your Emacs session. By
1970 default (for backwards compatibility reasons), its value is @code{t}.
1971 Note that once the variables are made buffer local, they will retain
1972 this property for the remainder of the current Emacs session. To change
1973 this behavior, set @code{c-style-variables-are-local-p} to @code{nil}
1974 @emph{before} you load @file{cc-mode.el}.
1848 1975
1849 @menu 1976 @menu
1850 * Custom Indentation Functions:: 1977 * Custom Indentation Functions::
1851 * Custom Brace and Colon Hanging:: 1978 * Custom Brace and Colon Hanging::
1852 * Customizing Semi-colons and Commas:: 1979 * Customizing Semi-colons and Commas::
1860 @subsection Custom Indentation Functions 1987 @subsection Custom Indentation Functions
1861 @cindex Custom Indentation Functions 1988 @cindex Custom Indentation Functions
1862 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 1989 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1863 1990
1864 @cindex custom indentation functions 1991 @cindex custom indentation functions
1865 One of the most common ways to customize @code{cc-mode} is by writing 1992 The most flexible way to customize @ccmode{} is by writing @dfn{custom
1866 @dfn{custom indentation functions} and associating them with specific 1993 indentation functions} and associating them with specific syntactic
1867 syntactic symbols (see @ref{Syntactic Symbols}). @code{cc-mode} itself 1994 symbols (see @ref{Syntactic Symbols}). @ccmode{} itself uses custom
1868 uses custom indentation functions to provide more sophisticated 1995 indentation functions to provide more sophisticated indentation, for
1869 indentation, for example when lining up C++ stream operator blocks: 1996 example when lining up C++ stream operator blocks:
1870 @example 1997 @example
1871 @group 1998 @group
1872 1999
1873 1: void main(int argc, char**) 2000 1: void main(int argc, char**)
1874 2: @{ 2001 2: @{
1883 2010
1884 In this example, lines 4 through 6 are assigned the @code{stream-op} 2011 In this example, lines 4 through 6 are assigned the @code{stream-op}
1885 syntactic symbol. Here, @code{stream-op} has an offset of @code{+}, and 2012 syntactic symbol. Here, @code{stream-op} has an offset of @code{+}, and
1886 with a @code{c-basic-offset} of 2, you can see that lines 4 through 6 2013 with a @code{c-basic-offset} of 2, you can see that lines 4 through 6
1887 are simply indented two spaces to the right of line 3. But perhaps we'd 2014 are simply indented two spaces to the right of line 3. But perhaps we'd
1888 like @code{cc-mode} to be a little more intelligent so that it lines up 2015 like @ccmode{} to be a little more intelligent so that it lines up
1889 all the @samp{<<} symbols in lines 3 through 6. To do this, we have 2016 all the @samp{<<} symbols in lines 3 through 6. To do this, we have
1890 to write a custom indentation function which finds the column of first 2017 to write a custom indentation function which finds the column of first
1891 stream operator on the first line of the statement. Here is the lisp 2018 stream operator on the first line of the statement. Here is the lisp
1892 code (from the @file{cc-mode.el} source file) that implements this: 2019 code (from the @file{cc-mode.el} source file) that implements this:
1893 @example 2020 @example
1910 component cons cell (see @ref{Syntactic Analysis}). The 2037 component cons cell (see @ref{Syntactic Analysis}). The
1911 function returns an integer offset value that will be added to the 2038 function returns an integer offset value that will be added to the
1912 running total indentation for the line. Note that what actually gets 2039 running total indentation for the line. Note that what actually gets
1913 returned is the difference between the column that the first stream 2040 returned is the difference between the column that the first stream
1914 operator is on, and the column of the buffer relative position passed in 2041 operator is on, and the column of the buffer relative position passed in
1915 the function's argument. Remember that @code{cc-mode} automatically 2042 the function's argument. Remember that @ccmode{} automatically
1916 adds in the column of the component's relative buffer position and we 2043 adds in the column of the component's relative buffer position and we
1917 don't want that value added into the final total twice. 2044 don't want that value added into the final total twice.
1918 2045
1919 @cindex stream-op syntactic symbol 2046 @cindex stream-op syntactic symbol
1920 @findex c-lineup-streamop 2047 @findex c-lineup-streamop
1949 2076
1950 @vindex c-offsets-alist 2077 @vindex c-offsets-alist
1951 @vindex offsets-alist (c-) 2078 @vindex offsets-alist (c-)
1952 Custom indentation functions can be as simple or as complex as you like, 2079 Custom indentation functions can be as simple or as complex as you like,
1953 and any syntactic symbol that appears in @code{c-offsets-alist} can have 2080 and any syntactic symbol that appears in @code{c-offsets-alist} can have
1954 a custom indentation function associated with it. @code{cc-mode} comes 2081 a custom indentation function associated with it. @ccmode{} comes
1955 with several standard custom indentation functions, not all of which are 2082 with several standard custom indentation functions, not all of which are
1956 used by the default styles. 2083 used by the default styles.
1957 2084
1958 @itemize @bullet 2085 @itemize @bullet
1959 @item 2086 @item
2045 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 2172 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2046 2173
2047 @vindex c-hanging-braces-alist 2174 @vindex c-hanging-braces-alist
2048 @vindex hanging-braces-alist (c-) 2175 @vindex hanging-braces-alist (c-)
2049 Syntactic symbols aren't the only place where you can customize 2176 Syntactic symbols aren't the only place where you can customize
2050 @code{cc-mode} with the lisp equivalent of callback functions. Brace 2177 @ccmode{} with the lisp equivalent of callback functions. Brace
2051 ``hanginess'' can also be determined by custom functions associated with 2178 ``hanginess'' can also be determined by custom functions associated with
2052 syntactic symbols on the @code{c-hanging-braces-alist} variable. 2179 syntactic symbols on the @code{c-hanging-braces-alist} variable.
2053 Remember that @var{ACTION}'s are typically a list containing some 2180 Remember that @var{ACTION}'s are typically a list containing some
2054 combination of the symbols @code{before} and @code{after} (see 2181 combination of the symbols @code{before} and @code{after} (see
2055 @ref{Hanging Braces}). However, an @var{ACTION} can also be a function 2182 @ref{Hanging Braces}). However, an @var{ACTION} can also be a function
2062 brace was inserted. The @var{ACTION} function is expected to return a 2189 brace was inserted. The @var{ACTION} function is expected to return a
2063 list containing some combination of @code{before} and @code{after}. The 2190 list containing some combination of @code{before} and @code{after}. The
2064 function can also return @code{nil}. This return value has the normal 2191 function can also return @code{nil}. This return value has the normal
2065 brace hanging semantics. 2192 brace hanging semantics.
2066 2193
2067 As an example, @code{cc-mode} itself uses this feature to dynamically 2194 As an example, @ccmode{} itself uses this feature to dynamically
2068 determine the hanginess of braces which close ``do-while'' 2195 determine the hanginess of braces which close ``do-while''
2069 constructs: 2196 constructs:
2070 @example 2197 @example
2071 @group 2198 @group
2072 2199
2082 @end group 2209 @end group
2083 @end example 2210 @end example
2084 2211
2085 @findex c-snug-do-while 2212 @findex c-snug-do-while
2086 @findex snug-do-while (c-) 2213 @findex snug-do-while (c-)
2087 @code{cc-mode} assigns the @code{block-close} syntactic symbol to the 2214 @ccmode{} assigns the @code{block-close} syntactic symbol to the
2088 brace that closes the @code{do} construct, and normally we'd like the 2215 brace that closes the @code{do} construct, and normally we'd like the
2089 line that follows a @code{block-close} brace to begin on a separate 2216 line that follows a @code{block-close} brace to begin on a separate
2090 line. However, with ``do-while'' constructs, we want the 2217 line. However, with ``do-while'' constructs, we want the
2091 @code{while} clause to follow the closing brace. To do this, we 2218 @code{while} clause to follow the closing brace. To do this, we
2092 associate the @code{block-close} symbol with the @var{ACTION} function 2219 associate the @code{block-close} symbol with the @var{ACTION} function
2128 @vindex c-hanging-colon-alist 2255 @vindex c-hanging-colon-alist
2129 @vindex hanging-colon-alist (c-) 2256 @vindex hanging-colon-alist (c-)
2130 Note that for symmetry, colon hanginess should be customizable by 2257 Note that for symmetry, colon hanginess should be customizable by
2131 allowing function symbols as @var{ACTION}s on the 2258 allowing function symbols as @var{ACTION}s on the
2132 @code{c-hanging-colon-alist} variable. Since no use has actually been 2259 @code{c-hanging-colon-alist} variable. Since no use has actually been
2133 found for this feature, it isn't currently implemented. 2260 found for this feature, it isn't currently implemented!
2134 2261
2135 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 2262 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2136 @node Customizing Semi-colons and Commas, Other Special Indentations, Custom Brace and Colon Hanging, Advanced Customizations 2263 @node Customizing Semi-colons and Commas, Other Special Indentations, Custom Brace and Colon Hanging, Advanced Customizations
2137 @comment node-name, next, previous,up 2264 @comment node-name, next, previous,up
2138 2265
2171 semi-colons which do not appear inside parenthesis lists (i.e. those 2298 semi-colons which do not appear inside parenthesis lists (i.e. those
2172 that separate @code{for}-clause statements). 2299 that separate @code{for}-clause statements).
2173 2300
2174 Here's an example of a criteria function that will prevent newlines from 2301 Here's an example of a criteria function that will prevent newlines from
2175 being inserted after semicolons when there is a non-blank following 2302 being inserted after semicolons when there is a non-blank following
2176 line. Otherwise, it makes no determination: 2303 line. Otherwise, it makes no determination. To use, add this to the
2304 front of the @code{c-hanging-semi&comma-criteria} list.
2177 2305
2178 @example 2306 @example
2179 @group 2307 @group
2180 2308
2181 (defun my-semicolon-criteria () 2309 (defun my-semicolon-criteria ()
2199 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 2327 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2200 2328
2201 @vindex c-label-minimum-indentation 2329 @vindex c-label-minimum-indentation
2202 @vindex label-minimum-indentation (c-) 2330 @vindex label-minimum-indentation (c-)
2203 In @samp{gnu} style (see @ref{Built-in Styles}), a minimum indentation 2331 In @samp{gnu} style (see @ref{Built-in Styles}), a minimum indentation
2204 is imposed on lines with @code{label} or @code{case-label} syntax. This 2332 is imposed on lines inside top-level constructs. This minimum
2205 minimum indentation is controlled by the variable 2333 indentation is controlled by the variable
2206 @code{c-label-minimum-indentation}. The default value for this variable 2334 @code{c-label-minimum-indentation}. The default value for this variable
2207 is 1. 2335 is 1.
2208 2336
2209 @vindex c-special-indent-hook 2337 @vindex c-special-indent-hook
2210 @vindex special-indent-hook (c-) 2338 @vindex special-indent-hook (c-)
2211 One other customization variable is available in @code{cc-mode}: 2339 One other customization variable is available in @ccmode{}:
2212 @code{c-special-indent-hook}. This is a standard hook variable that is 2340 @code{c-special-indent-hook}. This is a standard hook variable that is
2213 called after every line is indented by @code{cc-mode}. You can use it 2341 called after every line is indented by @ccmode{}. You can use it
2214 to do any special indentation or line adjustments your style dictates, 2342 to do any special indentation or line adjustments your style dictates,
2215 such as adding extra indentation to constructors or destructor 2343 such as adding extra indentation to constructors or destructor
2216 declarations in a class definition, etc. Note however, that you should 2344 declarations in a class definition, etc. Note however, that you should
2217 not change Point or Mark inside your @code{c-special-indent-hook} 2345 not change point or mark inside your @code{c-special-indent-hook}
2218 functions (i.e. you'll probably want to wrap your function in a 2346 functions (i.e. you'll probably want to wrap your function in a
2219 @code{save-excursion}). 2347 @code{save-excursion}).
2220 2348
2221 Setting @code{c-special-indent-hook} in your style definition is handled 2349 Setting @code{c-special-indent-hook} in your style definition is handled
2222 slightly differently than other variables. In your style definition, 2350 slightly differently than other variables. In your style definition,
2260 @item 2388 @item
2261 @code{inline-open} --- brace that opens an in-class inline method 2389 @code{inline-open} --- brace that opens an in-class inline method
2262 @item 2390 @item
2263 @code{inline-close} --- brace that closes an in-class inline method 2391 @code{inline-close} --- brace that closes an in-class inline method
2264 @item 2392 @item
2265 @code{ansi-funcdecl-cont} --- the nether region between an ANSI function 2393 @code{func-decl-cont} --- the nether region between a function
2266 declaration and the defun opening brace 2394 declaration's argument list and the defun opening brace. In C++ and
2395 Java, this can include the @code{throws} clauses of a method
2396 declaration.
2267 @item 2397 @item
2268 @code{knr-argdecl-intro} --- first line of a K&R C argument declaration 2398 @code{knr-argdecl-intro} --- first line of a K&R C argument declaration
2269 @item 2399 @item
2270 @code{knr-argdecl} --- subsequent lines in a K&R C argument declaration 2400 @code{knr-argdecl} --- subsequent lines in a K&R C argument declaration
2271 @item 2401 @item
2272 @code{topmost-intro} --- the first line in a topmost construct definition 2402 @code{topmost-intro} --- the first line in a topmost definition
2273 @item 2403 @item
2274 @code{topmost-intro-cont} --- topmost definition continuation lines 2404 @code{topmost-intro-cont} --- topmost definition continuation lines
2275 @item 2405 @item
2276 @code{member-init-intro} --- first line in a member initialization list 2406 @code{member-init-intro} --- first line in a member initialization list
2277 @item 2407 @item
2291 @item 2421 @item
2292 @code{brace-list-intro} --- first line in an enum or static array list 2422 @code{brace-list-intro} --- first line in an enum or static array list
2293 @item 2423 @item
2294 @code{brace-list-entry} --- subsequent lines in an enum or static array list 2424 @code{brace-list-entry} --- subsequent lines in an enum or static array list
2295 @item 2425 @item
2296 @code{statement} --- a C (or like) statement 2426 @code{statement} --- a C statement
2297 @item 2427 @item
2298 @code{statement-cont} --- a continuation of a C (or like) statement 2428 @code{statement-cont} --- a continuation of a C statement
2299 @item 2429 @item
2300 @code{statement-block-intro} --- the first line in a new statement block 2430 @code{statement-block-intro} --- the first line in a new statement block
2301 @item 2431 @item
2302 @code{statement-case-intro} --- the first line in a case `block' 2432 @code{statement-case-intro} --- the first line in a case `block'
2303 @item 2433 @item
2304 @code{statement-case-open} --- the first line in a case block starting 2434 @code{statement-case-open} --- the first line in a case block starting
2305 with brace 2435 with brace
2306 @item 2436 @item
2307 @code{substatement} --- the first line after an if/while/for/do/else 2437 @code{substatement} --- the first line after a conditional
2308 @item 2438 @item
2309 @code{substatement-open} --- the brace that opens a substatement block 2439 @code{substatement-open} --- the brace that opens a substatement block
2310 @item 2440 @item
2311 @code{case-label} --- a case or default label 2441 @code{case-label} --- a case or default label
2312 @item 2442 @item
2313 @code{access-label} --- C++ private/protected/public access label 2443 @code{access-label} --- C++ access control label
2314 @item 2444 @item
2315 @code{label} --- any non-special C (or like) label 2445 @code{label} --- any non-special C label
2316 @item 2446 @item
2317 @code{do-while-closure} --- the `while' that ends a do/while construct 2447 @code{do-while-closure} --- the `while' that ends a
2318 @item 2448 @code{do}-@code{while} construct
2319 @code{else-clause} --- the `else' of an if/else construct 2449 @item
2450 @code{else-clause} --- the `else' of an @code{if}-@code{else} construct
2320 @item 2451 @item
2321 @code{comment-intro} --- a line containing only a comment introduction 2452 @code{comment-intro} --- a line containing only a comment introduction
2322 @item 2453 @item
2323 @code{arglist-intro} --- the first line in an argument list 2454 @code{arglist-intro} --- the first line in an argument list
2324 @item 2455 @item
2328 @code{arglist-cont-nonempty} --- subsequent argument list lines when at 2459 @code{arglist-cont-nonempty} --- subsequent argument list lines when at
2329 least one argument follows on the same line as the arglist opening paren 2460 least one argument follows on the same line as the arglist opening paren
2330 @item 2461 @item
2331 @code{arglist-close} --- the solo close paren of an argument list 2462 @code{arglist-close} --- the solo close paren of an argument list
2332 @item 2463 @item
2333 @code{stream-op} --- lines continuing a stream operator construct 2464 @code{stream-op} --- lines continuing a stream operator
2334 @item 2465 @item
2335 @code{inclass} --- the construct is nested inside a class definition 2466 @code{inclass} --- the line is nested inside a class definition
2336 @item 2467 @item
2337 @code{cpp-macro} --- the start of a cpp macro 2468 @code{cpp-macro} --- the start of a cpp macro
2338 @item 2469 @item
2339 @code{friend} --- a C++ friend declaration 2470 @code{friend} --- a C++ friend declaration
2340 @item 2471 @item
2347 @item 2478 @item
2348 @code{extern-lang-open} --- brace that opens an external language block 2479 @code{extern-lang-open} --- brace that opens an external language block
2349 @item 2480 @item
2350 @code{extern-lang-close} --- brace that closes an external language block 2481 @code{extern-lang-close} --- brace that closes an external language block
2351 @item 2482 @item
2352 @code{inextern-lang} --- analogous to `inclass' syntactic symbol 2483 @code{inextern-lang} --- analogous to `inclass' syntactic symbol, but
2484 for @code{extern} blocks.
2353 @end itemize 2485 @end itemize
2354 2486
2355 @cindex -open syntactic symbols 2487 @cindex -open syntactic symbols
2356 @cindex -close syntactic symbols 2488 @cindex -close syntactic symbols
2357 Most syntactic symbol names follow a general naming convention. When a 2489 Most syntactic symbol names follow a general naming convention. When a
2748 are assigned @code{arglist-cont-nonempty} syntax. What this means 2880 are assigned @code{arglist-cont-nonempty} syntax. What this means
2749 is that they continue an argument list, but that the line containing the 2881 is that they continue an argument list, but that the line containing the
2750 parenthesis that opens the list is @emph{not empty} following the open 2882 parenthesis that opens the list is @emph{not empty} following the open
2751 parenthesis. Contrast this against lines 6 and 13 which are assigned 2883 parenthesis. Contrast this against lines 6 and 13 which are assigned
2752 @code{arglist-cont} syntax. This is because the parenthesis that opens 2884 @code{arglist-cont} syntax. This is because the parenthesis that opens
2753 their argument lists is the last character on that line @footnote{The 2885 their argument lists is the last character on that line.
2754 need for this somewhat confusing arrangement is that the typical
2755 indentation desired for these lines is calculated differently.
2756 This should be simplified in version 5 of @code{cc-mode}, along with the
2757 added distinction between argument lists in function declarations, and
2758 argument lists in function calls.}.
2759 2886
2760 Note that there is no @code{arglist-open} syntax. This is because any 2887 Note that there is no @code{arglist-open} syntax. This is because any
2761 parenthesis that opens an argument list, appearing on a separate line, 2888 parenthesis that opens an argument list, appearing on a separate line,
2762 is assigned the @code{statement-cont} syntax instead. 2889 is assigned the @code{statement-cont} syntax instead.
2763 2890
2764 A few miscellaneous syntactic symbols that haven't been previously 2891 A few miscellaneous syntactic symbols that haven't been previously
2765 covered are illustrated by this example: 2892 covered are illustrated by this C++ example:
2766 @example 2893 @example
2767 @group 2894 @group
2768 2895
2769 1: void Bass::play( int volume ) 2896 1: void Bass::play( int volume )
2770 2: const 2897 2: const
2771 3: @{ 2898 3: @{
2772 4: /* this line starts a multi-line 2899 4: /* this line starts a multi-line
2773 5: * comment. This line should get `c' syntax */ 2900 5: * comment. This line should get `c' syntax */
2774 6: 2901 6:
2775 7: char* a_long_multiline_string = "This line starts a multi-line \ 2902 7: char* a_multiline_string = "This line starts a multi-line \
2776 8: string. This line should get `string' syntax."; 2903 8: string. This line should get `string' syntax.";
2777 9: 2904 9:
2778 10: note: 2905 10: note:
2779 11: @{ 2906 11: @{
2780 12: #ifdef LOCK 2907 12: #ifdef LOCK
2792 @cindex modifier syntactic symbol 2919 @cindex modifier syntactic symbol
2793 The lines to note in this example include: 2920 The lines to note in this example include:
2794 2921
2795 @itemize @bullet 2922 @itemize @bullet
2796 2923
2797 @cindex ansi-funcdecl-cont syntactic symbol 2924 @cindex func-decl-cont syntactic symbol
2798 @item 2925 @item
2799 line 2, assigned the @code{ansi-funcdecl-cont} syntax; 2926 line 2, assigned the @code{func-decl-cont} syntax;
2800 2927
2801 @cindex comment-intro syntactic symbol 2928 @cindex comment-intro syntactic symbol
2802 @item 2929 @item
2803 line 4, assigned both @code{defun-block-intro} @emph{and} 2930 line 4, assigned both @code{defun-block-intro} @emph{and}
2804 @code{comment-intro} syntax @footnote{The @code{comment-intro} syntactic 2931 @code{comment-intro} syntax;
2805 symbol is is another example of a @dfn{modifier} since it always appears
2806 on a syntactic analysis list with other symbols, and rarely has an
2807 associated relative buffer position.};
2808 2932
2809 @cindex c syntactic symbol 2933 @cindex c syntactic symbol
2810 @item 2934 @item
2811 line 5, assigned @code{c} syntax; 2935 line 5, assigned @code{c} syntax;
2812 2936
2835 @item 2959 @item
2836 lines 12 and 14, assigned @code{cpp-macro} syntax; 2960 lines 12 and 14, assigned @code{cpp-macro} syntax;
2837 2961
2838 @cindex stream-op syntactic symbol 2962 @cindex stream-op syntactic symbol
2839 @item 2963 @item
2840 line 17, assigned @code{stream-op} syntax @footnote{In C++ only.}. 2964 line 17, assigned @code{stream-op} syntax.
2841 2965
2842 @end itemize 2966 @end itemize
2843 2967
2844 In Objective-C buffers, there are three additional syntactic symbols 2968 In Objective-C buffers, there are three additional syntactic symbols
2845 assigned to various message calling constructs. Here's an example 2969 assigned to various message calling constructs. Here's an example
2895 @chapter Performance Issues 3019 @chapter Performance Issues
2896 @cindex Performance Issues 3020 @cindex Performance Issues
2897 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 3021 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2898 3022
2899 C and it's derivative languages are highly complex creatures. Often, 3023 C and it's derivative languages are highly complex creatures. Often,
2900 ambiguous code situations arise that require @code{cc-mode} to scan 3024 ambiguous code situations arise that require @ccmode{} to scan
2901 large portions of the buffer to determine syntactic context. Such 3025 large portions of the buffer to determine syntactic context. Such
2902 pathological code@footnote{such as the output of @code{lex(1)}!} 3026 pathological code@footnote{such as the output of @code{lex(1)}!}
2903 can cause @code{cc-mode} to perform fairly badly. 3027 can cause @ccmode{} to perform fairly badly.
2904 This section identifies some of the coding styles to watch out for, and 3028 This section identifies some of the coding styles to watch out for, and
2905 suggests some workarounds that you can use to improve performance. 3029 suggests some workarounds that you can use to improve performance.
2906 3030
2907 Note that this is an area that will get a lot of attention in 3031 Because @ccmode{} has to scan the buffer backwards from the current
2908 @code{cc-mode} version 5. The mode should end up being much faster, at
2909 the expense of dropping Emacs 18 support, owing to the implementation of
2910 syntactic analysis caching.
2911
2912 Because @code{cc-mode} has to scan the buffer backwards from the current
2913 insertion point, and because C's syntax is fairly difficult to parse in 3032 insertion point, and because C's syntax is fairly difficult to parse in
2914 the backwards direction, @code{cc-mode} often tries to find the nearest 3033 the backwards direction, @ccmode{} often tries to find the nearest
2915 position higher up in the buffer from which to begin a forward scan. 3034 position higher up in the buffer from which to begin a forward scan.
2916 The farther this position is from the current insertion point, the 3035 The farther this position is from the current insertion point, the
2917 slower the mode gets. Some coding styles can even force @code{cc-mode} 3036 slower the mode gets. Some coding styles can even force @ccmode{}
2918 to scan from the beginning of the buffer! 3037 to scan from the beginning of the buffer!
2919 3038
2920 @findex beginning-of-defun 3039 @findex beginning-of-defun
2921 @findex defun-prompt-regexp 3040 @findex defun-prompt-regexp
2922 One of the simplest things you can do to reduce scan time, is make sure 3041 One of the simplest things you can do to reduce scan time, is make sure
2923 any brace that opens a top-level block construct always appears in the 3042 any brace that opens a top-level block construct always appears in the
2924 leftmost column. This is actually an Emacs constraint, as embodied in 3043 leftmost column. This is actually an Emacs constraint, as embodied in
2925 the @code{beginning-of-defun} function which @code{cc-mode} uses 3044 the @code{beginning-of-defun} function which @ccmode{} uses
2926 heavily. If you insist on hanging top-level open braces on the right 3045 heavily. If you insist on hanging top-level open braces on the right
2927 side of the line, then you should set the variable 3046 side of the line, then you should set the variable
2928 @code{defun-prompt-regexp} to something reasonable @footnote{Note that 3047 @code{defun-prompt-regexp} to something reasonable @footnote{Note that
2929 this variable is only defined in Emacs 19.}, however that ``something 3048 this variable is only defined in Emacs 19.}, however that ``something
2930 reasonable'' is difficult to define, so @code{cc-mode} doesn't do it 3049 reasonable'' is difficult to define, so @ccmode{} doesn't do it
2931 for you. 3050 for you.
2932 3051
2933 You will probably notice pathological behavior from @code{cc-mode} when 3052 @vindex c-Java-defun-prompt-regexp
3053 @vindex Java-defun-prompt-regexp (c-)
3054 A special note about @code{defun-prompt-regexp} in Java mode: while much
3055 of the early sample Java code seems to encourage a style where the brace
3056 that opens a class is hung on the right side of the line, this is not a
3057 good style to pursue in Emacs. @ccmode{} comes with a variable
3058 @code{c-Java-defun-prompt-regexp} which tries to define a regular
3059 expression usable for this style, but there are problems with it. In
3060 some cases it can cause @code{beginning-of-defun} to hang@footnote{This
3061 has been observed in Emacs 19.34 and XEmacs 19.15.}. For this reason,
3062 it is not used by default, but if you feel adventurous, you can set
3063 @code{defun-prompt-regexp} to it in your mode hook. In any event,
3064 setting and rely on @code{defun-prompt-regexp} will definitely slow
3065 things down!
3066
3067 You will probably notice pathological behavior from @ccmode{} when
2934 working in files containing large amounts of cpp macros. This is 3068 working in files containing large amounts of cpp macros. This is
2935 because @code{cc-mode} cannot quickly skip backwards over these lines. 3069 because @ccmode{} cannot quickly skip backwards over these lines.
2936 3070
2937 @vindex c-recognize-knr-p 3071 @vindex c-recognize-knr-p
2938 @vindex recognize-knr-p (c-) 3072 @vindex recognize-knr-p (c-)
2939 Previous versions of @code{cc-mode} had potential performance problems 3073 Previous versions of @ccmode{} had potential performance problems
2940 when recognizing ``K&R'' style function argument declarations. This was 3074 when recognizing K&R style function argument declarations. This was
2941 because there are ambiguities in the C syntax when K&R style argument 3075 because there are ambiguities in the C syntax when K&R style argument
2942 lists are used (it is hard to distinguish them from top-level 3076 lists are used@footnote{It is hard to distinguish them from top-level
2943 declarations). @code{cc-mode} has adopted BOCM's convention for 3077 declarations.}. @ccmode{} has adopted BOCM's convention for
2944 limiting the search: it assumes that argdecls are indented at least one 3078 limiting the search: it assumes that argdecls are indented at least one
2945 space, and that the function headers are not indented at all. With 3079 space, and that the function headers are not indented at all. With
2946 current versions of @code{cc-mode}, 3080 current versions of @ccmode{}, user customization of
2947 @code{c-recognize-knr-p} is deprecated. 3081 @code{c-recognize-knr-p} is deprecated. Just don't put argdecls in
3082 column zero!
2948 3083
2949 @cindex @file{cc-lobotomy.el} file 3084 @cindex @file{cc-lobotomy.el} file
2950 @vindex cc-lobotomy-pith-list 3085 @vindex cc-lobotomy-pith-list
2951 You might want to investigate some of the 3086 You might want to investigate the speed-ups contained in the
2952 speed-ups contained in the file @file{cc-lobotomy.el}, which 3087 file @file{cc-lobotomy.el}, which is part of the @ccmode{} distribution.
2953 is part of the canonical @code{cc-mode} distribution. As mentioned 3088 As mentioned previous, @ccmode{} always trades accuracy for speed,
2954 previous, @code{cc-mode} always trades accuracy for speed, however it is 3089 however it is recognized that sometimes you need speed and can sacrifice
2955 recognized that sometimes you need speed and can sacrifice some accuracy 3090 some accuracy in indentation. The file @file{cc-lobotomy.el} contains
2956 in indentation. The file @file{cc-lobotomy.el} contains hacks that 3091 hacks that will ``dumb down'' @ccmode{} in some specific ways, making
2957 will ``dumb down'' @code{cc-mode} in some specific ways, making that 3092 that trade-off of speed for accuracy. I won't go into details of its
2958 trade-off of speed for accuracy. I won't go into details of its use 3093 use here; you should read the comments at the top of the file, and look
2959 here; you should read the comments at the top of the file, and look at 3094 at the variable @code{cc-lobotomy-pith-list} for details.
2960 the variable @code{cc-lobotomy-pith-list} for details. 3095
2961 3096
2962 3097 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2963 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 3098 @node Frequently Asked Questions, Getting the latest CC Mode release, Performance Issues, Top
2964 @node Frequently Asked Questions, Getting the latest cc-mode release, Performance Issues, Top
2965 @comment node-name, next, previous,up 3099 @comment node-name, next, previous,up
2966 3100
2967 @chapter Frequently Asked Questions 3101 @chapter Frequently Asked Questions
2968 @cindex Frequently Asked Questions 3102 @cindex Frequently Asked Questions
2969 @comment FAQ 3103 @comment FAQ
3012 3146
3013 (define-key c-mode-map "\C-m" 'newline-and-indent) 3147 (define-key c-mode-map "\C-m" 'newline-and-indent)
3014 3148
3015 @end example 3149 @end example
3016 3150
3017 This is a very common question. @code{:-)} If you want this to be the 3151 This is a very common question. If you want this to be the default
3018 default behavior, don't lobby me, lobby RMS! 3152 behavior, don't lobby me, lobby RMS! @code{:-)}
3019 @sp 1 3153 @sp 1
3020 3154
3021 @strong{Q.} @emph{I put @code{(c-set-offset 'substatement-open 0)} 3155 @strong{Q.} @emph{I put @code{(c-set-offset 'substatement-open 0)}
3022 in my @file{.emacs} file but I get an error saying that 3156 in my @file{.emacs} file but I get an error saying that
3023 @code{c-set-offset}'s function definition is void.} 3157 @code{c-set-offset}'s function definition is void.}
3024 3158
3025 @strong{A.} This means that @code{cc-mode} wasn't loaded into your 3159 @strong{A.} This means that @ccmode{} wasn't loaded into your
3026 Emacs session by the time the @code{c-set-offset} call was reached, 3160 Emacs session by the time the @code{c-set-offset} call was reached,
3027 mostly likely because @code{cc-mode} is being autoloaded. Instead 3161 mostly likely because @ccmode{} is being autoloaded. Instead
3028 of putting the @code{c-set-offset} line in your top-level 3162 of putting the @code{c-set-offset} line in your top-level
3029 @file{.emacs} file, put it in your @code{c-mode-common-hook}, or 3163 @file{.emacs} file, put it in your @code{c-mode-common-hook}, or
3030 simply add the following to the top of your @file{.emacs} file: 3164 simply add the following to the top of your @file{.emacs} file:
3031 @example 3165 @example
3032 3166
3040 @sp 1 3174 @sp 1
3041 @strong{Q.} @emph{How do I make strings, comments, keywords, and other 3175 @strong{Q.} @emph{How do I make strings, comments, keywords, and other
3042 constructs appear in different colors, or in bold face, etc.?} 3176 constructs appear in different colors, or in bold face, etc.?}
3043 3177
3044 @strong{A.} ``Syntax Colorization'' is an Emacs 19 feature, controlled 3178 @strong{A.} ``Syntax Colorization'' is an Emacs 19 feature, controlled
3045 by @code{font-lock-mode}. It is not part of @code{cc-mode}. 3179 by @code{font-lock-mode}. It is not part of @ccmode{}.
3046 3180
3047 @sp 1 3181 @sp 1
3048 @strong{Q.} @emph{I @code{setq} @code{c-basic-offset} to 4 in my 3182 @strong{Q.} @emph{I @code{setq} @code{c-basic-offset} to 4 in my
3049 @file{.emacs} file, but why does everything still get indented with only 3183 @file{.emacs} file, but why does everything still get indented with only
3050 2 spaces?} 3184 2 spaces?}
3051 3185
3052 @strong{A.} It's because @code{c-basic-offset} is now a ``buffer local 3186 @vindex c-style-variables-are-local-p
3053 variable'', meaning its value is unique to each buffer. The prefered 3187 @vindex style-variables-are-local-p
3054 way to customize this is to change its value in a ``mode hook'' (most 3188 @strong{A.} It's because @code{c-basic-offset} is, by default, a
3055 likely @code{c-mode-common-hook}. Alternatively you can use 3189 ``buffer local variable'', meaning its value is unique to each buffer.
3056 @code{setq-default} to change its value globally. 3190 The prefered way to customize this is to change its value in a ``mode
3191 hook'' (most likely @code{c-mode-common-hook}). Alternatively you can
3192 use @code{setq-default} to change its value globally. Better yet,
3193 before you load @file{cc-mode.el}, set the variable
3194 @code{c-style-variables-are-local-p} to @code{nil}. @xref{Advanced
3195 Customizations}.
3057 3196
3058 @end quotation 3197 @end quotation
3059 3198
3060 3199
3061 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 3200 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3062 @node Getting the latest cc-mode release, Sample .emacs File, Frequently Asked Questions, Top 3201 @node Getting the latest CC Mode release, Sample .emacs File, Frequently Asked Questions, Top
3063 @comment node-name, next, previous,up 3202 @comment node-name, next, previous,up
3064 3203
3065 @chapter Getting the latest @code{cc-mode} release 3204 @chapter Getting the latest CC Mode release
3066 @cindex Getting the latest @code{cc-mode} release 3205 @cindex Getting the latest CC Mode release
3067 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 3206 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3068 3207
3069 @code{cc-mode} is now distributed with both Emacs 19 and XEmacs 19, so 3208 @ccmode{} is now distributed with Emacs 19, XEmacs 19, and XEmacs 20, so
3070 you would typically just use the version that comes with your Emacs. 3209 you would typically just use the version that comes with your Emacs.
3071 These may be slightly out of date due to release schedule skew, so you 3210 These may be slightly out of date due to release schedule skew, so you
3072 should always check the canonical site for the latest version. 3211 should always check the canonical site for the latest version.
3073 3212
3074 @example 3213 @example
3087 3226
3088 There are many files under these directories; you can pick up the entire 3227 There are many files under these directories; you can pick up the entire
3089 distribution (named @code{cc-mode.tar.gz}; a gzip'd tar file), or any of 3228 distribution (named @code{cc-mode.tar.gz}; a gzip'd tar file), or any of
3090 the individual files, including PostScript documentation. 3229 the individual files, including PostScript documentation.
3091 3230
3092 If you do not have anonymous ftp access, you can get the distribution 3231 If you do not have World Wide Web, or anonymous ftp access, you can get
3093 through an anonymous ftp-to-mail gateway, such as the one run by DEC at 3232 the distribution through an anonymous ftp-to-mail gateway, such as the
3094 @code{ftpmail@@decwrl.dec.com}. To get @code{cc-mode} via email, send 3233 one run by DEC at:
3095 the following message in the body of your mail to that address: 3234 @example
3235
3236 @code{ftpmail@@decwrl.dec.com}
3237
3238 @end example
3239 To get @ccmode{} via email, send the following message in the body of
3240 your mail to that address:
3096 @example 3241 @example
3097 3242
3098 reply <a valid net address back to you> 3243 reply <a valid net address back to you>
3099 connect ftp.python.org 3244 connect ftp.python.org
3100 binary 3245 binary
3108 Response times will vary with the number of requests in the queue. I am 3253 Response times will vary with the number of requests in the queue. I am
3109 in no way connected to this service, so I make no claims or guarantees 3254 in no way connected to this service, so I make no claims or guarantees
3110 about its availability! 3255 about its availability!
3111 3256
3112 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 3257 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3113 @node Sample .emacs File, Limitations and Known Bugs, Getting the latest cc-mode release, Top 3258 @node Sample .emacs File, Limitations and Known Bugs, Getting the latest CC Mode release, Top
3114 @comment node-name, next, previous,up 3259 @comment node-name, next, previous,up
3115 3260
3116 @chapter Sample @file{.emacs} file 3261 @chapter Sample .emacs file
3117 @cindex Sample @file{.emacs} file 3262 @cindex Sample .emacs file
3118 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 3263 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3119 3264
3120 @example 3265 @example
3121 ;; Here's a sample .emacs file that might help you along the way. Just 3266 ;; Here's a sample .emacs file that might help you along the way. Just
3122 ;; copy this region and paste it into your .emacs file. You may want to 3267 ;; copy this region and paste it into your .emacs file. You may want to
3123 ;; change some of the actual values. 3268 ;; change some of the actual values.
3124 3269
3125 (defconst my-c-style 3270 (defconst my-c-style
3126 '((c-tab-always-indent . t) 3271 '((c-tab-always-indent . t)
3127 (c-comment-only-line-offset . 4) 3272 (c-comment-only-line-offset . 4)
3128 (c-hanging-braces-alist . ((substatement-open after) 3273 (c-hanging-braces-alist . ((substatement-open after)
3129 (brace-list-open))) 3274 (brace-list-open)))
3130 (c-hanging-colons-alist . ((member-init-intro before) 3275 (c-hanging-colons-alist . ((member-init-intro before)
3131 (inher-intro) 3276 (inher-intro)
3132 (case-label after) 3277 (case-label after)
3133 (label after) 3278 (label after)
3134 (access-label after))) 3279 (access-label after)))
3135 (c-cleanup-list . (scope-operator 3280 (c-cleanup-list . (scope-operator
3136 empty-defun-braces 3281 empty-defun-braces
3137 defun-close-semi)) 3282 defun-close-semi))
3138 (c-offsets-alist . ((arglist-close . c-lineup-arglist) 3283 (c-offsets-alist . ((arglist-close . c-lineup-arglist)
3139 (substatement-open . 0) 3284 (substatement-open . 0)
3140 (case-label . 4) 3285 (case-label . 4)
3141 (block-open . 0) 3286 (block-open . 0)
3142 (knr-argdecl-intro . -))) 3287 (knr-argdecl-intro . -)))
3143 (c-echo-syntactic-information-p . t) 3288 (c-echo-syntactic-information-p . t)
3144 ) 3289 )
3145 "My C Programming Style") 3290 "My C Programming Style")
3146 3291
3147 ;; Customizations for all of c-mode, c++-mode, and objc-mode 3292 ;; Customizations for all of c-mode, c++-mode, and objc-mode
3181 3326
3182 @item 3327 @item
3183 Re-indenting large regions or expressions can be slow. 3328 Re-indenting large regions or expressions can be slow.
3184 3329
3185 @item 3330 @item
3186 Use with Emacs 18 can be slow and annoying. You should seriously 3331 Use with Emacs 18 can be slow and annoying. You should seriously
3187 consider upgrading to Emacs 19. 3332 consider upgrading to Emacs 19.
3188 3333
3189 @item 3334 @item
3190 There is still some weird behavior when filling C block comments. 3335 Add-on fill packages may not work as well as @ccmode{}'s built-in
3191 My suggestion is to check out separate fill packages such as 3336 filling routines. I no longer recommend you use @code{filladapt} to
3192 @code{filladapt} or @code{adaptive-fill-mode}. These can do a much 3337 fill comments.
3193 better job of filling comment regions.
3194 3338
3195 @cindex c-indent-exp 3339 @cindex c-indent-exp
3196 @cindex indent-exp (c-) 3340 @cindex indent-exp (c-)
3197 @item 3341 @item
3198 @code{c-indent-exp} has not been fully optimized. It essentially 3342 @code{c-indent-exp} has not been fully optimized. It essentially
3223 @emph{before} your bug example, if you think it might affect my ability 3367 @emph{before} your bug example, if you think it might affect my ability
3224 to reproduce it. 3368 to reproduce it.
3225 3369
3226 Bug reports are now sent to the following email addresses: 3370 Bug reports are now sent to the following email addresses:
3227 @code{cc-mode-help@@python.org} and 3371 @code{cc-mode-help@@python.org} and
3228 @code{bug-gnu-emacs@@prep.ai.mit.edu}; the latter is mirrored on the Usenet 3372 @code{bug-gnu-emacs@@prep.ai.mit.edu}; the latter is mirrored on the
3229 newsgroup @code{gnu.emacs.bug}. Other questions and suggestions should 3373 Usenet newsgroup @code{gnu.emacs.bug}. You can send other questions,
3230 be mailed to @code{help-gnu-emacs@@prep.ai.mit.edu} which is mirrored on 3374 suggestions, and kudos to @code{cc-mode-help@@python.org}, or
3375 @code{help-gnu-emacs@@prep.ai.mit.edu} which is mirrored on newsgroup
3231 @code{gnu.emacs.help}. 3376 @code{gnu.emacs.help}.
3232 3377
3233 3378
3234 @c !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 3379 @c !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3235 @node Concept Index, Command Index, Mailing Lists and Submitting Bug Reports, Top 3380 @node Concept Index, Command Index, Mailing Lists and Submitting Bug Reports, Top
3247 @c !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 3392 @c !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3248 3393
3249 @ifinfo 3394 @ifinfo
3250 3395
3251 @end ifinfo 3396 @end ifinfo
3252 Since all @code{cc-mode} commands are prepended with the string 3397 Since all @ccmode{} commands are prepended with the string
3253 @samp{c-}, each appears under its @code{c-@var{<thing>}} name and its 3398 @samp{c-}, each appears under its @code{c-@var{<thing>}} name and its
3254 @code{@var{<thing>} (c-)} name. 3399 @code{@var{<thing>} (c-)} name.
3255 @iftex 3400 @iftex
3256 @sp 2 3401 @sp 2
3257 @end iftex 3402 @end iftex
3271 @node Variable Index, , Key Index, Top 3416 @node Variable Index, , Key Index, Top
3272 @comment node-name, next, previous, up 3417 @comment node-name, next, previous, up
3273 @unnumbered Variable Index 3418 @unnumbered Variable Index
3274 @c !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 3419 @c !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3275 3420
3276 @ifinfo 3421 Since all @ccmode{} variables are prepended with the string
3277
3278 @end ifinfo
3279 Since all @code{cc-mode} variables are prepended with the string
3280 @samp{c-}, each appears under its @code{c-@var{<thing>}} name and its 3422 @samp{c-}, each appears under its @code{c-@var{<thing>}} name and its
3281 @code{@var{<thing>} (c-)} name. 3423 @code{@var{<thing>} (c-)} name.
3282 @iftex 3424 @iftex
3283 @sp 2 3425 @sp 2
3284 @end iftex 3426 @end iftex