comparison man/cc-mode.texi @ 70:131b0175ea99 r20-0b30

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