Sync to HEAD
[bpt/emacs.git] / man / cc-mode.texi
CommitLineData
6bf7aab6
DL
1\input texinfo
2
6b61353c
KH
3@c Notes to self regarding line handling:
4@c
5@c Empty lines are often significant before @end directives; avoid them.
6@c
7@c Empty lines before and after @example directives are significant in
8@c info output but not in TeX. Empty lines inside @example directives
9@c are significant.
10
11@c Conventions for formatting examples:
12@c o If the example contains empty lines then put the surrounding empty
13@c lines inside the @example directives. Put them outside otherwise.
14@c o Use @group inside the example only if it shows indentation where
15@c the relation between lines inside is relevant.
16@c o Format line number columns like this:
17@c 1: foo
18@c 2: bar
19@c ^ one space
20@c ^^ two columns, right alignment
21@c o Check line lengths in TeX output; they can typically be no longer
22@c than 70 chars, 60 if the paragraph is indented.
23
24@comment TBD: Document the finer details of statement anchoring?
25
6bf7aab6
DL
26@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
27@comment %**start of header (This is for running Texinfo on a region)
28@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
29
d7bd46ed
GM
30@comment No overfull hbox marks in the dvi file.
31@finalout
6bf7aab6 32
94cae5a8 33@setfilename ../info/ccmode
cb7f2e96 34@settitle CC Mode Manual
d7bd46ed 35@footnotestyle end
6bf7aab6
DL
36
37@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
38@comment @setchapternewpage odd !! we don't want blank pages !!
39@comment %**end of header (This is for running Texinfo on a region)
40@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
41
42
43@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6b61353c 44@comment
6bf7aab6
DL
45@comment Texinfo manual for CC Mode
46@comment Generated from the original README file by Krishna Padmasola
47@comment <krishna@earth-gw.njit.edu>
cb7f2e96
GM
48@comment
49@comment Authors:
50@comment Barry A. Warsaw
51@comment Martin Stjernholm
52@comment
f214c025 53@comment Maintained by Martin Stjernholm <bug-cc-mode@gnu.org>
6b61353c 54@comment
6bf7aab6
DL
55@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
56
6b61353c
KH
57@comment Define an index for syntactic symbols.
58@defindex ss
59
60@comment Combine key, syntactic symbol and concept indices into one.
61@syncodeindex ss cp
62@syncodeindex ky cp
63
18f952d5
KB
64@copying
65This manual is for CC Mode in Emacs.
cb7f2e96 66
6b61353c
KH
67Copyright @copyright{} 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
682003 Free Software Foundation, Inc.
94cae5a8 69
18f952d5 70@quotation
94cae5a8
GM
71Permission is granted to copy, distribute and/or modify this document
72under the terms of the GNU Free Documentation License, Version 1.1 or
73any later version published by the Free Software Foundation; with the
74Invariant Sections being ``The GNU Manifesto'', ``Distribution'' and
75``GNU GENERAL PUBLIC LICENSE'', with the Front-Cover texts being ``A GNU
76Manual'', and with the Back-Cover Texts as in (a) below. A copy of the
77license is included in the section entitled ``GNU Free Documentation
78License'' in the Emacs manual.
79
80(a) The FSF's Back-Cover Text is: ``You have freedom to copy and modify
81this GNU Manual, like GNU software. Copies published by the Free
82Software Foundation raise funds for GNU development.''
83
84This document is part of a collection distributed under the GNU Free
85Documentation License. If you want to distribute this document
86separately from the collection, you can do so by adding a copy of the
87license to the document, as described in section 6 of the license.
18f952d5
KB
88@end quotation
89@end copying
90
18f952d5
KB
91@comment Info directory entry for use by install-info. The indentation
92@comment here is by request from the FSF folks.
93@dircategory Emacs
94@direntry
6b61353c
KH
95* CC Mode: (ccmode). Emacs mode for editing C, C++, Objective-C,
96 Java, Pike, AWK, and CORBA IDL code.
18f952d5 97@end direntry
6bf7aab6
DL
98
99@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
cb7f2e96 100@comment TeX title page
6bf7aab6
DL
101@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
102
103@titlepage
104@sp 10
105
6b61353c 106@center @titlefont{CC Mode 5.30}
6bf7aab6
DL
107@sp 2
108@center @subtitlefont{A GNU Emacs mode for editing C and C-like languages}
109@sp 2
6b61353c 110@center Barry A. Warsaw, Martin Stjernholm, Alan Mackenzie (AWK support)
6bf7aab6
DL
111
112@page
113@vskip 0pt plus 1filll
18f952d5 114@insertcopying
6bf7aab6
DL
115@end titlepage
116
6bf7aab6
DL
117@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
118@comment The Top node contains the master menu for the Info file.
119@comment This appears only in the Info file, not the printed manual.
120@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
121
d7bd46ed
GM
122@node Top, Introduction, (dir), (dir)
123@comment node-name, next, previous, up
124
125@macro ccmode
126CC Mode
127@end macro
128
129@ifinfo
130@top @ccmode{}
6bf7aab6 131
d7bd46ed 132@ccmode{} is a GNU Emacs mode for editing files containing C, C++,
6b61353c
KH
133Objective-C, Java, CORBA IDL (and the variants PSDL and CIDL), Pike
134code and to a certain extent, AWK code @xref{AWK Mode}. It provides
135syntax-based indentation, font locking, and has several handy commands
136and some minor modes to make the editing easier. It does not provide
137tools to look up and navigate between functions, classes etc - there are
138other packages for that.
d7bd46ed 139@end ifinfo
6bf7aab6
DL
140
141@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
142@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
143
144@menu
d7bd46ed
GM
145* Introduction::
146* Getting Connected::
6b61353c 147* Indentation Engine::
6bf7aab6 148* Minor Modes::
d7bd46ed 149* Text Filling and Line Breaking::
6b61353c
KH
150* Macro Handling::
151* Font Locking::
6bf7aab6
DL
152* Commands::
153* Customizing Indentation::
154* Syntactic Symbols::
d7bd46ed 155* Indentation Functions::
6b61353c
KH
156* AWK Mode::
157* Odds and Ends::
6bf7aab6 158* Performance Issues::
cb7f2e96 159* Limitations and Known Bugs::
6bf7aab6 160* Frequently Asked Questions::
d7bd46ed 161* Getting the Latest CC Mode Release::
d7bd46ed 162* Mailing Lists and Submitting Bug Reports::
cb7f2e96 163* Sample .emacs File::
d7bd46ed
GM
164
165 --- Indices ---
166
6b61353c 167* Command and Function Index::
d7bd46ed 168* Variable Index::
6b61353c 169* Concept Index::
d7bd46ed 170
6b61353c 171@detailmenu
d7bd46ed
GM
172 --- The Detailed Node Listing ---
173
6b61353c 174Indentation Engine
d7bd46ed
GM
175
176* Syntactic Analysis::
177* Indentation Calculation::
178
179Minor Modes
180
181* Auto-newline Insertion::
182* Hungry-deletion of Whitespace::
183
6b61353c
KH
184Font Locking
185
186* Font Locking Preliminaries::
187* Faces::
188* Documentation Comments::
189
d7bd46ed
GM
190Auto-newline Insertion
191
192* Hanging Braces::
193* Hanging Colons::
6b61353c 194* Hanging Semicolons and Commas::
d7bd46ed
GM
195* Other Electric Commands::
196* Clean-ups::
197
198Commands
199
200* Indentation Commands::
201* Movement Commands::
202* Other Commands::
203
204Customizing Indentation
205
206* Interactive Customization::
207* Permanent Customization::
208* Hooks::
209* Styles::
210* Advanced Customizations::
211
212Styles
213
214* Built-in Styles::
6b61353c 215* Choosing a Style::
d7bd46ed
GM
216* Adding Styles::
217* File Styles::
218
219Advanced Customizations
220
221* Custom Indentation Functions::
222* Custom Brace and Colon Hanging::
6b61353c 223* Customizing Semicolons and Commas::
d7bd46ed 224* Other Special Indentations::
6b61353c
KH
225
226AWK Mode
227
228* Initialising AWK Mode::
229* AWK Mode Font Locking::
230* AWK Mode Defuns::
231@end detailmenu
6bf7aab6
DL
232@end menu
233
d7bd46ed 234
6bf7aab6 235@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
d7bd46ed
GM
236@node Introduction, Getting Connected, Top, Top
237@comment node-name, next, previous, up
6b61353c 238@chapter Introduction
6bf7aab6
DL
239@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
240
6bf7aab6
DL
241@cindex BOCM
242
d7bd46ed 243Welcome to @ccmode{}, a GNU Emacs mode for editing files containing C,
6b61353c
KH
244C++, Objective-C, Java, CORBA IDL (and the variants CORBA PSDL and
245CIDL), Pike and to a certain extent, AWK code (@pxref{AWK Mode}). This
246incarnation of the mode is descended from @file{c-mode.el} (also called
247``Boring Old C Mode'' or BOCM @t{:-)}, and @file{c++-mode.el} version 2,
248which Barry has been maintaining since 1992. Late in 1997, Martin
d7bd46ed 249joined the @ccmode{} Maintainers Team, and implemented the Pike support.
6b61353c
KH
250As of 2000 Martin has taken over as the sole maintainer. @ccmode{} did
251not originally contain the font lock support for its languages --- that
252was added in version 5.30. AWK support was also added in 5.30 by Alan
253Mackenzie.
d7bd46ed
GM
254
255This manual describes @ccmode{}
256@comment The following line must appear on its own, so that the automated
6b61353c 257version 5.30.
d7bd46ed 258@comment Release.py script can update the version number automatically
6bf7aab6 259
6b61353c
KH
260@ccmode{} supports the editing of K&R and ANSI C, C++, Objective-C,
261Java, CORBA's Interface Definition Language, Pike@footnote{A C-like
262scripting language with its roots in the LPC language used in some MUD
263engines. See @uref{http://pike.ida.liu.se/}.} and AWK files. In this
264way, you can easily set up consistent font locking and coding styles for
265use in editing all of these languages, although AWK is not yet as
266uniformly integrated as the other languages.
6bf7aab6
DL
267
268@findex c-mode
269@findex c++-mode
270@findex objc-mode
271@findex java-mode
272@findex idl-mode
d7bd46ed 273@findex pike-mode
6b61353c 274@findex awk-mode
94cae5a8 275Note that the name of this package is ``@ccmode{},'' but there is no top
6bf7aab6 276level @code{cc-mode} entry point. All of the variables, commands, and
6b61353c 277functions in @ccmode{} are prefixed with @code{c-@var{thing}}, and
d7bd46ed 278@code{c-mode}, @code{c++-mode}, @code{objc-mode}, @code{java-mode},
6b61353c
KH
279@code{idl-mode}, @code{pike-mode}, and @code{awk-mode} entry points are
280provided. This package is intended to be a replacement for
281@file{c-mode.el}, @file{c++-mode.el} and @file{awk-mode.el}.
282
283@c @cindex @file{cc-compat.el} file
284@c This distribution also contains a file
285@c called @file{cc-compat.el} which should ease your transition from BOCM
286@c to @ccmode{}. If you have a BOCM configuration you are really happy
287@c with, and want to postpone learning how to configure @ccmode{}, take a
288@c look at that file. It maps BOCM configuration variables to @ccmode{}'s
289@c indentation model. It is not actively supported so for the long run,
290@c you should learn how to customize @ccmode{} to support your coding
291@c style.
6bf7aab6
DL
292
293A special word of thanks goes to Krishna Padmasola for his work in
294converting the original @file{README} file to Texinfo format. I'd also
295like to thank all the @ccmode{} victims who help enormously during the
296early beta stages of @ccmode{}'s development.
297
298
299@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6b61353c 300@node Getting Connected, Indentation Engine, Introduction, Top
d7bd46ed 301@comment node-name, next, previous, up
6b61353c 302@chapter Getting Connected
6bf7aab6
DL
303@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
304
305If you got this version of @ccmode{} with Emacs or XEmacs, it should
306work just fine right out of the box. Note however that you may not have
307the latest @ccmode{} release and may want to upgrade your copy.
308
309If you are upgrading an existing @ccmode{} installation, please see the
310@file{README} file for installation details. @ccmode{} may not work
311with older versions of Emacs or XEmacs. See the @ccmode{} release notes
6b61353c
KH
312at @uref{http://cc-mode.sourceforge.net} for the latest information on
313Emacs version and package compatibility (@pxref{Getting the Latest CC
314Mode Release}).
6bf7aab6 315
6b61353c 316@deffn Command c-version
6bf7aab6
DL
317@findex version (c-)
318You can find out what version of @ccmode{} you are using by visiting a C
319file and entering @kbd{M-x c-version RET}. You should see this message in
320the echo area:
6bf7aab6 321
6b61353c 322@example
6bf7aab6 323Using CC Mode version 5.XX
6bf7aab6
DL
324@end example
325
326@noindent
327where @samp{XX} is the minor release number.
6b61353c 328@end deffn
6bf7aab6
DL
329
330
331@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6b61353c 332@node Indentation Engine, Minor Modes, Getting Connected, Top
d7bd46ed 333@comment node-name, next, previous, up
6b61353c 334@chapter Indentation Engine
6bf7aab6
DL
335@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
336
6b61353c
KH
337@ccmode{} has an indentation engine that provides a flexible and general
338mechanism for customizing indentation. It separates indentation
339calculation into two steps: first, @ccmode{} analyzes the line of code
340being indented to determine the kind of language construct it's looking
341at, then it applies user defined offsets to the current line based on
342this analysis.
6bf7aab6
DL
343
344This section will briefly cover how indentation is calculated in
6b61353c
KH
345@ccmode{}. It is important to understand the indentation model being
346used so that you will know how to customize @ccmode{} for your personal
347coding style. All the details are in @ref{Customizing Indentation}, and
348later chapters.
349
350@defopt c-syntactic-indentation
351@vindex syntactic-indentation (c-)
352Syntactic analysis for indentation is done when this is non-@code{nil}
353(which is the default). When it's @code{nil} every line is just
354indented to the same level as the previous one, and @kbd{TAB}
355(@code{c-indent-command}) adjusts the indentation in steps of
356@code{c-basic-offset}. The indentation style has no effect, nor any of
357the indentation associated variables, e.g. @code{c-special-indent-hook}.
358@end defopt
6bf7aab6
DL
359
360@menu
361* Syntactic Analysis::
362* Indentation Calculation::
363@end menu
364
365
366@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6b61353c 367@node Syntactic Analysis, Indentation Calculation, , Indentation Engine
d7bd46ed 368@comment node-name, next, previous, up
6b61353c 369@section Syntactic Analysis
d7bd46ed 370@cindex syntactic analysis
6bf7aab6
DL
371@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
372
6bf7aab6 373@cindex relative buffer position
6b61353c 374@cindex syntactic symbols
6bf7aab6
DL
375@cindex syntactic component
376@cindex syntactic component list
6bf7aab6
DL
377The first thing @ccmode{} does when indenting a line of code, is to
378analyze the line, determining the @dfn{syntactic component list} of the
d7bd46ed 379construct on that line. A syntactic component consists of a pair of
6b61353c
KH
380elements (in lisp parlance, a @emph{cons cell}), the first being
381a @dfn{syntactic symbol}, the second being a @dfn{relative
6bf7aab6 382buffer position}. Syntactic symbols describe elements of C code
6b61353c 383@footnote{Unless otherwise noted, the term ``C code'' refers to all
d7bd46ed
GM
384the C-like languages.}, e.g. @code{statement}, @code{substatement},
385@code{class-open}, @code{class-close}, etc. @xref{Syntactic Symbols},
386for a complete list of currently recognized syntactic symbols and their
387semantics. The style variable @code{c-offsets-alist} also contains the
388list of currently supported syntactic symbols.
6bf7aab6
DL
389
390Conceptually, a line of C code is always indented relative to the
391indentation of some line higher up in the buffer. This is represented
392by the relative buffer position in the syntactic component.
393
394Here is an example. Suppose we had the following code as the only thing
d7bd46ed
GM
395in a C++ buffer @footnote{The line numbers in this and future examples
396don't actually appear in the buffer, of course!}:
6bf7aab6 397
6b61353c
KH
398@example
399 1: void swap( int& a, int& b )
400 2: @{
401 3: int tmp = a;
402 4: a = b;
403 5: b = tmp;
404 6: @}
6bf7aab6
DL
405@end example
406
407@kindex C-c C-s
408@findex c-show-syntactic-information
409@findex show-syntactic-information (c-)
6b61353c
KH
410We can use the command @kbd{C-c C-s} (bound to
411@code{c-show-syntactic-information}) to simply report what the
6bf7aab6 412syntactic analysis is for the current line. Running this command on
6b61353c
KH
413line 4 of this example, we'd see in the echo area@footnote{With a
414universal argument (i.e. @kbd{C-u C-c C-s}) the analysis is inserted
415into the buffer as a comment on the current line.}:
6bf7aab6 416
6b61353c
KH
417@example
418((statement 35))
6bf7aab6
DL
419@end example
420
421This tells us that the line is a statement and it is indented relative
422to buffer position 35, which happens to be the @samp{i} in @code{int} on
423line 3. If you were to move point to line 3 and hit @kbd{C-c C-s}, you
424would see:
6bf7aab6 425
6b61353c
KH
426@example
427((defun-block-intro 29))
6bf7aab6
DL
428@end example
429
430This indicates that the @samp{int} line is the first statement in a top
431level function block, and is indented relative to buffer position 29,
432which is the brace just after the function header.
433
434Here's another example:
6bf7aab6 435
6b61353c
KH
436@example
437 1: int add( int val, int incr, int doit )
438 2: @{
439 3: if( doit )
440 4: @{
441 5: return( val + incr );
442 6: @}
443 7: return( val );
444 8: @}
6bf7aab6
DL
445@end example
446
447@noindent
448Hitting @kbd{C-c C-s} on line 4 gives us:
6bf7aab6 449
6b61353c
KH
450@example
451((substatement-open 46))
6bf7aab6
DL
452@end example
453
454@cindex substatement
d7bd46ed 455@cindex substatement block
6bf7aab6
DL
456@noindent
457which tells us that this is a brace that @emph{opens} a substatement
458block. @footnote{A @dfn{substatement} is the line after a
459conditional statement, such as @code{if}, @code{else}, @code{while},
460@code{do}, @code{switch}, etc. A @dfn{substatement
461block} is a brace block following one of these conditional statements.}
462
463@cindex comment-only line
464Syntactic component lists can contain more than one component, and
465individual syntactic components need not have relative buffer positions.
466The most common example of this is a line that contains a @dfn{comment
467only line}.
6bf7aab6 468
6b61353c
KH
469@example
470 1: void draw_list( List<Drawables>& drawables )
471 2: @{
472 3: // call the virtual draw() method on each element in list
473 4: for( int i=0; i < drawables.count(), ++i )
474 5: @{
475 6: drawables[i].draw();
476 7: @}
477 8: @}
6bf7aab6
DL
478@end example
479
480@noindent
481Hitting @kbd{C-c C-s} on line 3 of this example gives:
6bf7aab6 482
6b61353c
KH
483@example
484((comment-intro) (defun-block-intro 46))
6bf7aab6
DL
485@end example
486
487@noindent
488and you can see that the syntactic component list contains two syntactic
489components. Also notice that the first component,
490@samp{(comment-intro)} has no relative buffer position.
491
492
493@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6b61353c 494@node Indentation Calculation, , Syntactic Analysis, Indentation Engine
d7bd46ed 495@comment node-name, next, previous, up
6b61353c
KH
496@section Indentation Calculation
497@cindex indentation
6bf7aab6
DL
498@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
499
6bf7aab6 500Indentation for a line is calculated using the syntactic
d7bd46ed 501component list derived in step 1 above (@pxref{Syntactic Analysis}).
6bf7aab6
DL
502Each component contributes to the final total indentation of the line in
503two ways.
504
505First, the syntactic symbols are looked up in the @code{c-offsets-alist}
d7bd46ed
GM
506style variable, which is an association list of syntactic symbols and
507the offsets to apply for those symbols. These offsets are added to a
6bf7aab6
DL
508running total.
509
510Second, if the component has a relative buffer position, @ccmode{}
511adds the column number of that position to the running total. By adding
512up the offsets and columns for every syntactic component on the list,
513the final total indentation for the current line is computed.
514
515Let's use our two code examples above to see how this works. Here is
516our first example again:
6bf7aab6 517
6b61353c
KH
518@example
519 1: void swap( int& a, int& b )
520 2: @{
521 3: int tmp = a;
522 4: a = b;
523 5: b = tmp;
524 6: @}
6bf7aab6
DL
525@end example
526
6b61353c 527Let's say point is on line 3 and we hit the @kbd{TAB} key to reindent
6bf7aab6
DL
528the line. Remember that the syntactic component list for that
529line is:
6bf7aab6 530
6b61353c
KH
531@example
532((defun-block-intro 29))
6bf7aab6
DL
533@end example
534
535@noindent
536@ccmode{} looks up @code{defun-block-intro} in the
d7bd46ed
GM
537@code{c-offsets-alist} style variable. Let's say it finds the value
538@samp{4}; it adds this to the running total (initialized to zero),
539yielding a running total indentation of 4 spaces.
6bf7aab6
DL
540
541Next @ccmode{} goes to buffer position 29 and asks for the current
542column. This brace is in column zero, so @ccmode{}
543adds @samp{0} to the running total. Since there is only one syntactic
544component on the list for this line, indentation calculation is
545complete, and the total indentation for the line
546is 4 spaces.
547
548Here's another example:
6bf7aab6 549
6b61353c
KH
550@example
551 1: int add( int val, int incr, int doit )
552 2: @{
553 3: if( doit )
554 4: @{
555 5: return( val + incr );
556 6: @}
557 7: return( val );
558 8: @}
6bf7aab6
DL
559@end example
560
561If we were to hit @kbd{TAB} on line 4 in the above example, the same
562basic process is performed, despite the differences in the syntactic
563component list. Remember that the list for this line is:
6bf7aab6 564
6b61353c
KH
565@example
566((substatement-open 46))
6bf7aab6
DL
567@end example
568
569Here, @ccmode{} first looks up the @code{substatement-open} symbol
570in @code{c-offsets-alist}. Let's say it finds the value @samp{4}. This
571yields a running total of 4. @ccmode{} then goes to
572buffer position 46, which is the @samp{i} in @code{if} on line 3. This
573character is in the fourth column on that line so adding this to the
574running total yields an indentation for the line of 8 spaces.
575
576Simple, huh?
577
578Actually, the mode usually just does The Right Thing without you having
579to think about it in this much detail. But when customizing
580indentation, it's helpful to understand the general indentation model
581being used.
582
6bf7aab6
DL
583As you configure @ccmode{}, you might want to set the variable
584@code{c-echo-syntactic-information-p} to non-@code{nil} so that the
585syntactic component list and calculated offset will always be echoed in
586the minibuffer when you hit @kbd{TAB}.
587
588
589@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6b61353c 590@node Minor Modes, Text Filling and Line Breaking, Indentation Engine, Top
d7bd46ed 591@comment node-name, next, previous, up
6b61353c 592@chapter Minor Modes
6bf7aab6
DL
593@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
594
595@ccmode{} contains two minor-mode-like features that you should
6b61353c 596find useful while entering new C code. The first is called
6bf7aab6
DL
597@dfn{auto-newline} mode, and the second is called @dfn{hungry-delete}
598mode. These minor modes can be toggled on and off independently, and
599@ccmode{} can be configured so that it starts up with any
600combination of these minor modes. By default, both of these minor modes
601are turned off.
602
603The state of the minor modes is always reflected in the minor mode list
604on the modeline of the @ccmode{} buffer. When auto-newline mode is
6b61353c
KH
605enabled, you will see @samp{C/a} on the mode line@footnote{The @samp{C}
606would be replaced with the name of the language in question for the
607other languages @ccmode{} supports.}. When hungry delete mode is
608enabled you will see @samp{C/h} and if both modes were enabled, you'd
609see @samp{C/ah}.
6bf7aab6
DL
610
611@kindex C-c C-a
612@kindex C-c C-d
613@kindex C-c C-t
614@findex c-toggle-hungry-state
615@findex c-toggle-auto-state
616@findex c-toggle-auto-hungry-state
617@findex toggle-hungry-state (c-)
618@findex toggle-auto-state (c-)
619@findex toggle-auto-hungry-state (c-)
47d7776c 620@ccmode{} provides key bindings which allow you to toggle the minor
6bf7aab6 621modes on the fly while editing code. To toggle just the auto-newline
6b61353c
KH
622state, hit @kbd{C-c C-a} (bound to @code{c-toggle-auto-state}). When
623you do this, you should see the @samp{a} indicator either appear or
624disappear on the modeline. Similarly, to toggle just the
625hungry-delete state, use @kbd{C-c C-d} (@code{c-toggle-hungry-state}),
626and to toggle both states, use @kbd{C-c C-t}
627(@code{c-toggle-auto-hungry-state}).
6bf7aab6
DL
628
629To set up the auto-newline and hungry-delete states to your preferred
630values, you would need to add some lisp to your @file{.emacs} file that
631called one of the @code{c-toggle-*-state} functions directly. When
632called programmatically, each function takes a numeric value, where
633a positive number enables the minor mode, a negative number disables the
634mode, and zero toggles the current state of the mode.
635
636So for example, if you wanted to enable both auto-newline and
637hungry-delete for all your C file editing, you could add the following
638to your @file{.emacs} file:
6bf7aab6 639
6b61353c 640@example
6bf7aab6 641(add-hook 'c-mode-common-hook
6b61353c 642 (lambda () (c-toggle-auto-hungry-state 1)))
6bf7aab6
DL
643@end example
644
6bf7aab6 645@menu
d7bd46ed
GM
646* Auto-newline Insertion::
647* Hungry-deletion of Whitespace::
6bf7aab6
DL
648@end menu
649
6bf7aab6 650
d7bd46ed
GM
651@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
652@node Auto-newline Insertion, Hungry-deletion of Whitespace, , Minor Modes
653@comment node-name, next, previous, up
6b61353c
KH
654@section Auto-newline Insertion
655@cindex auto-newline
6bf7aab6
DL
656@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
657
6b61353c 658@cindex electric characters
6bf7aab6 659Auto-newline minor mode works by enabling certain @dfn{electric
6b61353c
KH
660characters}. Special characters such as the left and right braces,
661colons, semicolons, etc., have been made electric to perform some
662magic formatting in addition to inserting the typed character. As a
663general rule, electric characters are only electric when the following
664conditions apply:
6bf7aab6
DL
665
666@itemize @bullet
667@item
668Auto-newline minor mode is enabled, as evidenced by a @samp{C/a} or
669@samp{C/ah} indicator on the modeline.
670
6b61353c 671@item
6bf7aab6
DL
672@cindex literal
673@cindex syntactic whitespace
6bf7aab6 674The character was not typed inside of a literal @footnote{A
6b61353c 675@dfn{literal} is defined as any comment, string, or preprocessor macro
6bf7aab6
DL
676definition. These constructs are also known as @dfn{syntactic
677whitespace} since they are usually ignored when scanning C code.}.
678
679@item
6bf7aab6
DL
680No numeric argument was supplied to the command (i.e. it was typed as
681normal, with no @kbd{C-u} prefix).
6bf7aab6
DL
682@end itemize
683
684@menu
685* Hanging Braces::
686* Hanging Colons::
6b61353c 687* Hanging Semicolons and Commas::
d7bd46ed 688* Other Electric Commands::
6bf7aab6
DL
689* Clean-ups::
690@end menu
691
6bf7aab6 692
d7bd46ed
GM
693@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
694@node Hanging Braces, Hanging Colons, , Auto-newline Insertion
695@comment node-name, next, previous, up
696@subsection Hanging Braces
697@cindex hanging braces
6bf7aab6
DL
698@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
699
700@findex c-electric-brace
701@findex electric-brace (c-)
6b61353c
KH
702@kindex @{
703@kindex @}
704
6bf7aab6
DL
705When you type either an open or close brace (i.e. @kbd{@{} or @kbd{@}}),
706the electric command @code{c-electric-brace} gets run. This command has
707two electric formatting behaviors. First, it will perform some
6b61353c 708reindentation of the line the brace was typed on, and second, it will
6bf7aab6 709add various newlines before and/or after the typed brace.
6b61353c 710Reindentation occurs automatically whenever the electric behavior is
6bf7aab6 711enabled. If the brace ends up on a line other than the one it was typed
6b61353c 712on, then that line is also reindented.
d7bd46ed
GM
713
714The default in auto-newline mode is to insert newlines both before and
715after a brace, but that can be controlled by the
6b61353c
KH
716@code{c-hanging-braces-alist} style variable.
717
718@defopt c-hanging-braces-alist
719@vindex hanging-braces-alist (c-)
720
721This variable contains a mapping between syntactic symbols related to
722braces, and a list of places to insert a newline. The syntactic symbols
723that are useful for this list are @code{brace-list-intro},
724@code{statement-cont}, @code{inexpr-class-open},
725@code{inexpr-class-close}, and all the @code{*-open} and @code{*-close}
726symbols. @xref{Syntactic Symbols}, for a more detailed description of
727these syntactic symbols, except for @code{inexpr-class-open} and
728@code{inexpr-class-close}, which aren't actual syntactic symbols.
d7bd46ed
GM
729
730The braces of anonymous inner classes in Java are given the special
731symbols @code{inexpr-class-open} and @code{inexpr-class-close}, so that
732they can be distinguished from the braces of normal classes@footnote{The
6b61353c 733braces of anonymous classes produce a combination of
d7bd46ed
GM
734@code{inexpr-class}, and @code{class-open} or @code{class-close} in
735normal indentation analysis.}.
736
6b61353c
KH
737Note that the aggregate constructs in Pike mode, @samp{(@{}, @samp{@})},
738@samp{([}, @samp{])}, and @samp{(<}, @samp{>)}, do not count as brace
739lists in this regard, even though they do for normal indentation
740purposes. It's currently not possible to set automatic newlines on
741these constructs.
742
6bf7aab6 743The value associated with each syntactic symbol in this association list
6b61353c 744is called an @var{action}, which can be either a function or a list.
393759c7 745@xref{Custom Brace and Colon Hanging}, for a more detailed discussion of
6b61353c 746using a function as a brace hanging @var{action}.
6bf7aab6 747
6b61353c 748When the @var{action} is a list, it can contain any combination of the
6bf7aab6
DL
749symbols @code{before} and @code{after}, directing @ccmode{} where to
750put newlines in relationship to the brace being inserted. Thus, if the
751list contains only the symbol @code{after}, then the brace is said to
752@dfn{hang} on the right side of the line, as in:
6bf7aab6 753
6b61353c 754@example
6bf7aab6
DL
755// here, open braces always `hang'
756void spam( int i ) @{
757 if( i == 7 ) @{
758 dosomething(i);
759 @}
760@}
6bf7aab6
DL
761@end example
762
763When the list contains both @code{after} and @code{before}, the braces
764will appear on a line by themselves, as shown by the close braces in the
765above example. The list can also be empty, in which case no newlines
766are added either before or after the brace.
767
d7bd46ed
GM
768If a syntactic symbol is missing entirely from
769@code{c-hanging-braces-alist}, it's treated in the same way as an
6b61353c 770@var{action} with a list containing @code{before} and @code{after}, so
d7bd46ed
GM
771that braces by default end up on their own line.
772
6bf7aab6 773For example, the default value of @code{c-hanging-braces-alist} is:
6bf7aab6 774
6b61353c
KH
775@example
776((brace-list-open)
777 (brace-entry-open)
778 (statement-cont)
779 (substatement-open after)
780 (block-close . c-snug-do-while)
781 (extern-lang-open after)
782 (inexpr-class-open after)
783 (inexpr-class-close before))
6bf7aab6
DL
784@end example
785
6b61353c
KH
786@noindent which says that @code{brace-list-open},
787@code{brace-entry-open} and @code{statement-cont}@footnote{Brace lists
788inside statements, such as initializers for static array variables
789inside functions in C, are recognized as @code{statement-cont}. All
790normal substatement blocks are recognized with other symbols.} braces
791should both hang on the right side and allow subsequent text to follow
792on the same line as the brace. Also, @code{substatement-open},
793@code{extern-lang-open}, and @code{inexpr-class-open} braces should hang
794on the right side, but subsequent text should follow on the next line.
795The opposite holds for @code{inexpr-class-close} braces; they won't
796hang, but the following text continues on the same line. Here, in the
797@code{block-close} entry, you also see an example of using a function as
798an @var{action}. In all other cases, braces are put on a line by
799themselves.
800@end defopt
6bf7aab6
DL
801
802
803@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6b61353c 804@node Hanging Colons, Hanging Semicolons and Commas, Hanging Braces, Auto-newline Insertion
d7bd46ed
GM
805@comment node-name, next, previous, up
806@subsection Hanging Colons
807@cindex hanging colons
6bf7aab6
DL
808@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
809
d7bd46ed
GM
810Using a mechanism similar to brace hanging (@pxref{Hanging Braces}),
811colons can also be made to hang using the style variable
6b61353c
KH
812@code{c-hanging-colons-alist}.
813
814@defopt c-hanging-colons-alist
815@vindex hanging-colons-alist (c-)
816
817The syntactic symbols appropriate for this association list are:
818@code{case-label}, @code{label}, @code{access-label},
819@code{member-init-intro}, and @code{inher-intro}. Note however that for
820@code{c-hanging-colons-alist}, @var{action}s as functions are not
821supported. See also @ref{Custom Brace and Colon Hanging} for details.
6bf7aab6 822
6bf7aab6
DL
823In C++, double-colons are used as a scope operator but because these
824colons always appear right next to each other, newlines before and after
825them are controlled by a different mechanism, called @dfn{clean-ups} in
393759c7 826@ccmode{}. @xref{Clean-ups}, for details.
6b61353c 827@end defopt
6bf7aab6
DL
828
829
830@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6b61353c 831@node Hanging Semicolons and Commas, Other Electric Commands, Hanging Colons, Auto-newline Insertion
d7bd46ed 832@comment node-name, next, previous, up
6b61353c
KH
833@subsection Hanging Semicolons and Commas
834@cindex hanging semicolons
d7bd46ed 835@cindex hanging commas
6bf7aab6
DL
836@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
837
838Semicolons and commas are also electric in @ccmode{}, but since
839these characters do not correspond directly to syntactic symbols, a
840different mechanism is used to determine whether newlines should be
841automatically inserted after these characters. @xref{Customizing
6b61353c 842Semicolons and Commas}, for details.
6bf7aab6
DL
843
844
845@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6b61353c 846@node Other Electric Commands, Clean-ups, Hanging Semicolons and Commas, Auto-newline Insertion
d7bd46ed
GM
847@comment node-name, next, previous, up
848@subsection Other Electric Commands
6bf7aab6
DL
849@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
850
6b61353c
KH
851A few other keys also provide electric behavior, often only to reindent
852the line. Common to all of them is that they only reindent if used in
853normal code (as opposed to in a string literal or comment), and
854@code{c-syntactic-indentation} isn't @code{nil}. They are:
855
856@table @kbd
857@item #
6bf7aab6
DL
858@kindex #
859@findex c-electric-pound
6bf7aab6 860@findex electric-pound (c-)
6b61353c 861@vindex c-electric-pound-behavior
6bf7aab6 862@vindex electric-pound-behavior (c-)
6b61353c
KH
863Pound (bound to @code{c-electric-pound}) is electric when typed as the
864first non-whitespace character on a line and not within a macro
865definition. In this case, the variable @code{c-electric-pound-behavior}
866is consulted for the electric behavior. This variable takes a list
867value, although the only element currently defined is @code{alignleft},
868which tells this command to force the @samp{#} character into column
869zero. This is useful for entering preprocessor macro definitions.
870
871Pound is not electric in AWK buffers, where @samp{#} starts a comment,
872and is bound to @code{self-insert-command} like any typical printable
873character.
6bf7aab6 874
6b61353c
KH
875@item *
876@kindex *
877@itemx /
878@kindex /
6bf7aab6 879@findex c-electric-star
6bf7aab6 880@findex electric-star (c-)
6b61353c 881@findex c-electric-slash
6bf7aab6 882@findex electric-slash (c-)
6b61353c
KH
883Stars and slashes (bound to @code{c-electric-star} and
884@code{c-electric-slash} respectively) are also electric under certain
885circumstances. If a @samp{*} is inserted as the second character of a C
886style block comment on a comment-only line, then the comment delimiter
887is indented as defined by @code{c-offsets-alist}. A comment-only line
888is defined as a line which contains only a comment, as in:
889
6bf7aab6
DL
890@example
891@group
177c0ea7 892void spam( int i )
6bf7aab6 893@{
6b61353c
KH
894 // this is a comment-only line...
895 if( i == 7 ) // but this is not
6bf7aab6
DL
896 @{
897 dosomething(i);
898 @}
899@}
6bf7aab6
DL
900@end group
901@end example
902
6b61353c
KH
903Likewise, if a @samp{/} is inserted as the second slash in a C++ style
904line comment (also only on a comment-only line), then the line is
905indented as defined by @code{c-offsets-alist}.
6bf7aab6 906
6b61353c
KH
907In AWK mode, @samp{*} and @samp{/} do not delimit comments and are
908bound to @code{self-insert-command}.
909
910@item <
6bf7aab6 911@kindex <
6b61353c 912@itemx >
6bf7aab6 913@kindex >
6b61353c
KH
914@findex c-electric-lt-gt
915@findex electric-lt-gt (c-)
916Less-than and greater-than signs (bound to @code{c-electric-lt-gt}) are
6bf7aab6 917electric, but only in C++ mode. Hitting the second of two @kbd{<} or
6b61353c 918@kbd{>} keys reindents the line if it is a C++ style stream operator.
6bf7aab6 919
6b61353c 920@item (
d7bd46ed 921@kindex (
6b61353c 922@itemx )
d7bd46ed 923@kindex )
6b61353c
KH
924@findex c-electric-paren
925@findex electric-paren (c-)
926The normal parenthesis characters @samp{(} and @samp{)} reindent the
927current line. This is useful for getting the closing parenthesis of an
928argument list aligned automatically.
929@end table
930
931@deffn Command c-electric-continued-statement
932@findex electric-continued-statement (c-)
933
934Certain keywords, depending on language, are electric to cause
935reindentation when they are preceded only by whitespace on the line.
936The keywords are those that continue an earlier statement instead of
937starting a new one: @code{else}, @code{while}, @code{catch} (only in C++
938and Java) and @code{finally} (only in Java).
939
940An example:
941
942@example
943@group
944for (i = 0; i < 17; i++)
945 if (a[i])
946 res += a[i]->offset;
947else
948@end group
949@end example
950
951Here, the @code{else} should be indented like the preceding @code{if},
952since it continues that statement. @ccmode{} will automatically reindent
953it after the @code{else} has been typed in full, since it's not until
954then it's possible to decide whether it's a new statement or a
955continuation of the preceding @code{if}.
956
957@vindex abbrev-mode
958@findex abbrev-mode
959@cindex Abbrev mode
960@ccmode{} uses Abbrev mode (@pxref{Abbrevs,,, emacs, The Emacs Editor})
961to accomplish this. It's therefore turned on by default in all language
962modes except IDL mode, since CORBA IDL doesn't have any statements.
963@end deffn
6bf7aab6 964
6bf7aab6 965
d7bd46ed
GM
966@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
967@node Clean-ups, , Other Electric Commands, Auto-newline Insertion
968@comment node-name, next, previous, up
969@subsection Clean-ups
970@cindex clean-ups
6bf7aab6
DL
971@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
972
cb7f2e96
GM
973@dfn{Clean-ups} are mechanisms complementary to colon and brace hanging.
974On the surface, it would seem that clean-ups overlap the functionality
975provided by the @code{c-hanging-*-alist} variables. Clean-ups are
94cae5a8 976however used to adjust code ``after-the-fact,'' i.e. to adjust the
cb7f2e96
GM
977whitespace in constructs after they are typed.
978
979Most of the clean-ups are only applicable to counteract automatically
980inserted newlines, and will therefore only have any effect if the
981auto-newline minor mode is turned on. Others will work all the time.
6bf7aab6 982
6b61353c 983@defopt c-cleanup-list
d7bd46ed 984@vindex cleanup-list (c-)
6bf7aab6 985@cindex literal
6b61353c 986
d7bd46ed 987You can configure @ccmode{}'s clean-ups by setting the style variable
6bf7aab6 988@code{c-cleanup-list}, which is a list of clean-up symbols. By default,
d7bd46ed
GM
989@ccmode{} cleans up only the @code{scope-operator} construct, which is
990necessary for proper C++ support. Note that clean-ups are only
991performed when the construct does not occur within a literal
992(@pxref{Auto-newline Insertion}), and when there is nothing but
993whitespace appearing between the individual components of the construct.
6b61353c 994@end defopt
6bf7aab6 995
6b61353c 996These are the clean-ups that are only active in the auto-newline minor
cb7f2e96 997mode:
6bf7aab6 998
6b61353c
KH
999@c TBD: Would like to use some sort of @deffoo here; @table indents a
1000@c bit too much in dvi output.
1001@table @code
1002@item brace-else-brace
1003Clean up @samp{@} else @{} constructs by placing the entire construct on
1004a single line. Clean-up occurs when the open brace after the
1005@samp{else} is typed. So for example, this:
1006
6bf7aab6
DL
1007@example
1008@group
6bf7aab6
DL
1009void spam(int i)
1010@{
6b61353c 1011 if( i==7 ) @{
6bf7aab6
DL
1012 dosomething();
1013 @}
1014 else
1015 @{
6bf7aab6
DL
1016@end group
1017@end example
6b61353c 1018
6bf7aab6 1019@noindent
6b61353c
KH
1020appears like this after the last open brace is typed:
1021
6bf7aab6
DL
1022@example
1023@group
6bf7aab6
DL
1024void spam(int i)
1025@{
1026 if( i==7 ) @{
1027 dosomething();
1028 @} else @{
6bf7aab6
DL
1029@end group
1030@end example
1031
6b61353c
KH
1032@item brace-elseif-brace
1033Similar to the @code{brace-else-brace} clean-up, but this cleans up
1034@samp{@} else if (...) @{} constructs. For example:
1035
6bf7aab6
DL
1036@example
1037@group
6bf7aab6
DL
1038void spam(int i)
1039@{
6b61353c 1040 if( i==7 ) @{
6bf7aab6
DL
1041 dosomething();
1042 @}
d7bd46ed
GM
1043 else if( i==3 )
1044 @{
6bf7aab6
DL
1045@end group
1046@end example
6b61353c 1047
6bf7aab6 1048@noindent
6b61353c
KH
1049appears like this after the last open parenthesis is typed:
1050
d7bd46ed
GM
1051@example
1052@group
d7bd46ed
GM
1053void spam(int i)
1054@{
1055 if( i==7 ) @{
1056 dosomething();
1057 @} else if( i==3 )
1058 @{
d7bd46ed
GM
1059@end group
1060@end example
6b61353c 1061
d7bd46ed 1062@noindent
6b61353c
KH
1063and like this after the last open brace is typed:
1064
6bf7aab6
DL
1065@example
1066@group
6bf7aab6
DL
1067void spam(int i)
1068@{
1069 if( i==7 ) @{
1070 dosomething();
1071 @} else if( i==3 ) @{
6bf7aab6
DL
1072@end group
1073@end example
1074
6b61353c
KH
1075@item brace-catch-brace
1076Analogous to @code{brace-elseif-brace}, but cleans up @samp{@} catch
1077(...) @{} in C++ and Java mode.
1078
1079@item empty-defun-braces
1080Clean up braces following a top-level function or class definition that
1081contains no body. Clean up occurs when the closing brace is typed.
1082Thus the following:
d7bd46ed 1083
6bf7aab6
DL
1084@example
1085@group
6bf7aab6
DL
1086class Spam
1087@{
1088@}
6bf7aab6
DL
1089@end group
1090@end example
6b61353c 1091
6bf7aab6
DL
1092@noindent
1093is transformed into this when the close brace is typed:
6b61353c 1094
6bf7aab6
DL
1095@example
1096@group
6bf7aab6
DL
1097class Spam
1098@{@}
6bf7aab6
DL
1099@end group
1100@end example
1101
6b61353c
KH
1102@item defun-close-semi
1103Clean up the terminating semicolon on top-level function or class
1104definitions when they follow a close brace. Clean up occurs when the
1105semicolon is typed. So for example, the following:
1106
6bf7aab6
DL
1107@example
1108@group
6bf7aab6
DL
1109class Spam
1110@{
1111@}
1112;
6bf7aab6
DL
1113@end group
1114@end example
6b61353c 1115
6bf7aab6 1116@noindent
6b61353c 1117is transformed into this when the semicolon is typed:
6bf7aab6
DL
1118
1119@example
1120@group
6bf7aab6
DL
1121class Spam
1122@{
1123@};
6bf7aab6
DL
1124@end group
1125@end example
1126
6b61353c
KH
1127@item list-close-comma
1128Clean up commas following braces in array and aggregate initializers.
1129Clean up occurs when the comma is typed.
1130
1131@item scope-operator
1132Clean up double colons which may designate a C++ scope operator split
1133across multiple lines@footnote{Certain C++ constructs introduce
1134ambiguous situations, so @code{scope-operator} clean-ups may not always
1135be correct. This usually only occurs when scoped identifiers appear in
1136switch label tags.}. Clean up occurs when the second colon is typed.
1137You will always want @code{scope-operator} in the @code{c-cleanup-list}
1138when you are editing C++ code.
1139@end table
6bf7aab6 1140
cb7f2e96
GM
1141The following clean-ups are always active when they occur on
1142@code{c-cleanup-list}, and are thus not affected by the auto-newline
1143minor mode:
1144
6b61353c
KH
1145@table @code
1146@item space-before-funcall
1147Insert a space between the function name and the opening parenthesis of
1148a function call. This produces function calls in the style mandated by
1149the GNU coding standards, e.g. @samp{signal (SIGINT, SIG_IGN)} and
1150@samp{abort ()}. Clean up occurs when the opening parenthesis is typed.
1151
1152@item compact-empty-funcall
1153Clean up any space between the function name and the opening parenthesis
1154of a function call that has no arguments. This is typically used
1155together with @code{space-before-funcall} if you prefer the GNU function
1156call style for functions with arguments but think it looks ugly when
1157it's only an empty parenthesis pair. I.e. you will get @samp{signal
1158(SIGINT, SIG_IGN)}, but @samp{abort()}. Clean up occurs when the
1159closing parenthesis is typed.
1160@end table
cb7f2e96 1161
6bf7aab6
DL
1162
1163@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
d7bd46ed
GM
1164@node Hungry-deletion of Whitespace, , Auto-newline Insertion, Minor Modes
1165@comment node-name, next, previous, up
6b61353c
KH
1166@section Hungry-deletion of Whitespace
1167@cindex hungry-deletion
6bf7aab6
DL
1168@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1169
1170Hungry deletion of whitespace, or as it more commonly called,
1171@dfn{hungry-delete mode}, is a simple feature that some people find
1172extremely useful. In fact, you might find yourself wanting
1173hungry-delete in @strong{all} your editing modes!
1174
1175@kindex DEL
6b61353c
KH
1176@kindex C-d
1177
1178In a nutshell, when hungry-delete mode is enabled, hitting the @kbd{DEL}
1179or @kbd{C-d} keys will consume all preceding or following whitespace,
1180including newlines and tabs. This can really cut down on the number of
1181times you have to hit these keys if, for example, you made a mistake on
6bf7aab6
DL
1182the preceding line.
1183
6b61353c 1184@deffn Command c-electric-backspace
6bf7aab6 1185@findex electric-backspace (c-)
6b61353c
KH
1186This command is run by default when you hit the @kbd{DEL} key. It
1187deletes any amount of whitespace in the backwards direction if
1188hungry-delete mode is enabled. When it's disabled, or when used with
1189a prefix argument or in a literal (@pxref{Auto-newline Insertion}),
1190the function contained in the @code{c-backspace-function} variable is
1191called with the prefix argument.
1192@end deffn
1193
1194@defvar c-backspace-function
6bf7aab6 1195@vindex backspace-function (c-)
6b61353c
KH
1196@findex backward-delete-char-untabify
1197Hook that gets called by @code{c-electric-backspace} when it doesn't
1198do an ``electric'' deletion of the preceding whitespace. The default
1199value is @code{backward-delete-char-untabify}.
1200@end defvar
1201
1202@deffn Command c-electric-delete-forward
1203@findex electric-delete-forward (c-)
1204This function, which is bound to @kbd{C-d} by default, works just like
1205@code{c-electric-backspace} but in the forward direction. When it
1206doesn't do an ``electric'' deletion of the following whitespace, it
1207calls the function in @code{c-delete-function} with its prefix
1208argument.
1209@end deffn
1210
1211@defvar c-delete-function
1212@vindex delete-function (c-)
1213@findex delete-char
1214Hook that gets called by @code{c-electric-delete-forward} when it
1215doesn't do an ``electric'' deletion of the following whitespace. The
1216default value is @code{delete-char}.
1217@end defvar
1218
1219Above we have only talked about the @kbd{DEL} and @kbd{C-d} key events,
1220without connecting them to the physical keys commonly known as
1221@key{Backspace} and @key{Delete}. The default behavior of those two
1222depends on the flavor of (X)Emacs you are using.
6bf7aab6
DL
1223
1224@findex c-electric-delete
1225@findex electric-delete (c-)
6b61353c 1226@vindex delete-key-deletes-forward
6bf7aab6 1227
6b61353c
KH
1228In XEmacs 20.3 and beyond, the @key{Backspace} key is bound to
1229@code{c-electric-backspace} and the @key{Delete} key is bound to
1230@code{c-electric-delete}. You control the direction it deletes in by
1231setting the variable @code{delete-key-deletes-forward}, a standard
1232XEmacs variable. When this variable is non-@code{nil},
1233@code{c-electric-delete} will do forward deletion with
1234@code{c-electric-delete-forward}, otherwise it does backward deletion
1235with @code{c-electric-backspace}.
1236
1237In other Emacs versions, @ccmode{} doesn't bind either @key{Backspace}
1238or @key{Delete}. In XEmacs 19 and Emacs prior to 21 that means that
1239it's up to you to fix them. Emacs 21 automatically binds them as
1240appropriate to @kbd{DEL} and @kbd{C-d}.
1241
1242Another way to use hungry deletion is to bind
1243@code{c-hungry-backspace} and @code{c-hungry-delete-forward} directly
1244to keys, and not use the mode toggling. For example @kbd{C-c C-d} and
1245@kbd{C-c DEL} to match plain @kbd{C-d} and @kbd{DEL},
6bf7aab6 1246
6b61353c
KH
1247@example
1248(add-hook
1249 'c-mode-common-hook
1250 (lambda ()
1251 (define-key c-mode-base-map
1252 [?\C-c ?\d] 'c-hungry-backspace)
1253 (define-key c-mode-base-map
1254 [?\C-c ?\C-d] 'c-hungry-delete-forward)))
1255@end example
6bf7aab6 1256
6b61353c
KH
1257@deffn Command c-hungry-backspace
1258@findex hungry-backspace (c-)
1259Delete any amount of whitespace in the backwards direction (regardless
1260whether hungry-delete mode is enabled or not).
1261@end deffn
6bf7aab6 1262
6b61353c
KH
1263@deffn Command c-hungry-delete-forward
1264@findex hungry-delete-forward (c-)
1265Delete any amount of whitespace in the forward direction (regardless
1266whether hungry-delete mode is enabled or not).
1267@end deffn
6bf7aab6
DL
1268
1269
1270@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6b61353c 1271@node Text Filling and Line Breaking, Macro Handling, Minor Modes, Top
d7bd46ed 1272@comment node-name, next, previous, up
6b61353c
KH
1273@chapter Text Filling and Line Breaking
1274@cindex text filling
1275@cindex line breaking
1276@cindex comment handling
6bf7aab6
DL
1277@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1278
d7bd46ed
GM
1279Since there's a lot of normal text in comments and string literals,
1280@ccmode{} provides features to edit these like in text mode. The goal
1281is to do it as seamlessly as possible, i.e. you can use auto fill mode,
1282sentence and paragraph movement, paragraph filling, adaptive filling etc
1283wherever there's a piece of normal text without having to think much
1284about it. @ccmode{} should keep the indentation, fix the comment line
1285decorations, and so on, for you. It does that by hooking in on the
1286different line breaking functions and tuning relevant variables as
1287necessary.
1288
1289@vindex c-comment-prefix-regexp
1290@vindex comment-prefix-regexp (c-)
1291@cindex comment line prefix
1292@vindex comment-start
1293@vindex comment-end
1294@vindex comment-start-skip
1295@vindex paragraph-start
1296@vindex paragraph-separate
1297@vindex paragraph-ignore-fill-prefix
1298@vindex adaptive-fill-mode
1299@vindex adaptive-fill-regexp
1300@vindex adaptive-fill-first-line-regexp
1301To make Emacs recognize comments and treat text in them as normal
1302paragraphs, @ccmode{} makes several standard
1303variables@footnote{@code{comment-start}, @code{comment-end},
1304@code{comment-start-skip}, @code{paragraph-start},
1305@code{paragraph-separate}, @code{paragraph-ignore-fill-prefix},
1306@code{adaptive-fill-mode}, @code{adaptive-fill-regexp}, and
1307@code{adaptive-fill-first-line-regexp}.} buffer local and modifies them
6b61353c
KH
1308according to the language syntax and the comment line prefix.
1309
1310@defopt c-comment-prefix-regexp
1311@vindex comment-prefix-regexp (c-)
1312This style variable contains the regexp used to recognize the
1313@dfn{comment line prefix}, which is the line decoration that starts
1314every line in a comment. The default is @samp{//+\\|\\**}, which
d7bd46ed 1315matches C++ style line comments like
d7bd46ed 1316
6b61353c 1317@example
d7bd46ed 1318// blah blah
d7bd46ed
GM
1319@end example
1320
1321@noindent
1322with two or more slashes in front of them, and C style block comments
1323like
6b61353c 1324
d7bd46ed
GM
1325@example
1326@group
d7bd46ed
GM
1327/*
1328 * blah blah
1329 */
d7bd46ed
GM
1330@end group
1331@end example
1332
1333@noindent
1334with zero or more stars at the beginning of every line. If you change
6b61353c 1335this variable, please make sure it still matches the comment starter
d7bd46ed 1336(i.e. @code{//}) of line comments @emph{and} the line prefix inside
6b61353c
KH
1337block comments.
1338
1339@findex c-setup-paragraph-variables
1340@findex setup-paragraph-variables (c-)
1341Also note that since @ccmode{} uses the value of
d7bd46ed 1342@code{c-comment-prefix-regexp} to set up several other variables at mode
6b61353c
KH
1343initialization, there won't have any effect if you change it inside a
1344@ccmode{} buffer. You need to call the command
1345@code{c-setup-paragraph-variables} to update those other variables with
1346the new value. That's also the case if you modify this variable in a
1347mode hook, since @ccmode{} sets up all variables before calling them.
1348@end defopt
d7bd46ed
GM
1349
1350@findex auto-fill-mode
6b61353c
KH
1351@cindex Auto Fill mode
1352@cindex paragraph filling
d7bd46ed
GM
1353Line breaks are by default handled (almost) the same regardless whether
1354they are made by auto fill mode (@pxref{Auto Fill,,, emacs, The Emacs
1355Editor}), paragraph filling (e.g. with @kbd{M-q}), or explicitly with
1356@kbd{M-j} or similar methods. In string literals, the new line gets the
1357same indentation as the previous nonempty line (may be changed with the
1358@code{string} syntactic symbol). In comments, @ccmode{} uses
1359@code{c-comment-prefix-regexp} to adapt the line prefix from the other
1360lines in the comment.
1361
1362@vindex adaptive-fill-mode
6b61353c 1363@cindex Adaptive Fill mode
d7bd46ed
GM
1364@ccmode{} uses adaptive fill mode (@pxref{Adaptive Fill,,, emacs, The
1365Emacs Editor}) to make Emacs correctly keep the line prefix when filling
1366paragraphs. That also makes Emacs preserve the text indentation
1367@emph{inside} the comment line prefix. E.g. in the following comment,
6b61353c
KH
1368both paragraphs will be filled with the left margins of the texts kept
1369intact:
1370
d7bd46ed
GM
1371@example
1372@group
d7bd46ed
GM
1373/* Make a balanced b-tree of the nodes in the incoming
1374 * stream. But, to quote the famous words of Donald E.
1375 * Knuth,
1376 *
1377 * Beware of bugs in the above code; I have only
1378 * proved it correct, not tried it.
1379 */
d7bd46ed
GM
1380@end group
1381@end example
1382
1383@findex c-setup-filladapt
1384@findex setup-filladapt (c-)
1385@findex filladapt-mode
1386@vindex filladapt-mode
1387@cindex Filladapt mode
1388It's also possible to use other adaptive filling packages, notably Kyle
1389E. Jones' Filladapt package@footnote{It's available from
1390@uref{http://www.wonderworks.com/}. As of version 2.12, it does however
1391lack a feature that makes it work suboptimally when
1392@code{c-comment-prefix-regexp} matches the empty string (which it does
1393by default). A patch for that is available from
6b61353c 1394@uref{http://cc-mode.sourceforge.net/,, the CC Mode web site}.},
d7bd46ed
GM
1395which handles things like bulleted lists nicely. There's a convenience
1396function @code{c-setup-filladapt} that tunes the relevant variables in
1397Filladapt for use in @ccmode{}. Call it from a mode hook, e.g. with
1398something like this in your @file{.emacs}:
d7bd46ed 1399
6b61353c 1400@example
d7bd46ed
GM
1401(defun my-c-mode-common-hook ()
1402 (c-setup-filladapt)
1403 (filladapt-mode 1))
1404(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
d7bd46ed 1405@end example
6bf7aab6 1406
6b61353c 1407@defopt c-block-comment-prefix
d7bd46ed 1408@vindex block-comment-prefix (c-)
6bf7aab6
DL
1409@vindex c-comment-continuation-stars
1410@vindex comment-continuation-stars (c-)
d7bd46ed
GM
1411Normally the comment line prefix inserted for a new line inside a
1412comment is deduced from other lines in it. However there's one
6b61353c
KH
1413situation when there's no hint about what the prefix should look like,
1414namely when a block comment is broken for the first time. This style
1415variable@footnote{In versions before 5.26, this variable was called
1416@code{c-comment-continuation-stars}. As a compatibility measure,
1417@ccmode{} still uses the value on that variable if it's set.} is used
1418then as the comment prefix. It defaults to @samp{* }, which makes a
1419comment
6bf7aab6 1420
6b61353c 1421@example
d7bd46ed 1422/* Got O(n^2) here, which is a Bad Thing. */
d7bd46ed 1423@end example
6bf7aab6 1424
d7bd46ed
GM
1425@noindent
1426break into
6b61353c 1427
d7bd46ed
GM
1428@example
1429@group
d7bd46ed
GM
1430/* Got O(n^2) here,
1431 * which is a Bad Thing. */
d7bd46ed
GM
1432@end group
1433@end example
1434
6b61353c
KH
1435Note that it won't work to adjust the indentation by putting leading
1436spaces in @code{c-block-comment-prefix}, since @ccmode{} still uses the
1437normal indentation engine to indent the line. Thus, the right way to
1438fix the indentation is by customizing the @code{c} syntactic symbol. It
1439defaults to @code{c-lineup-C-comments}, which handles the indentation of
1440most common comment styles, see @ref{Indentation Functions}.
1441@end defopt
d7bd46ed 1442
6b61353c 1443@defopt c-ignore-auto-fill
d7bd46ed
GM
1444@vindex ignore-auto-fill (c-)
1445When auto fill mode is enabled, @ccmode{} can selectively ignore it
1446depending on the context the line break would occur in, e.g. to never
6b61353c
KH
1447break a line automatically inside a string literal. This variable
1448takes a list of symbols for the different contexts where auto-filling
1449never should occur:
d7bd46ed 1450
6b61353c
KH
1451@table @code
1452@item string
1453Inside a string or character literal.
1454@item c
1455Inside a C style block comment.
1456@item c++
1457Inside a C++ style line comment.
1458@item cpp
1459Inside a preprocessor directive.
1460@item code
1461Anywhere else, i.e. in normal code.
1462@end table
d7bd46ed
GM
1463
1464By default, @code{c-ignore-auto-fill} is set to @code{'(string cpp
1465code)}, which means that auto-filling only occurs in comments when
1466auto-fill mode is activated. In literals, it's often desirable to have
1467explicit control over newlines. In preprocessor directives, the
1468necessary @samp{\} escape character before the newline is not
1469automatically inserted, so an automatic line break would produce invalid
1470code. In normal code, line breaks are normally dictated by some logical
1471structure in the code rather than the last whitespace character, so
1472automatic line breaks there will produce poor results in the current
1473implementation.
6b61353c 1474@end defopt
d7bd46ed 1475
6b61353c 1476The commands that do the actual work follow.
d7bd46ed
GM
1477
1478@table @asis
6b61353c 1479@item @kbd{M-q} (@code{c-fill-paragraph})
d7bd46ed
GM
1480@kindex M-q
1481@findex c-fill-paragraph
1482@findex fill-paragraph (c-)
1483@cindex Javadoc markup
cb7f2e96 1484@cindex Pike autodoc markup
d7bd46ed
GM
1485This is the replacement for @code{fill-paragraph} in @ccmode{}
1486buffers. It's used to fill multiline string literals and both block and
1487line style comments. In Java buffers, the Javadoc markup words are
cb7f2e96
GM
1488recognized as paragraph starters. The line oriented Pike autodoc markup
1489words are recognized in the same way in Pike mode.
d7bd46ed
GM
1490
1491The function keeps the comment starters and enders of block comments as
1492they were before the filling. This means that a comment ender on the
1493same line as the paragraph being filled will be filled with the
1494paragraph, and one on a line by itself will stay as it is. The comment
1495starter is handled similarly@footnote{This means that the variables
1496@code{c-hanging-comment-starter-p} and @code{c-hanging-comment-ender-p},
1497which controlled this behavior in earlier versions of @ccmode{}, are now
1498obsolete.}.
1499
6b61353c 1500@item @kbd{M-j} (@code{c-indent-new-comment-line})
d7bd46ed
GM
1501@kindex M-j
1502@findex c-indent-new-comment-line
1503@findex indent-new-comment-line (c-)
d7bd46ed
GM
1504This is the replacement for @code{indent-new-comment-line}. It breaks
1505the line at point and indents the new line like the current one.
1506
1507@vindex comment-multi-line
1508If inside a comment and @code{comment-multi-line} is non-@code{nil}, the
1509indentation and line prefix are preserved. If inside a comment and
1510@code{comment-multi-line} is @code{nil}, a new comment of the same type
1511is started on the next line and indented as appropriate for comments.
1512
6b61353c
KH
1513Note that @ccmode{} sets @code{comment-multi-line} to @code{t} at
1514startup. The reason is that @kbd{M-j} could otherwise produce sequences
1515of single line block comments for texts that should logically be treated
1516as one comment, and the rest of the paragraph handling code
1517(e.g. @kbd{M-q} and @kbd{M-a}) can't cope with that, which would lead to
1518inconsistent behavior.
1519
1520@item @kbd{M-x c-context-line-break}
d7bd46ed
GM
1521@findex c-context-line-break
1522@findex context-line-break (c-)
d7bd46ed
GM
1523This is a function that works like @code{indent-new-comment-line} in
1524comments and @code{newline-and-indent} elsewhere, thus combining those
1525two in a way that uses each one in the context it's best suited for.
6b61353c
KH
1526I.e. in comments the comment line prefix and indentation is kept for
1527the new line, and in normal code it's indented according to context by
1528the indentation engine.
1529
1530In macros it acts like @code{newline-and-indent} but additionally
1531inserts and optionally aligns the line ending backslash so that the
1532macro remains unbroken. @xref{Macro Handling}, for details about the
1533backslash alignment.
d7bd46ed
GM
1534
1535It's not bound to a key by default, but it's intended to be used on the
1536@kbd{RET} key. If you like the behavior of @code{newline-and-indent} on
6b61353c
KH
1537@kbd{RET}, you should consider switching to this function.
1538
1539@item @kbd{M-x c-context-open-line}
1540@findex c-context-open-line
1541@findex context-open-line (c-)
1542This is to @kbd{C-o} (@kbd{M-x open-line}) as
1543@code{c-context-line-break} is to @kbd{RET}. I.e. it works just like
1544@code{c-context-line-break} but leaves the point before the inserted
1545line break.
d7bd46ed 1546@end table
6bf7aab6 1547
d7bd46ed
GM
1548
1549@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6b61353c 1550@node Macro Handling, Font Locking, Text Filling and Line Breaking, Top
d7bd46ed 1551@comment node-name, next, previous, up
6b61353c
KH
1552@chapter Macro Handling
1553@cindex macros
1554@cindex preprocessor directives
6bf7aab6
DL
1555@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1556
6b61353c
KH
1557Preprocessor directives are handled as syntactic whitespace from other
1558code, i.e. they can be interspersed anywhere without affecting the
1559syntactic analysis, just like comments.
6bf7aab6 1560
6b61353c
KH
1561The code inside macro definitions is still analyzed syntactically so
1562that you get relative indentation there just as you'd get if the same
1563code was outside a macro. However, since there is no hint about the
1564syntactic context, i.e. whether the macro expands to an expression, to some
1565statements, or perhaps to whole functions, the syntactic recognition can be
1566wrong. @ccmode{} manages to figure it out correctly most of the time,
1567though. @xref{Syntactic Symbols}, for details about the indentation.
6bf7aab6 1568
6b61353c
KH
1569@defopt c-syntactic-indentation-in-macros
1570@vindex syntactic-indentation-in-macros (c-)
1571Enable syntactic analysis inside macros, which is the default. If this
1572is @code{nil}, all lines inside macro definitions are analyzed as
1573@code{cpp-macro-cont}.
1574@end defopt
6bf7aab6 1575
6b61353c
KH
1576@ccmode{} provides some tools to help keep the line continuation
1577backslashes in macros neat and tidy:
1578
1579@table @asis
1580@item @kbd{C-c C-\} (@code{c-backslash-region})
1581@kindex C-c C-\
1582@findex c-backslash-region
1583@findex backslash-region (c-)
1584This function inserts and aligns or deletes the end-of-line backslashes
1585in the current region.
1586
1587With no prefix argument, it inserts any missing backslashes and aligns
1588them according to the @code{c-backslash-column} and
1589@code{c-backslash-max-column} variables. With a prefix argument, it
1590deletes any backslashes.
1591
1592The function does not modify blank lines at the start of the region. If
1593the region ends at the start of a line, it always deletes the backslash
1594(if any) at the end of the previous line.
1595@end table
1596
1597@defopt c-backslash-column
1598@vindex backslash-column (c-)
1599@defoptx c-backslash-max-column
1600@vindex backslash-max-column (c-)
1601These variables control the alignment columns for line continuation
1602backslashes in multiline macros. They are used by the functions that
1603automatically insert or align such backslashes,
1604e.g. @code{c-backslash-region} and @code{c-context-line-break}.
1605
1606@code{c-backslash-column} specifies the minimum column for the
1607backslashes. If any line in the macro exceeds it then the next tab
1608stop from that line is used as the alignment column for all the
1609backslashes, so that they remain in a single column. However, if some
1610lines exceed @code{c-backslash-max-column} then the backslashes in the
1611rest of the macro will be kept at that column, so that the
1612lines which are too long ``stick out'' instead.
1613@end defopt
1614
1615@defopt c-auto-align-backslashes
1616@vindex auto-align-backslashes (c-)
1617Align automatically inserted line continuation backslashes if
1618non-@code{nil}. When line continuation backslashes are inserted
1619automatically for line breaks in multiline macros, e.g. by
1620@code{c-context-line-break}, they are aligned with the other backslashes
1621in the same macro if this flag is set. Otherwise the inserted
1622backslashes are preceded by a single space.
1623@end defopt
1624
1625The recommended line breaking function, @code{c-context-line-break}
1626(@pxref{Text Filling and Line Breaking}), is especially nice if you edit
1627multiline macros frequently. When used inside a macro, it automatically
1628inserts and adjusts the mandatory backslash at the end of the line to
1629keep the macro together, and it leaves the point at the right
1630indentation column for the code. Thus you can write code inside macros
1631almost exactly as you can elsewhere, without having to bother with the
1632trailing backslashes.
1633
1634
1635@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1636@node Font Locking, Commands, Macro Handling, Top
1637@comment node-name, next, previous, up
1638@chapter Font Locking
1639@cindex font locking
1640@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1641
1642@strong{Note:} The font locking in AWK mode is currently not integrated
1643with the rest of @ccmode{}, so this section does not apply there.
1644@xref{AWK Mode Font Locking}, instead.
1645
1646@cindex Font Lock mode
1647
1648@ccmode{} provides font locking for its supported languages by supplying
1649patterns for use with Font Lock mode. This means that you get distinct
1650faces on the various syntactic parts such as comments, strings, keywords
1651and types, which is very helpful in telling them apart at a glance and
1652discovering syntactic errors. @xref{Font Lock,,, emacs, The Emacs
1653Editor}, for ways to enable font locking in @ccmode{} buffers.
1654
1655@menu
1656* Font Locking Preliminaries::
1657* Faces::
1658* Documentation Comments::
1659@end menu
1660
1661
1662@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1663@node Font Locking Preliminaries, Faces, , Font Locking
1664@comment node-name, next, previous, up
1665@section Font Locking Preliminaries
1666@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1667
1668The font locking for most of the @ccmode{} languages were provided
1669directly by the Font Lock package prior to version 5.30 of @ccmode{}.
1670In the transition to @ccmode{} the patterns have been reworked
1671completely and are applied uniformly across all the languages except AWK
1672mode, just like the indentation rules (although each language still has
1673some pecularities of its own, of course). Since the languages
1674previously had completely separate font locking patterns, this means
1675that it's a bit different in most languages now.
1676
1677The main goal for the font locking in @ccmode{} is accuracy, to provide
1678a dependable aid in recognizing the various constructs. Some, like
1679strings and comments, are easy to recognize while others like
1680declarations and types can be very tricky. @ccmode{} can go to great
1681lengths to recognize declarations and casts correctly, especially when
1682the types aren't recognized by standard patterns. This is a fairly
1683demanding analysis which can be slow on older hardware, and it can
1684therefore be disabled by choosing a lower decoration level with the
1685variable @code{font-lock-maximum-decoration}.
1686
1687@vindex font-lock-maximum-decoration
1688
1689The decoration levels are used as follows:
1690
1691@enumerate
1692@comment 1
1693@item
1694Minimal font locking: Fontify only comments, strings and preprocessor
1695directives (in the languages that use cpp).
1696
1697@comment 2
1698@item
1699Fast normal font locking: In addition to level 1, fontify keywords,
1700simple types and declarations that are easy to recognize. The variables
1701@code{*-font-lock-extra-types} (where @samp{*} is the name of the
1702language) are used to recognize types (see below). Documentation
1703comments like Javadoc are fontified according to
1704@code{c-doc-comment-style} (@pxref{Documentation Comments}).
1705
1706Use this if you think the font locking is too slow. It's the closest
1707corresponding level to level 3 in the old font lock patterns.
1708
1709@comment 3
1710@item
1711Accurate normal font locking: Like level 2 but uses a different approach
1712that can recognize types and declarations much more accurately. The
1713@code{*-font-lock-extra-types} variables are still used, but user
1714defined types are recognized correctly anyway in most cases. Therefore
1715those variables should be fairly restrictive and not contain patterns
1716that are uncertain.
1717
1718@cindex Lazy Lock mode
1719@cindex Just-in-time Lock mode
1720
1721This level is designed for fairly modern hardware and a font lock
1722support mode like Lazy Lock or Just-in-time Lock mode that only
1723fontifies the parts that are actually shown.
1724@end enumerate
1725
1726@cindex user defined types
1727@cindex types, user defined
1728
1729Since user defined types are hard to recognize you can provide
1730additional regexps to match those you use:
1731
1732@defopt c-font-lock-extra-types
1733@defoptx c++-font-lock-extra-types
1734@defoptx objc-font-lock-extra-types
1735@defoptx java-font-lock-extra-types
1736@defoptx idl-font-lock-extra-types
1737@defoptx pike-font-lock-extra-types
1738For each language there's a variable @code{*-font-lock-extra-types},
1739where @samp{*} stands for the language in question. It contains a list
1740of regexps that matches identifiers that should be recognized as types,
1741e.g. @samp{\\sw+_t} to recognize all identifiers ending with @samp{_t}
1742as is customary in C code. Each regexp should not match more than a
1743single identifier.
1744
1745The default values contain regexps for many types in standard runtime
1746libraries that are otherwise difficult to recognize, and patterns for
1747standard type naming conventions like the @samp{_t} suffix in C and C++.
1748Java, Objective-C and Pike have as a convention to start class names
1749with capitals, so there are patterns for that in those languages.
1750
1751Despite the names of these variables, they are not only used for
1752fontification but in other places as well where @ccmode{} needs to
1753recognize types.
1754@end defopt
1755
1756
1757@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1758@node Faces, Documentation Comments, Font Locking Preliminaries, Font Locking
1759@comment node-name, next, previous, up
1760@section Faces
1761@cindex faces
1762@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1763
1764@ccmode{} attempts to use the standard faces for programming languages
1765in accordance with their intended purposes as far as possible. No extra
1766faces are currently provided, with the exception of a replacement face
1767@code{c-invalid-face} for emacsen that don't provide
1768@code{font-lock-warning-face}.
1769
1770@itemize @bullet
1771@item
1772@vindex font-lock-comment-face
1773Normal comments are fontified in @code{font-lock-comment-face}.
1774
1775@item
1776@vindex font-lock-doc-face
1777@vindex font-lock-doc-string-face
1778@vindex font-lock-comment-face
1779Comments that are recognized as documentation (@pxref{Documentation
1780Comments}) get @code{font-lock-doc-face} (Emacs) or
1781@code{font-lock-doc-string-face} (XEmacs) if those faces exist. If they
1782don't then @code{font-lock-comment-face} is used.
1783
1784@item
1785@vindex font-lock-string-face
1786String and character literals are fontified in
1787@code{font-lock-string-face}.
1788
1789@item
1790@vindex font-lock-keyword-face
1791Keywords are fontified with @code{font-lock-keyword-face}.
1792
1793@item
1794@vindex font-lock-function-name-face
1795@code{font-lock-function-name-face} is used for function names in
1796declarations and definitions, and classes in those contexts. It's also
1797used for preprocessor defines with arguments.
1798
1799@item
1800@vindex font-lock-variable-name-face
1801Variables in declarations and definitions, and other identifiers in such
1802variable contexts, get @code{font-lock-variable-name-face}. It's also
1803used for preprocessor defines without arguments.
1804
1805@item
1806@vindex font-lock-constant-face
1807@vindex font-lock-reference-face
1808Builtin constants are fontified in @code{font-lock-constant-face} if it
1809exists, @code{font-lock-reference-face} otherwise. As opposed to the
1810preceding two faces, this is used on the names in expressions, and it's
1811not used in declarations, even if there happen to be a @samp{const} in
1812them somewhere.
1813
1814@item
1815@vindex font-lock-type-face
1816@code{font-lock-type-face} is put on types (both predefined and user
1817defined) and classes in type contexts.
1818
1819@item
1820@vindex font-lock-constant-face
1821@vindex font-lock-reference-face
1822Label identifiers get @code{font-lock-constant-face} if it exists,
1823@code{font-lock-reference-face} otherwise.
1824
1825@item
1826Name qualifiers and identifiers for scope constructs are fontified like
1827labels.
1828
1829@item
1830Special markup inside documentation comments are also fontified like
1831labels.
1832
1833@item
1834@vindex font-lock-preprocessor-face
1835@vindex font-lock-builtin-face
1836@vindex font-lock-reference-face
1837Preprocessor directives get @code{font-lock-preprocessor-face} if it
1838exists (i.e. XEmacs). In Emacs they get @code{font-lock-builtin-face}
1839or @code{font-lock-reference-face}, for lack of a closer equivalent.
1840
1841@item
1842@vindex font-lock-warning-face
1843@vindex c-invalid-face
1844@vindex invalid-face (c-)
1845Some kinds of syntactic errors are fontified with
1846@code{font-lock-warning-face} in Emacs. In older XEmacs versions
1847there's no corresponding standard face, so there a special
1848@code{c-invalid-face} is used, which is defined to stand out sharply by
1849default.
1850
1851Note that it's not used for @samp{#error} or @samp{#warning} directives,
1852since those aren't syntactic errors in themselves.
1853@end itemize
1854
1855
1856@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1857@node Documentation Comments, , Faces, Font Locking
1858@comment node-name, next, previous, up
1859@section Documentation Comments
1860@cindex documentation comments
1861@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1862
1863There are various tools to supply documentation in the source as
1864specially structured comments, e.g. the standard Javadoc tool in Java.
1865@ccmode{} provides an extensible mechanism to fontify such comments and
1866the special markup inside them.
1867
1868@defopt c-doc-comment-style
1869@vindex doc-comment-style (c-)
1870This is a style variable that specifies which documentation comment
1871style to recognize, e.g. @code{javadoc} for Javadoc comments.
1872
1873The value may also be a list of styles, in which case all of them are
1874recognized simultaneously (presumably with markup cues that don't
1875conflict).
1876
1877The value may also be an association list to specify different comment
1878styles for different languages. The symbol for the major mode is then
1879looked up in the alist, and the value of that element is interpreted as
1880above if found. If it isn't found then the symbol `other' is looked up
1881and its value is used instead.
1882
1883Note that @ccmode{} uses this variable to set other variables that
1884handle fontification etc. That's done at mode initialization or when
1885you switch to a style which sets this variable. Thus, if you change it
1886in some other way, e.g. interactively in a CC Mode buffer, you will need
1887to do @kbd{M-x java-mode} (or whatever mode you're currently using) to
1888reinitialize.
1889
1890@findex c-setup-doc-comment-style
1891@findex setup-doc-comment-style (c-)
1892Note also that when @ccmode{} starts up, the other variables are
1893modified before the mode hooks are run. If you change this variable in
1894a mode hook, you have to call @code{c-setup-doc-comment-style}
1895afterwards to redo that work.
1896@end defopt
1897
1898@ccmode{} currently provides handing of the following doc comment
1899styles:
1900
1901@table @code
1902@item javadoc
1903@cindex Javadoc markup
1904Javadoc comments, the standard tool in Java.
1905
1906@item autodoc
1907@cindex Pike autodoc markup
1908For Pike autodoc markup, the standard in Pike.
1909@end table
1910
1911The above is by no means complete. If you'd like to see support for
1912other doc comment styles, please let us know (@pxref{Mailing Lists and
1913Submitting Bug Reports}).
1914
1915You can also write your own doc comment fontification support to use
1916with @code{c-doc-comment-style}: Supply a variable or function
1917@code{*-font-lock-keywords} where @samp{*} is the name you want to use
1918in @code{c-doc-comment-style}. If it's a variable, it's prepended to
1919@code{font-lock-keywords}. If it's a function, it's called at mode
1920initialization and the result is prepended. For an example, see
1921@code{javadoc-font-lock-keywords} in @file{cc-fonts.el}.
1922
1923If you add support for another doc comment style, please consider
1924contributing it --- send a note to @email{bug-cc-mode@@gnu.org}.
1925
1926
1927@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1928@node Commands, Customizing Indentation, Font Locking, Top
1929@comment node-name, next, previous, up
1930@chapter Commands
1931@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1932
1933@menu
1934* Indentation Commands::
1935* Movement Commands::
1936* Other Commands::
1937@end menu
1938
1939See also @ref{Text Filling and Line Breaking} and @ref{Macro Handling},
1940for commands concerning those bits.
1941
1942
1943@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
d7bd46ed
GM
1944@node Indentation Commands, Movement Commands, , Commands
1945@comment node-name, next, previous,up
6b61353c 1946@section Indentation Commands
d7bd46ed 1947@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6bf7aab6 1948
6b61353c
KH
1949The following list of commands reindent C constructs. Note that when
1950you change your coding style, either interactively or through some other
1951means, your file does @emph{not} automatically get reindented. You
1952will need to execute one of the following commands to see the effects of
d7bd46ed
GM
1953your changes.
1954
1955@cindex GNU indent program
1956Also, variables like @code{c-hanging-*} and @code{c-cleanup-list}
1957only affect how on-the-fly code is formatted. Changing the
6b61353c 1958``hanginess'' of a brace and then reindenting, will not move the brace
d7bd46ed 1959to a different line. For this, you're better off getting an external
6b61353c 1960program like GNU @code{indent}, which will rearrange brace location,
d7bd46ed
GM
1961among other things.
1962
6b61353c 1963Reindenting large sections of code can take a long time. When
d7bd46ed 1964@ccmode{} reindents a region of code, it is essentially equivalent to
6b61353c 1965hitting @kbd{TAB} on every line of the region.
d7bd46ed
GM
1966
1967These commands are useful when indenting code:
6bf7aab6 1968
d7bd46ed 1969@table @asis
6b61353c 1970@item @kbd{TAB} (@code{c-indent-command})
d7bd46ed 1971@kindex TAB
6bf7aab6
DL
1972@findex c-indent-command
1973@findex indent-command (c-)
d7bd46ed
GM
1974Indents the current line. The actual behavior is controlled by several
1975variables, described below. See @code{c-tab-always-indent},
1976@code{c-insert-tab-function}, and @code{indent-tabs-mode}. With a
1977numeric argument, this command rigidly indents the region, preserving
1978the relative indentation among the lines.
6bf7aab6 1979
6b61353c 1980@item @kbd{C-M-q} (@code{c-indent-exp})
718fb8a1 1981@kindex C-M-q
6bf7aab6
DL
1982@findex c-indent-exp
1983@findex indent-exp (c-)
d7bd46ed
GM
1984Indent an entire balanced brace or parenthesis expression. Note that
1985point must be on the opening brace or parenthesis of the expression you
1986want to indent.
6bf7aab6 1987
6b61353c 1988@item @kbd{C-c C-q} (@code{c-indent-defun})
6bf7aab6
DL
1989@kindex C-c C-q
1990@findex c-indent-defun
1991@findex indent-defun (c-)
6b61353c
KH
1992Indents the entire top-level function, class or macro definition
1993encompassing point. It leaves point unchanged. This function can't be
1994used to reindent a nested brace construct, such as a nested class or
1995function, or a Java method. The top-level construct being reindented
1996must be complete, i.e. it must have both a beginning brace and an ending
1997brace.
6bf7aab6 1998
6b61353c 1999@item @kbd{C-M-\} (@code{indent-region})
718fb8a1 2000@kindex C-M-\
6bf7aab6 2001@findex indent-region
d7bd46ed 2002Indents an arbitrary region of code. This is a standard Emacs command,
6b61353c 2003tailored for C code in a @ccmode{} buffer. Note, of course, that point
d7bd46ed 2004and mark must delineate the region you want to indent.
6bf7aab6 2005
6b61353c
KH
2006@item @kbd{M-;} (@code{indent-for-comment})
2007@kindex M-;
2008@findex indent-for-comment
2009Insert a comment at the end of the current line, if none is there already.
2010Then reindent the comment according to the variables
2011@code{c-indent-comment-alist}, @code{c-indent-comments-syntactically-p}
2012and @code{comment-column}. Then position the point after the comment
2013starter. This is a standard Emacs command, but @ccmode{} enhances it a
2014bit with two variables:
2015
2016@defopt c-indent-comment-alist
2017@vindex indent-comment-alist (c-)
2018@vindex comment-column
2019This style variable allows you to control which column @kbd{M-;}
2020indents the comment to, depending on the preceding code and the
2021indentation of a similar comment on the preceding line, if there is
2022any. It is an association list that maps different types of lines to
2023actions describing how they should be handled. If a certain line type
2024isn't present on the list then the line is indented to the column
2025specified by @code{comment-column}. See the documentation string for
2026@code{c-indent-comment-alist} for a full description of the available
2027line types and actions (use @kbd{C-h v c-indent-comment-alist}).
2028@end defopt
2029
2030@defopt c-indent-comments-syntactically-p
2031@vindex indent-comments-syntactically-p (c-)
2032Normally, when this variable is @code{nil}, @kbd{M-;} will indent
2033comment-only lines according to @code{c-indent-comment-alist}, just as
2034it does with lines where other code precede the comments. However, if
2035you want it to act just like @kbd{TAB} for comment-only lines you can
2036get that by setting @code{c-indent-comments-syntactically-p} to
2037non-@code{nil}.
2038
2039If @code{c-indent-comments-syntactically-p} is non-@code{nil} then
2040@code{c-indent-comment-alist} won't be consulted at all for comment-only
2041lines.
2042@end defopt
2043
2044@item @kbd{C-M-h} (@code{c-mark-function})
718fb8a1 2045@kindex C-M-h
6bf7aab6
DL
2046@findex c-mark-function
2047@findex mark-function (c-)
d7bd46ed
GM
2048While not strictly an indentation command, this is useful for marking
2049the current top-level function or class definition as the current
2050region. As with @code{c-indent-defun}, this command operates on
2051top-level constructs, and can't be used to mark say, a Java method.
d7bd46ed
GM
2052@end table
2053
2054These variables are also useful when indenting code:
2055
6b61353c 2056@defopt c-tab-always-indent
d7bd46ed
GM
2057@vindex tab-always-indent (c-)
2058@kindex TAB
2059@cindex literal
6b61353c
KH
2060This variable controls how @kbd{TAB} (@code{c-indent-command}) operates.
2061When it is @code{t}, @kbd{TAB} always indents the current line. When it
2062is @code{nil}, the line is indented only if point is at the left margin,
2063or on or before the first non-whitespace character on the line,
2064otherwise some whitespace is inserted. If this variable is the symbol
2065@code{other}, then some whitespace is inserted only within strings and
2066comments (literals), and inside preprocessor directives, but the line is
2067always reindented.
2068@end defopt
2069
2070@defopt c-insert-tab-function
d7bd46ed
GM
2071@vindex insert-tab-function (c-)
2072@findex tab-to-tab-stop
d7bd46ed
GM
2073When ``some whitespace'' is inserted as described above, what actually
2074happens is that the function stored in @code{c-insert-tab-function} is
2075called. Normally, this just inserts a real tab character, or the
2076equivalent number of spaces, depending on @code{indent-tabs-mode}.
2077Some people, however, set @code{c-insert-tab-function} to
2078@code{tab-to-tab-stop} so as to get hard tab stops when indenting.
6b61353c 2079@end defopt
d7bd46ed 2080
6b61353c
KH
2081@defopt indent-tabs-mode
2082This is a standard Emacs variable that controls how line indentation
2083is composed. When it's non-@code{nil}, tabs can be used in a line's
2084indentation, otherwise only spaces can be used.
2085@end defopt
d7bd46ed 2086
6b61353c 2087@defopt c-progress-interval
d7bd46ed 2088@vindex progress-interval (c-)
177c0ea7 2089When indenting large regions of code, this variable controls how often a
d7bd46ed 2090progress message is displayed. Set this variable to @code{nil} to
6b61353c
KH
2091inhibit the progress messages, or set it to an integer which is how
2092often (in seconds) progress messages are to be displayed.
2093@end defopt
d7bd46ed
GM
2094
2095
2096@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2097@node Movement Commands, Other Commands, Indentation Commands, Commands
2098@comment node-name, next, previous, up
6b61353c
KH
2099@section Movement Commands
2100@cindex movement
6bf7aab6
DL
2101@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2102
6b61353c 2103@ccmode{} contains some useful commands for moving around in C
6bf7aab6
DL
2104code.
2105
d7bd46ed 2106@table @asis
6b61353c 2107@item @kbd{M-x c-beginning-of-defun}
6bf7aab6
DL
2108@findex c-beginning-of-defun
2109@findex beginning-of-defun (c-)
2110@findex beginning-of-defun
6b61353c 2111Move point back to the least-enclosing brace. This function is
6bf7aab6
DL
2112analogous to the Emacs built-in command @code{beginning-of-defun},
2113except it eliminates the constraint that the top-level opening brace
2114must be in column zero. See @code{beginning-of-defun} for more
2115information.
2116
2117Depending on the coding style being used, you might prefer
2118@code{c-beginning-of-defun} to @code{beginning-of-defun}. If so,
2119consider binding @kbd{C-M-a} to the former instead. For backwards
2120compatibility reasons, the default binding remains in effect.
2121
6b61353c
KH
2122In AWK mode, a defun doesn't necessarily have braces at all. AWK Mode
2123therefore has its own version of this function which is bound by
2124default to @kbd{C-M-a}. You can thus chose freely which function to
2125bind to @kbd{C-M-a} for the other modes without worrying about AWK
2126buffers. @xref{AWK Mode Defuns}.
2127
2128@item @kbd{M-x c-end-of-defun}
6bf7aab6
DL
2129@findex c-end-of-defun
2130@findex end-of-defun (c-)
2131@findex end-of-defun
6bf7aab6
DL
2132Moves point to the end of the current top-level definition. This
2133function is analogous to the Emacs built-in command @code{end-of-defun},
2134except it eliminates the constraint that the top-level opening brace of
6b61353c 2135the defun must be in column zero. See @code{end-of-defun} for more
6bf7aab6
DL
2136information.
2137
2138Depending on the coding style being used, you might prefer
2139@code{c-end-of-defun} to @code{end-of-defun}. If so,
2140consider binding @kbd{C-M-e} to the former instead. For backwards
2141compatibility reasons, the default binding remains in effect.
2142
6b61353c
KH
2143In AWK Mode, a defun doesn't necessarily have braces at all. AWK Mode
2144therefore has its own version of this function which is bound by
2145default to @kbd{C-M-e}. You can thus chose freely which function to
2146bind to @kbd{C-M-e} for the other modes without worrying about AWK
2147buffers. @ref{AWK Mode Defuns}.
2148
2149@item @kbd{C-c C-u} (@code{c-up-conditional})
6bf7aab6
DL
2150@kindex C-c C-u
2151@findex c-up-conditional
2152@findex up-conditional (c-)
6bf7aab6
DL
2153Move point back to the containing preprocessor conditional, leaving the
2154mark behind. A prefix argument acts as a repeat count. With a negative
2155argument, move point forward to the end of the containing
d7bd46ed
GM
2156preprocessor conditional.
2157
2158@samp{#elif} is treated like @samp{#else} followed by @samp{#if}, so the
2159function stops at them when going backward, but not when going forward.
2160
6b61353c 2161@item @kbd{M-x c-up-conditional-with-else}
d7bd46ed
GM
2162@findex c-up-conditional-with-else
2163@findex up-conditional-with-else (c-)
d7bd46ed
GM
2164A variety of @code{c-up-conditional} that also stops at @samp{#else}
2165lines. Normally those lines are ignored.
2166
6b61353c 2167@item @kbd{M-x c-down-conditional}
d7bd46ed
GM
2168@findex c-down-conditional
2169@findex down-conditional (c-)
d7bd46ed
GM
2170Move point forward into the next nested preprocessor conditional,
2171leaving the mark behind. A prefix argument acts as a repeat count.
2172With a negative argument, move point backward into the previous
2173nested preprocessor conditional.
2174
2175@samp{#elif} is treated like @samp{#else} followed by @samp{#if}, so the
2176function stops at them when going forward, but not when going backward.
2177
6b61353c 2178@item @kbd{M-x c-down-conditional-with-else}
d7bd46ed
GM
2179@findex c-down-conditional-with-else
2180@findex down-conditional-with-else (c-)
d7bd46ed
GM
2181A variety of @code{c-down-conditional} that also stops at @samp{#else}
2182lines. Normally those lines are ignored.
6bf7aab6 2183
6b61353c 2184@item @kbd{C-c C-p} (@code{c-backward-conditional})
6bf7aab6
DL
2185@kindex C-c C-p
2186@findex c-backward-conditional
2187@findex backward-conditional (c-)
6bf7aab6
DL
2188Move point back over a preprocessor conditional, leaving the mark
2189behind. A prefix argument acts as a repeat count. With a negative
2190argument, move forward.
2191
6b61353c 2192@item @kbd{C-c C-n} (@code{c-forward-conditional})
6bf7aab6
DL
2193@kindex C-c C-n
2194@findex c-forward-conditional
2195@findex forward-conditional (c-)
6bf7aab6
DL
2196Move point forward across a preprocessor conditional, leaving the mark
2197behind. A prefix argument acts as a repeat count. With a negative
2198argument, move backward.
2199
6b61353c 2200@item @kbd{M-a} (@code{c-beginning-of-statement})
d7bd46ed 2201@kindex M-a
6bf7aab6
DL
2202@findex c-beginning-of-statement
2203@findex beginning-of-statement (c-)
6bf7aab6 2204Move point to the beginning of the innermost C statement. If point is
cb7f2e96
GM
2205already at the beginning of a statement, move to the beginning of the
2206closest preceding statement, even if that means moving into a block (you
718fb8a1 2207can use @kbd{C-M-b} to move over a balanced block). With prefix
6bf7aab6
DL
2208argument @var{n}, move back @var{n} @minus{} 1 statements.
2209
cb7f2e96
GM
2210If point is within or next to a comment or a string which spans more
2211than one line, this command moves by sentences instead of statements.
6bf7aab6
DL
2212
2213When called from a program, this function takes three optional
cb7f2e96
GM
2214arguments: the repetition count, a buffer position limit which is the
2215farthest back to search for the syntactic context, and a flag saying
2216whether to do sentence motion in or near comments and multiline strings.
6bf7aab6 2217
6b61353c 2218@item @kbd{M-e} (@code{c-end-of-statement})
d7bd46ed 2219@kindex M-e
6bf7aab6
DL
2220@findex c-end-of-statement
2221@findex end-of-statement (c-)
6bf7aab6
DL
2222Move point to the end of the innermost C statement. If point is at the
2223end of a statement, move to the end of the next statement, even if it's
718fb8a1 2224inside a nested block (use @kbd{C-M-f} to move to the other side of the
6bf7aab6
DL
2225block). With prefix argument @var{n}, move forward @var{n} @minus{} 1
2226statements.
2227
cb7f2e96
GM
2228If point is within or next to a comment or a string which spans more
2229than one line, this command moves by sentences instead of statements.
6bf7aab6
DL
2230
2231When called from a program, this function takes three optional
cb7f2e96
GM
2232arguments: the repetition count, a buffer position limit which is the
2233farthest back to search for the syntactic context, and a flag saying
2234whether to do sentence motion in or near comments and multiline strings.
6bf7aab6 2235
6b61353c 2236@item @kbd{M-x c-forward-into-nomenclature}
6bf7aab6
DL
2237@findex c-forward-into-nomenclature
2238@findex forward-into-nomenclature (c-)
6bf7aab6
DL
2239A popular programming style, especially for object-oriented languages
2240such as C++ is to write symbols in a mixed case format, where the first
2241letter of each word is capitalized, and not separated by underscores.
2242E.g. @samp{SymbolsWithMixedCaseAndNoUnderlines}.
2243
2244This command moves point forward to next capitalized word. With prefix
2245argument @var{n}, move @var{n} times.
2246
6b61353c 2247@item @kbd{M-x c-backward-into-nomenclature}
6bf7aab6
DL
2248@findex c-backward-into-nomenclature
2249@findex backward-into-nomenclature (c-)
6bf7aab6
DL
2250Move point backward to beginning of the next capitalized
2251word. With prefix argument @var{n}, move @var{n} times. If
2252@var{n} is negative, move forward.
d7bd46ed
GM
2253@end table
2254
2255
2256@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2257@node Other Commands, , Movement Commands, Commands
2258@comment node-name, next, previous, up
6b61353c 2259@section Other Commands
d7bd46ed
GM
2260@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2261
6b61353c 2262Here are the various other commands that didn't fit anywhere else:
d7bd46ed
GM
2263
2264@table @asis
6b61353c 2265@item @kbd{C-c :} (@code{c-scope-operator})
6bf7aab6
DL
2266@kindex C-c :
2267@findex c-scope-operator
2268@findex scope-operator (c-)
6bf7aab6
DL
2269In C++, it is also sometimes desirable to insert the double-colon scope
2270operator without performing the electric behavior of colon insertion.
2271@kbd{C-c :} does just this.
6bf7aab6
DL
2272@end table
2273
d7bd46ed
GM
2274@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2275@node Customizing Indentation, Syntactic Symbols, Commands, Top
2276@comment node-name, next, previous, up
6b61353c
KH
2277@chapter Customizing Indentation
2278@cindex customization, indentation
2279@cindex indentation
6bf7aab6
DL
2280@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2281
6b61353c
KH
2282The context sensitive indentation is mainly controlled by the variable
2283@code{c-offsets-alist}:
2284
2285@defopt c-offsets-alist
6bf7aab6 2286@vindex offsets-alist (c-)
6b61353c
KH
2287This special style variable contains the mappings between syntactic
2288symbols and the offsets to apply for those symbols. It's set at mode
2289initialization from a @emph{style} you may specify. Styles are
d7bd46ed 2290groupings of syntactic symbol offsets and other style variable values.
6b61353c 2291Most likely, you'll find that one of the predefined styles will suit
d7bd46ed
GM
2292your needs. @xref{Styles}, for an explanation of how to set up named
2293styles.
2294
2295Only syntactic symbols not already bound on @code{c-offsets-alist} will
2296be set from styles. This means that any association you set on it, be
2297it before or after mode initialization, will not be changed. The
2298@code{c-offsets-alist} variable may therefore be used from e.g. the
2299Customization interface@footnote{Available in Emacs 20 and later, and
2300XEmacs 19.15 and later.} to easily change indentation offsets without
2301having to bother about styles. Initially @code{c-offsets-alist} is
2302empty, so that all syntactic symbols are set by the style system.
2303
6b61353c
KH
2304The offset associated with any particular syntactic symbol can be an
2305integer, a function or lambda expression, a variable name, a vector, a
2306list, or one of the following special symbols: @code{+}, @code{-},
2307@code{++}, @code{--}, @code{*}, or @code{/}. The meaning of these
2308values are described in detail below.
2309@end defopt
d7bd46ed 2310
6b61353c
KH
2311The special symbols describe an offset in multiples of the value of
2312@code{c-basic-offset}:
2313
2314@defopt c-basic-offset
d7bd46ed 2315@vindex basic-offset (c-)
6b61353c
KH
2316Style variable that holds the basic offset between indentation levels.
2317@end defopt
6bf7aab6 2318
6b61353c
KH
2319By defining a style's indentation in terms of @code{c-basic-offset},
2320you can change the amount of whitespace given to an indentation level
2321while maintaining the same basic shape of your code. Here are the
2322values that the special symbols correspond to:
6bf7aab6 2323
6b61353c 2324@table @code
6bf7aab6
DL
2325@item +
2326@code{c-basic-offset} times 1
2327@item -
2328@code{c-basic-offset} times -1
2329@item ++
2330@code{c-basic-offset} times 2
2331@item --
2332@code{c-basic-offset} times -2
2333@item *
2334@code{c-basic-offset} times 0.5
2335@item /
2336@code{c-basic-offset} times -0.5
6bf7aab6
DL
2337@end table
2338
d7bd46ed
GM
2339@cindex indentation functions
2340
2341When a function is used as offset, it's called an @dfn{indentation
2342function}. Such functions are useful when more context than just the
2343syntactic symbol is needed to get the desired indentation.
2344@xref{Indentation Functions}, and @ref{Custom Indentation Functions},
2345for details about them.
2346
cb7f2e96 2347If the offset is a vector, its first element sets the absolute
6b61353c
KH
2348indentation column, which will override any previous relative
2349indentation. It won't override additional relative indentation for
2350nested constructs, though.
cb7f2e96 2351
d7bd46ed
GM
2352@vindex c-strict-syntax-p
2353@vindex strict-syntax-p (c-)
2354The offset can also be a list, in which case it is evaluated recursively
2355using the semantics described above. The first element of the list that
2356returns a non-@code{nil} value succeeds and the evaluation stops. If
2357none of the list elements return a non-@code{nil} value, then an offset
2358of 0 (zero) is used@footnote{There is however a variable
2359@code{c-strict-syntax-p} that, when set to non-@code{nil}, will cause an
6b61353c 2360error to be signalled in that case. It's now considered obsolete since
d7bd46ed
GM
2361it doesn't work well with some of the alignment functions that now
2362returns @code{nil} instead of zero to be more usable in lists. You
2363should therefore leave @code{c-strict-syntax-p} set to @code{nil}.}.
2364
6bf7aab6
DL
2365So, for example, because most of the default offsets are defined in
2366terms of @code{+}, @code{-}, and @code{0}, if you like the general
2367indentation style, but you use 4 spaces instead of 2 spaces per level,
2368you can probably achieve your style just by changing
d7bd46ed
GM
2369@code{c-basic-offset} like so@footnote{You can try this interactively in
2370a C buffer by typing the text that appears in italics.}:
6bf7aab6 2371
6b61353c 2372@example
d7bd46ed
GM
2373@emph{M-x set-variable RET}
2374Set variable: @emph{c-basic-offset RET}
2375Set c-basic-offset to value: @emph{4 RET}
6bf7aab6
DL
2376@end example
2377
2378@noindent
2379This would change
6b61353c 2380
6bf7aab6
DL
2381@example
2382@group
6bf7aab6
DL
2383int add( int val, int incr, int doit )
2384@{
2385 if( doit )
2386 @{
2387 return( val + incr );
2388 @}
2389 return( val );
2390@}
6bf7aab6
DL
2391@end group
2392@end example
6b61353c 2393
6bf7aab6
DL
2394@noindent
2395to
6b61353c 2396
6bf7aab6
DL
2397@example
2398@group
6bf7aab6
DL
2399int add( int val, int incr, int doit )
2400@{
2401 if( doit )
2402 @{
2403 return( val + incr );
2404 @}
2405 return( val );
2406@}
6bf7aab6
DL
2407@end group
2408@end example
2409
6bf7aab6 2410To change indentation styles more radically, you will want to change the
d7bd46ed
GM
2411offsets associated with other syntactic symbols. First, I'll show you
2412how to do that interactively, then I'll describe how to make changes to
2413your @file{.emacs} file so that your changes are more permanent.
6bf7aab6
DL
2414
2415@menu
2416* Interactive Customization::
2417* Permanent Customization::
d7bd46ed 2418* Hooks::
6bf7aab6
DL
2419* Styles::
2420* Advanced Customizations::
2421@end menu
2422
6bf7aab6 2423
d7bd46ed
GM
2424@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2425@node Interactive Customization, Permanent Customization, , Customizing Indentation
2426@comment node-name, next, previous, up
6b61353c
KH
2427@section Interactive Customization
2428@cindex customization, interactive
d7bd46ed 2429@cindex interactive customization
6bf7aab6
DL
2430@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2431
2432As an example of how to customize indentation, let's change the
6b61353c 2433style of this example@footnote{In this and subsequent examples, the
6bf7aab6 2434original code is formatted using the @samp{gnu} style unless otherwise
d7bd46ed 2435indicated. @xref{Styles}.}:
6b61353c 2436
6bf7aab6
DL
2437@example
2438@group
6b61353c
KH
2439 1: int add( int val, int incr, int doit )
2440 2: @{
2441 3: if( doit )
2442 4: @{
2443 5: return( val + incr );
2444 6: @}
2445 7: return( val );
2446 8: @}
6bf7aab6
DL
2447@end group
2448@end example
6b61353c 2449
6bf7aab6
DL
2450@noindent
2451to:
6b61353c 2452
6bf7aab6
DL
2453@example
2454@group
6b61353c
KH
2455 1: int add( int val, int incr, int doit )
2456 2: @{
2457 3: if( doit )
2458 4: @{
2459 5: return( val + incr );
2460 6: @}
2461 7: return( val );
2462 8: @}
6bf7aab6
DL
2463@end group
2464@end example
2465
2466In other words, we want to change the indentation of braces that open a
2467block following a condition so that the braces line up under the
2468conditional, instead of being indented. Notice that the construct we
2469want to change starts on line 4. To change the indentation of a line,
2470we need to see which syntactic components affect the offset calculations
2471for that line. Hitting @kbd{C-c C-s} on line 4 yields:
6bf7aab6 2472
6b61353c
KH
2473@example
2474((substatement-open 44))
6bf7aab6
DL
2475@end example
2476
6bf7aab6
DL
2477@noindent
2478so we know that to change the offset of the open brace, we need to
2479change the indentation for the @code{substatement-open} syntactic
6b61353c
KH
2480symbol.
2481
2482To do this interactively, just hit @kbd{C-c C-o}. This prompts
d7bd46ed
GM
2483you for the syntactic symbol to change, providing a reasonable default.
2484In this case, the default is @code{substatement-open}, which is just the
2485syntactic symbol we want to change!
6bf7aab6
DL
2486
2487After you hit return, @ccmode{} will then prompt you for the new
2488offset value, with the old value as the default. The default in this
2489case is @samp{+}, but we want no extra indentation so enter
2490@samp{0} and @kbd{RET}. This will associate the offset 0 with the
d7bd46ed 2491syntactic symbol @code{substatement-open}.
6bf7aab6 2492
6bf7aab6
DL
2493To check your changes quickly, just hit @kbd{C-c C-q}
2494(@code{c-indent-defun}) to reindent the entire function. The example
2495should now look like:
6b61353c 2496
6bf7aab6
DL
2497@example
2498@group
6b61353c
KH
2499 1: int add( int val, int incr, int doit )
2500 2: @{
2501 3: if( doit )
2502 4: @{
2503 5: return( val + incr );
2504 6: @}
2505 7: return( val );
2506 8: @}
6bf7aab6
DL
2507@end group
2508@end example
2509
2510Notice how just changing the open brace offset on line 4 is all we
2511needed to do. Since the other affected lines are indented relative to
2512line 4, they are automatically indented the way you'd expect. For more
2513complicated examples, this may not always work. The general approach to
2514take is to always start adjusting offsets for lines higher up in the
6b61353c 2515file, then reindent and see if any following lines need further
6bf7aab6
DL
2516adjustments.
2517
6b61353c
KH
2518@deffn Command c-set-offset symbol offset
2519@findex set-offset (c-)
2520@kindex C-c C-o
2521This is the command bound to @kbd{C-c C-o}. It provides a convenient
2522way to set offsets on @code{c-offsets-alist} both interactively (see
2523the example above) and from your mode hook.
2524
2525It takes two arguments when used programmatically: @var{symbol} is the
2526syntactic element symbol to change and @var{offset} is the new offset
2527for that syntactic element.
2528@end deffn
2529
d7bd46ed
GM
2530
2531@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2532@node Permanent Customization, Hooks, Interactive Customization, Customizing Indentation
2533@comment node-name, next, previous, up
6b61353c
KH
2534@section Permanent Customization
2535@cindex customization, permanent
d7bd46ed 2536@cindex permanent customization
6bf7aab6 2537@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6bf7aab6 2538
d7bd46ed
GM
2539To make your changes permanent, you need to add some lisp code to your
2540@file{.emacs} file. @ccmode{} supports many different ways to be
2541configured, from the straightforward way by setting variables globally
2542in @file{.emacs} or in the Customization interface, to the complex and
2543precisely controlled way by using styles and hook functions.
2544
2545The simplest way of customizing @ccmode{} permanently is to set the
2546variables in your @file{.emacs} with @code{setq} and similar commands.
6b61353c
KH
2547So to make a permanent setting of @code{substatement-open} to 0, add
2548this to the @file{.emacs} file:
2549
d7bd46ed
GM
2550@example
2551@group
6b61353c
KH
2552(setq c-offsets-alist
2553 '((substatement-open . 0)))
d7bd46ed
GM
2554@end group
2555@end example
2556
6b61353c
KH
2557When @ccmode{} initializes a buffer, it will fill out
2558@code{c-offsets-alist} with the remaining syntactic symbols according to
2559the style system.
d7bd46ed
GM
2560
2561You can also use the more user friendly Customization interface, but
2562this manual does not cover how that works.
2563
2564Variables set like this at the top level in @file{.emacs} take effect in
2565all @ccmode{} buffers, regardless of language. The indentation style
6b61353c 2566related variables, e.g. @code{c-offsets-alist}, that you don't set this
f214c025
GM
2567way get their value from the style system (@pxref{Styles}), and they
2568therefore depend on the setting of @code{c-default-style}. Note that if
2569you use Customize, this means that the greyed-out default values
2570presented there might not be the ones you actually get, since the actual
2571values depend on the style, which may very well be different for
2572different languages.
d7bd46ed
GM
2573
2574If you want to make more advanced configurations, e.g. language-specific
6b61353c 2575customization, setting global variables isn't enough. For that you can
d7bd46ed
GM
2576use the language hooks, see @ref{Hooks}, and/or the style system, see
2577@ref{Styles}.
2578
6b61353c 2579@defopt c-style-variables-are-local-p
d7bd46ed 2580@vindex style-variables-are-local-p (c-)
6b61353c
KH
2581By default, all style variables are buffer local, so that different
2582buffers can have different style settings. If you only use one style
2583in all the files you edit you might want to share them between buffers
2584so that a change take effect in all buffers. That's done by setting
2585this variable to @code{nil}. The value takes effect when @ccmode{} is
2586activated in a buffer for the first time in the Emacs session, so you
2587typically set it in your @file{.emacs} file and then restart Emacs.
2588@end defopt
d7bd46ed
GM
2589
2590
2591@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2592@node Hooks, Styles, Permanent Customization, Customizing Indentation
2593@comment node-name, next, previous, up
6b61353c
KH
2594@section Hooks
2595@cindex mode hooks
6bf7aab6
DL
2596@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2597
d7bd46ed
GM
2598@ccmode{} provides several hooks that you can use to customize the mode
2599according to your coding style. Each language mode has its own hook,
2600adhering to standard Emacs major mode conventions. There is also one
2601general hook and one package initialization hook:
6bf7aab6 2602
6b61353c
KH
2603@defvar c-initialization-hook
2604@vindex initialization-hook (c-)
2605Hook run only once per Emacs session, when @ccmode{} is initialized.
2606@end defvar
6bf7aab6 2607
6b61353c
KH
2608@defvar c-mode-common-hook
2609@vindex mode-common-hook (c-)
2610Common hook across all languages. It's run immediately before the
2611language specific hook.
2612@end defvar
2613
2614@defvar c-mode-hook
2615@defvarx c++-mode-hook
2616@defvarx objc-mode-hook
2617@defvarx java-mode-hook
2618@defvarx idl-mode-hook
2619@defvarx pike-mode-hook
2620@defvarx awk-mode-hook
2621The language specific mode hooks. The appropriate one is run as the
2622last thing when you enter that language mode.
2623@end defvar
cb7f2e96
GM
2624
2625Note that all the language-specific mode setup that CC Mode does is done
2626prior to both @code{c-mode-common-hook} and the language specific hook.
2627That includes installing the indentation style, which can be mode
2628specific (and also is by default for Java mode). Thus, any style
2629settings done in @code{c-mode-common-hook} will override whatever
2630language-specific style is chosen by @code{c-default-style}.
6bf7aab6
DL
2631
2632Here's a simplified example of what you can add to your @file{.emacs}
d7bd46ed
GM
2633file to do things whenever any @ccmode{} language is edited. See the
2634Emacs manuals for more information on customizing Emacs via hooks.
2635@xref{Sample .emacs File}, for a more complete sample @file{.emacs}
2636file.
6bf7aab6 2637
6b61353c 2638@example
6bf7aab6
DL
2639(defun my-c-mode-common-hook ()
2640 ;; my customizations for all of c-mode and related modes
d7bd46ed 2641 (no-case-fold-search)
6bf7aab6
DL
2642 )
2643(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
6bf7aab6
DL
2644@end example
2645
6bf7aab6
DL
2646
2647@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
d7bd46ed
GM
2648@node Styles, Advanced Customizations, Hooks, Customizing Indentation
2649@comment node-name, next, previous, up
6b61353c 2650@section Styles
d7bd46ed 2651@cindex styles
6bf7aab6
DL
2652@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2653
2654Most people only need to edit code formatted in just a few well-defined
2655and consistent styles. For example, their organization might impose a
2656``blessed'' style that all its programmers must conform to. Similarly,
d7bd46ed
GM
2657people who work on GNU software will have to use the GNU coding style.
2658Some shops are more lenient, allowing a variety of coding styles, and as
2659programmers come and go, there could be a number of styles in use. For
2660this reason, @ccmode{} makes it convenient for you to set up logical
2661groupings of customizations called @dfn{styles}, associate a single name
2662for any particular style, and pretty easily start editing new or
2663existing code using these styles.
2664
2665@cindex style variables
2666The variables that the style system affect are called @dfn{style
2667variables}. They are handled specially in several ways:
2668
2669@itemize @bullet
2670@item
6b61353c
KH
2671Style variables are by default buffer local variables. However, they
2672can instead be made global by setting
2673@code{c-style-variables-are-local-p} to @code{nil} before @ccmode{} is
2674initialized.
d7bd46ed 2675
6b61353c 2676@item
d7bd46ed
GM
2677@vindex c-old-style-variable-behavior
2678@vindex old-style-variable-behavior (c-)
d7bd46ed
GM
2679The default value of any style variable (with two exceptions --- see
2680below) is the special symbol @code{set-from-style}. Variables that are
2681still set to that symbol when a @ccmode{} buffer is initialized will be
2682set according to the current style, otherwise they will keep their
2683current value@footnote{This is a big change from versions of @ccmode{}
2684earlier than 5.26, where such settings would get overridden by the style
2685system unless special precautions were taken. That was changed since it
2686was counterintuitive and confusing, especially to novice users. If your
2687configuration depends on the old overriding behavior, you can set the
2688variable @code{c-old-style-variable-behavior} to non-@code{nil}.}.
2689
2690Note that when we talk about the ``default value'' for a style variable,
2691we don't mean the @code{set-from-style} symbol that all style variables
2692are set to initially, but instead the value it will get at mode
2693initialization when neither a style nor a global setting has set its
2694value.
2695
2696The style variable @code{c-offsets-alist} is handled a little
2697differently from the other style variables. It's an association list,
2698and is thus by default set to the empty list, @code{nil}. When the
2699style system is initialized, any syntactic symbols already on it are
2700kept --- only the missing ones are filled in from the chosen style.
2701
2702The style variable @code{c-special-indent-hook} is also handled in a
2703special way. Styles may only add more functions on this hook, so the
2704global settings on it are always preserved@footnote{This did not change
2705in version 5.26.}.
2706
2707@item
2708The global settings of style variables get captured in the special
2709@code{user} style, which is used as the base for all the other styles.
2710@xref{Built-in Styles}, for details.
d7bd46ed
GM
2711@end itemize
2712
2713The style variables are:
2714@code{c-basic-offset},
2715@code{c-comment-only-line-offset},
2716@code{c-block-comment-prefix},
2717@code{c-comment-prefix-regexp},
2718@code{c-cleanup-list},
2719@code{c-hanging-braces-alist},
2720@code{c-hanging-colons-alist},
2721@code{c-hanging-semi&comma-criteria},
2722@code{c-backslash-column},
6b61353c 2723@code{c-backslash-max-column},
d7bd46ed
GM
2724@code{c-special-indent-hook},
2725@code{c-label-minimum-indentation}, and
2726@code{c-offsets-alist}.
6bf7aab6
DL
2727
2728@menu
2729* Built-in Styles::
6b61353c 2730* Choosing a Style::
6bf7aab6
DL
2731* Adding Styles::
2732* File Styles::
2733@end menu
2734
2735
2736@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6b61353c 2737@node Built-in Styles, Choosing a Style, , Styles
d7bd46ed
GM
2738@comment node-name, next, previous, up
2739@subsection Built-in Styles
6b61353c 2740@cindex styles, built-in
6bf7aab6
DL
2741@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2742
2743If you're lucky, one of @ccmode{}'s built-in styles might be just
2744what you're looking for. These include:
2745
6b61353c
KH
2746@table @code
2747@item gnu
6bf7aab6 2748@cindex GNU style
6b61353c 2749Coding style blessed by the Free Software Foundation
d7bd46ed 2750for C code in GNU programs.
6bf7aab6 2751
6b61353c 2752@item k&r
6bf7aab6 2753@cindex K&R style
6b61353c 2754The classic Kernighan and Ritchie style for C code.
6bf7aab6 2755
6b61353c 2756@item bsd
6bf7aab6 2757@cindex BSD style
6b61353c 2758Also known as ``Allman style'' after Eric Allman.
6bf7aab6 2759
6b61353c
KH
2760@item whitesmith
2761@cindex Whitesmith style
2762Popularized by the examples that came with Whitesmiths C, an early
2763commercial C compiler.
6bf7aab6 2764
6b61353c 2765@item stroustrup
6bf7aab6 2766@cindex Stroustrup style
6b61353c 2767The classic Stroustrup style for C++ code.
6bf7aab6 2768
6b61353c 2769@item ellemtel
6bf7aab6 2770@cindex Ellemtel style
6b61353c
KH
2771Popular C++ coding standards as defined by ``Programming in C++, Rules
2772and Recommendations,'' Erik Nyquist and Mats Henricson,
2773Ellemtel@footnote{This document is available at
d7bd46ed
GM
2774@uref{http://www.doc.ic.ac.uk/lab/cplus/c++.rules/} among other
2775places.}.
6bf7aab6 2776
6b61353c 2777@item linux
6bf7aab6 2778@cindex Linux style
6b61353c 2779C coding standard for Linux (the kernel).
6bf7aab6 2780
6b61353c 2781@item python
6bf7aab6 2782@cindex Python style
6b61353c
KH
2783C coding standard for Python extension modules@footnote{Python is a
2784high level scripting language with a C/C++ foreign function interface.
2785For more information, see @uref{http://www.python.org/}.}.
6bf7aab6 2786
6b61353c 2787@item java
6bf7aab6 2788@cindex Java style
6b61353c 2789The style for editing Java code. Note that the default
cb7f2e96
GM
2790value for @code{c-default-style} installs this style when you enter
2791@code{java-mode}.
6bf7aab6 2792
6b61353c 2793@item user
6bf7aab6 2794@cindex User style
6b61353c 2795This is a special style for several reasons. First, the
d7bd46ed
GM
2796@ccmode{} customizations you do by using either the Customization
2797interface, or by writing @code{setq}'s at the top level of your
2798@file{.emacs} file, will be captured in the @code{user} style. Also,
2799all other styles implicitly inherit their settings from @code{user}
2800style. This means that for any styles you add via @code{c-add-style}
2801(@pxref{Adding Styles}) you need only define the differences between
2802your new style and @code{user} style.
6b61353c 2803@end table
d7bd46ed 2804
d7bd46ed 2805
6b61353c
KH
2806@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2807@node Choosing a Style, Adding Styles, Built-in Styles, Styles
2808@comment node-name, next, previous, up
2809@subsection Choosing a Style
2810@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2811
2812Use @kbd{C-c .} to choose a style interactively:
2813
2814@deffn Command c-set-style style-name
2815@findex set-style (c-)
2816@kindex C-c .
2817Switch to the specified style in the current buffer. Use
2818interactively like this:
2819
2820@example
2821@kbd{C-c . @var{style-name} RET}
2822@end example
2823
2824Note that all style names are case insensitive, even the ones you
2825define.
2826
2827Setting a style in this way does @emph{not} automatically reindent your
2828file. For commands that you can use to view the effect of your changes,
2829see @ref{Commands}.
2830@end deffn
2831
2832The default style in all newly created buffers is @code{gnu}, except
2833in Java mode where it's @code{java}. Although the @code{user} style
2834is not the default style, any style variable settings you do with the
2835Customization interface or on the top level in your @file{.emacs} file
2836will by default override the style system, so you don't need to set
2837@code{c-default-style} to @code{user} to see the effect of such
2838settings.
2839
2840@defopt c-default-style
2841@vindex default-style (c-)
2842This variable specifies which style to install by default in new
2843buffers. It takes either a style name string, or an association list
2844of major mode symbols to style names:
2845
2846@enumerate
2847@item
2848When @code{c-default-style} is a string, it must be an existing style
2849name. This style is then used for all modes.
6bf7aab6 2850
d7bd46ed 2851@item
6b61353c
KH
2852When @code{c-default-style} is an association list, the mode language
2853is looked up to find a style name string.
d7bd46ed
GM
2854
2855@item
6b61353c
KH
2856If @code{c-default-style} is an association list where the mode
2857language mode isn't found then the special symbol @samp{other} is
2858looked up. If it's found then the associated style is used.
d7bd46ed
GM
2859
2860@item
6b61353c 2861If @samp{other} is not found then the @samp{gnu} style is used.
d7bd46ed
GM
2862
2863@item
6b61353c 2864In all cases, the style described in @code{c-default-style} is installed
d7bd46ed 2865@emph{before} the language hooks are run, so you can always override
6b61353c 2866this setting by including an explicit call to @code{c-set-style} in your
d7bd46ed 2867language mode hook, or in @code{c-mode-common-hook}.
d7bd46ed 2868@end enumerate
6b61353c 2869@end defopt
6bf7aab6 2870
6b61353c 2871@defvar c-indentation-style
6bf7aab6 2872@vindex indentation-style (c-)
6b61353c
KH
2873This variable always contains the buffer's current style name, as a
2874string.
2875@end defvar
6bf7aab6
DL
2876
2877
2878@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6b61353c 2879@node Adding Styles, File Styles, Choosing a Style, Styles
d7bd46ed
GM
2880@comment node-name, next, previous, up
2881@subsection Adding Styles
6bf7aab6
DL
2882@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2883
6bf7aab6
DL
2884If none of the built-in styles is appropriate, you'll probably want to
2885add a new @dfn{style definition}. Styles are kept in the
6b61353c
KH
2886@code{c-style-alist} variable, but you should never modify this
2887variable directly. Instead, @ccmode{} provides the function
6bf7aab6 2888@code{c-add-style} that you can use to easily add new styles or change
6b61353c
KH
2889existing styles:
2890
2891@defun c-add-style stylename description &optional set-p
2892@findex add-style (c-)
2893Add or update a style. If @var{stylename} is not already in
2894@code{c-style-alist} then a new style according to @var{description}
2895is added, otherwise the existing style is changed. If the optional
2896@var{set-p} is non-@code{nil} then the new style is applied to the
2897current buffer as well.
6bf7aab6
DL
2898
2899@comment TBD: The next paragraph is bogus. I really need to better
2900@comment document adding styles, including setting up inherited styles.
2901
2902The sample @file{.emacs} file provides a concrete example of how a new
2903style can be added and automatically set. @xref{Sample .emacs File}.
6b61353c
KH
2904@end defun
2905
2906@defvar c-style-alist
2907@vindex style-alist (c-)
2908This is the variable that holds the definitions for the styles. It
2909should not be changed directly; use @code{c-add-style} instead.
2910@end defvar
6bf7aab6 2911
6bf7aab6 2912
d7bd46ed
GM
2913@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2914@node File Styles, , Adding Styles, Styles
2915@comment node-name, next, previous, up
2916@subsection File Styles
6b61353c 2917@cindex styles, file local
6bf7aab6
DL
2918@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2919
6b61353c 2920@cindex file local variables
6bf7aab6 2921
6b61353c
KH
2922The Emacs manual describes how you can customize certain variables on
2923a per-file basis by including a @dfn{file local variable} block at the
2924end of the file. So far, you've only seen a functional interface to
2925@ccmode{} customization, which can't be used there. @ccmode{}
2926provides two variables allow customization of the indentation style on
2927a per-file basis:
6bf7aab6 2928
6b61353c 2929@defvar c-file-style
6bf7aab6 2930@vindex file-style (c-)
6b61353c
KH
2931This variable can be set to a style name string. When the file is
2932visited, @ccmode{} will automatically set the file's style to this
2933one using @code{c-set-style}.
2934@end defvar
6bf7aab6 2935
6b61353c
KH
2936@defvar c-file-offsets
2937@vindex file-offsets (c-)
2938This variable takes an association list similar to what is allowed in
2939@code{c-offsets-alist}. When the file is visited, @ccmode{} will
2940automatically institute these offsets using @code{c-set-offset}.
2941@end defvar
6bf7aab6
DL
2942
2943Note that file style settings (i.e. @code{c-file-style}) are applied
2944before file offset settings (i.e. @code{c-file-offsets}). Also, if
2945either of these are set in a file's local variable section, all the
2946style variable values are made local to that buffer.
2947
2948
2949@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
d7bd46ed
GM
2950@node Advanced Customizations, , Styles, Customizing Indentation
2951@comment node-name, next, previous, up
6b61353c 2952@section Advanced Customizations
6bf7aab6
DL
2953@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2954
6b61353c
KH
2955For most users, @ccmode{} will support their coding styles with very
2956little need for more advanced customizations. Usually, one of the
2957standard styles (@pxref{Built-in Styles}) will do the trick. At most,
2958perhaps one of the syntactic symbol offsets will need to be tweaked
2959slightly, or maybe @code{c-basic-offset} will need to be changed.
2960However, some styles require a more flexible framework for
2961customization, and one of the real strengths of @ccmode{} is that the
2962syntactic analysis model provides just such a framework. This allows
6bf7aab6
DL
2963you to implement custom indentation calculations for situations not
2964handled by the mode directly.
2965
6bf7aab6
DL
2966@menu
2967* Custom Indentation Functions::
2968* Custom Brace and Colon Hanging::
6b61353c 2969* Customizing Semicolons and Commas::
6bf7aab6
DL
2970* Other Special Indentations::
2971@end menu
2972
2973@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
d7bd46ed
GM
2974@node Custom Indentation Functions, Custom Brace and Colon Hanging, , Advanced Customizations
2975@comment node-name, next, previous, up
2976@subsection Custom Indentation Functions
6b61353c 2977@cindex customization, indentation functions
6bf7aab6
DL
2978@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2979
d7bd46ed
GM
2980The most flexible way to customize @ccmode{} is by writing custom
2981indentation functions, and associating them with specific syntactic
2982symbols (@pxref{Syntactic Symbols}). @ccmode{} itself uses indentation
2983functions to provide more sophisticated indentation, for example when
2984lining up C++ stream operator blocks:
6b61353c 2985
6bf7aab6
DL
2986@example
2987@group
6b61353c
KH
2988 1: void main(int argc, char**)
2989 2: @{
2990 3: cout << "There were "
2991 4: << argc
2992 5: << "arguments passed to the program"
2993 6: << endl;
2994 7: @}
6bf7aab6
DL
2995@end group
2996@end example
2997
2998In this example, lines 4 through 6 are assigned the @code{stream-op}
2999syntactic symbol. Here, @code{stream-op} has an offset of @code{+}, and
3000with a @code{c-basic-offset} of 2, you can see that lines 4 through 6
3001are simply indented two spaces to the right of line 3. But perhaps we'd
3002like @ccmode{} to be a little more intelligent so that it aligns
3003all the @samp{<<} symbols in lines 3 through 6. To do this, we have
6b61353c
KH
3004to write a custom indentation function which finds the column of the first
3005stream operator on the first line of the statement. Here is sample
6bf7aab6 3006lisp code implementing this:
6bf7aab6 3007
6b61353c 3008@example
6bf7aab6 3009(defun c-lineup-streamop (langelem)
6bf7aab6 3010 (save-excursion
6b61353c
KH
3011 (goto-char (cdr langelem))
3012 (re-search-forward "<<\\|>>" (c-point 'eol) 'move)
3013 (goto-char (match-beginning 0))
3014 (vector (current-column))))
6bf7aab6 3015@end example
6b61353c 3016
d7bd46ed 3017Indentation functions take a single argument, which is a syntactic
6b61353c
KH
3018component cons cell (@pxref{Syntactic Analysis}). The function can
3019return an integer which is added to the running total indentation for
3020the line, or a vector containing an integer which is an absolute
3021column to align to. Usually an absolute column is wanted when
3022aligning to existing text, as in this example.
d7bd46ed
GM
3023
3024The function should return @code{nil} if it's used in a situation where
6b61353c 3025it doesn't want to make any decision. If the function is used in a list
d7bd46ed
GM
3026expression (@pxref{Customizing Indentation}), that will cause @ccmode{}
3027to go on and check the next entry in the list.
6bf7aab6 3028
6bf7aab6
DL
3029Now, to associate the function @code{c-lineup-streamop} with the
3030@code{stream-op} syntactic symbol, we can add something like the
3031following to our @code{c++-mode-hook}@footnote{It probably makes more
3032sense to add this to @code{c++-mode-hook} than @code{c-mode-common-hook}
d7bd46ed 3033since stream operators are only relevant for C++.}:
6bf7aab6 3034
6b61353c 3035@example
6bf7aab6 3036(c-set-offset 'stream-op 'c-lineup-streamop)
6bf7aab6
DL
3037@end example
3038
6b61353c 3039Now the function looks like this after reindenting (using @kbd{C-c
6bf7aab6 3040C-q}):
6b61353c 3041
6bf7aab6
DL
3042@example
3043@group
6b61353c
KH
3044 1: void main(int argc, char**)
3045 2: @{
3046 3: cout << "There were "
3047 4: << argc
3048 5: << " arguments passed to the program"
3049 6: << endl;
3050 7: @}
6bf7aab6
DL
3051@end group
3052@end example
3053
6bf7aab6
DL
3054Custom indentation functions can be as simple or as complex as you like,
3055and any syntactic symbol that appears in @code{c-offsets-alist} can have
d7bd46ed 3056a custom indentation function associated with it.
6bf7aab6 3057
d7bd46ed
GM
3058@ccmode{} comes with an extensive set of predefined indentation
3059functions, not all of which are used by the default styles. So there's
3060a good chance the function you want already exists. @xref{Indentation
3061Functions}, for a list of them. If you have written an indentation
3062function that you think is generally useful, you're very welcome to
3063contribute it; please contact @email{bug-cc-mode@@gnu.org}.
6bf7aab6 3064
6bf7aab6
DL
3065
3066@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6b61353c 3067@node Custom Brace and Colon Hanging, Customizing Semicolons and Commas, Custom Indentation Functions, Advanced Customizations
d7bd46ed
GM
3068@comment node-name, next, previous, up
3069@subsection Custom Brace and Colon Hanging
6bf7aab6
DL
3070@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3071
3072@vindex c-hanging-braces-alist
3073@vindex hanging-braces-alist (c-)
3074Syntactic symbols aren't the only place where you can customize
3075@ccmode{} with the lisp equivalent of callback functions. Brace
3076``hanginess'' can also be determined by custom functions associated with
d7bd46ed 3077syntactic symbols on the @code{c-hanging-braces-alist} style variable.
6b61353c 3078Remember that @var{action}'s are typically a list containing some
d7bd46ed 3079combination of the symbols @code{before} and @code{after}
6b61353c 3080(@pxref{Hanging Braces}). However, an @var{action} can also be a
d7bd46ed
GM
3081function which gets called when a brace matching that syntactic symbol
3082is entered.
6bf7aab6 3083
6b61353c
KH
3084@cindex customization, brace hanging
3085These @var{action} functions are called with two arguments: the
6bf7aab6 3086syntactic symbol for the brace, and the buffer position at which the
6b61353c 3087brace was inserted. The @var{action} function is expected to return a
d7bd46ed
GM
3088list containing some combination of @code{before} and @code{after},
3089including neither of them (i.e. @code{nil}). This return value has the
3090normal brace hanging semantics.
6bf7aab6
DL
3091
3092As an example, @ccmode{} itself uses this feature to dynamically
3093determine the hanginess of braces which close ``do-while''
3094constructs:
6bf7aab6 3095
6b61353c 3096@example
6bf7aab6
DL
3097void do_list( int count, char** atleast_one_string )
3098@{
3099 int i=0;
3100 do @{
3101 handle_string( atleast_one_string[i] );
3102 i++;
3103 @} while( i < count );
3104@}
6bf7aab6
DL
3105@end example
3106
6bf7aab6
DL
3107@ccmode{} assigns the @code{block-close} syntactic symbol to the
3108brace that closes the @code{do} construct, and normally we'd like the
3109line that follows a @code{block-close} brace to begin on a separate
3110line. However, with ``do-while'' constructs, we want the
3111@code{while} clause to follow the closing brace. To do this, we
6b61353c 3112associate the @code{block-close} symbol with the @var{action} function
6bf7aab6 3113@code{c-snug-do-while}:
6bf7aab6 3114
6b61353c 3115@example
6bf7aab6 3116(defun c-snug-do-while (syntax pos)
6b61353c 3117 "Dynamically calculate brace hanginess for do-while statements."
6bf7aab6
DL
3118 (save-excursion
3119 (let (langelem)
3120 (if (and (eq syntax 'block-close)
3121 (setq langelem (assq 'block-close c-syntactic-context))
3122 (progn (goto-char (cdr langelem))
3123 (if (= (following-char) ?@{)
3124 (forward-sexp -1))
3125 (looking-at "\\<do\\>[^_]")))
3126 '(before)
3127 '(before after)))))
6bf7aab6
DL
3128@end example
3129
6b61353c
KH
3130@findex c-snug-do-while
3131@findex snug-do-while (c-)
6bf7aab6
DL
3132This function simply looks to see if the brace closes a ``do-while''
3133clause and if so, returns the list @samp{(before)} indicating
3134that a newline should be inserted before the brace, but not after it.
3135In all other cases, it returns the list @samp{(before after)} so
3136that the brace appears on a line by itself.
3137
6b61353c 3138@defvar c-syntactic-context
6bf7aab6 3139@vindex syntactic-context (c-)
6b61353c
KH
3140During the call to the indentation or brace hanging @var{action}
3141function, this variable is bound to the full syntactic analysis list.
3142@end defvar
6bf7aab6 3143
6b61353c
KH
3144@cindex customization, colon hanging
3145@vindex c-hanging-colons-alist
3146@vindex hanging-colons-alist (c-)
6bf7aab6 3147Note that for symmetry, colon hanginess should be customizable by
6b61353c
KH
3148allowing function symbols as @var{action}s on the
3149@code{c-hanging-colons-alist} style variable. Since no use has actually
d7bd46ed 3150been found for this feature, it isn't currently implemented!
6bf7aab6 3151
6bf7aab6 3152
d7bd46ed 3153@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6b61353c 3154@node Customizing Semicolons and Commas, Other Special Indentations, Custom Brace and Colon Hanging, Advanced Customizations
d7bd46ed 3155@comment node-name, next, previous, up
6b61353c
KH
3156@subsection Customizing Semicolons and Commas
3157@cindex customization, semicolon newlines
3158@cindex customization, comma newlines
6bf7aab6
DL
3159@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3160
6b61353c
KH
3161You can also customize the insertion of newlines after semicolons and
3162commas when the auto-newline minor mode is enabled (@pxref{Minor
3163Modes}).
6bf7aab6 3164
6b61353c
KH
3165@defopt c-hanging-semi&comma-criteria
3166@vindex hanging-semi&comma-criteria (c-)
3167This style variable takes a list of hooks that get called when a
3168semicolon or comma is inserted. The hooks are called in order without
3169arguments, and are expected to return one of the following values:
6bf7aab6 3170
6b61353c
KH
3171@table @code
3172@item t
3173A newline is inserted, and no more functions from the list are called.
3174@item stop
3175No more functions from the list are called, but no newline is
3176inserted.
3177@item nil
3178No determination is made, and the next function in the list is called.
3179@end table
6bf7aab6
DL
3180
3181If every function in the list is called without a determination being
3182made, then no newline is added. The default value for this variable is a
3183list containing a single function which inserts newlines only after
6b61353c 3184semicolons which do not appear inside parenthesis lists (i.e. those
6bf7aab6 3185that separate @code{for}-clause statements).
6b61353c 3186@end defopt
6bf7aab6 3187
6b61353c 3188@defun c-semi&comma-no-newlines-before-nonblanks
6bf7aab6 3189@findex semi&comma-no-newlines-before-nonblanks (c-)
6b61353c
KH
3190This is an example of a criteria function, provided by @ccmode{}. It
3191prevents newlines from being inserted after semicolons when there is a
3192non-blank following line. Otherwise, it makes no determination. To
3193use, add this function to the front of the
3194@code{c-hanging-semi&comma-criteria} list.
6bf7aab6
DL
3195
3196@example
6bf7aab6
DL
3197(defun c-semi&comma-no-newlines-before-nonblanks ()
3198 (save-excursion
3199 (if (and (eq last-command-char ?\;)
3200 (zerop (forward-line 1))
3201 (not (looking-at "^[ \t]*$")))
3202 'stop
3203 nil)))
6bf7aab6 3204@end example
6b61353c 3205@end defun
6bf7aab6 3206
6b61353c 3207@defun c-semi&comma-inside-parenlist
6bf7aab6 3208@findex semi&comma-inside-parenlist (c-)
6b61353c 3209@defunx c-semi&comma-no-newlines-for-oneline-inliners
6bf7aab6 3210@findex semi&comma-no-newlines-for-oneline-inliners (c-)
d7bd46ed
GM
3211The function @code{c-semi&comma-inside-parenlist} is what prevents
3212newlines from being inserted inside the parenthesis list of @code{for}
3213statements. In addition to
6bf7aab6
DL
3214@code{c-semi&comma-no-newlines-before-nonblanks} described above,
3215@ccmode{} also comes with the criteria function
3216@code{c-semi&comma-no-newlines-for-oneline-inliners}, which suppresses
3217newlines after semicolons inside one-line inline method definitions
6b61353c
KH
3218(e.g. in C++ or Java).
3219@end defun
6bf7aab6 3220
6bf7aab6 3221
d7bd46ed 3222@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6b61353c 3223@node Other Special Indentations, , Customizing Semicolons and Commas, Advanced Customizations
d7bd46ed
GM
3224@comment node-name, next, previous, up
3225@subsection Other Special Indentations
6bf7aab6
DL
3226@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3227
6b61353c
KH
3228Here are the remaining odds and ends regarding indentation:
3229
3230@defopt c-label-minimum-indentation
6bf7aab6 3231@vindex label-minimum-indentation (c-)
d7bd46ed 3232In @samp{gnu} style (@pxref{Built-in Styles}), a minimum indentation
6bf7aab6 3233is imposed on lines inside top-level constructs. This minimum
6b61353c 3234indentation is controlled by this style variable. The default value
6bf7aab6 3235is 1.
6b61353c 3236@end defopt
6bf7aab6 3237
6b61353c 3238@defopt c-special-indent-hook
6bf7aab6 3239@vindex special-indent-hook (c-)
6b61353c
KH
3240This style variable is a standard hook variable that is called after
3241every line is indented by @ccmode{}. You can use it to do any special
3242indentation or line adjustments your style dictates, such as adding
3243extra indentation to constructors or destructor declarations in a
3244class definition, etc. Note that you should not change point or mark
3245inside your @code{c-special-indent-hook} functions, i.e. you'll
3246probably want to wrap your function in a @code{save-excursion}.
3247
3248Setting @code{c-special-indent-hook} in your style definition is
3249handled slightly differently than other variables. In your style
3250definition, you should set the value for @code{c-special-indent-hook}
3251to a function or list of functions, which will be appended to
3252@code{c-special-indent-hook} using @code{add-hook}. That way, the
3253current setting for the buffer local value of
6bf7aab6 3254@code{c-special-indent-hook} won't be overridden.
6b61353c 3255@end defopt
d7bd46ed 3256
6bf7aab6 3257
d7bd46ed
GM
3258@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3259@node Syntactic Symbols, Indentation Functions, Customizing Indentation, Top
3260@comment node-name, next, previous, up
6b61353c 3261@chapter Syntactic Symbols
6bf7aab6
DL
3262@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3263
6b61353c 3264@cindex syntactic symbols, brief list
6bf7aab6
DL
3265@vindex c-offsets-alist
3266@vindex offsets-alist (c-)
6bf7aab6 3267Here is a complete list of the recognized syntactic symbols as described
d7bd46ed
GM
3268in the @code{c-offsets-alist} style variable, along with a brief
3269description. More detailed descriptions follow.
6bf7aab6 3270
d7bd46ed
GM
3271@table @code
3272@item string
6b61353c 3273Inside a multiline string.
d7bd46ed 3274@item c
6b61353c 3275Inside a multiline C style block comment.
d7bd46ed
GM
3276@item defun-open
3277Brace that opens a top-level function definition.
3278@item defun-close
3279Brace that closes a top-level function definition.
3280@item defun-block-intro
3281The first line in a top-level defun.
3282@item class-open
3283Brace that opens a class definition.
3284@item class-close
3285Brace that closes a class definition.
3286@item inline-open
3287Brace that opens an in-class inline method.
3288@item inline-close
3289Brace that closes an in-class inline method.
3290@item func-decl-cont
3291The region between a function definition's argument list and the
3292function opening brace (excluding K&R argument declarations). In C, you
3293cannot put anything but whitespace and comments in this region, however
3294in C++ and Java, @code{throws} declarations and other things can appear
3295here.
3296@item knr-argdecl-intro
3297First line of a K&R C argument declaration.
3298@item knr-argdecl
3299Subsequent lines in a K&R C argument declaration.
3300@item topmost-intro
3301The first line in a ``topmost'' definition.
3302@item topmost-intro-cont
6b61353c
KH
3303Topmost definition continuation lines. This is only used in the parts
3304that aren't covered by other symbols such as @code{func-decl-cont} and
3305@code{knr-argdecl}.
d7bd46ed
GM
3306@item member-init-intro
3307First line in a member initialization list.
3308@item member-init-cont
3309Subsequent member initialization list lines.
3310@item inher-intro
3311First line of a multiple inheritance list.
3312@item inher-cont
3313Subsequent multiple inheritance lines.
3314@item block-open
3315Statement block open brace.
3316@item block-close
3317Statement block close brace.
3318@item brace-list-open
3319Open brace of an enum or static array list.
3320@item brace-list-close
3321Close brace of an enum or static array list.
3322@item brace-list-intro
3323First line in an enum or static array list.
3324@item brace-list-entry
3325Subsequent lines in an enum or static array list.
3326@item brace-entry-open
3327Subsequent lines in an enum or static array list where the line begins
3328with an open brace.
3329@item statement
3330A statement.
3331@item statement-cont
3332A continuation of a statement.
3333@item statement-block-intro
3334The first line in a new statement block.
3335@item statement-case-intro
3336The first line in a case block.
3337@item statement-case-open
3338The first line in a case block that starts with a brace.
3339@item substatement
3340The first line after a conditional or loop construct.
3341@item substatement-open
3342The brace that opens a substatement block.
6b61353c
KH
3343@item substatement-label
3344The first line after a conditional or loop construct if it's a label.
d7bd46ed 3345@item case-label
6b61353c 3346A label in a @code{switch} block.
d7bd46ed
GM
3347@item access-label
3348C++ access control label.
3349@item label
6b61353c 3350Any other label.
d7bd46ed
GM
3351@item do-while-closure
3352The @code{while} line that ends a @code{do}-@code{while} construct.
3353@item else-clause
3354The @code{else} line of an @code{if}-@code{else} construct.
3355@item catch-clause
3356The @code{catch} or @code{finally} (in Java) line of a
3357@code{try}-@code{catch} construct.
3358@item comment-intro
3359A line containing only a comment introduction.
3360@item arglist-intro
3361The first line in an argument list.
3362@item arglist-cont
3363Subsequent argument list lines when no arguments follow on the same line
6b1f5814 3364as the arglist opening paren.
d7bd46ed
GM
3365@item arglist-cont-nonempty
3366Subsequent argument list lines when at least one argument follows on the
3367same line as the arglist opening paren.
3368@item arglist-close
3369The solo close paren of an argument list.
3370@item stream-op
3371Lines continuing a stream operator (C++ only).
3372@item inclass
3373The line is nested inside a class definition.
3374@item cpp-macro
6b61353c
KH
3375The start of a preprocessor macro definition.
3376@item cpp-define-intro
3377The first line inside a multiline preproprocessor macro if
3378@code{c-syntactic-indentation-in-macros} is set.
d7bd46ed 3379@item cpp-macro-cont
6b61353c
KH
3380All lines inside multiline preprocessor macros if
3381@code{c-syntactic-indentation-in-macros} is @code{nil}.
d7bd46ed
GM
3382@item friend
3383A C++ friend declaration.
3384@item objc-method-intro
6b61353c 3385The first line of an Objective-C method definition.
d7bd46ed 3386@item objc-method-args-cont
6b61353c 3387Lines continuing an Objective-C method definition.
d7bd46ed
GM
3388@item objc-method-call-cont
3389Lines continuing an Objective-C method call.
3390@item extern-lang-open
6b61353c 3391Brace that opens an @code{extern} block (e.g. @code{extern "C" @{...@}}).
d7bd46ed 3392@item extern-lang-close
6b61353c 3393Brace that closes an @code{extern} block.
d7bd46ed 3394@item inextern-lang
6b61353c
KH
3395Analogous to @code{inclass} syntactic symbol, but used inside
3396@code{extern} blocks.
d7bd46ed 3397@item namespace-open
6b61353c
KH
3398@itemx namespace-close
3399@itemx innamespace
3400These are analogous to the three @code{extern-lang} symbols above, but
3401are returned for C++ namespace blocks.
3402@item module-open
3403@itemx module-close
3404@itemx inmodule
3405Analogous to the above, but for CORBA IDL @code{module} blocks.
3406@item composition-open
3407@itemx composition-close
3408@itemx incomposition
3409Analogous to the above, but for CORBA CIDL @code{composition} blocks.
d7bd46ed
GM
3410@item template-args-cont
3411C++ template argument list continuations.
3412@item inlambda
3413Analogous to @code{inclass} syntactic symbol, but used inside lambda
3414(i.e. anonymous) functions. Only used in Pike mode.
3415@item lambda-intro-cont
3416Lines continuing the header of a lambda function, i.e. between the
3417@code{lambda} keyword and the function body. Only used in Pike mode.
3418@item inexpr-statement
3419A statement block inside an expression. The gcc C extension of this is
3420recognized. It's also used for the special functions that takes a
3421statement block as an argument in Pike.
3422@item inexpr-class
3423A class definition inside an expression. This is used for anonymous
3424classes in Java. It's also used for anonymous array initializers in
3425Java.
3426@end table
6bf7aab6 3427
6b61353c
KH
3428@ssindex -open symbols
3429@ssindex -close symbols
6bf7aab6
DL
3430Most syntactic symbol names follow a general naming convention. When a
3431line begins with an open or close brace, the syntactic symbol will
3432contain the suffix @code{-open} or @code{-close} respectively.
3433
6b61353c
KH
3434@ssindex -intro symbols
3435@ssindex -cont symbols
3436@ssindex -block-intro symbols
6bf7aab6
DL
3437Usually, a distinction is made between the first line that introduces a
3438construct and lines that continue a construct, and the syntactic symbols
3439that represent these lines will contain the suffix @code{-intro} or
3440@code{-cont} respectively. As a sub-classification of this scheme, a
3441line which is the first of a particular brace block construct will
3442contain the suffix @code{-block-intro}.
3443
6bf7aab6
DL
3444Let's look at some examples to understand how this works. Remember that
3445you can check the syntax of any line by using @kbd{C-c C-s}.
6bf7aab6 3446
6b61353c
KH
3447@example
3448 1: void
3449 2: swap( int& a, int& b )
3450 3: @{
3451 4: int tmp = a;
3452 5: a = b;
3453 6: b = tmp;
3454 7: int ignored =
3455 8: a + b;
3456 9: @}
6bf7aab6
DL
3457@end example
3458
6b61353c
KH
3459@ssindex topmost-intro
3460@ssindex topmost-intro-cont
3461@ssindex defun-open
3462@ssindex defun-close
3463@ssindex defun-block-intro
6bf7aab6
DL
3464Line 1 shows a @code{topmost-intro} since it is the first line that
3465introduces a top-level construct. Line 2 is a continuation of the
3466top-level construct introduction so it has the syntax
3467@code{topmost-intro-cont}. Line 3 shows a @code{defun-open} since it is
d7bd46ed
GM
3468the brace that opens a top-level function definition. Line 9 is the
3469corresponding
6bf7aab6
DL
3470@code{defun-close} since it contains the brace that closes the top-level
3471function definition. Line 4 is a @code{defun-block-intro}, i.e. it is
3472the first line of a brace-block, enclosed in a
3473top-level function definition.
3474
6b61353c
KH
3475@ssindex statement
3476@ssindex statement-cont
6bf7aab6
DL
3477Lines 5, 6, and 7 are all given @code{statement} syntax since there
3478isn't much special about them. Note however that line 8 is given
3479@code{statement-cont} syntax since it continues the statement begun
3480on the previous line.
3481
3482Here's another example, which illustrates some C++ class syntactic
3483symbols:
6bf7aab6 3484
6b61353c
KH
3485@example
3486 1: class Bass
3487 2: : public Guitar,
3488 3: public Amplifiable
3489 4: @{
3490 5: public:
3491 6: Bass()
3492 7: : eString( new BassString( 0.105 )),
3493 8: aString( new BassString( 0.085 )),
3494 9: dString( new BassString( 0.065 )),
349510: gString( new BassString( 0.045 ))
349611: @{
349712: eString.tune( 'E' );
349813: aString.tune( 'A' );
349914: dString.tune( 'D' );
350015: gString.tune( 'G' );
350116: @}
350217: friend class Luthier;
350318: @};
6bf7aab6
DL
3504@end example
3505
6b61353c
KH
3506@ssindex class-open
3507@ssindex class-close
6bf7aab6
DL
3508As in the previous example, line 1 has the @code{topmost-intro} syntax.
3509Here however, the brace that opens a C++ class definition on line 4 is
3510assigned the @code{class-open} syntax. Note that in C++, classes,
3511structs, and unions are essentially equivalent syntactically (and are
3512very similar semantically), so replacing the @code{class} keyword in the
3513example above with @code{struct} or @code{union} would still result in a
3514syntax of @code{class-open} for line 4 @footnote{This is the case even
3515for C and Objective-C. For consistency, structs in all supported
3516languages are syntactically equivalent to classes. Note however that
3517the keyword @code{class} is meaningless in C and Objective-C.}.
3518Similarly, line 18 is assigned @code{class-close} syntax.
3519
6b61353c
KH
3520@ssindex inher-intro
3521@ssindex inher-cont
6bf7aab6
DL
3522Line 2 introduces the inheritance list for the class so it is assigned
3523the @code{inher-intro} syntax, and line 3, which continues the
3524inheritance list is given @code{inher-cont} syntax.
3525
6b61353c
KH
3526@ssindex access-label
3527@ssindex inclass
6bf7aab6
DL
3528Hitting @kbd{C-c C-s} on line 5 shows the following analysis:
3529
3530@example
6b61353c 3531((inclass 58) (access-label 58))
6bf7aab6
DL
3532@end example
3533
3534@noindent
3535The primary syntactic symbol for this line is @code{access-label} as
3536this a label keyword that specifies access protection in C++. However,
3537because this line is also a top-level construct inside a class
3538definition, the analysis actually shows two syntactic symbols. The
3539other syntactic symbol assigned to this line is @code{inclass}.
3540Similarly, line 6 is given both @code{inclass} and @code{topmost-intro}
3541syntax:
3542
3543@example
6b61353c 3544((inclass 58) (topmost-intro 60))
6bf7aab6
DL
3545@end example
3546
6b61353c
KH
3547@ssindex member-init-intro
3548@ssindex member-init-cont
6bf7aab6
DL
3549Line 7 introduces a C++ member initialization list and as such is given
3550@code{member-init-intro} syntax. Note that in this case it is
3551@emph{not} assigned @code{inclass} since this is not considered a
3552top-level construct. Lines 8 through 10 are all assigned
3553@code{member-init-cont} since they continue the member initialization
3554list started on line 7.
3555
3556@cindex in-class inline methods
6b61353c
KH
3557@ssindex inline-open
3558@ssindex inline-close
6bf7aab6
DL
3559Line 11's analysis is a bit more complicated:
3560
3561@example
6b61353c 3562((inclass 58) (inline-open))
6bf7aab6
DL
3563@end example
3564
3565This line is assigned a syntax of both @code{inline-open} and
3566@code{inclass} because it opens an @dfn{in-class} C++ inline method
3567definition. This is distinct from, but related to, the C++ notion of an
3568inline function in that its definition occurs inside an enclosing class
3569definition, which in C++ implies that the function should be inlined.
6b61353c 3570However, if the definition of the @code{Bass} constructor appeared
6bf7aab6
DL
3571outside the class definition, the construct would be given the
3572@code{defun-open} syntax, even if the keyword @code{inline} appeared
3573before the method name, as in:
6bf7aab6 3574
6b61353c
KH
3575@example
3576 1: class Bass
3577 2: : public Guitar,
3578 3: public Amplifiable
3579 4: @{
3580 5: public:
3581 6: Bass();
3582 7: @};
3583 8:
3584 9: inline
358510: Bass::Bass()
358611: : eString( new BassString( 0.105 )),
358712: aString( new BassString( 0.085 )),
358813: dString( new BassString( 0.065 )),
358914: gString( new BassString( 0.045 ))
359015: @{
359116: eString.tune( 'E' );
359217: aString.tune( 'A' );
359318: dString.tune( 'D' );
359419: gString.tune( 'G' );
359520: @}
6bf7aab6
DL
3596@end example
3597
6b61353c 3598@ssindex friend
6bf7aab6
DL
3599Returning to the previous example, line 16 is given @code{inline-close}
3600syntax, while line 12 is given @code{defun-block-open} syntax, and lines
360113 through 15 are all given @code{statement} syntax. Line 17 is
3602interesting in that its syntactic analysis list contains three
3603elements:
3604
3605@example
6b61353c 3606((inclass 58) (topmost-intro 380) (friend))
6bf7aab6
DL
3607@end example
3608
3609The @code{friend} syntactic symbol is a modifier that typically does not
3610have a relative buffer position.
3611
3612Template definitions introduce yet another syntactic symbol:
3613
3614@example
6b61353c
KH
3615 1: ThingManager <int,
3616 2: Framework::Callback *,
3617 3: Mutex> framework_callbacks;
6bf7aab6
DL
3618@end example
3619
3620Here, line 1 is analyzed as a @code{topmost-intro}, but lines 2 and 3
3621are both analyzed as @code{template-args-cont} lines.
3622
3623Here is another (totally contrived) example which illustrates how syntax
3624is assigned to various conditional constructs:
6bf7aab6 3625
6b61353c
KH
3626@example
3627 1: void spam( int index )
3628 2: @{
3629 3: for( int i=0; i<index; i++ )
3630 4: @{
3631 5: if( i == 10 )
3632 6: do_something_special();
3633 7: else
3634 8: silly_label:
3635 9: do_something( i );
363610: @}
363711: do @{
363812: another_thing( i-- );
363913: @}
364014: while( i > 0 );
364115: @}
6bf7aab6
DL
3642@end example
3643
6bf7aab6
DL
3644Only the lines that illustrate new syntactic symbols will be discussed.
3645
6b61353c
KH
3646@ssindex substatement-open
3647@ssindex substatement-block-intro
3648@ssindex block-close
6bf7aab6
DL
3649Line 4 has a brace which opens a conditional's substatement block. It
3650is thus assigned @code{substatement-open} syntax, and since line 5 is
3651the first line in the substatement block, it is assigned
6b61353c
KH
3652@code{substatement-block-intro} syntax. Line 10 contains the brace that
3653closes the inner substatement block, and is therefore given the syntax
3654@code{block-close}. Line 13 is treated the same way.
3655
3656@ssindex substatement
3657Lines 6 and 9 are also substatements of conditionals, but since they
3658don't start blocks they are given @code{substatement} syntax
3659instead of @code{substatement-open}.
3660
3661@ssindex substatement-label
3662Line 8 contains a label, which is normally given @code{label} syntax.
3663This one is however a bit special since it's between a conditional and
3664its substatement. It's analyzed as @code{substatement-label} to let you
3665handle this rather odd case differently from normal labels.
3666
3667@ssindex else-clause
3668@ssindex catch-clause
3669Line 7 start with an @code{else} that matches the @code{if} statement on
3670line 5. It is therefore given the @code{else-clause} syntax and is
3671anchored on the matching @code{if}. The @code{try}-@code{catch}
3672constructs in C++ and Java are treated this way too, except that
3673@code{catch} and (in Java) @code{finally}, are marked with
3674@code{catch-clause}.
3675
3676@ssindex do-while-closure
3677The @code{while} construct on line 14 that closes a @code{do}
3678conditional is given the special syntax @code{do-while-closure} if it
3679appears on a line by itself. Note that if the @code{while} appeared on
3680the same line as the preceding close brace, that line would still have
3681@code{block-close} syntax.
6bf7aab6
DL
3682
3683Switch statements have their own set of syntactic symbols. Here's an
3684example:
6bf7aab6 3685
6b61353c
KH
3686@example
3687 1: void spam( enum Ingredient i )
3688 2: @{
3689 3: switch( i ) @{
3690 4: case Ham:
3691 5: be_a_pig();
3692 6: break;
3693 7: case Salt:
3694 8: drink_some_water();
3695 9: break;
369610: default:
369711: @{
369812: what_is_it();
369913: break;
370014: @}
370115: @}
370214: @}
6bf7aab6
DL
3703@end example
3704
6b61353c
KH
3705@ssindex case-label
3706@ssindex statement-case-intro
3707@ssindex statement-case-open
6bf7aab6
DL
3708Here, lines 4, 7, and 10 are all assigned @code{case-label} syntax,
3709while lines 5 and 8 are assigned @code{statement-case-intro}. Line 11
3710is treated slightly differently since it contains a brace that opens a
3711block --- it is given @code{statement-case-open} syntax.
3712
3713@cindex brace lists
3714There are a set of syntactic symbols that are used to recognize
3715constructs inside of brace lists. A brace list is defined as an
3716@code{enum} or aggregate initializer list, such as might statically
d7bd46ed
GM
3717initialize an array of structs. The three special aggregate constructs
3718in Pike, @code{(@{ @})}, @code{([ ])} and @code{(< >)}, are treated as
3719brace lists too. An example:
6bf7aab6 3720
6b61353c
KH
3721@example
3722 1: static char* ingredients[] =
3723 2: @{
3724 3: "Ham",
3725 4: "Salt",
3726 5: NULL
3727 6: @};
6bf7aab6
DL
3728@end example
3729
6b61353c
KH
3730@ssindex brace-list-open
3731@ssindex brace-list-intro
3732@ssindex brace-list-close
3733@ssindex brace-list-entry
6bf7aab6
DL
3734Following convention, line 2 in this example is assigned
3735@code{brace-list-open} syntax, and line 3 is assigned
3736@code{brace-list-intro} syntax. Likewise, line 6 is assigned
3737@code{brace-list-close} syntax. Lines 4 and 5 however, are assigned
3738@code{brace-list-entry} syntax, as would all subsequent lines in this
3739initializer list.
3740
6b61353c 3741@ssindex brace-entry-open
d7bd46ed
GM
3742Your static initializer might be initializing nested structures, for
3743example:
d7bd46ed 3744
6b61353c
KH
3745@example
3746 1: struct intpairs[] =
3747 2: @{
3748 3: @{ 1, 2 @},
3749 4: @{
3750 5: 3,
3751 6: 4
3752 7: @}
3753 8: @{ 1,
3754 9: 2 @},
375510: @{ 3, 4 @}
375611: @};
d7bd46ed
GM
3757@end example
3758
3759Here, you've already seen the analysis of lines 1, 2, 3, and 11. On
3760line 4, things get interesting; this line is assigned
3761@code{brace-entry-open} syntactic symbol because it's a bracelist entry
3762line that starts with an open brace. Lines 5 and 6 (and line 9) are
3763pretty standard, and line 7 is a @code{brace-list-close} as you'd
3764expect. Once again, line 8 is assigned as @code{brace-entry-open} as is
3765line 10.
3766
6bf7aab6
DL
3767External language definition blocks also have their own syntactic
3768symbols. In this example:
6bf7aab6 3769
6b61353c
KH
3770@example
3771 1: extern "C"
3772 2: @{
3773 3: int thing_one( int );
3774 4: int thing_two( double );
3775 5: @}
6bf7aab6
DL
3776@end example
3777
6b61353c
KH
3778@ssindex extern-lang-open
3779@ssindex extern-lang-close
3780@ssindex inextern-lang
3781@ssindex inclass
6bf7aab6
DL
3782@noindent
3783line 2 is given the @code{extern-lang-open} syntax, while line 5 is given
3784the @code{extern-lang-close} syntax. The analysis for line 3 yields:
6bf7aab6 3785
6bf7aab6 3786@example
6b61353c 3787((inextern-lang) (topmost-intro 14))
6bf7aab6
DL
3788@end example
3789
6bf7aab6 3790@noindent
6b61353c
KH
3791where @code{inextern-lang} is a modifier similar in purpose to
3792@code{inclass}.
3793
3794There are various other top level blocks like @code{extern}, and they
3795are all treated in the same way except that the symbols are named after
3796the keyword that introduces the block. E.g. C++ namespace blocks get
3797the three symbols @code{namespace-open}, @code{namespace-close} and
3798@code{innamespace}. The currently recognized top level blocks are:
3799
3800@table @asis
3801@item @code{extern-lang-open}, @code{extern-lang-close}, @code{inextern-lang}
3802@code{extern} blocks in C and C++.@footnote{These should logically be
3803named @code{extern-open}, @code{extern-close} and @code{inextern}, but
3804that isn't the case for historical reasons.}
3805
3806@item @code{namespace-open}, @code{namespace-close}, @code{innamespace}
3807@ssindex namespace-open
3808@ssindex namespace-close
3809@ssindex innamespace
3810@code{namespace} blocks in C++.
3811
3812@item @code{module-open}, @code{module-close}, @code{inmodule}
3813@ssindex module-open
3814@ssindex module-close
3815@ssindex inmodule
3816@code{module} blocks in CORBA IDL.
3817
3818@item @code{composition-open}, @code{composition-close}, @code{incomposition}
3819@ssindex composition-open
3820@ssindex composition-close
3821@ssindex incomposition
3822@code{composition} blocks in CORBA CIDL.
3823@end table
6bf7aab6
DL
3824
3825A number of syntactic symbols are associated with parenthesis lists,
3826a.k.a argument lists, as found in function declarations and function
3827calls. This example illustrates these:
6bf7aab6 3828
6b61353c
KH
3829@example
3830 1: void a_function( int line1,
3831 2: int line2 );
3832 3:
3833 4: void a_longer_function(
3834 5: int line1,
3835 6: int line2
3836 7: );
3837 8:
3838 9: void call_them( int line1, int line2 )
383910: @{
384011: a_function(
384112: line1,
384213: line2
384314: );
384415:
384516: a_longer_function( line1,
384617: line2 );
384718: @}
6bf7aab6
DL
3848@end example
3849
6b61353c
KH
3850@ssindex arglist-intro
3851@ssindex arglist-close
6bf7aab6
DL
3852Lines 5 and 12 are assigned @code{arglist-intro} syntax since they are
3853the first line following the open parenthesis, and lines 7 and 14 are
3854assigned @code{arglist-close} syntax since they contain the parenthesis
3855that closes the argument list.
3856
6b61353c
KH
3857@ssindex arglist-cont-nonempty
3858@ssindex arglist-cont
6bf7aab6
DL
3859Lines that continue argument lists can be assigned one of two syntactic
3860symbols. For example, Lines 2 and 17
3861are assigned @code{arglist-cont-nonempty} syntax. What this means
3862is that they continue an argument list, but that the line containing the
3863parenthesis that opens the list is @emph{not empty} following the open
3864parenthesis. Contrast this against lines 6 and 13 which are assigned
3865@code{arglist-cont} syntax. This is because the parenthesis that opens
3866their argument lists is the last character on that line.
3867
3868Note that there is no @code{arglist-open} syntax. This is because any
3869parenthesis that opens an argument list, appearing on a separate line,
3870is assigned the @code{statement-cont} syntax instead.
3871
3872A few miscellaneous syntactic symbols that haven't been previously
3873covered are illustrated by this C++ example:
6bf7aab6 3874
6b61353c
KH
3875@example
3876 1: void Bass::play( int volume )
3877 2: const
3878 3: @{
3879 4: /* this line starts a multiline
3880 5: * comment. This line should get `c' syntax */
3881 6:
3882 7: char* a_multiline_string = "This line starts a multiline \
3883 8: string. This line should get `string' syntax.";
3884 9:
388510: note:
388611: @{
388712: #ifdef LOCK
388813: Lock acquire();
388914: #endif // LOCK
389015: slap_pop();
389116: cout << "I played "
389217: << "a note\n";
389318: @}
389419: @}
6bf7aab6
DL
3895@end example
3896
6bf7aab6
DL
3897The lines to note in this example include:
3898
3899@itemize @bullet
6bf7aab6 3900@item
6b61353c 3901@ssindex func-decl-cont
f214c025 3902Line 2 is assigned the @code{func-decl-cont} syntax.
6bf7aab6 3903
6bf7aab6 3904@item
6b61353c 3905@ssindex comment-intro
f214c025
GM
3906Line 4 is assigned both @code{defun-block-intro} @emph{and}
3907@code{comment-intro} syntax.
6bf7aab6 3908
6bf7aab6 3909@item
6b61353c 3910@ssindex c
f214c025 3911Line 5 is assigned @code{c} syntax.
6bf7aab6
DL
3912
3913@item
3914@cindex syntactic whitespace
f214c025 3915Line 6 which, even though it contains nothing but whitespace, is
6bf7aab6
DL
3916assigned @code{defun-block-intro}. Note that the appearance of the
3917comment on lines 4 and 5 do not cause line 6 to be assigned
3918@code{statement} syntax because comments are considered to be
3919@dfn{syntactic whitespace}, which are ignored when analyzing
f214c025 3920code.
6bf7aab6 3921
6bf7aab6 3922@item
6b61353c 3923@ssindex string
f214c025 3924Line 8 is assigned @code{string} syntax.
6bf7aab6 3925
6bf7aab6 3926@item
6b61353c 3927@ssindex label
f214c025 3928Line 10 is assigned @code{label} syntax.
6bf7aab6 3929
6bf7aab6 3930@item
6b61353c 3931@ssindex block-open
f214c025 3932Line 11 is assigned @code{block-open} syntax.
6bf7aab6 3933
6bf7aab6 3934@item
6b61353c 3935@ssindex cpp-macro
f214c025
GM
3936Lines 12 and 14 are assigned @code{cpp-macro} syntax in addition to the
3937normal syntactic symbols (@code{statement-block-intro} and
3938@code{statement}, respectively). Normally @code{cpp-macro} is
3939configured to cancel out the normal syntactic context to make all
3940preprocessor directives stick to the first column, but that's easily
3941changed if you want preprocessor directives to be indented like the rest
3942of the code.
6bf7aab6 3943
6bf7aab6 3944@item
6b61353c 3945@ssindex stream-op
f214c025 3946Line 17 is assigned @code{stream-op} syntax.
6bf7aab6
DL
3947@end itemize
3948
6b61353c 3949@cindex multiline macros
6bf7aab6 3950@cindex syntactic whitespace
6b61353c
KH
3951@ssindex cpp-define-intro
3952Multiline preprocessor macro definitions are normally handled just like
3953other code, i.e. the lines inside them are indented according to the
3954syntactic analysis of the preceding lines inside the macro. The first
3955line inside a macro definition (i.e. the line after the starting line of
3956the cpp directive itself) gets @code{cpp-define-intro}. In this example:
6bf7aab6 3957
6b61353c
KH
3958@example
3959 1: #define LIST_LOOP(cons, listp) \
3960 2: for (cons = listp; !NILP (cons); cons = XCDR (cons)) \
3961 3: if (!CONSP (cons)) \
3962 4: signal_error ("Invalid list format", listp); \
3963 5: else
6bf7aab6 3964@end example
6b61353c 3965
6bf7aab6 3966@noindent
6b61353c
KH
3967line 1 is given the syntactic symbol @code{cpp-macro}. The first line
3968of a cpp directive is always given that symbol. Line 2 is given
3969@code{cpp-define-intro}, so that you can give the macro body as a whole
3970some extra indentation. Lines 3 through 5 are then analyzed as normal
3971code, i.e. @code{substatement} on lines 3 and 4, and @code{else-clause}
3972on line 5.
3973
3974The syntactic analysis inside macros can be turned off with
3975@code{c-syntactic-indentation-in-macros}. In that case, lines 2 through
39765 would all be given @code{cpp-macro-cont} with a relative buffer
3977position pointing to the @code{#} which starts the cpp
3978directive@footnote{This is how @ccmode{} 5.28 and earlier analyzed
3979macros.}.
3980
3981@xref{Macro Handling}, for more info about the treatment of macros.
6bf7aab6
DL
3982
3983In Objective-C buffers, there are three additional syntactic symbols
3984assigned to various message calling constructs. Here's an example
3985illustrating these:
6bf7aab6 3986
6b61353c
KH
3987@example
3988 1: - (void)setDelegate:anObject
3989 2: withStuff:stuff
3990 3: @{
3991 4: [delegate masterWillRebind:self
3992 5: toDelegate:anObject
3993 6: withExtraStuff:stuff];
3994 7: @}
6bf7aab6
DL
3995@end example
3996
6b61353c
KH
3997@ssindex objc-method-intro
3998@ssindex objc-method-args-cont
3999@ssindex objc-method-call-cont
6bf7aab6
DL
4000Here, line 1 is assigned @code{objc-method-intro} syntax, and line 2 is
4001assigned @code{objc-method-args-cont} syntax. Lines 5 and 6 are both
4002assigned @code{objc-method-call-cont} syntax.
4003
d7bd46ed
GM
4004Java has a concept of anonymous classes, which may look something like
4005this:
d7bd46ed 4006
6b61353c
KH
4007@example
4008 1: public void watch(Observable o) @{
4009 2: o.addObserver(new Observer() @{
4010 3: public void update(Observable o, Object arg) @{
4011 4: history.addElement(arg);
4012 5: @}
4013 6: @});
4014 7: @}
d7bd46ed
GM
4015@end example
4016
6b61353c 4017@ssindex inexpr-class
d7bd46ed
GM
4018The brace following the @code{new} operator opens the anonymous class.
4019Lines 3 and 6 are assigned the @code{inexpr-class} syntax, besides the
4020@code{inclass} symbol used in normal classes. Thus, the class will be
4021indented just like a normal class, with the added indentation given to
4022@code{inexpr-class}.
4023
4024There are a few occasions where a statement block may be used inside an
4025expression. One is in C code using the gcc extension for this, e.g:
d7bd46ed 4026
6b61353c
KH
4027@example
4028 1: int res = (@{
4029 2: int y = foo (); int z;
4030 3: if (y > 0) z = y; else z = - y;
4031 4: z;
4032 5: @});
d7bd46ed
GM
4033@end example
4034
6b61353c 4035@ssindex inexpr-statement
d7bd46ed
GM
4036Lines 2 and 5 get the @code{inexpr-statement} syntax, besides the
4037symbols they'd get in a normal block. Therefore, the indentation put on
4038@code{inexpr-statement} is added to the normal statement block
4039indentation.
4040
4041In Pike code, there are a few other situations where blocks occur inside
4042statements, as illustrated here:
d7bd46ed 4043
6b61353c
KH
4044@example
4045 1: array itgob()
4046 2: @{
4047 3: string s = map (backtrace()[-2][3..],
4048 4: lambda
4049 5: (mixed arg)
4050 6: @{
4051 7: return sprintf ("%t", arg);
4052 8: @}) * ", " + "\n";
4053 9: return catch @{
405410: write (s + "\n");
405511: @};
405612: @}
d7bd46ed
GM
4057@end example
4058
6b61353c
KH
4059@ssindex inlambda
4060@ssindex lambda-intro-cont
d7bd46ed
GM
4061Lines 4 through 8 contain a lambda function, which @ccmode{} recognizes
4062by the @code{lambda} keyword. If the function argument list is put
4063on a line of its own, as in line 5, it gets the @code{lambda-intro-cont}
4064syntax. The function body is handled as an inline method body, with the
4065addition of the @code{inlambda} syntactic symbol. This means that line
40666 gets @code{inlambda} and @code{inline-open}, and line 8 gets
4067@code{inline-close}@footnote{You might wonder why it doesn't get
4068@code{inlambda} too. It's because the closing brace is relative to the
4069opening brace, which stands on its own line in this example. If the
4070opening brace was hanging on the previous line, then the closing brace
4071would get the @code{inlambda} syntax too to be indented correctly.}.
4072
6b61353c 4073@ssindex inexpr-statement
d7bd46ed
GM
4074On line 9, @code{catch} is a special function taking a statement block
4075as its argument. The block is handled as an in-expression statement
4076with the @code{inexpr-statement} syntax, just like the gcc extended C
4077example above. The other similar special function, @code{gauge}, is
4078handled like this too.
4079
6b61353c
KH
4080@ssindex knr-argdecl-intro
4081@ssindex knr-argdecl
6bf7aab6
DL
4082Two other syntactic symbols can appear in old style, non-prototyped C
4083code @footnote{a.k.a. K&R C, or Kernighan & Ritchie C}:
6bf7aab6 4084
6b61353c
KH
4085@example
4086 1: int add_three_integers(a, b, c)
4087 2: int a;
4088 3: int b;
4089 4: int c;
4090 5: @{
4091 6: return a + b + c;
4092 7: @}
6bf7aab6
DL
4093@end example
4094
4095Here, line 2 is the first line in an argument declaration list and so is
4096given the @code{knr-argdecl-intro} syntactic symbol. Subsequent lines
4097(i.e. lines 3 and 4 in this example), are given @code{knr-argdecl}
4098syntax.
4099
d7bd46ed 4100
6bf7aab6 4101@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6b61353c 4102@node Indentation Functions, AWK Mode, Syntactic Symbols, Top
d7bd46ed 4103@comment node-name, next, previous, up
6b61353c 4104@chapter Indentation Functions
d7bd46ed
GM
4105@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
4106
6b61353c
KH
4107@cindex indentation function
4108@cindex line-up function
4109Often there are cases when a simple offset setting on a syntactic
4110symbol isn't enough to get the desired indentation. Therefore, it's
4111also possible to use an @dfn{indentation function} (a.k.a. @dfn{line-up
4112function}) for a syntactic symbol.
d7bd46ed
GM
4113
4114@ccmode{} comes with many predefined indentation functions for common
4115situations. If none of these does what you want, you can write your
4116own, see @ref{Custom Indentation Functions}. If you do, it's probably a
4117good idea to start working from one of these predefined functions, they
4118can be found in the file @file{cc-align.el}.
4119
4120For every function below there is a ``works with'' list that indicates
4121which syntactic symbols the function is intended to be used with.
4122
4123@macro workswith
cb7f2e96 4124@emph{Works with:@ }
d7bd46ed
GM
4125@end macro
4126@ifinfo
4127@unmacro workswith
4128@macro workswith
4129Works with:
4130@end macro
4131@end ifinfo
4132
6b61353c
KH
4133@macro sssTBasicOffset
4134<--> @i{c-basic-offset}@c
4135@end macro
d7bd46ed 4136
6b61353c
KH
4137@macro sssTsssTBasicOffset
4138<--><--> @i{c-basic-offset}@c
4139@end macro
d7bd46ed 4140
6b61353c
KH
4141@macro hereFn{func}
4142<- @i{\func\}@c
4143@end macro
d7bd46ed 4144
6b61353c
KH
4145@c The TeX backend seems to insert extra spaces around the argument. :P
4146@iftex
4147@unmacro hereFn
4148@macro hereFn{func}
4149<-@i{\func\}@c
4150@end macro
4151@end iftex
d7bd46ed 4152
6b61353c 4153@comment ------------------------------------------------------------
d7bd46ed 4154
6b61353c
KH
4155@defun c-indent-one-line-block
4156@findex indent-one-line-block (c-)
4157Indent a one line block @code{c-basic-offset} extra. E.g:
d7bd46ed 4158
d7bd46ed
GM
4159@example
4160@group
6b61353c
KH
4161if (n > 0)
4162 @{m+=n; n=0;@} @hereFn{c-indent-one-line-block}
4163@sssTBasicOffset{}
d7bd46ed
GM
4164@end group
4165@end example
6b61353c 4166
d7bd46ed
GM
4167@noindent
4168and
6b61353c 4169
d7bd46ed
GM
4170@example
4171@group
6b61353c
KH
4172if (n > 0)
4173@{ @hereFn{c-indent-one-line-block}
4174 m+=n; n=0;
4175@}
d7bd46ed
GM
4176@end group
4177@end example
4178
6b61353c
KH
4179The block may be surrounded by any kind of parenthesis characters.
4180@code{nil} is returned if the line doesn't start with a one line block,
4181which makes the function usable in list expressions.
d7bd46ed 4182
6b61353c
KH
4183@workswith Almost all syntactic symbols, but most useful on the
4184@code{-open} symbols.
4185@end defun
d7bd46ed 4186
6b61353c
KH
4187@comment ------------------------------------------------------------
4188
4189@defun c-indent-multi-line-block
4190@findex indent-multi-line-block (c-)
4191Indent a multiline block @code{c-basic-offset} extra. E.g:
d7bd46ed 4192
f214c025
GM
4193@example
4194@group
6b61353c
KH
4195int *foo[] = @{
4196 NULL,
4197 @{17@}, @hereFn{c-indent-multi-line-block}
f214c025
GM
4198@end group
4199@end example
6b61353c 4200
f214c025
GM
4201@noindent
4202and
6b61353c 4203
f214c025
GM
4204@example
4205@group
6b61353c
KH
4206int *foo[] = @{
4207 NULL,
4208 @{ @hereFn{c-indent-multi-line-block}
4209 17
4210 @},
4211 @sssTBasicOffset{}
4212@end group
4213@end example
f214c025 4214
6b61353c
KH
4215The block may be surrounded by any kind of parenthesis characters.
4216@code{nil} is returned if the line doesn't start with a multiline
4217block, which makes the function usable in list expressions.
4218
4219@workswith Almost all syntactic symbols, but most useful on the
4220@code{-open} symbols.
4221@end defun
f214c025 4222
6b61353c
KH
4223@comment ------------------------------------------------------------
4224
4225@defun c-lineup-argcont
4226@findex lineup-argcont (c-)
4227Line up a continued argument. E.g:
4228
4229@example
4230@group
4231foo (xyz, aaa + bbb + ccc
4232 + ddd + eee + fff); @hereFn{c-lineup-argcont}
f214c025
GM
4233@end group
4234@end example
6b61353c
KH
4235
4236Only continuation lines like this are touched, @code{nil} is returned on
4237lines which are the start of an argument.
4238
4239Within a gcc @code{asm} block, @code{:} is recognised as an argument
4240separator, but of course only between operand specifications, not in the
4241expressions for the operands.
4242
4243@workswith @code{arglist-cont}, @code{arglist-cont-nonempty}.
4244@end defun
4245
4246@comment ------------------------------------------------------------
4247
4248@defun c-lineup-arglist
4249@findex lineup-arglist (c-)
4250Line up the current argument line under the first argument.
4251
4252As a special case, if an argument on the same line as the open
4253parenthesis starts with a brace block opener, the indentation is
4254@code{c-basic-offset} only. This is intended as a ``DWIM'' measure in
4255cases like macros that contains statement blocks, e.g:
4256
f214c025
GM
4257@example
4258@group
6b61353c
KH
4259A_VERY_LONG_MACRO_NAME (@{
4260 some (code, with + long, lines * in[it]);
4261 @});
4262@sssTBasicOffset{}
4263@end group
4264@end example
f214c025 4265
6b61353c
KH
4266This is motivated partly because it's more in line with how code
4267blocks are handled, and partly since it approximates the behavior of
4268earlier CC Mode versions, which due to inaccurate analysis tended to
4269indent such cases this way.
4270
4271@workswith @code{arglist-cont-nonempty}, @code{arglist-close}.
4272@end defun
4273
4274@comment ------------------------------------------------------------
4275
4276@defun c-lineup-arglist-intro-after-paren
4277@findex lineup-arglist-intro-after-paren (c-)
4278Line up a line to just after the open paren of the surrounding paren or
4279brace block.
4280
4281@workswith @code{defun-block-intro}, @code{brace-list-intro},
4282@code{statement-block-intro}, @code{statement-case-intro},
4283@code{arglist-intro}.
4284@end defun
4285
4286@comment ------------------------------------------------------------
4287
4288@defun c-lineup-arglist-close-under-paren
4289@findex lineup-arglist-close-under-paren (c-)
4290Set your @code{arglist-close} syntactic symbol to this line-up function
4291so that parentheses that close argument lists will line up under the
4292parenthesis that opened the argument list. It can also be used with
4293@code{arglist-cont} and @code{arglist-cont-nonempty} to line up all
4294lines inside a parenthesis under the open paren.
4295
4296As a special case, if a brace block is opened at the same line as the
4297open parenthesis of the argument list, the indentation is
4298@code{c-basic-offset} only. See @code{c-lineup-arglist} for further
4299discussion of this ``DWIM'' measure.
4300
4301@workswith Almost all symbols, but are typically most useful on
4302@code{arglist-close}, @code{brace-list-close}, @code{arglist-cont} and
4303@code{arglist-cont-nonempty}.
4304@end defun
4305
4306@comment ------------------------------------------------------------
4307
4308@defun c-lineup-arglist-operators
4309@findex lineup-arglist-operators (c-)
4310Line up lines starting with an infix operator under the open paren.
4311Return @code{nil} on lines that don't start with an operator, to leave
4312those cases to other lineup functions. Example:
f214c025 4313
6b61353c
KH
4314@example
4315@group
4316if ( x < 10
4317 || at_limit (x, @hereFn{c-lineup-arglist-operators}
4318 list) @hereFn{c-lineup-arglist-operators@r{ returns nil}}
4319 )
f214c025
GM
4320@end group
4321@end example
4322
6b61353c
KH
4323Since this function doesn't do anything for lines without an infix
4324operator you typically want to use it together with some other lineup
4325settings, e.g. as follows (the @code{arglist-close} setting is just a
4326suggestion to get a consistent style):
d7bd46ed 4327
d7bd46ed 4328@example
6b61353c
KH
4329(c-set-offset 'arglist-cont
4330 '(c-lineup-arglist-operators 0))
4331(c-set-offset 'arglist-cont-nonempty
4332 '(c-lineup-arglist-operators c-lineup-arglist))
4333(c-set-offset 'arglist-close
4334 '(c-lineup-arglist-close-under-paren))
4335@end example
d7bd46ed 4336
6b61353c
KH
4337@workswith @code{arglist-cont}, @code{arglist-cont-nonempty}.
4338@end defun
4339
4340@comment ------------------------------------------------------------
d7bd46ed 4341
6b61353c
KH
4342@defun c-lineup-C-comments
4343@findex lineup-C-comments (c-)
4344Line up C block comment continuation lines. Various heuristics are used
4345to handle most of the common comment styles. Some examples:
d7bd46ed 4346
6b61353c
KH
4347@example
4348@group
4349/* /** /*
4350 * text * text text
4351 */ */ */
d7bd46ed
GM
4352@end group
4353@end example
6b61353c 4354
d7bd46ed
GM
4355@example
4356@group
6b61353c
KH
4357/* text /* /**
4358 text ** text ** text
4359*/ */ */
4360@end group
4361@end example
d7bd46ed 4362
6b61353c
KH
4363@example
4364@group
4365/**************************************************
4366 * text
4367 *************************************************/
4368@end group
4369@end example
d7bd46ed 4370
6b61353c
KH
4371@vindex comment-start-skip
4372@example
4373@group
4374/**************************************************
4375 Free form text comments:
4376 In comments with a long delimiter line at the
4377 start, the indentation is kept unchanged for lines
4378 that start with an empty comment line prefix. The
4379 delimiter line is whatever matches the
4380 @code{comment-start-skip} regexp.
4381**************************************************/
d7bd46ed
GM
4382@end group
4383@end example
4384
6b61353c
KH
4385The style variable @code{c-comment-prefix-regexp} is used to recognize
4386the comment line prefix, e.g. the @samp{*} that usually starts every
4387line inside a comment.
4388
4389@workswith The @code{c} syntactic symbol.
4390@end defun
4391
4392@comment ------------------------------------------------------------
4393
4394@defun c-lineup-cascaded-calls
4395@findex lineup-cascaded-calls (c-)
4396Line up ``cascaded calls'' under each other. If the line begins with
4397@code{->} or @code{.} and the preceding line ends with one or more
4398function calls preceded by the same token, then the arrow is lined up
4399with the first of those tokens. E.g:
d7bd46ed 4400
d7bd46ed
GM
4401@example
4402@group
6b61353c
KH
4403r = proc->add(17)->add(18)
4404 ->add(19) + @hereFn{c-lineup-cascaded-calls}
4405 offset; @hereFn{c-lineup-cascaded-calls@r{ (inactive)}}
4406@end group
4407@end example
d7bd46ed 4408
6b61353c
KH
4409In any other situation @code{nil} is returned to allow use in list
4410expressions.
4411
4412@workswith @code{topmost-intro-cont}, @code{statement-cont},
4413@code{arglist-cont}, @code{arglist-cont-nonempty}.
4414@end defun
d7bd46ed 4415
6b61353c
KH
4416@comment ------------------------------------------------------------
4417
4418@defun c-lineup-close-paren
4419@findex lineup-close-paren (c-)
4420Line up the closing paren under its corresponding open paren if the
4421open paren is followed by code. If the open paren ends its line, no
4422indentation is added. E.g:
d7bd46ed 4423
6b61353c
KH
4424@example
4425@group
4426main (int,
4427 char **
4428 ) @hereFn{c-lineup-close-paren}
d7bd46ed
GM
4429@end group
4430@end example
6b61353c 4431
d7bd46ed
GM
4432@noindent
4433and
6b61353c 4434
d7bd46ed
GM
4435@example
4436@group
6b61353c
KH
4437main (
4438 int, char **
4439) @hereFn{c-lineup-close-paren}
4440@end group
4441@end example
d7bd46ed 4442
6b61353c
KH
4443As a special case, if a brace block is opened at the same line as the
4444open parenthesis of the argument list, the indentation is
4445@code{c-basic-offset} instead of the open paren column. See
4446@code{c-lineup-arglist} for further discussion of this ``DWIM'' measure.
4447
4448@workswith All @code{*-close} symbols.
4449@end defun
4450
4451@comment ------------------------------------------------------------
4452
4453@defun c-lineup-comment
4454@findex lineup-comment (c-)
4455Line up a comment-only line according to the style variable
4456@code{c-comment-only-line-offset}. If the comment is lined up with a
4457comment starter on the previous line, that alignment is preserved.
4458
4459@defopt c-comment-only-line-offset
4460@vindex comment-only-line-offset (c-)
4461This style variable specifies the extra offset for the line. It can
4462contain an integer or a cons cell of the form
4463
4464@example
4465(@r{@var{non-anchored-offset}} . @r{@var{anchored-offset}})
4466@end example
4467
4468@noindent
4469where @var{non-anchored-offset} is the amount of offset given to
4470non-column-zero anchored lines, and @var{anchored-offset} is the amount
4471of offset to give column-zero anchored lines. Just an integer as value
4472is equivalent to @code{(@r{@var{value}} . -1000)}.
4473@end defopt
d7bd46ed 4474
6b61353c
KH
4475@workswith @code{comment-intro}.
4476@end defun
4477
4478@comment ------------------------------------------------------------
4479
4480@defun c-lineup-cpp-define
4481@findex lineup-cpp-define (c-)
4482Line up macro continuation lines according to the indentation of the
4483construct preceding the macro. E.g:
4484
4485@example
4486@group
4487const char msg[] = @hereFn{@r{The beginning of the preceding construct.}}
4488 \"Some text.\";
4489
4490#define X(A, B) \
4491do @{ \ @hereFn{c-lineup-cpp-define}
4492 printf (A, B); \
4493@} while (0)
d7bd46ed
GM
4494@end group
4495@end example
4496
6b61353c
KH
4497@noindent
4498and:
d7bd46ed 4499
d7bd46ed
GM
4500@example
4501@group
6b61353c
KH
4502int dribble() @{
4503 if (!running) @hereFn{@r{The beginning of the preceding construct.}}
4504 error(\"Not running!\");
4505
4506#define X(A, B) \
4507 do @{ \ @hereFn{c-lineup-cpp-define}
4508 printf (A, B); \
4509 @} while (0)
4510@end group
4511@end example
d7bd46ed 4512
6b61353c
KH
4513If @code{c-syntactic-indentation-in-macros} is non-@code{nil}, the
4514function returns the relative indentation to the macro start line to
4515allow accumulation with other offsets. E.g. in the following cases,
4516@code{cpp-define-intro} is combined with the
4517@code{statement-block-intro} that comes from the @samp{do @{} that hangs
4518on the @samp{#define} line:
177c0ea7 4519
6b61353c
KH
4520@example
4521@group
4522const char msg[] =
4523 \"Some text.\";
d7bd46ed 4524
6b61353c
KH
4525#define X(A, B) do @{ \
4526 printf (A, B); \ @hereFn{c-lineup-cpp-define}
4527 this->refs++; \
4528@} while (0) @hereFn{c-lineup-cpp-define}
d7bd46ed
GM
4529@end group
4530@end example
6b61353c 4531
d7bd46ed 4532@noindent
6b61353c
KH
4533and:
4534
d7bd46ed
GM
4535@example
4536@group
6b61353c
KH
4537int dribble() @{
4538 if (!running)
4539 error(\"Not running!\");
4540
4541#define X(A, B) do @{ \
4542 printf (A, B); \ @hereFn{c-lineup-cpp-define}
4543 this->refs++; \
4544 @} while (0) @hereFn{c-lineup-cpp-define}
4545@end group
4546@end example
d7bd46ed 4547
6b61353c
KH
4548The relative indentation returned by @code{c-lineup-cpp-define} is zero
4549and two, respectively, on the two lines in each of these examples. They
4550are then added to the two column indentation that
4551@code{statement-block-intro} gives in both cases here.
4552
4553If the relative indentation is zero, then @code{nil} is returned
4554instead. That is useful in a list expression to specify the default
4555indentation on the top level.
4556
4557If @code{c-syntactic-indentation-in-macros} is @code{nil} then this
4558function keeps the current indentation, except for empty lines (ignoring
4559the ending backslash) where it takes the indentation from the closest
4560preceding nonempty line in the macro. If there's no such line in the
4561macro then the indentation is taken from the construct preceding it, as
4562described above.
4563
4564@workswith @code{cpp-define-intro}.
4565@end defun
4566
4567@comment ------------------------------------------------------------
4568
4569@defun c-lineup-dont-change
4570@findex lineup-dont-change (c-)
4571This lineup function makes the line stay at whatever indentation it
4572already has; think of it as an identity function for lineups.
4573
4574@workswith Any syntactic symbol.
4575@end defun
4576
4577@comment ------------------------------------------------------------
4578
4579@defun c-lineup-gcc-asm-reg
4580@findex lineup-gcc-asm-reg (c-)
4581Line up a gcc asm register under one on a previous line.
d7bd46ed 4582
6b61353c
KH
4583@example
4584@group
4585 asm ("foo %1, %0\n"
4586 "bar %0, %1"
4587 : "=r" (w),
4588 "=r" (x)
4589 : "0" (y),
4590 "1" (z));
d7bd46ed
GM
4591@end group
4592@end example
4593
6b61353c
KH
4594The @samp{x} line is aligned to the text after the @samp{:} on the
4595@samp{w} line, and similarly @samp{z} under @samp{y}.
d7bd46ed 4596
6b61353c
KH
4597This is done only in an @samp{asm} or @samp{__asm__} block, and only to
4598those lines mentioned. Anywhere else @code{nil} is returned. The usual
4599arrangement is to have this routine as an extra feature at the start of
4600arglist lineups, e.g.
d7bd46ed 4601
d7bd46ed 4602@example
6b61353c
KH
4603(c-lineup-gcc-asm-reg c-lineup-arglist)
4604@end example
d7bd46ed 4605
6b61353c
KH
4606@workswith @code{arglist-cont}, @code{arglist-cont-nonempty}.
4607@end defun
4608
4609@comment ------------------------------------------------------------
4610
4611@defun c-lineup-inexpr-block
4612@findex lineup-inexpr-block (c-)
4613This can be used with the in-expression block symbols to indent the
4614whole block to the column where the construct is started. E.g. for Java
4615anonymous classes, this lines up the class under the @samp{new} keyword,
4616and in Pike it lines up the lambda function body under the @samp{lambda}
4617keyword. Returns @code{nil} if the block isn't part of such a
4618construct.
4619
4620@workswith @code{inlambda}, @code{inexpr-statement},
4621@code{inexpr-class}.
4622@end defun
4623
4624@comment ------------------------------------------------------------
d7bd46ed 4625
6b61353c
KH
4626@defun c-lineup-java-inher
4627@findex lineup-java-inher (c-)
4628Line up Java implements and extends declarations. If class names
4629follow on the same line as the @samp{implements}/@samp{extends}
4630keyword, they are lined up under each other. Otherwise, they are
4631indented by adding @code{c-basic-offset} to the column of the keyword.
4632E.g:
4633
4634@example
4635@group
4636class Foo
4637 extends
4638 Bar @hereFn{c-lineup-java-inher}
4639 @sssTBasicOffset{}
d7bd46ed
GM
4640@end group
4641@end example
6b61353c 4642
d7bd46ed
GM
4643@noindent
4644and
6b61353c 4645
d7bd46ed
GM
4646@example
4647@group
6b61353c
KH
4648class Foo
4649 extends Cyphr,
4650 Bar @hereFn{c-lineup-java-inher}
4651@end group
4652@end example
d7bd46ed 4653
6b61353c
KH
4654@workswith @code{inher-cont}.
4655@end defun
d7bd46ed 4656
6b61353c 4657@comment ------------------------------------------------------------
d7bd46ed 4658
6b61353c
KH
4659@defun c-lineup-java-throws
4660@findex lineup-java-throws (c-)
4661Line up Java throws declarations. If exception names follow on the
4662same line as the throws keyword, they are lined up under each other.
4663Otherwise, they are indented by adding @code{c-basic-offset} to the
4664column of the @samp{throws} keyword. The @samp{throws} keyword itself
4665is also indented by @code{c-basic-offset} from the function declaration
4666start if it doesn't hang. E.g:
4667
4668@example
4669@group
4670int foo()
4671 throws @hereFn{c-lineup-java-throws}
4672 Bar @hereFn{c-lineup-java-throws}
4673@sssTsssTBasicOffset{}
d7bd46ed
GM
4674@end group
4675@end example
4676
6b61353c
KH
4677@noindent
4678and
d7bd46ed 4679
d7bd46ed 4680@example
d7bd46ed 4681@group
6b61353c
KH
4682int foo() throws Cyphr,
4683 Bar, @hereFn{c-lineup-java-throws}
4684 Vlod @hereFn{c-lineup-java-throws}
d7bd46ed 4685@end group
6b61353c
KH
4686@end example
4687
4688@workswith @code{func-decl-cont}.
4689@end defun
4690
4691@comment ------------------------------------------------------------
4692
4693@defun c-lineup-knr-region-comment
4694@findex lineup-knr-region-comment (c-)
4695Line up a comment in the ``K&R region'' with the declaration. That is
4696the region between the function or class header and the beginning of the
4697block. E.g:
d7bd46ed 4698
6b61353c 4699@example
d7bd46ed 4700@group
6b61353c
KH
4701int main()
4702/* Called at startup. */ @hereFn{c-lineup-knr-region-comment}
4703@{
4704 return 0;
4705@}
d7bd46ed 4706@end group
6b61353c
KH
4707@end example
4708
4709Return @code{nil} if called in any other situation, to be useful in list
4710expressions.
d7bd46ed 4711
6b61353c
KH
4712@workswith @code{comment-intro}.
4713@end defun
4714
4715@comment ------------------------------------------------------------
4716
4717@defun c-lineup-math
4718@findex lineup-math (c-)
4719Line up the current line to after the equal sign on the first line in the
4720statement. If there isn't any, indent with @code{c-basic-offset}. If
4721the current line contains an equal sign too, try to align it with the
4722first one.
4723
4724@workswith @code{topmost-intro-cont}, @code{statement-cont},
4725@code{arglist-cont}, @code{arglist-cont-nonempty}.
4726@end defun
4727
4728@comment ------------------------------------------------------------
4729
4730@defun c-lineup-multi-inher
4731@findex lineup-multi-inher (c-)
4732Line up the classes in C++ multiple inheritance clauses and member
4733initializers under each other. E.g:
4734
4735@example
d7bd46ed 4736@group
6b61353c
KH
4737Foo::Foo (int a, int b):
4738 Cyphr (a),
4739 Bar (b) @hereFn{c-lineup-multi-inher}
d7bd46ed 4740@end group
6b61353c 4741@end example
d7bd46ed 4742
6b61353c
KH
4743@noindent
4744and
4745
4746@example
d7bd46ed 4747@group
6b61353c
KH
4748class Foo
4749 : public Cyphr,
4750 public Bar @hereFn{c-lineup-multi-inher}
d7bd46ed 4751@end group
6b61353c
KH
4752@end example
4753
4754@noindent
4755and
d7bd46ed 4756
6b61353c
KH
4757@example
4758@group
4759Foo::Foo (int a, int b)
4760 : Cyphr (a)
4761 , Bar (b) @hereFn{c-lineup-multi-inher}
4762@end group
d7bd46ed
GM
4763@end example
4764
6b61353c
KH
4765@workswith @code{inher-cont}, @code{member-init-cont}.
4766@end defun
d7bd46ed 4767
6b61353c 4768@comment ------------------------------------------------------------
d7bd46ed 4769
6b61353c
KH
4770@defun c-lineup-ObjC-method-call
4771@findex lineup-ObjC-method-call (c-)
4772For Objective-C code, line up selector args as Emacs Lisp mode does
4773with function args: go to the position right after the message receiver,
4774and if you are at the end of the line, indent the current line
4775c-basic-offset columns from the opening bracket; otherwise you are
4776looking at the first character of the first method call argument, so
4777lineup the current line with it.
d7bd46ed 4778
6b61353c
KH
4779@workswith @code{objc-method-call-cont}.
4780@end defun
d7bd46ed 4781
6b61353c 4782@comment ------------------------------------------------------------
d7bd46ed 4783
6b61353c
KH
4784@defun c-lineup-ObjC-method-args
4785@findex lineup-ObjC-method-args (c-)
4786For Objective-C code, line up the colons that separate args. The colon
4787on the current line is aligned with the one on the first line.
d7bd46ed 4788
6b61353c
KH
4789@workswith @code{objc-method-args-cont}.
4790@end defun
d7bd46ed 4791
6b61353c
KH
4792@comment ------------------------------------------------------------
4793
4794@defun c-lineup-ObjC-method-args-2
4795@findex lineup-ObjC-method-args-2 (c-)
4796Similar to @code{c-lineup-ObjC-method-args} but lines up the colon on
4797the current line with the colon on the previous line.
4798
4799@workswith @code{objc-method-args-cont}.
4800@end defun
d7bd46ed 4801
6b61353c
KH
4802@comment ------------------------------------------------------------
4803
4804@defun c-lineup-runin-statements
d7bd46ed 4805@findex lineup-runin-statements (c-)
d7bd46ed
GM
4806Line up statements for coding standards which place the first statement
4807in a block on the same line as the block opening brace@footnote{Run-in
4808style doesn't really work too well. You might need to write your own
4809custom indentation functions to better support this style.}. E.g:
6b61353c 4810
d7bd46ed
GM
4811@example
4812@group
d7bd46ed 4813int main()
6b61353c
KH
4814@{ puts ("Hello!");
4815 return 0; @hereFn{c-lineup-runin-statements}
d7bd46ed 4816@}
d7bd46ed
GM
4817@end group
4818@end example
4819
4820If there is no statement after the opening brace to align with,
4821@code{nil} is returned. This makes the function usable in list
4822expressions.
4823
4824@workswith The @code{statement} syntactic symbol.
6b61353c 4825@end defun
d7bd46ed 4826
6b61353c 4827@comment ------------------------------------------------------------
d7bd46ed 4828
6b61353c
KH
4829@defun c-lineup-streamop
4830@findex lineup-streamop (c-)
4831Line up C++ stream operators (i.e. @samp{<<} and @samp{>>}).
4832
4833@workswith @code{stream-op}.
4834@end defun
4835
4836@comment ------------------------------------------------------------
4837
4838@defun c-lineup-string-cont
4839@findex lineup-string-cont (c-)
4840Line up a continued string under the one it continues. A continued
4841string in this sense is where a string literal follows directly after
4842another one. E.g:
4843
4844@example
4845@group
4846result = prefix + "A message "
4847 "string."; @hereFn{c-lineup-string-cont}
4848@end group
4849@end example
4850
4851@code{nil} is returned in other situations, to allow stacking with other
4852lineup functions.
d7bd46ed 4853
6b61353c
KH
4854@workswith @code{topmost-intro-cont}, @code{statement-cont},
4855@code{arglist-cont}, @code{arglist-cont-nonempty}.
4856@end defun
4857
4858@comment ------------------------------------------------------------
4859
4860@defun c-lineup-template-args
d7bd46ed 4861@findex lineup-template-args (c-)
d7bd46ed
GM
4862Line up the arguments of a template argument list under each other, but
4863only in the case where the first argument is on the same line as the
4864opening @samp{<}.
4865
4866To allow this function to be used in a list expression, @code{nil} is
4867returned if there's no template argument on the first line.
4868
4869@workswith @code{template-args-cont}.
6b61353c 4870@end defun
d7bd46ed 4871
6b61353c 4872@comment ------------------------------------------------------------
d7bd46ed 4873
6b61353c
KH
4874@defun c-lineup-topmost-intro-cont
4875@findex lineup-topmost-intro-cont (c-)
4876Line up declaration continuation lines zero or one indentation
4877step@footnote{This function is mainly provided to mimic the behavior of
4878CC Mode 5.28 and earlier where this case wasn't handled consistently so
4879that those lines could be analyzed as either topmost-intro-cont or
4880statement-cont. It's used for @code{topmost-intro-cont} by default, but
4881you might consider using @code{+} instead.}. For lines preceding a
4882definition, zero is used. For other lines, @code{c-basic-offset} is
4883added to the indentation. E.g:
d7bd46ed 4884
6b61353c
KH
4885@example
4886@group
4887int
4888neg (int i) @hereFn{c-lineup-topmost-intro-cont}
4889@{
4890 return -i;
4891@}
4892@end group
4893@end example
d7bd46ed 4894
6b61353c
KH
4895@noindent
4896and
d7bd46ed 4897
6b61353c
KH
4898@example
4899@group
4900struct
4901larch @hereFn{c-lineup-topmost-intro-cont}
4902@{
4903 double height;
4904@}
4905 the_larch, @hereFn{c-lineup-topmost-intro-cont}
4906 another_larch; @hereFn{c-lineup-topmost-intro-cont}
4907@sssTBasicOffset{}
4908@end group
4909@end example
d7bd46ed 4910
6b61353c
KH
4911@noindent
4912and
d7bd46ed 4913
6b61353c
KH
4914@example
4915@group
4916struct larch
4917the_larch, @hereFn{c-lineup-topmost-intro-cont}
4918 another_larch; @hereFn{c-lineup-topmost-intro-cont}
4919@end group
4920@end example
d7bd46ed 4921
6b61353c
KH
4922@workswith @code{topmost-intro-cont}.
4923@end defun
d7bd46ed 4924
6b61353c
KH
4925@comment ------------------------------------------------------------
4926
4927@defun c-lineup-whitesmith-in-block
d7bd46ed 4928@findex lineup-whitesmith-in-block (c-)
6b61353c 4929Line up lines inside a block in Whitesmith style. It's done in a way
d7bd46ed 4930that works both when the opening brace hangs and when it doesn't. E.g:
6b61353c 4931
d7bd46ed
GM
4932@example
4933@group
d7bd46ed
GM
4934something
4935 @{
6b61353c 4936 foo; @hereFn{c-lineup-whitesmith-in-block}
d7bd46ed 4937 @}
d7bd46ed
GM
4938@end group
4939@end example
6b61353c 4940
d7bd46ed
GM
4941@noindent
4942and
6b61353c 4943
d7bd46ed
GM
4944@example
4945@group
d7bd46ed 4946something @{
6b61353c 4947 foo; @hereFn{c-lineup-whitesmith-in-block}
d7bd46ed 4948 @}
6b61353c 4949@sssTBasicOffset{}
d7bd46ed
GM
4950@end group
4951@end example
4952
4953In the first case the indentation is kept unchanged, in the second
4954@code{c-basic-offset} is added.
4955
4956@workswith @code{defun-close}, @code{defun-block-intro},
4957@code{block-close}, @code{brace-list-close}, @code{brace-list-intro},
6b61353c
KH
4958@code{statement-block-intro} and all @code{in*} symbols,
4959e.g. @code{inclass} and @code{inextern-lang}.
4960@end defun
d7bd46ed 4961
d7bd46ed 4962
6b61353c
KH
4963@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
4964@node AWK Mode, Odds and Ends, Indentation Functions, Top
4965@comment node-name, next, previous, up
4966@chapter Status of AWK Mode
4967@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
4968
4969@dfn{AWK mode} existed until recently in the file @file{awk-mode.el}
4970as a mode derived from c-mode. It had not been actively maintained to
4971keep pace with the newer @ccmode{}, and its indentation mechanism no
4972longer worked satisfactorally.
4973
4974The current AWK mode is based around the GNU implementation,
4975@emph{GAWK version 3.1.0}, though it should work pretty well with any
4976AWK. It has now been updated and integrated into @ccmode{} to a
4977substantial extent, though as yet not all the features of @ccmode{}
4978have been adapted to support it.
4979
4980If your (X)Emacs is set up to use the old file @file{awk-mode.elc}
4981(which will usually be the case if you have obtained this @ccmode{}
4982independently of (X)Emacs itself), or if you are not sure, insert the
4983following form into your @file{.emacs} or @file{init.el} so that the new
4984AWK mode will be used instead:
4985
4986@example
4987(autoload 'awk-mode "cc-mode" nil t)
4988@end example
4989
4990You can check which AWK mode you are running by displaying the mode
4991documentation string with @kbd{C-h m} from an AWK buffer. The newer
4992mode's doc string contains @code{To submit a problem report, enter
4993`C-c C-b'} near the top of the doc string where the older mode has
4994@code{This is much like C mode except ....}.
4995
4996Since this newer AWK mode makes essential use of a relatively new
4997Emacs Lisp feature@footnote{Specifically, the @code{syntax-table} text
4998property.}, you need either GNU Emacs 20.1 (or later) or XEmacs 21.4
4999(or later) to use it. If your Emacs version is earlier than one of
5000these, the older @file{awk-mode.el} will get loaded and run in place
5001of the AWK mode described here, even when you have put the above
5002@code{autoload} form into your @file{.emacs} or @file{init.el}.
5003Upgrading your (X)Emacs is strongly recommended if this is the case.
d7bd46ed 5004
6b61353c
KH
5005Here is an overview of which @ccmode{} features currently work with
5006AWK mode and which don't:
5007
5008@table @asis
5009@item Indentation Engine
5010The @ccmode{} indentation engine fully supports AWK mode.
5011@xref{Indentation Engine}.
5012
5013AWK mode handles code formatted in the conventional AWK fashion:
5014@samp{@{}s which start actions, user-defined functions, or compound
5015statements are placed on the same line as the associated construct; the
5016matching @samp{@}}s are normally placed under the start of the
5017respective pattern, function definition, or structured statement.
5018@c Add in a bit about the @samp{@}} being on the same line when the
5019@c contents are short.
5020
5021The predefined indentation functions (@pxref{Indentation Functions})
5022haven't yet been adapted for AWK mode, though some of them may work
5023serendipitously. There shouldn't be any problems writing custom
5024indentation functions for AWK mode.
5025
5026The command @kbd{C-c C-q} (@code{c-indent-defun}) hasn't yet been
5027adapted for AWK, though in practice it works properly nearly all the
5028time. Should it fail, explicitly set the region around the function
5029(using @kbd{C-u C-SPC}: @kbd{C-M-h} probably won't work either) then do
5030@kbd{C-M-\} (@code{indent-region}).
5031
5032@item Font Locking
5033There is a single level of font locking in AWK mode, rather than the
5034three distinct levels the other modes have. There are several
5035idiosyncrasies in AWK mode's font-locking due to the peculiarities of
5036the AWK language itself. @xref{AWK Mode Font Locking}.
5037
5038@item Comment Commands
5039@kbd{M-;} (@code{indent-for-comment}) works fine. None of the other
5040@ccmode{} comment formatting commands have yet been adapted for AWK
5041mode. @xref{Text Filling and Line Breaking}.
5042
5043@item Movement Commands
5044Most of the movement commands work in AWK mode. The most important
5045exceptions are @kbd{M-a} (@code{c-beginning-of-statement}) and
5046@kbd{M-e} (@code{c-end-of-statement}) which haven't yet been adapted.
5047
5048The notion of @dfn{defun} has been augmented to include pattern-action
5049pairs. See @ref{AWK Mode Defuns} for a description of commands which
5050work on AWK ``defuns''.
5051
5052Since there is no preprocessor in AWK, the commands which move to
5053preprocessor directives (e.g. @code{c-up-conditional}) are meaningless
5054in AWK mode and are not bound in the AWK mode keymap.
5055
5056@item Auto-newline Insertion and Clean-ups
5057Auto-newline insertion hasn't yet been adapted for AWK. Some of the
5058clean-ups can actually convert good AWK code into syntactically
5059invalid code.
5060
5061If auto-newline or its associated clean-ups are enabled generally for
5062the modes in @ccmode{}, you are strongly recommended to disable them
5063in the AWK Mode hook. @xref{Initialising AWK Mode}.
5064
5065The clean-up @code{space-before-funcall}, which is independent of
5066auto-newline, should never be active in AWK mode (since inserting a
5067space between a user function's name and its opening @samp{(} makes
5068the call syntactically invalid). If necessary, this should be
5069disabled in the AWK Mode hook. @xref{Initialising AWK Mode}.
5070
5071@end table
5072
5073@menu
5074* Initialising AWK Mode::
5075* AWK Mode Font Locking::
5076* AWK Mode Defuns::
5077@end menu
5078
5079
5080@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5081@node Initialising AWK Mode, AWK Mode Font Locking, , AWK Mode
5082@comment node-name, next, previous, up
5083@section AWK mode - What to put in your @file{.emacs} or @file{init.el}
5084@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5085
5086Much of the AWK mode initialization can, of course, be done by the
5087@ccmode{} general initialization procedure. You may want to use certain
5088@ccmode{} features such as @code{auto-newline} and @code{clean-ups} in
5089the other modes, and you might thus have enabled them in a
5090@code{c-mode-common-hook} function, as described in @ref{Sample .emacs File}.
5091These features have not yet been amended for AWK mode, and far from
5092being useful, can be irritating in AWK mode or actually make AWK code
5093syntactically invalid. Adding the following code to your
5094@file{.emacs} or @file{init.el} file will disable them for AWK mode.
5095
5096@example
5097(defun my-awk-mode-hook ()
5098 "Disable certain @ccmode{} features which could impair AWK mode."
5099 (c-toggle-auto-state -1) ; disable automatic insertions of newlines
5100 (if (memq 'space-before-funcall c-cleanup-list)
5101 (setq c-cleanup-list ; don't automatically insert a space into "foo("
5102 (remove 'space-before-funcall c-cleanup-list))))
5103(add-hook 'awk-mode-hook 'my-awk-mode-hook)
5104@end example
5105
5106Naturally you can add your own AWK-specific customizations to this
5107function. @xref{Hooks}.
5108
5109
5110@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5111@node AWK Mode Font Locking, AWK Mode Defuns, Initialising AWK Mode, AWK Mode
5112@comment node-name, next, previous, up
5113@section AWK Mode Font Locking
5114@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5115
5116The general appearance of font-locking in AWK mode is much like in any
5117other programming mode. @xref{Faces For Font Lock,,,elisp}.
5118
5119The following faces are, however, used in a non-standard fashion in
5120AWK mode:
5121
5122@table @asis
5123@item @code{font-lock-variable-name-face}
5124This face was intended for variable declarations. Since variables are
5125not declared in AWK, this face is used instead for AWK system
5126variables (such as @code{NF}) and ``Special File Names'' (such as
5127@code{"/dev/stderr"}).
5128
5129@item @code{font-lock-builtin-face} (Emacs)/@code{font-lock-preprocessor-face} (XEmacs)
5130This face is normally used for preprocessor directives in @ccmode{}.
5131There are no such things in AWK, so this face is used instead for
5132standard functions (such as @code{match}).
5133
5134@item @code{font-lock-string-face}
5135As well as being used for strings, including localizable strings,
5136(delimited by @samp{"} and @samp{_"}), this face is also used for AWK
5137regular expressions (delimited by @samp{/}).
5138
5139@item @code{font-lock-warning-face} (Emacs)/@code{c-invalid-face} (XEmacs)
5140This face highlights the following syntactically invalid AWK
5141constructs:
5142
5143@itemize @bullet
5144@item
5145An unterminated string or regular expression. Here the opening
5146delimiter (@samp{"} or @samp{/} or @samp{_"}) is displayed in
5147@code{font-lock-warning-face}. This is most noticeable when typing in a
5148new string/regular expression into a buffer, when the warning-face
5149serves as a continual reminder to terminate the construct.
5150
5151AWK mode fontifies unterminated strings/regular expressions
5152differently from other modes: Only the text up to the end of the line
5153is fontified as a string (escaped newlines being handled correctly),
5154rather than the text up to the next string quote.
5155
5156@item
5157A space between the function name and opening parenthesis when calling
5158a user function. The last character of the function name and the
5159opening parenthesis are highlighted. This font-locking rule will
5160spuriously highlight a valid concatenation expression where an
5161identifier precedes a parenthesised expression. Unfortunately.
5162
5163@item
5164Whitespace following the @samp{\} in what otherwise looks like an
5165escaped newline. The @samp{\} is highlighted.
5166@end itemize
5167@end table
5168
5169
5170@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5171@node AWK Mode Defuns, , AWK Mode Font Locking, AWK Mode
5172@comment node-name, next, previous, up
5173@section AWK Mode Defuns
5174@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5175
5176In AWK mode, @dfn{defun} means either a user-defined function or a
5177pattern-action pair. Either the pattern or the action may be
5178implicit.
5179
5180The beginning of a defun is recognised heuristically as, more or less,
5181code which begins in column zero. Having the @samp{@{} in column zero,
5182as is suggested for some modes, is neither necessary nor helpful in AWK
5183mode.
5184
5185More precisely, the beginning of a defun is code which begins in
5186column zero, and which isn't a closing brace, a comment, or a
5187continuation of the previous line. Code is the @dfn{continuation of
5188the previous line} when that line is syntactically incomplete, for
5189example when it ends with @samp{@{} or an escaped newline.
5190
5191The end of a defun is the @samp{@}} which matches the @samp{@{} (if
5192any) at the beginning of the action or function body, or the EOL or
5193@samp{;} which marks an implicit action. Although this @samp{@}} is
5194usually placed in column zero, AWK mode doesn't need it to be placed
5195there.
5196
5197@table @asis
5198@item @kbd{C-M-a} @code{c-awk-beginning-of-defun}
5199@itemx @kbd{C-M-e} @code{c-awk-end-of-defun}
5200@findex c-awk-beginning-of-defun
5201@findex awk-beginning-of-defun (c-)
5202@findex c-awk-end-of-defun
5203@findex awk-end-of-defun (c-)
5204Move point back to the beginning or forward to the end of the current
5205AWK defun. These functions can take prefix-arguments, their
5206functionality being entirely equivalent to @code{beginning-of-defun}
5207and @code{end-of-defun}. @xref{Moving by Defuns,,,emacs}.
5208
5209@item @kbd{C-M-h} @code{c-mark-function}
5210This works fine with AWK defuns. @xref{Indentation Commands}.
d7bd46ed
GM
5211@end table
5212
6bf7aab6 5213
d7bd46ed 5214@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6b61353c
KH
5215@node Odds and Ends, Performance Issues, AWK Mode, Top
5216@comment node-name, next, previous, up
5217@chapter Odds and Ends
5218@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5219
5220The stuff that didn't fit in anywhere else is documented here.
5221
5222@defopt c-require-final-newline
5223@vindex require-final-newline (c-)
5224Controls whether a final newline is ensured when the file is saved. The
5225value is an association list that for each language mode specifies the
5226value to give to @code{require-final-newline} at mode initialization;
5227see that variable for details about the value. If a language isn't
5228present on the association list, CC Mode won't set
5229@code{require-final-newline} in buffers for that language.
5230
5231The default is to set @code{require-final-newline} to @code{t} in the
5232languages that mandates that source files should end with newlines,
5233i.e. C, C++ and Objective-C.
5234@end defopt
5235
5236@defopt c-echo-syntactic-information-p
5237@vindex echo-syntactic-information-p (c-)
5238If non-@code{nil}, the syntactic analysis for the current line is shown
5239in the echo area when it's indented (unless
5240@code{c-syntactic-indentation} is @code{nil}). That's useful when
5241finding out which syntactic symbols to modify to get the indentation you
5242want.
5243@end defopt
5244
5245@defopt c-report-syntactic-errors
5246@vindex report-syntactic-errors (c-)
5247If non-@code{nil}, certain syntactic errors are reported with a ding and
5248a message, for example when an @code{else} is indented for which there
5249is no corresponding @code{if}.
5250
5251Note however that @ccmode{} doesn't make any special effort to check for
5252syntactic errors; that's the job of the compiler. The reason it can
5253report cases like the one above is that it can't find the correct
5254anchoring position to indent the line in that case.
5255@end defopt
5256
5257
5258@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5259@node Performance Issues, Limitations and Known Bugs, Odds and Ends, Top
d7bd46ed 5260@comment node-name, next, previous, up
6b61353c
KH
5261@chapter Performance Issues
5262@cindex performance
6bf7aab6
DL
5263@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5264
6b61353c
KH
5265@comment FIXME: (ACM, 2003/5/24). Check whether AWK needs mentioning here.
5266
6bf7aab6 5267C and its derivative languages are highly complex creatures. Often,
6b61353c
KH
5268ambiguous code situations arise that require @ccmode{} to scan large
5269portions of the buffer to determine syntactic context. Such
5270pathological code can cause @ccmode{} to perform fairly badly. This
5271section gives some insight in how @ccmode{} operates, how that interacts
5272with some coding styles, and what you can use to improve performance.
5273
5274The overall goal is that @ccmode{} shouldn't be overly slow (i.e. take
5275more than a fraction of a second) in any interactive operation.
5276I.e. it's tuned to limit the maximum response time in single operations,
5277which sometimes is at the expense of batch-like operations like
5278reindenting whole blocks. If you find that @ccmode{} gradually gets
5279slower and slower in certain situations, perhaps as the file grows in
5280size or as the macro or comment you're editing gets bigger, then chances
5281are that something isn't working right. You should consider reporting
5282it, unless it's something that's mentioned in this section.
6bf7aab6
DL
5283
5284Because @ccmode{} has to scan the buffer backwards from the current
5285insertion point, and because C's syntax is fairly difficult to parse in
5286the backwards direction, @ccmode{} often tries to find the nearest
6b61353c
KH
5287position higher up in the buffer from which to begin a forward scan
5288(it's typically an opening or closing parethesis of some kind). The
5289farther this position is from the current insertion point, the slower it
5290gets.
6bf7aab6
DL
5291
5292@findex beginning-of-defun
5293@findex defun-prompt-regexp
5294One of the simplest things you can do to reduce scan time, is make sure
d7bd46ed 5295any brace that opens a top-level construct@footnote{E.g. a function in
6bf7aab6
DL
5296C, or outermost class definition in C++ or Java.} always appears in the
5297leftmost column. This is actually an Emacs constraint, as embodied in
d7bd46ed 5298the @code{beginning-of-defun} function which @ccmode{} uses heavily. If
6b61353c
KH
5299you hang top-level open braces on the right side of the line, then you
5300might want to set the variable @code{defun-prompt-regexp} to something
5301reasonable, however that ``something reasonable'' is difficult to
5302define, so @ccmode{} doesn't do it for you.
6bf7aab6
DL
5303
5304@vindex c-Java-defun-prompt-regexp
5305@vindex Java-defun-prompt-regexp (c-)
6b61353c
KH
5306A special note about @code{defun-prompt-regexp} in Java mode: The common
5307style is to hang the opening braces of functions and classes on the
5308right side of the line, and that doesn't work well with the Emacs
5309approach. @ccmode{} comes with a variable
6bf7aab6
DL
5310@code{c-Java-defun-prompt-regexp} which tries to define a regular
5311expression usable for this style, but there are problems with it. In
5312some cases it can cause @code{beginning-of-defun} to hang@footnote{This
5313has been observed in Emacs 19.34 and XEmacs 19.15.}. For this reason,
5314it is not used by default, but if you feel adventurous, you can set
5315@code{defun-prompt-regexp} to it in your mode hook. In any event,
6b61353c
KH
5316setting and relying on @code{defun-prompt-regexp} will definitely slow
5317things down because (X)Emacs will be doing regular expression searches a
5318lot, so you'll probably be taking a hit either way!
5319
5320@ccmode{} maintains a cache of the opening parentheses of the blocks
5321surrounding the point, and it adapts that cache as the point is moved
5322around. That means that in bad cases it can take noticeable time to
5323indent a line in a new surrounding, but after that it gets fast as long
5324as the point isn't moved far off. The farther the point is moved, the
5325less useful is the cache. Since editing typically is done in ``chunks''
5326rather than on single lines far apart from each other, the cache
5327typically gives good performance even when the code doesn't fit the
5328Emacs approach to finding the defun starts.
d7bd46ed
GM
5329
5330@vindex c-enable-xemacs-performance-kludge-p
5331@vindex enable-xemacs-performance-kludge-p (c-)
6b61353c 5332XEmacs users can set the variable
d7bd46ed
GM
5333@code{c-enable-xemacs-performance-kludge-p} to non-@code{nil}. This
5334tells @ccmode{} to use XEmacs-specific built-in functions which, in some
6b61353c 5335circumstances, can locate the top-most opening brace much more quickly than
d7bd46ed
GM
5336@code{beginning-of-defun}. Preliminary testing has shown that for
5337styles where these braces are hung (e.g. most JDK-derived Java styles),
5338this hack can improve performance of the core syntax parsing routines
5339from 3 to 60 times. However, for styles which @emph{do} conform to
5340Emacs' recommended style of putting top-level braces in column zero,
5341this hack can degrade performance by about as much. Thus this variable
6b61353c
KH
5342is set to @code{nil} by default, since the Emacs-friendly styles should
5343be more common (and encouraged!). Note that this variable has no effect
5344in Emacs since the necessary built-in functions don't exist (in Emacs
534521.3 as of this writing in May 2003).
5346
5347Text properties are used to speed up skipping over syntactic whitespace,
5348i.e. comments and preprocessor directives. Indenting a line after a
5349huge macro definition can be slow the first time, but after that the
5350text properties are in place and it should be fast (even after you've
5351edited other parts of the file and then moved back).
5352
5353Font locking can be a CPU hog, especially the font locking done on
5354decoration level 3 which tries to be very accurate. Note that that
5355level is designed to be used with a font lock support mode that only
5356fontifies the text that's actually shown, i.e. Lazy Lock or Just-in-time
5357Lock mode, so make sure you use one of them. Fontification of a whole
5358buffer with some thousand lines can often take over a minute. That is
5359a known weakness; the idea is that it never should happen.
5360
5361The most effective way to speed up font locking is to reduce the
5362decoration level to 2 by setting @code{font-lock-maximum-decoration}
5363appropriately. That level is designed to be as pretty as possible
5364without sacrificing performance. @xref{Font Locking Preliminaries}, for
5365more info.
6bf7aab6
DL
5366
5367
cb7f2e96
GM
5368@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5369@node Limitations and Known Bugs, Frequently Asked Questions, Performance Issues, Top
5370@comment node-name, next, previous, up
6b61353c 5371@chapter Limitations and Known Bugs
cb7f2e96
GM
5372@cindex limitations
5373@cindex bugs
5374@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5375
5376@itemize @bullet
5377@item
6b61353c
KH
5378There is no way to apply auto newline settings (@pxref{Auto-newline
5379Insertion}) on already typed lines. That's only a feature to ease
5380interactive editing.
cb7f2e96 5381
6b61353c
KH
5382To generalize this issue a bit: @ccmode{} is not intended to be used as
5383a reformatter for old code in some more or less batch-like way. With
5384the exception of some functions like @code{c-indent-region}, it's only
5385geared to be used interactively to edit new code. There's currently no
5386intention to change this goal.
5387
5388If you want to reformat old code, you're probably better off using some
5389other tool instead, e.g. @ref{Top, , GNU indent, indent, The `indent'
5390Manual}, which has more powerful reformatting capabilities than
5391@ccmode{}.
cb7f2e96 5392
cb7f2e96 5393@item
6b61353c
KH
5394@vindex signal-error-on-buffer-boundary
5395XEmacs has a variable called @code{signal-error-on-buffer-boundary}.
5396It's used as a solution to user interface problems associated with
cb7f2e96 5397buffer movement and the @code{zmacs-region} deactivation on errors.
6b61353c
KH
5398However, setting this variable to a non-default value in XEmacs 19 and
539920 had the deleterious side effect of breaking many built-in primitive
5400functions. @strong{Do not set this variable to @code{nil} in XEmacs
540119 and 20}; you will cause serious problems in @ccmode{} and probably
5402other XEmacs packages! In XEmacs 21 the effects of the variable is
5403limited to some functions that are only used interactively, so it's
5404not a problem there.
cb7f2e96
GM
5405@end itemize
5406
5407
6bf7aab6 5408@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
cb7f2e96 5409@node Frequently Asked Questions, Getting the Latest CC Mode Release, Limitations and Known Bugs, Top
d7bd46ed 5410@comment node-name, next, previous, up
cb7f2e96 5411@appendix Frequently Asked Questions
6bf7aab6
DL
5412@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5413
6b61353c
KH
5414@itemize @bullet
5415@item
6bf7aab6 5416@kindex C-x h
d7bd46ed 5417@kindex C-M-\
6b61353c 5418@emph{How do I reindent the whole file?}
6bf7aab6 5419
6b61353c
KH
5420Visit the file and hit @kbd{C-x h} to mark the whole buffer. Then hit
5421@kbd{C-M-\}.
6bf7aab6 5422
6b61353c
KH
5423@item
5424@kindex C-M-q
5425@kindex C-M-u
5426@emph{How do I reindent the current block?}
6bf7aab6 5427
6b61353c
KH
5428First move to the brace which opens the block with @kbd{C-M-u}, then
5429reindent that expression with @kbd{C-M-q}.
6bf7aab6 5430
6b61353c
KH
5431@item
5432@kindex RET
5433@kindex C-j
5434@emph{Why doesn't the @kbd{RET} key indent the new line?}
6bf7aab6 5435
6b61353c
KH
5436Emacs' convention is that @kbd{RET} just adds a newline, and that
5437@kbd{C-j} adds a newline and indents it. You can make @kbd{RET} do this
5438too by adding this to your @code{c-mode-common-hook}:
6bf7aab6 5439
6bf7aab6 5440@example
d7bd46ed 5441(define-key c-mode-base-map "\C-m" 'c-context-line-break)
6bf7aab6
DL
5442@end example
5443
5444This is a very common question. If you want this to be the default
d7bd46ed 5445behavior, don't lobby me, lobby RMS! @t{:-)}
6bf7aab6 5446
6b61353c
KH
5447@item
5448@emph{I put @code{(c-set-offset 'substatement-open 0)} in my
5449@file{.emacs} file but I get an error saying that @code{c-set-offset}'s
5450function definition is void. What's wrong?}
6bf7aab6 5451
6b61353c
KH
5452This means that @ccmode{} wasn't loaded into your Emacs session by the
5453time the @code{c-set-offset} call was reached, most likely because
5454@ccmode{} is being autoloaded. Instead of putting the
5455@code{c-set-offset} line in your top-level @file{.emacs} file, put it in
5456your @code{c-mode-common-hook}, or simply modify @code{c-offsets-alist}
5457directly:
f214c025 5458
6b61353c
KH
5459@example
5460(setq c-offsets-alist '((substatement-open . 0)))
6bf7aab6
DL
5461@end example
5462
6b61353c
KH
5463@item
5464@kindex M-a
5465@kindex M-e
5466@emph{@kbd{M-a} and @kbd{M-e} used to move over entire balanced brace
5467lists, but now they move into blocks. How do I get the old behavior
5468back?}
5469
5470Use @kbd{C-M-f} and @kbd{C-M-b} to move over balanced brace blocks. Use
5471@kbd{M-a} and @kbd{M-e} to move by statements, which will also move into
5472blocks.
5473
5474@item
5475@emph{Whenever I try to indent a line or type an ``electric'' key such
5476as @kbd{;}, @kbd{@{}, or @kbd{@}}, I get an error that look like this:
5477@code{Invalid function: (macro . #[...}. What gives?}
5478
5479This is a common error when @ccmode{} hasn't been compiled correctly,
5480especially under Emacs 19.34@footnote{Technically, it's because some
5481macro wasn't defined during the compilation, so the byte compiler put
5482in function calls instead of the macro expansions. Later, when the
5483interpreter tries to call the macro as a function, it shows this
5484(somewhat cryptic) error message.}. If you are using the standalone
d7bd46ed
GM
5485@ccmode{} distribution, try recompiling it according to the instructions
5486in the @file{README} file.
6b61353c 5487@end itemize
6bf7aab6
DL
5488
5489
5490@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
cb7f2e96 5491@node Getting the Latest CC Mode Release, Mailing Lists and Submitting Bug Reports, Frequently Asked Questions, Top
d7bd46ed 5492@comment node-name, next, previous, up
cb7f2e96 5493@appendix Getting the Latest CC Mode Release
6bf7aab6
DL
5494@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5495
6b61353c
KH
5496@ccmode{} has been standard with all versions of Emacs since 19.34 and
5497of XEmacs since 19.16.
d7bd46ed 5498
6b61353c 5499@cindex web site
d7bd46ed 5500Due to release schedule skew, it is likely that all of these Emacsen
177c0ea7 5501have old versions of @ccmode{} and so should be upgraded. Access to the
d7bd46ed 5502@ccmode{} source code, as well as more detailed information on Emacsen
6b61353c 5503compatibility, etc. are all available on the web site:
d7bd46ed 5504
6b61353c
KH
5505@quotation
5506@uref{http://cc-mode.sourceforge.net/}
5507@end quotation
6bf7aab6 5508
6bf7aab6 5509
cb7f2e96
GM
5510@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5511@node Mailing Lists and Submitting Bug Reports, Sample .emacs File, Getting the Latest CC Mode Release, Top
5512@comment node-name, next, previous, up
5513@appendix Mailing Lists and Submitting Bug Reports
cb7f2e96
GM
5514@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5515
5516@kindex C-c C-b
5517@findex c-submit-bug-report
5518@findex submit-bug-report (c-)
6b61353c
KH
5519To report bugs, use the @kbd{C-c C-b} (bound to
5520@code{c-submit-bug-report}) command. This provides vital information
5521we need to reproduce your problem. Make sure you include a concise,
5522but complete code example. Please try to boil your example down to
5523just the essential code needed to reproduce the problem, and include
5524an exact recipe of steps needed to expose the bug. Be especially sure
5525to include any code that appears @emph{before} your bug example, if
5526you think it might affect our ability to reproduce it.
cb7f2e96
GM
5527
5528Please try to produce the problem in an Emacs instance without any
5529customizations loaded (i.e. start it with the @code{-q -no-site-file}
5530arguments). If it works correctly there, the problem might be caused by
5531faulty customizations in either your own or your site configuration. In
5532that case, we'd appreciate if you isolate the Emacs Lisp code that trigs
5533the bug and include it in your report.
5534
5535@cindex bug report mailing list
6b61353c
KH
5536Bug reports are sent to @email{bug-cc-mode@@gnu.org}. You can also send
5537other questions and suggestions (kudos? @t{;-)} to that address. It's a
5538mailing list which you can join or browse an archive of; see the web
5539site at @uref{http://cc-mode.sourceforge.net/} for further details.
cb7f2e96
GM
5540
5541@cindex announcement mailing list
5542If you want to get announcements of new @ccmode{} releases, send the
5543word @emph{subscribe} in the body of a message to
6b61353c
KH
5544@email{cc-mode-announce-request@@lists.sourceforge.net}. It's possible
5545to subscribe from the web site too. Announcements will also be posted
5546to the Usenet newsgroups @code{gnu.emacs.sources}, @code{comp.emacs} and
5547@code{comp.emacs.xemacs}.
cb7f2e96
GM
5548
5549
6bf7aab6 5550@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6b61353c 5551@node Sample .emacs File, Command and Function Index, Mailing Lists and Submitting Bug Reports, Top
d7bd46ed 5552@comment node-name, next, previous, up
cb7f2e96 5553@appendix Sample .emacs file
6bf7aab6
DL
5554@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5555
5556@example
6b61353c
KH
5557;; Here's a sample .emacs file that might help you along the way.
5558;; Just copy this region and paste it into your .emacs file. You may
5559;; want to change some of the actual values.
6bf7aab6
DL
5560
5561(defconst my-c-style
5562 '((c-tab-always-indent . t)
5563 (c-comment-only-line-offset . 4)
5564 (c-hanging-braces-alist . ((substatement-open after)
5565 (brace-list-open)))
5566 (c-hanging-colons-alist . ((member-init-intro before)
5567 (inher-intro)
5568 (case-label after)
5569 (label after)
5570 (access-label after)))
5571 (c-cleanup-list . (scope-operator
5572 empty-defun-braces
5573 defun-close-semi))
5574 (c-offsets-alist . ((arglist-close . c-lineup-arglist)
5575 (substatement-open . 0)
5576 (case-label . 4)
5577 (block-open . 0)
5578 (knr-argdecl-intro . -)))
6b61353c 5579 (c-echo-syntactic-information-p . t))
6bf7aab6
DL
5580 "My C Programming Style")
5581
d7bd46ed 5582;; offset customizations not in my-c-style
f214c025 5583(setq c-offsets-alist '((member-init-intro . ++)))
d7bd46ed
GM
5584
5585;; Customizations for all modes in CC Mode.
6bf7aab6
DL
5586(defun my-c-mode-common-hook ()
5587 ;; add my personal style and set it for the current buffer
5588 (c-add-style "PERSONAL" my-c-style t)
6bf7aab6
DL
5589 ;; other customizations
5590 (setq tab-width 8
5591 ;; this will make sure spaces are used instead of tabs
5592 indent-tabs-mode nil)
5593 ;; we like auto-newline and hungry-delete
5594 (c-toggle-auto-hungry-state 1)
47d7776c 5595 ;; key bindings for all supported languages. We can put these in
6bf7aab6 5596 ;; c-mode-base-map because c-mode-map, c++-mode-map, objc-mode-map,
d7bd46ed 5597 ;; java-mode-map, idl-mode-map, and pike-mode-map inherit from it.
6b61353c 5598 (define-key c-mode-base-map "\C-m" 'c-context-line-break))
6bf7aab6
DL
5599
5600(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
5601@end example
5602
d7bd46ed 5603
6bf7aab6 5604@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6b61353c 5605@node Command and Function Index, Variable Index, Sample .emacs File, Top
d7bd46ed 5606@comment node-name, next, previous, up
6b61353c 5607@unnumbered Command and Function Index
d7bd46ed 5608@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6bf7aab6 5609
6b61353c
KH
5610Since most @ccmode{} commands are prepended with the string
5611@samp{c-}, each appears under its @code{c-@var{thing}} name and its
5612@code{@var{thing} (c-)} name.
5613@iftex
5614@sp 2
5615@end iftex
5616@printindex fn
6bf7aab6
DL
5617
5618
d7bd46ed 5619@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6b61353c 5620@node Variable Index, Concept Index, Command and Function Index, Top
d7bd46ed 5621@comment node-name, next, previous, up
6b61353c 5622@unnumbered Variable Index
d7bd46ed 5623@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6bf7aab6 5624
6b61353c
KH
5625Since most @ccmode{} variables are prepended with the string
5626@samp{c-}, each appears under its @code{c-@var{thing}} name and its
5627@code{@var{thing} (c-)} name.
6bf7aab6
DL
5628@iftex
5629@sp 2
5630@end iftex
6b61353c 5631@printindex vr
6bf7aab6
DL
5632
5633
d7bd46ed 5634@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6b61353c 5635@node Concept Index, , Variable Index, Top
d7bd46ed 5636@comment node-name, next, previous, up
6b61353c 5637@unnumbered Concept Index
d7bd46ed 5638@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6bf7aab6 5639
6b61353c 5640@printindex cp
6bf7aab6
DL
5641
5642
d7bd46ed 5643@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6b61353c 5644@comment Epilogue.
d7bd46ed 5645@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6bf7aab6 5646
cb7f2e96 5647@iftex
6bf7aab6
DL
5648@page
5649@summarycontents
5650@contents
cb7f2e96
GM
5651@end iftex
5652
6bf7aab6 5653@bye
6b61353c
KH
5654
5655@ignore
5656 arch-tag: c4cab162-5e57-4366-bdce-4a9db2fc97f0
5657@end ignore