cc-mode.texi 263 KB
Newer Older
Glenn Morris's avatar
Glenn Morris committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
\input texinfo
@c Notes to self regarding line handling:
@c Empty lines are often significant before @end directives; avoid them.
@c Empty lines before and after @example directives are significant in
@c info output but not in TeX.  Empty lines inside @example directives
@c are significant.

@c Conventions for formatting examples:
@c o  If the example contains empty lines then put the surrounding empty
@c    lines inside the @example directives.  Put them outside otherwise.
@c o  Use @group inside the example only if it shows indentation where
@c    the relation between lines inside is relevant.
@c o  Format line number columns like this:
@c     1: foo
@c     2: bar
@c       ^ one space
@c    ^^ two columns, right alignment
@c o  Check line lengths in TeX output; they can typically be no longer
@c    than 70 chars, 60 if the paragraph is indented.

@comment TBD: Document the finer details of statement anchoring?

@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@comment %**start of header (This is for running Texinfo on a region)
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@comment How to make the various output formats:
@comment (Thanks to Robert Chassell for supplying this information.)
@comment Note that Texinfo 4.7 (or later) is needed.
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
In each of the following pairs of commands, the first generates a
version with cross references pointing to the GNU Emacs manuals,
the second with them pointing to the XEmacs manuals.
    ## Info output
    makeinfo cc-mode.texi
    makeinfo -DXEMACS cc-mode.texi

    ## DVI output
    ## You may need to set up the environment variable TEXINPUTS so
    ## that tex can find the file texinfo.tex - See the tex
    ## manpage.
    texi2dvi cc-mode.texi
    texi2dvi -t "@set XEMACS " cc-mode.texi

    ## HTML output.  (The --no-split parameter is optional)
    makeinfo --html --no-split cc-mode.texi
    makeinfo --html --no-split -DXEMACS cc-mode.texi

    ## Plain text output
    makeinfo --fill-column=70 --no-split --paragraph-indent=0 \
      --no-headers --output=cc-mode.txt cc-mode.texi
    makeinfo --fill-column=70 --no-split --paragraph-indent=0 \
      --no-headers --output=cc-mode.txt -DXEMACS cc-mode.texi

    ## DocBook output
    makeinfo --docbook --no-split --paragraph-indent=0 \
    makeinfo --docbook --no-split --paragraph-indent=0 \
      -DXEMACS cc-mode.texi

    ## XML output
    makeinfo --xml --no-split --paragraph-indent=0 \
    makeinfo --xml --no-split --paragraph-indent=0 \
      -DXEMACS cc-mode.texi

    #### (You must be in the same directory as the viewed file.)

      ## View DVI output
      xdvi cc-mode.dvi &

      ## View HTML output
      mozilla cc-mode.html
@end ignore

@comment No overfull hbox marks in the dvi file.

@setfilename  ../../info/ccmode
Glenn Morris's avatar
Glenn Morris committed
@settitle     CC Mode Manual
Paul Eggert's avatar
Paul Eggert committed
@documentencoding UTF-8
Glenn Morris's avatar
Glenn Morris committed
87 88 89 90 91
@footnotestyle end

@c The following four macros generate the filenames and titles of the
@c main (X)Emacs manual and the Elisp/Lispref manual.  Leave the
@c Texinfo variable `XEMACS' unset to generate a GNU Emacs version, set it
@c to generate an XEmacs version, e.g., with
Glenn Morris's avatar
Glenn Morris committed
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
@c "makeinfo -DXEMACS cc-mode.texi".
@ifset XEMACS
@macro emacsman
@end macro
@macro emacsmantitle
XEmacs User's Manual
@end macro
@macro lispref
@end macro
@macro lispreftitle
XEmacs Lisp Reference Manual
@end macro
@end ifset

@ifclear XEMACS
@macro emacsman
@end macro
@macro emacsmantitle
GNU Emacs Manual
@end macro
@macro lispref
@end macro
@macro lispreftitle
GNU Emacs Lisp Reference Manual
@end macro
@end ifclear

@macro ccmode
CC Mode
@end macro

@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@comment @setchapternewpage odd !! we don't want blank pages !!
@comment %**end of header (This is for running Texinfo on a region)
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@comment Texinfo manual for CC Mode
@comment Generated from the original README file by Krishna Padmasola
@comment <>
@comment Authors:
@comment Barry A. Warsaw
@comment Martin Stjernholm
@comment Alan Mackenzie
@comment Maintained by Martin Stjernholm and Alan Mackenzie <>
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

@comment Define an index for syntactic symbols.
@defindex ss

@comment Combine key, syntactic symbol and concept indices into one.
@syncodeindex ss cp
@syncodeindex ky cp

This manual is for CC Mode in Emacs.

Paul Eggert's avatar
Paul Eggert committed
Copyright @copyright{} 1995--2014 Free Software Foundation, Inc.
Glenn Morris's avatar
Glenn Morris committed
161 162 163

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
165 166 167 168
any later version published by the Free Software Foundation; with no
Invariant Sections, with the Front-Cover texts being ``A GNU Manual'',
and with the Back-Cover Texts as in (a) below.  A copy of the license
is included in the section entitled ``GNU Free Documentation License''.
Glenn Morris's avatar
Glenn Morris committed

(a) The FSF's Back-Cover Text is: ``You have the freedom to copy and
modify this GNU manual.''
Glenn Morris's avatar
Glenn Morris committed
172 173 174 175 176
@end quotation
@end copying

@comment Info directory entry for use by install-info. The indentation
@comment here is by request from the FSF folks.
@dircategory Emacs editing modes
Glenn Morris's avatar
Glenn Morris committed
* CC Mode: (ccmode).            Emacs mode for editing C, C++, Objective-C,
                                  Java, Pike, AWK, and CORBA IDL code.
Glenn Morris's avatar
Glenn Morris committed
181 182 183 184 185 186 187 188 189
@end direntry

@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@comment TeX title page
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

@sp 10

@center @titlefont{CC Mode 5.32}
Glenn Morris's avatar
Glenn Morris committed
@sp 2
@center A GNU Emacs mode for editing C and C-like languages
Glenn Morris's avatar
Glenn Morris committed
193 194 195 196 197 198 199
@sp 2
@center Barry A. Warsaw, Martin Stjernholm, Alan Mackenzie

@vskip 0pt plus 1filll

200 201
This manual was generated from cc-mode.texi, which is distributed with Emacs,
or can be downloaded from @url{}.
Glenn Morris's avatar
Glenn Morris committed
202 203 204 205 206 207 208
@end titlepage

@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@comment The Top node contains the master menu for the Info file.
@comment This appears only in the Info file, not the printed manual.
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

209 210 211

Glenn Morris's avatar
Glenn Morris committed
212 213 214
@node    Top, Introduction, (dir), (dir)
@comment node-name, next, previous, up

Glenn Morris's avatar
Glenn Morris committed
216 217 218 219 220 221 222
@top @ccmode{}

@ccmode{} is a GNU Emacs mode for editing files containing C, C++,
Objective-C, Java, CORBA IDL (and the variants PSDL and CIDL), Pike
and AWK code.  It provides syntax-based indentation, font locking, and
has several handy commands and some minor modes to make the editing
easier.  It does not provide tools to look up and navigate between
functions, classes, etc.; there are other packages for that.
224 225 226

@end ifnottex
Glenn Morris's avatar
Glenn Morris committed
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244

@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

* Introduction::
* Overview::
* Getting Started::
* Commands::
* Font Locking::
* Config Basics::
* Custom Filling and Breaking::
* Custom Auto-newlines::
* Clean-ups::
* Indentation Engine Basics::
* Customizing Indentation::
* Custom Macros::
* Odds and Ends::
* Sample Init File::
Glenn Morris's avatar
Glenn Morris committed
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
* Performance Issues::
* Limitations and Known Bugs::
* FAQ::
* Updating CC Mode::
* Mailing Lists and Bug Reports::
* GNU Free Documentation License::
* Command and Function Index::
* Variable Index::
* Concept and Key Index::

 --- The Detailed Node Listing ---


* Indentation Commands::
* Comment Commands::
* Movement Commands::
* Filling and Breaking::
* Minor Modes::
* Electric Keys::
* Auto-newlines::
* Hungry WS Deletion::
* Subword Movement::
* Other Commands::

Font Locking

* Font Locking Preliminaries::
* Faces::
* Doc Comments::
* AWK Mode Font Locking::

Configuration Basics

* CC Hooks::
* Style Variables::
* Styles::


Paul Eggert's avatar
Paul Eggert committed
287 288 289 290 291
* Built-in Styles::
* Choosing a Style::
* Adding Styles::
* Guessing the Style::
* File Styles::
Glenn Morris's avatar
Glenn Morris committed
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310

Customizing Auto-newlines

* Hanging Braces::
* Hanging Colons::
* Hanging Semicolons and Commas::

Hanging Braces

* Custom Braces::

Indentation Engine Basics

* Syntactic Analysis::
* Syntactic Symbols::
* Indentation Calculation::

Syntactic Symbols

Paul Eggert's avatar
Paul Eggert committed
311 312 313 314 315 316 317 318 319 320
* Function Symbols::
* Class Symbols::
* Conditional Construct Symbols::
* Switch Statement Symbols::
* Brace List Symbols::
* External Scope Symbols::
* Paren List Symbols::
* Literal Symbols::
* Multiline Macro Symbols::
* Objective-C Method Symbols::
* Java Symbols::
Paul Eggert's avatar
Paul Eggert committed
322 323
* Statement Block Symbols::
* K&R Symbols::
Glenn Morris's avatar
Glenn Morris committed
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340

Customizing Indentation

* c-offsets-alist::
* Interactive Customization::
* Line-Up Functions::
* Custom Line-Up::
* Other Indentation::

Line-Up Functions

* Brace/Paren Line-Up::
* List Line-Up::
* Operator Line-Up::
* Comment Line-Up::
* Misc Line-Up::

341 342
Customizing Macros

Paul Eggert's avatar
Paul Eggert committed
343 344
* Macro Backslashes::
* Macros with ;::

Glenn Morris's avatar
Glenn Morris committed
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
@end detailmenu
@end menu

@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@node    Introduction, Overview, Top, Top
@comment node-name, next, previous, up
@chapter Introduction
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

@cindex BOCM
@cindex history
@cindex awk-mode.el
@cindex c-mode.el
@cindex c++-mode.el

Welcome to @ccmode{}, a GNU Emacs mode for editing files containing C,
C++, Objective-C, Java, CORBA IDL (and the variants CORBA PSDL and
CIDL), Pike and AWK code.  This incarnation of the mode is descended
from @file{c-mode.el} (also called ``Boring Old C Mode'' or BOCM
@t{:-)}, @file{c++-mode.el} version 2, which Barry Warsaw had been
maintaining since 1992, and @file{awk-mode.el}, a long neglected mode
in the (X)Emacs base.

Late in 1997, Martin Stjernholm joined Barry on the @ccmode{}
Maintainers Team, and implemented the Pike support.  In 2000 Martin
took over as the sole maintainer.  In 2001 Alan Mackenzie joined the
team, implementing AWK support in version 5.30.  @ccmode{} did not
originally contain the font lock support for its languages; that
Glenn Morris's avatar
Glenn Morris committed
374 375 376 377
was added in version 5.30.

This manual describes @ccmode{}
@comment The following line must appear on its own, so that the
version 5.32.
Glenn Morris's avatar
Glenn Morris committed
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444
@comment script can update the version number automatically

@ccmode{} supports the editing of K&R and ANSI C, C++, Objective-C,
Java, CORBA's Interface Definition Language, Pike@footnote{A C-like
scripting language with its roots in the LPC language used in some MUD
engines.  See @uref{}.} and AWK files.  In this
way, you can easily set up consistent font locking and coding styles for
use in editing all of these languages, although AWK is not yet as
uniformly integrated as the other languages.

@findex c-mode
@findex c++-mode
@findex objc-mode
@findex java-mode
@findex idl-mode
@findex pike-mode
@findex awk-mode
Note that the name of this package is ``@ccmode{}'', but there is no top
level @code{cc-mode} entry point.  All of the variables, commands, and
functions in @ccmode{} are prefixed with @code{c-@var{thing}}, and
@code{c-mode}, @code{c++-mode}, @code{objc-mode}, @code{java-mode},
@code{idl-mode}, @code{pike-mode}, and @code{awk-mode} entry points are
provided.  This package is intended to be a replacement for
@file{c-mode.el}, @file{c++-mode.el} and @file{awk-mode.el}.

A special word of thanks goes to Krishna Padmasola for his work in
converting the original @file{README} file to Texinfo format.  I'd
also like to thank all the @ccmode{} victims who help enormously
during the early beta stages of @ccmode{}'s development.

@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@node    Overview, Getting Started, Introduction, Top
@comment  node-name,  next,  previous,  up@cindex organization of the manual
@chapter Overview of the Manual
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

The manual starts with several introductory chapters (including this

The next chunk of the manual describes the day to day @emph{use} of
@ccmode{} (as contrasted with how to customize it).

@itemize @bullet
The chapter ``Commands'' describes in detail how to use (nearly) all
of @ccmode{}'s features.  There are extensive cross-references from
here to the corresponding sections later in the manual which tell you
how to customize these features.

``Font Locking'' describes how ``syntax highlighting'' is applied to
your buffers.  It is mainly background information and can be skipped
over at a first reading.
@end itemize

The next chunk of the manual describes how to @emph{customize}
@ccmode{}.  Typically, an overview of a topic is given at the chapter
level, then the sections and subsections describe the material in
increasing detail.

@itemize @bullet
The chapter ``Configuration Basics'' tells you @emph{how} to write
customizations: whether in hooks, in styles, in both, or in neither,
Glenn Morris's avatar
Glenn Morris committed
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
depending on your needs.  It describes the @ccmode{} style system and
lists the standard styles that @ccmode{} supplies.

The next few chapters describe in detail how to customize the various
features of @ccmode{}.

Finally, there is a sample @file{.emacs} fragment, which might help you
in creating your own customization.
@end itemize

The manual ends with ``this and that'', things that don't fit cleanly
into any of the previous chunks.

@itemize @bullet
Two chapters discuss the performance of @ccmode{} and known

The FAQ contains a list of common problems and questions.

The next two chapters tell you how to get in touch with the @ccmode{}
project: whether for updating @ccmode{} or submitting bug reports.
Glenn Morris's avatar
Glenn Morris committed
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
@end itemize

Finally, there are the customary indices.

@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@node    Getting Started, Commands, Overview, Top
@comment node-name, next, previous, up
@chapter Getting Started
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

If you got this version of @ccmode{} with Emacs or XEmacs, it should
work just fine right out of the box.  Note however that you might not
have the latest @ccmode{} release and might want to upgrade your copy
(see below).

489 490
You should probably start by skimming through the entire Commands chapter
(@pxref{Commands}) to get an overview of @ccmode{}'s capabilities.
Glenn Morris's avatar
Glenn Morris committed
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648

After trying out some commands, you may dislike some aspects of
@ccmode{}'s default configuration.  Here is an outline of how to
change some of the settings that newcomers to @ccmode{} most often
want to change:

@table @asis
@item c-basic-offset
This Lisp variable holds an integer, the number of columns @ccmode{}
indents nested code.  To set this value to 6, customize
@code{c-basic-offset} or put this into your @file{.emacs}:

(setq c-basic-offset 6)
@end example

@item The (indentation) style
The basic ``shape'' of indentation created by @ccmode{}---by default,
this is @code{gnu} style (except for Java and AWK buffers).  A list of
the available styles and their descriptions can be found in
@ref{Built-in Styles}.  A complete specification of the @ccmode{}
style system, including how to create your own style, can be found in
the chapter @ref{Styles}.  To set your style to @code{linux}, either
customize @code{c-default-style} or put this into your @file{.emacs}:

(setq c-default-style '((java-mode . "java")
                        (awk-mode . "awk")
                        (other . "linux")))
@end example

@item Electric Indentation
Normally, when you type ``punctuation'' characters such as @samp{;} or
@samp{@{}, @ccmode{} instantly reindents the current line.  This can
be disconcerting until you get used to it.  To disable @dfn{electric
indentation} in the current buffer, type @kbd{C-c C-l}.  Type the same
thing to enable it again.  To have electric indentation disabled by
default, put the following into your @file{.emacs} file@footnote{There
is no ``easy customization'' facility for making this change.}:

(setq-default c-electric-flag nil)
@end example

Details of this and other similar ``Minor Modes'' appear in the
section @ref{Minor Modes}.

@item Making the @key{RET} key indent the new line
The standard Emacs binding for @key{RET} just adds a new line.  If you
want it to reindent the new line as well, rebind the key.  Note that
the action of rebinding would fail if the pertinent keymap didn't yet
exist---we thus need to delay the action until after @ccmode{} has
been loaded.  Put the following code into your @file{.emacs}:

(defun my-make-CR-do-indent ()
  (define-key c-mode-base-map "\C-m" 'c-context-line-break))
(add-hook 'c-initialization-hook 'my-make-CR-do-indent)
@end example

This example demonstrates the use of a very powerful @ccmode{} (and
Emacs) facility, the hook.  The use of @ccmode{}'s hooks is described
in @ref{CC Hooks}.
@end table

All these settings should occur in your @file{.emacs} @emph{before}
any @ccmode{} buffers get loaded---in particular, before any call of

As you get to know the mode better, you may want to make more
ambitious changes to your configuration.  For this, you should start
reading the chapter @ref{Config Basics}.

If you are upgrading an existing @ccmode{} installation, please see
the @file{README} file for installation details.  In particular, if
you are going to be editing AWK files, @file{README} describes how to
configure your (X)Emacs so that @ccmode{} will supersede the obsolete
@code{awk-mode.el} which might have been supplied with your (X)Emacs.
@ccmode{} might not work with older versions of Emacs or XEmacs.  See
the @ccmode{} release notes at @uref{}
for the latest information on Emacs version and package compatibility
(@pxref{Updating CC Mode}).

@deffn Command c-version
@findex version (c-)
You can find out what version of @ccmode{} you are using by visiting a C
file and entering @kbd{M-x c-version RET}.  You should see this message in
the echo area:

Using CC Mode version 5.XX
@end example

where @samp{XX} is the minor release number.
@end deffn

@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@node    Commands, Font Locking, Getting Started, Top
@comment node-name, next, previous, up
@chapter Commands
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

This chapter specifies all of CC Mode's commands, and thus contains
nearly everything you need to know to @emph{use} @ccmode{} (as
contrasted with configuring it).  @dfn{Commands} here means both
control key sequences and @dfn{electric keys}, these being characters
such as @samp{;} which, as well as inserting themselves into the
buffer, also do other things.

You might well want to review
@ifset XEMACS
@ref{Lists,,,@emacsman{}, @emacsmantitle{}},
@end ifset
@ifclear XEMACS
@ref{Moving by Parens,,,@emacsman{}, @emacsmantitle{}},
@end ifclear
which describes commands for moving around brace and parenthesis

* Indentation Commands::
* Comment Commands::
* Movement Commands::
* Filling and Breaking::
* Minor Modes::
* Electric Keys::
* Auto-newlines::
* Hungry WS Deletion::
* Subword Movement::
* Other Commands::
@end menu

@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@node    Indentation Commands, Comment Commands, Commands, Commands
@comment node-name, next, previous,up
@section Indentation Commands
@cindex indentation
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

The following commands reindent C constructs.  Note that when you
change your coding style, either interactively or through some other
means, your file does @emph{not} automatically get reindented.  You
will need to execute one of the following commands to see the effects
of your changes.

@cindex GNU indent program
Also, variables like @code{c-hanging-*} and @code{c-cleanup-list}
(@pxref{Custom Auto-newlines}) only affect how on-the-fly code is
formatted.  Changing the ``hanginess'' of a brace and then
reindenting, will not move the brace to a different line.  For this,
you're better off getting an external program like GNU @code{indent},
which will rearrange brace location, amongst other things.

Preprocessor directives are handled as syntactic whitespace from other
code, i.e., they can be interspersed anywhere without affecting the
Glenn Morris's avatar
Glenn Morris committed
650 651 652 653 654
indentation of the surrounding code, just like comments.

The code inside macro definitions is, by default, still analyzed
syntactically so that you get relative indentation there just as you'd
get if the same code was outside a macro.  However, since there is no
hint about the syntactic context, i.e., whether the macro expands to an
Glenn Morris's avatar
Glenn Morris committed
656 657 658 659
expression, to some statements, or perhaps to whole functions, the
syntactic recognition can be wrong.  @ccmode{} manages to figure it
out correctly most of the time, though.

660 661 662 663
Some macros, when invoked, ''have their own semicolon''.  To get the
next line indented correctly, rather than as a continuation line,
@xref{Macros with ;}.

Glenn Morris's avatar
Glenn Morris committed
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703
Reindenting large sections of code can take a long time.  When
@ccmode{} reindents a region of code, it is essentially equivalent to
hitting @key{TAB} on every line of the region.

These commands indent code:

@table @asis
@item @kbd{@key{TAB}} (@code{c-indent-command})
@kindex TAB
@findex c-indent-command
@findex indent-command (c-)
This command indents the current line.  That is all you need to know
about it for normal use.

@code{c-indent-command} does different things, depending on the
setting of @code{c-syntactic-indentation} (@pxref{Indentation Engine

@itemize @bullet
When it's non-@code{nil} (which it normally is), the command indents
the line according to its syntactic context.  With a prefix argument
(@kbd{C-u @key{TAB}}), it will re-indent the entire
expression@footnote{this is only useful for a line starting with a
comment opener or an opening brace, parenthesis, or string quote.}
that begins at the line's left margin.

When it's @code{nil}, the command indents the line by an extra
@code{c-basic-offset} columns.  A prefix argument acts as a
multiplier.  A bare prefix (@kbd{C-u @key{TAB}}) is equivalent to -1,
removing @code{c-basic-offset} columns from the indentation.
@end itemize

The precise behavior is modified by several variables: With
@code{c-tab-always-indent}, you can make @key{TAB} insert whitespace
in some circumstances---@code{c-insert-tab-function} then defines
precisely what sort of ``whitespace'' this will be.  Set the standard
Emacs variable @code{indent-tabs-mode} to @code{t} if you want real
@samp{tab} characters to be used in the indentation, to @code{nil} if
you want only spaces.  @xref{Just Spaces,,,@emacsman{},
Glenn Morris's avatar
Glenn Morris committed
705 706 707 708 709 710 711 712 713 714 715 716 717 718

@defopt c-tab-always-indent
@vindex tab-always-indent (c-)
@cindex literal
This variable modifies how @key{TAB} operates.
@itemize @bullet
When it is @code{t} (the default), @key{TAB} simply indents the
current line.
When it is @code{nil}, @key{TAB} (re)indents the line only if point is
to the left of the first non-whitespace character on the line.
Otherwise it inserts some whitespace (a tab or an equivalent number of
spaces; see below) at point.
Glenn Morris's avatar
Glenn Morris committed
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775
With some other value, the line is reindented.  Additionally, if point
is within a string or comment, some whitespace is inserted.
@end itemize
@end defopt

@defopt c-insert-tab-function
@vindex insert-tab-function (c-)
@findex tab-to-tab-stop
When ``some whitespace'' is inserted as described above, what actually
happens is that the function stored in @code{c-insert-tab-function} is
called.  Normally, this is @code{insert-tab}, which inserts a real tab
character or the equivalent number of spaces (depending on
@code{indent-tabs-mode}).  Some people, however, set
@code{c-insert-tab-function} to @code{tab-to-tab-stop} so as to get
hard tab stops when indenting.
@end defopt
@end table

The kind of indentation the next five commands do depends on the
setting of @code{c-syntactic-indentation} (@pxref{Indentation Engine
@itemize @bullet
when it is non-@code{nil} (the default), the commands indent lines
according to their syntactic context;
when it is @code{nil}, they just indent each line the same amount as
the previous non-blank line.  The commands that indent a region aren't
very useful in this case.
@end itemize

@table @asis
@item @kbd{C-j} (@code{newline-and-indent})
@kindex C-j
@findex newline-and-indent
Inserts a newline and indents the new blank line, ready to start
typing.  This is a standard (X)Emacs command.

@item @kbd{C-M-q} (@code{c-indent-exp})
@kindex C-M-q
@findex c-indent-exp
@findex indent-exp (c-)
Indents an entire balanced brace or parenthesis expression.  Note that
point must be on the opening brace or parenthesis of the expression
you want to indent.

@item @kbd{C-c C-q} (@code{c-indent-defun})
@kindex C-c C-q
@findex c-indent-defun
@findex indent-defun (c-)
Indents the entire top-level function, class or macro definition
encompassing point.  It leaves point unchanged.  This function can't be
used to reindent a nested brace construct, such as a nested class or
function, or a Java method.  The top-level construct being reindented
must be complete, i.e., it must have both a beginning brace and an ending
Glenn Morris's avatar
Glenn Morris committed
777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823

@item @kbd{C-M-\} (@code{indent-region})
@kindex C-M-\
@findex indent-region
Indents an arbitrary region of code.  This is a standard Emacs command,
tailored for C code in a @ccmode{} buffer.  Note, of course, that point
and mark must delineate the region you want to indent.

@item @kbd{C-M-h} (@code{c-mark-function})
@kindex C-M-h
@findex c-mark-function
@findex mark-function (c-)
While not strictly an indentation command, this is useful for marking
the current top-level function or class definition as the current
region.  As with @code{c-indent-defun}, this command operates on
top-level constructs, and can't be used to mark say, a Java method.
@end table

These variables are also useful when indenting code:

@defopt indent-tabs-mode
This is a standard Emacs variable that controls how line indentation
is composed.  When it's non-@code{nil}, tabs can be used in a line's
indentation, otherwise only spaces are used.
@end defopt

@defopt c-progress-interval
@vindex progress-interval (c-)
When indenting large regions of code, this variable controls how often a
progress message is displayed.  Set this variable to @code{nil} to
inhibit the progress messages, or set it to an integer which is how
often (in seconds) progress messages are to be displayed.
@end defopt

@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@node    Comment Commands, Movement Commands, Indentation Commands, Commands
@comment node-name, next, previous, up
@section Comment Commands
@cindex comments (insertion of)
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

@table @asis
@item @kbd{C-c C-c} (@code{comment-region})
@kindex C-c C-c
@findex comment-region
This command comments out the lines that start in the region.  With a
negative argument, it does the opposite: it deletes the comment
Glenn Morris's avatar
Glenn Morris committed
825 826
delimiters from these lines.  @xref{Multi-Line Comments,,, emacs, GNU
Emacs Manual}, for fuller details.  @code{comment-region} isn't
actually part of @ccmode{}; it is given a @ccmode{} binding for
Glenn Morris's avatar
Glenn Morris committed
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890

@item @kbd{M-;} (@code{comment-dwim} or @code{indent-for-comment} @footnote{The name of this command varies between (X)Emacs versions.})
@kindex M-;
@findex comment-dwim
@findex indent-for-comment
Insert a comment at the end of the current line, if none is there
already.  Then reindent the comment according to @code{comment-column}
@ifclear XEMACS
(@pxref{Options for Comments,,, emacs, GNU Emacs Manual})
@end ifclear
@ifset XEMACS
(@pxref{Comments,,, xemacs, XEmacs User's Manual})
@end ifset
and the variables below.  Finally, position the point after the
comment starter.  @kbd{C-u M-;} kills any comment on the current line,
together with any whitespace before it.  This is a standard Emacs
command, but @ccmode{} enhances it a bit with two variables:

@defopt c-indent-comment-alist
@vindex indent-comment-alist (c-)
@vindex comment-column
This style variable allows you to vary the column that @kbd{M-;} puts
the comment at, depending on what sort of code is on the line, and
possibly the indentation of any similar comment on the preceding line.
It is an association list that maps different types of lines to
actions describing how they should be handled.  If a certain line type
isn't present on the list then the line is indented to the column
specified by @code{comment-column}.

See the documentation string for a full description of this
variable (use @kbd{C-h v c-indent-comment-alist}).
@end defopt

@defopt c-indent-comments-syntactically-p
@vindex indent-comments-syntactically-p (c-)
Normally, when this style variable is @code{nil}, @kbd{M-;} will
indent comment-only lines according to @code{c-indent-comment-alist},
just as it does with lines where other code precede the comments.
However, if you want it to act just like @key{TAB} for comment-only
lines you can get that by setting
@code{c-indent-comments-syntactically-p} to non-@code{nil}.

If @code{c-indent-comments-syntactically-p} is non-@code{nil} then
@code{c-indent-comment-alist} won't be consulted at all for comment-only
@end defopt
@end table

@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@node    Movement Commands, Filling and Breaking, Comment Commands, Commands
@comment node-name, next, previous, up
@section Movement Commands
@cindex movement
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

@ccmode{} contains some useful commands for moving around in C code.

@table @asis
@item @kbd{C-M-a} (@code{c-beginning-of-defun})
@itemx @kbd{C-M-e} (@code{c-end-of-defun})
@findex c-beginning-of-defun
@findex c-end-of-defun
891 892
@vindex c-defun-tactic
@vindex defun-tactic (c-)
Glenn Morris's avatar
Glenn Morris committed
893 894 895 896 897 898 899 900 901 902 903 904 905

Move to the beginning or end of the current or next function.  Other
constructs (such as a structs or classes) which have a brace block
also count as ``functions'' here.  To move over several functions, you
can give these commands a repeat count.

The start of a function is at its header.  The end of the function is
after its closing brace, or after the semicolon of a construct (such
as a @code{struct}) which doesn't end at the brace.  These two
commands try to leave point at the beginning of a line near the actual
start or end of the function.  This occasionally causes point not to
move at all.

906 907 908 909 910 911
By default, these commands will recognize functions contained within a
@dfn{declaration scope} such as a C++ @code{class} or @code{namespace}
construct, should the point start inside it.  If @ccmode fails to find
function beginnings or ends inside the current declaration scope, it
will search the enclosing scopes.  If you want @ccmode to recognize
functions only at the top level@footnote{this was @ccmode{}'s
Paul Eggert's avatar
Paul Eggert committed
behavior prior to version 5.32.}, set @code{c-defun-tactic} to
913 914

Glenn Morris's avatar
Glenn Morris committed
915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023
These functions are analogous to the Emacs built-in commands
@code{beginning-of-defun} and @code{end-of-defun}, except they
eliminate the constraint that the top-level opening brace of the defun
must be in column zero.  See @ref{Defuns,,,@emacsman{},
@emacsmantitle{}}, for more information.

@item @kbd{C-M-a} (AWK Mode) (@code{c-awk-beginning-of-defun})
@itemx @kbd{C-M-e} (AWK Mode) (@code{c-awk-end-of-defun})
@kindex C-M-a (AWK Mode)
@kindex C-M-e (AWK Mode)
@findex c-awk-beginning-of-defun
@findex awk-beginning-of-defun (c-)
@findex c-awk-end-of-defun
@findex awk-end-of-defun (c-)
Move to the beginning or end of the current or next AWK defun.  These
commands can take prefix-arguments, their functionality being entirely
equivalent to @code{beginning-of-defun} and @code{end-of-defun}.

AWK Mode @dfn{defuns} are either pattern/action pairs (either of which
might be implicit) or user defined functions.  Having the @samp{@{} and
@samp{@}} (if there are any) in column zero, as is suggested for some
modes, is neither necessary nor helpful in AWK mode.

@item @kbd{M-a} (@code{c-beginning-of-statement})
@itemx @kbd{M-e} (@code{c-end-of-statement})
@kindex M-a
@kindex M-e
@findex c-beginning-of-statement
@findex c-end-of-statement
@findex beginning-of-statement (c-)
@findex end-of-statement (c-)
Move to the beginning or end of the innermost C statement.  If point
is already there, move to the next beginning or end of a statement,
even if that means moving into a block.  (Use @kbd{C-M-b} or
@kbd{C-M-f} to move over a balanced block.)  A prefix argument @var{n}
means move over @var{n} statements.

If point is within or next to a comment or a string which spans more
than one line, these commands move by sentences instead of statements.

When called from a program, these functions take three optional
arguments: the repetition count, a buffer position limit which is the
farthest back to search for the syntactic context, and a flag saying
whether to do sentence motion in or near comments and multiline

@item @kbd{C-c C-u} (@code{c-up-conditional})
@kindex C-c C-u
@findex c-up-conditional
@findex up-conditional (c-)
Move back to the containing preprocessor conditional, leaving the mark
behind.  A prefix argument acts as a repeat count.  With a negative
argument, move forward to the end of the containing preprocessor

@samp{#elif} is treated like @samp{#else} followed by @samp{#if}, so the
function stops at them when going backward, but not when going

This key sequence is not bound in AWK Mode, which doesn't have
preprocessor statements.

@item @kbd{M-x c-up-conditional-with-else}
@findex c-up-conditional-with-else
@findex up-conditional-with-else (c-)
A variety of @code{c-up-conditional} that also stops at @samp{#else}
lines.  Normally those lines are ignored.

@item @kbd{M-x c-down-conditional}
@findex c-down-conditional
@findex down-conditional (c-)
Move forward into the next nested preprocessor conditional, leaving
the mark behind.  A prefix argument acts as a repeat count.  With a
negative argument, move backward into the previous nested preprocessor

@samp{#elif} is treated like @samp{#else} followed by @samp{#if}, so the
function stops at them when going forward, but not when going backward.

@item @kbd{M-x c-down-conditional-with-else}
@findex c-down-conditional-with-else
@findex down-conditional-with-else (c-)
A variety of @code{c-down-conditional} that also stops at @samp{#else}
lines.  Normally those lines are ignored.

@item @kbd{C-c C-p} (@code{c-backward-conditional})
@itemx @kbd{C-c C-n} (@code{c-forward-conditional})
@kindex C-c C-p
@kindex C-c C-n
@findex c-backward-conditional
@findex c-forward-conditional
@findex backward-conditional (c-)
@findex forward-conditional (c-)
Move backward or forward across a preprocessor conditional, leaving
the mark behind.  A prefix argument acts as a repeat count.  With a
negative argument, move in the opposite direction.

These key sequences are not bound in AWK Mode, which doesn't have
preprocessor statements.

@item @kbd{M-x c-backward-into-nomenclature}
@itemx @kbd{M-x c-forward-into-nomenclature}
@findex c-backward-into-nomenclature
@findex c-forward-into-nomenclature
@findex backward-into-nomenclature (c-)
@findex forward-into-nomenclature (c-)
A popular programming style, especially for object-oriented languages
such as C++ is to write symbols in a mixed case format, where the
first letter of each word is capitalized, and not separated by
underscores.  E.g., @samp{SymbolsWithMixedCaseAndNoUnderlines}.
Glenn Morris's avatar
Glenn Morris committed
1025 1026 1027 1028 1029 1030

These commands move backward or forward to the beginning of the next
capitalized word.  With prefix argument @var{n}, move @var{n} times.
If @var{n} is negative, move in the opposite direction.

Note that these two commands have been superseded by
@code{subword-mode}, which you should use instead.  @xref{Subword
Glenn Morris's avatar
Glenn Morris committed
1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045
Movement}.  They might be removed from a future release of @ccmode{}.
@end table

@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@node    Filling and Breaking, Minor Modes, Movement Commands, Commands
@comment  node-name,  next,  previous,  up
@section Filling and Line Breaking Commands
@cindex text filling
@cindex line breaking
@cindex comment handling
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Since there's a lot of normal text in comments and string literals,
@ccmode{} provides features to edit these like in text mode.  The goal
is to do it seamlessly, i.e., you can use auto fill mode, sentence and
Glenn Morris's avatar
Glenn Morris committed
1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060
paragraph movement, paragraph filling, adaptive filling etc. wherever
there's a piece of normal text without having to think much about it.
@ccmode{} keeps the indentation, fixes suitable comment line prefixes,
and so on.

You can configure the exact way comments get filled and broken, and
where Emacs does auto-filling (see @pxref{Custom Filling and
Breaking}).  Typically, the style system (@pxref{Styles}) will have
set this up for you, so you probably won't have to bother.

@findex auto-fill-mode
@cindex Auto Fill mode
@cindex paragraph filling
Line breaks are by default handled (almost) the same regardless of
whether they are made by auto fill mode (@pxref{Auto
Fill,,,@emacsman{}, @emacsmantitle{}}), by paragraph filling (e.g., with
Glenn Morris's avatar
Glenn Morris committed
1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116
@kbd{M-q}), or explicitly with @kbd{M-j} or similar methods.  In
string literals, the new line gets the same indentation as the
previous nonempty line.@footnote{You can change this default by
setting the @code{string} syntactic symbol (@pxref{Syntactic Symbols}
and @pxref{Customizing Indentation})}.

@table @asis
@item @kbd{M-q} (@code{c-fill-paragraph})
@kindex M-q
@findex c-fill-paragraph
@findex fill-paragraph (c-)
@cindex Javadoc markup
@cindex Pike autodoc markup
This command fills multiline string literals and both block
and line style comments.  In Java buffers, the Javadoc markup words
are recognized as paragraph starters.  The line oriented Pike autodoc
markup words are recognized in the same way in Pike mode.

The formatting of the starters (@code{/*}) and enders (@code{*/}) of
block comments are kept as they were before the filling.  I.e., if
either the starter or ender were on a line of its own, then it stays
on its own line; conversely, if the delimiter has comment text on its
line, it keeps at least one word of that text with it on the line.

This command is the replacement for @code{fill-paragraph} in @ccmode{}

@item @kbd{M-j} (@code{c-indent-new-comment-line})
@kindex M-j
@findex c-indent-new-comment-line
@findex indent-new-comment-line (c-)
This breaks the current line at point and indents the new line.  If
point was in a comment, the new line gets the proper comment line
prefix.  If point was inside a macro, a backslash is inserted before
the line break.  It is the replacement for

@item @kbd{M-x c-context-line-break}
@findex c-context-line-break
@findex context-line-break (c-)
Insert a line break suitable to the context: If the point is inside a
comment, the new line gets the suitable indentation and comment line
prefix like @code{c-indent-new-comment-line}.  In normal code it's
indented like @code{newline-and-indent} would do.  In macros it acts
like @code{newline-and-indent} but additionally inserts and optionally
aligns the line ending backslash so that the macro remains unbroken.
@xref{Custom Macros}, for details about the backslash alignment.  In a
string, a backslash is inserted only if the string is within a
macro@footnote{In GCC, unescaped line breaks within strings are

This function is not bound to a key by default, but it's intended to be
used on the @kbd{RET} key.  If you like the behavior of
@code{newline-and-indent} on @kbd{RET}, you should consider switching to
this function.  @xref{Sample Init File}.
Glenn Morris's avatar
Glenn Morris committed
1118 1119 1120 1121 1122

@item @kbd{M-x c-context-open-line}
@findex c-context-open-line
@findex context-open-line (c-)
This is to @kbd{C-o} (@kbd{M-x open-line}) as
@code{c-context-line-break} is to @kbd{RET}.  I.e., it works just like
Glenn Morris's avatar
Glenn Morris committed
1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146
@code{c-context-line-break} but leaves the point before the inserted
line break.
@end table

@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@node    Minor Modes, Electric Keys, Filling and Breaking, Commands
@comment node-name, next, previous, up
@section Minor Modes
@cindex Minor Modes
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

@ccmode{} contains several minor-mode-like features that you might
find useful while writing new code or editing old code:

@table @asis
@item electric mode
When this is enabled, certain visible characters cause reformatting as
they are typed.  This is normally helpful, but can be a nuisance when
editing chaotically formatted code.  It can also be disconcerting,
especially for users who are new to @ccmode{}.
@item auto-newline mode
This automatically inserts newlines where you'd probably want to type
them yourself, e.g., after typing @samp{@}}s.  Its action is suppressed
Glenn Morris's avatar
Glenn Morris committed
1148 1149 1150
when electric mode is disabled.
@item hungry-delete mode
This lets you delete a contiguous block of whitespace with a single
key: for example, the newline and indentation just inserted by
Glenn Morris's avatar
Glenn Morris committed
1152 1153 1154 1155 1156 1157
auto-newline when you want to back up and write a comment after the
last statement.
@item subword mode
This mode makes basic word movement commands like @kbd{M-f}
(@code{forward-word}) and @kbd{M-b} (@code{backward-word}) treat the
parts of sillycapsed symbols as different words.
E.g., @samp{NSGraphicsContext} is treated as three words @samp{NS},
Glenn Morris's avatar
Glenn Morris committed
1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172
@samp{Graphics}, and @samp{Context}.
@item syntactic-indentation mode
When this is enabled (which it normally is), indentation commands such
as @kbd{C-j} indent lines of code according to their syntactic
structure.  Otherwise, a line is simply indented to the same level as
the previous one and @kbd{@key{TAB}} adjusts the indentation in steps
of `c-basic-offset'.
@end table

Full details on how these minor modes work are at @ref{Electric Keys},
@ref{Auto-newlines}, @ref{Hungry WS Deletion}, @ref{Subword Movement},
and @ref{Indentation Engine Basics}.

You can toggle each of these minor modes on and off, and you can
Paul Eggert's avatar
Paul Eggert committed
configure @ccmode{} so that it starts up with your favorite
combination of them (@pxref{Sample Init File}).  By default, when
Glenn Morris's avatar
Glenn Morris committed
you initialize a buffer, electric mode and syntactic-indentation mode
are enabled but the other three modes are disabled.
Glenn Morris's avatar
Glenn Morris committed
1177 1178 1179

@ccmode{} displays the current state of the first four of these minor
modes on the modeline by appending letters to the major mode's name,
one letter for each enabled minor mode: @samp{l} for electric mode,
Glenn Morris's avatar
Glenn Morris committed
1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212
@samp{a} for auto-newline mode, @samp{h} for hungry delete mode, and
@samp{w} for subword mode.  If all these modes were enabled, you'd see
@samp{C/lahw}@footnote{The @samp{C} would be replaced with the name of
the language in question for the other languages @ccmode{} supports.}.

Here are the commands to toggle these modes:

@table @asis
@item @kbd{C-c C-l} (@code{c-toggle-electric-state})
@kindex C-c C-l
@findex c-toggle-electric-state
@findex toggle-electric-state (c-)
Toggle electric minor mode.  When the command turns the mode off, it
also suppresses auto-newline mode.

@item @kbd{C-c C-a} (@code{c-toggle-auto-newline})
@kindex C-c C-a
@findex c-toggle-auto-newline
@findex toggle-auto-newline (c-)
Toggle auto-newline minor mode.  When the command turns the mode on,
it also enables electric minor mode.

@item @kbd{M-x c-toggle-hungry-state}@footnote{Prior to @ccmode{} 5.31, this command was bound to @kbd{C-c C-d}.}
@findex c-toggle-hungry-state
@findex toggle-hungry-state (c-)
Toggle hungry-delete minor mode.

@item @kbd{M-x c-toggle-auto-hungry-state}@footnote{Prior to @ccmode{} 5.31, this command was bound to @kbd{C-c C-t}.}
@findex c-toggle-auto-hungry-state
@findex toggle-auto-hungry-state (c-)
Toggle both auto-newline and hungry delete minor modes.

@item @kbd{C-c C-w} (@code{M-x subword-mode})
Glenn Morris's avatar
Glenn Morris committed
@kindex C-c C-w
@findex subword-mode
Glenn Morris's avatar
Glenn Morris committed
1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237
Toggle subword mode.

@item @kbd{M-x c-toggle-syntactic-indentation}
@findex c-toggle-syntactic-indentation
@findex toggle-syntactic-indentation (c-)
Toggle syntactic-indentation mode.
@end table

Common to all the toggle functions above is that if they are called
programmatically, they take an optional numerical argument.  A
positive value will turn on the minor mode (or both of them in the
case of @code{c-toggle-auto-hungry-state}) and a negative value will
turn it (or them) off.

@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@node    Electric Keys, Auto-newlines, Minor Modes, Commands
@comment node-name, next, previous, up
@section Electric Keys and Keywords
@cindex electric characters
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Most punctuation keys provide @dfn{electric} behavior: as well as
Glenn Morris's avatar
Glenn Morris committed
1239 1240 1241 1242 1243
inserting themselves they perform some other action, such as
reindenting the line.  This reindentation saves you from having to
reindent a line manually after typing, say, a @samp{@}}.  A few
keywords, such as @code{else}, also trigger electric action.

You can inhibit the electric behavior described here by disabling
Glenn Morris's avatar
Glenn Morris committed
1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290
electric minor mode (@pxref{Minor Modes}).

Common to all these keys is that they only behave electrically when
used in normal code (as contrasted with getting typed in a string
literal or comment).  Those which cause re-indentation do so only when
@code{c-syntactic-indentation} has a non-@code{nil} value (which it
does by default).

These keys and keywords are:
@c ACM, 2004/8/24:  c-electric-pound doesn't check c-s-i: this is more
@c like a bug in the code than a bug in this document.  It'll get
@c fixed in the code sometime.

@table @kbd
@item #
@kindex #
@findex c-electric-pound
@findex electric-pound (c-)
@vindex c-electric-pound-behavior
@vindex electric-pound-behavior (c-)
Pound (bound to @code{c-electric-pound}) is electric when typed as the
first non-whitespace character on a line and not within a macro
definition.  In this case, the variable @code{c-electric-pound-behavior}
is consulted for the electric behavior.  This variable takes a list
value, although the only element currently defined is @code{alignleft},
which tells this command to force the @samp{#} character into column
zero.  This is useful for entering preprocessor macro definitions.

Pound is not electric in AWK buffers, where @samp{#} starts a comment,
and is bound to @code{self-insert-command} like any typical printable
@c ACM, 2004/8/24:  Change this (and the code) to do AWK comment
@c reindentation.

@item *
@kindex *
@itemx /
@kindex /
@findex c-electric-star
@findex electric-star (c-)
@findex c-electric-slash
@findex electric-slash (c-)
A star (bound to @code{c-electric-star}) or a slash
(@code{c-electric-slash}) causes reindentation when you type it as the
second component of a C style block comment opener (@samp{/*}) or a
C++ line comment opener (@samp{//}) respectively, but only if the
comment opener is the first thing on the line (i.e., there's only
Glenn Morris's avatar
Glenn Morris committed
1292 1293 1294 1295 1296
whitespace before it).

Additionally, you can configure @ccmode{} so that typing a slash at
the start of a line within a block comment will terminate the
comment.  You don't need to have electric minor mode enabled to get
this behavior.  @xref{Clean-ups}.
Glenn Morris's avatar
Glenn Morris committed
1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404

In AWK mode, @samp{*} and @samp{/} do not delimit comments and are not

@item <
@kindex <
@itemx >
@kindex >
@findex c-electric-lt-gt
@findex electric-lt-gt (c-)
A less-than or greater-than sign (bound to @code{c-electric-lt-gt}) is
electric in two circumstances: when it is an angle bracket in a C++
@samp{template} declaration (and similar constructs in other
languages) and when it is the second of two @kbd{<} or @kbd{>}
characters in a C++ style stream operator.  In either case, the line
is reindented.  Angle brackets in C @samp{#include} directives are not

@item (
@kindex (
@itemx )
@kindex )
@findex c-electric-paren
@findex electric-paren (c-)
The normal parenthesis characters @samp{(} and @samp{)} (bound to
@code{c-electric-paren}) reindent the current line.  This is useful
for getting the closing parenthesis of an argument list aligned

You can also configure @ccmode{} to insert a space automatically
between a function name and the @samp{(} you've just typed, and to
remove it automatically after typing @samp{)}, should the argument
list be empty.  You don't need to have electric minor mode enabled to
get these actions.  @xref{Clean-ups}.

@item @{
@kindex @{
@itemx @}
@kindex @}
@findex c-electric-brace
@findex electric-brace (c-)
Typing a brace (bound to @code{c-electric-brace}) reindents the
current line.  Also, one or more newlines might be inserted if
auto-newline minor mode is enabled.  @xref{Auto-newlines}.
Additionally, you can configure @ccmode{} to compact excess whitespace
inserted by auto-newline mode in certain circumstances.

@item :
@kindex :
@findex c-electric-colon
@findex electric-colon (c-)
Typing a colon (bound to @code{c-electric-colon}) reindents the
current line.  Additionally, one or more newlines might be inserted if
auto-newline minor mode is enabled.  @xref{Auto-newlines}.  If you
type a second colon immediately after such an auto-newline, by default
the whitespace between the two colons is removed, leaving a C++ scope
operator.  @xref{Clean-ups}.

If you prefer, you can insert @samp{::} in a single operation,
avoiding all these spurious reindentations, newlines, and clean-ups.
@xref{Other Commands}.

@item ;
@kindex ;
@itemx ,
@kindex ,
@findex c-electric-semi&comma
@findex electric-semi&comma (c-)
Typing a semicolon or comma (bound to @code{c-electric-semi&comma})
reindents the current line.  Also, a newline might be inserted if
auto-newline minor mode is enabled.  @xref{Auto-newlines}.
Additionally, you can configure @ccmode{} so that when auto-newline
has inserted whitespace after a @samp{@}}, it will be removed again
when you type a semicolon or comma just after it.  @xref{Clean-ups}.

@end table

@deffn Command c-electric-continued-statement
@findex electric-continued-statement (c-)

Certain keywords are electric, causing reindentation when they are
preceded only by whitespace on the line.  The keywords are those that
continue an earlier statement instead of starting a new one:
@code{else}, @code{while}, @code{catch} (only in C++ and Java) and
@code{finally} (only in Java).

An example:

for (i = 0; i < 17; i++)
  if (a[i])
    res += a[i]->offset;
@end group
@end example

Here, the @code{else} should be indented like the preceding @code{if},
since it continues that statement. @ccmode{} will automatically
reindent it after the @code{else} has been typed in full, since only
then is it possible to decide whether it's a new statement or a
continuation of the preceding @code{if}.

@vindex abbrev-mode
@findex abbrev-mode
@cindex Abbrev mode
@ccmode{} uses Abbrev mode (@pxref{Abbrevs,,,@emacsman{}, @emacsmantitle{}})
Glenn Morris's avatar
Glenn Morris committed
1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428
to accomplish this. It's therefore turned on by default in all language
modes except IDL mode, since CORBA IDL doesn't have any statements.
@end deffn

@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@node    Auto-newlines, Hungry WS Deletion, Electric Keys, Commands
@comment node-name, next, previous, up
@section Auto-newline Insertion
@cindex auto-newline
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

When you have @dfn{Auto-newline minor mode} enabled (@pxref{Minor
Modes}), @ccmode{} inserts newlines for you automatically (in certain
syntactic contexts) when you type a left or right brace, a colon, a
semicolon, or a comma.  Sometimes a newline appears before the
character you type, sometimes after it, sometimes both.

Auto-newline only triggers when the following conditions hold:

@itemize @bullet
Auto-newline minor mode is enabled, as evidenced by the indicator
@samp{a} after the mode name on the modeline (e.g., @samp{C/a} or
Glenn Morris's avatar
Glenn Morris committed
1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448

The character was typed at the end of a line, or with only whitespace
after it, and possibly a @samp{\} escaping the newline.

The character is not on its own line already.  (This applies only to
insertion of a newline @emph{before} the character.)

@cindex literal
@cindex syntactic whitespace
The character was not typed inside of a literal @footnote{A
@dfn{literal} is defined as any comment, string, or preprocessor macro
definition.  These constructs are also known as @dfn{syntactic
whitespace} since they are usually ignored when scanning C code.}.

No numeric argument was supplied to the command (i.e., it was typed as
Glenn Morris's avatar
Glenn Morris committed
1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633
normal, with no @kbd{C-u} prefix).
@end itemize

You can configure the precise circumstances in which newlines get
inserted (see @pxref{Custom Auto-newlines}).  Typically, the style
system (@pxref{Styles}) will have set this up for you, so you probably
won't have to bother.

Sometimes @ccmode{} inserts an auto-newline where you don't want one,
such as after a @samp{@}} when you're about to type a @samp{;}.
Hungry deletion can help here (@pxref{Hungry WS Deletion}), or you can
activate an appropriate @dfn{clean-up}, which will remove the excess
whitespace after you've typed the @samp{;}.  See @ref{Clean-ups} for a
full description.  See also @ref{Electric Keys} for a summary of
clean-ups listed by key.

@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@node    Hungry WS Deletion, Subword Movement, Auto-newlines, Commands
@comment node-name, next, previous, up
@section Hungry Deletion of Whitespace
@cindex hungry-deletion
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

If you want to delete an entire block of whitespace at point, you can
use @dfn{hungry deletion}.  This deletes all the contiguous whitespace
either before point or after point in a single operation.
``Whitespace'' here includes tabs and newlines, but not comments or
preprocessor commands.  Hungry deletion can markedly cut down on the
number of times you have to hit deletion keys when, for example,
you've made a mistake on the preceding line and have already pressed

Hungry deletion is a simple feature that some people find extremely
useful.  In fact, you might find yourself wanting it in @strong{all}
your editing modes!

Loosely speaking, in what follows, @dfn{@key{DEL}} means ``the
backspace key'' and @dfn{@key{DELETE}} means ``the forward delete
key''.  This is discussed in more detail below.

There are two different ways you can use hungry deletion:

@table @asis
@item Using @dfn{Hungry Delete Mode} with @kbd{@key{DEL}} and @kbd{C-d}
Here you toggle Hungry Delete minor mode with @kbd{M-x
c-toggle-hungry-state}@footnote{Prior to @ccmode{} 5.31, this command
was bound to @kbd{C-c C-d}.  @kbd{C-c C-d} is now the default binding
for @code{c-hungry-delete-forward}.} (@pxref{Minor Modes}.)  This
makes @kbd{@key{DEL}} and @kbd{C-d} do backwards and forward hungry

@table @asis
@item @kbd{@key{DEL}} (@code{c-electric-backspace})
@kindex DEL
@findex c-electric-backspace
@findex electric-backspace (c-)
This command is run by default when you hit the @kbd{DEL} key.  When
hungry delete mode is enabled, it deletes any amount of whitespace in
the backwards direction.  Otherwise, or when used with a prefix
argument or in a literal (@pxref{Auto-newlines}), the command just
deletes backwards in the usual way.  (More precisely, it calls the
function contained in the variable @code{c-backspace-function},
passing it the prefix argument, if any.)

@item @code{c-backspace-function}
@vindex c-backspace-function
@vindex backspace-function (c-)
@findex backward-delete-char-untabify
Hook that gets called by @code{c-electric-backspace} when it doesn't
do an ``electric'' deletion of the preceding whitespace.  The default
value is @code{backward-delete-char-untabify}
(@pxref{Deletion,,,@lispref{}, @lispreftitle{}}, the function which
deletes a single character.

@item @kbd{C-d} (@code{c-electric-delete-forward})
@kindex C-d
@findex c-electric-delete-forward
@findex electric-delete-forward (c-)
This function, which is bound to @kbd{C-d} by default, works just like
@code{c-electric-backspace} but in the forward direction.  When it
doesn't do an ``electric'' deletion of the following whitespace, it
just does @code{delete-char}, more or less.  (Strictly speaking, it
calls the function in @code{c-delete-function} with the prefix

@item @code{c-delete-function}
@vindex c-delete-function
@vindex delete-function (c-)
@findex delete-char
Hook that gets called by @code{c-electric-delete-forward} when it
doesn't do an ``electric'' deletion of the following whitespace.  The
default value is @code{delete-char}.
@end table

@item Using Distinct Bindings
The other (newer and recommended) way to use hungry deletion is to
perform @code{c-hungry-delete-backwards} and
@code{c-hungry-delete-forward} directly through their key sequences
rather than using the minor mode toggling.

@table @asis
@item @kbd{C-c C-@key{DEL}}, or @kbd{C-c @key{DEL}} (@code{c-hungry-delete-backwards})@footnote{This command was formerly known as @code{c-hungry-backspace}.}
@kindex C-c C-<backspace>
@kindex C-c <backspace>
@kindex C-c C-DEL
@kindex C-c DEL
@findex c-hungry-delete-backwards
@findex hungry-delete-backwards (c-)
Delete any amount of whitespace in the backwards direction (regardless
whether hungry-delete mode is enabled or not).  This command is bound
to both @kbd{C-c C-@key{DEL}} and @kbd{C-c @key{DEL}}, since the more
natural one, @kbd{C-c C-@key{DEL}}, is sometimes difficult to type at
a character terminal.

@item @kbd{C-c C-d}, @kbd{C-c C-@key{DELETE}}, or @kbd{C-c @key{DELETE}} (@code{c-hungry-delete-forward})
@kindex C-c C-d
@kindex C-c C-<DELETE>
@kindex C-c <DELETE>
@findex c-hungry-delete-forward
@findex hungry-delete-forward (c-)
Delete any amount of whitespace in the forward direction (regardless
whether hungry-delete mode is enabled or not).  This command is bound
to both @kbd{C-c C-@key{DELETE}} and @kbd{C-c @key{DELETE}} for the
same reason as for @key{DEL} above.
@end table
@end table

@kindex <delete>
@kindex <backspace>

When we talk about @kbd{@key{DEL}}, and @kbd{@key{DELETE}} above, we
actually do so without connecting them to the physical keys commonly
known as @key{Backspace} and @key{Delete}.  The default bindings to
those two keys depends on the flavor of (X)Emacs you are using.

@findex c-electric-delete
@findex electric-delete (c-)
@findex c-hungry-delete
@findex hungry-delete (c-)
@vindex delete-key-deletes-forward
In XEmacs 20.3 and beyond, the @key{Backspace} key is bound to
@code{c-electric-backspace} and the @key{Delete} key is bound to
@code{c-electric-delete}.  You control the direction it deletes in by
setting the variable @code{delete-key-deletes-forward}, a standard
XEmacs variable.
@c This variable is encapsulated by XEmacs's (defsubst delete-forward-p ...).
When this variable is non-@code{nil}, @code{c-electric-delete} will do
forward deletion with @code{c-electric-delete-forward}, otherwise it
does backward deletion with @code{c-electric-backspace}.  Similarly,
@kbd{C-c @key{Delete}} and @kbd{C-c C-@key{Delete}} are bound to
@code{c-hungry-delete} which is controlled in the same way by

@findex normal-erase-is-backspace-mode

Emacs 21 and later automatically binds @key{Backspace} and
@key{Delete} to @kbd{DEL} and @kbd{C-d} according to your environment,
and @ccmode{} extends those bindings to @kbd{C-c C-@key{Backspace}}
etc.  If you need to change the bindings through
@code{normal-erase-is-backspace-mode} then @ccmode{} will also adapt
its extended bindings accordingly.

In earlier (X)Emacs versions, @ccmode{} doesn't bind either
@key{Backspace} or @key{Delete} directly.  Only the key codes
@kbd{DEL} and @kbd{C-d} are bound, and it's up to the default bindings
to map the physical keys to them.  You might need to modify this
yourself if the defaults are unsuitable.

Getting your @key{Backspace} and @key{Delete} keys properly set up can
sometimes be tricky.  The information in @ref{DEL Does Not
Delete,,,emacs, GNU Emacs Manual}, might be helpful if you're having
trouble with this in GNU Emacs.

@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@node    Subword Movement, Other Commands, Hungry WS Deletion, Commands
@comment node-name, next, previous, up
@section Subword Movement and Editing
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

@cindex nomenclature
@cindex subword
In spite of the GNU Coding Standards, it is popular to name a symbol
by mixing uppercase and lowercase letters, e.g., @samp{GtkWidget},
Glenn Morris's avatar
Glenn Morris committed
1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711
@samp{EmacsFrameClass}, or @samp{NSGraphicsContext}.  Here we call
these mixed case symbols @dfn{nomenclatures}.  Also, each capitalized
(or completely uppercase) part of a nomenclature is called a
@dfn{subword}.  Here are some examples:

@multitable {@samp{NSGraphicsContext}} {@samp{NS}, @samp{Graphics}, and @samp{Context}}
@c This could be converted to @headitem when we require Texinfo 4.7
@item @b{Nomenclature}
  @tab @b{Subwords}
@end iftex
@item Nomenclature
  @tab Subwords
@item ---------------------------------------------------------
@end ifnottex
@item @samp{GtkWindow}
  @tab @samp{Gtk} and @samp{Window}
@item @samp{EmacsFrameClass}
  @tab @samp{Emacs}, @samp{Frame}, and @samp{Class}
@item @samp{NSGraphicsContext}
  @tab @samp{NS}, @samp{Graphics}, and @samp{Context}
@end multitable

The subword minor mode replaces the basic word oriented movement and
editing commands with variants that recognize subwords in a
nomenclature and treat them as separate words:

@findex c-forward-subword
@findex forward-subword (c-)
@findex c-backward-subword
@findex backward-subword (c-)
@findex c-mark-subword
@findex mark-subword (c-)
@findex c-kill-subword
@findex kill-subword (c-)
@findex c-backward-kill-subword
@findex backward-kill-subword (c-)
@findex c-transpose-subwords
@findex transpose-subwords (c-)
@findex c-capitalize-subword
@findex capitalize-subword (c-)
@findex c-upcase-subword
@findex upcase-subword (c-)
@findex c-downcase-subword
@findex downcase-subword (c-)
@multitable @columnfractions .20 .40 .40
@c This could be converted to @headitem when we require Texinfo 4.7
@item     @b{Key}     @tab @b{Word oriented command} @tab @b{Subword oriented command}
@end iftex
@item     Key         @tab Word oriented command     @tab Subword oriented command
@item ----------------------------------------------------------------------------
@end ifnottex
@item     @kbd{M-f}   @tab @code{forward-word}       @tab @code{c-forward-subword}
@item     @kbd{M-b}   @tab @code{backward-word}      @tab @code{c-backward-subword}
@item     @kbd{M-@@}  @tab @code{mark-word}          @tab @code{c-mark-subword}
@item     @kbd{M-d}   @tab @code{kill-word}          @tab @code{c-kill-subword}
@item     @kbd{M-DEL} @tab @code{backward-kill-word} @tab @code{c-backward-kill-subword}
@item     @kbd{M-t}   @tab @code{transpose-words}    @tab @code{c-transpose-subwords}
@item     @kbd{M-c}   @tab @code{capitalize-word}    @tab @code{c-capitalize-subword}
@item     @kbd{M-u}   @tab @code{upcase-word}        @tab @code{c-upcase-subword}
@item     @kbd{M-l}   @tab @code{downcase-word}      @tab @code{c-downcase-subword}
@end multitable

Note that if you have changed the key bindings for the word oriented
commands in your @file{.emacs} or a similar place, the keys you have
configured are also used for the corresponding subword oriented

Type @kbd{C-c C-w} to toggle subword mode on and off.  To make the
mode turn on automatically, put the following code in your

(add-hook 'c-mode-common-hook
          (lambda () (subword-mode 1)))
Glenn Morris's avatar
Glenn Morris committed
1713 1714
@end example

1715 1716
As a bonus, you can also use @code{subword-mode} in non-@ccmode{}
buffers by typing @kbd{M-x subword-mode}.
Glenn Morris's avatar
Glenn Morris committed
1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821

@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@node    Other Commands,  , Subword Movement, Commands
@comment node-name, next, previous, up
@section Other Commands
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Here are the various other commands that didn't fit anywhere else:

@table @asis
@item @kbd{C-c .} (@code{c-set-style})
@kindex C-c .
@findex c-set-style
@findex set-style (c-)
Switch to the specified style in the current buffer.  Use like this:

@kbd{C-c . @var{style-name} @key{RET}}
@end example

You can use the @key{TAB} in the normal way to do completion on the
style name.  Note that all style names are case insensitive, even the
ones you define yourself.

Setting a style in this way does @emph{not} automatically reindent your
file.  For commands that you can use to view the effect of your changes,
see @ref{Indentation Commands} and @ref{Filling and Breaking}.

For details of the @ccmode{} style system, see @ref{Styles}.
@item @kbd{C-c :} (@code{c-scope-operator})
@kindex C-c :
@findex c-scope-operator
@findex scope-operator (c-)
In C++, it is also sometimes desirable to insert the double-colon scope
operator without performing the electric behavior of colon insertion.
@kbd{C-c :} does just this.

@item @kbd{C-c C-\} (@code{c-backslash-region})
@kindex C-c C-\
@findex c-backslash-region
@findex backslash-region (c-)
This function inserts and aligns or deletes end-of-line backslashes in
the current region.  These are typically used in multi-line macros.

With no prefix argument, it inserts any missing backslashes and aligns
them according to the @code{c-backslash-column} and
@code{c-backslash-max-column} variables.  With a prefix argument, it
deletes any backslashes.

The function does not modify blank lines at the start of the region.  If
the region ends at the start of a line, it always deletes the backslash
(if any) at the end of the previous line.

To customize the precise workings of this command, @ref{Custom Macros}.
@end table

The recommended line breaking function, @code{c-context-line-break}
(@pxref{Filling and Breaking}), is especially nice if you edit
multiline macros frequently.  When used inside a macro, it
automatically inserts and adjusts the mandatory backslash at the end
of the line to keep the macro together, and it leaves the point at the
right indentation column for the code.  Thus you can write code inside
macros almost exactly as you can elsewhere, without having to bother
with the trailing backslashes.

@table @asis
@item @kbd{C-c C-e} (@code{c-macro-expand})
@kindex C-c C-e
@findex c-macro-expand
@findex macro-expand (c-)
This command expands C, C++, Objective C or Pike macros in the region,
using an appropriate external preprocessor program.  Normally it
displays its output in a temporary buffer, but if you give it a prefix
arg (with @kbd{C-u C-c C-e}) it will overwrite the original region
with the expansion.

The command does not work in any of the other modes, and the key
sequence is not bound in these other modes.

@code{c-macro-expand} isn't actually part of @ccmode{}, even though it
is bound to a @ccmode{} key sequence.  If you need help setting it up
or have other problems with it, you can either read its source code or
ask for help in the standard (X)Emacs forums.
@end table

@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@node    Font Locking, Config Basics, Commands, Top
@comment node-name, next, previous, up
@chapter Font Locking
@cindex font locking
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

@cindex Font Lock mode

@ccmode{} provides font locking for its supported languages by
supplying patterns for use with Font Lock mode.  This means that you
get distinct faces on the various syntactic parts such as comments,
strings, keywords and types, which is very helpful in telling them
apart at a glance and discovering syntactic errors.  @xref{Font
Lock,,, emacs, GNU Emacs Manual}, for ways to enable font locking in
@ccmode{} buffers.

@strong{Please note:} The font locking in AWK mode is currently not
integrated with the rest of @ccmode{}.  Only the last section of this
chapter, @ref{AWK Mode Font Locking}, applies to AWK@.  The other
Glenn Morris's avatar
Glenn Morris committed
1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914
sections apply to the other languages.

* Font Locking Preliminaries::
* Faces::
* Doc Comments::
* AWK Mode Font Locking::
@end menu

@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@node    Font Locking Preliminaries, Faces, Font Locking, Font Locking
@comment node-name, next, previous, up
@section Font Locking Preliminaries
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

The font locking for most of the @ccmode{} languages were provided
directly by the Font Lock package prior to version 5.30 of @ccmode{}.
In the transition to @ccmode{} the patterns have been reworked
completely and are applied uniformly across all the languages except AWK
mode, just like the indentation rules (although each language still has
some peculiarities of its own, of course).  Since the languages
previously had completely separate font locking patterns, this means
that it's a bit different in most languages now.

The main goal for the font locking in @ccmode{} is accuracy, to provide
a dependable aid in recognizing the various constructs.  Some, like
strings and comments, are easy to recognize while others, like
declarations and types, can be very tricky.  @ccmode{} can go to great
lengths to recognize declarations and casts correctly, especially when
the types aren't recognized by standard patterns.  This is a fairly
demanding analysis which can be slow on older hardware, and it can
therefore be disabled by choosing a lower decoration level with the
variable @code{font-lock-maximum-decoration} (@pxref{Font Lock,,,
emacs, GNU Emacs Manual}).

@vindex font-lock-maximum-decoration

The decoration levels are used as follows:

@comment 1
Minimal font locking: Fontify only comments, strings and preprocessor
directives (in the languages that use cpp).

@comment 2
Fast font locking: In addition to level 1, fontify keywords, simple
types and declarations that are easy to recognize.  The variables
@code{*-font-lock-extra-types} (where @samp{*} is the name of the
language) are used to recognize types (see below).  Documentation
comments like Javadoc are fontified according to
@code{c-doc-comment-style} (@pxref{Doc Comments}).

Use this if you think the font locking is too slow.  It's the closest
corresponding level to level 3 in the old font lock patterns.

@comment 3
Accurate font locking: Like level 2 but uses a different approach that
can recognize types and declarations much more accurately.  The
@code{*-font-lock-extra-types} variables are still used, but user
defined types are recognized correctly anyway in most cases.  Therefore
those variables should be fairly restrictive and not contain patterns
that are uncertain.

@cindex Lazy Lock mode
@cindex Just-in-time Lock mode

This level is designed for fairly modern hardware and a font lock
support mode like Lazy Lock or Just-in-time Lock mode that only
fontifies the parts that are actually shown.  Fontifying the whole
buffer at once can easily get bothersomely slow even on contemporary
hardware. @xref{Font Lock,,,@emacsman{}, @emacsmantitle{}}.
@end enumerate

@cindex user defined types
@cindex types, user defined

Since user defined types are hard to recognize you can provide
additional regexps to match those you use:

@defopt c-font-lock-extra-types
@defoptx c++-font-lock-extra-types
@defoptx objc-font-lock-extra-types
@defoptx java-font-lock-extra-types
@defoptx idl-font-lock-extra-types
@defoptx pike-font-lock-extra-types
For each language there's a variable @code{*-font-lock-extra-types},
where @samp{*} stands for the language in question.  It contains a list
of regexps that matches identifiers that should be recognized as types,
e.g., @samp{\\sw+_t} to recognize all identifiers ending with @samp{_t}
Glenn Morris's avatar
Glenn Morris committed
1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011
as is customary in C code.  Each regexp should not match more than a
single identifier.

The default values contain regexps for many types in standard runtime
libraries that are otherwise difficult to recognize, and patterns for
standard type naming conventions like the @samp{_t} suffix in C and C++.
Java, Objective-C and Pike have as a convention to start class names
with capitals, so there are patterns for that in those languages.

Despite the names of these variables, they are not only used for
fontification but in other places as well where @ccmode{} needs to
recognize types.
@end defopt

@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@node    Faces, Doc Comments, Font Locking Preliminaries, Font Locking
@comment node-name, next, previous, up
@section Faces
@cindex faces
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

@ccmode{} attempts to use the standard faces for programming languages
in accordance with their intended purposes as far as possible.  No extra
faces are currently provided, with the exception of a replacement face
@code{c-invalid-face} for emacsen that don't provide

@itemize @bullet
@vindex font-lock-comment-face
Normal comments are fontified in @code{font-lock-comment-face}.

@vindex font-lock-doc-face
@vindex font-lock-doc-string-face
@vindex font-lock-comment-face
Comments that are recognized as documentation (@pxref{Doc Comments})
get @code{font-lock-doc-face} (Emacs) or
@code{font-lock-doc-string-face} (XEmacs) if those faces exist.  If
they don't then @code{font-lock-comment-face} is used.

@vindex font-lock-string-face
String and character literals are fontified in

@vindex font-lock-keyword-face
Keywords are fontified with @code{font-lock-keyword-face}.

@vindex font-lock-function-name-face
@code{font-lock-function-name-face} is used for function names in
declarations and definitions, and classes in those contexts.  It's also
used for preprocessor defines with arguments.

@vindex font-lock-variable-name-face
Variables in declarations and definitions, and other identifiers in such
variable contexts, get @code{font-lock-variable-name-face}.  It's also
used for preprocessor defines without arguments.

@vindex font-lock-constant-face
@vindex font-lock-reference-face
Builtin constants are fontified in @code{font-lock-constant-face} if it
exists, @code{font-lock-reference-face} otherwise.  As opposed to the
preceding two faces, this is used on the names in expressions, and it's
not used in declarations, even if there happen to be a @samp{const} in
them somewhere.

@vindex font-lock-type-face
@code{font-lock-type-face} is put on types (both predefined and user
defined) and classes in type contexts.

@vindex font-lock-constant-face
@vindex font-lock-reference-face
Label identifiers get @code{font-lock-constant-face} if it exists,
@code{font-lock-reference-face} otherwise.

Name qualifiers and identifiers for scope constructs are fontified like

Special markup inside documentation comments are also fontified like

@vindex font-lock-preprocessor-face
@vindex font-lock-builtin-face
@vindex font-lock-reference-face
Preprocessor directives get @code{font-lock-preprocessor-face} if it
exists (i.e., XEmacs).  In Emacs they get @code{font-lock-builtin-face}
Glenn Morris's avatar
Glenn Morris committed
2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037
or @code{font-lock-reference-face}, for lack of a closer equivalent.

@vindex font-lock-warning-face
@vindex c-invalid-face
@vindex invalid-face (c-)
Some kinds of syntactic errors are fontified with
@code{font-lock-warning-face} in Emacs.  In older XEmacs versions
there's no corresponding standard face, so there a special
@code{c-invalid-face} is used, which is defined to stand out sharply by

Note that it's not used for @samp{#error} or @samp{#warning} directives,
since those aren't syntactic errors in themselves.
@end itemize

@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@node    Doc Comments, AWK Mode Font Locking, Faces, Font Locking
@comment node-name, next, previous, up
@section Documentation Comments
@cindex documentation comments
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

There are various tools to supply documentation in the source as