| 1 |
\input texinfo |
|---|
| 2 |
@c Notes to self regarding line handling: |
|---|
| 3 |
@c |
|---|
| 4 |
@c Empty lines are often significant before @end directives; avoid them. |
|---|
| 5 |
@c |
|---|
| 6 |
@c Empty lines before and after @example directives are significant in |
|---|
| 7 |
@c info output but not in TeX. Empty lines inside @example directives |
|---|
| 8 |
@c are significant. |
|---|
| 9 |
|
|---|
| 10 |
@c Conventions for formatting examples: |
|---|
| 11 |
@c o If the example contains empty lines then put the surrounding empty |
|---|
| 12 |
@c lines inside the @example directives. Put them outside otherwise. |
|---|
| 13 |
@c o Use @group inside the example only if it shows indentation where |
|---|
| 14 |
@c the relation between lines inside is relevant. |
|---|
| 15 |
@c o Format line number columns like this: |
|---|
| 16 |
@c 1: foo |
|---|
| 17 |
@c 2: bar |
|---|
| 18 |
@c ^ one space |
|---|
| 19 |
@c ^^ two columns, right alignment |
|---|
| 20 |
@c o Check line lengths in TeX output; they can typically be no longer |
|---|
| 21 |
@c than 70 chars, 60 if the paragraph is indented. |
|---|
| 22 |
|
|---|
| 23 |
@comment TBD: Document the finer details of statement anchoring? |
|---|
| 24 |
|
|---|
| 25 |
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 26 |
@comment %**start of header (This is for running Texinfo on a region) |
|---|
| 27 |
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 31 |
@comment How to make the various output formats: |
|---|
| 32 |
@comment (Thanks to Robert Chassell for supplying this information.) |
|---|
| 33 |
@comment Note that Texinfo 4.7 (or later) is needed. |
|---|
| 34 |
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 35 |
@ignore |
|---|
| 36 |
In each of the following pairs of commands, the first generates a |
|---|
| 37 |
version with cross references pointing to the GNU Emacs manuals, |
|---|
| 38 |
the second with them pointing to the XEmacs manuals. |
|---|
| 39 |
## Info output |
|---|
| 40 |
makeinfo cc-mode.texi |
|---|
| 41 |
makeinfo -DXEMACS cc-mode.texi |
|---|
| 42 |
|
|---|
| 43 |
## DVI output |
|---|
| 44 |
## You may need to set up the environment variable TEXINPUTS so |
|---|
| 45 |
## that tex can find the file texinfo.tex - See the tex |
|---|
| 46 |
## manpage. |
|---|
| 47 |
texi2dvi cc-mode.texi |
|---|
| 48 |
texi2dvi -t "@set XEMACS " cc-mode.texi |
|---|
| 49 |
|
|---|
| 50 |
## HTML output. (The --no-split parameter is optional) |
|---|
| 51 |
makeinfo --html --no-split cc-mode.texi |
|---|
| 52 |
makeinfo --html --no-split -DXEMACS cc-mode.texi |
|---|
| 53 |
|
|---|
| 54 |
## Plain text output |
|---|
| 55 |
makeinfo --fill-column=70 --no-split --paragraph-indent=0 \ |
|---|
| 56 |
--no-headers --output=cc-mode.txt cc-mode.texi |
|---|
| 57 |
makeinfo --fill-column=70 --no-split --paragraph-indent=0 \ |
|---|
| 58 |
--no-headers --output=cc-mode.txt -DXEMACS cc-mode.texi |
|---|
| 59 |
|
|---|
| 60 |
## DocBook output |
|---|
| 61 |
makeinfo --docbook --no-split --paragraph-indent=0 \ |
|---|
| 62 |
cc-mode.texi |
|---|
| 63 |
makeinfo --docbook --no-split --paragraph-indent=0 \ |
|---|
| 64 |
-DXEMACS cc-mode.texi |
|---|
| 65 |
|
|---|
| 66 |
## XML output |
|---|
| 67 |
makeinfo --xml --no-split --paragraph-indent=0 \ |
|---|
| 68 |
cc-mode.texi |
|---|
| 69 |
makeinfo --xml --no-split --paragraph-indent=0 \ |
|---|
| 70 |
-DXEMACS cc-mode.texi |
|---|
| 71 |
|
|---|
| 72 |
#### (You must be in the same directory as the viewed file.) |
|---|
| 73 |
|
|---|
| 74 |
## View DVI output |
|---|
| 75 |
xdvi cc-mode.dvi & |
|---|
| 76 |
|
|---|
| 77 |
## View HTML output |
|---|
| 78 |
mozilla cc-mode.html |
|---|
| 79 |
@end ignore |
|---|
| 80 |
|
|---|
| 81 |
@comment No overfull hbox marks in the dvi file. |
|---|
| 82 |
@finalout |
|---|
| 83 |
|
|---|
| 84 |
@setfilename ../info/ccmode |
|---|
| 85 |
@settitle CC Mode Manual |
|---|
| 86 |
@footnotestyle end |
|---|
| 87 |
|
|---|
| 88 |
@c The following four macros generate the filenames and titles of the |
|---|
| 89 |
@c main (X)Emacs manual and the Elisp/Lispref manual. Leave the |
|---|
| 90 |
@c Texinfo variable `XEMACS' unset to generate a GNU Emacs version, set it |
|---|
| 91 |
@c to generate an XEmacs version, e.g. with |
|---|
| 92 |
@c "makeinfo -DXEMACS cc-mode.texi". |
|---|
| 93 |
@ifset XEMACS |
|---|
| 94 |
@macro emacsman |
|---|
| 95 |
xemacs |
|---|
| 96 |
@end macro |
|---|
| 97 |
@macro emacsmantitle |
|---|
| 98 |
XEmacs User's Manual |
|---|
| 99 |
@end macro |
|---|
| 100 |
@macro lispref |
|---|
| 101 |
lispref |
|---|
| 102 |
@end macro |
|---|
| 103 |
@macro lispreftitle |
|---|
| 104 |
XEmacs Lisp Reference Manual |
|---|
| 105 |
@end macro |
|---|
| 106 |
@end ifset |
|---|
| 107 |
|
|---|
| 108 |
@ifclear XEMACS |
|---|
| 109 |
@macro emacsman |
|---|
| 110 |
emacs |
|---|
| 111 |
@end macro |
|---|
| 112 |
@macro emacsmantitle |
|---|
| 113 |
GNU Emacs Manual |
|---|
| 114 |
@end macro |
|---|
| 115 |
@macro lispref |
|---|
| 116 |
elisp |
|---|
| 117 |
@end macro |
|---|
| 118 |
@macro lispreftitle |
|---|
| 119 |
GNU Emacs Lisp Reference Manual |
|---|
| 120 |
@end macro |
|---|
| 121 |
@end ifclear |
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
@macro ccmode |
|---|
| 125 |
CC Mode |
|---|
| 126 |
@end macro |
|---|
| 127 |
|
|---|
| 128 |
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 129 |
@comment @setchapternewpage odd !! we don't want blank pages !! |
|---|
| 130 |
@comment %**end of header (This is for running Texinfo on a region) |
|---|
| 131 |
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 135 |
@comment |
|---|
| 136 |
@comment Texinfo manual for CC Mode |
|---|
| 137 |
@comment Generated from the original README file by Krishna Padmasola |
|---|
| 138 |
@comment <krishna@earth-gw.njit.edu> |
|---|
| 139 |
@comment |
|---|
| 140 |
@comment Authors: |
|---|
| 141 |
@comment Barry A. Warsaw |
|---|
| 142 |
@comment Martin Stjernholm |
|---|
| 143 |
@comment Alan Mackenzie |
|---|
| 144 |
@comment |
|---|
| 145 |
@comment Maintained by Martin Stjernholm and Alan Mackenzie <bug-cc-mode@gnu.org> |
|---|
| 146 |
@comment |
|---|
| 147 |
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 148 |
|
|---|
| 149 |
@comment Define an index for syntactic symbols. |
|---|
| 150 |
@ifnottex @c In texi2dvi, the @defindex would create an empty cc-mode.ss |
|---|
| 151 |
@c For Info, unlike tex, @syncodeindex needs a matching @defindex. |
|---|
| 152 |
@defindex ss |
|---|
| 153 |
@end ifnottex |
|---|
| 154 |
|
|---|
| 155 |
@comment Combine key, syntactic symbol and concept indices into one. |
|---|
| 156 |
@syncodeindex ss cp |
|---|
| 157 |
@syncodeindex ky cp |
|---|
| 158 |
|
|---|
| 159 |
@copying |
|---|
| 160 |
This manual is for CC Mode in Emacs. |
|---|
| 161 |
|
|---|
| 162 |
Copyright @copyright{} 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, |
|---|
| 163 |
2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
|---|
| 164 |
|
|---|
| 165 |
@quotation |
|---|
| 166 |
Permission is granted to copy, distribute and/or modify this document |
|---|
| 167 |
under the terms of the GNU Free Documentation License, Version 1.2 or |
|---|
| 168 |
any later version published by the Free Software Foundation; with the |
|---|
| 169 |
Invariant Sections being ``The GNU Manifesto'', ``Distribution'' and |
|---|
| 170 |
``GNU GENERAL PUBLIC LICENSE'', with the Front-Cover texts being ``A GNU |
|---|
| 171 |
Manual'', and with the Back-Cover Texts as in (a) below. A copy of the |
|---|
| 172 |
license is included in the section entitled ``GNU Free Documentation |
|---|
| 173 |
License'' in the Emacs manual. |
|---|
| 174 |
|
|---|
| 175 |
(a) The FSF's Back-Cover Text is: ``You have freedom to copy and modify |
|---|
| 176 |
this GNU Manual, like GNU software. Copies published by the Free |
|---|
| 177 |
Software Foundation raise funds for GNU development.'' |
|---|
| 178 |
|
|---|
| 179 |
This document is part of a collection distributed under the GNU Free |
|---|
| 180 |
Documentation License. If you want to distribute this document |
|---|
| 181 |
separately from the collection, you can do so by adding a copy of the |
|---|
| 182 |
license to the document, as described in section 6 of the license. |
|---|
| 183 |
@end quotation |
|---|
| 184 |
@end copying |
|---|
| 185 |
|
|---|
| 186 |
@comment Info directory entry for use by install-info. The indentation |
|---|
| 187 |
@comment here is by request from the FSF folks. |
|---|
| 188 |
@dircategory Emacs |
|---|
| 189 |
@direntry |
|---|
| 190 |
* CC Mode: (ccmode). Emacs mode for editing C, C++, Objective-C, |
|---|
| 191 |
Java, Pike, AWK, and CORBA IDL code. |
|---|
| 192 |
@end direntry |
|---|
| 193 |
|
|---|
| 194 |
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 195 |
@comment TeX title page |
|---|
| 196 |
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 197 |
|
|---|
| 198 |
@titlepage |
|---|
| 199 |
@sp 10 |
|---|
| 200 |
|
|---|
| 201 |
@center @titlefont{CC Mode 5.31} |
|---|
| 202 |
@sp 2 |
|---|
| 203 |
@center @subtitlefont{A GNU Emacs mode for editing C and C-like languages} |
|---|
| 204 |
@sp 2 |
|---|
| 205 |
@center Barry A. Warsaw, Martin Stjernholm, Alan Mackenzie |
|---|
| 206 |
|
|---|
| 207 |
@page |
|---|
| 208 |
@vskip 0pt plus 1filll |
|---|
| 209 |
@insertcopying |
|---|
| 210 |
|
|---|
| 211 |
This manual was generated from $Revision$ of $RCSfile$, which can be |
|---|
| 212 |
downloaded from |
|---|
| 213 |
@url{http://cvs.savannah.gnu.org/viewcvs/emacs/emacs/man/cc-mode.texi}. |
|---|
| 214 |
@end titlepage |
|---|
| 215 |
|
|---|
| 216 |
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 217 |
@comment The Top node contains the master menu for the Info file. |
|---|
| 218 |
@comment This appears only in the Info file, not the printed manual. |
|---|
| 219 |
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 220 |
|
|---|
| 221 |
@node Top, Introduction, (dir), (dir) |
|---|
| 222 |
@comment node-name, next, previous, up |
|---|
| 223 |
|
|---|
| 224 |
@ifinfo |
|---|
| 225 |
@top @ccmode{} |
|---|
| 226 |
|
|---|
| 227 |
@ccmode{} is a GNU Emacs mode for editing files containing C, C++, |
|---|
| 228 |
Objective-C, Java, CORBA IDL (and the variants PSDL and CIDL), Pike |
|---|
| 229 |
and AWK code. It provides syntax-based indentation, font locking, and |
|---|
| 230 |
has several handy commands and some minor modes to make the editing |
|---|
| 231 |
easier. It does not provide tools to look up and navigate between |
|---|
| 232 |
functions, classes etc - there are other packages for that. |
|---|
| 233 |
@end ifinfo |
|---|
| 234 |
|
|---|
| 235 |
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 236 |
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 237 |
|
|---|
| 238 |
@menu |
|---|
| 239 |
* Introduction:: |
|---|
| 240 |
* Overview:: |
|---|
| 241 |
* Getting Started:: |
|---|
| 242 |
* Commands:: |
|---|
| 243 |
* Font Locking:: |
|---|
| 244 |
* Config Basics:: |
|---|
| 245 |
* Custom Filling and Breaking:: |
|---|
| 246 |
* Custom Auto-newlines:: |
|---|
| 247 |
* Clean-ups:: |
|---|
| 248 |
* Indentation Engine Basics:: |
|---|
| 249 |
* Customizing Indentation:: |
|---|
| 250 |
* Custom Macros:: |
|---|
| 251 |
* Odds and Ends:: |
|---|
| 252 |
* Sample .emacs File:: |
|---|
| 253 |
* Performance Issues:: |
|---|
| 254 |
* Limitations and Known Bugs:: |
|---|
| 255 |
* FAQ:: |
|---|
| 256 |
* Updating CC Mode:: |
|---|
| 257 |
* Mailing Lists and Bug Reports:: |
|---|
| 258 |
* GNU Free Documentation License:: |
|---|
| 259 |
* Command and Function Index:: |
|---|
| 260 |
* Variable Index:: |
|---|
| 261 |
* Concept and Key Index:: |
|---|
| 262 |
|
|---|
| 263 |
@detailmenu |
|---|
| 264 |
--- The Detailed Node Listing --- |
|---|
| 265 |
|
|---|
| 266 |
Commands |
|---|
| 267 |
|
|---|
| 268 |
* Indentation Commands:: |
|---|
| 269 |
* Comment Commands:: |
|---|
| 270 |
* Movement Commands:: |
|---|
| 271 |
* Filling and Breaking:: |
|---|
| 272 |
* Minor Modes:: |
|---|
| 273 |
* Electric Keys:: |
|---|
| 274 |
* Auto-newlines:: |
|---|
| 275 |
* Hungry WS Deletion:: |
|---|
| 276 |
* Subword Movement:: |
|---|
| 277 |
* Other Commands:: |
|---|
| 278 |
|
|---|
| 279 |
Font Locking |
|---|
| 280 |
|
|---|
| 281 |
* Font Locking Preliminaries:: |
|---|
| 282 |
* Faces:: |
|---|
| 283 |
* Doc Comments:: |
|---|
| 284 |
* AWK Mode Font Locking:: |
|---|
| 285 |
|
|---|
| 286 |
Configuration Basics |
|---|
| 287 |
|
|---|
| 288 |
* CC Hooks:: |
|---|
| 289 |
* Style Variables:: |
|---|
| 290 |
* Styles:: |
|---|
| 291 |
|
|---|
| 292 |
Styles |
|---|
| 293 |
|
|---|
| 294 |
* Built-in Styles:: |
|---|
| 295 |
* Choosing a Style:: |
|---|
| 296 |
* Adding Styles:: |
|---|
| 297 |
* File Styles:: |
|---|
| 298 |
|
|---|
| 299 |
Customizing Auto-newlines |
|---|
| 300 |
|
|---|
| 301 |
* Hanging Braces:: |
|---|
| 302 |
* Hanging Colons:: |
|---|
| 303 |
* Hanging Semicolons and Commas:: |
|---|
| 304 |
|
|---|
| 305 |
Hanging Braces |
|---|
| 306 |
|
|---|
| 307 |
* Custom Braces:: |
|---|
| 308 |
|
|---|
| 309 |
Indentation Engine Basics |
|---|
| 310 |
|
|---|
| 311 |
* Syntactic Analysis:: |
|---|
| 312 |
* Syntactic Symbols:: |
|---|
| 313 |
* Indentation Calculation:: |
|---|
| 314 |
|
|---|
| 315 |
Syntactic Symbols |
|---|
| 316 |
|
|---|
| 317 |
* Function Symbols:: |
|---|
| 318 |
* Class Symbols:: |
|---|
| 319 |
* Conditional Construct Symbols:: |
|---|
| 320 |
* Switch Statement Symbols:: |
|---|
| 321 |
* Brace List Symbols:: |
|---|
| 322 |
* External Scope Symbols:: |
|---|
| 323 |
* Paren List Symbols:: |
|---|
| 324 |
* Literal Symbols:: |
|---|
| 325 |
* Multiline Macro Symbols:: |
|---|
| 326 |
* Objective-C Method Symbols:: |
|---|
| 327 |
* Anonymous Class Symbol:: |
|---|
| 328 |
* Statement Block Symbols:: |
|---|
| 329 |
* K&R Symbols:: |
|---|
| 330 |
|
|---|
| 331 |
Customizing Indentation |
|---|
| 332 |
|
|---|
| 333 |
* c-offsets-alist:: |
|---|
| 334 |
* Interactive Customization:: |
|---|
| 335 |
* Line-Up Functions:: |
|---|
| 336 |
* Custom Line-Up:: |
|---|
| 337 |
* Other Indentation:: |
|---|
| 338 |
|
|---|
| 339 |
Line-Up Functions |
|---|
| 340 |
|
|---|
| 341 |
* Brace/Paren Line-Up:: |
|---|
| 342 |
* List Line-Up:: |
|---|
| 343 |
* Operator Line-Up:: |
|---|
| 344 |
* Comment Line-Up:: |
|---|
| 345 |
* Misc Line-Up:: |
|---|
| 346 |
|
|---|
| 347 |
@end detailmenu |
|---|
| 348 |
@end menu |
|---|
| 349 |
|
|---|
| 350 |
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 351 |
@node Introduction, Overview, Top, Top |
|---|
| 352 |
@comment node-name, next, previous, up |
|---|
| 353 |
@chapter Introduction |
|---|
| 354 |
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 355 |
|
|---|
| 356 |
@cindex BOCM |
|---|
| 357 |
@cindex history |
|---|
| 358 |
@cindex awk-mode.el |
|---|
| 359 |
@cindex c-mode.el |
|---|
| 360 |
@cindex c++-mode.el |
|---|
| 361 |
|
|---|
| 362 |
Welcome to @ccmode{}, a GNU Emacs mode for editing files containing C, |
|---|
| 363 |
C++, Objective-C, Java, CORBA IDL (and the variants CORBA PSDL and |
|---|
| 364 |
CIDL), Pike and AWK code. This incarnation of the mode is descended |
|---|
| 365 |
from @file{c-mode.el} (also called ``Boring Old C Mode'' or BOCM |
|---|
| 366 |
@t{:-)}, @file{c++-mode.el} version 2, which Barry Warsaw had been |
|---|
| 367 |
maintaining since 1992, and @file{awk-mode.el}, a long neglected mode |
|---|
| 368 |
in the (X)Emacs base. |
|---|
| 369 |
|
|---|
| 370 |
Late in 1997, Martin Stjernholm joined Barry on the @ccmode{} |
|---|
| 371 |
Maintainers Team, and implemented the Pike support. In 2000 Martin |
|---|
| 372 |
took over as the sole maintainer. In 2001 Alan Mackenzie joined the |
|---|
| 373 |
team, implementing AWK support in version 5.30. @ccmode{} did not |
|---|
| 374 |
originally contain the font lock support for its languages --- that |
|---|
| 375 |
was added in version 5.30. |
|---|
| 376 |
|
|---|
| 377 |
This manual describes @ccmode{} |
|---|
| 378 |
@comment The following line must appear on its own, so that the |
|---|
| 379 |
version 5.31. |
|---|
| 380 |
@comment Release.py script can update the version number automatically |
|---|
| 381 |
|
|---|
| 382 |
@ccmode{} supports the editing of K&R and ANSI C, C++, Objective-C, |
|---|
| 383 |
Java, CORBA's Interface Definition Language, Pike@footnote{A C-like |
|---|
| 384 |
scripting language with its roots in the LPC language used in some MUD |
|---|
| 385 |
engines. See @uref{http://pike.ida.liu.se/}.} and AWK files. In this |
|---|
| 386 |
way, you can easily set up consistent font locking and coding styles for |
|---|
| 387 |
use in editing all of these languages, although AWK is not yet as |
|---|
| 388 |
uniformly integrated as the other languages. |
|---|
| 389 |
|
|---|
| 390 |
@findex c-mode |
|---|
| 391 |
@findex c++-mode |
|---|
| 392 |
@findex objc-mode |
|---|
| 393 |
@findex java-mode |
|---|
| 394 |
@findex idl-mode |
|---|
| 395 |
@findex pike-mode |
|---|
| 396 |
@findex awk-mode |
|---|
| 397 |
Note that the name of this package is ``@ccmode{}'', but there is no top |
|---|
| 398 |
level @code{cc-mode} entry point. All of the variables, commands, and |
|---|
| 399 |
functions in @ccmode{} are prefixed with @code{c-@var{thing}}, and |
|---|
| 400 |
@code{c-mode}, @code{c++-mode}, @code{objc-mode}, @code{java-mode}, |
|---|
| 401 |
@code{idl-mode}, @code{pike-mode}, and @code{awk-mode} entry points are |
|---|
| 402 |
provided. This package is intended to be a replacement for |
|---|
| 403 |
@file{c-mode.el}, @file{c++-mode.el} and @file{awk-mode.el}. |
|---|
| 404 |
|
|---|
| 405 |
A special word of thanks goes to Krishna Padmasola for his work in |
|---|
| 406 |
converting the original @file{README} file to Texinfo format. I'd |
|---|
| 407 |
also like to thank all the @ccmode{} victims who help enormously |
|---|
| 408 |
during the early beta stages of @ccmode{}'s development. |
|---|
| 409 |
|
|---|
| 410 |
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 411 |
@node Overview, Getting Started, Introduction, Top |
|---|
| 412 |
@comment node-name, next, previous, up@cindex organization of the manual |
|---|
| 413 |
@chapter Overview of the Manual |
|---|
| 414 |
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 415 |
|
|---|
| 416 |
@noindent |
|---|
| 417 |
The manual starts with several introductory chapters (including this |
|---|
| 418 |
one). |
|---|
| 419 |
|
|---|
| 420 |
@noindent |
|---|
| 421 |
The next chunk of the manual describes the day to day @emph{use} of |
|---|
| 422 |
@ccmode{} (as contrasted with how to customize it). |
|---|
| 423 |
|
|---|
| 424 |
@itemize @bullet |
|---|
| 425 |
@item |
|---|
| 426 |
The chapter ``Commands'' describes in detail how to use (nearly) all |
|---|
| 427 |
of @ccmode{}'s features. There are extensive cross-references from |
|---|
| 428 |
here to the corresponding sections later in the manual which tell you |
|---|
| 429 |
how to customize these features. |
|---|
| 430 |
|
|---|
| 431 |
@item |
|---|
| 432 |
``Font Locking'' describes how ``syntax highlighting'' is applied to |
|---|
| 433 |
your buffers. It is mainly background information and can be skipped |
|---|
| 434 |
over at a first reading. |
|---|
| 435 |
@end itemize |
|---|
| 436 |
|
|---|
| 437 |
@noindent |
|---|
| 438 |
The next chunk of the manual describes how to @emph{customize} |
|---|
| 439 |
@ccmode{}. Typically, an overview of a topic is given at the chapter |
|---|
| 440 |
level, then the sections and subsections describe the material in |
|---|
| 441 |
increasing detail. |
|---|
| 442 |
|
|---|
| 443 |
@itemize @bullet |
|---|
| 444 |
@item |
|---|
| 445 |
The chapter ``Configuration Basics'' tells you @emph{how} to write |
|---|
| 446 |
customizations - whether in hooks, in styles, in both, or in neither, |
|---|
| 447 |
depending on your needs. It describes the @ccmode{} style system and |
|---|
| 448 |
lists the standard styles that @ccmode{} supplies. |
|---|
| 449 |
|
|---|
| 450 |
@item |
|---|
| 451 |
The next few chapters describe in detail how to customize the various |
|---|
| 452 |
features of @ccmode{}. |
|---|
| 453 |
|
|---|
| 454 |
@item |
|---|
| 455 |
Finally, there is a sample @file{.emacs} fragment, which might help you |
|---|
| 456 |
in creating your own customization. |
|---|
| 457 |
@end itemize |
|---|
| 458 |
|
|---|
| 459 |
@noindent |
|---|
| 460 |
The manual ends with ``this and that'', things that don't fit cleanly |
|---|
| 461 |
into any of the previous chunks. |
|---|
| 462 |
|
|---|
| 463 |
@itemize @bullet |
|---|
| 464 |
@item |
|---|
| 465 |
Two chapters discuss the performance of @ccmode{} and known |
|---|
| 466 |
bugs/limitations. |
|---|
| 467 |
|
|---|
| 468 |
@item |
|---|
| 469 |
The FAQ contains a list of common problems and questions. |
|---|
| 470 |
|
|---|
| 471 |
@item |
|---|
| 472 |
The next two chapters tell you how to get in touch with the @ccmode{} |
|---|
| 473 |
project - whether for updating @ccmode{} or submitting bug reports. |
|---|
| 474 |
@end itemize |
|---|
| 475 |
|
|---|
| 476 |
@noindent |
|---|
| 477 |
Finally, there are the customary indices. |
|---|
| 478 |
|
|---|
| 479 |
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 480 |
@node Getting Started, Commands, Overview, Top |
|---|
| 481 |
@comment node-name, next, previous, up |
|---|
| 482 |
@chapter Getting Started |
|---|
| 483 |
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 484 |
|
|---|
| 485 |
If you got this version of @ccmode{} with Emacs or XEmacs, it should |
|---|
| 486 |
work just fine right out of the box. Note however that you might not |
|---|
| 487 |
have the latest @ccmode{} release and might want to upgrade your copy |
|---|
| 488 |
(see below). |
|---|
| 489 |
|
|---|
| 490 |
You should probably start by skimming through the entire Commands chapter |
|---|
| 491 |
(@pxref{Commands}) to get an overview of @ccmode{}'s capabilities. |
|---|
| 492 |
|
|---|
| 493 |
After trying out some commands, you may dislike some aspects of |
|---|
| 494 |
@ccmode{}'s default configuration. Here is an outline of how to |
|---|
| 495 |
change some of the settings that newcomers to @ccmode{} most often |
|---|
| 496 |
want to change: |
|---|
| 497 |
|
|---|
| 498 |
@table @asis |
|---|
| 499 |
@item c-basic-offset |
|---|
| 500 |
This Lisp variable holds an integer, the number of columns @ccmode{} |
|---|
| 501 |
indents nested code. To set this value to 6, customize |
|---|
| 502 |
@code{c-basic-offset} or put this into your @file{.emacs}: |
|---|
| 503 |
|
|---|
| 504 |
@example |
|---|
| 505 |
(setq c-basic-offset 6) |
|---|
| 506 |
@end example |
|---|
| 507 |
|
|---|
| 508 |
@item The (indentation) style |
|---|
| 509 |
The basic ``shape'' of indentation created by @ccmode{}---by default, |
|---|
| 510 |
this is @code{gnu} style (except for Java and AWK buffers). A list of |
|---|
| 511 |
the available styles and their descriptions can be found in |
|---|
| 512 |
@ref{Built-in Styles}. A complete specification of the @ccmode{} |
|---|
| 513 |
style system, including how to create your own style, can be found in |
|---|
| 514 |
the chapter @ref{Styles}. To set your style to @code{linux}, either |
|---|
| 515 |
customize @code{c-default-style} or put this into your @file{.emacs}: |
|---|
| 516 |
|
|---|
| 517 |
@example |
|---|
| 518 |
(setq c-default-style '((java-mode . "java") |
|---|
| 519 |
(awk-mode . "awk") |
|---|
| 520 |
(other . "linux"))) |
|---|
| 521 |
@end example |
|---|
| 522 |
|
|---|
| 523 |
@item Electric Indentation |
|---|
| 524 |
Normally, when you type ``punctuation'' characters such as @samp{;} or |
|---|
| 525 |
@samp{@{}, @ccmode{} instantly reindents the current line. This can |
|---|
| 526 |
be disconcerting until you get used to it. To disable @dfn{electric |
|---|
| 527 |
indentation} in the current buffer, type @kbd{C-c C-l}. Type the same |
|---|
| 528 |
thing to enable it again. To have electric indentation disabled by |
|---|
| 529 |
default, put the following into your @file{.emacs} file@footnote{There |
|---|
| 530 |
is no ``easy customization'' facility for making this change.}: |
|---|
| 531 |
|
|---|
| 532 |
@example |
|---|
| 533 |
(setq-default c-electric-flag nil) |
|---|
| 534 |
@end example |
|---|
| 535 |
|
|---|
| 536 |
@noindent |
|---|
| 537 |
Details of this and other similar ``Minor Modes'' appear in the |
|---|
| 538 |
section @ref{Minor Modes}. |
|---|
| 539 |
|
|---|
| 540 |
@item Making the @key{RET} key indent the new line |
|---|
| 541 |
The standard Emacs binding for @key{RET} just adds a new line. If you |
|---|
| 542 |
want it to reindent the new line as well, rebind the key. Note that |
|---|
| 543 |
the action of rebinding would fail if the pertinent keymap didn't yet |
|---|
| 544 |
exist---we thus need to delay the action until after @ccmode{} has |
|---|
| 545 |
been loaded. Put the following code into your @file{.emacs}: |
|---|
| 546 |
|
|---|
| 547 |
@example |
|---|
| 548 |
(defun my-make-CR-do-indent () |
|---|
| 549 |
(define-key c-mode-base-map "\C-m" 'c-context-line-break)) |
|---|
| 550 |
(add-hook 'c-initialization-hook 'my-make-CR-do-indent) |
|---|
| 551 |
@end example |
|---|
| 552 |
|
|---|
| 553 |
@noindent |
|---|
| 554 |
This example demonstrates the use of a very powerful @ccmode{} (and |
|---|
| 555 |
Emacs) facility, the hook. The use of @ccmode{}'s hooks is described |
|---|
| 556 |
in @ref{CC Hooks}. |
|---|
| 557 |
@end table |
|---|
| 558 |
|
|---|
| 559 |
All these settings should occur in your @file{.emacs} @emph{before} |
|---|
| 560 |
any @ccmode{} buffers get loaded---in particular, before any call of |
|---|
| 561 |
@code{desktop-read}. |
|---|
| 562 |
|
|---|
| 563 |
As you get to know the mode better, you may want to make more |
|---|
| 564 |
ambitious changes to your configuration. For this, you should start |
|---|
| 565 |
reading the chapter @ref{Config Basics}. |
|---|
| 566 |
|
|---|
| 567 |
If you are upgrading an existing @ccmode{} installation, please see |
|---|
| 568 |
the @file{README} file for installation details. In particular, if |
|---|
| 569 |
you are going to be editing AWK files, @file{README} describes how to |
|---|
| 570 |
configure your (X)Emacs so that @ccmode{} will supersede the obsolete |
|---|
| 571 |
@code{awk-mode.el} which might have been supplied with your (X)Emacs. |
|---|
| 572 |
@ccmode{} might not work with older versions of Emacs or XEmacs. See |
|---|
| 573 |
the @ccmode{} release notes at @uref{http://cc-mode.sourceforge.net} |
|---|
| 574 |
for the latest information on Emacs version and package compatibility |
|---|
| 575 |
(@pxref{Updating CC Mode}). |
|---|
| 576 |
|
|---|
| 577 |
@deffn Command c-version |
|---|
| 578 |
@findex version (c-) |
|---|
| 579 |
You can find out what version of @ccmode{} you are using by visiting a C |
|---|
| 580 |
file and entering @kbd{M-x c-version RET}. You should see this message in |
|---|
| 581 |
the echo area: |
|---|
| 582 |
|
|---|
| 583 |
@example |
|---|
| 584 |
Using CC Mode version 5.XX |
|---|
| 585 |
@end example |
|---|
| 586 |
|
|---|
| 587 |
@noindent |
|---|
| 588 |
where @samp{XX} is the minor release number. |
|---|
| 589 |
@end deffn |
|---|
| 590 |
|
|---|
| 591 |
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 592 |
@node Commands, Font Locking, Getting Started, Top |
|---|
| 593 |
@comment node-name, next, previous, up |
|---|
| 594 |
@chapter Commands |
|---|
| 595 |
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 596 |
|
|---|
| 597 |
This chapter specifies all of CC Mode's commands, and thus contains |
|---|
| 598 |
nearly everything you need to know to @emph{use} @ccmode{} (as |
|---|
| 599 |
contrasted with configuring it). @dfn{Commands} here means both |
|---|
| 600 |
control key sequences and @dfn{electric keys}, these being characters |
|---|
| 601 |
such as @samp{;} which, as well as inserting themselves into the |
|---|
| 602 |
buffer, also do other things. |
|---|
| 603 |
|
|---|
| 604 |
You might well want to review |
|---|
| 605 |
@ifset XEMACS |
|---|
| 606 |
@ref{Lists,,,@emacsman{}, @emacsmantitle{}}, |
|---|
| 607 |
@end ifset |
|---|
| 608 |
@ifclear XEMACS |
|---|
| 609 |
@ref{Moving by Parens,,,@emacsman{}, @emacsmantitle{}}, |
|---|
| 610 |
@end ifclear |
|---|
| 611 |
which describes commands for moving around brace and parenthesis |
|---|
| 612 |
structures. |
|---|
| 613 |
|
|---|
| 614 |
|
|---|
| 615 |
@menu |
|---|
| 616 |
* Indentation Commands:: |
|---|
| 617 |
* Comment Commands:: |
|---|
| 618 |
* Movement Commands:: |
|---|
| 619 |
* Filling and Breaking:: |
|---|
| 620 |
* Minor Modes:: |
|---|
| 621 |
* Electric Keys:: |
|---|
| 622 |
* Auto-newlines:: |
|---|
| 623 |
* Hungry WS Deletion:: |
|---|
| 624 |
* Subword Movement:: |
|---|
| 625 |
* Other Commands:: |
|---|
| 626 |
@end menu |
|---|
| 627 |
|
|---|
| 628 |
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 629 |
@node Indentation Commands, Comment Commands, Commands, Commands |
|---|
| 630 |
@comment node-name, next, previous,up |
|---|
| 631 |
@section Indentation Commands |
|---|
| 632 |
@cindex indentation |
|---|
| 633 |
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 634 |
|
|---|
| 635 |
The following commands reindent C constructs. Note that when you |
|---|
| 636 |
change your coding style, either interactively or through some other |
|---|
| 637 |
means, your file does @emph{not} automatically get reindented. You |
|---|
| 638 |
will need to execute one of the following commands to see the effects |
|---|
| 639 |
of your changes. |
|---|
| 640 |
|
|---|
| 641 |
@cindex GNU indent program |
|---|
| 642 |
Also, variables like @code{c-hanging-*} and @code{c-cleanup-list} |
|---|
| 643 |
(@pxref{Custom Auto-newlines}) only affect how on-the-fly code is |
|---|
| 644 |
formatted. Changing the ``hanginess'' of a brace and then |
|---|
| 645 |
reindenting, will not move the brace to a different line. For this, |
|---|
| 646 |
you're better off getting an external program like GNU @code{indent}, |
|---|
| 647 |
which will rearrange brace location, amongst other things. |
|---|
| 648 |
|
|---|
| 649 |
Preprocessor directives are handled as syntactic whitespace from other |
|---|
| 650 |
code, i.e. they can be interspersed anywhere without affecting the |
|---|
| 651 |
indentation of the surrounding code, just like comments. |
|---|
| 652 |
|
|---|
| 653 |
The code inside macro definitions is, by default, still analyzed |
|---|
| 654 |
syntactically so that you get relative indentation there just as you'd |
|---|
| 655 |
get if the same code was outside a macro. However, since there is no |
|---|
| 656 |
hint about the syntactic context, i.e. whether the macro expands to an |
|---|
| 657 |
expression, to some statements, or perhaps to whole functions, the |
|---|
| 658 |
syntactic recognition can be wrong. @ccmode{} manages to figure it |
|---|
| 659 |
out correctly most of the time, though. |
|---|
| 660 |
|
|---|
| 661 |
Reindenting large sections of code can take a long time. When |
|---|
| 662 |
@ccmode{} reindents a region of code, it is essentially equivalent to |
|---|
| 663 |
hitting @key{TAB} on every line of the region. |
|---|
| 664 |
|
|---|
| 665 |
These commands indent code: |
|---|
| 666 |
|
|---|
| 667 |
@table @asis |
|---|
| 668 |
@item @kbd{@key{TAB}} (@code{c-indent-command}) |
|---|
| 669 |
@kindex TAB |
|---|
| 670 |
@findex c-indent-command |
|---|
| 671 |
@findex indent-command (c-) |
|---|
| 672 |
This command indents the current line. That is all you need to know |
|---|
| 673 |
about it for normal use. |
|---|
| 674 |
|
|---|
| 675 |
@code{c-indent-command} does different things, depending on the |
|---|
| 676 |
setting of @code{c-syntactic-indentation} (@pxref{Indentation Engine |
|---|
| 677 |
Basics}): |
|---|
| 678 |
|
|---|
| 679 |
@itemize @bullet |
|---|
| 680 |
@item |
|---|
| 681 |
When it's non-@code{nil} (which it normally is), the command indents |
|---|
| 682 |
the line according to its syntactic context. With a prefix argument |
|---|
| 683 |
(@kbd{C-u @key{TAB}}), it will re-indent the entire |
|---|
| 684 |
expression@footnote{this is only useful for a line starting with a |
|---|
| 685 |
comment opener or an opening brace, parenthesis, or string quote.} |
|---|
| 686 |
that begins at the line's left margin. |
|---|
| 687 |
|
|---|
| 688 |
@item |
|---|
| 689 |
When it's @code{nil}, the command indents the line by an extra |
|---|
| 690 |
@code{c-basic-offset} columns. A prefix argument acts as a |
|---|
| 691 |
multiplier. A bare prefix (@kbd{C-u @key{TAB}}) is equivalent to -1, |
|---|
| 692 |
removing @code{c-basic-offset} columns from the indentation. |
|---|
| 693 |
@end itemize |
|---|
| 694 |
|
|---|
| 695 |
The precise behavior is modified by several variables: With |
|---|
| 696 |
@code{c-tab-always-indent}, you can make @key{TAB} insert whitespace |
|---|
| 697 |
in some circumstances---@code{c-insert-tab-function} then defines |
|---|
| 698 |
precisely what sort of ``whitespace'' this will be. Set the standard |
|---|
| 699 |
Emacs variable @code{indent-tabs-mode} to @code{t} if you want real |
|---|
| 700 |
@samp{tab} characters to be used in the indentation, to @code{nil} if |
|---|
| 701 |
you want only spaces. @xref{Just Spaces,,, @emacsman{}, |
|---|
| 702 |
@emacsmantitle{}}. |
|---|
| 703 |
|
|---|
| 704 |
@defopt c-tab-always-indent |
|---|
| 705 |
@vindex tab-always-indent (c-) |
|---|
| 706 |
@cindex literal |
|---|
| 707 |
This variable modifies how @key{TAB} operates. |
|---|
| 708 |
@itemize @bullet |
|---|
| 709 |
@item |
|---|
| 710 |
When it is @code{t} (the default), @key{TAB} simply indents the |
|---|
| 711 |
current line. |
|---|
| 712 |
@item |
|---|
| 713 |
When it is @code{nil}, @key{TAB} (re)indents the line only if point is |
|---|
| 714 |
to the left of the first non-whitespace character on the line. |
|---|
| 715 |
Otherwise it inserts some whitespace (a tab or an equivalent number of |
|---|
| 716 |
spaces - see below) at point. |
|---|
| 717 |
@item |
|---|
| 718 |
With some other value, the line is reindented. Additionally, if point |
|---|
| 719 |
is within a string or comment, some whitespace is inserted. |
|---|
| 720 |
@end itemize |
|---|
| 721 |
@end defopt |
|---|
| 722 |
|
|---|
| 723 |
@defopt c-insert-tab-function |
|---|
| 724 |
@vindex insert-tab-function (c-) |
|---|
| 725 |
@findex tab-to-tab-stop |
|---|
| 726 |
When ``some whitespace'' is inserted as described above, what actually |
|---|
| 727 |
happens is that the function stored in @code{c-insert-tab-function} is |
|---|
| 728 |
called. Normally, this is @code{insert-tab}, which inserts a real tab |
|---|
| 729 |
character or the equivalent number of spaces (depending on |
|---|
| 730 |
@code{indent-tabs-mode}). Some people, however, set |
|---|
| 731 |
@code{c-insert-tab-function} to @code{tab-to-tab-stop} so as to get |
|---|
| 732 |
hard tab stops when indenting. |
|---|
| 733 |
@end defopt |
|---|
| 734 |
@end table |
|---|
| 735 |
|
|---|
| 736 |
@noindent |
|---|
| 737 |
The kind of indentation the next five commands do depends on the |
|---|
| 738 |
setting of @code{c-syntactic-indentation} (@pxref{Indentation Engine |
|---|
| 739 |
Basics}): |
|---|
| 740 |
@itemize @bullet |
|---|
| 741 |
@item |
|---|
| 742 |
when it is non-@code{nil} (the default), the commands indent lines |
|---|
| 743 |
according to their syntactic context; |
|---|
| 744 |
@item |
|---|
| 745 |
when it is @code{nil}, they just indent each line the same amount as |
|---|
| 746 |
the previous non-blank line. The commands that indent a region aren't |
|---|
| 747 |
very useful in this case. |
|---|
| 748 |
@end itemize |
|---|
| 749 |
|
|---|
| 750 |
@table @asis |
|---|
| 751 |
@item @kbd{C-j} (@code{newline-and-indent}) |
|---|
| 752 |
@kindex C-j |
|---|
| 753 |
@findex newline-and-indent |
|---|
| 754 |
Inserts a newline and indents the new blank line, ready to start |
|---|
| 755 |
typing. This is a standard (X)Emacs command. |
|---|
| 756 |
|
|---|
| 757 |
@item @kbd{C-M-q} (@code{c-indent-exp}) |
|---|
| 758 |
@kindex C-M-q |
|---|
| 759 |
@findex c-indent-exp |
|---|
| 760 |
@findex indent-exp (c-) |
|---|
| 761 |
Indents an entire balanced brace or parenthesis expression. Note that |
|---|
| 762 |
point must be on the opening brace or parenthesis of the expression |
|---|
| 763 |
you want to indent. |
|---|
| 764 |
|
|---|
| 765 |
@item @kbd{C-c C-q} (@code{c-indent-defun}) |
|---|
| 766 |
@kindex C-c C-q |
|---|
| 767 |
@findex c-indent-defun |
|---|
| 768 |
@findex indent-defun (c-) |
|---|
| 769 |
Indents the entire top-level function, class or macro definition |
|---|
| 770 |
encompassing point. It leaves point unchanged. This function can't be |
|---|
| 771 |
used to reindent a nested brace construct, such as a nested class or |
|---|
| 772 |
function, or a Java method. The top-level construct being reindented |
|---|
| 773 |
must be complete, i.e. it must have both a beginning brace and an ending |
|---|
| 774 |
brace. |
|---|
| 775 |
|
|---|
| 776 |
@item @kbd{C-M-\} (@code{indent-region}) |
|---|
| 777 |
@kindex C-M-\ |
|---|
| 778 |
@findex indent-region |
|---|
| 779 |
Indents an arbitrary region of code. This is a standard Emacs command, |
|---|
| 780 |
tailored for C code in a @ccmode{} buffer. Note, of course, that point |
|---|
| 781 |
and mark must delineate the region you want to indent. |
|---|
| 782 |
|
|---|
| 783 |
@item @kbd{C-M-h} (@code{c-mark-function}) |
|---|
| 784 |
@kindex C-M-h |
|---|
| 785 |
@findex c-mark-function |
|---|
| 786 |
@findex mark-function (c-) |
|---|
| 787 |
While not strictly an indentation command, this is useful for marking |
|---|
| 788 |
the current top-level function or class definition as the current |
|---|
| 789 |
region. As with @code{c-indent-defun}, this command operates on |
|---|
| 790 |
top-level constructs, and can't be used to mark say, a Java method. |
|---|
| 791 |
@end table |
|---|
| 792 |
|
|---|
| 793 |
These variables are also useful when indenting code: |
|---|
| 794 |
|
|---|
| 795 |
@defopt indent-tabs-mode |
|---|
| 796 |
This is a standard Emacs variable that controls how line indentation |
|---|
| 797 |
is composed. When it's non-@code{nil}, tabs can be used in a line's |
|---|
| 798 |
indentation, otherwise only spaces are used. |
|---|
| 799 |
@end defopt |
|---|
| 800 |
|
|---|
| 801 |
@defopt c-progress-interval |
|---|
| 802 |
@vindex progress-interval (c-) |
|---|
| 803 |
When indenting large regions of code, this variable controls how often a |
|---|
| 804 |
progress message is displayed. Set this variable to @code{nil} to |
|---|
| 805 |
inhibit the progress messages, or set it to an integer which is how |
|---|
| 806 |
often (in seconds) progress messages are to be displayed. |
|---|
| 807 |
@end defopt |
|---|
| 808 |
|
|---|
| 809 |
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 810 |
@node Comment Commands, Movement Commands, Indentation Commands, Commands |
|---|
| 811 |
@comment node-name, next, previous, up |
|---|
| 812 |
@section Comment Commands |
|---|
| 813 |
@cindex comments (insertion of) |
|---|
| 814 |
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 815 |
|
|---|
| 816 |
@table @asis |
|---|
| 817 |
@item @kbd{C-c C-c} (@code{comment-region}) |
|---|
| 818 |
@kindex C-c C-c |
|---|
| 819 |
@findex comment-region |
|---|
| 820 |
This command comments out the lines that start in the region. With a |
|---|
| 821 |
negative argument, it does the opposite - it deletes the comment |
|---|
| 822 |
delimiters from these lines. @xref{Multi-Line Comments,,, emacs, GNU |
|---|
| 823 |
Emacs Manual}, for fuller details. @code{comment-region} isn't |
|---|
| 824 |
actually part of @ccmode{} - it is given a @ccmode{} binding for |
|---|
| 825 |
convenience. |
|---|
| 826 |
|
|---|
| 827 |
@item @kbd{M-;} (@code{comment-dwim} or @code{indent-for-comment} @footnote{The name of this command varies between (X)Emacs versions.}) |
|---|
| 828 |
@kindex M-; |
|---|
| 829 |
@findex comment-dwim |
|---|
| 830 |
@findex indent-for-comment |
|---|
| 831 |
Insert a comment at the end of the current line, if none is there |
|---|
| 832 |
already. Then reindent the comment according to @code{comment-column} |
|---|
| 833 |
@ifclear XEMACS |
|---|
| 834 |
(@pxref{Options for Comments,,, emacs, GNU Emacs Manual}) |
|---|
| 835 |
@end ifclear |
|---|
| 836 |
@ifset XEMACS |
|---|
| 837 |
(@pxref{Comments,,, xemacs, XEmacs User's Manual}) |
|---|
| 838 |
@end ifset |
|---|
| 839 |
and the variables below. Finally, position the point after the |
|---|
| 840 |
comment starter. @kbd{C-u M-;} kills any comment on the current line, |
|---|
| 841 |
together with any whitespace before it. This is a standard Emacs |
|---|
| 842 |
command, but @ccmode{} enhances it a bit with two variables: |
|---|
| 843 |
|
|---|
| 844 |
@defopt c-indent-comment-alist |
|---|
| 845 |
@vindex indent-comment-alist (c-) |
|---|
| 846 |
@vindex comment-column |
|---|
| 847 |
This style variable allows you to vary the column that @kbd{M-;} puts |
|---|
| 848 |
the comment at, depending on what sort of code is on the line, and |
|---|
| 849 |
possibly the indentation of any similar comment on the preceding line. |
|---|
| 850 |
It is an association list that maps different types of lines to |
|---|
| 851 |
actions describing how they should be handled. If a certain line type |
|---|
| 852 |
isn't present on the list then the line is indented to the column |
|---|
| 853 |
specified by @code{comment-column}. |
|---|
| 854 |
|
|---|
| 855 |
See the documentation string for a full description of this |
|---|
| 856 |
variable (use @kbd{C-h v c-indent-comment-alist}). |
|---|
| 857 |
@end defopt |
|---|
| 858 |
|
|---|
| 859 |
@defopt c-indent-comments-syntactically-p |
|---|
| 860 |
@vindex indent-comments-syntactically-p (c-) |
|---|
| 861 |
Normally, when this style variable is @code{nil}, @kbd{M-;} will |
|---|
| 862 |
indent comment-only lines according to @code{c-indent-comment-alist}, |
|---|
| 863 |
just as it does with lines where other code precede the comments. |
|---|
| 864 |
However, if you want it to act just like @key{TAB} for comment-only |
|---|
| 865 |
lines you can get that by setting |
|---|
| 866 |
@code{c-indent-comments-syntactically-p} to non-@code{nil}. |
|---|
| 867 |
|
|---|
| 868 |
If @code{c-indent-comments-syntactically-p} is non-@code{nil} then |
|---|
| 869 |
@code{c-indent-comment-alist} won't be consulted at all for comment-only |
|---|
| 870 |
lines. |
|---|
| 871 |
@end defopt |
|---|
| 872 |
@end table |
|---|
| 873 |
|
|---|
| 874 |
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 875 |
@node Movement Commands, Filling and Breaking, Comment Commands, Commands |
|---|
| 876 |
@comment node-name, next, previous, up |
|---|
| 877 |
@section Movement Commands |
|---|
| 878 |
@cindex movement |
|---|
| 879 |
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 880 |
|
|---|
| 881 |
@ccmode{} contains some useful commands for moving around in C code. |
|---|
| 882 |
|
|---|
| 883 |
@table @asis |
|---|
| 884 |
@item @kbd{C-M-a} (@code{c-beginning-of-defun}) |
|---|
| 885 |
@itemx @kbd{C-M-e} (@code{c-end-of-defun}) |
|---|
| 886 |
@findex c-beginning-of-defun |
|---|
| 887 |
@findex c-end-of-defun |
|---|
| 888 |
|
|---|
| 889 |
Move to the beginning or end of the current or next function. Other |
|---|
| 890 |
constructs (such as a structs or classes) which have a brace block |
|---|
| 891 |
also count as ``functions'' here. To move over several functions, you |
|---|
| 892 |
can give these commands a repeat count. |
|---|
| 893 |
|
|---|
| 894 |
The start of a function is at its header. The end of the function is |
|---|
| 895 |
after its closing brace, or after the semicolon of a construct (such |
|---|
| 896 |
as a @code{struct}) which doesn't end at the brace. These two |
|---|
| 897 |
commands try to leave point at the beginning of a line near the actual |
|---|
| 898 |
start or end of the function. This occasionally causes point not to |
|---|
| 899 |
move at all. |
|---|
| 900 |
|
|---|
| 901 |
These functions are analogous to the Emacs built-in commands |
|---|
| 902 |
@code{beginning-of-defun} and @code{end-of-defun}, except they |
|---|
| 903 |
eliminate the constraint that the top-level opening brace of the defun |
|---|
| 904 |
must be in column zero. See @ref{Defuns,,,@emacsman{}, |
|---|
| 905 |
@emacsmantitle{}}, for more information. |
|---|
| 906 |
|
|---|
| 907 |
@item @kbd{C-M-a} (AWK Mode) (@code{c-awk-beginning-of-defun}) |
|---|
| 908 |
@itemx @kbd{C-M-e} (AWK Mode) (@code{c-awk-end-of-defun}) |
|---|
| 909 |
@kindex C-M-a (AWK Mode) |
|---|
| 910 |
@kindex C-M-e (AWK Mode) |
|---|
| 911 |
@findex c-awk-beginning-of-defun |
|---|
| 912 |
@findex awk-beginning-of-defun (c-) |
|---|
| 913 |
@findex c-awk-end-of-defun |
|---|
| 914 |
@findex awk-end-of-defun (c-) |
|---|
| 915 |
Move to the beginning or end of the current or next AWK defun. These |
|---|
| 916 |
commands can take prefix-arguments, their functionality being entirely |
|---|
| 917 |
equivalent to @code{beginning-of-defun} and @code{end-of-defun}. |
|---|
| 918 |
|
|---|
| 919 |
AWK Mode @dfn{defuns} are either pattern/action pairs (either of which |
|---|
| 920 |
might be implicit) or user defined functions. Having the @samp{@{} and |
|---|
| 921 |
@samp{@}} (if there are any) in column zero, as is suggested for some |
|---|
| 922 |
modes, is neither necessary nor helpful in AWK mode. |
|---|
| 923 |
|
|---|
| 924 |
@item @kbd{M-a} (@code{c-beginning-of-statement}) |
|---|
| 925 |
@itemx @kbd{M-e} (@code{c-end-of-statement}) |
|---|
| 926 |
@kindex M-a |
|---|
| 927 |
@kindex M-e |
|---|
| 928 |
@findex c-beginning-of-statement |
|---|
| 929 |
@findex c-end-of-statement |
|---|
| 930 |
@findex beginning-of-statement (c-) |
|---|
| 931 |
@findex end-of-statement (c-) |
|---|
| 932 |
Move to the beginning or end of the innermost C statement. If point |
|---|
| 933 |
is already there, move to the next beginning or end of a statement, |
|---|
| 934 |
even if that means moving into a block. (Use @kbd{C-M-b} or |
|---|
| 935 |
@kbd{C-M-f} to move over a balanced block.) A prefix argument @var{n} |
|---|
| 936 |
means move over @var{n} statements. |
|---|
| 937 |
|
|---|
| 938 |
If point is within or next to a comment or a string which spans more |
|---|
| 939 |
than one line, these commands move by sentences instead of statements. |
|---|
| 940 |
|
|---|
| 941 |
When called from a program, these functions take three optional |
|---|
| 942 |
arguments: the repetition count, a buffer position limit which is the |
|---|
| 943 |
farthest back to search for the syntactic context, and a flag saying |
|---|
| 944 |
whether to do sentence motion in or near comments and multiline |
|---|
| 945 |
strings. |
|---|
| 946 |
|
|---|
| 947 |
@item @kbd{C-c C-u} (@code{c-up-conditional}) |
|---|
| 948 |
@kindex C-c C-u |
|---|
| 949 |
@findex c-up-conditional |
|---|
| 950 |
@findex up-conditional (c-) |
|---|
| 951 |
Move back to the containing preprocessor conditional, leaving the mark |
|---|
| 952 |
behind. A prefix argument acts as a repeat count. With a negative |
|---|
| 953 |
argument, move forward to the end of the containing preprocessor |
|---|
| 954 |
conditional. |
|---|
| 955 |
|
|---|
| 956 |
@samp{#elif} is treated like @samp{#else} followed by @samp{#if}, so the |
|---|
| 957 |
function stops at them when going backward, but not when going |
|---|
| 958 |
forward. |
|---|
| 959 |
|
|---|
| 960 |
This key sequence is not bound in AWK Mode, which doesn't have |
|---|
| 961 |
preprocessor statements. |
|---|
| 962 |
|
|---|
| 963 |
@item @kbd{M-x c-up-conditional-with-else} |
|---|
| 964 |
@findex c-up-conditional-with-else |
|---|
| 965 |
@findex up-conditional-with-else (c-) |
|---|
| 966 |
A variety of @code{c-up-conditional} that also stops at @samp{#else} |
|---|
| 967 |
lines. Normally those lines are ignored. |
|---|
| 968 |
|
|---|
| 969 |
@item @kbd{M-x c-down-conditional} |
|---|
| 970 |
@findex c-down-conditional |
|---|
| 971 |
@findex down-conditional (c-) |
|---|
| 972 |
Move forward into the next nested preprocessor conditional, leaving |
|---|
| 973 |
the mark behind. A prefix argument acts as a repeat count. With a |
|---|
| 974 |
negative argument, move backward into the previous nested preprocessor |
|---|
| 975 |
conditional. |
|---|
| 976 |
|
|---|
| 977 |
@samp{#elif} is treated like @samp{#else} followed by @samp{#if}, so the |
|---|
| 978 |
function stops at them when going forward, but not when going backward. |
|---|
| 979 |
|
|---|
| 980 |
@item @kbd{M-x c-down-conditional-with-else} |
|---|
| 981 |
@findex c-down-conditional-with-else |
|---|
| 982 |
@findex down-conditional-with-else (c-) |
|---|
| 983 |
A variety of @code{c-down-conditional} that also stops at @samp{#else} |
|---|
| 984 |
lines. Normally those lines are ignored. |
|---|
| 985 |
|
|---|
| 986 |
@item @kbd{C-c C-p} (@code{c-backward-conditional}) |
|---|
| 987 |
@itemx @kbd{C-c C-n} (@code{c-forward-conditional}) |
|---|
| 988 |
@kindex C-c C-p |
|---|
| 989 |
@kindex C-c C-n |
|---|
| 990 |
@findex c-backward-conditional |
|---|
| 991 |
@findex c-forward-conditional |
|---|
| 992 |
@findex backward-conditional (c-) |
|---|
| 993 |
@findex forward-conditional (c-) |
|---|
| 994 |
Move backward or forward across a preprocessor conditional, leaving |
|---|
| 995 |
the mark behind. A prefix argument acts as a repeat count. With a |
|---|
| 996 |
negative argument, move in the opposite direction. |
|---|
| 997 |
|
|---|
| 998 |
These key sequences are not bound in AWK Mode, which doesn't have |
|---|
| 999 |
preprocessor statements. |
|---|
| 1000 |
|
|---|
| 1001 |
@item @kbd{M-x c-backward-into-nomenclature} |
|---|
| 1002 |
@itemx @kbd{M-x c-forward-into-nomenclature} |
|---|
| 1003 |
@findex c-backward-into-nomenclature |
|---|
| 1004 |
@findex c-forward-into-nomenclature |
|---|
| 1005 |
@findex backward-into-nomenclature (c-) |
|---|
| 1006 |
@findex forward-into-nomenclature (c-) |
|---|
| 1007 |
A popular programming style, especially for object-oriented languages |
|---|
| 1008 |
such as C++ is to write symbols in a mixed case format, where the |
|---|
| 1009 |
first letter of each word is capitalized, and not separated by |
|---|
| 1010 |
underscores. E.g. @samp{SymbolsWithMixedCaseAndNoUnderlines}. |
|---|
| 1011 |
|
|---|
| 1012 |
These commands move backward or forward to the beginning of the next |
|---|
| 1013 |
capitalized word. With prefix argument @var{n}, move @var{n} times. |
|---|
| 1014 |
If @var{n} is negative, move in the opposite direction. |
|---|
| 1015 |
|
|---|
| 1016 |
Note that these two commands have been superseded by |
|---|
| 1017 |
@code{c-subword-mode}, which you should use instead. @xref{Subword |
|---|
| 1018 |
Movement}. They might be removed from a future release of @ccmode{}. |
|---|
| 1019 |
@end table |
|---|
| 1020 |
|
|---|
| 1021 |
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 1022 |
@node Filling and Breaking, Minor Modes, Movement Commands, Commands |
|---|
| 1023 |
@comment node-name, next, previous, up |
|---|
| 1024 |
@section Filling and Line Breaking Commands |
|---|
| 1025 |
@cindex text filling |
|---|
| 1026 |
@cindex line breaking |
|---|
| 1027 |
@cindex comment handling |
|---|
| 1028 |
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 1029 |
|
|---|
| 1030 |
Since there's a lot of normal text in comments and string literals, |
|---|
| 1031 |
@ccmode{} provides features to edit these like in text mode. The goal |
|---|
| 1032 |
is to do it seamlessly, i.e. you can use auto fill mode, sentence and |
|---|
| 1033 |
paragraph movement, paragraph filling, adaptive filling etc. wherever |
|---|
| 1034 |
there's a piece of normal text without having to think much about it. |
|---|
| 1035 |
@ccmode{} keeps the indentation, fixes suitable comment line prefixes, |
|---|
| 1036 |
and so on. |
|---|
| 1037 |
|
|---|
| 1038 |
You can configure the exact way comments get filled and broken, and |
|---|
| 1039 |
where Emacs does auto-filling (see @pxref{Custom Filling and |
|---|
| 1040 |
Breaking}). Typically, the style system (@pxref{Styles}) will have |
|---|
| 1041 |
set this up for you, so you probably won't have to bother. |
|---|
| 1042 |
|
|---|
| 1043 |
@findex auto-fill-mode |
|---|
| 1044 |
@cindex Auto Fill mode |
|---|
| 1045 |
@cindex paragraph filling |
|---|
| 1046 |
Line breaks are by default handled (almost) the same regardless of |
|---|
| 1047 |
whether they are made by auto fill mode (@pxref{Auto Fill,,, |
|---|
| 1048 |
@emacsman{}, @emacsmantitle{}}), by paragraph filling (e.g. with |
|---|
| 1049 |
@kbd{M-q}), or explicitly with @kbd{M-j} or similar methods. In |
|---|
| 1050 |
string literals, the new line gets the same indentation as the |
|---|
| 1051 |
previous nonempty line.@footnote{You can change this default by |
|---|
| 1052 |
setting the @code{string} syntactic symbol (@pxref{Syntactic Symbols} |
|---|
| 1053 |
and @pxref{Customizing Indentation})}. |
|---|
| 1054 |
|
|---|
| 1055 |
@table @asis |
|---|
| 1056 |
@item @kbd{M-q} (@code{c-fill-paragraph}) |
|---|
| 1057 |
@kindex M-q |
|---|
| 1058 |
@findex c-fill-paragraph |
|---|
| 1059 |
@findex fill-paragraph (c-) |
|---|
| 1060 |
@cindex Javadoc markup |
|---|
| 1061 |
@cindex Pike autodoc markup |
|---|
| 1062 |
This command fills multiline string literals and both block |
|---|
| 1063 |
and line style comments. In Java buffers, the Javadoc markup words |
|---|
| 1064 |
are recognized as paragraph starters. The line oriented Pike autodoc |
|---|
| 1065 |
markup words are recognized in the same way in Pike mode. |
|---|
| 1066 |
|
|---|
| 1067 |
The formatting of the starters (@code{/*}) and enders (@code{*/}) of |
|---|
| 1068 |
block comments are kept as they were before the filling. I.e., if |
|---|
| 1069 |
either the starter or ender were on a line of its own, then it stays |
|---|
| 1070 |
on its own line; conversely, if the delimiter has comment text on its |
|---|
| 1071 |
line, it keeps at least one word of that text with it on the line. |
|---|
| 1072 |
|
|---|
| 1073 |
This command is the replacement for @code{fill-paragraph} in @ccmode{} |
|---|
| 1074 |
buffers. |
|---|
| 1075 |
|
|---|
| 1076 |
@item @kbd{M-j} (@code{c-indent-new-comment-line}) |
|---|
| 1077 |
@kindex M-j |
|---|
| 1078 |
@findex c-indent-new-comment-line |
|---|
| 1079 |
@findex indent-new-comment-line (c-) |
|---|
| 1080 |
This breaks the current line at point and indents the new line. If |
|---|
| 1081 |
point was in a comment, the new line gets the proper comment line |
|---|
| 1082 |
prefix. If point was inside a macro, a backslash is inserted before |
|---|
| 1083 |
the line break. It is the replacement for |
|---|
| 1084 |
@code{indent-new-comment-line}. |
|---|
| 1085 |
|
|---|
| 1086 |
@item @kbd{M-x c-context-line-break} |
|---|
| 1087 |
@findex c-context-line-break |
|---|
| 1088 |
@findex context-line-break (c-) |
|---|
| 1089 |
Insert a line break suitable to the context: If the point is inside a |
|---|
| 1090 |
comment, the new line gets the suitable indentation and comment line |
|---|
| 1091 |
prefix like @code{c-indent-new-comment-line}. In normal code it's |
|---|
| 1092 |
indented like @code{newline-and-indent} would do. In macros it acts |
|---|
| 1093 |
like @code{newline-and-indent} but additionally inserts and optionally |
|---|
| 1094 |
aligns the line ending backslash so that the macro remains unbroken. |
|---|
| 1095 |
@xref{Custom Macros}, for details about the backslash alignment. In a |
|---|
| 1096 |
string, a backslash is inserted only if the string is within a |
|---|
| 1097 |
macro@footnote{In GCC, unescaped line breaks within strings are |
|---|
| 1098 |
valid.}. |
|---|
| 1099 |
|
|---|
| 1100 |
This function is not bound to a key by default, but it's intended to be |
|---|
| 1101 |
used on the @kbd{RET} key. If you like the behavior of |
|---|
| 1102 |
@code{newline-and-indent} on @kbd{RET}, you should consider switching to |
|---|
| 1103 |
this function. @xref{Sample .emacs File}. |
|---|
| 1104 |
|
|---|
| 1105 |
@item @kbd{M-x c-context-open-line} |
|---|
| 1106 |
@findex c-context-open-line |
|---|
| 1107 |
@findex context-open-line (c-) |
|---|
| 1108 |
This is to @kbd{C-o} (@kbd{M-x open-line}) as |
|---|
| 1109 |
@code{c-context-line-break} is to @kbd{RET}. I.e. it works just like |
|---|
| 1110 |
@code{c-context-line-break} but leaves the point before the inserted |
|---|
| 1111 |
line break. |
|---|
| 1112 |
@end table |
|---|
| 1113 |
|
|---|
| 1114 |
|
|---|
| 1115 |
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 1116 |
@node Minor Modes, Electric Keys, Filling and Breaking, Commands |
|---|
| 1117 |
@comment node-name, next, previous, up |
|---|
| 1118 |
@section Minor Modes |
|---|
| 1119 |
@cindex Minor Modes |
|---|
| 1120 |
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 1121 |
|
|---|
| 1122 |
@ccmode{} contains several minor-mode-like features that you might |
|---|
| 1123 |
find useful while writing new code or editing old code: |
|---|
| 1124 |
|
|---|
| 1125 |
@table @asis |
|---|
| 1126 |
@item electric mode |
|---|
| 1127 |
When this is enabled, certain visible characters cause reformatting as |
|---|
| 1128 |
they are typed. This is normally helpful, but can be a nuisance when |
|---|
| 1129 |
editing chaotically formatted code. It can also be disconcerting, |
|---|
| 1130 |
especially for users who are new to @ccmode{}. |
|---|
| 1131 |
@item auto-newline mode |
|---|
| 1132 |
This automatically inserts newlines where you'd probably want to type |
|---|
| 1133 |
them yourself, e.g. after typing @samp{@}}s. Its action is suppressed |
|---|
| 1134 |
when electric mode is disabled. |
|---|
| 1135 |
@item hungry-delete mode |
|---|
| 1136 |
This lets you delete a contiguous block of whitespace with a single |
|---|
| 1137 |
key - for example, the newline and indentation just inserted by |
|---|
| 1138 |
auto-newline when you want to back up and write a comment after the |
|---|
| 1139 |
last statement. |
|---|
| 1140 |
@item subword mode |
|---|
| 1141 |
This mode makes basic word movement commands like @kbd{M-f} |
|---|
| 1142 |
(@code{forward-word}) and @kbd{M-b} (@code{backward-word}) treat the |
|---|
| 1143 |
parts of sillycapsed symbols as different words. |
|---|
| 1144 |
E.g. @samp{NSGraphicsContext} is treated as three words @samp{NS}, |
|---|
| 1145 |
@samp{Graphics}, and @samp{Context}. |
|---|
| 1146 |
@item syntactic-indentation mode |
|---|
| 1147 |
When this is enabled (which it normally is), indentation commands such |
|---|
| 1148 |
as @kbd{C-j} indent lines of code according to their syntactic |
|---|
| 1149 |
structure. Otherwise, a line is simply indented to the same level as |
|---|
| 1150 |
the previous one and @kbd{@key{TAB}} adjusts the indentation in steps |
|---|
| 1151 |
of `c-basic-offset'. |
|---|
| 1152 |
@end table |
|---|
| 1153 |
|
|---|
| 1154 |
Full details on how these minor modes work are at @ref{Electric Keys}, |
|---|
| 1155 |
@ref{Auto-newlines}, @ref{Hungry WS Deletion}, @ref{Subword Movement}, |
|---|
| 1156 |
and @ref{Indentation Engine Basics}. |
|---|
| 1157 |
|
|---|
| 1158 |
You can toggle each of these minor modes on and off, and you can |
|---|
| 1159 |
configure @ccmode{} so that it starts up with your favourite |
|---|
| 1160 |
combination of them (@pxref{Sample .emacs File}). By default, when |
|---|
| 1161 |
you initialize a buffer, electric mode and syntactic-indentation mode |
|---|
| 1162 |
are enabled but the other two modes are disabled. |
|---|
| 1163 |
|
|---|
| 1164 |
@ccmode{} displays the current state of the first four of these minor |
|---|
| 1165 |
modes on the modeline by appending letters to the major mode's name, |
|---|
| 1166 |
one letter for each enabled minor mode - @samp{l} for electric mode, |
|---|
| 1167 |
@samp{a} for auto-newline mode, @samp{h} for hungry delete mode, and |
|---|
| 1168 |
@samp{w} for subword mode. If all these modes were enabled, you'd see |
|---|
| 1169 |
@samp{C/lahw}@footnote{The @samp{C} would be replaced with the name of |
|---|
| 1170 |
the language in question for the other languages @ccmode{} supports.}. |
|---|
| 1171 |
|
|---|
| 1172 |
Here are the commands to toggle these modes: |
|---|
| 1173 |
|
|---|
| 1174 |
@table @asis |
|---|
| 1175 |
@item @kbd{C-c C-l} (@code{c-toggle-electric-state}) |
|---|
| 1176 |
@kindex C-c C-l |
|---|
| 1177 |
@findex c-toggle-electric-state |
|---|
| 1178 |
@findex toggle-electric-state (c-) |
|---|
| 1179 |
Toggle electric minor mode. When the command turns the mode off, it |
|---|
| 1180 |
also suppresses auto-newline mode. |
|---|
| 1181 |
|
|---|
| 1182 |
@item @kbd{C-c C-a} (@code{c-toggle-auto-newline}) |
|---|
| 1183 |
@kindex C-c C-a |
|---|
| 1184 |
@findex c-toggle-auto-newline |
|---|
| 1185 |
@findex toggle-auto-newline (c-) |
|---|
| 1186 |
Toggle auto-newline minor mode. When the command turns the mode on, |
|---|
| 1187 |
it also enables electric minor mode. |
|---|
| 1188 |
|
|---|
| 1189 |
@item @kbd{M-x c-toggle-hungry-state}@footnote{Prior to @ccmode{} 5.31, this command was bound to @kbd{C-c C-d}.} |
|---|
| 1190 |
@findex c-toggle-hungry-state |
|---|
| 1191 |
@findex toggle-hungry-state (c-) |
|---|
| 1192 |
Toggle hungry-delete minor mode. |
|---|
| 1193 |
|
|---|
| 1194 |
@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}.} |
|---|
| 1195 |
@findex c-toggle-auto-hungry-state |
|---|
| 1196 |
@findex toggle-auto-hungry-state (c-) |
|---|
| 1197 |
Toggle both auto-newline and hungry delete minor modes. |
|---|
| 1198 |
|
|---|
| 1199 |
@item @kbd{C-c C-w} (@code{M-x c-subword-mode}) |
|---|
| 1200 |
@kindex C-c C-w |
|---|
| 1201 |
@findex c-subword-mode |
|---|
| 1202 |
@findex subword-mode (c-) |
|---|
| 1203 |
Toggle subword mode. |
|---|
| 1204 |
|
|---|
| 1205 |
@item @kbd{M-x c-toggle-syntactic-indentation} |
|---|
| 1206 |
@findex c-toggle-syntactic-indentation |
|---|
| 1207 |
@findex toggle-syntactic-indentation (c-) |
|---|
| 1208 |
Toggle syntactic-indentation mode. |
|---|
| 1209 |
@end table |
|---|
| 1210 |
|
|---|
| 1211 |
Common to all the toggle functions above is that if they are called |
|---|
| 1212 |
programmatically, they take an optional numerical argument. A |
|---|
| 1213 |
positive value will turn on the minor mode (or both of them in the |
|---|
| 1214 |
case of @code{c-toggle-auto-hungry-state}) and a negative value will |
|---|
| 1215 |
turn it (or them) off. |
|---|
| 1216 |
|
|---|
| 1217 |
|
|---|
| 1218 |
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 1219 |
@node Electric Keys, Auto-newlines, Minor Modes, Commands |
|---|
| 1220 |
@comment node-name, next, previous, up |
|---|
| 1221 |
@section Electric Keys and Keywords |
|---|
| 1222 |
@cindex electric characters |
|---|
| 1223 |
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 1224 |
|
|---|
| 1225 |
Most punctuation keys provide @dfn{electric} behavior - as well as |
|---|
| 1226 |
inserting themselves they perform some other action, such as |
|---|
| 1227 |
reindenting the line. This reindentation saves you from having to |
|---|
| 1228 |
reindent a line manually after typing, say, a @samp{@}}. A few |
|---|
| 1229 |
keywords, such as @code{else}, also trigger electric action. |
|---|
| 1230 |
|
|---|
| 1231 |
You can inhibit the electric behavior described here by disabling |
|---|
| 1232 |
electric minor mode (@pxref{Minor Modes}). |
|---|
| 1233 |
|
|---|
| 1234 |
Common to all these keys is that they only behave electrically when |
|---|
| 1235 |
used in normal code (as contrasted with getting typed in a string |
|---|
| 1236 |
literal or comment). Those which cause re-indentation do so only when |
|---|
| 1237 |
@code{c-syntactic-indentation} has a non-@code{nil} value (which it |
|---|
| 1238 |
does by default). |
|---|
| 1239 |
|
|---|
| 1240 |
These keys and keywords are: |
|---|
| 1241 |
@c ACM, 2004/8/24: c-electric-pound doesn't check c-s-i: this is more |
|---|
| 1242 |
@c like a bug in the code than a bug in this document. It'll get |
|---|
| 1243 |
@c fixed in the code sometime. |
|---|
| 1244 |
|
|---|
| 1245 |
@table @kbd |
|---|
| 1246 |
@item # |
|---|
| 1247 |
@kindex # |
|---|
| 1248 |
@findex c-electric-pound |
|---|
| 1249 |
@findex electric-pound (c-) |
|---|
| 1250 |
@vindex c-electric-pound-behavior |
|---|
| 1251 |
@vindex elect |
|---|