root/branches/2.1/info/ccmode-3

Revision 3212, 48.4 kB (checked in by miyoshi, 5 years ago)

Sync up with Emacs-21.3.

Line 
1 This is ../info/ccmode, produced by makeinfo version 4.2 from
2 cc-mode.texi.
3
4 INFO-DIR-SECTION Emacs
5 START-INFO-DIR-ENTRY
6 * CC Mode: (ccmode).   Emacs mode for editing C, C++, Objective-C,
7                           Java, Pike, and IDL code.
8 END-INFO-DIR-ENTRY
9
10    Copyright (C) 1995, 96, 97, 98, 99, 2000, 2001 Free Software
11 Foundation, Inc.
12
13    Permission is granted to copy, distribute and/or modify this document
14 under the terms of the GNU Free Documentation License, Version 1.1 or
15 any later version published by the Free Software Foundation; with the
16 Invariant Sections being "The GNU Manifesto", "Distribution" and "GNU
17 GENERAL PUBLIC LICENSE", with the Front-Cover texts being "A GNU
18 Manual", and with the Back-Cover Texts as in (a) below.  A copy of the
19 license is included in the section entitled "GNU Free Documentation
20 License" in the Emacs manual.
21
22    (a) The FSF's Back-Cover Text is: "You have freedom to copy and
23 modify this GNU Manual, like GNU software.  Copies published by the Free
24 Software Foundation raise funds for GNU development."
25
26    This document is part of a collection distributed under the GNU Free
27 Documentation License.  If you want to distribute this document
28 separately from the collection, you can do so by adding a copy of the
29 license to the document, as described in section 6 of the license.
30
31 
32 File: ccmode,  Node: Syntactic Symbols,  Next: Indentation Functions,  Prev: Customizing Indentation,  Up: Top
33
34 Syntactic Symbols
35 *****************
36
37    Here is a complete list of the recognized syntactic symbols as
38 described in the `c-offsets-alist' style variable, along with a brief
39 description.  More detailed descriptions follow.
40
41 `string'
42      Inside a multi-line string.
43
44 `c'
45      Inside a multi-line C style block comment.
46
47 `defun-open'
48      Brace that opens a top-level function definition.
49
50 `defun-close'
51      Brace that closes a top-level function definition.
52
53 `defun-block-intro'
54      The first line in a top-level defun.
55
56 `class-open'
57      Brace that opens a class definition.
58
59 `class-close'
60      Brace that closes a class definition.
61
62 `inline-open'
63      Brace that opens an in-class inline method.
64
65 `inline-close'
66      Brace that closes an in-class inline method.
67
68 `func-decl-cont'
69      The region between a function definition's argument list and the
70      function opening brace (excluding K&R argument declarations).  In
71      C, you cannot put anything but whitespace and comments in this
72      region, however in C++ and Java, `throws' declarations and other
73      things can appear here.
74
75 `knr-argdecl-intro'
76      First line of a K&R C argument declaration.
77
78 `knr-argdecl'
79      Subsequent lines in a K&R C argument declaration.
80
81 `topmost-intro'
82      The first line in a "topmost" definition.
83
84 `topmost-intro-cont'
85      Topmost definition continuation lines.
86
87 `member-init-intro'
88      First line in a member initialization list.
89
90 `member-init-cont'
91      Subsequent member initialization list lines.
92
93 `inher-intro'
94      First line of a multiple inheritance list.
95
96 `inher-cont'
97      Subsequent multiple inheritance lines.
98
99 `block-open'
100      Statement block open brace.
101
102 `block-close'
103      Statement block close brace.
104
105 `brace-list-open'
106      Open brace of an enum or static array list.
107
108 `brace-list-close'
109      Close brace of an enum or static array list.
110
111 `brace-list-intro'
112      First line in an enum or static array list.
113
114 `brace-list-entry'
115      Subsequent lines in an enum or static array list.
116
117 `brace-entry-open'
118      Subsequent lines in an enum or static array list where the line
119      begins with an open brace.
120
121 `statement'
122      A statement.
123
124 `statement-cont'
125      A continuation of a statement.
126
127 `statement-block-intro'
128      The first line in a new statement block.
129
130 `statement-case-intro'
131      The first line in a case block.
132
133 `statement-case-open'
134      The first line in a case block that starts with a brace.
135
136 `substatement'
137      The first line after a conditional or loop construct.
138
139 `substatement-open'
140      The brace that opens a substatement block.
141
142 `case-label'
143      A `case' or `default' label.
144
145 `access-label'
146      C++ access control label.
147
148 `label'
149      Any non-special C label.
150
151 `do-while-closure'
152      The `while' line that ends a `do'-`while' construct.
153
154 `else-clause'
155      The `else' line of an `if'-`else' construct.
156
157 `catch-clause'
158      The `catch' or `finally' (in Java) line of a `try'-`catch'
159      construct.
160
161 `comment-intro'
162      A line containing only a comment introduction.
163
164 `arglist-intro'
165      The first line in an argument list.
166
167 `arglist-cont'
168      Subsequent argument list lines when no arguments follow on the
169      same line as the arglist opening paren.
170
171 `arglist-cont-nonempty'
172      Subsequent argument list lines when at least one argument follows
173      on the same line as the arglist opening paren.
174
175 `arglist-close'
176      The solo close paren of an argument list.
177
178 `stream-op'
179      Lines continuing a stream operator (C++ only).
180
181 `inclass'
182      The line is nested inside a class definition.
183
184 `cpp-macro'
185      The start of a C preprocessor macro definition.
186
187 `cpp-macro-cont'
188      Subsequent lines of a multi-line C preprocessor macro definition.
189
190 `friend'
191      A C++ friend declaration.
192
193 `objc-method-intro'
194      The first line of an Objective-C method.  definition.
195
196 `objc-method-args-cont'
197      Lines continuing an Objective-C method.  definition
198
199 `objc-method-call-cont'
200      Lines continuing an Objective-C method call.
201
202 `extern-lang-open'
203      Brace that opens an external language block.
204
205 `extern-lang-close'
206      Brace that closes an external language block.
207
208 `inextern-lang'
209      Analogous to `inclass' syntactic symbol, but used inside external
210      language blocks (e.g. `extern "C" {').
211
212 `namespace-open'
213      Brace that opens a C++ namespace block.
214
215 `namespace-close'
216      Brace that closes a C++ namespace block.
217
218 `innamespace'
219      Analogous to `inextern-lang' syntactic symbol, but used inside C++
220      namespace blocks.
221
222 `template-args-cont'
223      C++ template argument list continuations.
224
225 `inlambda'
226      Analogous to `inclass' syntactic symbol, but used inside lambda
227      (i.e. anonymous) functions.  Only used in Pike mode.
228
229 `lambda-intro-cont'
230      Lines continuing the header of a lambda function, i.e. between the
231      `lambda' keyword and the function body.  Only used in Pike mode.
232
233 `inexpr-statement'
234      A statement block inside an expression.  The gcc C extension of
235      this is recognized.  It's also used for the special functions that
236      takes a statement block as an argument in Pike.
237
238 `inexpr-class'
239      A class definition inside an expression.  This is used for
240      anonymous classes in Java.  It's also used for anonymous array
241      initializers in Java.
242
243    Most syntactic symbol names follow a general naming convention.
244 When a line begins with an open or close brace, the syntactic symbol
245 will contain the suffix `-open' or `-close' respectively.
246
247    Usually, a distinction is made between the first line that
248 introduces a construct and lines that continue a construct, and the
249 syntactic symbols that represent these lines will contain the suffix
250 `-intro' or `-cont' respectively.  As a sub-classification of this
251 scheme, a line which is the first of a particular brace block construct
252 will contain the suffix `-block-intro'.
253
254    Let's look at some examples to understand how this works.  Remember
255 that you can check the syntax of any line by using `C-c C-s'.
256
257        1: void
258        2: swap( int& a, int& b )
259        3: {
260        4:     int tmp = a;
261        5:     a = b;
262        6:     b = tmp;
263        7:     int ignored =
264        8:         a + b;
265        9: }
266
267    Line 1 shows a `topmost-intro' since it is the first line that
268 introduces a top-level construct.  Line 2 is a continuation of the
269 top-level construct introduction so it has the syntax
270 `topmost-intro-cont'.  Line 3 shows a `defun-open' since it is the
271 brace that opens a top-level function definition.  Line 9 is the
272 corresponding `defun-close' since it contains the brace that closes the
273 top-level function definition.  Line 4 is a `defun-block-intro', i.e.
274 it is the first line of a brace-block, enclosed in a top-level function
275 definition.
276
277    Lines 5, 6, and 7 are all given `statement' syntax since there isn't
278 much special about them.  Note however that line 8 is given
279 `statement-cont' syntax since it continues the statement begun on the
280 previous line.
281
282    Here's another example, which illustrates some C++ class syntactic
283 symbols:
284
285         1: class Bass
286         2:     : public Guitar,
287         3:       public Amplifiable
288         4: {
289         5: public:
290         6:     Bass()
291         7:         : eString( new BassString( 0.105 )),
292         8:           aString( new BassString( 0.085 )),
293         9:           dString( new BassString( 0.065 )),
294        10:           gString( new BassString( 0.045 ))
295        11:     {
296        12:         eString.tune( 'E' );
297        13:         aString.tune( 'A' );
298        14:         dString.tune( 'D' );
299        15:         gString.tune( 'G' );
300        16:     }
301        17:     friend class Luthier;
302        18: }
303
304    As in the previous example, line 1 has the `topmost-intro' syntax.
305 Here however, the brace that opens a C++ class definition on line 4 is
306 assigned the `class-open' syntax.  Note that in C++, classes, structs,
307 and unions are essentially equivalent syntactically (and are very
308 similar semantically), so replacing the `class' keyword in the example
309 above with `struct' or `union' would still result in a syntax of
310 `class-open' for line 4 (1).  Similarly, line 18 is assigned
311 `class-close' syntax.
312
313    Line 2 introduces the inheritance list for the class so it is
314 assigned the `inher-intro' syntax, and line 3, which continues the
315 inheritance list is given `inher-cont' syntax.
316
317    Hitting `C-c C-s' on line 5 shows the following analysis:
318
319
320      `((inclass . 58) (access-label . 67))'
321
322 The primary syntactic symbol for this line is `access-label' as this a
323 label keyword that specifies access protection in C++.  However,
324 because this line is also a top-level construct inside a class
325 definition, the analysis actually shows two syntactic symbols.  The
326 other syntactic symbol assigned to this line is `inclass'.  Similarly,
327 line 6 is given both `inclass' and `topmost-intro' syntax:
328
329
330      `((inclass . 58) (topmost-intro . 60))'
331
332    Line 7 introduces a C++ member initialization list and as such is
333 given `member-init-intro' syntax.  Note that in this case it is _not_
334 assigned `inclass' since this is not considered a top-level construct.
335 Lines 8 through 10 are all assigned `member-init-cont' since they
336 continue the member initialization list started on line 7.
337
338    Line 11's analysis is a bit more complicated:
339
340
341      `((inclass . 58) (inline-open))'
342
343    This line is assigned a syntax of both `inline-open' and `inclass'
344 because it opens an "in-class" C++ inline method definition.  This is
345 distinct from, but related to, the C++ notion of an inline function in
346 that its definition occurs inside an enclosing class definition, which
347 in C++ implies that the function should be inlined.  If though, the
348 definition of the `Bass' constructor appeared outside the class
349 definition, the construct would be given the `defun-open' syntax, even
350 if the keyword `inline' appeared before the method name, as in:
351
352      class Bass
353          : public Guitar,
354            public Amplifiable
355      {
356      public:
357          Bass();
358      }
359      
360      inline
361      Bass::Bass()
362          : eString( new BassString( 0.105 )),
363            aString( new BassString( 0.085 )),
364            dString( new BassString( 0.065 )),
365            gString( new BassString( 0.045 ))
366      {
367          eString.tune( 'E' );
368          aString.tune( 'A' );
369          dString.tune( 'D' );
370          gString.tune( 'G' );
371      }
372
373    Returning to the previous example, line 16 is given `inline-close'
374 syntax, while line 12 is given `defun-block-open' syntax, and lines 13
375 through 15 are all given `statement' syntax.  Line 17 is interesting in
376 that its syntactic analysis list contains three elements:
377
378
379      `((friend) (inclass . 58) (topmost-intro . 380))'
380
381    The `friend' syntactic symbol is a modifier that typically does not
382 have a relative buffer position.
383
384    Template definitions introduce yet another syntactic symbol:
385
386
387         1: ThingManager <int,
388         2:    Framework::Callback *,
389         3:    Mutex> framework_callbacks;
390
391    Here, line 1 is analyzed as a `topmost-intro', but lines 2 and 3 are
392 both analyzed as `template-args-cont' lines.
393
394    Here is another (totally contrived) example which illustrates how
395 syntax is assigned to various conditional constructs:
396
397         1: void spam( int index )
398         2: {
399         3:     for( int i=0; i<index; i++ )
400         4:     {
401         5:         if( i == 10 )
402         6:         {
403         7:             do_something_special();
404         8:         }
405         9:         else
406        10:             do_something( i );
407        11:     }
408        12:     do {
409        13:         another_thing( i-- );
410        14:     }
411        15:     while( i > 0 );
412        16: }
413
414 Only the lines that illustrate new syntactic symbols will be discussed.
415
416    Line 4 has a brace which opens a conditional's substatement block.
417 It is thus assigned `substatement-open' syntax, and since line 5 is the
418 first line in the substatement block, it is assigned
419 `substatement-block-intro' syntax.  Lines 6 and 7 are assigned similar
420 syntax.  Line 8 contains the brace that closes the inner substatement
421 block.  It is given the syntax `block-close', as are lines 11 and 14.
422
423    Line 9 is a little different -- since it contains the keyword `else'
424 matching the `if' statement introduced on line 5, it is given the
425 `else-clause' syntax.  The `try'-`catch' constructs in C++ and Java are
426 treated this way too, with the only difference that the `catch', and in
427 Java also `finally', is marked with `catch-clause'.
428
429    Line 10 is also slightly different.  Because `else' is considered a
430 conditional introducing keyword (2), and because the following
431 substatement is not a brace block, line 10 is assigned the
432 `substatement' syntax.
433
434    One other difference is seen on line 15.  The `while' construct that
435 closes a `do' conditional is given the special syntax
436 `do-while-closure' if it appears on a line by itself.  Note that if the
437 `while' appeared on the same line as the preceding close brace, that
438 line would have been assigned `block-close' syntax instead.
439
440    Switch statements have their own set of syntactic symbols.  Here's an
441 example:
442
443         1: void spam( enum Ingredient i )
444         2: {
445         3:     switch( i ) {
446         4:     case Ham:
447         5:         be_a_pig();
448         6:         break;
449         7:     case Salt:
450         8:         drink_some_water();
451         9:         break;
452        10:     default:
453        11:         {
454        12:             what_is_it();
455        13:             break;
456        14:         }
457        15:     }
458        14: }
459
460    Here, lines 4, 7, and 10 are all assigned `case-label' syntax, while
461 lines 5 and 8 are assigned `statement-case-intro'.  Line 11 is treated
462 slightly differently since it contains a brace that opens a block -- it
463 is given `statement-case-open' syntax.
464
465    There are a set of syntactic symbols that are used to recognize
466 constructs inside of brace lists.  A brace list is defined as an `enum'
467 or aggregate initializer list, such as might statically initialize an
468 array of structs.  The three special aggregate constructs in Pike, `({
469 })', `([ ])' and `(< >)', are treated as brace lists too.  An example:
470
471        1: static char* ingredients[] =
472        2: {
473        3:     "Ham",
474        4:     "Salt",
475        5:     NULL
476        6: }
477
478    Following convention, line 2 in this example is assigned
479 `brace-list-open' syntax, and line 3 is assigned `brace-list-intro'
480 syntax.  Likewise, line 6 is assigned `brace-list-close' syntax.  Lines
481 4 and 5 however, are assigned `brace-list-entry' syntax, as would all
482 subsequent lines in this initializer list.
483
484    Your static initializer might be initializing nested structures, for
485 example:
486
487        1: struct intpairs[] =
488        2: {
489        3:     { 1, 2 },
490        4:     {
491        5:         3,
492        6:         4
493        7:     }
494        8:     { 1,
495        9:       2 },
496       10:     { 3, 4 }
497       11: }
498
499    Here, you've already seen the analysis of lines 1, 2, 3, and 11.  On
500 line 4, things get interesting; this line is assigned
501 `brace-entry-open' syntactic symbol because it's a bracelist entry line
502 that starts with an open brace.  Lines 5 and 6 (and line 9) are pretty
503 standard, and line 7 is a `brace-list-close' as you'd expect.  Once
504 again, line 8 is assigned as `brace-entry-open' as is line 10.
505
506    External language definition blocks also have their own syntactic
507 symbols.  In this example:
508
509         1: extern "C"
510         2: {
511         3:     int thing_one( int );
512         4:     int thing_two( double );
513         5: }
514
515 line 2 is given the `extern-lang-open' syntax, while line 5 is given
516 the `extern-lang-close' syntax.  The analysis for line 3 yields:
517 `((inextern-lang) (topmost-intro . 14))', where `inextern-lang' is a
518 modifier similar in purpose to `inclass'.
519
520    Similarly, C++ namespace constructs have their own associated
521 syntactic symbols.  In this example:
522
523         1: namespace foo
524         2: {
525         3:     void xxx() {}
526         4: }
527
528 line 2 is given the `namespace-open' syntax, while line 4 is given the
529 `namespace-close' syntax.  The analysis for line 3 yields:
530 `((innamespace) (topmost-intro . 17))', where `innamespace' is a
531 modifier similar in purpose to `inextern-lang' and `inclass'.
532
533    A number of syntactic symbols are associated with parenthesis lists,
534 a.k.a argument lists, as found in function declarations and function
535 calls.  This example illustrates these:
536
537         1: void a_function( int line1,
538         2:                  int line2 );
539         3:
540         4: void a_longer_function(
541         5:     int line1,
542         6:     int line2
543         7:     );
544         8:
545         9: void call_them( int line1, int line2 )
546        10: {
547        11:     a_function(
548        12:         line1,
549        13:         line2
550        14:         );
551        15:
552        16:     a_longer_function( line1,
553        17:                        line2 );
554        18: }
555
556    Lines 5 and 12 are assigned `arglist-intro' syntax since they are
557 the first line following the open parenthesis, and lines 7 and 14 are
558 assigned `arglist-close' syntax since they contain the parenthesis that
559 closes the argument list.
560
561    Lines that continue argument lists can be assigned one of two
562 syntactic symbols.  For example, Lines 2 and 17 are assigned
563 `arglist-cont-nonempty' syntax.  What this means is that they continue
564 an argument list, but that the line containing the parenthesis that
565 opens the list is _not empty_ following the open parenthesis.  Contrast
566 this against lines 6 and 13 which are assigned `arglist-cont' syntax.
567 This is because the parenthesis that opens their argument lists is the
568 last character on that line.
569
570    Note that there is no `arglist-open' syntax.  This is because any
571 parenthesis that opens an argument list, appearing on a separate line,
572 is assigned the `statement-cont' syntax instead.
573
574    A few miscellaneous syntactic symbols that haven't been previously
575 covered are illustrated by this C++ example:
576
577         1: void Bass::play( int volume )
578         2: const
579         3: {
580         4:     /* this line starts a multi-line
581         5:      * comment.  This line should get `c' syntax */
582         6:
583         7:     char* a_multiline_string = "This line starts a multi-line \
584         8: string.  This line should get `string' syntax.";
585         9:
586        10:   note:
587        11:     {
588        12: #ifdef LOCK
589        13:         Lock acquire();
590        14: #endif // LOCK
591        15:         slap_pop();
592        16:         cout << "I played "
593        17:              << "a note\n";
594        18:     }
595        19: }
596
597    The lines to note in this example include:
598
599    * Line 2 is assigned the `func-decl-cont' syntax.
600
601    * Line 4 is assigned both `defun-block-intro' _and_ `comment-intro'
602      syntax.
603
604    * Line 5 is assigned `c' syntax.
605
606    * Line 6 which, even though it contains nothing but whitespace, is
607      assigned `defun-block-intro'.  Note that the appearance of the
608      comment on lines 4 and 5 do not cause line 6 to be assigned
609      `statement' syntax because comments are considered to be
610      "syntactic whitespace", which are ignored when analyzing code.
611
612    * Line 8 is assigned `string' syntax.
613
614    * Line 10 is assigned `label' syntax.
615
616    * Line 11 is assigned `block-open' syntax.
617
618    * Lines 12 and 14 are assigned `cpp-macro' syntax in addition to the
619      normal syntactic symbols (`statement-block-intro' and `statement',
620      respectively).  Normally `cpp-macro' is configured to cancel out
621      the normal syntactic context to make all preprocessor directives
622      stick to the first column, but that's easily changed if you want
623      preprocessor directives to be indented like the rest of the code.
624
625    * Line 17 is assigned `stream-op' syntax.
626
627
628    Multi-line C preprocessor macros are now (somewhat) supported.  At
629 least CC Mode now recognizes the fact that it is inside a multi-line
630 macro, and it properly skips such macros as syntactic whitespace.  In
631 this example:
632
633         1: #define LIST_LOOP(cons, listp)                           \
634         2:   for (cons = listp; !NILP (cons); cons = XCDR (cons))   \
635         3:      if (!CONSP (cons))                                  \
636         4:        signal_error ("Invalid list format", listp);      \
637         5:      else
638
639 line 1 is given the syntactic symbol `cpp-macro'.  This first line of a
640 macro is always given this symbol.  The second and subsequent lines
641 (e.g. lines 2 through 5) are given the `cpp-macro-cont' syntactic
642 symbol, with a relative buffer position pointing to the `#' which
643 starts the macro definition.
644
645    In Objective-C buffers, there are three additional syntactic symbols
646 assigned to various message calling constructs.  Here's an example
647 illustrating these:
648
649        1: - (void)setDelegate:anObject
650        2:           withStuff:stuff
651        3: {
652        4:     [delegate masterWillRebind:self
653        5:               toDelegate:anObject
654        6:               withExtraStuff:stuff];
655        7: }
656
657    Here, line 1 is assigned `objc-method-intro' syntax, and line 2 is
658 assigned `objc-method-args-cont' syntax.  Lines 5 and 6 are both
659 assigned `objc-method-call-cont' syntax.
660
661    Java has a concept of anonymous classes, which may look something
662 like this:
663
664        1: public void watch(Observable o) {
665        2:     o.addObserver(new Observer() {
666        3:             public void update(Observable o, Object arg) {
667        4:                 history.addElement(arg);
668        5:             }
669        6:         });
670        7: }
671
672    The brace following the `new' operator opens the anonymous class.
673 Lines 3 and 6 are assigned the `inexpr-class' syntax, besides the
674 `inclass' symbol used in normal classes.  Thus, the class will be
675 indented just like a normal class, with the added indentation given to
676 `inexpr-class'.
677
678    There are a few occasions where a statement block may be used inside
679 an expression.  One is in C code using the gcc extension for this, e.g:
680
681        1: int res = ({
682        2:         int y = foo (); int z;
683        3:         if (y > 0) z = y; else z = - y;
684        4:         z;
685        5:     });
686
687    Lines 2 and 5 get the `inexpr-statement' syntax, besides the symbols
688 they'd get in a normal block.  Therefore, the indentation put on
689 `inexpr-statement' is added to the normal statement block indentation.
690
691    In Pike code, there are a few other situations where blocks occur
692 inside statements, as illustrated here:
693
694        1: array itgob()
695        2: {
696        3:     string s = map (backtrace()[-2][3..],
697        4:                     lambda
698        5:                         (mixed arg)
699        6:                     {
700        7:                         return sprintf ("%t", arg);
701        8:                     }) * ", " + "\n";
702        9:     return catch {
703       10:             write (s + "\n");
704       11:         };
705       12: }
706
707    Lines 4 through 8 contain a lambda function, which CC Mode recognizes
708 by the `lambda' keyword.  If the function argument list is put on a
709 line of its own, as in line 5, it gets the `lambda-intro-cont' syntax.
710 The function body is handled as an inline method body, with the
711 addition of the `inlambda' syntactic symbol.  This means that line 6
712 gets `inlambda' and `inline-open', and line 8 gets `inline-close'(3).
713
714    On line 9, `catch' is a special function taking a statement block as
715 its argument.  The block is handled as an in-expression statement with
716 the `inexpr-statement' syntax, just like the gcc extended C example
717 above.  The other similar special function, `gauge', is handled like
718 this too.
719
720    Two other syntactic symbols can appear in old style, non-prototyped C
721 code (4):
722
723        1: int add_three_integers(a, b, c)
724        2:      int a;
725        3:      int b;
726        4:      int c;
727        5: {
728        6:     return a + b + c;
729        7: }
730
731    Here, line 2 is the first line in an argument declaration list and
732 so is given the `knr-argdecl-intro' syntactic symbol.  Subsequent lines
733 (i.e. lines 3 and 4 in this example), are given `knr-argdecl' syntax.
734
735    ---------- Footnotes ----------
736
737    (1) This is the case even for C and Objective-C.  For consistency,
738 structs in all supported languages are syntactically equivalent to
739 classes.  Note however that the keyword `class' is meaningless in C and
740 Objective-C.
741
742    (2) The list of conditional keywords are (in C, C++, Objective-C,
743 Java, and Pike): `for', `if', `do', `else', `while', and `switch'.  C++
744 and Java have two additional conditional keywords: `try' and `catch'.
745 Java also has the `finally' and `synchronized' keywords.
746
747    (3) You might wonder why it doesn't get `inlambda' too.  It's
748 because the closing brace is relative to the opening brace, which
749 stands on its own line in this example.  If the opening brace was
750 hanging on the previous line, then the closing brace would get the
751 `inlambda' syntax too to be indented correctly.
752
753    (4) a.k.a. K&R C, or Kernighan & Ritchie C
754
755 
756 File: ccmode,  Node: Indentation Functions,  Next: Performance Issues,  Prev: Syntactic Symbols,  Up: Top
757
758 Indentation Functions
759 *********************
760
761    Often there are cases when a simple offset setting on a syntactic
762 symbol isn't enough to get the desired indentation.  Therefore, it's
763 also possible to use a "indentation function" (a.k.a. line-up function)
764 for a syntactic symbol.
765
766    CC Mode comes with many predefined indentation functions for common
767 situations.  If none of these does what you want, you can write your
768 own, see *Note Custom Indentation Functions::.  If you do, it's
769 probably a good idea to start working from one of these predefined
770 functions, they can be found in the file `cc-align.el'.
771
772    For every function below there is a "works with" list that indicates
773 which syntactic symbols the function is intended to be used with.
774
775 `c-lineup-arglist'
776      Line up the current argument line under the first argument.
777
778      Works with: `arglist-cont-nonempty'.
779
780 `c-lineup-arglist-intro-after-paren'
781      Line up a line just after the open paren of the surrounding paren
782      or brace block.
783
784      Works with: `defun-block-intro', `brace-list-intro',
785      `statement-block-intro', `statement-case-intro', `arglist-intro'.
786
787 `c-lineup-arglist-close-under-paren'
788      Set e.g. your `arglist-close' syntactic symbol to this line-up
789      function so that parentheses that close argument lists will line up
790      under the parenthesis that opened the argument list.
791
792      Works with: `defun-close', `class-close', `inline-close',
793      `block-close', `brace-list-close', `arglist-close',
794      `extern-lang-close', `namespace-close' (for most of these, a zero
795      offset will normally produce the same result, though).
796
797 `c-lineup-close-paren'
798      Line up the closing paren under its corresponding open paren if the
799      open paren is followed by code.  If the open paren ends its line,
800      no indentation is added.  E.g:
801
802           main (int,
803                 char **
804                )                   // c-lineup-close-paren
805
806      and
807
808           main (
809               int, char **
810           )                        // c-lineup-close-paren
811
812      Works with: `defun-close', `class-close', `inline-close',
813      `block-close', `brace-list-close', `arglist-close',
814      `extern-lang-close', `namespace-close'.
815
816 `c-lineup-streamop'
817      Line up C++ stream operators (i.e. `<<' and `>>').
818
819      Works with: `stream-op'.
820
821 `c-lineup-multi-inher'
822      Line up the classes in C++ multiple inheritance clauses and member
823      initializers under each other.  E.g:
824
825           Foo::Foo (int a, int b):
826               Cyphr (a),
827               Bar (b)              // c-lineup-multi-inher
828
829      and
830
831           class Foo
832               : public Cyphr,
833                 public Bar         // c-lineup-multi-inher
834
835      and
836
837           Foo::Foo (int a, int b)
838               : Cyphr (a)
839               , Bar (b)            // c-lineup-multi-inher
840
841      Works with: `inher-cont', `member-init-cont'.
842
843 `c-lineup-java-inher'
844      Line up Java implements and extends declarations.  If class names
845      follows on the same line as the `implements'/`extends' keyword,
846      they are lined up under each other.  Otherwise, they are indented
847      by adding `c-basic-offset' to the column of the keyword.  E.g:
848
849           class Foo
850               extends
851                   Bar              // c-lineup-java-inher
852          
853               <--> c-basic-offset
854
855      and
856
857           class Foo
858               extends Cyphr,
859                       Bar          // c-lineup-java-inher
860
861      Works with: `inher-cont'.
862
863 `c-lineup-java-throws'
864      Line up Java throws declarations.  If exception names follows on
865      the same line as the throws keyword, they are lined up under each
866      other.  Otherwise, they are indented by adding `c-basic-offset' to
867      the column of the `throws' keyword.  The `throws' keyword itself
868      is also indented by `c-basic-offset' from the function declaration
869      start if it doesn't hang.  E.g:
870
871           int foo()
872               throws               // c-lineup-java-throws
873                   Bar              // c-lineup-java-throws
874          
875           <--><--> c-basic-offset
876
877      and
878
879           int foo() throws Cyphr,
880                            Bar,    // c-lineup-java-throws
881                            Vlod    // c-lineup-java-throws
882
883      Works with: `func-decl-cont'.
884
885 `c-indent-one-line-block'
886      Indent a one line block `c-basic-offset' extra.  E.g:
887
888           if (n > 0)
889               {m+=n; n=0;}         // c-indent-one-line-block
890          
891           <--> c-basic-offset
892
893      and
894
895           if (n > 0)
896           {                        // c-indent-one-line-block
897               m+=n; n=0;
898           }
899
900      The block may be surrounded by any kind of parenthesis characters.
901      `nil' is returned if the line doesn't start with a one line block,
902      which makes the function usable in list expressions.
903
904      Works with: Almost all syntactic symbols, but most useful on the
905      `-open' symbols.
906
907 `c-indent-multi-line-block'
908      Indent a multi line block `c-basic-offset' extra.  E.g:
909
910           int *foo[] = {
911               NULL,
912               {17},                // c-indent-multi-line-block
913
914      and
915
916           int *foo[] = {
917               NULL,
918                   {                // c-indent-multi-line-block
919                   17
920                   },
921          
922               <--> c-basic-offset
923
924      The block may be surrounded by any kind of parenthesis characters.
925      `nil' is returned if the line doesn't start with a multi line
926      block, which makes the function usable in list expressions.
927
928      Works with: Almost all syntactic symbols, but most useful on the
929      `-open' symbols.
930
931 `c-lineup-C-comments'
932      Line up C block comment continuation lines.  Various heuristics
933      are used to handle most of the common comment styles.  Some
934      examples:
935
936           /*                 /**               /*
937            * text             * text             text
938            */                 */               */
939          
940           /* text            /*                /**
941              text            ** text            ** text
942           */                 */                 */
943          
944           /**************************************************
945            * text
946            *************************************************/
947          
948           /**************************************************
949               Free form text comments:
950            In comments with a long delimiter line at the
951            start, the indentation is kept unchanged for lines
952            that start with an empty comment line prefix.  The
953            delimiter line is whatever matches the
954            `comment-start-skip' regexp.
955           **************************************************/
956
957
958      The style variable `c-comment-prefix-regexp' is used to recognize
959      the comment line prefix, e.g. the `*' that usually starts every
960      line inside a comment.
961
962      Works with: The `c' syntactic symbol.
963
964 `c-lineup-comment'
965      Line up a comment-only line according to the style variable
966      `c-comment-only-line-offset'.  If the comment is lined up with a
967      comment starter on the previous line, that alignment is preserved.
968
969      `c-comment-only-line-offset' specifies the extra offset for the
970      line.  It can contain an integer or a cons cell of the form
971
972            (<non-anchored-offset> . <anchored-offset>)
973
974      where NON-ANCHORED-OFFSET is the amount of offset given to
975      non-column-zero anchored lines, and ANCHORED-OFFSET is the amount
976      of offset to give column-zero anchored lines.  Just an integer as
977      value is equivalent to `(<value> . -1000)'.
978
979      Works with: `comment-intro'.
980
981 `c-lineup-runin-statements'
982      Line up statements for coding standards which place the first
983      statement in a block on the same line as the block opening
984      brace(1).  E.g:
985
986           int main()
987           { puts (\"Hello world!\");
988             return 0;              // c-lineup-runin-statements
989           }
990
991      If there is no statement after the opening brace to align with,
992      `nil' is returned.  This makes the function usable in list
993      expressions.
994
995      Works with: The `statement' syntactic symbol.
996
997 `c-lineup-math'
998      Line up the current line after the equal sign on the first line in
999      the statement.  If there isn't any, indent with `c-basic-offset'.
1000      If the current line contains an equal sign too, try to align it
1001      with the first one.
1002
1003      Works with: `statement-cont'.
1004
1005 `c-lineup-template-args'
1006      Line up the arguments of a template argument list under each
1007      other, but only in the case where the first argument is on the
1008      same line as the opening `<'.
1009
1010      To allow this function to be used in a list expression, `nil' is
1011      returned if there's no template argument on the first line.
1012
1013      Works with: `template-args-cont'.
1014
1015 `c-lineup-ObjC-method-call'
1016      For Objective-C code, line up selector args as `elisp-mode' does
1017      with function args: go to the position right after the message
1018      receiver, and if you are at the end of the line, indent the
1019      current line c-basic-offset columns from the opening bracket;
1020      otherwise you are looking at the first character of the first
1021      method call argument, so lineup the current line with it.
1022
1023      Works with: `objc-method-call-cont'.
1024
1025 `c-lineup-ObjC-method-args'
1026      For Objective-C code, line up the colons that separate args.  The
1027      colon on the current line is aligned with the one on the first
1028      line.
1029
1030      Works with: `objc-method-args-cont'.
1031
1032 `c-lineup-ObjC-method-args-2'
1033      Similar to `c-lineup-ObjC-method-args' but lines up the colon on
1034      the current line with the colon on the previous line.
1035
1036      Works with: `objc-method-args-cont'.
1037
1038 `c-lineup-inexpr-block'
1039      This can be used with the in-expression block symbols to indent the
1040      whole block to the column where the construct is started.  E.g.
1041      for Java anonymous classes, this lines up the class under the
1042      `new' keyword, and in Pike it lines up the lambda function body
1043      under the `lambda' keyword.  Returns `nil' if the block isn't part
1044      of such a construct.
1045
1046      Works with: `inlambda', `inexpr-statement', `inexpr-class'.
1047
1048 `c-lineup-whitesmith-in-block'
1049      Line up lines inside a block in Whitesmith style.  It's done in a
1050      way that works both when the opening brace hangs and when it
1051      doesn't.  E.g:
1052
1053           something
1054               {
1055               foo;                 // c-lineup-whitesmith-in-block
1056               }
1057
1058      and
1059
1060           something {
1061               foo;                 // c-lineup-whitesmith-in-block
1062               }
1063          
1064           <--> c-basic-offset
1065
1066      In the first case the indentation is kept unchanged, in the second
1067      `c-basic-offset' is added.
1068
1069      Works with: `defun-close', `defun-block-intro', `block-close',
1070      `brace-list-close', `brace-list-intro', `statement-block-intro',
1071      `inclass', `inextern-lang', `innamespace'.
1072
1073 `c-lineup-dont-change'
1074      This lineup function makes the line stay at whatever indentation it
1075      already has; think of it as an identity function for lineups.  It
1076      is used for `cpp-macro-cont' lines.
1077
1078      Works with: Any syntactic symbol.
1079
1080    ---------- Footnotes ----------
1081
1082    (1) Run-in style doesn't really work too well.  You might need to
1083 write your own custom indentation functions to better support this
1084 style.
1085
1086 
1087 File: ccmode,  Node: Performance Issues,  Next: Limitations and Known Bugs,  Prev: Indentation Functions,  Up: Top
1088
1089 Performance Issues
1090 ******************
1091
1092    C and its derivative languages are highly complex creatures.  Often,
1093 ambiguous code situations arise that require CC Mode to scan large
1094 portions of the buffer to determine syntactic context.  Such
1095 pathological code(1) can cause CC Mode to perform fairly badly.  This
1096 section identifies some of the coding styles to watch out for, and
1097 suggests some workarounds that you can use to improve performance.
1098
1099    Because CC Mode has to scan the buffer backwards from the current
1100 insertion point, and because C's syntax is fairly difficult to parse in
1101 the backwards direction, CC Mode often tries to find the nearest
1102 position higher up in the buffer from which to begin a forward scan.
1103 The farther this position is from the current insertion point, the
1104 slower the mode gets.  Some coding styles can even force CC Mode to
1105 scan from the beginning of the buffer for every line of code!
1106
1107    One of the simplest things you can do to reduce scan time, is make
1108 sure any brace that opens a top-level construct(2) always appears in the
1109 leftmost column.  This is actually an Emacs constraint, as embodied in
1110 the `beginning-of-defun' function which CC Mode uses heavily.  If you
1111 insist on hanging top-level open braces on the right side of the line,
1112 then you might want to set the variable `defun-prompt-regexp' to
1113 something reasonable, however that "something reasonable" is difficult
1114 to define, so CC Mode doesn't do it for you.
1115
1116    A special note about `defun-prompt-regexp' in Java mode: while much
1117 of the early sample Java code seems to encourage a style where the brace
1118 that opens a class is hung on the right side of the line, this is not a
1119 good style to pursue in Emacs.  CC Mode comes with a variable
1120 `c-Java-defun-prompt-regexp' which tries to define a regular expression
1121 usable for this style, but there are problems with it.  In some cases
1122 it can cause `beginning-of-defun' to hang(3).  For this reason, it is
1123 not used by default, but if you feel adventurous, you can set
1124 `defun-prompt-regexp' to it in your mode hook.  In any event, setting
1125 and rely on `defun-prompt-regexp' will definitely slow things down
1126 anyway because you'll be doing regular expression searches for every
1127 line you indent, so you're probably screwed either way!
1128
1129    Another alternative for XEmacs users, is to set the variable
1130 `c-enable-xemacs-performance-kludge-p' to non-`nil'.  This tells CC
1131 Mode to use XEmacs-specific built-in functions which,