diff options
| author | Gerd Moellmann | 1999-12-12 18:30:44 +0000 |
|---|---|---|
| committer | Gerd Moellmann | 1999-12-12 18:30:44 +0000 |
| commit | d7bd46ed5f4602f27f28aa1ac38afb48309aab39 (patch) | |
| tree | 3ccf2525d565b3f851becb0788e6d1654a87e3ca | |
| parent | 03d218b4f864dcfe9904d97f8c3d8f92b8013c66 (diff) | |
| download | emacs-d7bd46ed5f4602f27f28aa1ac38afb48309aab39.tar.gz emacs-d7bd46ed5f4602f27f28aa1ac38afb48309aab39.zip | |
Installed cc-mode version 5.26.
| -rw-r--r-- | man/cc-mode.texi | 3193 |
1 files changed, 2091 insertions, 1102 deletions
diff --git a/man/cc-mode.texi b/man/cc-mode.texi index 83f89bd3d78..54775c2799b 100644 --- a/man/cc-mode.texi +++ b/man/cc-mode.texi | |||
| @@ -4,15 +4,12 @@ | |||
| 4 | @comment %**start of header (This is for running Texinfo on a region) | 4 | @comment %**start of header (This is for running Texinfo on a region) |
| 5 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 5 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 6 | 6 | ||
| 7 | @setfilename ../info/ccmode | 7 | @comment No overfull hbox marks in the dvi file. |
| 8 | @settitle CC MODE Version 5 Documentation | 8 | @finalout |
| 9 | @footnotestyle end | ||
| 10 | 9 | ||
| 11 | @dircategory Editors | 10 | @setfilename ../info/cc-mode.info |
| 12 | @direntry | 11 | @settitle CC Mode Version 5 Documentation |
| 13 | * CC mode: (ccmode). The GNU Emacs mode for editing C, C++, Objective-C | 12 | @footnotestyle end |
| 14 | and Java code. | ||
| 15 | @end direntry | ||
| 16 | 13 | ||
| 17 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 14 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 18 | @comment @setchapternewpage odd !! we don't want blank pages !! | 15 | @comment @setchapternewpage odd !! we don't want blank pages !! |
| @@ -26,7 +23,8 @@ | |||
| 26 | @comment Generated from the original README file by Krishna Padmasola | 23 | @comment Generated from the original README file by Krishna Padmasola |
| 27 | @comment <krishna@earth-gw.njit.edu> | 24 | @comment <krishna@earth-gw.njit.edu> |
| 28 | @comment | 25 | @comment |
| 29 | @comment Maintained by Barry A. Warsaw <cc-mode-help@python.org> | 26 | @comment Maintained by Barry A. Warsaw and Martin Stjernholm |
| 27 | @comment <bug-cc-mode@gnu.org> (or <cc-mode-help@python.org>) | ||
| 30 | @comment | 28 | @comment |
| 31 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 29 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 32 | 30 | ||
| @@ -37,7 +35,7 @@ | |||
| 37 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 35 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 38 | 36 | ||
| 39 | @ifinfo | 37 | @ifinfo |
| 40 | Copyright @copyright{} 1995,96,97,98 Free Software Foundation, Inc. | 38 | Copyright @copyright{} 1995-1999 Free Software Foundation, Inc. |
| 41 | @end ifinfo | 39 | @end ifinfo |
| 42 | 40 | ||
| 43 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 41 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| @@ -52,11 +50,12 @@ Copyright @copyright{} 1995,96,97,98 Free Software Foundation, Inc. | |||
| 52 | @comment The title is printed in a large font. | 50 | @comment The title is printed in a large font. |
| 53 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 51 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 54 | 52 | ||
| 55 | @center @titlefont{CC Mode 5.21} | 53 | @center @titlefont{CC Mode 5.26} |
| 56 | @sp 2 | 54 | @sp 2 |
| 57 | @center @subtitlefont{A GNU Emacs mode for editing C and C-like languages} | 55 | @center @subtitlefont{A GNU Emacs mode for editing C and C-like languages} |
| 58 | @sp 2 | 56 | @sp 2 |
| 59 | @center Barry A. Warsaw | 57 | @center Barry A. Warsaw |
| 58 | @center Martin Stjernholm | ||
| 60 | 59 | ||
| 61 | 60 | ||
| 62 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 61 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| @@ -66,7 +65,7 @@ Copyright @copyright{} 1995,96,97,98 Free Software Foundation, Inc. | |||
| 66 | 65 | ||
| 67 | @page | 66 | @page |
| 68 | @vskip 0pt plus 1filll | 67 | @vskip 0pt plus 1filll |
| 69 | Copyright @copyright{} 1995,96,97,98 Free Software Foundation, Inc. | 68 | Copyright @copyright{} 1995-1999 Free Software Foundation, Inc. |
| 70 | @end titlepage | 69 | @end titlepage |
| 71 | 70 | ||
| 72 | 71 | ||
| @@ -75,65 +74,132 @@ Copyright @copyright{} 1995,96,97,98 Free Software Foundation, Inc. | |||
| 75 | @comment This appears only in the Info file, not the printed manual. | 74 | @comment This appears only in the Info file, not the printed manual. |
| 76 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 75 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 77 | 76 | ||
| 78 | @node Top, Introduction, (dir), (dir) | 77 | @node Top, Introduction, (dir), (dir) |
| 79 | @comment node-name, next, previous, up | 78 | @comment node-name, next, previous, up |
| 79 | |||
| 80 | @macro ccmode | ||
| 81 | CC Mode | ||
| 82 | @end macro | ||
| 83 | |||
| 84 | @ifinfo | ||
| 85 | @top @ccmode{} | ||
| 80 | 86 | ||
| 87 | @ccmode{} is a GNU Emacs mode for editing files containing C, C++, | ||
| 88 | Objective-C, Java, CORBA IDL, and Pike code. It provides syntax-based | ||
| 89 | indentation and has several handy commands and some minor modes to make | ||
| 90 | the editing easier. Note that @ccmode{} does @emph{not} provide | ||
| 91 | font-locking; there are other Emacs packages for that. | ||
| 92 | @end ifinfo | ||
| 81 | 93 | ||
| 82 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 94 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 83 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 95 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 84 | 96 | ||
| 85 | @menu | 97 | @menu |
| 86 | * Introduction:: | 98 | * Introduction:: |
| 87 | * Getting Connected:: | 99 | * Getting Connected:: |
| 88 | * New Indentation Engine:: | 100 | * New Indentation Engine:: |
| 89 | * Minor Modes:: | 101 | * Minor Modes:: |
| 102 | * Text Filling and Line Breaking:: | ||
| 90 | * Commands:: | 103 | * Commands:: |
| 91 | * Customizing Indentation:: | 104 | * Customizing Indentation:: |
| 92 | * Syntactic Symbols:: | 105 | * Syntactic Symbols:: |
| 106 | * Indentation Functions:: | ||
| 93 | * Performance Issues:: | 107 | * Performance Issues:: |
| 94 | * Frequently Asked Questions:: | 108 | * Frequently Asked Questions:: |
| 95 | * Getting the latest CC Mode release:: | 109 | * Getting the Latest CC Mode Release:: |
| 96 | * Sample .emacs File:: | 110 | * Sample .emacs File:: |
| 97 | * Limitations and Known Bugs:: | 111 | * Limitations and Known Bugs:: |
| 98 | * Mailing Lists and Submitting Bug Reports:: | 112 | * Mailing Lists and Submitting Bug Reports:: |
| 99 | * Concept Index:: | 113 | |
| 100 | * Command Index:: Command Index | 114 | --- Indices --- |
| 101 | * Key Index:: Key Index | 115 | |
| 102 | * Variable Index:: Variable Index | 116 | * Concept Index:: |
| 117 | * Command Index:: | ||
| 118 | * Key Index:: | ||
| 119 | * Variable Index:: | ||
| 120 | |||
| 121 | --- The Detailed Node Listing --- | ||
| 122 | |||
| 123 | New Indentation Engine | ||
| 124 | |||
| 125 | * Syntactic Analysis:: | ||
| 126 | * Indentation Calculation:: | ||
| 127 | |||
| 128 | Minor Modes | ||
| 129 | |||
| 130 | * Auto-newline Insertion:: | ||
| 131 | * Hungry-deletion of Whitespace:: | ||
| 132 | |||
| 133 | Auto-newline Insertion | ||
| 134 | |||
| 135 | * Hanging Braces:: | ||
| 136 | * Hanging Colons:: | ||
| 137 | * Hanging Semi-colons and Commas:: | ||
| 138 | * Other Electric Commands:: | ||
| 139 | * Clean-ups:: | ||
| 140 | |||
| 141 | Commands | ||
| 142 | |||
| 143 | * Indentation Commands:: | ||
| 144 | * Movement Commands:: | ||
| 145 | * Other Commands:: | ||
| 146 | |||
| 147 | Customizing Indentation | ||
| 148 | |||
| 149 | * Interactive Customization:: | ||
| 150 | * Permanent Customization:: | ||
| 151 | * Hooks:: | ||
| 152 | * Styles:: | ||
| 153 | * Advanced Customizations:: | ||
| 154 | |||
| 155 | Styles | ||
| 156 | |||
| 157 | * Built-in Styles:: | ||
| 158 | * Adding Styles:: | ||
| 159 | * File Styles:: | ||
| 160 | |||
| 161 | Advanced Customizations | ||
| 162 | |||
| 163 | * Custom Indentation Functions:: | ||
| 164 | * Custom Brace and Colon Hanging:: | ||
| 165 | * Customizing Semi-colons and Commas:: | ||
| 166 | * Other Special Indentations:: | ||
| 103 | @end menu | 167 | @end menu |
| 104 | 168 | ||
| 169 | |||
| 105 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 170 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 171 | @node Introduction, Getting Connected, Top, Top | ||
| 172 | @comment node-name, next, previous, up | ||
| 173 | @chapter Introduction | ||
| 106 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 174 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 107 | 175 | ||
| 108 | @node Introduction, Getting Connected, Top, Top | ||
| 109 | @comment node-name, next, previous, up | ||
| 110 | @chapter Introduction | ||
| 111 | @cindex Introduction | ||
| 112 | |||
| 113 | @macro ccmode | ||
| 114 | CC Mode | ||
| 115 | @end macro | ||
| 116 | |||
| 117 | @cindex BOCM | 176 | @cindex BOCM |
| 118 | 177 | ||
| 119 | Welcome to @ccmode{}. This is a GNU Emacs mode for editing files | 178 | Welcome to @ccmode{}, a GNU Emacs mode for editing files containing C, |
| 120 | containing C, C++, Objective-C, Java, and CORBA IDL code. This | 179 | C++, Objective-C, Java, CORBA IDL, and Pike code. This incarnation of |
| 121 | incarnation of the mode is descendant from @file{c-mode.el} (also called | 180 | the mode is descendant from @file{c-mode.el} (also called "Boring Old C |
| 122 | "Boring Old C Mode" or BOCM @code{:-)}, and @file{c++-mode.el} version | 181 | Mode" or BOCM @t{:-)}, and @file{c++-mode.el} version 2, which Barry has |
| 123 | 2, which I have been maintaining since 1992. @ccmode{} represents a | 182 | been maintaining since 1992. @ccmode{} represents a significant |
| 124 | significant milestone in the mode's life. It has been fully merged back | 183 | milestone in the mode's life. It has been fully merged back with Emacs |
| 125 | with Emacs 19's @file{c-mode.el}. Also a new, more intuitive and | 184 | 19's @file{c-mode.el}. Also a new, more intuitive and flexible mechanism |
| 126 | flexible mechanism for controlling indentation has been developed. | 185 | for controlling indentation has been developed. Late in 1997, Martin |
| 186 | joined the @ccmode{} Maintainers Team, and implemented the Pike support. | ||
| 187 | |||
| 188 | This manual describes @ccmode{} | ||
| 189 | @comment The following line must appear on its own, so that the automated | ||
| 190 | version 5.26. | ||
| 191 | @comment Release.py script can update the version number automatically | ||
| 127 | 192 | ||
| 128 | @ccmode{} supports the editing of K&R and ANSI C, @dfn{ARM} | 193 | @ccmode{} supports the editing of K&R and ANSI C, @dfn{ARM} |
| 129 | @footnote{``The Annotated C++ Reference Manual'', by Ellis and | 194 | @footnote{@cite{The Annotated C++ Reference Manual}, by Ellis and |
| 130 | Stroustrup.} C++, Objective-C, Java and CORBA's Interface | 195 | Stroustrup.} C++, Objective-C, Java, CORBA's Interface Definition |
| 131 | Definition Language files. In this way, you can | 196 | Language, and Pike@footnote{A C-like scripting language with its roots |
| 132 | easily set up consistent coding styles for use in editing all C, C++, | 197 | in the LPC language used in some MUD engines. See |
| 133 | Objective-C, Java and IDL programs. @ccmode{} does @emph{not} handle | 198 | @uref{http://pike.idonex.se/}.} files. In this way, you can easily set |
| 134 | font-locking (a.k.a. syntax coloring, keyword highlighting) or anything | 199 | up consistent coding styles for use in editing all of these languages. |
| 135 | of that nature, for any of these modes. Font-locking is handled by other | 200 | @ccmode{} does @emph{not} handle font-locking (a.k.a. syntax coloring, |
| 136 | Emacs packages. | 201 | keyword highlighting) or anything of that nature, for any of these |
| 202 | modes. Font-locking is handled by other Emacs packages. | ||
| 137 | 203 | ||
| 138 | This manual will describe the following: | 204 | This manual will describe the following: |
| 139 | 205 | ||
| @@ -154,12 +220,14 @@ How to customize the new indentation engine. | |||
| 154 | @findex objc-mode | 220 | @findex objc-mode |
| 155 | @findex java-mode | 221 | @findex java-mode |
| 156 | @findex idl-mode | 222 | @findex idl-mode |
| 223 | @findex pike-mode | ||
| 157 | Note that the name of this package is ``@ccmode{}'', but there is no top | 224 | Note that the name of this package is ``@ccmode{}'', but there is no top |
| 158 | level @code{cc-mode} entry point. All of the variables, commands, and | 225 | level @code{cc-mode} entry point. All of the variables, commands, and |
| 159 | functions in @ccmode{} are prefixed with @code{c-@var{<thing>}}, and | 226 | functions in @ccmode{} are prefixed with @code{c-@var{<thing>}}, and |
| 160 | @code{c-mode}, @code{c++-mode}, @code{objc-mode}, @code{java-mode}, and | 227 | @code{c-mode}, @code{c++-mode}, @code{objc-mode}, @code{java-mode}, |
| 161 | @code{idl-mode} entry points are provided. This file is intended to be | 228 | @code{idl-mode}, and @code{pike-mode} entry points are provided. This |
| 162 | a replacement for @file{c-mode.el} and @file{c++-mode.el}. | 229 | package is intended to be a replacement for @file{c-mode.el} and |
| 230 | @file{c++-mode.el}. | ||
| 163 | 231 | ||
| 164 | @cindex @file{cc-compat.el} file | 232 | @cindex @file{cc-compat.el} file |
| 165 | This distribution also contains a file | 233 | This distribution also contains a file |
| @@ -178,12 +246,9 @@ early beta stages of @ccmode{}'s development. | |||
| 178 | 246 | ||
| 179 | 247 | ||
| 180 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 248 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 181 | 249 | @node Getting Connected, New Indentation Engine, Introduction, Top | |
| 182 | @node Getting Connected, New Indentation Engine, Introduction, Top | 250 | @comment node-name, next, previous, up |
| 183 | @comment node-name, next, previous, up | 251 | @chapter Getting Connected |
| 184 | @chapter Getting Connected | ||
| 185 | @cindex Getting Connected | ||
| 186 | |||
| 187 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 252 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 188 | 253 | ||
| 189 | If you got this version of @ccmode{} with Emacs or XEmacs, it should | 254 | If you got this version of @ccmode{} with Emacs or XEmacs, it should |
| @@ -194,12 +259,12 @@ If you are upgrading an existing @ccmode{} installation, please see the | |||
| 194 | @file{README} file for installation details. @ccmode{} may not work | 259 | @file{README} file for installation details. @ccmode{} may not work |
| 195 | with older versions of Emacs or XEmacs. See the @ccmode{} release notes | 260 | with older versions of Emacs or XEmacs. See the @ccmode{} release notes |
| 196 | Web pages for the latest information on Emacs version and package | 261 | Web pages for the latest information on Emacs version and package |
| 197 | compatibility (see @ref{Getting the latest CC Mode release}). | 262 | compatibility (@pxref{Getting the Latest CC Mode Release}). |
| 198 | 263 | ||
| 199 | @cindex @file{cc-mode-18.el} file | 264 | @cindex @file{cc-mode-18.el} file |
| 200 | @emph{Note that @ccmode{} no longer works with Emacs 18!} The | 265 | @emph{Note that @ccmode{} no longer |
| 201 | @file{cc-mode-18.el} file is no longer distributed with @ccmode{}. If | 266 | works with Emacs 18!}, so if you haven't upgraded from Emacs 18 by now, |
| 202 | you haven't upgraded from Emacs 18 by now, you are out of luck. | 267 | you are out of luck. |
| 203 | 268 | ||
| 204 | @findex c-version | 269 | @findex c-version |
| 205 | @findex version (c-) | 270 | @findex version (c-) |
| @@ -217,11 +282,10 @@ where @samp{XX} is the minor release number. | |||
| 217 | 282 | ||
| 218 | 283 | ||
| 219 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 284 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 220 | @node New Indentation Engine, Minor Modes, Getting Connected, Top | 285 | @node New Indentation Engine, Minor Modes, Getting Connected, Top |
| 221 | @comment node-name, next, previous, up | 286 | @comment node-name, next, previous, up |
| 222 | 287 | @chapter New Indentation Engine | |
| 223 | @chapter New Indentation Engine | 288 | @cindex indentation engine |
| 224 | @cindex New Indentation Engine | ||
| 225 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 289 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 226 | 290 | ||
| 227 | @ccmode{} has a new indentation engine, providing a simplified, yet | 291 | @ccmode{} has a new indentation engine, providing a simplified, yet |
| @@ -243,41 +307,36 @@ your personal coding style. | |||
| 243 | 307 | ||
| 244 | 308 | ||
| 245 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 309 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 246 | @node Syntactic Analysis, Indentation Calculation, , New Indentation Engine | 310 | @node Syntactic Analysis, Indentation Calculation, , New Indentation Engine |
| 247 | @comment node-name, next, previous,up | 311 | @comment node-name, next, previous, up |
| 248 | @section Syntactic Analysis | 312 | @section Syntactic Analysis |
| 249 | @cindex Syntactic Analysis | 313 | @cindex syntactic analysis |
| 250 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 314 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 251 | 315 | ||
| 252 | @vindex c-offsets-alist | ||
| 253 | @vindex offsets-alist (c-) | ||
| 254 | @cindex relative buffer position | 316 | @cindex relative buffer position |
| 255 | @cindex syntactic symbol | 317 | @cindex syntactic symbol |
| 256 | @cindex syntactic component | 318 | @cindex syntactic component |
| 257 | @cindex syntactic component list | 319 | @cindex syntactic component list |
| 258 | @cindex relative buffer position | ||
| 259 | The first thing @ccmode{} does when indenting a line of code, is to | 320 | The first thing @ccmode{} does when indenting a line of code, is to |
| 260 | analyze the line, determining the @dfn{syntactic component list} of the | 321 | analyze the line, determining the @dfn{syntactic component list} of the |
| 261 | construct on that line. A syntactic component consists of a pair | 322 | construct on that line. A syntactic component consists of a pair of |
| 262 | of information (in lisp parlance, a @emph{cons cell}), where the first | 323 | information (in lisp parlance, a @emph{cons cell}), where the first part |
| 263 | part is a @dfn{syntactic symbol}, and the second part is a @dfn{relative | 324 | is a @dfn{syntactic symbol}, and the second part is a @dfn{relative |
| 264 | buffer position}. Syntactic symbols describe elements of C code | 325 | buffer position}. Syntactic symbols describe elements of C code |
| 265 | @footnote{or C++, Objective-C, Java or IDL code. In general, for the rest | 326 | @footnote{Unless otherwise noted, the term ``C code'' to refers to all |
| 266 | of this manual I'll use the term ``C code'' to refer to all the C-like | 327 | the C-like languages.}, e.g. @code{statement}, @code{substatement}, |
| 267 | dialects, unless otherwise noted.}, e.g. @code{statement}, | 328 | @code{class-open}, @code{class-close}, etc. @xref{Syntactic Symbols}, |
| 268 | @code{substatement}, @code{class-open}, @code{class-close}, etc. | 329 | for a complete list of currently recognized syntactic symbols and their |
| 269 | @xref{Syntactic Symbols}, for a complete list of currently recognized | 330 | semantics. The style variable @code{c-offsets-alist} also contains the |
| 270 | syntactic symbols and their semantics. The variable | 331 | list of currently supported syntactic symbols. |
| 271 | @code{c-offsets-alist} also contains the list of currently supported | ||
| 272 | syntactic symbols. | ||
| 273 | 332 | ||
| 274 | Conceptually, a line of C code is always indented relative to the | 333 | Conceptually, a line of C code is always indented relative to the |
| 275 | indentation of some line higher up in the buffer. This is represented | 334 | indentation of some line higher up in the buffer. This is represented |
| 276 | by the relative buffer position in the syntactic component. | 335 | by the relative buffer position in the syntactic component. |
| 277 | 336 | ||
| 278 | Here is an example. Suppose we had the following code as the only thing | 337 | Here is an example. Suppose we had the following code as the only thing |
| 279 | in a @code{c++-mode} buffer @footnote{The line numbers in this and | 338 | in a C++ buffer @footnote{The line numbers in this and future examples |
| 280 | future examples don't actually appear in the buffer, of course!}: | 339 | don't actually appear in the buffer, of course!}: |
| 281 | @example | 340 | @example |
| 282 | @group | 341 | @group |
| 283 | 342 | ||
| @@ -346,7 +405,7 @@ Hitting @kbd{C-c C-s} on line 4 gives us: | |||
| 346 | @end example | 405 | @end example |
| 347 | 406 | ||
| 348 | @cindex substatement | 407 | @cindex substatement |
| 349 | @cindex substatment block | 408 | @cindex substatement block |
| 350 | @noindent | 409 | @noindent |
| 351 | which tells us that this is a brace that @emph{opens} a substatement | 410 | which tells us that this is a brace that @emph{opens} a substatement |
| 352 | block. @footnote{A @dfn{substatement} is the line after a | 411 | block. @footnote{A @dfn{substatement} is the line after a |
| @@ -389,22 +448,20 @@ components. Also notice that the first component, | |||
| 389 | 448 | ||
| 390 | 449 | ||
| 391 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 450 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 392 | @node Indentation Calculation, , Syntactic Analysis, New Indentation Engine | 451 | @node Indentation Calculation, , Syntactic Analysis, New Indentation Engine |
| 393 | @comment node-name, next, previous,up | 452 | @comment node-name, next, previous, up |
| 394 | @section Indentation Calculation | 453 | @section Indentation Calculation |
| 395 | @cindex Indentation Calculation | 454 | @cindex indentation calculation |
| 396 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 455 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 397 | 456 | ||
| 398 | @vindex c-offsets-alist | ||
| 399 | @vindex offsets-alist (c-) | ||
| 400 | Indentation for a line is calculated using the syntactic | 457 | Indentation for a line is calculated using the syntactic |
| 401 | component list derived in step 1 above (see @ref{Syntactic Analysis}). | 458 | component list derived in step 1 above (@pxref{Syntactic Analysis}). |
| 402 | Each component contributes to the final total indentation of the line in | 459 | Each component contributes to the final total indentation of the line in |
| 403 | two ways. | 460 | two ways. |
| 404 | 461 | ||
| 405 | First, the syntactic symbols are looked up in the @code{c-offsets-alist} | 462 | First, the syntactic symbols are looked up in the @code{c-offsets-alist} |
| 406 | variable, which is an association list of syntactic symbols and the | 463 | style variable, which is an association list of syntactic symbols and |
| 407 | offsets to apply for those symbols. These offsets are added to a | 464 | the offsets to apply for those symbols. These offsets are added to a |
| 408 | running total. | 465 | running total. |
| 409 | 466 | ||
| 410 | Second, if the component has a relative buffer position, @ccmode{} | 467 | Second, if the component has a relative buffer position, @ccmode{} |
| @@ -427,7 +484,6 @@ our first example again: | |||
| 427 | @end group | 484 | @end group |
| 428 | @end example | 485 | @end example |
| 429 | 486 | ||
| 430 | @kindex TAB | ||
| 431 | Let's say point is on line 3 and we hit the @kbd{TAB} key to re-indent | 487 | Let's say point is on line 3 and we hit the @kbd{TAB} key to re-indent |
| 432 | the line. Remember that the syntactic component list for that | 488 | the line. Remember that the syntactic component list for that |
| 433 | line is: | 489 | line is: |
| @@ -439,9 +495,9 @@ line is: | |||
| 439 | 495 | ||
| 440 | @noindent | 496 | @noindent |
| 441 | @ccmode{} looks up @code{defun-block-intro} in the | 497 | @ccmode{} looks up @code{defun-block-intro} in the |
| 442 | @code{c-offsets-alist} variable. Let's say it finds the value @samp{4}; | 498 | @code{c-offsets-alist} style variable. Let's say it finds the value |
| 443 | it adds this to the running total (initialized to zero), yielding a | 499 | @samp{4}; it adds this to the running total (initialized to zero), |
| 444 | running total indentation of 4 spaces. | 500 | yielding a running total indentation of 4 spaces. |
| 445 | 501 | ||
| 446 | Next @ccmode{} goes to buffer position 29 and asks for the current | 502 | Next @ccmode{} goes to buffer position 29 and asks for the current |
| 447 | column. This brace is in column zero, so @ccmode{} | 503 | column. This brace is in column zero, so @ccmode{} |
| @@ -491,7 +547,6 @@ being used. | |||
| 491 | 547 | ||
| 492 | @vindex c-echo-syntactic-information-p | 548 | @vindex c-echo-syntactic-information-p |
| 493 | @vindex echo-syntactic-information-p (c-) | 549 | @vindex echo-syntactic-information-p (c-) |
| 494 | @cindex TAB | ||
| 495 | As you configure @ccmode{}, you might want to set the variable | 550 | As you configure @ccmode{}, you might want to set the variable |
| 496 | @code{c-echo-syntactic-information-p} to non-@code{nil} so that the | 551 | @code{c-echo-syntactic-information-p} to non-@code{nil} so that the |
| 497 | syntactic component list and calculated offset will always be echoed in | 552 | syntactic component list and calculated offset will always be echoed in |
| @@ -499,11 +554,9 @@ the minibuffer when you hit @kbd{TAB}. | |||
| 499 | 554 | ||
| 500 | 555 | ||
| 501 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 556 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 502 | @node Minor Modes, Commands, New Indentation Engine, Top | 557 | @node Minor Modes, Text Filling and Line Breaking, New Indentation Engine, Top |
| 503 | @comment node-name, next, previous,up | 558 | @comment node-name, next, previous, up |
| 504 | 559 | @chapter Minor Modes | |
| 505 | @chapter Minor Modes | ||
| 506 | @cindex Minor Modes | ||
| 507 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 560 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 508 | 561 | ||
| 509 | @ccmode{} contains two minor-mode-like features that you should | 562 | @ccmode{} contains two minor-mode-like features that you should |
| @@ -516,11 +569,11 @@ are turned off. | |||
| 516 | 569 | ||
| 517 | The state of the minor modes is always reflected in the minor mode list | 570 | The state of the minor modes is always reflected in the minor mode list |
| 518 | on the modeline of the @ccmode{} buffer. When auto-newline mode is | 571 | on the modeline of the @ccmode{} buffer. When auto-newline mode is |
| 519 | enabled, you will see @samp{C/a} on the mode line @footnote{Remember | 572 | enabled, you will see @samp{C/a} on the mode line @footnote{The @samp{C} |
| 520 | that the @samp{C} could be replaced with @samp{C++}, @samp{ObjC}, | 573 | would be replaced with @samp{C++}, @samp{ObjC}, @samp{Java}, @samp{IDL}, |
| 521 | @samp{Java} or @samp{IDL}.}. When hungry delete mode is enabled you | 574 | or @samp{Pike} for the respective languages.}. When hungry delete mode |
| 522 | would see @samp{C/h} and when both modes are enabled, you'd see | 575 | is enabled you would see @samp{C/h} and when both modes are enabled, |
| 523 | @samp{C/ah}. | 576 | you'd see @samp{C/ah}. |
| 524 | 577 | ||
| 525 | @kindex C-c C-a | 578 | @kindex C-c C-a |
| 526 | @kindex C-c C-d | 579 | @kindex C-c C-d |
| @@ -560,17 +613,16 @@ to your @file{.emacs} file: | |||
| 560 | @cindex electric characters | 613 | @cindex electric characters |
| 561 | 614 | ||
| 562 | @menu | 615 | @menu |
| 563 | * Auto-newline insertion:: | 616 | * Auto-newline Insertion:: |
| 564 | * Hungry-deletion of whitespace:: | 617 | * Hungry-deletion of Whitespace:: |
| 565 | * Auto-fill mode interaction:: | ||
| 566 | @end menu | 618 | @end menu |
| 567 | 619 | ||
| 568 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| 569 | @node Auto-newline insertion, Hungry-deletion of whitespace, , Minor Modes | ||
| 570 | @comment node-name, next, previous,up | ||
| 571 | 620 | ||
| 572 | @section Auto-newline insertion | 621 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 573 | @cindex Auto-newline insertion | 622 | @node Auto-newline Insertion, Hungry-deletion of Whitespace, , Minor Modes |
| 623 | @comment node-name, next, previous, up | ||
| 624 | @section Auto-newline Insertion | ||
| 625 | @cindex auto-newline insertion | ||
| 574 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 626 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 575 | 627 | ||
| 576 | @cindex electric commands | 628 | @cindex electric commands |
| @@ -604,25 +656,23 @@ normal, with no @kbd{C-u} prefix). | |||
| 604 | @menu | 656 | @menu |
| 605 | * Hanging Braces:: | 657 | * Hanging Braces:: |
| 606 | * Hanging Colons:: | 658 | * Hanging Colons:: |
| 607 | * Hanging Semi-colons and commas:: | 659 | * Hanging Semi-colons and Commas:: |
| 608 | * Other electric commands:: | 660 | * Other Electric Commands:: |
| 609 | * Clean-ups:: | 661 | * Clean-ups:: |
| 610 | @end menu | 662 | @end menu |
| 611 | 663 | ||
| 612 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| 613 | @node Hanging Braces, Hanging Colons, , Auto-newline insertion | ||
| 614 | @comment node-name, next, previous,up | ||
| 615 | 664 | ||
| 616 | @subsection Hanging Braces | 665 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 617 | @cindex Hanging Braces | 666 | @node Hanging Braces, Hanging Colons, , Auto-newline Insertion |
| 667 | @comment node-name, next, previous, up | ||
| 668 | @subsection Hanging Braces | ||
| 669 | @cindex hanging braces | ||
| 618 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 670 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 619 | 671 | ||
| 620 | @findex c-electric-brace | 672 | @findex c-electric-brace |
| 621 | @findex electric-brace (c-) | 673 | @findex electric-brace (c-) |
| 622 | @vindex c-hanging-braces-alist | 674 | @vindex c-hanging-braces-alist |
| 623 | @vindex hanging-braces-alist (c-) | 675 | @vindex hanging-braces-alist (c-) |
| 624 | @vindex c-offsets-alist | ||
| 625 | @vindex offsets-alist (c-) | ||
| 626 | When you type either an open or close brace (i.e. @kbd{@{} or @kbd{@}}), | 676 | When you type either an open or close brace (i.e. @kbd{@{} or @kbd{@}}), |
| 627 | the electric command @code{c-electric-brace} gets run. This command has | 677 | the electric command @code{c-electric-brace} gets run. This command has |
| 628 | two electric formatting behaviors. First, it will perform some | 678 | two electric formatting behaviors. First, it will perform some |
| @@ -641,32 +691,47 @@ on, then that line is also re-indented. | |||
| 641 | @cindex brace-list-open syntactic symbol | 691 | @cindex brace-list-open syntactic symbol |
| 642 | @cindex brace-list-close syntactic symbol | 692 | @cindex brace-list-close syntactic symbol |
| 643 | @cindex brace-list-intro syntactic symbol | 693 | @cindex brace-list-intro syntactic symbol |
| 644 | @cindex brace-list-entry syntactic symbol | 694 | @cindex brace-entry-open syntactic symbol |
| 645 | @cindex block-open syntactic symbol | 695 | @cindex block-open syntactic symbol |
| 646 | @cindex block-close syntactic symbol | 696 | @cindex block-close syntactic symbol |
| 647 | @cindex substatement-open syntactic symbol | 697 | @cindex substatement-open syntactic symbol |
| 648 | @cindex statement-case-open syntactic symbol | 698 | @cindex statement-case-open syntactic symbol |
| 649 | @cindex extern-lang-open syntactic symbol | 699 | @cindex extern-lang-open syntactic symbol |
| 650 | @cindex extern-lang-close syntactic symbol | 700 | @cindex extern-lang-close syntactic symbol |
| 651 | @cindex namespace-open symbol | 701 | @cindex namespace-open syntactic symbol |
| 652 | @cindex namespace-close symbol | 702 | @cindex namespace-close syntactic symbol |
| 653 | 703 | @cindex inexpr-class-open symbol | |
| 654 | The insertion of newlines is controlled by the | 704 | @cindex inexpr-class-close symbol |
| 655 | @code{c-hanging-braces-alist} variable. This variable contains a | 705 | |
| 706 | The default in auto-newline mode is to insert newlines both before and | ||
| 707 | after a brace, but that can be controlled by the | ||
| 708 | @code{c-hanging-braces-alist} style variable. This variable contains a | ||
| 656 | mapping between syntactic symbols related to braces, and a list of | 709 | mapping between syntactic symbols related to braces, and a list of |
| 657 | places to insert a newline. The syntactic symbols that are useful for | 710 | places to insert a newline. The syntactic symbols that are useful for |
| 658 | this list are: @code{class-open}, @code{class-close}, @code{defun-open}, | 711 | this list are: @code{class-open}, @code{class-close}, @code{defun-open}, |
| 659 | @code{defun-close}, @code{inline-open}, @code{inline-close}, | 712 | @code{defun-close}, @code{inline-open}, @code{inline-close}, |
| 660 | @code{brace-list-open}, @code{brace-list-close}, | 713 | @code{brace-list-open}, @code{brace-list-close}, |
| 661 | @code{brace-list-intro}, @code{brace-list-entry}, @code{block-open}, | 714 | @code{brace-list-intro}, @code{brace-entry-open}, @code{block-open}, |
| 662 | @code{block-close}, @code{substatement-open}, | 715 | @code{block-close}, @code{substatement-open}, |
| 663 | @code{statement-case-open}, | 716 | @code{statement-case-open}, @code{extern-lang-open}, |
| 664 | @code{extern-lang-open}, @code{extern-lang-close}, | 717 | @code{extern-lang-close}, @code{namespace-open}, @code{namespace-close}, |
| 665 | @code{namespace-open}, and @code{namespace-close}. | 718 | @code{inexpr-class-open}, and @code{inexpr-class-close}@footnote{Note |
| 666 | @xref{Syntactic Symbols}, for a more | 719 | that the aggregate constructs in Pike mode, @samp{(@{}, @samp{@})}, |
| 667 | detailed description of these syntactic symbols. | 720 | @samp{([}, @samp{])}, and @samp{(<}, @samp{>)}, do not count as brace |
| 668 | 721 | lists in this regard, even though they do for normal indentation | |
| 669 | @cindex Custom Indentation Functions | 722 | purposes. It's currently not possible to set automatic newlines on |
| 723 | these constructs.}. @xref{Syntactic Symbols}, for a more detailed | ||
| 724 | description of these syntactic symbols, except for | ||
| 725 | @code{inexpr-class-open} and @code{inexpr-class-close}, which aren't | ||
| 726 | actual syntactic symbols. | ||
| 727 | |||
| 728 | The braces of anonymous inner classes in Java are given the special | ||
| 729 | symbols @code{inexpr-class-open} and @code{inexpr-class-close}, so that | ||
| 730 | they can be distinguished from the braces of normal classes@footnote{The | ||
| 731 | braces of anonymous classes produces a combination of | ||
| 732 | @code{inexpr-class}, and @code{class-open} or @code{class-close} in | ||
| 733 | normal indentation analysis.}. | ||
| 734 | |||
| 670 | The value associated with each syntactic symbol in this association list | 735 | The value associated with each syntactic symbol in this association list |
| 671 | is called an @var{ACTION} which can be either a function or a list. | 736 | is called an @var{ACTION} which can be either a function or a list. |
| 672 | @xref{Custom Brace and Colon Hanging}, for a more detailed discussion of | 737 | @xref{Custom Brace and Colon Hanging}, for a more detailed discussion of |
| @@ -696,45 +761,55 @@ will appear on a line by themselves, as shown by the close braces in the | |||
| 696 | above example. The list can also be empty, in which case no newlines | 761 | above example. The list can also be empty, in which case no newlines |
| 697 | are added either before or after the brace. | 762 | are added either before or after the brace. |
| 698 | 763 | ||
| 764 | If a syntactic symbol is missing entirely from | ||
| 765 | @code{c-hanging-braces-alist}, it's treated in the same way as an | ||
| 766 | @var{ACTION} with a list containing @code{before} and @code{after}, so | ||
| 767 | that braces by default end up on their own line. | ||
| 768 | |||
| 699 | For example, the default value of @code{c-hanging-braces-alist} is: | 769 | For example, the default value of @code{c-hanging-braces-alist} is: |
| 700 | @example | 770 | @example |
| 701 | @group | 771 | @group |
| 702 | 772 | ||
| 703 | (defvar c-hanging-braces-alist '((brace-list-open) | 773 | ((brace-list-open) |
| 704 | (substatement-open after) | 774 | (brace-entry-open) |
| 705 | (block-close . c-snug-do-while) | 775 | (substatement-open after) |
| 706 | (extern-lang-open after))) | 776 | (block-close . c-snug-do-while) |
| 777 | (extern-lang-open after) | ||
| 778 | (inexpr-class-open after) | ||
| 779 | (inexpr-class-close before)) | ||
| 707 | 780 | ||
| 708 | @end group | 781 | @end group |
| 709 | @end example | 782 | @end example |
| 710 | 783 | ||
| 711 | @noindent | 784 | @noindent which says that @code{brace-list-open} and |
| 712 | which says that @code{brace-list-open} braces should both hang on the | 785 | @code{brace-entry-open} braces should both hang on the right side, and |
| 713 | right side, and allow subsequent text to follow on the same line as the | 786 | allow subsequent text to follow on the same line as the brace. Also, |
| 714 | brace. Also, @code{substatement-open} and @code{extern-lang-open} | 787 | @code{substatement-open}, @code{extern-lang-open}, and |
| 715 | braces should hang on the right side, but subsequent text should follow | 788 | @code{inexpr-class-open} braces should hang on the right side, but |
| 716 | on the next line. Here, in the @code{block-close} entry, you also see | 789 | subsequent text should follow on the next line. The opposite holds for |
| 717 | an example of using a function as an @var{ACTION}. | 790 | @code{inexpr-class-close} braces; they won't hang, but the following |
| 791 | text continues on the same line. Here, in the @code{block-close} entry, | ||
| 792 | you also see an example of using a function as an @var{ACTION}. In all | ||
| 793 | other cases, braces are put on a line by themselves. | ||
| 718 | 794 | ||
| 719 | A word of caution: it is not a good idea to hang top-level construct | 795 | A word of caution: it is not a good idea to hang top-level construct |
| 720 | introducing braces, such as @code{class-open} or @code{defun-open}. | 796 | introducing braces, such as @code{class-open} or @code{defun-open}. |
| 721 | Emacs makes an assumption that such braces will always appear in column | 797 | Emacs makes an assumption that such braces will always appear in column |
| 722 | zero, hanging such braces can introduce performance problems. | 798 | zero, hanging them can introduce performance problems. |
| 723 | @xref{Performance Issues}, for more information. | 799 | @xref{Performance Issues}, for more information. |
| 724 | 800 | ||
| 725 | 801 | ||
| 726 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 802 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 727 | @node Hanging Colons, Hanging Semi-colons and commas, Hanging Braces, Auto-newline insertion | 803 | @node Hanging Colons, Hanging Semi-colons and Commas, Hanging Braces, Auto-newline Insertion |
| 728 | @comment node-name, next, previous,up | 804 | @comment node-name, next, previous, up |
| 729 | 805 | @subsection Hanging Colons | |
| 730 | @subsection Hanging Colons | 806 | @cindex hanging colons |
| 731 | @cindex Hanging Colons | ||
| 732 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 807 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 733 | 808 | ||
| 734 | @vindex hanging-colons-alist (c-) | 809 | @vindex hanging-colons-alist (c-) |
| 735 | @vindex c-hanging-colons-alist | 810 | @vindex c-hanging-colons-alist |
| 736 | Using a mechanism similar to brace hanging (see @ref{Hanging Braces}), | 811 | Using a mechanism similar to brace hanging (@pxref{Hanging Braces}), |
| 737 | colons can also be made to hang using the variable | 812 | colons can also be made to hang using the style variable |
| 738 | @code{c-hanging-colons-alist}. The syntactic symbols appropriate for | 813 | @code{c-hanging-colons-alist}. The syntactic symbols appropriate for |
| 739 | this assocation list are: @code{case-label}, @code{label}, | 814 | this assocation list are: @code{case-label}, @code{label}, |
| 740 | @code{access-label}, @code{member-init-intro}, and @code{inher-intro}. | 815 | @code{access-label}, @code{member-init-intro}, and @code{inher-intro}. |
| @@ -742,7 +817,6 @@ Note however that for @code{c-hanging-colons-alist}, @var{ACTION}s as | |||
| 742 | functions are not supported. See also @ref{Custom Brace and Colon | 817 | functions are not supported. See also @ref{Custom Brace and Colon |
| 743 | Hanging} for details. | 818 | Hanging} for details. |
| 744 | 819 | ||
| 745 | @cindex Clean-ups | ||
| 746 | In C++, double-colons are used as a scope operator but because these | 820 | In C++, double-colons are used as a scope operator but because these |
| 747 | colons always appear right next to each other, newlines before and after | 821 | colons always appear right next to each other, newlines before and after |
| 748 | them are controlled by a different mechanism, called @dfn{clean-ups} in | 822 | them are controlled by a different mechanism, called @dfn{clean-ups} in |
| @@ -750,11 +824,11 @@ them are controlled by a different mechanism, called @dfn{clean-ups} in | |||
| 750 | 824 | ||
| 751 | 825 | ||
| 752 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 826 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 753 | @node Hanging Semi-colons and commas, Other electric commands, Hanging Colons, Auto-newline insertion | 827 | @node Hanging Semi-colons and Commas, Other Electric Commands, Hanging Colons, Auto-newline Insertion |
| 754 | @comment node-name, next, previous,up | 828 | @comment node-name, next, previous, up |
| 755 | 829 | @subsection Hanging Semi-colons and Commas | |
| 756 | @subsection Hanging Semi-colons and commas | 830 | @cindex hanging semi-colons |
| 757 | @cindex Hanging Semi-colons and commas | 831 | @cindex hanging commas |
| 758 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 832 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 759 | 833 | ||
| 760 | Semicolons and commas are also electric in @ccmode{}, but since | 834 | Semicolons and commas are also electric in @ccmode{}, but since |
| @@ -765,11 +839,9 @@ Semi-colons and Commas}, for details. | |||
| 765 | 839 | ||
| 766 | 840 | ||
| 767 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 841 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 768 | @node Other electric commands, Clean-ups, Hanging Semi-colons and commas, Auto-newline insertion | 842 | @node Other Electric Commands, Clean-ups, Hanging Semi-colons and Commas, Auto-newline Insertion |
| 769 | @comment node-name, next, previous,up | 843 | @comment node-name, next, previous, up |
| 770 | 844 | @subsection Other Electric Commands | |
| 771 | @subsection Other electric commands | ||
| 772 | @cindex Other electric commands | ||
| 773 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 845 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 774 | 846 | ||
| 775 | @kindex # | 847 | @kindex # |
| @@ -777,8 +849,6 @@ Semi-colons and Commas}, for details. | |||
| 777 | @vindex c-electric-pound-behavior | 849 | @vindex c-electric-pound-behavior |
| 778 | @findex electric-pound (c-) | 850 | @findex electric-pound (c-) |
| 779 | @vindex electric-pound-behavior (c-) | 851 | @vindex electric-pound-behavior (c-) |
| 780 | @vindex c-offsets-alist | ||
| 781 | @vindex offsets-alist (c-) | ||
| 782 | A few other keys also provide electric behavior. For example | 852 | A few other keys also provide electric behavior. For example |
| 783 | @kbd{#} (@code{c-electric-pound}) is electric when typed as | 853 | @kbd{#} (@code{c-electric-pound}) is electric when typed as |
| 784 | the first non-whitespace character on a line. In this case, the | 854 | the first non-whitespace character on a line. In this case, the |
| @@ -792,11 +862,10 @@ C preprocessor macro definitions. | |||
| 792 | @findex c-electric-slash | 862 | @findex c-electric-slash |
| 793 | @findex electric-star (c-) | 863 | @findex electric-star (c-) |
| 794 | @findex electric-slash (c-) | 864 | @findex electric-slash (c-) |
| 795 | @cindex comment-only line | ||
| 796 | Stars and slashes (i.e. @kbd{*} and @kbd{/}, @code{c-electric-star} and | 865 | Stars and slashes (i.e. @kbd{*} and @kbd{/}, @code{c-electric-star} and |
| 797 | @code{c-electric-slash} respectively) are also electric under | 866 | @code{c-electric-slash} respectively) are also electric under |
| 798 | certain circumstances. If a star is inserted as the second character of | 867 | certain circumstances. If a star is inserted as the second character of |
| 799 | a C style block comment on a @dfn{comment-only} line, then the comment | 868 | a C style block comment on a comment-only line, then the comment |
| 800 | delimiter is indented as defined by @code{c-offsets-alist}. A | 869 | delimiter is indented as defined by @code{c-offsets-alist}. A |
| 801 | comment-only line is defined as a line which contains only a comment, as | 870 | comment-only line is defined as a line which contains only a comment, as |
| 802 | in: | 871 | in: |
| @@ -827,13 +896,21 @@ Less-than and greater-than signs (@code{c-electric-lt-gt}) are also | |||
| 827 | electric, but only in C++ mode. Hitting the second of two @kbd{<} or | 896 | electric, but only in C++ mode. Hitting the second of two @kbd{<} or |
| 828 | @kbd{>} keys re-indents the line if it is a C++ style stream operator. | 897 | @kbd{>} keys re-indents the line if it is a C++ style stream operator. |
| 829 | 898 | ||
| 899 | @findex c-electric-paren | ||
| 900 | @findex electric-paren (c-) | ||
| 901 | @kindex ( | ||
| 902 | @kindex ) | ||
| 903 | The normal parenthesis characters @samp{(} and @samp{)} also reindent | ||
| 904 | the current line if they are used in normal code. This is useful for | ||
| 905 | getting the closing parenthesis of an argument list aligned | ||
| 906 | automatically. | ||
| 830 | 907 | ||
| 831 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| 832 | @node Clean-ups, , Other electric commands, Auto-newline insertion | ||
| 833 | @comment node-name, next, previous,up | ||
| 834 | 908 | ||
| 835 | @subsection Clean-ups | 909 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 836 | @cindex Clean-ups | 910 | @node Clean-ups, , Other Electric Commands, Auto-newline Insertion |
| 911 | @comment node-name, next, previous, up | ||
| 912 | @subsection Clean-ups | ||
| 913 | @cindex clean-ups | ||
| 837 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 914 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 838 | 915 | ||
| 839 | @dfn{Clean-ups} are a mechanism complementary to colon and brace | 916 | @dfn{Clean-ups} are a mechanism complementary to colon and brace |
| @@ -844,17 +921,17 @@ enabled. Clean-ups are used however to adjust code ``after-the-fact'', | |||
| 844 | i.e. to eliminate some whitespace that is inserted by electric | 921 | i.e. to eliminate some whitespace that is inserted by electric |
| 845 | commands, or whitespace that contains intervening constructs. | 922 | commands, or whitespace that contains intervening constructs. |
| 846 | 923 | ||
| 924 | @vindex c-cleanup-list | ||
| 925 | @vindex cleanup-list (c-) | ||
| 847 | @cindex literal | 926 | @cindex literal |
| 848 | You can configure @ccmode{}'s clean-ups by setting the variable | 927 | You can configure @ccmode{}'s clean-ups by setting the style variable |
| 849 | @code{c-cleanup-list}, which is a list of clean-up symbols. By default, | 928 | @code{c-cleanup-list}, which is a list of clean-up symbols. By default, |
| 850 | @ccmode{} cleans up only the @code{scope-operator} construct, which | 929 | @ccmode{} cleans up only the @code{scope-operator} construct, which is |
| 851 | is necessary for proper C++ support. Note that clean-ups are only | 930 | necessary for proper C++ support. Note that clean-ups are only |
| 852 | performed when the construct does not occur within a literal (see | 931 | performed when the construct does not occur within a literal |
| 853 | @ref{Auto-newline insertion}), and when there is nothing but whitespace | 932 | (@pxref{Auto-newline Insertion}), and when there is nothing but |
| 854 | appearing between the individual components of the construct. | 933 | whitespace appearing between the individual components of the construct. |
| 855 | 934 | ||
| 856 | @vindex c-cleanup-list | ||
| 857 | @vindex cleanup-list (c-) | ||
| 858 | There are currently only five specific constructs that @ccmode{} | 935 | There are currently only five specific constructs that @ccmode{} |
| 859 | can clean up, as indicated by these symbols: | 936 | can clean up, as indicated by these symbols: |
| 860 | 937 | ||
| @@ -904,12 +981,27 @@ void spam(int i) | |||
| 904 | @{ | 981 | @{ |
| 905 | dosomething(); | 982 | dosomething(); |
| 906 | @} | 983 | @} |
| 907 | else if( i==3 ) @{ | 984 | else if( i==3 ) |
| 985 | @{ | ||
| 908 | 986 | ||
| 909 | @end group | 987 | @end group |
| 910 | @end example | 988 | @end example |
| 911 | @noindent | 989 | @noindent |
| 912 | appears like this after the open brace is typed: | 990 | appears like this after the open parenthesis is typed: |
| 991 | @example | ||
| 992 | @group | ||
| 993 | |||
| 994 | void spam(int i) | ||
| 995 | @{ | ||
| 996 | if( i==7 ) @{ | ||
| 997 | dosomething(); | ||
| 998 | @} else if( i==3 ) | ||
| 999 | @{ | ||
| 1000 | |||
| 1001 | @end group | ||
| 1002 | @end example | ||
| 1003 | @noindent | ||
| 1004 | and like this after the open brace is typed: | ||
| 913 | @example | 1005 | @example |
| 914 | @group | 1006 | @group |
| 915 | 1007 | ||
| @@ -923,6 +1015,10 @@ void spam(int i) | |||
| 923 | @end example | 1015 | @end example |
| 924 | 1016 | ||
| 925 | @item | 1017 | @item |
| 1018 | @code{brace-catch-brace} --- analogous to @code{brace-elseif-brace}, but | ||
| 1019 | cleans up @samp{@} catch (...) @{} in C++ and Java mode. | ||
| 1020 | |||
| 1021 | @item | ||
| 926 | @code{empty-defun-braces} --- cleans up braces following a top-level | 1022 | @code{empty-defun-braces} --- cleans up braces following a top-level |
| 927 | function or class definition that contains no body. Clean up occurs | 1023 | function or class definition that contains no body. Clean up occurs |
| 928 | when the closing brace is typed. Thus the following: | 1024 | when the closing brace is typed. Thus the following: |
| @@ -991,11 +1087,10 @@ in the @code{c-cleanup-list} when you are editing C++ code. | |||
| 991 | 1087 | ||
| 992 | 1088 | ||
| 993 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 1089 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 994 | @node Hungry-deletion of whitespace, Auto-fill mode interaction, Auto-newline insertion, Minor Modes | 1090 | @node Hungry-deletion of Whitespace, , Auto-newline Insertion, Minor Modes |
| 995 | @comment node-name, next, previous,up | 1091 | @comment node-name, next, previous, up |
| 996 | 1092 | @section Hungry-deletion of Whitespace | |
| 997 | @section Hungry-deletion of whitespace | 1093 | @cindex hungry-deletion of whitespace |
| 998 | @cindex Hungry-deletion of whitespace | ||
| 999 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 1094 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 1000 | 1095 | ||
| 1001 | Hungry deletion of whitespace, or as it more commonly called, | 1096 | Hungry deletion of whitespace, or as it more commonly called, |
| @@ -1032,199 +1127,447 @@ the preceding line. | |||
| 1032 | 1127 | ||
| 1033 | @findex backward-delete-char-untabify | 1128 | @findex backward-delete-char-untabify |
| 1034 | 1129 | ||
| 1035 | By default, when you hit the @key{Backspace} key | 1130 | By default, when you hit the @key{Backspace} key @ccmode{} runs the |
| 1036 | @ccmode{} runs the command @code{c-electric-backspace}, which deletes | 1131 | command @code{c-electric-backspace}, which deletes text in the backwards |
| 1037 | text in the backwards direction. When deleting a single character, or | 1132 | direction. When deleting a single character, or when @key{Backspace} is |
| 1038 | when @key{Backspace} is hit in a literal | 1133 | hit in a literal (@pxref{Auto-newline Insertion}), or when hungry-delete |
| 1039 | (see @ref{Auto-newline insertion}), | 1134 | mode is disabled, the function contained in the |
| 1040 | or when hungry-delete mode is disabled, the function | 1135 | @code{c-backspace-function} variable is called with one argument (the |
| 1041 | contained in the @code{c-backspace-function} variable is called with one | 1136 | number of characters to delete). This variable is set to |
| 1042 | argument (the number of characters to delete). This variable is set to | ||
| 1043 | @code{backward-delete-char-untabify} by default. | 1137 | @code{backward-delete-char-untabify} by default. |
| 1044 | 1138 | ||
| 1045 | @vindex delete-key-deletes-forward | 1139 | @vindex delete-key-deletes-forward |
| 1046 | @findex delete-char | 1140 | @findex delete-char |
| 1047 | 1141 | ||
| 1048 | Similarly, hitting the @key{Delete} key runs the command | 1142 | The default behavior of the @key{Delete} key depends on the flavor of |
| 1049 | @code{c-electric-delete}. When deleting a single character, or when | 1143 | Emacs you are using. By default in XEmacs 20.3 and beyond, the |
| 1050 | @key{Delete} is hit in a literal, or when hungry-delete mode is | 1144 | @key{Delete} key is bound to @code{c-electric-delete}. You control the |
| 1051 | disabled, the function contained in the @code{c-delete-function} | 1145 | direction that the @key{Delete} key deletes by setting the variable |
| 1052 | variable is called with one argument (the number of characters to | 1146 | @code{delete-key-deletes-forward}, a standard XEmacs variable. When |
| 1053 | delete). This variable is set to @code{delete-char} by default. | 1147 | this variable is non-@code{nil} and hungry-delete mode is enabled, |
| 1054 | 1148 | @code{c-electric-delete} will consume all whitespace @emph{following} | |
| 1055 | However, if @code{delete-key-deletes-forward} is @code{nil}, or your | 1149 | point. When @code{delete-key-deletes-forward} is @code{nil}, it deletes |
| 1056 | Emacs does not support separation of @key{Backspace} and @key{DEL}, then | 1150 | all whitespace @emph{preceding} point@footnote{i.e. it literally calls |
| 1057 | @code{c-electric-delete} simply calls @code{c-electric-backspace}. | 1151 | @code{c-electric-backspace}.} When deleting a single character, or if |
| 1152 | @key{Delete} is hit in a literal, or hungry-delete mode is disabled, the | ||
| 1153 | function contained in @code{c-delete-function} is called with one | ||
| 1154 | argument: the number of characters to delete. This variable is set to | ||
| 1155 | @code{delete-char} by default. | ||
| 1156 | |||
| 1157 | In Emacs 19 or Emacs 20, both the @key{Delete} and @key{Backspace} keys | ||
| 1158 | are bound to @code{c-electric-backspace}, however you can change this by | ||
| 1159 | explicitly binding @code{[delete]}@footnote{E.g. to | ||
| 1160 | @code{c-electric-delete} in your @file{.emacs} file. Note however, that | ||
| 1161 | Emacs 20 does not have a standard variable such as | ||
| 1162 | @code{delete-key-deletes-forward}.}. | ||
| 1163 | |||
| 1164 | XEmacsen older than 20.3 behave similar to Emacs 19 and Emacs 20. | ||
| 1058 | 1165 | ||
| 1059 | 1166 | ||
| 1060 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 1167 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 1061 | @node Auto-fill mode interaction, , Hungry-deletion of whitespace, Minor Modes | 1168 | @node Text Filling and Line Breaking, Commands, Minor Modes, Top |
| 1062 | @comment node-name, next, previous,up | 1169 | @comment node-name, next, previous, up |
| 1063 | 1170 | @chapter Text Filling and Line Breaking | |
| 1064 | @section Auto-fill mode interaction | ||
| 1065 | @cindex Auto-fill mode interaction | ||
| 1066 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 1171 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 1067 | 1172 | ||
| 1068 | One other note about minor modes is worth mentioning here. CC Mode now | 1173 | Since there's a lot of normal text in comments and string literals, |
| 1069 | works much better with auto-fill mode (a standard Emacs minor mode) by | 1174 | @ccmode{} provides features to edit these like in text mode. The goal |
| 1070 | correctly auto-filling both line (e.g. C++ style) and block (e.g. C | 1175 | is to do it as seamlessly as possible, i.e. you can use auto fill mode, |
| 1071 | style) oriented comments. When @code{auto-fill-mode} is enabled, line | 1176 | sentence and paragraph movement, paragraph filling, adaptive filling etc |
| 1072 | oriented comments will also be auto-filled by inserting a newline at the | 1177 | wherever there's a piece of normal text without having to think much |
| 1073 | line break, and inserting @samp{//} at the start of the next line. | 1178 | about it. @ccmode{} should keep the indentation, fix the comment line |
| 1179 | decorations, and so on, for you. It does that by hooking in on the | ||
| 1180 | different line breaking functions and tuning relevant variables as | ||
| 1181 | necessary. | ||
| 1182 | |||
| 1183 | @vindex c-comment-prefix-regexp | ||
| 1184 | @vindex comment-prefix-regexp (c-) | ||
| 1185 | @cindex comment line prefix | ||
| 1186 | @vindex comment-start | ||
| 1187 | @vindex comment-end | ||
| 1188 | @vindex comment-start-skip | ||
| 1189 | @vindex paragraph-start | ||
| 1190 | @vindex paragraph-separate | ||
| 1191 | @vindex paragraph-ignore-fill-prefix | ||
| 1192 | @vindex adaptive-fill-mode | ||
| 1193 | @vindex adaptive-fill-regexp | ||
| 1194 | @vindex adaptive-fill-first-line-regexp | ||
| 1195 | To make Emacs recognize comments and treat text in them as normal | ||
| 1196 | paragraphs, @ccmode{} makes several standard | ||
| 1197 | variables@footnote{@code{comment-start}, @code{comment-end}, | ||
| 1198 | @code{comment-start-skip}, @code{paragraph-start}, | ||
| 1199 | @code{paragraph-separate}, @code{paragraph-ignore-fill-prefix}, | ||
| 1200 | @code{adaptive-fill-mode}, @code{adaptive-fill-regexp}, and | ||
| 1201 | @code{adaptive-fill-first-line-regexp}.} buffer local and modifies them | ||
| 1202 | according to the language syntax and the style of line decoration that | ||
| 1203 | starts every line in a comment. The style variable | ||
| 1204 | @code{c-comment-prefix-regexp} contains the regexp used to recognize | ||
| 1205 | this @dfn{comment line prefix}. The default is @samp{//+\\|\\**}, which | ||
| 1206 | matches C++ style line comments like | ||
| 1207 | @example | ||
| 1208 | |||
| 1209 | // blah blah | ||
| 1210 | |||
| 1211 | @end example | ||
| 1212 | |||
| 1213 | @noindent | ||
| 1214 | with two or more slashes in front of them, and C style block comments | ||
| 1215 | like | ||
| 1216 | @example | ||
| 1217 | @group | ||
| 1218 | |||
| 1219 | /* | ||
| 1220 | * blah blah | ||
| 1221 | */ | ||
| 1222 | |||
| 1223 | @end group | ||
| 1224 | @end example | ||
| 1225 | |||
| 1226 | @noindent | ||
| 1227 | with zero or more stars at the beginning of every line. If you change | ||
| 1228 | that variable, please make sure it still matches the comment starter | ||
| 1229 | (i.e. @code{//}) of line comments @emph{and} the line prefix inside | ||
| 1230 | block comments. Also note that since @ccmode{} uses the value of | ||
| 1231 | @code{c-comment-prefix-regexp} to set up several other variables at mode | ||
| 1232 | initialization, you need to reinitialize the program mode if you change | ||
| 1233 | it inside a @ccmode{} buffer. | ||
| 1234 | |||
| 1235 | @findex auto-fill-mode | ||
| 1236 | @cindex auto fill mode | ||
| 1237 | @cindex paragraph fill | ||
| 1238 | Line breaks are by default handled (almost) the same regardless whether | ||
| 1239 | they are made by auto fill mode (@pxref{Auto Fill,,, emacs, The Emacs | ||
| 1240 | Editor}), paragraph filling (e.g. with @kbd{M-q}), or explicitly with | ||
| 1241 | @kbd{M-j} or similar methods. In string literals, the new line gets the | ||
| 1242 | same indentation as the previous nonempty line (may be changed with the | ||
| 1243 | @code{string} syntactic symbol). In comments, @ccmode{} uses | ||
| 1244 | @code{c-comment-prefix-regexp} to adapt the line prefix from the other | ||
| 1245 | lines in the comment. | ||
| 1246 | |||
| 1247 | @vindex adaptive-fill-mode | ||
| 1248 | @cindex adaptive fill mode | ||
| 1249 | @ccmode{} uses adaptive fill mode (@pxref{Adaptive Fill,,, emacs, The | ||
| 1250 | Emacs Editor}) to make Emacs correctly keep the line prefix when filling | ||
| 1251 | paragraphs. That also makes Emacs preserve the text indentation | ||
| 1252 | @emph{inside} the comment line prefix. E.g. in the following comment, | ||
| 1253 | both paragraphs will be filled with the left margins kept intact: | ||
| 1254 | @example | ||
| 1255 | @group | ||
| 1256 | |||
| 1257 | /* Make a balanced b-tree of the nodes in the incoming | ||
| 1258 | * stream. But, to quote the famous words of Donald E. | ||
| 1259 | * Knuth, | ||
| 1260 | * | ||
| 1261 | * Beware of bugs in the above code; I have only | ||
| 1262 | * proved it correct, not tried it. | ||
| 1263 | */ | ||
| 1264 | |||
| 1265 | @end group | ||
| 1266 | @end example | ||
| 1267 | |||
| 1268 | @findex c-setup-filladapt | ||
| 1269 | @findex setup-filladapt (c-) | ||
| 1270 | @findex filladapt-mode | ||
| 1271 | @vindex filladapt-mode | ||
| 1272 | @cindex Filladapt mode | ||
| 1273 | It's also possible to use other adaptive filling packages, notably Kyle | ||
| 1274 | E. Jones' Filladapt package@footnote{It's available from | ||
| 1275 | @uref{http://www.wonderworks.com/}. As of version 2.12, it does however | ||
| 1276 | lack a feature that makes it work suboptimally when | ||
| 1277 | @code{c-comment-prefix-regexp} matches the empty string (which it does | ||
| 1278 | by default). A patch for that is available from | ||
| 1279 | @uref{http://www.python.org/emacs/cc-mode/,, the CC Mode site}.}, | ||
| 1280 | which handles things like bulleted lists nicely. There's a convenience | ||
| 1281 | function @code{c-setup-filladapt} that tunes the relevant variables in | ||
| 1282 | Filladapt for use in @ccmode{}. Call it from a mode hook, e.g. with | ||
| 1283 | something like this in your @file{.emacs}: | ||
| 1284 | @example | ||
| 1285 | @group | ||
| 1286 | |||
| 1287 | (defun my-c-mode-common-hook () | ||
| 1288 | (c-setup-filladapt) | ||
| 1289 | (filladapt-mode 1)) | ||
| 1290 | (add-hook 'c-mode-common-hook 'my-c-mode-common-hook) | ||
| 1291 | |||
| 1292 | @end group | ||
| 1293 | @end example | ||
| 1074 | 1294 | ||
| 1295 | @vindex c-block-comment-prefix | ||
| 1296 | @vindex block-comment-prefix (c-) | ||
| 1075 | @vindex c-comment-continuation-stars | 1297 | @vindex c-comment-continuation-stars |
| 1076 | @vindex comment-continuation-stars (c-) | 1298 | @vindex comment-continuation-stars (c-) |
| 1077 | @vindex comment-line-break-function | 1299 | Normally the comment line prefix inserted for a new line inside a |
| 1078 | When auto-filling block oriented comments, the behavior is dependent on | 1300 | comment is deduced from other lines in it. However there's one |
| 1079 | the value of the variable @code{c-comment-continuation-stars}. When | 1301 | situation when there's no clue about how the prefix should look, namely |
| 1080 | this variable is @code{nil}, the old behavior for auto-filling C | 1302 | when a block comment is broken for the first time. The string in the |
| 1081 | comments is in effect. In this case, the line is broken by closing the | 1303 | style variable @code{c-block-comment-prefix}@footnote{In versions before |
| 1082 | comment and starting a new comment on the next line. | 1304 | 5.26, this variable was called @code{c-comment-continuation-stars}. As |
| 1305 | a compatibility measure, @ccmode{} still uses the value on that variable | ||
| 1306 | if it's set.} is used in that case. It defaults to @samp{* }, which | ||
| 1307 | makes a comment | ||
| 1308 | @example | ||
| 1083 | 1309 | ||
| 1084 | If you set @code{c-comment-continuation-stars} to a string, then a long | 1310 | /* Got O(n^2) here, which is a Bad Thing. */ |
| 1085 | C block comment line is broken by inserting a newline at the line break | ||
| 1086 | position, and inserting this string at the beginning of the next comment | ||
| 1087 | line. The default value for @code{c-comment-continuation-stars} is | ||
| 1088 | @samp{* } (a star followed by a single space)@footnote{To get block | ||
| 1089 | comment continuation lines indented under the block comment starter | ||
| 1090 | (e.g. the @samp{/*}), it is not enough to set | ||
| 1091 | @code{c-comment-continuation-stars} to the empty string. You need to do | ||
| 1092 | this, but you also need to set the offset for the @code{c} syntactic | ||
| 1093 | symbol to be zero.}. | ||
| 1094 | 1311 | ||
| 1312 | @end example | ||
| 1095 | 1313 | ||
| 1096 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 1314 | @noindent |
| 1097 | @node Commands, Customizing Indentation, Minor Modes, Top | 1315 | break into |
| 1098 | @comment node-name, next, previous,up | 1316 | @example |
| 1317 | @group | ||
| 1318 | |||
| 1319 | /* Got O(n^2) here, | ||
| 1320 | * which is a Bad Thing. */ | ||
| 1099 | 1321 | ||
| 1100 | @chapter Commands | 1322 | @end group |
| 1101 | @cindex Commands | 1323 | @end example |
| 1324 | |||
| 1325 | Note that it won't work to justify the indentation by putting leading | ||
| 1326 | spaces in the @code{c-block-comment-prefix} string, since @ccmode{} | ||
| 1327 | still uses the normal indentation engine to indent the line. Thus, the | ||
| 1328 | right way to fix the indentation is by setting the @code{c} syntactic | ||
| 1329 | symbol. It defaults to @code{c-lineup-C-comments}, which handles the | ||
| 1330 | indentation of most common comment styles, see @ref{Indentation | ||
| 1331 | Functions}. | ||
| 1332 | |||
| 1333 | @vindex c-ignore-auto-fill | ||
| 1334 | @vindex ignore-auto-fill (c-) | ||
| 1335 | When auto fill mode is enabled, @ccmode{} can selectively ignore it | ||
| 1336 | depending on the context the line break would occur in, e.g. to never | ||
| 1337 | break a line automatically inside a string literal. This behavior can | ||
| 1338 | be controlled with the @code{c-ignore-auto-fill} variable. It takes a | ||
| 1339 | list of symbols for the different contexts where auto-filling never | ||
| 1340 | should occur: | ||
| 1341 | |||
| 1342 | @itemize @bullet | ||
| 1343 | @item @code{string} --- Inside a string or character literal. | ||
| 1344 | @item @code{c} --- Inside a C style block comment. | ||
| 1345 | @item @code{c++} --- Inside a C++ style line comment. | ||
| 1346 | @item @code{cpp} --- Inside a preprocessor directive. | ||
| 1347 | @item @code{code} --- Anywhere else, i.e. in normal code. | ||
| 1348 | @end itemize | ||
| 1349 | |||
| 1350 | By default, @code{c-ignore-auto-fill} is set to @code{'(string cpp | ||
| 1351 | code)}, which means that auto-filling only occurs in comments when | ||
| 1352 | auto-fill mode is activated. In literals, it's often desirable to have | ||
| 1353 | explicit control over newlines. In preprocessor directives, the | ||
| 1354 | necessary @samp{\} escape character before the newline is not | ||
| 1355 | automatically inserted, so an automatic line break would produce invalid | ||
| 1356 | code. In normal code, line breaks are normally dictated by some logical | ||
| 1357 | structure in the code rather than the last whitespace character, so | ||
| 1358 | automatic line breaks there will produce poor results in the current | ||
| 1359 | implementation. | ||
| 1360 | |||
| 1361 | The commands that does the actual work follows. | ||
| 1362 | |||
| 1363 | @table @asis | ||
| 1364 | |||
| 1365 | @kindex M-q | ||
| 1366 | @findex c-fill-paragraph | ||
| 1367 | @findex fill-paragraph (c-) | ||
| 1368 | @cindex Javadoc markup | ||
| 1369 | @item @kbd{M-q} (@code{c-fill-paragraph}) | ||
| 1370 | This is the replacement for @code{fill-paragraph} in @ccmode{} | ||
| 1371 | buffers. It's used to fill multiline string literals and both block and | ||
| 1372 | line style comments. In Java buffers, the Javadoc markup words are | ||
| 1373 | recognized as paragraph starters. | ||
| 1374 | |||
| 1375 | The function keeps the comment starters and enders of block comments as | ||
| 1376 | they were before the filling. This means that a comment ender on the | ||
| 1377 | same line as the paragraph being filled will be filled with the | ||
| 1378 | paragraph, and one on a line by itself will stay as it is. The comment | ||
| 1379 | starter is handled similarly@footnote{This means that the variables | ||
| 1380 | @code{c-hanging-comment-starter-p} and @code{c-hanging-comment-ender-p}, | ||
| 1381 | which controlled this behavior in earlier versions of @ccmode{}, are now | ||
| 1382 | obsolete.}. | ||
| 1383 | |||
| 1384 | @kindex M-j | ||
| 1385 | @findex c-indent-new-comment-line | ||
| 1386 | @findex indent-new-comment-line (c-) | ||
| 1387 | @item @kbd{M-j} (@code{c-indent-new-comment-line}) | ||
| 1388 | This is the replacement for @code{indent-new-comment-line}. It breaks | ||
| 1389 | the line at point and indents the new line like the current one. | ||
| 1390 | |||
| 1391 | @vindex comment-multi-line | ||
| 1392 | If inside a comment and @code{comment-multi-line} is non-@code{nil}, the | ||
| 1393 | indentation and line prefix are preserved. If inside a comment and | ||
| 1394 | @code{comment-multi-line} is @code{nil}, a new comment of the same type | ||
| 1395 | is started on the next line and indented as appropriate for comments. | ||
| 1396 | |||
| 1397 | @findex c-context-line-break | ||
| 1398 | @findex context-line-break (c-) | ||
| 1399 | @item @kbd{M-x c-context-line-break} | ||
| 1400 | This is a function that works like @code{indent-new-comment-line} in | ||
| 1401 | comments and @code{newline-and-indent} elsewhere, thus combining those | ||
| 1402 | two in a way that uses each one in the context it's best suited for. | ||
| 1403 | I.e. in comments the comment line prefix and indentation is kept for the | ||
| 1404 | new line, and in normal code it's indented according to context by the | ||
| 1405 | indentation engine. | ||
| 1406 | |||
| 1407 | It's not bound to a key by default, but it's intended to be used on the | ||
| 1408 | @kbd{RET} key. If you like the behavior of @code{newline-and-indent} on | ||
| 1409 | @kbd{RET}, you might consider switching to this function. | ||
| 1410 | |||
| 1411 | @end table | ||
| 1412 | |||
| 1413 | |||
| 1414 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| 1415 | @node Commands, Customizing Indentation, Text Filling and Line Breaking, Top | ||
| 1416 | @comment node-name, next, previous, up | ||
| 1417 | @chapter Commands | ||
| 1102 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 1418 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 1103 | 1419 | ||
| 1104 | @menu | 1420 | @menu |
| 1105 | * Indentation Commands:: | 1421 | * Indentation Commands:: |
| 1422 | * Movement Commands:: | ||
| 1106 | * Other Commands:: | 1423 | * Other Commands:: |
| 1107 | @end menu | 1424 | @end menu |
| 1108 | 1425 | ||
| 1109 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 1426 | See also @ref{Text Filling and Line Breaking}, for commands concerning |
| 1110 | @node Indentation Commands, Other Commands, , Commands | 1427 | that bit. |
| 1111 | @comment node-name, next, previous,up | ||
| 1112 | |||
| 1113 | @section Indentation Commands | ||
| 1114 | @cindex Indentation Commands | ||
| 1115 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| 1116 | 1428 | ||
| 1117 | Various commands are provided which allow you to conveniently re-indent | ||
| 1118 | C constructs. There are several things to | ||
| 1119 | note about these indentation commands. First, when you | ||
| 1120 | change your programming style, either interactively or through some | ||
| 1121 | other means, your file does @emph{not} automatically get re-indented. | ||
| 1122 | When you change style parameters, you will typically need to reformat | ||
| 1123 | the line, expression, or buffer to see the effects of your changes. | ||
| 1124 | 1429 | ||
| 1125 | @cindex c-hanging- functions | 1430 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 1126 | @findex c-hanging-braces-alist | 1431 | @node Indentation Commands, Movement Commands, , Commands |
| 1127 | @findex hanging-braces-alist (c-) | 1432 | @comment node-name, next, previous,up |
| 1128 | Second, changing some variables have no effect on existing code, even | 1433 | @section Indentation Commands |
| 1129 | when you do re-indent. For example, the @code{c-hanging-*} variables | 1434 | @cindex indentation commands |
| 1130 | and @code{c-cleanup-list} only affect new code as it is typed in | 1435 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 1131 | on-the-fly, so changing @code{c-hanging-braces-alist} and re-indenting | ||
| 1132 | the buffer will not adjust placement of braces already in the file. | ||
| 1133 | 1436 | ||
| 1134 | @vindex c-progress-interval | 1437 | The following list of commands re-indent C constructs. Note that when |
| 1135 | @vindex progress-interval (c-) | 1438 | you change your coding style, either interactively or through some other |
| 1136 | Third, re-indenting large portions of code is currently rather | 1439 | means, your file does @emph{not} automatically get re-indented. You |
| 1137 | inefficient. Improvements have been made since previous releases of | 1440 | will need to execute one of the following commands to see the effects of |
| 1138 | @ccmode{}, and much more radical improvements are planned, but for now | 1441 | your changes. |
| 1139 | you need to be aware of this @footnote{In particular, I have had people | 1442 | |
| 1443 | @cindex GNU indent program | ||
| 1444 | Also, variables like @code{c-hanging-*} and @code{c-cleanup-list} | ||
| 1445 | only affect how on-the-fly code is formatted. Changing the | ||
| 1446 | ``hanginess'' of a brace and then re-indenting, will not move the brace | ||
| 1447 | to a different line. For this, you're better off getting an external | ||
| 1448 | program like GNU @code{indent}, which will re-arrange brace location, | ||
| 1449 | among other things. | ||
| 1450 | |||
| 1451 | Re-indenting large sections of code can take a long time. When | ||
| 1452 | @ccmode{} reindents a region of code, it is essentially equivalent to | ||
| 1453 | hitting @kbd{TAB} on every line of the region. Especially vulnerable is | ||
| 1454 | code generator output@footnote{In particular, I have had people | ||
| 1140 | complain about the speed with which @code{lex(1)} output is re-indented. | 1455 | complain about the speed with which @code{lex(1)} output is re-indented. |
| 1141 | Lex, yacc, and other code generators usually output some pretty | 1456 | Lex, yacc, and other code generators usually output some pretty |
| 1142 | perversely formatted code. @emph{Don't} try to indent this stuff!}. | 1457 | perversely formatted code. Re-indenting such code will be slow.}. |
| 1143 | Some provision has been made to at least inform you as to the progress | 1458 | |
| 1144 | of the re-indentation. The variable @code{c-progress-interval} controls | 1459 | These commands are useful when indenting code: |
| 1145 | how often a progress message is displayed. Set this variable to | ||
| 1146 | @code{nil} to inhibit progress messages, including messages normally | ||
| 1147 | printed when indentation is started and completed. | ||
| 1148 | 1460 | ||
| 1149 | Also, except as noted below, re-indentation is always driven by the | 1461 | @table @asis |
| 1150 | same mechanisms that control on-the-fly indentation of code. @xref{New | ||
| 1151 | Indentation Engine}, for details. | ||
| 1152 | 1462 | ||
| 1463 | @kindex TAB | ||
| 1153 | @findex c-indent-command | 1464 | @findex c-indent-command |
| 1154 | @findex indent-command (c-) | 1465 | @findex indent-command (c-) |
| 1155 | @vindex c-tab-always-indent | 1466 | @item @kbd{TAB} (@code{c-indent-command}) |
| 1156 | @vindex tab-always-indent (c-) | 1467 | Indents the current line. The actual behavior is controlled by several |
| 1157 | @kindex TAB | 1468 | variables, described below. See @code{c-tab-always-indent}, |
| 1158 | @cindex literal | 1469 | @code{c-insert-tab-function}, and @code{indent-tabs-mode}. With a |
| 1159 | @vindex indent-tabs-mode | 1470 | numeric argument, this command rigidly indents the region, preserving |
| 1160 | @vindex c-insert-tab-function | 1471 | the relative indentation among the lines. |
| 1161 | @vindex insert-tab-function (c-) | ||
| 1162 | @findex tab-to-tab-stop | ||
| 1163 | To indent a single line of code, use @kbd{TAB} | ||
| 1164 | (@code{c-indent-command}). The behavior of this command is controlled | ||
| 1165 | by the variable @code{c-tab-always-indent}. When this variable is | ||
| 1166 | @code{t}, @kbd{TAB} always just indents the current line. When | ||
| 1167 | @code{nil}, the line is indented only if point is at the left margin, or | ||
| 1168 | on or before the first non-whitespace character on the line, otherwise | ||
| 1169 | @emph{something else happens}@footnote{Actually what happens is that the | ||
| 1170 | function stored in @code{c-insert-tab-function} is called. | ||
| 1171 | Normally this just inserts a real tab character, or the equivalent | ||
| 1172 | number of spaces, depending on the setting of the variable | ||
| 1173 | @code{indent-tabs-mode}. If you preferred, you could set | ||
| 1174 | @code{c-insert-tab-function} to @code{tab-to-tab-stop} for example.}. | ||
| 1175 | If the value of @code{c-tab-always-indent} is something other than | ||
| 1176 | @code{t} or @code{nil} (e.g. @code{'other}), then a real tab | ||
| 1177 | character@footnote{The caveat about @code{indent-tabs-mode} in the | ||
| 1178 | previous footnote also applies here.} is inserted only when point is | ||
| 1179 | inside a literal (see @ref{Auto-newline insertion}), otherwise the line | ||
| 1180 | is indented. | ||
| 1181 | 1472 | ||
| 1182 | @kindex M-C-q | 1473 | @kindex M-C-q |
| 1183 | @findex c-indent-exp | 1474 | @findex c-indent-exp |
| 1184 | @findex indent-exp (c-) | 1475 | @findex indent-exp (c-) |
| 1185 | To indent an entire balanced brace or parenthesis expression, use | 1476 | @item @kbd{M-C-q} (@code{c-indent-exp}) |
| 1186 | @kbd{M-C-q} (@code{c-indent-exp}). Note that point should be on | 1477 | Indent an entire balanced brace or parenthesis expression. Note that |
| 1187 | the opening brace or parenthesis of the expression you want to indent. | 1478 | point must be on the opening brace or parenthesis of the expression you |
| 1479 | want to indent. | ||
| 1188 | 1480 | ||
| 1189 | @kindex C-c C-q | 1481 | @kindex C-c C-q |
| 1190 | @findex c-indent-defun | 1482 | @findex c-indent-defun |
| 1191 | @findex indent-defun (c-) | 1483 | @findex indent-defun (c-) |
| 1192 | Another very convenient keystroke is @kbd{C-c C-q} | 1484 | @item @kbd{C-c C-q} (@code{c-indent-defun}) |
| 1193 | (@code{c-indent-defun}) when re-indents the entire top-level function or | 1485 | Indents the entire top-level function or class definition encompassing |
| 1194 | class definition that encompasses point. It leaves point at the | 1486 | point. It leaves point unchanged. This function can't be used to |
| 1195 | same position within the buffer. | 1487 | re-indent a nested brace construct, such as a nested class or function, |
| 1488 | or a Java method. The top-level construct being re-indented must be | ||
| 1489 | complete, i.e. it must have both a beginning brace and an ending brace. | ||
| 1196 | 1490 | ||
| 1197 | @kindex M-C-\ | 1491 | @kindex M-C-\ |
| 1198 | @findex indent-region | 1492 | @findex indent-region |
| 1199 | To indent any arbitrary region of code, use @kbd{M-C-\} | 1493 | @item @kbd{M-C-\} (@code{indent-region}) |
| 1200 | (@code{indent-region}). This is a standard Emacs command, specially | 1494 | Indents an arbitrary region of code. This is a standard Emacs command, |
| 1201 | tailored for C code in a @ccmode{} buffer. Note that of course, | 1495 | tailored for C code in a @ccmode{} buffer. Note that of course, point |
| 1202 | point and mark must delineate the region you | 1496 | and mark must delineate the region you want to indent. |
| 1203 | want to indent. | ||
| 1204 | 1497 | ||
| 1205 | @kindex M-C-h | 1498 | @kindex M-C-h |
| 1206 | @findex c-mark-function | 1499 | @findex c-mark-function |
| 1207 | @findex mark-function (c-) | 1500 | @findex mark-function (c-) |
| 1208 | While not strictly an indentation function, @kbd{M-C-h} | 1501 | @item @kbd{M-C-h} (@code{c-mark-function}) |
| 1209 | (@code{c-mark-function}) is useful for marking the current top-level | 1502 | While not strictly an indentation command, this is useful for marking |
| 1210 | function or class definition as the current region. | 1503 | the current top-level function or class definition as the current |
| 1504 | region. As with @code{c-indent-defun}, this command operates on | ||
| 1505 | top-level constructs, and can't be used to mark say, a Java method. | ||
| 1506 | |||
| 1507 | @end table | ||
| 1508 | |||
| 1509 | These variables are also useful when indenting code: | ||
| 1510 | |||
| 1511 | @table @code | ||
| 1512 | |||
| 1513 | @vindex c-tab-always-indent | ||
| 1514 | @vindex tab-always-indent (c-) | ||
| 1515 | @kindex TAB | ||
| 1516 | @cindex literal | ||
| 1517 | @item c-tab-always-indent | ||
| 1518 | This variable controls how @kbd{TAB} @code{c-indent-command} operates. | ||
| 1519 | When this variable is @code{t}, @kbd{TAB} always just indents the | ||
| 1520 | current line. When it is @code{nil}, the line is indented only if point | ||
| 1521 | is at the left margin, or on or before the first non-whitespace | ||
| 1522 | character on the line, otherwise some whitespace is inserted. If this | ||
| 1523 | variable is the symbol @code{other}, then some whitespace is inserted | ||
| 1524 | only within strings and comments (literals), an inside preprocessor | ||
| 1525 | directives, but the line is always reindented. | ||
| 1526 | |||
| 1527 | @vindex c-insert-tab-function | ||
| 1528 | @vindex insert-tab-function (c-) | ||
| 1529 | @findex tab-to-tab-stop | ||
| 1530 | @item c-insert-tab-function | ||
| 1531 | When ``some whitespace'' is inserted as described above, what actually | ||
| 1532 | happens is that the function stored in @code{c-insert-tab-function} is | ||
| 1533 | called. Normally, this just inserts a real tab character, or the | ||
| 1534 | equivalent number of spaces, depending on @code{indent-tabs-mode}. | ||
| 1535 | Some people, however, set @code{c-insert-tab-function} to | ||
| 1536 | @code{tab-to-tab-stop} so as to get hard tab stops when indenting. | ||
| 1537 | |||
| 1538 | @vindex indent-tabs-mode | ||
| 1539 | @item indent-tabs-mode | ||
| 1540 | This is a standard Emacs variable that controls how line indentation is | ||
| 1541 | composed. When this variable is non-@code{nil}, then tabs can be used | ||
| 1542 | in a line's indentation, otherwise only spaces can be used. | ||
| 1543 | |||
| 1544 | @vindex c-progress-interval | ||
| 1545 | @vindex progress-interval (c-) | ||
| 1546 | @item c-progress-interval | ||
| 1547 | When indenting large regions of code, this variable controls how often a | ||
| 1548 | progress message is displayed. Set this variable to @code{nil} to | ||
| 1549 | inhibit the progress messages, or set it to an integer which is the | ||
| 1550 | interval in seconds that progress messages are displayed. | ||
| 1551 | |||
| 1552 | @end table | ||
| 1211 | 1553 | ||
| 1212 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| 1213 | @node Other Commands, , Indentation Commands, Commands | ||
| 1214 | @comment node-name, next, previous,up | ||
| 1215 | 1554 | ||
| 1216 | @section Other Commands | 1555 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 1217 | @cindex Other Commands | 1556 | @node Movement Commands, Other Commands, Indentation Commands, Commands |
| 1557 | @comment node-name, next, previous, up | ||
| 1558 | @section Movement Commands | ||
| 1559 | @cindex movement commands | ||
| 1218 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 1560 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 1219 | 1561 | ||
| 1220 | @ccmode{} contains other useful command for moving around in C | 1562 | @ccmode{} contains some useful command for moving around in C |
| 1221 | code. | 1563 | code. |
| 1222 | 1564 | ||
| 1223 | @table @code | 1565 | @table @asis |
| 1566 | |||
| 1224 | @findex c-beginning-of-defun | 1567 | @findex c-beginning-of-defun |
| 1225 | @findex beginning-of-defun (c-) | 1568 | @findex beginning-of-defun (c-) |
| 1226 | @findex beginning-of-defun | 1569 | @findex beginning-of-defun |
| 1227 | @item M-x c-beginning-of-defun | 1570 | @item @kbd{M-x c-beginning-of-defun} |
| 1228 | Moves point back to the least-enclosing brace. This function is | 1571 | Moves point back to the least-enclosing brace. This function is |
| 1229 | analogous to the Emacs built-in command @code{beginning-of-defun}, | 1572 | analogous to the Emacs built-in command @code{beginning-of-defun}, |
| 1230 | except it eliminates the constraint that the top-level opening brace | 1573 | except it eliminates the constraint that the top-level opening brace |
| @@ -1239,7 +1582,7 @@ compatibility reasons, the default binding remains in effect. | |||
| 1239 | @findex c-end-of-defun | 1582 | @findex c-end-of-defun |
| 1240 | @findex end-of-defun (c-) | 1583 | @findex end-of-defun (c-) |
| 1241 | @findex end-of-defun | 1584 | @findex end-of-defun |
| 1242 | @item M-x c-end-of-defun | 1585 | @item @kbd{M-x c-end-of-defun} |
| 1243 | Moves point to the end of the current top-level definition. This | 1586 | Moves point to the end of the current top-level definition. This |
| 1244 | function is analogous to the Emacs built-in command @code{end-of-defun}, | 1587 | function is analogous to the Emacs built-in command @code{end-of-defun}, |
| 1245 | except it eliminates the constraint that the top-level opening brace of | 1588 | except it eliminates the constraint that the top-level opening brace of |
| @@ -1254,18 +1597,42 @@ compatibility reasons, the default binding remains in effect. | |||
| 1254 | @kindex C-c C-u | 1597 | @kindex C-c C-u |
| 1255 | @findex c-up-conditional | 1598 | @findex c-up-conditional |
| 1256 | @findex up-conditional (c-) | 1599 | @findex up-conditional (c-) |
| 1257 | @item C-c C-u (c-up-conditional) | 1600 | @item @kbd{C-c C-u} (@code{c-up-conditional}) |
| 1258 | Move point back to the containing preprocessor conditional, leaving the | 1601 | Move point back to the containing preprocessor conditional, leaving the |
| 1259 | mark behind. A prefix argument acts as a repeat count. With a negative | 1602 | mark behind. A prefix argument acts as a repeat count. With a negative |
| 1260 | argument, move point forward to the end of the containing | 1603 | argument, move point forward to the end of the containing |
| 1261 | preprocessor conditional. When going backwards, @code{#elif} is treated | 1604 | preprocessor conditional. |
| 1262 | like @code{#else} followed by @code{#if}. When going forwards, | 1605 | |
| 1263 | @code{#elif} is ignored.@refill | 1606 | @samp{#elif} is treated like @samp{#else} followed by @samp{#if}, so the |
| 1607 | function stops at them when going backward, but not when going forward. | ||
| 1608 | |||
| 1609 | @findex c-up-conditional-with-else | ||
| 1610 | @findex up-conditional-with-else (c-) | ||
| 1611 | @item @kbd{M-x c-up-conditional-with-else} | ||
| 1612 | A variety of @code{c-up-conditional} that also stops at @samp{#else} | ||
| 1613 | lines. Normally those lines are ignored. | ||
| 1614 | |||
| 1615 | @findex c-down-conditional | ||
| 1616 | @findex down-conditional (c-) | ||
| 1617 | @item @kbd{M-x c-down-conditional} | ||
| 1618 | Move point forward into the next nested preprocessor conditional, | ||
| 1619 | leaving the mark behind. A prefix argument acts as a repeat count. | ||
| 1620 | With a negative argument, move point backward into the previous | ||
| 1621 | nested preprocessor conditional. | ||
| 1622 | |||
| 1623 | @samp{#elif} is treated like @samp{#else} followed by @samp{#if}, so the | ||
| 1624 | function stops at them when going forward, but not when going backward. | ||
| 1625 | |||
| 1626 | @findex c-down-conditional-with-else | ||
| 1627 | @findex down-conditional-with-else (c-) | ||
| 1628 | @item @kbd{M-x c-down-conditional-with-else} | ||
| 1629 | A variety of @code{c-down-conditional} that also stops at @samp{#else} | ||
| 1630 | lines. Normally those lines are ignored. | ||
| 1264 | 1631 | ||
| 1265 | @kindex C-c C-p | 1632 | @kindex C-c C-p |
| 1266 | @findex c-backward-conditional | 1633 | @findex c-backward-conditional |
| 1267 | @findex backward-conditional (c-) | 1634 | @findex backward-conditional (c-) |
| 1268 | @item C-c C-p (c-backward-conditional) | 1635 | @item @kbd{C-c C-p} (@code{c-backward-conditional}) |
| 1269 | Move point back over a preprocessor conditional, leaving the mark | 1636 | Move point back over a preprocessor conditional, leaving the mark |
| 1270 | behind. A prefix argument acts as a repeat count. With a negative | 1637 | behind. A prefix argument acts as a repeat count. With a negative |
| 1271 | argument, move forward. | 1638 | argument, move forward. |
| @@ -1273,15 +1640,15 @@ argument, move forward. | |||
| 1273 | @kindex C-c C-n | 1640 | @kindex C-c C-n |
| 1274 | @findex c-forward-conditional | 1641 | @findex c-forward-conditional |
| 1275 | @findex forward-conditional (c-) | 1642 | @findex forward-conditional (c-) |
| 1276 | @item C-c C-n (c-forward-conditional) | 1643 | @item @kbd{C-c C-n} (@code{c-forward-conditional}) |
| 1277 | Move point forward across a preprocessor conditional, leaving the mark | 1644 | Move point forward across a preprocessor conditional, leaving the mark |
| 1278 | behind. A prefix argument acts as a repeat count. With a negative | 1645 | behind. A prefix argument acts as a repeat count. With a negative |
| 1279 | argument, move backward. | 1646 | argument, move backward. |
| 1280 | 1647 | ||
| 1281 | @kindex ESC a | 1648 | @kindex M-a |
| 1282 | @findex c-beginning-of-statement | 1649 | @findex c-beginning-of-statement |
| 1283 | @findex beginning-of-statement (c-) | 1650 | @findex beginning-of-statement (c-) |
| 1284 | @item M-a (c-beginning-of-statement) | 1651 | @item @kbd{M-a} (@code{c-beginning-of-statement}) |
| 1285 | Move point to the beginning of the innermost C statement. If point is | 1652 | Move point to the beginning of the innermost C statement. If point is |
| 1286 | already at the beginning of a statement, it moves to the beginning of | 1653 | already at the beginning of a statement, it moves to the beginning of |
| 1287 | the closest preceding statement, even if that means moving into a block | 1654 | the closest preceding statement, even if that means moving into a block |
| @@ -1292,15 +1659,14 @@ If point is within a comment, or next to a comment, this command moves | |||
| 1292 | by sentences instead of statements. | 1659 | by sentences instead of statements. |
| 1293 | 1660 | ||
| 1294 | When called from a program, this function takes three optional | 1661 | When called from a program, this function takes three optional |
| 1295 | arguments: the numeric prefix argument, a buffer position limit (used as | 1662 | arguments: the numeric prefix argument, a buffer position limit which is |
| 1296 | a starting point for syntactic parsing and as a limit for backward | 1663 | the farthest back to search, and a flag to enable moving by sentence |
| 1297 | movement), and a flag to indicate whether movement should be by | 1664 | inside comments. |
| 1298 | statements (if @code{nil}) or sentence (if non-@code{nil}). | ||
| 1299 | 1665 | ||
| 1300 | @kindex ESC e | 1666 | @kindex M-e |
| 1301 | @findex c-end-of-statement | 1667 | @findex c-end-of-statement |
| 1302 | @findex end-of-statement (c-) | 1668 | @findex end-of-statement (c-) |
| 1303 | @item M-e (c-end-of-statement) | 1669 | @item @kbd{M-e} (@code{c-end-of-statement}) |
| 1304 | Move point to the end of the innermost C statement. If point is at the | 1670 | Move point to the end of the innermost C statement. If point is at the |
| 1305 | end of a statement, move to the end of the next statement, even if it's | 1671 | end of a statement, move to the end of the next statement, even if it's |
| 1306 | inside a nested block (use @kbd{M-C-f} to move to the other side of the | 1672 | inside a nested block (use @kbd{M-C-f} to move to the other side of the |
| @@ -1311,14 +1677,13 @@ If point is within a comment, or next to a comment, this command moves | |||
| 1311 | by sentences instead of statements. | 1677 | by sentences instead of statements. |
| 1312 | 1678 | ||
| 1313 | When called from a program, this function takes three optional | 1679 | When called from a program, this function takes three optional |
| 1314 | arguments: the numeric prefix argument, a buffer position limit (used as | 1680 | arguments: the numeric prefix argument, a buffer position limit which is |
| 1315 | a starting point for syntactic parsing and as a limit for backward | 1681 | the farthest back to search, and a flag to enable moving by sentence |
| 1316 | movement), and a flag to indicate whether movement should be by | 1682 | inside comments. |
| 1317 | statements (if @code{nil}) or sentence (if non-@code{nil}). | ||
| 1318 | 1683 | ||
| 1319 | @findex c-forward-into-nomenclature | 1684 | @findex c-forward-into-nomenclature |
| 1320 | @findex forward-into-nomenclature (c-) | 1685 | @findex forward-into-nomenclature (c-) |
| 1321 | @item M-x c-forward-into-nomenclature | 1686 | @item @kbd{M-x c-forward-into-nomenclature} |
| 1322 | A popular programming style, especially for object-oriented languages | 1687 | A popular programming style, especially for object-oriented languages |
| 1323 | such as C++ is to write symbols in a mixed case format, where the first | 1688 | such as C++ is to write symbols in a mixed case format, where the first |
| 1324 | letter of each word is capitalized, and not separated by underscores. | 1689 | letter of each word is capitalized, and not separated by underscores. |
| @@ -1329,94 +1694,98 @@ argument @var{n}, move @var{n} times. | |||
| 1329 | 1694 | ||
| 1330 | @findex c-backward-into-nomenclature | 1695 | @findex c-backward-into-nomenclature |
| 1331 | @findex backward-into-nomenclature (c-) | 1696 | @findex backward-into-nomenclature (c-) |
| 1332 | @item M-x c-backward-into-nomenclature | 1697 | @item @kbd{M-x c-backward-into-nomenclature} |
| 1333 | Move point backward to beginning of the next capitalized | 1698 | Move point backward to beginning of the next capitalized |
| 1334 | word. With prefix argument @var{n}, move @var{n} times. If | 1699 | word. With prefix argument @var{n}, move @var{n} times. If |
| 1335 | @var{n} is negative, move forward. | 1700 | @var{n} is negative, move forward. |
| 1336 | 1701 | ||
| 1702 | @end table | ||
| 1703 | |||
| 1704 | |||
| 1705 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| 1706 | @node Other Commands, , Movement Commands, Commands | ||
| 1707 | @comment node-name, next, previous, up | ||
| 1708 | @section Other Commands | ||
| 1709 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| 1710 | |||
| 1711 | @ccmode{} contains a few other useful commands: | ||
| 1712 | |||
| 1713 | @table @asis | ||
| 1714 | |||
| 1337 | @kindex C-c : | 1715 | @kindex C-c : |
| 1338 | @findex c-scope-operator | 1716 | @findex c-scope-operator |
| 1339 | @findex scope-operator (c-) | 1717 | @findex scope-operator (c-) |
| 1340 | @item C-c : (c-scope-operator) | 1718 | @item @kbd{C-c :} (@code{c-scope-operator}) |
| 1341 | In C++, it is also sometimes desirable to insert the double-colon scope | 1719 | In C++, it is also sometimes desirable to insert the double-colon scope |
| 1342 | operator without performing the electric behavior of colon insertion. | 1720 | operator without performing the electric behavior of colon insertion. |
| 1343 | @kbd{C-c :} does just this. | 1721 | @kbd{C-c :} does just this. |
| 1344 | 1722 | ||
| 1345 | @kindex ESC q | 1723 | @kindex C-c C-\ |
| 1346 | @findex fill-paragraph | 1724 | @findex c-backslash-region |
| 1347 | @vindex c-hanging-comment-starter-p | 1725 | @findex backslash-region (c-) |
| 1348 | @vindex c-hanging-comment-ender-p | 1726 | @item @kbd{C-c C-\} (@code{c-backslash-region}) |
| 1349 | @vindex hanging-comment-starter-p (c-) | 1727 | This function is handy when editing macros split over several lines by |
| 1350 | @vindex hanging-comment-ender-p (c-) | 1728 | ending each line with a backslash. It inserts and aligns, or deletes |
| 1351 | @item M-q (fill-paragraph) | 1729 | these end-of-line backslashes in the current region. |
| 1352 | The command is used to fill a block style (C) or line style (C++) | 1730 | |
| 1353 | comment, in much the same way that text in the various text modes can be | 1731 | @vindex c-backslash-column |
| 1354 | filled@footnote{You should not use specialized filling packages such as | 1732 | @vindex backslash-column (c-) |
| 1355 | @code{filladapt} with CC Mode. They don't work as well for filling as | 1733 | With no prefix argument, it inserts any missing backslashes and aligns |
| 1356 | @code{c-fill-paragraph}}. You should never attempt to fill non-comment | 1734 | them to the column specified by the @code{c-backslash-column} style |
| 1357 | code sections; you'll end up with garbage! Two variables control how C | 1735 | variable. With a prefix argument, it deletes any backslashes. |
| 1358 | style block comments are filled, specifically how the comment start and | 1736 | |
| 1359 | end delimiters are handled. | 1737 | The function does not modify blank lines at the start of the region. If |
| 1360 | 1738 | the region ends at the start of a line, it always deletes the backslash | |
| 1361 | The variable @code{c-hanging-comment-starter-p} controls whether comment | 1739 | (if any) at the end of the previous line. |
| 1362 | start delimiters which appear on a line by themselves, end up on a line | ||
| 1363 | by themselves after the fill. When the value is @code{nil}, the comment | ||
| 1364 | starter will remain on its own line@footnote{It will not be placed on a | ||
| 1365 | separate line if it is not already on a separate line.}. Otherwise, | ||
| 1366 | text on the next line will be put on the same line as the comment | ||
| 1367 | starter. This is called @dfn{hanging} because the following text hangs | ||
| 1368 | on the line with the comment starter@footnote{This variable is @code{t} | ||
| 1369 | by default, except in @code{java-mode}. Hanging comment starters mess | ||
| 1370 | up Javadoc style comments.} | ||
| 1371 | |||
| 1372 | The variable @code{c-hanging-comment-ender-p} controls the analogous | ||
| 1373 | behavior for the block comment end delimiter. When the value is | ||
| 1374 | @code{nil}, the comment ender will remain on its own line after the | ||
| 1375 | file@footnote{The same caveat as above holds true.}. Otherwise, the | ||
| 1376 | comment end delimiter will be placed at the end of the previous line. | ||
| 1377 | 1740 | ||
| 1378 | @end table | 1741 | @end table |
| 1379 | 1742 | ||
| 1380 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| 1381 | @node Customizing Indentation, Syntactic Symbols, Commands, Top | ||
| 1382 | @comment node-name, next, previous,up | ||
| 1383 | 1743 | ||
| 1384 | @chapter Customizing Indentation | 1744 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 1385 | @cindex Customizing Indentation | 1745 | @node Customizing Indentation, Syntactic Symbols, Commands, Top |
| 1746 | @comment node-name, next, previous, up | ||
| 1747 | @chapter Customizing Indentation | ||
| 1748 | @cindex customizing indentation | ||
| 1386 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 1749 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 1387 | 1750 | ||
| 1388 | @vindex c-offsets-alist | 1751 | @vindex c-offsets-alist |
| 1389 | @vindex offsets-alist (c-) | 1752 | @vindex offsets-alist (c-) |
| 1390 | @cindex c-set-offset | 1753 | The style variable @code{c-offsets-alist} contains the mappings between |
| 1391 | @cindex set-offset (c-) | 1754 | syntactic symbols and the offsets to apply for those symbols. It's set |
| 1392 | The variable @code{c-offsets-alist} contains the mappings between | 1755 | at mode initialization from a @emph{style} you may specify. Styles are |
| 1393 | syntactic symbols and the offsets to apply for those symbols. You | 1756 | groupings of syntactic symbol offsets and other style variable values. |
| 1394 | should never modify this variable directly though. Use the function | 1757 | Most likely, you'll find that one of the pre-defined styles will suit |
| 1395 | @code{c-set-offset} instead (see below for details). | 1758 | your needs. @xref{Styles}, for an explanation of how to set up named |
| 1396 | 1759 | styles. | |
| 1397 | The @code{c-offsets-alist} variable is where you customize all your | 1760 | |
| 1398 | indentations. You simply need to decide what additional offset you want | 1761 | Only syntactic symbols not already bound on @code{c-offsets-alist} will |
| 1399 | to add for every syntactic symbol. You can use the command @kbd{C-c | 1762 | be set from styles. This means that any association you set on it, be |
| 1400 | C-o} (@code{c-set-offset}) as the way to set offsets, both interactively | 1763 | it before or after mode initialization, will not be changed. The |
| 1401 | and from your mode hook. Also, you can set up @emph{styles} of | 1764 | @code{c-offsets-alist} variable may therefore be used from e.g. the |
| 1402 | indentatio. Most likely, you'll | 1765 | Customization interface@footnote{Available in Emacs 20 and later, and |
| 1403 | find one of the pre-defined styles will suit your needs, but if not, | 1766 | XEmacs 19.15 and later.} to easily change indentation offsets without |
| 1404 | this section will describe how to set up basic editing configurations. | 1767 | having to bother about styles. Initially @code{c-offsets-alist} is |
| 1405 | @xref{Styles}, for an explanation of how to set up named styles. | 1768 | empty, so that all syntactic symbols are set by the style system. |
| 1406 | 1769 | ||
| 1407 | @cindex c-basic-offset | 1770 | @kindex C-c C-o |
| 1408 | @cindex basic-offset (c-) | 1771 | @findex c-set-offset |
| 1409 | As mentioned previously, the variable @code{c-offsets-alist} is an | 1772 | @findex set-offset (c-) |
| 1410 | association list of syntactic symbols and the offsets to be applied for | 1773 | You can use the command @kbd{C-c C-o} (@code{c-set-offset}) as the way |
| 1411 | those symbols. In fact, these offset values can be any of an integer, a | 1774 | to set offsets, both interactively and from your mode |
| 1412 | function or lambda expression, a variable name, or one of the following | 1775 | hook@footnote{Obviously, you use the keybinding interactively, and the |
| 1413 | symbols: @code{+}, @code{-}, @code{++}, @code{--}, @code{*}, or | 1776 | function call programmatically!}. |
| 1414 | @code{/}. These symbols describe offset in multiples of the value of | 1777 | |
| 1415 | the variable @code{c-basic-offset}. By defining a style's indentation | 1778 | @vindex c-basic-offset |
| 1416 | in terms of this fundamental variable, you can change the amount of | 1779 | @vindex basic-offset (c-) |
| 1417 | whitespace given to an indentation level while leaving the same | 1780 | The offset associated with any particular syntactic symbol can be any of |
| 1418 | relationship between levels. Here are the values that the special | 1781 | an integer, a function or lambda expression, a variable name, or one of |
| 1419 | symbols correspond to: | 1782 | the following symbols: @code{+}, @code{-}, @code{++}, @code{--}, |
| 1783 | @code{*}, or @code{/}. These latter describe offset in multiples of the | ||
| 1784 | value of the style variable @code{c-basic-offset}. By defining a | ||
| 1785 | style's indentation in terms of this fundamental variable, you can | ||
| 1786 | change the amount of whitespace given to an indentation level while | ||
| 1787 | maintaining the same basic shape of your code. Here are the values that | ||
| 1788 | the special symbols correspond to: | ||
| 1420 | 1789 | ||
| 1421 | @table @code | 1790 | @table @code |
| 1422 | 1791 | ||
| @@ -1435,17 +1804,38 @@ symbols correspond to: | |||
| 1435 | 1804 | ||
| 1436 | @end table | 1805 | @end table |
| 1437 | 1806 | ||
| 1438 | @vindex c-style-variables-are-local-p | 1807 | @cindex indentation functions |
| 1439 | @vindex style-variables-are-local-p (c-) | 1808 | |
| 1440 | @noindent | 1809 | When a function is used as offset, it's called an @dfn{indentation |
| 1810 | function}. Such functions are useful when more context than just the | ||
| 1811 | syntactic symbol is needed to get the desired indentation. | ||
| 1812 | @xref{Indentation Functions}, and @ref{Custom Indentation Functions}, | ||
| 1813 | for details about them. | ||
| 1814 | |||
| 1815 | @vindex c-strict-syntax-p | ||
| 1816 | @vindex strict-syntax-p (c-) | ||
| 1817 | The offset can also be a list, in which case it is evaluated recursively | ||
| 1818 | using the semantics described above. The first element of the list that | ||
| 1819 | returns a non-@code{nil} value succeeds and the evaluation stops. If | ||
| 1820 | none of the list elements return a non-@code{nil} value, then an offset | ||
| 1821 | of 0 (zero) is used@footnote{There is however a variable | ||
| 1822 | @code{c-strict-syntax-p} that, when set to non-@code{nil}, will cause an | ||
| 1823 | error to be signalled in that case. It's now considered obsolete since | ||
| 1824 | it doesn't work well with some of the alignment functions that now | ||
| 1825 | returns @code{nil} instead of zero to be more usable in lists. You | ||
| 1826 | should therefore leave @code{c-strict-syntax-p} set to @code{nil}.}. | ||
| 1827 | |||
| 1441 | So, for example, because most of the default offsets are defined in | 1828 | So, for example, because most of the default offsets are defined in |
| 1442 | terms of @code{+}, @code{-}, and @code{0}, if you like the general | 1829 | terms of @code{+}, @code{-}, and @code{0}, if you like the general |
| 1443 | indentation style, but you use 4 spaces instead of 2 spaces per level, | 1830 | indentation style, but you use 4 spaces instead of 2 spaces per level, |
| 1444 | you can probably achieve your style just by changing | 1831 | you can probably achieve your style just by changing |
| 1445 | @code{c-basic-offset} like so (in your @file{.emacs} file): | 1832 | @code{c-basic-offset} like so@footnote{You can try this interactively in |
| 1833 | a C buffer by typing the text that appears in italics.}: | ||
| 1446 | @example | 1834 | @example |
| 1447 | 1835 | ||
| 1448 | (setq c-basic-offset 4) | 1836 | @emph{M-x set-variable RET} |
| 1837 | Set variable: @emph{c-basic-offset RET} | ||
| 1838 | Set c-basic-offset to value: @emph{4 RET} | ||
| 1449 | 1839 | ||
| 1450 | @end example | 1840 | @end example |
| 1451 | 1841 | ||
| @@ -1482,32 +1872,31 @@ int add( int val, int incr, int doit ) | |||
| 1482 | @end group | 1872 | @end group |
| 1483 | @end example | 1873 | @end example |
| 1484 | 1874 | ||
| 1485 | |||
| 1486 | To change indentation styles more radically, you will want to change the | 1875 | To change indentation styles more radically, you will want to change the |
| 1487 | value associated with the syntactic symbols in the | 1876 | offsets associated with other syntactic symbols. First, I'll show you |
| 1488 | @code{c-offsets-alist} variable. First, I'll show you how to do that | 1877 | how to do that interactively, then I'll describe how to make changes to |
| 1489 | interactively, then I'll describe how to make changes to your | 1878 | your @file{.emacs} file so that your changes are more permanent. |
| 1490 | @file{.emacs} file so that your changes are more permanent. | ||
| 1491 | 1879 | ||
| 1492 | @menu | 1880 | @menu |
| 1493 | * Interactive Customization:: | 1881 | * Interactive Customization:: |
| 1494 | * Permanent Customization:: | 1882 | * Permanent Customization:: |
| 1883 | * Hooks:: | ||
| 1495 | * Styles:: | 1884 | * Styles:: |
| 1496 | * Advanced Customizations:: | 1885 | * Advanced Customizations:: |
| 1497 | @end menu | 1886 | @end menu |
| 1498 | 1887 | ||
| 1499 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| 1500 | @node Interactive Customization, Permanent Customization, , Customizing Indentation | ||
| 1501 | @comment node-name, next, previous,up | ||
| 1502 | 1888 | ||
| 1503 | @section Interactive Customization | 1889 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 1504 | @cindex Interactive Customization | 1890 | @node Interactive Customization, Permanent Customization, , Customizing Indentation |
| 1891 | @comment node-name, next, previous, up | ||
| 1892 | @section Interactive Customization | ||
| 1893 | @cindex interactive customization | ||
| 1505 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 1894 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 1506 | 1895 | ||
| 1507 | As an example of how to customize indentation, let's change the | 1896 | As an example of how to customize indentation, let's change the |
| 1508 | style of this example@footnote{In this an subsequent examples, the | 1897 | style of this example@footnote{In this an subsequent examples, the |
| 1509 | original code is formatted using the @samp{gnu} style unless otherwise | 1898 | original code is formatted using the @samp{gnu} style unless otherwise |
| 1510 | indicated. @xref{Styles}.}: | 1899 | indicated. @xref{Styles}.}: |
| 1511 | @example | 1900 | @example |
| 1512 | @group | 1901 | @group |
| 1513 | 1902 | ||
| @@ -1551,28 +1940,20 @@ for that line. Hitting @kbd{C-c C-s} on line 4 yields: | |||
| 1551 | 1940 | ||
| 1552 | @end example | 1941 | @end example |
| 1553 | 1942 | ||
| 1554 | @findex c-set-offset | ||
| 1555 | @findex set-offset (c-) | ||
| 1556 | @kindex C-c C-o | ||
| 1557 | @noindent | 1943 | @noindent |
| 1558 | so we know that to change the offset of the open brace, we need to | 1944 | so we know that to change the offset of the open brace, we need to |
| 1559 | change the indentation for the @code{substatement-open} syntactic | 1945 | change the indentation for the @code{substatement-open} syntactic |
| 1560 | symbol. To do this interactively, just hit @kbd{C-c C-o} | 1946 | symbol. To do this interactively, just hit @kbd{C-c C-o}. This prompts |
| 1561 | (@code{c-set-offset}). This prompts you for the syntactic symbol to | 1947 | you for the syntactic symbol to change, providing a reasonable default. |
| 1562 | change, providing a reasonable default. In this case, the default is | 1948 | In this case, the default is @code{substatement-open}, which is just the |
| 1563 | @code{substatement-open}, which is just the syntactic symbol we want to | 1949 | syntactic symbol we want to change! |
| 1564 | change! | ||
| 1565 | 1950 | ||
| 1566 | After you hit return, @ccmode{} will then prompt you for the new | 1951 | After you hit return, @ccmode{} will then prompt you for the new |
| 1567 | offset value, with the old value as the default. The default in this | 1952 | offset value, with the old value as the default. The default in this |
| 1568 | case is @samp{+}, but we want no extra indentation so enter | 1953 | case is @samp{+}, but we want no extra indentation so enter |
| 1569 | @samp{0} and @kbd{RET}. This will associate the offset 0 with the | 1954 | @samp{0} and @kbd{RET}. This will associate the offset 0 with the |
| 1570 | syntactic symbol @code{substatement-open} in the @code{c-offsets-alist} | 1955 | syntactic symbol @code{substatement-open}. |
| 1571 | variable. | ||
| 1572 | 1956 | ||
| 1573 | @findex c-indent-defun | ||
| 1574 | @findex indent-defun (c-) | ||
| 1575 | @kindex C-c C-q | ||
| 1576 | To check your changes quickly, just hit @kbd{C-c C-q} | 1957 | To check your changes quickly, just hit @kbd{C-c C-q} |
| 1577 | (@code{c-indent-defun}) to reindent the entire function. The example | 1958 | (@code{c-indent-defun}) to reindent the entire function. The example |
| 1578 | should now look like: | 1959 | should now look like: |
| @@ -1599,124 +1980,224 @@ take is to always start adjusting offsets for lines higher up in the | |||
| 1599 | file, then re-indent and see if any following lines need further | 1980 | file, then re-indent and see if any following lines need further |
| 1600 | adjustments. | 1981 | adjustments. |
| 1601 | 1982 | ||
| 1983 | |||
| 1602 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 1984 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 1603 | @node Permanent Customization, Styles, Interactive Customization, Customizing Indentation | 1985 | @node Permanent Customization, Hooks, Interactive Customization, Customizing Indentation |
| 1604 | @comment node-name, next, previous,up | 1986 | @comment node-name, next, previous, up |
| 1987 | @section Permanent Customization | ||
| 1988 | @cindex permanent customization | ||
| 1989 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| 1990 | |||
| 1991 | To make your changes permanent, you need to add some lisp code to your | ||
| 1992 | @file{.emacs} file. @ccmode{} supports many different ways to be | ||
| 1993 | configured, from the straightforward way by setting variables globally | ||
| 1994 | in @file{.emacs} or in the Customization interface, to the complex and | ||
| 1995 | precisely controlled way by using styles and hook functions. | ||
| 1996 | |||
| 1997 | The simplest way of customizing @ccmode{} permanently is to set the | ||
| 1998 | variables in your @file{.emacs} with @code{setq} and similar commands. | ||
| 1999 | So to make the setting of @code{substatement-open} permanent, add this | ||
| 2000 | to the @file{.emacs} file: | ||
| 2001 | @example | ||
| 2002 | @group | ||
| 2003 | |||
| 2004 | (require 'cc-mode) | ||
| 2005 | (c-set-offset 'substatement-open 0) | ||
| 2006 | |||
| 2007 | @end group | ||
| 2008 | @end example | ||
| 2009 | |||
| 2010 | The @code{require} line is only needed once in the beginning to make | ||
| 2011 | sure @ccmode{} is loaded so that the @code{c-set-offset} function is | ||
| 2012 | defined. | ||
| 2013 | |||
| 2014 | You can also use the more user friendly Customization interface, but | ||
| 2015 | this manual does not cover how that works. | ||
| 2016 | |||
| 2017 | Variables set like this at the top level in @file{.emacs} take effect in | ||
| 2018 | all @ccmode{} buffers, regardless of language. The indentation style | ||
| 2019 | related variables that you don't set get their value from the style | ||
| 2020 | system (@pxref{Styles}), and they therefore depend on the setting of | ||
| 2021 | @code{c-default-style}. Note that if you use Customize, this means that | ||
| 2022 | the greyed-out default values presented there might not be the ones you | ||
| 2023 | actually get, since the actual values depend on the style, which may | ||
| 2024 | very well be different for different languages. | ||
| 2025 | |||
| 2026 | If you want to make more advanced configurations, e.g. language-specific | ||
| 2027 | customization, global variable settings isn't enough. For that you can | ||
| 2028 | use the language hooks, see @ref{Hooks}, and/or the style system, see | ||
| 2029 | @ref{Styles}. | ||
| 2030 | |||
| 2031 | @vindex c-style-variables-are-local-p | ||
| 2032 | @vindex style-variables-are-local-p (c-) | ||
| 2033 | By default, all style variables are global, so that every buffer will | ||
| 2034 | share the same style settings. This is fine if you primarily edit one | ||
| 2035 | style of code, but if you edit several languages and want to use | ||
| 2036 | different styles for them, you need finer control by making the style | ||
| 2037 | variables buffer local. The recommended way to do this is to set the | ||
| 2038 | variable @code{c-style-variables-are-local-p} to @code{t}. The | ||
| 2039 | variables will be made buffer local when @ccmode{} is activated in a | ||
| 2040 | buffer for the first time in the Emacs session. Note that once the | ||
| 2041 | style variables are made buffer local, they cannot be made global again, | ||
| 2042 | without restarting Emacs. | ||
| 2043 | |||
| 1605 | 2044 | ||
| 1606 | @section Permanent Customization | 2045 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 1607 | @cindex Permanent Customization | 2046 | @node Hooks, Styles, Permanent Customization, Customizing Indentation |
| 2047 | @comment node-name, next, previous, up | ||
| 2048 | @section Hooks | ||
| 2049 | @cindex hooks | ||
| 1608 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 2050 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 1609 | 2051 | ||
| 1610 | @vindex c-mode-common-hook | 2052 | @vindex c-mode-common-hook |
| 2053 | @vindex mode-common-hook (c-) | ||
| 1611 | @vindex c-mode-hook | 2054 | @vindex c-mode-hook |
| 1612 | @vindex c++-mode-hook | 2055 | @vindex c++-mode-hook |
| 1613 | @vindex objc-mode-hook | 2056 | @vindex objc-mode-hook |
| 1614 | @vindex java-mode-hook | 2057 | @vindex java-mode-hook |
| 1615 | @vindex idl-mode-hook | 2058 | @vindex idl-mode-hook |
| 2059 | @vindex pike-mode-hook | ||
| 1616 | @vindex c-initialization-hook | 2060 | @vindex c-initialization-hook |
| 1617 | @vindex initialization-hook (c-) | 2061 | @vindex initialization-hook (c-) |
| 1618 | @cindex hooks | 2062 | @ccmode{} provides several hooks that you can use to customize the mode |
| 1619 | To make your changes permanent, you need to add some lisp code to your | 2063 | according to your coding style. Each language mode has its own hook, |
| 1620 | @file{.emacs} file, but first you need to decide whether your styles | 2064 | adhering to standard Emacs major mode conventions. There is also one |
| 1621 | should be global in every buffer, or local to each specific buffer. | 2065 | general hook and one package initialization hook: |
| 1622 | |||
| 1623 | If you edit primarily one style of code, you may want to make the | ||
| 1624 | @ccmode{} style variables have global values so that every buffer will | ||
| 1625 | share the style settings. This will allow you to set the @ccmode{} | ||
| 1626 | variables at the top level of your @file{.emacs} file, and is the | ||
| 1627 | way @ccmode{} works by default. | ||
| 1628 | |||
| 1629 | @vindex c-mode-common-hook | ||
| 1630 | @vindex mode-common-hook (c-) | ||
| 1631 | @vindex c-style-variables-are-local-p | ||
| 1632 | @vindex style-variables-are-local-p (c-) | ||
| 1633 | If you edit many different styles of code at | ||
| 1634 | the same time, you might want to make the @ccmode{} style variables | ||
| 1635 | have buffer local values. If you do this, then you will need to set any | ||
| 1636 | @ccmode{} style variables in a hook function (e.g. off of | ||
| 1637 | @code{c-mode-common-hook} instead of at the top level of your | ||
| 1638 | @file{.emacs} file). The recommended way to do this is to set the | ||
| 1639 | variable @code{c-style-variables-are-local-p} to @code{t} | ||
| 1640 | @strong{before} @ccmode{} is loaded into your Emacs session. | ||
| 1641 | |||
| 1642 | @ccmode{} provides several hooks that you can | ||
| 1643 | use to customize the mode according to your coding style. Each language | ||
| 1644 | mode has its own hook, adhering to standard Emacs major mode | ||
| 1645 | conventions. There is also one general hook and one package | ||
| 1646 | initialization hook: | ||
| 1647 | 2066 | ||
| 1648 | @itemize @bullet | 2067 | @itemize @bullet |
| 1649 | 2068 | ||
| 1650 | @item | 2069 | @item |
| 1651 | @code{c-mode-hook} --- for C buffers only | 2070 | @code{c-mode-hook} --- For C buffers only. |
| 2071 | @item | ||
| 2072 | @code{c++-mode-hook} --- For C++ buffers only. | ||
| 1652 | @item | 2073 | @item |
| 1653 | @code{c++-mode-hook} --- for C++ buffers only | 2074 | @code{objc-mode-hook} --- For Objective-C buffers only. |
| 1654 | @item | 2075 | @item |
| 1655 | @code{objc-mode-hook} --- for Objective-C buffers only | 2076 | @code{java-mode-hook} --- For Java buffers only. |
| 1656 | @item | 2077 | @item |
| 1657 | @code{java-mode-hook} --- for Java buffers only | 2078 | @code{idl-mode-hook} --- For CORBA IDL buffers only. |
| 1658 | @item | 2079 | @item |
| 1659 | @code{idl-mode-hook} --- for IDL buffers only | 2080 | @code{pike-mode-hook} --- For Pike buffers only. |
| 1660 | @item | 2081 | @item |
| 1661 | @code{c-mode-common-hook} --- common across all languages | 2082 | @code{c-mode-common-hook} --- Common across all languages. |
| 1662 | @item | 2083 | @item |
| 1663 | @code{c-initialization-hook} --- hook run only once per Emacs session, | 2084 | @code{c-initialization-hook} --- Hook run only once per Emacs session, |
| 1664 | when @ccmode{} is initialized. | 2085 | when @ccmode{} is initialized. |
| 1665 | 2086 | ||
| 1666 | @end itemize | 2087 | @end itemize |
| 1667 | 2088 | ||
| 1668 | The language hooks get run as the last thing when you enter that | 2089 | The language hooks get run as the last thing when you enter that |
| 1669 | language mode. The @code{c-mode-common-hook} is run by all | 2090 | language mode. The @code{c-mode-common-hook} is run by all supported |
| 1670 | supported modes @emph{before} the language specific hook, and thus can | 2091 | modes @emph{before} the language specific hook, and thus can contain |
| 1671 | contain customizations that are common across all languages. Most of | 2092 | customizations that are common across all languages. Most of the |
| 1672 | the examples in this section will assume you are using the common | 2093 | examples in this section will assume you are using the common |
| 1673 | hook@footnote{The interaction between @code{java-mode} and the hook | 2094 | hook.@footnote{@code{java-mode} and the hook variables interact in a |
| 1674 | variables is slightly different than for the other modes. | 2095 | slightly different way than the other modes. @code{java-mode} normally |
| 1675 | @code{java-mode} sets the style (see @ref{Styles}) of the buffer to | 2096 | sets the style of the buffer to @samp{java} @emph{before} running the |
| 1676 | @samp{java} @emph{before} running the @code{c-mode-common-hook} or | 2097 | @code{c-mode-common-hook} or @code{java-mode-hook}. You need to be |
| 1677 | @code{java-mode-hook}. You need to be aware of this so that style | 2098 | aware of this so that style settings in @code{c-mode-common-hook} don't |
| 1678 | settings in @code{c-mode-common-hook} don't clobber your Java style.}. | 2099 | clobber your Java style. This is arguably bogus, but it's kept for |
| 2100 | historical reasons. @xref{Built-in Styles}, the documentation of | ||
| 2101 | @code{c-default-style}, for details.} | ||
| 1679 | 2102 | ||
| 1680 | Here's a simplified example of what you can add to your @file{.emacs} | 2103 | Here's a simplified example of what you can add to your @file{.emacs} |
| 1681 | file to make the changes described in the previous section | 2104 | file to do things whenever any @ccmode{} language is edited. See the |
| 1682 | (@ref{Interactive Customization}) more permanent. See the Emacs manuals | 2105 | Emacs manuals for more information on customizing Emacs via hooks. |
| 1683 | for more information on customizing Emacs via hooks. @xref{Sample | 2106 | @xref{Sample .emacs File}, for a more complete sample @file{.emacs} |
| 1684 | .emacs File}, for a more complete sample @file{.emacs} file. | 2107 | file. |
| 1685 | @example | 2108 | @example |
| 1686 | @group | 2109 | @group |
| 1687 | 2110 | ||
| 1688 | (defun my-c-mode-common-hook () | 2111 | (defun my-c-mode-common-hook () |
| 1689 | ;; my customizations for all of c-mode and related modes | 2112 | ;; my customizations for all of c-mode and related modes |
| 1690 | (c-set-offset 'substatement-open 0) | 2113 | (no-case-fold-search) |
| 1691 | ;; other customizations can go here | ||
| 1692 | ) | 2114 | ) |
| 1693 | (add-hook 'c-mode-common-hook 'my-c-mode-common-hook) | 2115 | (add-hook 'c-mode-common-hook 'my-c-mode-common-hook) |
| 1694 | 2116 | ||
| 1695 | @end group | 2117 | @end group |
| 1696 | @end example | 2118 | @end example |
| 1697 | 2119 | ||
| 1698 | For complex customizations, you will probably want to set up a | ||
| 1699 | @emph{style} that groups all your customizations under a single | ||
| 1700 | name. | ||
| 1701 | 2120 | ||
| 1702 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 2121 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 1703 | @node Styles, Advanced Customizations, Permanent Customization, Customizing Indentation | 2122 | @node Styles, Advanced Customizations, Hooks, Customizing Indentation |
| 1704 | @comment node-name, next, previous,up | 2123 | @comment node-name, next, previous, up |
| 1705 | 2124 | @section Styles | |
| 1706 | @section Styles | 2125 | @cindex styles |
| 1707 | @cindex Styles | ||
| 1708 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 2126 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 1709 | 2127 | ||
| 1710 | Most people only need to edit code formatted in just a few well-defined | 2128 | Most people only need to edit code formatted in just a few well-defined |
| 1711 | and consistent styles. For example, their organization might impose a | 2129 | and consistent styles. For example, their organization might impose a |
| 1712 | ``blessed'' style that all its programmers must conform to. Similarly, | 2130 | ``blessed'' style that all its programmers must conform to. Similarly, |
| 1713 | people who work on GNU software will have to use the GNU coding style on | 2131 | people who work on GNU software will have to use the GNU coding style. |
| 1714 | C code. Some shops are more lenient, allowing a variety of coding | 2132 | Some shops are more lenient, allowing a variety of coding styles, and as |
| 1715 | styles, and as programmers come and go, there could be a number of | 2133 | programmers come and go, there could be a number of styles in use. For |
| 1716 | styles in use. For this reason, @ccmode{} makes it convenient for | 2134 | this reason, @ccmode{} makes it convenient for you to set up logical |
| 1717 | you to set up logical groupings of customizations called @dfn{styles}, | 2135 | groupings of customizations called @dfn{styles}, associate a single name |
| 1718 | associate a single name for any particular style, and pretty easily | 2136 | for any particular style, and pretty easily start editing new or |
| 1719 | start editing new or existing code using these styles. | 2137 | existing code using these styles. |
| 2138 | |||
| 2139 | @cindex style variables | ||
| 2140 | The variables that the style system affect are called @dfn{style | ||
| 2141 | variables}. They are handled specially in several ways: | ||
| 2142 | |||
| 2143 | @itemize @bullet | ||
| 2144 | @item | ||
| 2145 | Style variables are by default global variables, i.e. they have the same | ||
| 2146 | value in all Emacs buffers. However, they can instead be made always | ||
| 2147 | buffer local by setting @code{c-style-variables-are-local-p} to | ||
| 2148 | non-@code{nil} before @ccmode{} is initialized. | ||
| 2149 | |||
| 2150 | @vindex c-old-style-variable-behavior | ||
| 2151 | @vindex old-style-variable-behavior (c-) | ||
| 2152 | @item | ||
| 2153 | The default value of any style variable (with two exceptions --- see | ||
| 2154 | below) is the special symbol @code{set-from-style}. Variables that are | ||
| 2155 | still set to that symbol when a @ccmode{} buffer is initialized will be | ||
| 2156 | set according to the current style, otherwise they will keep their | ||
| 2157 | current value@footnote{This is a big change from versions of @ccmode{} | ||
| 2158 | earlier than 5.26, where such settings would get overridden by the style | ||
| 2159 | system unless special precautions were taken. That was changed since it | ||
| 2160 | was counterintuitive and confusing, especially to novice users. If your | ||
| 2161 | configuration depends on the old overriding behavior, you can set the | ||
| 2162 | variable @code{c-old-style-variable-behavior} to non-@code{nil}.}. | ||
| 2163 | |||
| 2164 | Note that when we talk about the ``default value'' for a style variable, | ||
| 2165 | we don't mean the @code{set-from-style} symbol that all style variables | ||
| 2166 | are set to initially, but instead the value it will get at mode | ||
| 2167 | initialization when neither a style nor a global setting has set its | ||
| 2168 | value. | ||
| 2169 | |||
| 2170 | The style variable @code{c-offsets-alist} is handled a little | ||
| 2171 | differently from the other style variables. It's an association list, | ||
| 2172 | and is thus by default set to the empty list, @code{nil}. When the | ||
| 2173 | style system is initialized, any syntactic symbols already on it are | ||
| 2174 | kept --- only the missing ones are filled in from the chosen style. | ||
| 2175 | |||
| 2176 | The style variable @code{c-special-indent-hook} is also handled in a | ||
| 2177 | special way. Styles may only add more functions on this hook, so the | ||
| 2178 | global settings on it are always preserved@footnote{This did not change | ||
| 2179 | in version 5.26.}. | ||
| 2180 | |||
| 2181 | @item | ||
| 2182 | The global settings of style variables get captured in the special | ||
| 2183 | @code{user} style, which is used as the base for all the other styles. | ||
| 2184 | @xref{Built-in Styles}, for details. | ||
| 2185 | |||
| 2186 | @end itemize | ||
| 2187 | |||
| 2188 | The style variables are: | ||
| 2189 | @code{c-basic-offset}, | ||
| 2190 | @code{c-comment-only-line-offset}, | ||
| 2191 | @code{c-block-comment-prefix}, | ||
| 2192 | @code{c-comment-prefix-regexp}, | ||
| 2193 | @code{c-cleanup-list}, | ||
| 2194 | @code{c-hanging-braces-alist}, | ||
| 2195 | @code{c-hanging-colons-alist}, | ||
| 2196 | @code{c-hanging-semi&comma-criteria}, | ||
| 2197 | @code{c-backslash-column}, | ||
| 2198 | @code{c-special-indent-hook}, | ||
| 2199 | @code{c-label-minimum-indentation}, and | ||
| 2200 | @code{c-offsets-alist}. | ||
| 1720 | 2201 | ||
| 1721 | @menu | 2202 | @menu |
| 1722 | * Built-in Styles:: | 2203 | * Built-in Styles:: |
| @@ -1726,11 +2207,10 @@ start editing new or existing code using these styles. | |||
| 1726 | 2207 | ||
| 1727 | 2208 | ||
| 1728 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 2209 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 1729 | @node Built-in Styles, Adding Styles, , Styles | 2210 | @node Built-in Styles, Adding Styles, , Styles |
| 1730 | @comment node-name, next, previous,up | 2211 | @comment node-name, next, previous, up |
| 1731 | 2212 | @subsection Built-in Styles | |
| 1732 | @subsection Built-in Styles | 2213 | @cindex built-in styles |
| 1733 | @cindex Built-in Styles | ||
| 1734 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 2214 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 1735 | 2215 | ||
| 1736 | If you're lucky, one of @ccmode{}'s built-in styles might be just | 2216 | If you're lucky, one of @ccmode{}'s built-in styles might be just |
| @@ -1739,10 +2219,8 @@ what you're looking for. These include: | |||
| 1739 | @itemize @bullet | 2219 | @itemize @bullet |
| 1740 | @cindex GNU style | 2220 | @cindex GNU style |
| 1741 | @item | 2221 | @item |
| 1742 | @code{gnu} --- coding style blessed by the Free Software Foundation | 2222 | @code{gnu} --- Coding style blessed by the Free Software Foundation |
| 1743 | for C code in GNU programs. This is the default style for all newly | 2223 | for C code in GNU programs. |
| 1744 | created buffers, but you can change this by setting the variable | ||
| 1745 | @code{c-default-style}. | ||
| 1746 | 2224 | ||
| 1747 | @cindex K&R style | 2225 | @cindex K&R style |
| 1748 | @item | 2226 | @item |
| @@ -1765,8 +2243,9 @@ Whitesmiths C, an early commercial C compiler. | |||
| 1765 | @item | 2243 | @item |
| 1766 | @code{ellemtel} --- Popular C++ coding standards as defined by | 2244 | @code{ellemtel} --- Popular C++ coding standards as defined by |
| 1767 | ``Programming in C++, Rules and Recommendations'', Erik Nyquist and Mats | 2245 | ``Programming in C++, Rules and Recommendations'', Erik Nyquist and Mats |
| 1768 | Henricson, Ellemtel @footnote{This document is ftp'able from | 2246 | Henricson, Ellemtel@footnote{This document is available at |
| 1769 | @code{euagate.eua.ericsson.se}}. | 2247 | @uref{http://www.doc.ic.ac.uk/lab/cplus/c++.rules/} among other |
| 2248 | places.}. | ||
| 1770 | 2249 | ||
| 1771 | @cindex Linux style | 2250 | @cindex Linux style |
| 1772 | @item | 2251 | @item |
| @@ -1777,37 +2256,75 @@ Henricson, Ellemtel @footnote{This document is ftp'able from | |||
| 1777 | @code{python} --- C coding standard for Python extension | 2256 | @code{python} --- C coding standard for Python extension |
| 1778 | modules@footnote{Python is a high level scripting language with a C/C++ | 2257 | modules@footnote{Python is a high level scripting language with a C/C++ |
| 1779 | foreign function interface. For more information, see | 2258 | foreign function interface. For more information, see |
| 1780 | @code{<http://www.python.org/>}.}. | 2259 | @uref{http://www.python.org/}.}. |
| 1781 | 2260 | ||
| 1782 | @cindex Java style | 2261 | @cindex Java style |
| 1783 | @cindex java-mode | 2262 | @findex java-mode |
| 1784 | @item | 2263 | @item |
| 1785 | @code{java} --- The style for editing Java code. Note that this style is | 2264 | @code{java} --- The style for editing Java code. Note that this style is |
| 1786 | automatically installed when you enter @code{java-mode}. | 2265 | automatically installed when you enter @code{java-mode}. |
| 1787 | 2266 | ||
| 1788 | @cindex User style | 2267 | @cindex User style |
| 1789 | @cindex .emacs file | 2268 | @item |
| 2269 | @code{user} --- This is a special style for several reasons. First, the | ||
| 2270 | @ccmode{} customizations you do by using either the Customization | ||
| 2271 | interface, or by writing @code{setq}'s at the top level of your | ||
| 2272 | @file{.emacs} file, will be captured in the @code{user} style. Also, | ||
| 2273 | all other styles implicitly inherit their settings from @code{user} | ||
| 2274 | style. This means that for any styles you add via @code{c-add-style} | ||
| 2275 | (@pxref{Adding Styles}) you need only define the differences between | ||
| 2276 | your new style and @code{user} style. | ||
| 2277 | |||
| 2278 | @end itemize | ||
| 2279 | |||
| 1790 | @vindex c-default-style | 2280 | @vindex c-default-style |
| 1791 | @vindex default-style (c-) | 2281 | @vindex default-style (c-) |
| 2282 | The default style in all newly created buffers is @code{gnu}, but you | ||
| 2283 | can change this by setting variable @code{c-default-style}. Although | ||
| 2284 | the @code{user} style is not the default style, any style variable | ||
| 2285 | settings you do with the Customization interface or on the top level in | ||
| 2286 | your @file{.emacs} file will by default override the style system, so | ||
| 2287 | you don't need to set @code{c-default-style} to @code{user} to see the | ||
| 2288 | effect of these settings. | ||
| 2289 | |||
| 2290 | @code{c-default-style} takes either a style name string, or an | ||
| 2291 | association list of major mode symbols to style names. Thus you can | ||
| 2292 | control exactly which default style is used for which @ccmode{} language | ||
| 2293 | mode. Here are the rules: | ||
| 2294 | |||
| 2295 | @vindex c-style-alist | ||
| 2296 | @vindex style-alist (c-) | ||
| 2297 | @vindex c-mode-common-hook | ||
| 2298 | @vindex mode-common-hook (c-) | ||
| 2299 | @enumerate | ||
| 1792 | @item | 2300 | @item |
| 1793 | @code{user} --- This is a special style for several reasons. First, if | 2301 | When @code{c-default-style} is a string, it must be an existing style |
| 1794 | you customize @ccmode{} by using either the new Custom interface or by | 2302 | name as found in @code{c-style-alist}. This style is then used for all |
| 1795 | doing @code{setq}'s at the top level of your @file{.emacs} file, these | 2303 | modes @emph{except} @code{java-mode}, where the style @samp{java} is |
| 1796 | settings will be captured in the @code{user} style. Also, all other | 2304 | used by default@footnote{This is for backwards compatibility reasons. |
| 1797 | styles implicitly inherit their settings from @code{user} style. This | 2305 | The hard-coding of @code{java-mode} style is admittedly bogus!}. |
| 1798 | means that for any styles you add via @code{c-add-style} (@pxref{Adding | ||
| 1799 | Styles}) you need only define the differences between your new style and | ||
| 1800 | @code{user} style. | ||
| 1801 | |||
| 1802 | Note however that @code{user} style is @emph{not} the default style. | ||
| 1803 | @code{gnu} is the default style for all newly created buffers, but you | ||
| 1804 | can change this by setting variable @code{c-default-style}. Be careful | ||
| 1805 | if you customize @ccmode{} as described above; since your changes will | ||
| 1806 | be captured in the @code{user} style, you will also have to change | ||
| 1807 | @code{c-default-style} to "user" to see the effect of your | ||
| 1808 | customizations. | ||
| 1809 | 2306 | ||
| 1810 | @end itemize | 2307 | @item |
| 2308 | When @code{c-default-style} is an association list, the current major | ||
| 2309 | mode is looked up to find a style name string. In this case, this style | ||
| 2310 | is always used exactly as specified and an error will occur if the named | ||
| 2311 | style does not exist. | ||
| 2312 | |||
| 2313 | @item | ||
| 2314 | If @code{c-default-style} is an association list, but the current major | ||
| 2315 | mode isn't found, then the special symbol @samp{other} is looked up. If | ||
| 2316 | this value is found, the associated style is used. | ||
| 2317 | |||
| 2318 | @item | ||
| 2319 | If @samp{other} is not found, then the @samp{gnu} style is used. | ||
| 2320 | |||
| 2321 | @item | ||
| 2322 | In all cases, the style described in @code{c-default-style} is installed | ||
| 2323 | @emph{before} the language hooks are run, so you can always override | ||
| 2324 | this setting by including an explicit call to @code{c-set-style} in your | ||
| 2325 | language mode hook, or in @code{c-mode-common-hook}. | ||
| 2326 | |||
| 2327 | @end enumerate | ||
| 1811 | 2328 | ||
| 1812 | @findex c-set-style | 2329 | @findex c-set-style |
| 1813 | @findex set-style (c-) | 2330 | @findex set-style (c-) |
| @@ -1829,40 +2346,22 @@ Setting a style in this way does @emph{not} automatically re-indent your | |||
| 1829 | file. For commands that you can use to view the effect of your changes, | 2346 | file. For commands that you can use to view the effect of your changes, |
| 1830 | see @ref{Commands}. | 2347 | see @ref{Commands}. |
| 1831 | 2348 | ||
| 1832 | Once you find a built-in style you like, you can make the change | ||
| 1833 | permanent by adding some lisp to your @file{.emacs} file. Let's say for | ||
| 1834 | example that you want to use the @samp{ellemtel} style in all your | ||
| 1835 | files. You would add this: | ||
| 1836 | @example | ||
| 1837 | @group | ||
| 1838 | |||
| 1839 | (defun my-c-mode-common-hook () | ||
| 1840 | ;; use Ellemtel style for all C like languages | ||
| 1841 | (c-set-style "ellemtel") | ||
| 1842 | ;; other customizations can go here | ||
| 1843 | ) | ||
| 1844 | (add-hook 'c-mode-common-hook 'my-c-mode-common-hook) | ||
| 1845 | |||
| 1846 | @end group | ||
| 1847 | @end example | ||
| 1848 | |||
| 1849 | @vindex c-indentation-style | 2349 | @vindex c-indentation-style |
| 1850 | @vindex indentation-style (c-) | 2350 | @vindex indentation-style (c-) |
| 1851 | Note that for BOCM compatibility, @samp{gnu} is the default | 2351 | Note that for BOCM compatibility, @samp{gnu} is the default style, and |
| 1852 | style, and any non-style based customizations you make (i.e. in | 2352 | any non-style based customizations you make (i.e. in |
| 1853 | @code{c-mode-common-hook} in your | 2353 | @code{c-mode-common-hook} in your @file{.emacs} file) will be based on |
| 1854 | @file{.emacs} file) will be based on @samp{gnu} style unless you do | 2354 | @samp{gnu} style unless you set @code{c-default-style} or do a |
| 1855 | a @code{c-set-style} as the first thing in your hook. The variable | 2355 | @code{c-set-style} as the first thing in your hook. The variable |
| 1856 | @code{c-indentation-style} always contains the buffer's current style name, | 2356 | @code{c-indentation-style} always contains the buffer's current style |
| 1857 | as a string. | 2357 | name, as a string. |
| 1858 | 2358 | ||
| 1859 | 2359 | ||
| 1860 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 2360 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 1861 | @node Adding Styles, File Styles, Built-in Styles, Styles | 2361 | @node Adding Styles, File Styles, Built-in Styles, Styles |
| 1862 | @comment node-name, next, previous,up | 2362 | @comment node-name, next, previous, up |
| 1863 | 2363 | @subsection Adding Styles | |
| 1864 | @subsection Adding Styles | 2364 | @cindex adding styles |
| 1865 | @cindex Adding Styles | ||
| 1866 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 2365 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 1867 | 2366 | ||
| 1868 | @vindex c-style-alist | 2367 | @vindex c-style-alist |
| @@ -1889,12 +2388,12 @@ buffer. | |||
| 1889 | The sample @file{.emacs} file provides a concrete example of how a new | 2388 | The sample @file{.emacs} file provides a concrete example of how a new |
| 1890 | style can be added and automatically set. @xref{Sample .emacs File}. | 2389 | style can be added and automatically set. @xref{Sample .emacs File}. |
| 1891 | 2390 | ||
| 1892 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| 1893 | @node File Styles, , Adding Styles, Styles | ||
| 1894 | @comment node-name, next, previous,up | ||
| 1895 | 2391 | ||
| 1896 | @subsection File Styles | 2392 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 1897 | @cindex File Styles | 2393 | @node File Styles, , Adding Styles, Styles |
| 2394 | @comment node-name, next, previous, up | ||
| 2395 | @subsection File Styles | ||
| 2396 | @cindex file styles | ||
| 1898 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 2397 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 1899 | 2398 | ||
| 1900 | @cindex local variables | 2399 | @cindex local variables |
| @@ -1905,8 +2404,6 @@ the file. So far, you've only seen a functional interface to @ccmode{} | |||
| 1905 | customization, which is highly inconvenient for use in a Local Variable | 2404 | customization, which is highly inconvenient for use in a Local Variable |
| 1906 | block. @ccmode{} provides two variables that make it easier for you to | 2405 | block. @ccmode{} provides two variables that make it easier for you to |
| 1907 | customize your style on a per-file basis. | 2406 | customize your style on a per-file basis. |
| 1908 | It works via the standard Emacs hook variable | ||
| 1909 | @code{hack-local-variables-hook}. | ||
| 1910 | 2407 | ||
| 1911 | @vindex c-file-style | 2408 | @vindex c-file-style |
| 1912 | @vindex file-style (c-) | 2409 | @vindex file-style (c-) |
| @@ -1917,13 +2414,9 @@ The variable @code{c-file-style} can be set to a style name string. | |||
| 1917 | When the file is visited, @ccmode{} will automatically set the | 2414 | When the file is visited, @ccmode{} will automatically set the |
| 1918 | file's style to this style using @code{c-set-style}. | 2415 | file's style to this style using @code{c-set-style}. |
| 1919 | 2416 | ||
| 1920 | @vindex c-offsets-alist | ||
| 1921 | @vindex offsets-alist (c-) | ||
| 1922 | @findex c-set-offset | ||
| 1923 | @findex set-offset (c-) | ||
| 1924 | Another variable, @code{c-file-offsets}, takes an association list | 2417 | Another variable, @code{c-file-offsets}, takes an association list |
| 1925 | similar to what is allowed in @code{c-offsets-alist}. When the file is | 2418 | similar to what is allowed in @code{c-offsets-alist}. When the file is |
| 1926 | visited, @ccmode{} will automatically institute these offets using | 2419 | visited, @ccmode{} will automatically institute these offsets using |
| 1927 | @code{c-set-offset}. | 2420 | @code{c-set-offset}. |
| 1928 | 2421 | ||
| 1929 | Note that file style settings (i.e. @code{c-file-style}) are applied | 2422 | Note that file style settings (i.e. @code{c-file-style}) are applied |
| @@ -1933,17 +2426,13 @@ style variable values are made local to that buffer. | |||
| 1933 | 2426 | ||
| 1934 | 2427 | ||
| 1935 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 2428 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 1936 | @node Advanced Customizations, , Styles, Customizing Indentation | 2429 | @node Advanced Customizations, , Styles, Customizing Indentation |
| 1937 | @comment node-name, next, previous,up | 2430 | @comment node-name, next, previous, up |
| 1938 | 2431 | @section Advanced Customizations | |
| 1939 | @section Advanced Customizations | ||
| 1940 | @cindex Advanced Customizations | ||
| 1941 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 2432 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 1942 | 2433 | ||
| 1943 | @vindex c-style-alist | 2434 | @vindex c-style-alist |
| 1944 | @vindex style-alist (c-) | 2435 | @vindex style-alist (c-) |
| 1945 | @vindex c-basic-offset | ||
| 1946 | @vindex basic-offset (c-) | ||
| 1947 | For most users, @ccmode{} will support their coding styles with | 2436 | For most users, @ccmode{} will support their coding styles with |
| 1948 | very little need for more advanced customizations. Usually, one of the | 2437 | very little need for more advanced customizations. Usually, one of the |
| 1949 | standard styles defined in @code{c-style-alist} will do the trick. At | 2438 | standard styles defined in @code{c-style-alist} will do the trick. At |
| @@ -1955,23 +2444,6 @@ the syntactic analysis model provides just such a framework. This allows | |||
| 1955 | you to implement custom indentation calculations for situations not | 2444 | you to implement custom indentation calculations for situations not |
| 1956 | handled by the mode directly. | 2445 | handled by the mode directly. |
| 1957 | 2446 | ||
| 1958 | @vindex c-style-variables-are-local-p | ||
| 1959 | @vindex style-variables-are-local-p | ||
| 1960 | Note that the style controlling variables can either have global values, | ||
| 1961 | or can be buffer local (e.g. different in every buffer). If all the C | ||
| 1962 | files you edit tend to have the same style, you might want to keep the | ||
| 1963 | variables global. If you tend to edit files with many different styles, | ||
| 1964 | you will have to make the variables buffer local. The variable | ||
| 1965 | @code{c-style-variables-are-local-p} controls this. | ||
| 1966 | |||
| 1967 | When @code{c-style-variables-are-local-p} is non-nil, then the style | ||
| 1968 | variables will have a different settable value for each buffer, | ||
| 1969 | otherwise all buffers will share the same values. By default, its value | ||
| 1970 | is @code{nil} (i.e. global values). You @strong{must} set this variable | ||
| 1971 | before @ccmode{} is loaded into your Emacs session, and once the | ||
| 1972 | variables are made buffer local, they cannot be made global again | ||
| 1973 | (unless you restart Emacs of course!) | ||
| 1974 | |||
| 1975 | @menu | 2447 | @menu |
| 1976 | * Custom Indentation Functions:: | 2448 | * Custom Indentation Functions:: |
| 1977 | * Custom Brace and Colon Hanging:: | 2449 | * Custom Brace and Colon Hanging:: |
| @@ -1980,19 +2452,17 @@ variables are made buffer local, they cannot be made global again | |||
| 1980 | @end menu | 2452 | @end menu |
| 1981 | 2453 | ||
| 1982 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 2454 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 1983 | @node Custom Indentation Functions, Custom Brace and Colon Hanging, , Advanced Customizations | 2455 | @node Custom Indentation Functions, Custom Brace and Colon Hanging, , Advanced Customizations |
| 1984 | @comment node-name, next, previous,up | 2456 | @comment node-name, next, previous, up |
| 1985 | 2457 | @subsection Custom Indentation Functions | |
| 1986 | @subsection Custom Indentation Functions | 2458 | @cindex custom indentation functions |
| 1987 | @cindex Custom Indentation Functions | ||
| 1988 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 2459 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 1989 | 2460 | ||
| 1990 | @cindex Custom Indentation Functions | 2461 | The most flexible way to customize @ccmode{} is by writing custom |
| 1991 | The most flexible way to customize @ccmode{} is by writing @dfn{custom | 2462 | indentation functions, and associating them with specific syntactic |
| 1992 | indentation functions} and associating them with specific syntactic | 2463 | symbols (@pxref{Syntactic Symbols}). @ccmode{} itself uses indentation |
| 1993 | symbols (see @ref{Syntactic Symbols}). @ccmode{} itself uses custom | 2464 | functions to provide more sophisticated indentation, for example when |
| 1994 | indentation functions to provide more sophisticated indentation, for | 2465 | lining up C++ stream operator blocks: |
| 1995 | example when lining up C++ stream operator blocks: | ||
| 1996 | @example | 2466 | @example |
| 1997 | @group | 2467 | @group |
| 1998 | 2468 | ||
| @@ -2032,15 +2502,20 @@ lisp code implementing this: | |||
| 2032 | @end group | 2502 | @end group |
| 2033 | @end example | 2503 | @end example |
| 2034 | @noindent | 2504 | @noindent |
| 2035 | Custom indent functions take a single argument, which is a syntactic | 2505 | Indentation functions take a single argument, which is a syntactic |
| 2036 | component cons cell (see @ref{Syntactic Analysis}). The | 2506 | component cons cell (@pxref{Syntactic Analysis}). The function returns |
| 2037 | function returns an integer offset value that will be added to the | 2507 | an integer offset value that will be added to the running total |
| 2038 | running total indentation for the line. Note that what actually gets | 2508 | indentation for the line. Note that what actually gets returned is the |
| 2039 | returned is the difference between the column that the first stream | 2509 | difference between the column that the first stream operator is on, and |
| 2040 | operator is on, and the column of the buffer relative position passed in | 2510 | the column of the buffer relative position passed in the function's |
| 2041 | the function's argument. Remember that @ccmode{} automatically | 2511 | argument. Remember that @ccmode{} automatically adds in the column of |
| 2042 | adds in the column of the component's relative buffer position and we | 2512 | the component's relative buffer position and we don't the column offset |
| 2043 | don't the column offset added in twice. | 2513 | added in twice. |
| 2514 | |||
| 2515 | The function should return @code{nil} if it's used in a situation where | ||
| 2516 | it doesn't want to do any decision. If the function is used in a list | ||
| 2517 | expression (@pxref{Customizing Indentation}), that will cause @ccmode{} | ||
| 2518 | to go on and check the next entry in the list. | ||
| 2044 | 2519 | ||
| 2045 | @cindex stream-op syntactic symbol | 2520 | @cindex stream-op syntactic symbol |
| 2046 | @findex c-lineup-streamop | 2521 | @findex c-lineup-streamop |
| @@ -2049,14 +2524,13 @@ Now, to associate the function @code{c-lineup-streamop} with the | |||
| 2049 | @code{stream-op} syntactic symbol, we can add something like the | 2524 | @code{stream-op} syntactic symbol, we can add something like the |
| 2050 | following to our @code{c++-mode-hook}@footnote{It probably makes more | 2525 | following to our @code{c++-mode-hook}@footnote{It probably makes more |
| 2051 | sense to add this to @code{c++-mode-hook} than @code{c-mode-common-hook} | 2526 | sense to add this to @code{c++-mode-hook} than @code{c-mode-common-hook} |
| 2052 | since stream operators are only relevent for C++.}: | 2527 | since stream operators are only relevant for C++.}: |
| 2053 | @example | 2528 | @example |
| 2054 | 2529 | ||
| 2055 | (c-set-offset 'stream-op 'c-lineup-streamop) | 2530 | (c-set-offset 'stream-op 'c-lineup-streamop) |
| 2056 | 2531 | ||
| 2057 | @end example | 2532 | @end example |
| 2058 | 2533 | ||
| 2059 | @kindex C-c C-q | ||
| 2060 | Now the function looks like this after re-indenting (using @kbd{C-c | 2534 | Now the function looks like this after re-indenting (using @kbd{C-c |
| 2061 | C-q}): | 2535 | C-q}): |
| 2062 | @example | 2536 | @example |
| @@ -2066,132 +2540,29 @@ C-q}): | |||
| 2066 | 2: @{ | 2540 | 2: @{ |
| 2067 | 3: cout << "There were " | 2541 | 3: cout << "There were " |
| 2068 | 4: << argc | 2542 | 4: << argc |
| 2069 | 5: << "arguments passed to the program" | 2543 | 5: << " arguments passed to the program" |
| 2070 | 6: << endl; | 2544 | 6: << endl; |
| 2071 | 7: @} | 2545 | 7: @} |
| 2072 | 2546 | ||
| 2073 | @end group | 2547 | @end group |
| 2074 | @end example | 2548 | @end example |
| 2075 | 2549 | ||
| 2076 | @vindex c-offsets-alist | ||
| 2077 | @vindex offsets-alist (c-) | ||
| 2078 | Custom indentation functions can be as simple or as complex as you like, | 2550 | Custom indentation functions can be as simple or as complex as you like, |
| 2079 | and any syntactic symbol that appears in @code{c-offsets-alist} can have | 2551 | and any syntactic symbol that appears in @code{c-offsets-alist} can have |
| 2080 | a custom indentation function associated with it. @ccmode{} comes | 2552 | a custom indentation function associated with it. |
| 2081 | with several standard custom indentation functions, not all of which are | ||
| 2082 | used by the default styles. | ||
| 2083 | |||
| 2084 | @itemize @bullet | ||
| 2085 | @findex c-lineup-arglist | ||
| 2086 | @findex lineup-arglist (c-) | ||
| 2087 | @item | ||
| 2088 | @code{c-lineup-arglist} --- lines up function argument lines under the | ||
| 2089 | argument on the previous line. | ||
| 2090 | |||
| 2091 | @findex c-lineup-arglist-intro-after-paren | ||
| 2092 | @findex lineup-arglist-intro-after-paren (c-) | ||
| 2093 | @item | ||
| 2094 | @code{c-lineup-arglist-intro-after-paren} --- similar to | ||
| 2095 | @code{c-lineup-arglist}, but works for argument lists that begin with an | ||
| 2096 | open parenthesis followed by a newline. | ||
| 2097 | 2553 | ||
| 2098 | @findex c-lineup-arglist-close-under-paren | 2554 | @ccmode{} comes with an extensive set of predefined indentation |
| 2099 | @findex lineup-arglist-close-under-paren (c-) | 2555 | functions, not all of which are used by the default styles. So there's |
| 2100 | @item | 2556 | a good chance the function you want already exists. @xref{Indentation |
| 2101 | @code{c-lineup-arglist-close-under-paren} --- set your | 2557 | Functions}, for a list of them. If you have written an indentation |
| 2102 | @code{arglist-close} syntactic symbol to this line-up function so that | 2558 | function that you think is generally useful, you're very welcome to |
| 2103 | parentheses that close argument lists will line up under the parenthesis | 2559 | contribute it; please contact @email{bug-cc-mode@@gnu.org}. |
| 2104 | that opened the argument list. | ||
| 2105 | |||
| 2106 | @findex c-lineup-close-paren | ||
| 2107 | @findex lineup-close-paren (c-) | ||
| 2108 | @item | ||
| 2109 | @code{c-lineup-close-paren} --- lines up the closing parenthesis under | ||
| 2110 | its corresponding open parenthesis if that one is followed by code. | ||
| 2111 | Otherwise, if the open parenthesis ends its line, no indentation is | ||
| 2112 | added. Works with any @code{@dots{}-close} symbol. | ||
| 2113 | 2560 | ||
| 2114 | @findex c-lineup-streamop | ||
| 2115 | @findex lineup-streamop (c-) | ||
| 2116 | @item | ||
| 2117 | @code{c-lineup-streamop} --- lines up C++ stream operators | ||
| 2118 | (e.g. @samp{<<} and @samp{>>}). | ||
| 2119 | |||
| 2120 | @findex c-lineup-multi-inher | ||
| 2121 | @findex lineup-multi-inher (c-) | ||
| 2122 | @item | ||
| 2123 | @code{c-lineup-multi-inher} --- lines up multiple inheritance lines. | ||
| 2124 | |||
| 2125 | @findex c-indent-one-line-block | ||
| 2126 | @findex indent-one-line-block (c-) | ||
| 2127 | @item | ||
| 2128 | @code{c-indent-one-line-block} --- adds @code{c-basic-offset} to the | ||
| 2129 | indentation if the line is a one line block, otherwise 0. Intended to | ||
| 2130 | be used with any opening brace symbol, e.g. @code{substatement-open}. | ||
| 2131 | |||
| 2132 | @findex c-lineup-C-comments | ||
| 2133 | @findex lineup-C-comments (c-) | ||
| 2134 | @item | ||
| 2135 | @code{c-lineup-C-comments} --- lines up C block comment continuation | ||
| 2136 | lines. | ||
| 2137 | |||
| 2138 | @findex c-lineup-comment | ||
| 2139 | @findex lineup-comment (c-) | ||
| 2140 | @vindex c-comment-only-line-offset | ||
| 2141 | @vindex comment-only-line-offset (c-) | ||
| 2142 | @item | ||
| 2143 | @code{c-lineup-comment} --- lines up comment only lines according to | ||
| 2144 | the variable @code{c-comment-only-line-offset}. | ||
| 2145 | |||
| 2146 | @findex c-lineup-runin-statements | ||
| 2147 | @findex lineup-runin-statements (c-) | ||
| 2148 | @item | ||
| 2149 | @code{c-lineup-runin-statements} --- lines up @code{statement}s for coding | ||
| 2150 | standards which place the first statement in a block on the same line as | ||
| 2151 | the block opening brace@footnote{Run-in style doesn't really work too | ||
| 2152 | well. You might need to write your own custom indentation functions to | ||
| 2153 | better support this style.}. | ||
| 2154 | |||
| 2155 | @findex c-lineup-math | ||
| 2156 | @findex lineup-math (c-) | ||
| 2157 | @item | ||
| 2158 | @code{c-lineup-math} --- lines up math @code{statement-cont} lines under | ||
| 2159 | the previous line after the equals sign. | ||
| 2160 | |||
| 2161 | @findex c-lineup-ObjC-method-call | ||
| 2162 | @findex lineup-ObjC-method-call (c-) | ||
| 2163 | @item | ||
| 2164 | @code{c-lineup-ObjC-method-call} --- for Objective-C code, lines up | ||
| 2165 | selector arguments just after the message receiver. | ||
| 2166 | |||
| 2167 | @findex c-lineup-ObjC-method-args | ||
| 2168 | @findex lineup-ObjC-method-args (c-) | ||
| 2169 | @item | ||
| 2170 | @code{c-lineup-ObjC-method-args} --- for Objective-C code, lines up the | ||
| 2171 | colons that separate arguments by aligning colons vertically. | ||
| 2172 | |||
| 2173 | @findex c-lineup-ObjC-method-args-2 | ||
| 2174 | @findex lineup-ObjC-method-args-2 (c-) | ||
| 2175 | @item | ||
| 2176 | @code{c-lineup-ObjC-method-args-2} --- similar to | ||
| 2177 | @code{c-lineup-ObjC-method-args} but lines up the colon on the current | ||
| 2178 | line with the colon on the previous line. | ||
| 2179 | |||
| 2180 | @findex c-lineup-dont-change | ||
| 2181 | @findex lineup-dont-change (c-) | ||
| 2182 | @item | ||
| 2183 | @code{c-lineup-dont-change} --- this lineup function returns the | ||
| 2184 | indentation of the current line. Think of it as an identity function | ||
| 2185 | for lineups; it is used for @code{cpp-macro-cont} lines. | ||
| 2186 | |||
| 2187 | @end itemize | ||
| 2188 | 2561 | ||
| 2189 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 2562 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 2190 | @node Custom Brace and Colon Hanging, Customizing Semi-colons and Commas, Custom Indentation Functions, Advanced Customizations | 2563 | @node Custom Brace and Colon Hanging, Customizing Semi-colons and Commas, Custom Indentation Functions, Advanced Customizations |
| 2191 | @comment node-name, next, previous,up | 2564 | @comment node-name, next, previous, up |
| 2192 | 2565 | @subsection Custom Brace and Colon Hanging | |
| 2193 | @subsection Custom Brace and Colon Hanging | ||
| 2194 | @cindex Custom Brace and Colon Hanging | ||
| 2195 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 2566 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 2196 | 2567 | ||
| 2197 | @vindex c-hanging-braces-alist | 2568 | @vindex c-hanging-braces-alist |
| @@ -2199,20 +2570,20 @@ for lineups; it is used for @code{cpp-macro-cont} lines. | |||
| 2199 | Syntactic symbols aren't the only place where you can customize | 2570 | Syntactic symbols aren't the only place where you can customize |
| 2200 | @ccmode{} with the lisp equivalent of callback functions. Brace | 2571 | @ccmode{} with the lisp equivalent of callback functions. Brace |
| 2201 | ``hanginess'' can also be determined by custom functions associated with | 2572 | ``hanginess'' can also be determined by custom functions associated with |
| 2202 | syntactic symbols on the @code{c-hanging-braces-alist} variable. | 2573 | syntactic symbols on the @code{c-hanging-braces-alist} style variable. |
| 2203 | Remember that @var{ACTION}'s are typically a list containing some | 2574 | Remember that @var{ACTION}'s are typically a list containing some |
| 2204 | combination of the symbols @code{before} and @code{after} (see | 2575 | combination of the symbols @code{before} and @code{after} |
| 2205 | @ref{Hanging Braces}). However, an @var{ACTION} can also be a function | 2576 | (@pxref{Hanging Braces}). However, an @var{ACTION} can also be a |
| 2206 | which gets called when a brace matching that syntactic symbol is | 2577 | function which gets called when a brace matching that syntactic symbol |
| 2207 | entered. | 2578 | is entered. |
| 2208 | 2579 | ||
| 2209 | @cindex customizing brace hanging | 2580 | @cindex customizing brace hanging |
| 2210 | These @var{ACTION} functions are called with two arguments: the | 2581 | These @var{ACTION} functions are called with two arguments: the |
| 2211 | syntactic symbol for the brace, and the buffer position at which the | 2582 | syntactic symbol for the brace, and the buffer position at which the |
| 2212 | brace was inserted. The @var{ACTION} function is expected to return a | 2583 | brace was inserted. The @var{ACTION} function is expected to return a |
| 2213 | list containing some combination of @code{before} and @code{after}. The | 2584 | list containing some combination of @code{before} and @code{after}, |
| 2214 | function can also return @code{nil}. This return value has the normal | 2585 | including neither of them (i.e. @code{nil}). This return value has the |
| 2215 | brace hanging semantics. | 2586 | normal brace hanging semantics. |
| 2216 | 2587 | ||
| 2217 | As an example, @ccmode{} itself uses this feature to dynamically | 2588 | As an example, @ccmode{} itself uses this feature to dynamically |
| 2218 | determine the hanginess of braces which close ``do-while'' | 2589 | determine the hanginess of braces which close ``do-while'' |
| @@ -2279,23 +2650,22 @@ During the call to the brace hanging @var{ACTION} function, the variable | |||
| 2279 | @vindex hanging-colon-alist (c-) | 2650 | @vindex hanging-colon-alist (c-) |
| 2280 | Note that for symmetry, colon hanginess should be customizable by | 2651 | Note that for symmetry, colon hanginess should be customizable by |
| 2281 | allowing function symbols as @var{ACTION}s on the | 2652 | allowing function symbols as @var{ACTION}s on the |
| 2282 | @code{c-hanging-colon-alist} variable. Since no use has actually been | 2653 | @code{c-hanging-colon-alist} style variable. Since no use has actually |
| 2283 | found for this feature, it isn't currently implemented! | 2654 | been found for this feature, it isn't currently implemented! |
| 2284 | 2655 | ||
| 2285 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| 2286 | @node Customizing Semi-colons and Commas, Other Special Indentations, Custom Brace and Colon Hanging, Advanced Customizations | ||
| 2287 | @comment node-name, next, previous,up | ||
| 2288 | 2656 | ||
| 2289 | @subsection Customizing Semi-colons and Commas | 2657 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 2290 | @cindex Customizing Semi-colons and Commas | 2658 | @node Customizing Semi-colons and Commas, Other Special Indentations, Custom Brace and Colon Hanging, Advanced Customizations |
| 2659 | @comment node-name, next, previous, up | ||
| 2660 | @subsection Customizing Semi-colons and Commas | ||
| 2661 | @cindex customizing semi-colons and commas | ||
| 2291 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 2662 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 2292 | 2663 | ||
| 2293 | @cindex Customizing Semi-colons and Commas | ||
| 2294 | @vindex c-hanging-semi&comma-criteria | 2664 | @vindex c-hanging-semi&comma-criteria |
| 2295 | @vindex hanging-semi&comma-criteria (c-) | 2665 | @vindex hanging-semi&comma-criteria (c-) |
| 2296 | You can also customize the insertion of newlines after semi-colons and | 2666 | You can also customize the insertion of newlines after semi-colons and |
| 2297 | commas, when the auto-newline minor mode is enabled (see @ref{Minor | 2667 | commas, when the auto-newline minor mode is enabled (@pxref{Minor |
| 2298 | Modes}). This is controlled by the variable | 2668 | Modes}). This is controlled by the style variable |
| 2299 | @code{c-hanging-semi&comma-criteria}, which contains a list of functions | 2669 | @code{c-hanging-semi&comma-criteria}, which contains a list of functions |
| 2300 | that are called in the order they appear. Each function is called with | 2670 | that are called in the order they appear. Each function is called with |
| 2301 | zero arguments, and is expected to return one of the following values: | 2671 | zero arguments, and is expected to return one of the following values: |
| @@ -2347,39 +2717,37 @@ list. | |||
| 2347 | @findex c-semi&comma-no-newlines-for-oneline-inliners | 2717 | @findex c-semi&comma-no-newlines-for-oneline-inliners |
| 2348 | @findex semi&comma-inside-parenlist (c-) | 2718 | @findex semi&comma-inside-parenlist (c-) |
| 2349 | @findex semi&comma-no-newlines-for-oneline-inliners (c-) | 2719 | @findex semi&comma-no-newlines-for-oneline-inliners (c-) |
| 2350 | The default value of @code{c-hanging-semi&comma-criteria} is a list | 2720 | The function @code{c-semi&comma-inside-parenlist} is what prevents |
| 2351 | containing just the function @code{c-semi&comma-inside-parenlist}, which | 2721 | newlines from being inserted inside the parenthesis list of @code{for} |
| 2352 | suppresses newlines after semicolons inside parenthesis lists | 2722 | statements. In addition to |
| 2353 | (e.g. @code{for}-loops). In addition to | ||
| 2354 | @code{c-semi&comma-no-newlines-before-nonblanks} described above, | 2723 | @code{c-semi&comma-no-newlines-before-nonblanks} described above, |
| 2355 | @ccmode{} also comes with the criteria function | 2724 | @ccmode{} also comes with the criteria function |
| 2356 | @code{c-semi&comma-no-newlines-for-oneline-inliners}, which suppresses | 2725 | @code{c-semi&comma-no-newlines-for-oneline-inliners}, which suppresses |
| 2357 | newlines after semicolons inside one-line inline method definitions | 2726 | newlines after semicolons inside one-line inline method definitions |
| 2358 | (i.e. in C++ or Java). | 2727 | (i.e. in C++ or Java). |
| 2359 | 2728 | ||
| 2360 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| 2361 | @node Other Special Indentations, , Customizing Semi-colons and Commas, Advanced Customizations | ||
| 2362 | @comment node-name, next, previous,up | ||
| 2363 | 2729 | ||
| 2364 | @subsection Other Special Indentations | 2730 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 2365 | @cindex Customizing Semi-colons and Commas | 2731 | @node Other Special Indentations, , Customizing Semi-colons and Commas, Advanced Customizations |
| 2732 | @comment node-name, next, previous, up | ||
| 2733 | @subsection Other Special Indentations | ||
| 2366 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 2734 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 2367 | 2735 | ||
| 2368 | @vindex c-label-minimum-indentation | 2736 | @vindex c-label-minimum-indentation |
| 2369 | @vindex label-minimum-indentation (c-) | 2737 | @vindex label-minimum-indentation (c-) |
| 2370 | In @samp{gnu} style (see @ref{Built-in Styles}), a minimum indentation | 2738 | In @samp{gnu} style (@pxref{Built-in Styles}), a minimum indentation |
| 2371 | is imposed on lines inside top-level constructs. This minimum | 2739 | is imposed on lines inside top-level constructs. This minimum |
| 2372 | indentation is controlled by the variable | 2740 | indentation is controlled by the style variable |
| 2373 | @code{c-label-minimum-indentation}. The default value for this variable | 2741 | @code{c-label-minimum-indentation}. The default value for this variable |
| 2374 | is 1. | 2742 | is 1. |
| 2375 | 2743 | ||
| 2376 | @vindex c-special-indent-hook | 2744 | @vindex c-special-indent-hook |
| 2377 | @vindex special-indent-hook (c-) | 2745 | @vindex special-indent-hook (c-) |
| 2378 | One other customization variable is available in @ccmode{}: | 2746 | One other customization variable is available in @ccmode{}: The style |
| 2379 | @code{c-special-indent-hook}. This is a standard hook variable that is | 2747 | variable @code{c-special-indent-hook}. This is a standard hook variable |
| 2380 | called after every line is indented by @ccmode{}. You can use it | 2748 | that is called after every line is indented by @ccmode{}. You can use |
| 2381 | to do any special indentation or line adjustments your style dictates, | 2749 | it to do any special indentation or line adjustments your style |
| 2382 | such as adding extra indentation to constructors or destructor | 2750 | dictates, such as adding extra indentation to constructors or destructor |
| 2383 | declarations in a class definition, etc. Note however, that you should | 2751 | declarations in a class definition, etc. Note however, that you should |
| 2384 | not change point or mark inside your @code{c-special-indent-hook} | 2752 | not change point or mark inside your @code{c-special-indent-hook} |
| 2385 | functions (i.e. you'll probably want to wrap your function in a | 2753 | functions (i.e. you'll probably want to wrap your function in a |
| @@ -2398,7 +2766,6 @@ That way, the current setting for the buffer local value of | |||
| 2398 | @vindex c-indent-comments-syntactically-p | 2766 | @vindex c-indent-comments-syntactically-p |
| 2399 | @vindex indent-comments-syntactically-p (c-) | 2767 | @vindex indent-comments-syntactically-p (c-) |
| 2400 | @vindex comment-column | 2768 | @vindex comment-column |
| 2401 | |||
| 2402 | Normally, the standard Emacs command @kbd{M-;} | 2769 | Normally, the standard Emacs command @kbd{M-;} |
| 2403 | (@code{indent-for-comment}) will indent comment only lines to | 2770 | (@code{indent-for-comment}) will indent comment only lines to |
| 2404 | @code{comment-column}. Some users however, prefer that @kbd{M-;} act | 2771 | @code{comment-column}. Some users however, prefer that @kbd{M-;} act |
| @@ -2411,147 +2778,166 @@ default), @kbd{M-;} indents comment-only lines to @code{comment-column}, | |||
| 2411 | otherwise, they are indented just as they would be if @kbd{TAB} were | 2778 | otherwise, they are indented just as they would be if @kbd{TAB} were |
| 2412 | typed. | 2779 | typed. |
| 2413 | 2780 | ||
| 2414 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 2781 | Note that this has no effect for comment lines that are inserted with |
| 2415 | @node Syntactic Symbols, Performance Issues, Customizing Indentation, Top | 2782 | @kbd{M-;} at the end of regular code lines. These comments will always |
| 2416 | @comment node-name, next, previous,up | 2783 | start at @code{comment-column}. |
| 2784 | |||
| 2417 | 2785 | ||
| 2418 | @chapter Syntactic Symbols | 2786 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 2419 | @cindex Syntactic Symbols | 2787 | @node Syntactic Symbols, Indentation Functions, Customizing Indentation, Top |
| 2788 | @comment node-name, next, previous, up | ||
| 2789 | @chapter Syntactic Symbols | ||
| 2790 | @cindex syntactic symbols | ||
| 2420 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 2791 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 2421 | 2792 | ||
| 2422 | @vindex c-offsets-alist | 2793 | @vindex c-offsets-alist |
| 2423 | @vindex offsets-alist (c-) | 2794 | @vindex offsets-alist (c-) |
| 2424 | |||
| 2425 | Here is a complete list of the recognized syntactic symbols as described | 2795 | Here is a complete list of the recognized syntactic symbols as described |
| 2426 | in the @code{c-offsets-alist} variable, along with a brief description. | 2796 | in the @code{c-offsets-alist} style variable, along with a brief |
| 2427 | More detailed descriptions follow below. | 2797 | description. More detailed descriptions follow. |
| 2428 | 2798 | ||
| 2429 | @itemize @bullet | 2799 | @table @code |
| 2430 | @item | 2800 | @item string |
| 2431 | @code{string} --- inside multi-line string | 2801 | Inside a multi-line string. |
| 2432 | @item | 2802 | @item c |
| 2433 | @code{c} --- inside a multi-line C style block comment | 2803 | Inside a multi-line C style block comment. |
| 2434 | @item | 2804 | @item defun-open |
| 2435 | @code{defun-open} --- brace that opens a function definition | 2805 | Brace that opens a top-level function definition. |
| 2436 | @item | 2806 | @item defun-close |
| 2437 | @code{defun-close} --- brace that closes a function definition | 2807 | Brace that closes a top-level function definition. |
| 2438 | @item | 2808 | @item defun-block-intro |
| 2439 | @code{defun-block-intro} --- the first line in a top-level defun | 2809 | The first line in a top-level defun. |
| 2440 | @item | 2810 | @item class-open |
| 2441 | @code{class-open} --- brace that opens a class definition | 2811 | Brace that opens a class definition. |
| 2442 | @item | 2812 | @item class-close |
| 2443 | @code{class-close} --- brace that closes a class definition | 2813 | Brace that closes a class definition. |
| 2444 | @item | 2814 | @item inline-open |
| 2445 | @code{inline-open} --- brace that opens an in-class inline method | 2815 | Brace that opens an in-class inline method. |
| 2446 | @item | 2816 | @item inline-close |
| 2447 | @code{inline-close} --- brace that closes an in-class inline method | 2817 | Brace that closes an in-class inline method. |
| 2448 | @item | 2818 | @item func-decl-cont |
| 2449 | @code{func-decl-cont} --- the region between a function definition's | 2819 | The region between a function definition's argument list and the |
| 2450 | argument list and the function opening brace (excluding K&R argument | 2820 | function opening brace (excluding K&R argument declarations). In C, you |
| 2451 | declarations). In C, you cannot put anything but whitespace and comments | 2821 | cannot put anything but whitespace and comments in this region, however |
| 2452 | between them; in C++ and Java, @code{throws} declarations and other | 2822 | in C++ and Java, @code{throws} declarations and other things can appear |
| 2453 | things can appear in this context. | 2823 | here. |
| 2454 | @item | 2824 | @item knr-argdecl-intro |
| 2455 | @code{knr-argdecl-intro} --- first line of a K&R C argument declaration | 2825 | First line of a K&R C argument declaration. |
| 2456 | @item | 2826 | @item knr-argdecl |
| 2457 | @code{knr-argdecl} --- subsequent lines in a K&R C argument declaration | 2827 | Subsequent lines in a K&R C argument declaration. |
| 2458 | @item | 2828 | @item topmost-intro |
| 2459 | @code{topmost-intro} --- the first line in a topmost definition | 2829 | The first line in a ``topmost'' definition. |
| 2460 | @item | 2830 | @item topmost-intro-cont |
| 2461 | @code{topmost-intro-cont} --- topmost definition continuation lines | 2831 | Topmost definition continuation lines. |
| 2462 | @item | 2832 | @item member-init-intro |
| 2463 | @code{member-init-intro} --- first line in a member initialization list | 2833 | First line in a member initialization list. |
| 2464 | @item | 2834 | @item member-init-cont |
| 2465 | @code{member-init-cont} --- subsequent member initialization list lines | 2835 | Subsequent member initialization list lines. |
| 2466 | @item | 2836 | @item inher-intro |
| 2467 | @code{inher-intro} --- first line of a multiple inheritance list | 2837 | First line of a multiple inheritance list. |
| 2468 | @item | 2838 | @item inher-cont |
| 2469 | @code{inher-cont} --- subsequent multiple inheritance lines | 2839 | Subsequent multiple inheritance lines. |
| 2470 | @item | 2840 | @item block-open |
| 2471 | @code{block-open} --- statement block open brace | 2841 | Statement block open brace. |
| 2472 | @item | 2842 | @item block-close |
| 2473 | @code{block-close} --- statement block close brace | 2843 | Statement block close brace. |
| 2474 | @item | 2844 | @item brace-list-open |
| 2475 | @code{brace-list-open} --- open brace of an enum or static array list | 2845 | Open brace of an enum or static array list. |
| 2476 | @item | 2846 | @item brace-list-close |
| 2477 | @code{brace-list-close} --- close brace of an enum or static array list | 2847 | Close brace of an enum or static array list. |
| 2478 | @item | 2848 | @item brace-list-intro |
| 2479 | @code{brace-list-intro} --- first line in an enum or static array list | 2849 | First line in an enum or static array list. |
| 2480 | @item | 2850 | @item brace-list-entry |
| 2481 | @code{brace-list-entry} --- subsequent lines in an enum or static array list | 2851 | Subsequent lines in an enum or static array list. |
| 2482 | @item | 2852 | @item brace-entry-open |
| 2483 | @code{statement} --- a C statement | 2853 | Subsequent lines in an enum or static array list where the line begins |
| 2484 | @item | 2854 | with an open brace. |
| 2485 | @code{statement-cont} --- a continuation of a C statement | 2855 | @item statement |
| 2486 | @item | 2856 | A statement. |
| 2487 | @code{statement-block-intro} --- the first line in a new statement block | 2857 | @item statement-cont |
| 2488 | @item | 2858 | A continuation of a statement. |
| 2489 | @code{statement-case-intro} --- the first line in a case `block' | 2859 | @item statement-block-intro |
| 2490 | @item | 2860 | The first line in a new statement block. |
| 2491 | @code{statement-case-open} --- the first line in a case block starting | 2861 | @item statement-case-intro |
| 2492 | with brace | 2862 | The first line in a case block. |
| 2493 | @item | 2863 | @item statement-case-open |
| 2494 | @code{substatement} --- the first line after a conditional | 2864 | The first line in a case block that starts with a brace. |
| 2495 | @item | 2865 | @item substatement |
| 2496 | @code{substatement-open} --- the brace that opens a substatement block | 2866 | The first line after a conditional or loop construct. |
| 2497 | @item | 2867 | @item substatement-open |
| 2498 | @code{case-label} --- a case or default label | 2868 | The brace that opens a substatement block. |
| 2499 | @item | 2869 | @item case-label |
| 2500 | @code{access-label} --- C++ access control label | 2870 | A @code{case} or @code{default} label. |
| 2501 | @item | 2871 | @item access-label |
| 2502 | @code{label} --- any non-special C label | 2872 | C++ access control label. |
| 2503 | @item | 2873 | @item label |
| 2504 | @code{do-while-closure} --- the `while' that ends a | 2874 | Any non-special C label. |
| 2505 | @code{do}-@code{while} construct | 2875 | @item do-while-closure |
| 2506 | @item | 2876 | The @code{while} line that ends a @code{do}-@code{while} construct. |
| 2507 | @code{else-clause} --- the `else' of an @code{if}-@code{else} construct | 2877 | @item else-clause |
| 2508 | @item | 2878 | The @code{else} line of an @code{if}-@code{else} construct. |
| 2509 | @code{comment-intro} --- a line containing only a comment introduction | 2879 | @item catch-clause |
| 2510 | @item | 2880 | The @code{catch} or @code{finally} (in Java) line of a |
| 2511 | @code{arglist-intro} --- the first line in an argument list | 2881 | @code{try}-@code{catch} construct. |
| 2512 | @item | 2882 | @item comment-intro |
| 2513 | @code{arglist-cont} --- subsequent argument list lines when no arguments | 2883 | A line containing only a comment introduction. |
| 2514 | follow on the same line as the the arglist opening paren | 2884 | @item arglist-intro |
| 2515 | @item | 2885 | The first line in an argument list. |
| 2516 | @code{arglist-cont-nonempty} --- subsequent argument list lines when at | 2886 | @item arglist-cont |
| 2517 | least one argument follows on the same line as the arglist opening paren | 2887 | Subsequent argument list lines when no arguments follow on the same line |
| 2518 | @item | 2888 | as the the arglist opening paren. |
| 2519 | @code{arglist-close} --- the solo close paren of an argument list | 2889 | @item arglist-cont-nonempty |
| 2520 | @item | 2890 | Subsequent argument list lines when at least one argument follows on the |
| 2521 | @code{stream-op} --- lines continuing a stream operator | 2891 | same line as the arglist opening paren. |
| 2522 | @item | 2892 | @item arglist-close |
| 2523 | @code{inclass} --- the line is nested inside a class definition | 2893 | The solo close paren of an argument list. |
| 2524 | @item | 2894 | @item stream-op |
| 2525 | @code{cpp-macro} --- the start of a C preprocessor macro definition | 2895 | Lines continuing a stream operator (C++ only). |
| 2526 | @item | 2896 | @item inclass |
| 2527 | @code{cpp-macro-cont} --- subsequent lines of a multi-line C | 2897 | The line is nested inside a class definition. |
| 2528 | preprocessor macro definition | 2898 | @item cpp-macro |
| 2529 | @item | 2899 | The start of a C preprocessor macro definition. |
| 2530 | @code{friend} --- a C++ friend declaration | 2900 | @item cpp-macro-cont |
| 2531 | @item | 2901 | Subsequent lines of a multi-line C preprocessor macro definition. |
| 2532 | @code{objc-method-intro} --- the first line of an Objective-C method definition | 2902 | @item friend |
| 2533 | @item | 2903 | A C++ friend declaration. |
| 2534 | @code{objc-method-args-cont} --- lines continuing an Objective-C method | 2904 | @item objc-method-intro |
| 2535 | definition | 2905 | The first line of an Objective-C method. definition. |
| 2536 | @item | 2906 | @item objc-method-args-cont |
| 2537 | @code{objc-method-call-cont} --- lines continuing an Objective-C method call | 2907 | Lines continuing an Objective-C method. definition |
| 2538 | @item | 2908 | @item objc-method-call-cont |
| 2539 | @code{extern-lang-open} --- brace that opens an external language block | 2909 | Lines continuing an Objective-C method call. |
| 2540 | @item | 2910 | @item extern-lang-open |
| 2541 | @code{extern-lang-close} --- brace that closes an external language block | 2911 | Brace that opens an external language block. |
| 2542 | @item | 2912 | @item extern-lang-close |
| 2543 | @code{inextern-lang} --- analogous to `inclass' syntactic symbol, but | 2913 | Brace that closes an external language block. |
| 2544 | used inside external language blocks (e.g. @code{extern "C" @{}). | 2914 | @item inextern-lang |
| 2545 | @item | 2915 | Analogous to @code{inclass} syntactic symbol, but used inside external |
| 2546 | @code{namespace-open} --- brace that opens a C++ namespace block. | 2916 | language blocks (e.g. @code{extern "C" @{}). |
| 2547 | @item | 2917 | @item namespace-open |
| 2548 | @code{namespace-close} --- brace that closes a C++ namespace block. | 2918 | Brace that opens a C++ namespace block. |
| 2549 | @item | 2919 | @item namespace-close |
| 2550 | @code{innamespace} --- analogous to `inextern-lang' syntactic symbol, | 2920 | Brace that closes a C++ namespace block. |
| 2551 | but used inside C++ namespace blocks. | 2921 | @item innamespace |
| 2552 | @item | 2922 | Analogous to @code{inextern-lang} syntactic symbol, but used inside C++ |
| 2553 | @code{template-args-cont} --- C++ template argument list continuations | 2923 | namespace blocks. |
| 2554 | @end itemize | 2924 | @item template-args-cont |
| 2925 | C++ template argument list continuations. | ||
| 2926 | @item inlambda | ||
| 2927 | Analogous to @code{inclass} syntactic symbol, but used inside lambda | ||
| 2928 | (i.e. anonymous) functions. Only used in Pike mode. | ||
| 2929 | @item lambda-intro-cont | ||
| 2930 | Lines continuing the header of a lambda function, i.e. between the | ||
| 2931 | @code{lambda} keyword and the function body. Only used in Pike mode. | ||
| 2932 | @item inexpr-statement | ||
| 2933 | A statement block inside an expression. The gcc C extension of this is | ||
| 2934 | recognized. It's also used for the special functions that takes a | ||
| 2935 | statement block as an argument in Pike. | ||
| 2936 | @item inexpr-class | ||
| 2937 | A class definition inside an expression. This is used for anonymous | ||
| 2938 | classes in Java. It's also used for anonymous array initializers in | ||
| 2939 | Java. | ||
| 2940 | @end table | ||
| 2555 | 2941 | ||
| 2556 | @cindex -open syntactic symbols | 2942 | @cindex -open syntactic symbols |
| 2557 | @cindex -close syntactic symbols | 2943 | @cindex -close syntactic symbols |
| @@ -2569,7 +2955,6 @@ that represent these lines will contain the suffix @code{-intro} or | |||
| 2569 | line which is the first of a particular brace block construct will | 2955 | line which is the first of a particular brace block construct will |
| 2570 | contain the suffix @code{-block-intro}. | 2956 | contain the suffix @code{-block-intro}. |
| 2571 | 2957 | ||
| 2572 | @kindex C-c C-s | ||
| 2573 | Let's look at some examples to understand how this works. Remember that | 2958 | Let's look at some examples to understand how this works. Remember that |
| 2574 | you can check the syntax of any line by using @kbd{C-c C-s}. | 2959 | you can check the syntax of any line by using @kbd{C-c C-s}. |
| 2575 | @example | 2960 | @example |
| @@ -2597,7 +2982,8 @@ Line 1 shows a @code{topmost-intro} since it is the first line that | |||
| 2597 | introduces a top-level construct. Line 2 is a continuation of the | 2982 | introduces a top-level construct. Line 2 is a continuation of the |
| 2598 | top-level construct introduction so it has the syntax | 2983 | top-level construct introduction so it has the syntax |
| 2599 | @code{topmost-intro-cont}. Line 3 shows a @code{defun-open} since it is | 2984 | @code{topmost-intro-cont}. Line 3 shows a @code{defun-open} since it is |
| 2600 | the brace that opens a top-level function definition. Line 9 is a | 2985 | the brace that opens a top-level function definition. Line 9 is the |
| 2986 | corresponding | ||
| 2601 | @code{defun-close} since it contains the brace that closes the top-level | 2987 | @code{defun-close} since it contains the brace that closes the top-level |
| 2602 | function definition. Line 4 is a @code{defun-block-intro}, i.e. it is | 2988 | function definition. Line 4 is a @code{defun-block-intro}, i.e. it is |
| 2603 | the first line of a brace-block, enclosed in a | 2989 | the first line of a brace-block, enclosed in a |
| @@ -2664,7 +3050,7 @@ Hitting @kbd{C-c C-s} on line 5 shows the following analysis: | |||
| 2664 | @example | 3050 | @example |
| 2665 | @group | 3051 | @group |
| 2666 | 3052 | ||
| 2667 | @code{((inclass . 1) (access-label . 67))} | 3053 | @code{((inclass . 58) (access-label . 67))} |
| 2668 | 3054 | ||
| 2669 | @end group | 3055 | @end group |
| 2670 | @end example | 3056 | @end example |
| @@ -2703,7 +3089,7 @@ Line 11's analysis is a bit more complicated: | |||
| 2703 | @example | 3089 | @example |
| 2704 | @group | 3090 | @group |
| 2705 | 3091 | ||
| 2706 | @code{((inclass . 1) (inline-open))} | 3092 | @code{((inclass . 58) (inline-open))} |
| 2707 | 3093 | ||
| 2708 | @end group | 3094 | @end group |
| 2709 | @end example | 3095 | @end example |
| @@ -2816,18 +3202,23 @@ substatement block. It is given the syntax @code{block-close}, | |||
| 2816 | as are lines 11 and 14. | 3202 | as are lines 11 and 14. |
| 2817 | 3203 | ||
| 2818 | @cindex else-clause syntactic symbol | 3204 | @cindex else-clause syntactic symbol |
| 2819 | @cindex substatement syntactic symbol | 3205 | @cindex catch-clause syntactic symbol |
| 2820 | Line 9 is a little different --- since it contains the keyword | 3206 | Line 9 is a little different --- since it contains the keyword |
| 2821 | @code{else} matching the @code{if} statement introduced on line 5, it is | 3207 | @code{else} matching the @code{if} statement introduced on line 5, it is |
| 2822 | given the @code{else-clause} syntax. Note also that line 10 is slightly | 3208 | given the @code{else-clause} syntax. The @code{try}-@code{catch} |
| 2823 | different too. Because @code{else} is considered a conditional | 3209 | constructs in C++ and Java are treated this way too, with the only |
| 2824 | introducing keyword @footnote{The list of conditional keywords are (in | 3210 | difference that the @code{catch}, and in Java also @code{finally}, is |
| 2825 | C, C++, Objective-C, and Java): @code{for}, @code{if}, @code{do}, | 3211 | marked with @code{catch-clause}. |
| 2826 | @code{else}, @code{while}, and @code{switch}. C++ and Java have two | 3212 | |
| 2827 | additional conditional keywords: @code{try} and @code{catch}. Java also | 3213 | @cindex substatement syntactic symbol |
| 2828 | has the @code{finally} and @code{synchronized} keywords.}, and because | 3214 | Line 10 is also slightly different. Because @code{else} is considered a |
| 2829 | the following substatement is not a brace block, line 10 is assigned the | 3215 | conditional introducing keyword @footnote{The list of conditional |
| 2830 | @code{substatement} syntax. | 3216 | keywords are (in C, C++, Objective-C, Java, and Pike): @code{for}, |
| 3217 | @code{if}, @code{do}, @code{else}, @code{while}, and @code{switch}. C++ | ||
| 3218 | and Java have two additional conditional keywords: @code{try} and | ||
| 3219 | @code{catch}. Java also has the @code{finally} and @code{synchronized} | ||
| 3220 | keywords.}, and because the following substatement is not a brace block, | ||
| 3221 | line 10 is assigned the @code{substatement} syntax. | ||
| 2831 | 3222 | ||
| 2832 | @cindex do-while-closure syntactic symbol | 3223 | @cindex do-while-closure syntactic symbol |
| 2833 | One other difference is seen on line 15. The @code{while} construct | 3224 | One other difference is seen on line 15. The @code{while} construct |
| @@ -2873,7 +3264,9 @@ block --- it is given @code{statement-case-open} syntax. | |||
| 2873 | There are a set of syntactic symbols that are used to recognize | 3264 | There are a set of syntactic symbols that are used to recognize |
| 2874 | constructs inside of brace lists. A brace list is defined as an | 3265 | constructs inside of brace lists. A brace list is defined as an |
| 2875 | @code{enum} or aggregate initializer list, such as might statically | 3266 | @code{enum} or aggregate initializer list, such as might statically |
| 2876 | initialize an array of structs. For example: | 3267 | initialize an array of structs. The three special aggregate constructs |
| 3268 | in Pike, @code{(@{ @})}, @code{([ ])} and @code{(< >)}, are treated as | ||
| 3269 | brace lists too. An example: | ||
| 2877 | @example | 3270 | @example |
| 2878 | @group | 3271 | @group |
| 2879 | 3272 | ||
| @@ -2898,6 +3291,35 @@ Following convention, line 2 in this example is assigned | |||
| 2898 | @code{brace-list-entry} syntax, as would all subsequent lines in this | 3291 | @code{brace-list-entry} syntax, as would all subsequent lines in this |
| 2899 | initializer list. | 3292 | initializer list. |
| 2900 | 3293 | ||
| 3294 | @cindex brace-entry-open syntactic symbol | ||
| 3295 | Your static initializer might be initializing nested structures, for | ||
| 3296 | example: | ||
| 3297 | @example | ||
| 3298 | @group | ||
| 3299 | |||
| 3300 | 1: struct intpairs[] = | ||
| 3301 | 2: @{ | ||
| 3302 | 3: @{ 1, 2 @}, | ||
| 3303 | 4: @{ | ||
| 3304 | 5: 3, | ||
| 3305 | 6: 4 | ||
| 3306 | 7: @} | ||
| 3307 | 8: @{ 1, | ||
| 3308 | 9: 2 @}, | ||
| 3309 | 10: @{ 3, 4 @} | ||
| 3310 | 11: @} | ||
| 3311 | |||
| 3312 | @end group | ||
| 3313 | @end example | ||
| 3314 | |||
| 3315 | Here, you've already seen the analysis of lines 1, 2, 3, and 11. On | ||
| 3316 | line 4, things get interesting; this line is assigned | ||
| 3317 | @code{brace-entry-open} syntactic symbol because it's a bracelist entry | ||
| 3318 | line that starts with an open brace. Lines 5 and 6 (and line 9) are | ||
| 3319 | pretty standard, and line 7 is a @code{brace-list-close} as you'd | ||
| 3320 | expect. Once again, line 8 is assigned as @code{brace-entry-open} as is | ||
| 3321 | line 10. | ||
| 3322 | |||
| 2901 | External language definition blocks also have their own syntactic | 3323 | External language definition blocks also have their own syntactic |
| 2902 | symbols. In this example: | 3324 | symbols. In this example: |
| 2903 | @example | 3325 | @example |
| @@ -2935,9 +3357,9 @@ symbols. In this example: | |||
| 2935 | @end group | 3357 | @end group |
| 2936 | @end example | 3358 | @end example |
| 2937 | 3359 | ||
| 2938 | @cindex namespace-open syntactic-symbol | 3360 | @cindex namespace-open syntactic symbol |
| 2939 | @cindex namespace-close syntactic-symbol | 3361 | @cindex namespace-close syntactic symbol |
| 2940 | @cindex innamespace syntactic-symbol | 3362 | @cindex innamespace syntactic symbol |
| 2941 | @noindent | 3363 | @noindent |
| 2942 | line 2 is given the @code{namespace-open} syntax, while line 4 is given | 3364 | line 2 is given the @code{namespace-open} syntax, while line 4 is given |
| 2943 | the @code{namespace-close} syntax. The analysis for line 3 yields: | 3365 | the @code{namespace-close} syntax. The analysis for line 3 yields: |
| @@ -3022,7 +3444,6 @@ covered are illustrated by this C++ example: | |||
| 3022 | @end group | 3444 | @end group |
| 3023 | @end example | 3445 | @end example |
| 3024 | 3446 | ||
| 3025 | @cindex modifier syntactic symbol | ||
| 3026 | The lines to note in this example include: | 3447 | The lines to note in this example include: |
| 3027 | 3448 | ||
| 3028 | @itemize @bullet | 3449 | @itemize @bullet |
| @@ -3075,7 +3496,7 @@ line 17, assigned @code{stream-op} syntax. | |||
| 3075 | @cindex multi-line macros | 3496 | @cindex multi-line macros |
| 3076 | @cindex syntactic whitespace | 3497 | @cindex syntactic whitespace |
| 3077 | Multi-line C preprocessor macros are now (somewhat) supported. At least | 3498 | Multi-line C preprocessor macros are now (somewhat) supported. At least |
| 3078 | CC Mode now recognizes the fact that it is inside a multi-line macro, | 3499 | @ccmode{} now recognizes the fact that it is inside a multi-line macro, |
| 3079 | and it properly skips such macros as syntactic whitespace. In this | 3500 | and it properly skips such macros as syntactic whitespace. In this |
| 3080 | example: | 3501 | example: |
| 3081 | @example | 3502 | @example |
| @@ -3120,6 +3541,91 @@ Here, line 1 is assigned @code{objc-method-intro} syntax, and line 2 is | |||
| 3120 | assigned @code{objc-method-args-cont} syntax. Lines 5 and 6 are both | 3541 | assigned @code{objc-method-args-cont} syntax. Lines 5 and 6 are both |
| 3121 | assigned @code{objc-method-call-cont} syntax. | 3542 | assigned @code{objc-method-call-cont} syntax. |
| 3122 | 3543 | ||
| 3544 | Java has a concept of anonymous classes, which may look something like | ||
| 3545 | this: | ||
| 3546 | @example | ||
| 3547 | @group | ||
| 3548 | |||
| 3549 | 1: public void watch(Observable o) @{ | ||
| 3550 | 2: o.addObserver(new Observer() @{ | ||
| 3551 | 3: public void update(Observable o, Object arg) @{ | ||
| 3552 | 4: history.addElement(arg); | ||
| 3553 | 5: @} | ||
| 3554 | 6: @}); | ||
| 3555 | 7: @} | ||
| 3556 | |||
| 3557 | @end group | ||
| 3558 | @end example | ||
| 3559 | |||
| 3560 | @cindex inexpr-class syntactic symbol | ||
| 3561 | The brace following the @code{new} operator opens the anonymous class. | ||
| 3562 | Lines 3 and 6 are assigned the @code{inexpr-class} syntax, besides the | ||
| 3563 | @code{inclass} symbol used in normal classes. Thus, the class will be | ||
| 3564 | indented just like a normal class, with the added indentation given to | ||
| 3565 | @code{inexpr-class}. | ||
| 3566 | |||
| 3567 | There are a few occasions where a statement block may be used inside an | ||
| 3568 | expression. One is in C code using the gcc extension for this, e.g: | ||
| 3569 | @example | ||
| 3570 | @group | ||
| 3571 | |||
| 3572 | 1: int res = (@{ | ||
| 3573 | 2: int y = foo (); int z; | ||
| 3574 | 3: if (y > 0) z = y; else z = - y; | ||
| 3575 | 4: z; | ||
| 3576 | 5: @}); | ||
| 3577 | |||
| 3578 | @end group | ||
| 3579 | @end example | ||
| 3580 | |||
| 3581 | @cindex inexpr-statement syntactic symbol | ||
| 3582 | Lines 2 and 5 get the @code{inexpr-statement} syntax, besides the | ||
| 3583 | symbols they'd get in a normal block. Therefore, the indentation put on | ||
| 3584 | @code{inexpr-statement} is added to the normal statement block | ||
| 3585 | indentation. | ||
| 3586 | |||
| 3587 | In Pike code, there are a few other situations where blocks occur inside | ||
| 3588 | statements, as illustrated here: | ||
| 3589 | @example | ||
| 3590 | @group | ||
| 3591 | |||
| 3592 | 1: array itgob() | ||
| 3593 | 2: @{ | ||
| 3594 | 3: string s = map (backtrace()[-2][3..], | ||
| 3595 | 4: lambda | ||
| 3596 | 5: (mixed arg) | ||
| 3597 | 6: @{ | ||
| 3598 | 7: return sprintf ("%t", arg); | ||
| 3599 | 8: @}) * ", " + "\n"; | ||
| 3600 | 9: return catch @{ | ||
| 3601 | 10: write (s + "\n"); | ||
| 3602 | 11: @}; | ||
| 3603 | 12: @} | ||
| 3604 | |||
| 3605 | @end group | ||
| 3606 | @end example | ||
| 3607 | |||
| 3608 | @cindex inlambda syntactic symbol | ||
| 3609 | @cindex lambda-intro-cont syntactic symbol | ||
| 3610 | Lines 4 through 8 contain a lambda function, which @ccmode{} recognizes | ||
| 3611 | by the @code{lambda} keyword. If the function argument list is put | ||
| 3612 | on a line of its own, as in line 5, it gets the @code{lambda-intro-cont} | ||
| 3613 | syntax. The function body is handled as an inline method body, with the | ||
| 3614 | addition of the @code{inlambda} syntactic symbol. This means that line | ||
| 3615 | 6 gets @code{inlambda} and @code{inline-open}, and line 8 gets | ||
| 3616 | @code{inline-close}@footnote{You might wonder why it doesn't get | ||
| 3617 | @code{inlambda} too. It's because the closing brace is relative to the | ||
| 3618 | opening brace, which stands on its own line in this example. If the | ||
| 3619 | opening brace was hanging on the previous line, then the closing brace | ||
| 3620 | would get the @code{inlambda} syntax too to be indented correctly.}. | ||
| 3621 | |||
| 3622 | @cindex inexpr-statement syntactic symbol | ||
| 3623 | On line 9, @code{catch} is a special function taking a statement block | ||
| 3624 | as its argument. The block is handled as an in-expression statement | ||
| 3625 | with the @code{inexpr-statement} syntax, just like the gcc extended C | ||
| 3626 | example above. The other similar special function, @code{gauge}, is | ||
| 3627 | handled like this too. | ||
| 3628 | |||
| 3123 | @cindex knr-argdecl-intro syntactic symbol | 3629 | @cindex knr-argdecl-intro syntactic symbol |
| 3124 | @cindex knr-argdecl syntactic symbol | 3630 | @cindex knr-argdecl syntactic symbol |
| 3125 | Two other syntactic symbols can appear in old style, non-prototyped C | 3631 | Two other syntactic symbols can appear in old style, non-prototyped C |
| @@ -3143,12 +3649,464 @@ given the @code{knr-argdecl-intro} syntactic symbol. Subsequent lines | |||
| 3143 | (i.e. lines 3 and 4 in this example), are given @code{knr-argdecl} | 3649 | (i.e. lines 3 and 4 in this example), are given @code{knr-argdecl} |
| 3144 | syntax. | 3650 | syntax. |
| 3145 | 3651 | ||
| 3652 | |||
| 3653 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| 3654 | @node Indentation Functions, Performance Issues, Syntactic Symbols, Top | ||
| 3655 | @comment node-name, next, previous, up | ||
| 3656 | @chapter Indentation Functions | ||
| 3657 | @cindex indentation functions | ||
| 3658 | @cindex line-up functions | ||
| 3146 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 3659 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 3147 | @node Performance Issues, Frequently Asked Questions, Syntactic Symbols, Top | ||
| 3148 | @comment node-name, next, previous,up | ||
| 3149 | 3660 | ||
| 3150 | @chapter Performance Issues | 3661 | Often there are cases when a simple offset setting on a syntactic symbol |
| 3151 | @cindex Performance Issues | 3662 | isn't enough to get the desired indentation. Therefore, it's also |
| 3663 | possible to use a @dfn{indentation function} (a.k.a. line-up function) | ||
| 3664 | for a syntactic symbol. | ||
| 3665 | |||
| 3666 | @ccmode{} comes with many predefined indentation functions for common | ||
| 3667 | situations. If none of these does what you want, you can write your | ||
| 3668 | own, see @ref{Custom Indentation Functions}. If you do, it's probably a | ||
| 3669 | good idea to start working from one of these predefined functions, they | ||
| 3670 | can be found in the file @file{cc-align.el}. | ||
| 3671 | |||
| 3672 | For every function below there is a ``works with'' list that indicates | ||
| 3673 | which syntactic symbols the function is intended to be used with. | ||
| 3674 | |||
| 3675 | @macro workswith | ||
| 3676 | @emph{Works with:} | ||
| 3677 | @end macro | ||
| 3678 | @ifinfo | ||
| 3679 | @unmacro workswith | ||
| 3680 | @macro workswith | ||
| 3681 | Works with: | ||
| 3682 | @end macro | ||
| 3683 | @end ifinfo | ||
| 3684 | |||
| 3685 | @table @code | ||
| 3686 | |||
| 3687 | @findex c-lineup-arglist | ||
| 3688 | @findex lineup-arglist (c-) | ||
| 3689 | @item c-lineup-arglist | ||
| 3690 | Line up the current argument line under the first argument. | ||
| 3691 | |||
| 3692 | @workswith @code{arglist-cont-nonempty}. | ||
| 3693 | |||
| 3694 | @findex c-lineup-arglist-intro-after-paren | ||
| 3695 | @findex lineup-arglist-intro-after-paren (c-) | ||
| 3696 | @item c-lineup-arglist-intro-after-paren | ||
| 3697 | Line up a line just after the open paren of the surrounding paren or | ||
| 3698 | brace block. | ||
| 3699 | |||
| 3700 | @workswith @code{defun-block-intro}, @code{brace-list-intro}, | ||
| 3701 | @code{statement-block-intro}, @code{statement-case-intro}, | ||
| 3702 | @code{arglist-intro}. | ||
| 3703 | |||
| 3704 | @findex c-lineup-arglist-close-under-paren | ||
| 3705 | @findex lineup-arglist-close-under-paren (c-) | ||
| 3706 | @item c-lineup-arglist-close-under-paren | ||
| 3707 | Set e.g. your @code{arglist-close} syntactic symbol to this line-up | ||
| 3708 | function so that parentheses that close argument lists will line up | ||
| 3709 | under the parenthesis that opened the argument list. | ||
| 3710 | |||
| 3711 | @workswith @code{defun-close}, @code{class-close}, @code{inline-close}, | ||
| 3712 | @code{block-close}, @code{brace-list-close}, @code{arglist-close}, | ||
| 3713 | @code{extern-lang-close}, @code{namespace-close} (for most of these, a | ||
| 3714 | zero offset will normally produce the same result, though). | ||
| 3715 | |||
| 3716 | @findex c-lineup-close-paren | ||
| 3717 | @findex lineup-close-paren (c-) | ||
| 3718 | @item c-lineup-close-paren | ||
| 3719 | Line up the closing paren under its corresponding open paren if the | ||
| 3720 | open paren is followed by code. If the open paren ends its line, no | ||
| 3721 | indentation is added. E.g: | ||
| 3722 | @example | ||
| 3723 | @group | ||
| 3724 | |||
| 3725 | main (int, | ||
| 3726 | char ** | ||
| 3727 | ) // c-lineup-close-paren | ||
| 3728 | |||
| 3729 | @end group | ||
| 3730 | @end example | ||
| 3731 | @noindent | ||
| 3732 | and | ||
| 3733 | @example | ||
| 3734 | @group | ||
| 3735 | |||
| 3736 | main ( | ||
| 3737 | int, char ** | ||
| 3738 | ) // c-lineup-close-paren | ||
| 3739 | |||
| 3740 | @end group | ||
| 3741 | @end example | ||
| 3742 | |||
| 3743 | @workswith @code{defun-close}, @code{class-close}, @code{inline-close}, | ||
| 3744 | @code{block-close}, @code{brace-list-close}, @code{arglist-close}, | ||
| 3745 | @code{extern-lang-close}, @code{namespace-close}. | ||
| 3746 | |||
| 3747 | @findex c-lineup-streamop | ||
| 3748 | @findex lineup-streamop (c-) | ||
| 3749 | @item c-lineup-streamop | ||
| 3750 | Line up C++ stream operators (i.e. @samp{<<} and @samp{>>}). | ||
| 3751 | |||
| 3752 | @workswith @code{stream-op}. | ||
| 3753 | |||
| 3754 | @findex c-lineup-multi-inher | ||
| 3755 | @findex lineup-multi-inher (c-) | ||
| 3756 | @item c-lineup-multi-inher | ||
| 3757 | Line up the classes in C++ multiple inheritance clauses under each | ||
| 3758 | other. | ||
| 3759 | |||
| 3760 | @workswith @code{inher-cont}. | ||
| 3761 | |||
| 3762 | @findex c-lineup-java-inher | ||
| 3763 | @findex lineup-java-inher (c-) | ||
| 3764 | @item c-lineup-java-inher | ||
| 3765 | Line up Java implements and extends declarations. If class names | ||
| 3766 | follows on the same line as the @samp{implements}/@samp{extends} | ||
| 3767 | keyword, they are lined up under each other. Otherwise, they are | ||
| 3768 | indented by adding @code{c-basic-offset} to the column of the keyword. | ||
| 3769 | E.g: | ||
| 3770 | @example | ||
| 3771 | @group | ||
| 3772 | |||
| 3773 | class Foo | ||
| 3774 | extends | ||
| 3775 | Bar // c-lineup-java-inher | ||
| 3776 | |||
| 3777 | <--> c-basic-offset | ||
| 3778 | |||
| 3779 | @end group | ||
| 3780 | @end example | ||
| 3781 | @noindent | ||
| 3782 | and | ||
| 3783 | @example | ||
| 3784 | @group | ||
| 3785 | |||
| 3786 | class Foo | ||
| 3787 | extends Cyphr, | ||
| 3788 | Bar // c-lineup-java-inher | ||
| 3789 | |||
| 3790 | @end group | ||
| 3791 | @end example | ||
| 3792 | |||
| 3793 | @workswith @code{inher-cont}. | ||
| 3794 | |||
| 3795 | @findex c-lineup-java-throws | ||
| 3796 | @findex lineup-java-throws (c-) | ||
| 3797 | @item c-lineup-java-throws | ||
| 3798 | Line up Java throws declarations. If exception names follows on the | ||
| 3799 | same line as the throws keyword, they are lined up under each other. | ||
| 3800 | Otherwise, they are indented by adding @code{c-basic-offset} to the | ||
| 3801 | column of the @samp{throws} keyword. The @samp{throws} keyword itself | ||
| 3802 | is also indented by @code{c-basic-offset} from the function declaration | ||
| 3803 | start if it doesn't hang. E.g: | ||
| 3804 | @example | ||
| 3805 | @group | ||
| 3806 | |||
| 3807 | int foo() | ||
| 3808 | throws // c-lineup-java-throws | ||
| 3809 | Bar // c-lineup-java-throws | ||
| 3810 | |||
| 3811 | <--><--> c-basic-offset | ||
| 3812 | |||
| 3813 | @end group | ||
| 3814 | @end example | ||
| 3815 | @noindent | ||
| 3816 | and | ||
| 3817 | @example | ||
| 3818 | @group | ||
| 3819 | |||
| 3820 | int foo() throws Cyphr, | ||
| 3821 | Bar, // c-lineup-java-throws | ||
| 3822 | Vlod // c-lineup-java-throws | ||
| 3823 | |||
| 3824 | @end group | ||
| 3825 | @end example | ||
| 3826 | |||
| 3827 | @workswith @code{func-decl-cont}. | ||
| 3828 | |||
| 3829 | @findex c-indent-one-line-block | ||
| 3830 | @findex indent-one-line-block (c-) | ||
| 3831 | @item c-indent-one-line-block | ||
| 3832 | Indent a one line block @code{c-basic-offset} extra. E.g: | ||
| 3833 | @example | ||
| 3834 | @group | ||
| 3835 | |||
| 3836 | if (n > 0) | ||
| 3837 | @{m+=n; n=0;@} // c-indent-one-line-block | ||
| 3838 | |||
| 3839 | <--> c-basic-offset | ||
| 3840 | |||
| 3841 | @end group | ||
| 3842 | @end example | ||
| 3843 | @noindent | ||
| 3844 | and | ||
| 3845 | @example | ||
| 3846 | @group | ||
| 3847 | |||
| 3848 | if (n > 0) | ||
| 3849 | @{ // c-indent-one-line-block | ||
| 3850 | m+=n; n=0; | ||
| 3851 | @} | ||
| 3852 | |||
| 3853 | @end group | ||
| 3854 | @end example | ||
| 3855 | |||
| 3856 | The block may be surrounded by any kind of parenthesis characters. | ||
| 3857 | @code{nil} is returned if the line doesn't start with a one line block, | ||
| 3858 | which makes the function usable in list expressions. | ||
| 3859 | |||
| 3860 | @workswith Almost all syntactic symbols, but most useful on the | ||
| 3861 | @code{-open} symbols. | ||
| 3862 | |||
| 3863 | @findex c-indent-multi-line-block | ||
| 3864 | @findex indent-multi-line-block (c-) | ||
| 3865 | @item c-indent-multi-line-block | ||
| 3866 | Indent a multi line block @code{c-basic-offset} extra. E.g: | ||
| 3867 | @example | ||
| 3868 | @group | ||
| 3869 | |||
| 3870 | int *foo[] = @{ | ||
| 3871 | NULL, | ||
| 3872 | @{17@}, // c-indent-multi-line-block | ||
| 3873 | |||
| 3874 | @end group | ||
| 3875 | @end example | ||
| 3876 | @noindent | ||
| 3877 | and | ||
| 3878 | @example | ||
| 3879 | @group | ||
| 3880 | |||
| 3881 | int *foo[] = @{ | ||
| 3882 | NULL, | ||
| 3883 | @{ // c-indent-multi-line-block | ||
| 3884 | 17 | ||
| 3885 | @}, | ||
| 3886 | |||
| 3887 | <--> c-basic-offset | ||
| 3888 | |||
| 3889 | @end group | ||
| 3890 | @end example | ||
| 3891 | |||
| 3892 | The block may be surrounded by any kind of parenthesis characters. | ||
| 3893 | @code{nil} is returned if the line doesn't start with a multi line | ||
| 3894 | block, which makes the function usable in list expressions. | ||
| 3895 | |||
| 3896 | @workswith Almost all syntactic symbols, but most useful on the | ||
| 3897 | @code{-open} symbols. | ||
| 3898 | |||
| 3899 | @findex c-lineup-C-comments | ||
| 3900 | @findex lineup-C-comments (c-) | ||
| 3901 | @item c-lineup-C-comments | ||
| 3902 | Line up C block comment continuation lines. Various heuristics are used | ||
| 3903 | to handle most of the common comment styles. Some examples: | ||
| 3904 | @example | ||
| 3905 | |||
| 3906 | @group | ||
| 3907 | /* /** /* | ||
| 3908 | * text * text text | ||
| 3909 | */ */ */ | ||
| 3910 | @end group | ||
| 3911 | |||
| 3912 | @group | ||
| 3913 | /* text /* /** | ||
| 3914 | text ** text ** text | ||
| 3915 | */ */ */ | ||
| 3916 | @end group | ||
| 3917 | |||
| 3918 | @group | ||
| 3919 | /************************************************** | ||
| 3920 | * text | ||
| 3921 | *************************************************/ | ||
| 3922 | @end group | ||
| 3923 | |||
| 3924 | @vindex comment-start-skip | ||
| 3925 | @group | ||
| 3926 | /************************************************** | ||
| 3927 | Free form text comments: | ||
| 3928 | In comments with a long delimiter line at the | ||
| 3929 | start, the indentation is kept unchanged for lines | ||
| 3930 | that start with an empty comment line prefix. The | ||
| 3931 | delimiter line is whatever matches the | ||
| 3932 | @code{comment-start-skip} regexp. | ||
| 3933 | **************************************************/ | ||
| 3934 | @end group | ||
| 3935 | |||
| 3936 | @end example | ||
| 3937 | |||
| 3938 | The style variable @code{c-comment-prefix-regexp} is used to recognize | ||
| 3939 | the comment line prefix, e.g. the @samp{*} that usually starts every | ||
| 3940 | line inside a comment. | ||
| 3941 | |||
| 3942 | @workswith The @code{c} syntactic symbol. | ||
| 3943 | |||
| 3944 | @findex c-lineup-comment | ||
| 3945 | @findex lineup-comment (c-) | ||
| 3946 | @item c-lineup-comment | ||
| 3947 | Line up a comment-only line according to the style variable | ||
| 3948 | @code{c-comment-only-line-offset}. If the comment is lined up with a | ||
| 3949 | comment starter on the previous line, that alignment is preserved. | ||
| 3950 | |||
| 3951 | @vindex c-comment-only-line-offset | ||
| 3952 | @vindex comment-only-line-offset (c-) | ||
| 3953 | @code{c-comment-only-line-offset} specifies the extra offset for the | ||
| 3954 | line. It can contain an integer or a cons cell of the form | ||
| 3955 | @example | ||
| 3956 | |||
| 3957 | (@r{<non-anchored-offset>} . @r{<anchored-offset>}) | ||
| 3958 | |||
| 3959 | @end example | ||
| 3960 | |||
| 3961 | @noindent | ||
| 3962 | where @var{non-anchored-offset} is the amount of offset given to | ||
| 3963 | non-column-zero anchored lines, and @var{anchored-offset} is the amount | ||
| 3964 | of offset to give column-zero anchored lines. Just an integer as value | ||
| 3965 | is equivalent to @code{(@r{<value>} . -1000)}. | ||
| 3966 | |||
| 3967 | @workswith @code{comment-intro}. | ||
| 3968 | |||
| 3969 | @findex c-lineup-runin-statements | ||
| 3970 | @findex lineup-runin-statements (c-) | ||
| 3971 | @item c-lineup-runin-statements | ||
| 3972 | Line up statements for coding standards which place the first statement | ||
| 3973 | in a block on the same line as the block opening brace@footnote{Run-in | ||
| 3974 | style doesn't really work too well. You might need to write your own | ||
| 3975 | custom indentation functions to better support this style.}. E.g: | ||
| 3976 | @example | ||
| 3977 | @group | ||
| 3978 | |||
| 3979 | int main() | ||
| 3980 | @{ puts (\"Hello world!\"); | ||
| 3981 | return 0; // c-lineup-runin-statements | ||
| 3982 | @} | ||
| 3983 | |||
| 3984 | @end group | ||
| 3985 | @end example | ||
| 3986 | |||
| 3987 | If there is no statement after the opening brace to align with, | ||
| 3988 | @code{nil} is returned. This makes the function usable in list | ||
| 3989 | expressions. | ||
| 3990 | |||
| 3991 | @workswith The @code{statement} syntactic symbol. | ||
| 3992 | |||
| 3993 | @findex c-lineup-math | ||
| 3994 | @findex lineup-math (c-) | ||
| 3995 | @item c-lineup-math | ||
| 3996 | Line up the current line after the equal sign on the first line in the | ||
| 3997 | statement. If there isn't any, indent with @code{c-basic-offset}. If | ||
| 3998 | the current line contains an equal sign too, try to align it with the | ||
| 3999 | first one. | ||
| 4000 | |||
| 4001 | @workswith @code{statement-cont}. | ||
| 4002 | |||
| 4003 | @findex c-lineup-template-args | ||
| 4004 | @findex lineup-template-args (c-) | ||
| 4005 | @item c-lineup-template-args | ||
| 4006 | Line up the arguments of a template argument list under each other, but | ||
| 4007 | only in the case where the first argument is on the same line as the | ||
| 4008 | opening @samp{<}. | ||
| 4009 | |||
| 4010 | To allow this function to be used in a list expression, @code{nil} is | ||
| 4011 | returned if there's no template argument on the first line. | ||
| 4012 | |||
| 4013 | @workswith @code{template-args-cont}. | ||
| 4014 | |||
| 4015 | @findex c-lineup-ObjC-method-call | ||
| 4016 | @findex lineup-ObjC-method-call (c-) | ||
| 4017 | @item c-lineup-ObjC-method-call | ||
| 4018 | For Objective-C code, line up selector args as @code{elisp-mode} does | ||
| 4019 | with function args: go to the position right after the message receiver, | ||
| 4020 | and if you are at the end of the line, indent the current line | ||
| 4021 | c-basic-offset columns from the opening bracket; otherwise you are | ||
| 4022 | looking at the first character of the first method call argument, so | ||
| 4023 | lineup the current line with it. | ||
| 4024 | |||
| 4025 | @workswith @code{objc-method-call-cont}. | ||
| 4026 | |||
| 4027 | @findex c-lineup-ObjC-method-args | ||
| 4028 | @findex lineup-ObjC-method-args (c-) | ||
| 4029 | @item c-lineup-ObjC-method-args | ||
| 4030 | For Objective-C code, line up the colons that separate args. The colon | ||
| 4031 | on the current line is aligned with the one on the first line. | ||
| 4032 | |||
| 4033 | @workswith @code{objc-method-args-cont}. | ||
| 4034 | |||
| 4035 | @findex c-lineup-ObjC-method-args-2 | ||
| 4036 | @findex lineup-ObjC-method-args-2 (c-) | ||
| 4037 | @item c-lineup-ObjC-method-args-2 | ||
| 4038 | Similar to @code{c-lineup-ObjC-method-args} but lines up the colon on | ||
| 4039 | the current line with the colon on the previous line. | ||
| 4040 | |||
| 4041 | @workswith @code{objc-method-args-cont}. | ||
| 4042 | |||
| 4043 | @findex c-lineup-inexpr-block | ||
| 4044 | @findex lineup-inexpr-block (c-) | ||
| 4045 | @item c-lineup-inexpr-block | ||
| 4046 | This can be used with the in-expression block symbols to indent the | ||
| 4047 | whole block to the column where the construct is started. E.g. for Java | ||
| 4048 | anonymous classes, this lines up the class under the @samp{new} keyword, | ||
| 4049 | and in Pike it lines up the lambda function body under the @samp{lambda} | ||
| 4050 | keyword. Returns @code{nil} if the block isn't part of such a | ||
| 4051 | construct. | ||
| 4052 | |||
| 4053 | @workswith @code{inlambda}, @code{inexpr-statement}, | ||
| 4054 | @code{inexpr-class}. | ||
| 4055 | |||
| 4056 | @findex c-lineup-whitesmith-in-block | ||
| 4057 | @findex lineup-whitesmith-in-block (c-) | ||
| 4058 | @item c-lineup-whitesmith-in-block | ||
| 4059 | Line up lines inside a block in Whitesmith style. It's done in a way | ||
| 4060 | that works both when the opening brace hangs and when it doesn't. E.g: | ||
| 4061 | @example | ||
| 4062 | @group | ||
| 4063 | |||
| 4064 | something | ||
| 4065 | @{ | ||
| 4066 | foo; // c-lineup-whitesmith-in-block | ||
| 4067 | @} | ||
| 4068 | |||
| 4069 | @end group | ||
| 4070 | @end example | ||
| 4071 | @noindent | ||
| 4072 | and | ||
| 4073 | @example | ||
| 4074 | @group | ||
| 4075 | |||
| 4076 | something @{ | ||
| 4077 | foo; // c-lineup-whitesmith-in-block | ||
| 4078 | @} | ||
| 4079 | |||
| 4080 | <--> c-basic-offset | ||
| 4081 | |||
| 4082 | @end group | ||
| 4083 | @end example | ||
| 4084 | |||
| 4085 | In the first case the indentation is kept unchanged, in the second | ||
| 4086 | @code{c-basic-offset} is added. | ||
| 4087 | |||
| 4088 | @workswith @code{defun-close}, @code{defun-block-intro}, | ||
| 4089 | @code{block-close}, @code{brace-list-close}, @code{brace-list-intro}, | ||
| 4090 | @code{statement-block-intro}, @code{inclass}, @code{inextern-lang}, | ||
| 4091 | @code{innamespace}. | ||
| 4092 | |||
| 4093 | @findex c-lineup-dont-change | ||
| 4094 | @findex lineup-dont-change (c-) | ||
| 4095 | @item c-lineup-dont-change | ||
| 4096 | This lineup function returns the indentation of the current line. Think | ||
| 4097 | of it as an identity function for lineups; it is used for | ||
| 4098 | @code{cpp-macro-cont} lines. | ||
| 4099 | |||
| 4100 | @workswith Any syntactic symbol. | ||
| 4101 | |||
| 4102 | @end table | ||
| 4103 | |||
| 4104 | |||
| 4105 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| 4106 | @node Performance Issues, Frequently Asked Questions, Indentation Functions, Top | ||
| 4107 | @comment node-name, next, previous, up | ||
| 4108 | @chapter Performance Issues | ||
| 4109 | @cindex performance issues | ||
| 3152 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 4110 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 3153 | 4111 | ||
| 3154 | C and its derivative languages are highly complex creatures. Often, | 4112 | C and its derivative languages are highly complex creatures. Often, |
| @@ -3170,16 +4128,14 @@ to scan from the beginning of the buffer for every line of code! | |||
| 3170 | @findex beginning-of-defun | 4128 | @findex beginning-of-defun |
| 3171 | @findex defun-prompt-regexp | 4129 | @findex defun-prompt-regexp |
| 3172 | One of the simplest things you can do to reduce scan time, is make sure | 4130 | One of the simplest things you can do to reduce scan time, is make sure |
| 3173 | any brace that opens a top-level construct@footnote{e.g. a function in | 4131 | any brace that opens a top-level construct@footnote{E.g. a function in |
| 3174 | C, or outermost class definition in C++ or Java.} always appears in the | 4132 | C, or outermost class definition in C++ or Java.} always appears in the |
| 3175 | leftmost column. This is actually an Emacs constraint, as embodied in | 4133 | leftmost column. This is actually an Emacs constraint, as embodied in |
| 3176 | the @code{beginning-of-defun} function which @ccmode{} uses | 4134 | the @code{beginning-of-defun} function which @ccmode{} uses heavily. If |
| 3177 | heavily. If you insist on hanging top-level open braces on the right | 4135 | you insist on hanging top-level open braces on the right side of the |
| 3178 | side of the line, then you might want to set the variable | 4136 | line, then you might want to set the variable @code{defun-prompt-regexp} |
| 3179 | @code{defun-prompt-regexp} to something reasonable @footnote{Note that | 4137 | to something reasonable, however that ``something reasonable'' is |
| 3180 | this variable is only defined in Emacs 19.}, however that ``something | 4138 | difficult to define, so @ccmode{} doesn't do it for you. |
| 3181 | reasonable'' is difficult to define, so @ccmode{} doesn't do it | ||
| 3182 | for you. | ||
| 3183 | 4139 | ||
| 3184 | @vindex c-Java-defun-prompt-regexp | 4140 | @vindex c-Java-defun-prompt-regexp |
| 3185 | @vindex Java-defun-prompt-regexp (c-) | 4141 | @vindex Java-defun-prompt-regexp (c-) |
| @@ -3194,12 +4150,31 @@ has been observed in Emacs 19.34 and XEmacs 19.15.}. For this reason, | |||
| 3194 | it is not used by default, but if you feel adventurous, you can set | 4150 | it is not used by default, but if you feel adventurous, you can set |
| 3195 | @code{defun-prompt-regexp} to it in your mode hook. In any event, | 4151 | @code{defun-prompt-regexp} to it in your mode hook. In any event, |
| 3196 | setting and rely on @code{defun-prompt-regexp} will definitely slow | 4152 | setting and rely on @code{defun-prompt-regexp} will definitely slow |
| 3197 | things down! | 4153 | things down anyway because you'll be doing regular expression searches |
| 4154 | for every line you indent, so you're probably screwed either way! | ||
| 4155 | |||
| 4156 | @vindex c-enable-xemacs-performance-kludge-p | ||
| 4157 | @vindex enable-xemacs-performance-kludge-p (c-) | ||
| 4158 | Another alternative for XEmacs users, is to set the variable | ||
| 4159 | @code{c-enable-xemacs-performance-kludge-p} to non-@code{nil}. This | ||
| 4160 | tells @ccmode{} to use XEmacs-specific built-in functions which, in some | ||
| 4161 | circumstances, can locate the top-most opening brace much quicker than | ||
| 4162 | @code{beginning-of-defun}. Preliminary testing has shown that for | ||
| 4163 | styles where these braces are hung (e.g. most JDK-derived Java styles), | ||
| 4164 | this hack can improve performance of the core syntax parsing routines | ||
| 4165 | from 3 to 60 times. However, for styles which @emph{do} conform to | ||
| 4166 | Emacs' recommended style of putting top-level braces in column zero, | ||
| 4167 | this hack can degrade performance by about as much. Thus this variable | ||
| 4168 | is set to @code{nil} by default, since the Emacs-friendly styles | ||
| 4169 | should be more common (and | ||
| 4170 | encouraged!). Note that this variable has no effect in Emacs since the | ||
| 4171 | necessary built-in functions don't exist (in Emacs 20.2 or 20.3 as of | ||
| 4172 | this writing 27-Apr-1998). | ||
| 3198 | 4173 | ||
| 3199 | You will probably notice pathological behavior from @ccmode{} when | 4174 | You will probably notice pathological behavior from @ccmode{} when |
| 3200 | working in files containing large amounts of C preprocessor macros. | 4175 | working in files containing large amounts of C preprocessor macros. |
| 3201 | This is because Emacs cannot skip backwards over these lines as quickly | 4176 | This is because Emacs cannot skip backwards over these lines as quickly |
| 3202 | as it can comment. | 4177 | as it can comments. |
| 3203 | 4178 | ||
| 3204 | @vindex c-recognize-knr-p | 4179 | @vindex c-recognize-knr-p |
| 3205 | @vindex recognize-knr-p (c-) | 4180 | @vindex recognize-knr-p (c-) |
| @@ -3229,63 +4204,58 @@ at the variable @code{cc-lobotomy-pith-list} for details. | |||
| 3229 | 4204 | ||
| 3230 | 4205 | ||
| 3231 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 4206 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 3232 | @node Frequently Asked Questions, Getting the latest CC Mode release, Performance Issues, Top | 4207 | @node Frequently Asked Questions, Getting the Latest CC Mode Release, Performance Issues, Top |
| 3233 | @comment node-name, next, previous,up | 4208 | @comment node-name, next, previous, up |
| 3234 | 4209 | @chapter Frequently Asked Questions | |
| 3235 | @chapter Frequently Asked Questions | 4210 | @cindex frequently asked questions |
| 3236 | @cindex Frequently Asked Questions | 4211 | @cindex FAQ |
| 3237 | @comment FAQ | ||
| 3238 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 4212 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 3239 | 4213 | ||
| 3240 | @kindex C-x h | 4214 | @kindex C-x h |
| 3241 | @kindex ESC C-\ | 4215 | @kindex C-M-\ |
| 3242 | @kindex ESC C-x | 4216 | @kindex C-M-x |
| 3243 | @kindex C-c C-q | 4217 | @kindex C-M-q |
| 3244 | @kindex ESC C-q | 4218 | @kindex C-M-u |
| 3245 | @kindex ESC C-u | ||
| 3246 | @kindex RET | 4219 | @kindex RET |
| 3247 | @kindex C-j | 4220 | @kindex C-j |
| 3248 | @findex newline-and-indent | ||
| 3249 | @quotation | 4221 | @quotation |
| 3250 | 4222 | ||
| 3251 | @strong{Q.} @emph{How do I re-indent the whole file?} | 4223 | @strong{Q.} @emph{How do I re-indent the whole file?} |
| 3252 | 4224 | ||
| 3253 | @strong{A.} Visit the file and hit @kbd{C-x h} to mark the whole | 4225 | @strong{A.} Visit the file and hit @kbd{C-x h} to mark the whole |
| 3254 | buffer. Then hit @kbd{ESC C-\}. | 4226 | buffer. Then hit @kbd{C-M-\}. |
| 3255 | @sp 1 | ||
| 3256 | 4227 | ||
| 4228 | @sp 1 | ||
| 3257 | @strong{Q.} @emph{How do I re-indent the entire function? | 4229 | @strong{Q.} @emph{How do I re-indent the entire function? |
| 3258 | @kbd{ESC C-x} doesn't work.} | 4230 | @kbd{C-M-x} doesn't work.} |
| 3259 | 4231 | ||
| 3260 | @strong{A.} @kbd{ESC C-x} is reserved for future Emacs use. | 4232 | @strong{A.} @kbd{C-M-x} is reserved for future Emacs use. |
| 3261 | To re-indent the entire function hit @kbd{C-c C-q}. | 4233 | To re-indent the entire function hit @kbd{C-c C-q}. |
| 3262 | @sp 1 | ||
| 3263 | 4234 | ||
| 4235 | @sp 1 | ||
| 3264 | @strong{Q.} @emph{How do I re-indent the current block?} | 4236 | @strong{Q.} @emph{How do I re-indent the current block?} |
| 3265 | 4237 | ||
| 3266 | @strong{A.} First move to the brace which opens the block with | 4238 | @strong{A.} First move to the brace which opens the block with |
| 3267 | @kbd{ESC C-u}, then re-indent that expression with | 4239 | @kbd{C-M-u}, then re-indent that expression with |
| 3268 | @kbd{ESC C-q}. | 4240 | @kbd{C-M-q}. |
| 3269 | @sp 1 | ||
| 3270 | 4241 | ||
| 3271 | @strong{Q.} @emph{Why doesn't the @kbd{RET} key indent the line to | 4242 | @sp 1 |
| 3272 | where the new text should go after inserting the newline?} | 4243 | @strong{Q.} @emph{Why doesn't the @kbd{RET} key indent the new line?} |
| 3273 | 4244 | ||
| 3274 | @strong{A.} Emacs' convention is that @kbd{RET} just adds a newline, | 4245 | @strong{A.} Emacs' convention is that @kbd{RET} just adds a newline, |
| 3275 | and that @kbd{C-j} adds a newline and indents it. You can make | 4246 | and that @kbd{C-j} adds a newline and indents it. You can make |
| 3276 | @kbd{RET} do this too by adding this to your | 4247 | @kbd{RET} do this too by adding this to your |
| 3277 | @code{c-mode-common-hook} (see the sample @file{.emacs} file | 4248 | @code{c-mode-common-hook}: |
| 3278 | @ref{Sample .emacs File}): | ||
| 3279 | @example | 4249 | @example |
| 3280 | 4250 | ||
| 3281 | (define-key c-mode-base-map "\C-m" 'newline-and-indent) | 4251 | (define-key c-mode-base-map "\C-m" 'c-context-line-break) |
| 3282 | 4252 | ||
| 3283 | @end example | 4253 | @end example |
| 3284 | 4254 | ||
| 3285 | This is a very common question. If you want this to be the default | 4255 | This is a very common question. If you want this to be the default |
| 3286 | behavior, don't lobby me, lobby RMS! @code{:-)} | 4256 | behavior, don't lobby me, lobby RMS! @t{:-)} |
| 3287 | @sp 1 | ||
| 3288 | 4257 | ||
| 4258 | @sp 1 | ||
| 3289 | @strong{Q.} @emph{I put @code{(c-set-offset 'substatement-open 0)} | 4259 | @strong{Q.} @emph{I put @code{(c-set-offset 'substatement-open 0)} |
| 3290 | in my @file{.emacs} file but I get an error saying that | 4260 | in my @file{.emacs} file but I get an error saying that |
| 3291 | @code{c-set-offset}'s function definition is void.} | 4261 | @code{c-set-offset}'s function definition is void.} |
| @@ -3295,22 +4265,39 @@ Emacs session by the time the @code{c-set-offset} call was reached, | |||
| 3295 | mostly likely because @ccmode{} is being autoloaded. Instead | 4265 | mostly likely because @ccmode{} is being autoloaded. Instead |
| 3296 | of putting the @code{c-set-offset} line in your top-level | 4266 | of putting the @code{c-set-offset} line in your top-level |
| 3297 | @file{.emacs} file, put it in your @code{c-mode-common-hook}, or | 4267 | @file{.emacs} file, put it in your @code{c-mode-common-hook}, or |
| 3298 | simply add the following to the top of your @file{.emacs} file: | 4268 | simply modify @code{c-offsets-alist} directly: |
| 3299 | @example | 4269 | @example |
| 4270 | @group | ||
| 3300 | 4271 | ||
| 3301 | (require 'cc-mode) | 4272 | (setq c-offsets-alist (cons '(substatement-open . 0) |
| 3302 | 4273 | c-offsets-alist)) | |
| 4274 | @end group | ||
| 3303 | @end example | 4275 | @end example |
| 3304 | 4276 | ||
| 3305 | See the sample @file{.emacs} file @ref{Sample .emacs File} for | 4277 | @sp 1 |
| 3306 | details. | 4278 | @strong{Q.} @emph{My style settings works in all the @ccmode{} language |
| 4279 | modes except for Java, where I still get e.g. 4 column indentation.} | ||
| 4280 | |||
| 4281 | @strong{A.} Java mode switches to the @samp{java} style by default for | ||
| 4282 | historical reasons. You can override it by putting an association list | ||
| 4283 | on @code{c-default-style}: | ||
| 4284 | @example | ||
| 4285 | |||
| 4286 | (setq c-default-style '((other . "my-style"))) | ||
| 4287 | |||
| 4288 | @end example | ||
| 4289 | @noindent | ||
| 4290 | The @samp{other} symbol says that @ccmode{} should use "my-style" in all | ||
| 4291 | modes not explicitly listed. Since there's nothing else on the list | ||
| 4292 | this causes "my-style" to be used in every mode. | ||
| 3307 | 4293 | ||
| 3308 | @sp 1 | 4294 | @sp 1 |
| 3309 | @strong{Q.} @emph{How do I make strings, comments, keywords, and other | 4295 | @strong{Q.} @emph{How do I make strings, comments, keywords, and other |
| 3310 | constructs appear in different colors, or in bold face, etc.?} | 4296 | constructs appear in different colors, or in bold face, etc.?} |
| 3311 | 4297 | ||
| 3312 | @strong{A.} ``Syntax Colorization'' is a standard Emacs feature, | 4298 | @strong{A.} ``Syntax Colorization'' is a standard Emacs feature, |
| 3313 | controlled by @code{font-lock-mode}. It is not part of @ccmode{}. | 4299 | controlled by @code{font-lock-mode}. @ccmode{} does not contain |
| 4300 | font-lock definitions for any of its supported languages. | ||
| 3314 | 4301 | ||
| 3315 | @sp 1 | 4302 | @sp 1 |
| 3316 | @strong{Q.} @emph{@kbd{M-a} and @kbd{M-e} used to move over entire | 4303 | @strong{Q.} @emph{@kbd{M-a} and @kbd{M-e} used to move over entire |
| @@ -3319,75 +4306,59 @@ old behavior back?} | |||
| 3319 | 4306 | ||
| 3320 | @strong{A.} Use @kbd{C-M-f} and @kbd{C-M-b} to move over balanced brace | 4307 | @strong{A.} Use @kbd{C-M-f} and @kbd{C-M-b} to move over balanced brace |
| 3321 | blocks. Use @kbd{M-a} and @kbd{M-e} to move by statements, which will | 4308 | blocks. Use @kbd{M-a} and @kbd{M-e} to move by statements, which will |
| 3322 | move into blocks. | 4309 | also move into blocks. |
| 4310 | |||
| 4311 | @sp 1 | ||
| 4312 | @strong{Q.} @emph{Whenever I try to indent a line or type an | ||
| 4313 | ``electric'' key such as @kbd{;}, @kbd{@{}, or @kbd{@}}, I get an error | ||
| 4314 | that look like this: @code{Invalid function: (macro . #[...}. What | ||
| 4315 | gives?} | ||
| 4316 | |||
| 4317 | @strong{A.} This is a common error when @ccmode{} hasn't been compiled | ||
| 4318 | correctly, especially under Emacs 19.34@footnote{Technically, it's | ||
| 4319 | because some macros wasn't defined during the compilation, so the byte | ||
| 4320 | compiler put in function calls instead of the macro expansions. Later, | ||
| 4321 | when the interpreter tries to call the macros as functions, it shows | ||
| 4322 | this (somewhat cryptic) error message.}. If you are using the standalone | ||
| 4323 | @ccmode{} distribution, try recompiling it according to the instructions | ||
| 4324 | in the @file{README} file. | ||
| 3323 | 4325 | ||
| 3324 | @end quotation | 4326 | @end quotation |
| 3325 | 4327 | ||
| 3326 | 4328 | ||
| 3327 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 4329 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 3328 | @node Getting the latest CC Mode release, Sample .emacs File, Frequently Asked Questions, Top | 4330 | @node Getting the Latest CC Mode Release, Sample .emacs File, Frequently Asked Questions, Top |
| 3329 | @comment node-name, next, previous,up | 4331 | @comment node-name, next, previous, up |
| 3330 | 4332 | @chapter Getting the Latest CC Mode Release | |
| 3331 | @chapter Getting the latest CC Mode release | ||
| 3332 | @cindex Getting the latest CC Mode release | ||
| 3333 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 4333 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 3334 | 4334 | ||
| 3335 | @ccmode{} is now standard with the latest versions of Emacs 19 and | 4335 | @ccmode{} is standard with all versions of Emacs since 19.34 and of |
| 3336 | XEmacs 19. It is also the standard for Emacs 20 and XEmacs 20. You | 4336 | XEmacs since 19.16. |
| 3337 | would typically just use the version that comes with your X/Emacs. | 4337 | |
| 3338 | These may be slightly out of date due to release schedule skew, so you | 4338 | Due to release schedule skew, it is likely that all of these Emacsen |
| 3339 | should always check the canonical site for the latest version. | 4339 | have old versions of @ccmode{} and so should be upgraded. Access to the |
| 4340 | @ccmode{} source code, as well as more detailed information on Emacsen | ||
| 4341 | compatibility, etc. are all available via the Web at: | ||
| 3340 | 4342 | ||
| 3341 | @example | 4343 | @example |
| 3342 | @group | 4344 | @group |
| 3343 | 4345 | ||
| 3344 | World Wide Web: | 4346 | @uref{http://www.python.org/emacs/cc-mode/} |
| 3345 | |||
| 3346 | @code{http://www.python.org/ftp/emacs/} | ||
| 3347 | |||
| 3348 | Anonymous FTP: | ||
| 3349 | |||
| 3350 | @code{ftp://ftp.python.org/pub/emacs/} | ||
| 3351 | 4347 | ||
| 3352 | @end group | 4348 | @end group |
| 3353 | @end example | 4349 | @end example |
| 3354 | 4350 | ||
| 4351 | @emph{Old URLs, including the FTP URLs, should no longer be used.} | ||
| 4352 | |||
| 3355 | There are many files under these directories; you can pick up the entire | 4353 | There are many files under these directories; you can pick up the entire |
| 3356 | distribution (named @code{cc-mode.tar.gz}; a gzip'd tar file), or any of | 4354 | distribution (named @code{cc-mode.tar.gz}; a gzip'd tar file), or any of |
| 3357 | the individual files, including PostScript documentation. | 4355 | the individual files, including PostScript documentation. |
| 3358 | 4356 | ||
| 3359 | If you do not have World Wide Web, or anonymous ftp access, you can get | ||
| 3360 | the distribution through an anonymous ftp-to-mail gateway, such as the | ||
| 3361 | one run by DEC at: | ||
| 3362 | @example | ||
| 3363 | |||
| 3364 | @code{ftpmail@@decwrl.dec.com} | ||
| 3365 | |||
| 3366 | @end example | ||
| 3367 | To get @ccmode{} via email, send the following message in the body of | ||
| 3368 | your mail to that address: | ||
| 3369 | @example | ||
| 3370 | |||
| 3371 | reply <a valid net address back to you> | ||
| 3372 | connect ftp.python.org | ||
| 3373 | binary | ||
| 3374 | uuencode | ||
| 3375 | chdir pub/emacs | ||
| 3376 | get cc-mode.tar.gz | ||
| 3377 | |||
| 3378 | @end example | ||
| 3379 | @noindent | ||
| 3380 | or just send the message "help" for more information on ftpmail. | ||
| 3381 | Response times will vary with the number of requests in the queue. I am | ||
| 3382 | in no way connected to this service, so I make no claims or guarantees | ||
| 3383 | about its availability! | ||
| 3384 | 4357 | ||
| 3385 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 4358 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 3386 | @node Sample .emacs File, Limitations and Known Bugs, Getting the latest CC Mode release, Top | 4359 | @node Sample .emacs File, Limitations and Known Bugs, Getting the Latest CC Mode Release, Top |
| 3387 | @comment node-name, next, previous,up | 4360 | @comment node-name, next, previous, up |
| 3388 | 4361 | @chapter Sample .emacs file | |
| 3389 | @chapter Sample .emacs file | ||
| 3390 | @cindex Sample .emacs file | ||
| 3391 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 4362 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 3392 | 4363 | ||
| 3393 | @example | 4364 | @example |
| @@ -3417,12 +4388,14 @@ about its availability! | |||
| 3417 | ) | 4388 | ) |
| 3418 | "My C Programming Style") | 4389 | "My C Programming Style") |
| 3419 | 4390 | ||
| 3420 | ;; Customizations for all of c-mode, c++-mode, and objc-mode | 4391 | ;; offset customizations not in my-c-style |
| 4392 | (setq c-offsets-alist (cons '(member-init-intro . ++) | ||
| 4393 | c-offsets-alist)) | ||
| 4394 | |||
| 4395 | ;; Customizations for all modes in CC Mode. | ||
| 3421 | (defun my-c-mode-common-hook () | 4396 | (defun my-c-mode-common-hook () |
| 3422 | ;; add my personal style and set it for the current buffer | 4397 | ;; add my personal style and set it for the current buffer |
| 3423 | (c-add-style "PERSONAL" my-c-style t) | 4398 | (c-add-style "PERSONAL" my-c-style t) |
| 3424 | ;; offset customizations not in my-c-style | ||
| 3425 | (c-set-offset 'member-init-intro '++) | ||
| 3426 | ;; other customizations | 4399 | ;; other customizations |
| 3427 | (setq tab-width 8 | 4400 | (setq tab-width 8 |
| 3428 | ;; this will make sure spaces are used instead of tabs | 4401 | ;; this will make sure spaces are used instead of tabs |
| @@ -3431,95 +4404,115 @@ about its availability! | |||
| 3431 | (c-toggle-auto-hungry-state 1) | 4404 | (c-toggle-auto-hungry-state 1) |
| 3432 | ;; keybindings for all supported languages. We can put these in | 4405 | ;; keybindings for all supported languages. We can put these in |
| 3433 | ;; c-mode-base-map because c-mode-map, c++-mode-map, objc-mode-map, | 4406 | ;; c-mode-base-map because c-mode-map, c++-mode-map, objc-mode-map, |
| 3434 | ;; java-mode-map, and idl-mode-map inherit from it. | 4407 | ;; java-mode-map, idl-mode-map, and pike-mode-map inherit from it. |
| 3435 | (define-key c-mode-base-map "\C-m" 'newline-and-indent) | 4408 | (define-key c-mode-base-map "\C-m" 'c-context-line-break) |
| 3436 | ) | 4409 | ) |
| 3437 | 4410 | ||
| 3438 | (add-hook 'c-mode-common-hook 'my-c-mode-common-hook) | 4411 | (add-hook 'c-mode-common-hook 'my-c-mode-common-hook) |
| 3439 | @end example | 4412 | @end example |
| 3440 | 4413 | ||
| 4414 | |||
| 3441 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 4415 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 3442 | @node Limitations and Known Bugs, Mailing Lists and Submitting Bug Reports, Sample .emacs File, Top | 4416 | @node Limitations and Known Bugs, Mailing Lists and Submitting Bug Reports, Sample .emacs File, Top |
| 3443 | @comment node-name, next, previous,up | 4417 | @comment node-name, next, previous, up |
| 3444 | @chapter Limitations and Known Bugs | 4418 | @chapter Limitations and Known Bugs |
| 3445 | @cindex Limitations and Known Bugs | 4419 | @cindex limitations |
| 3446 | @comment * Limitations and Known Bugs | 4420 | @cindex bugs |
| 3447 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 4421 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 3448 | 4422 | ||
| 3449 | @itemize @bullet | 4423 | @itemize @bullet |
| 3450 | @item | 4424 | @item |
| 3451 | Re-indenting large regions or expressions can be slow. | 4425 | Re-indenting large regions or expressions can be slow. |
| 3452 | 4426 | ||
| 3453 | @item | 4427 | @findex c-indent-exp |
| 3454 | Add-on fill packages may not work as well as @ccmode{}'s built-in | 4428 | @findex indent-exp (c-) |
| 3455 | filling routines. I no longer recommend you use @code{filladapt} to | ||
| 3456 | fill comments. | ||
| 3457 | |||
| 3458 | @cindex c-indent-exp | ||
| 3459 | @cindex indent-exp (c-) | ||
| 3460 | @item | 4429 | @item |
| 3461 | @code{c-indent-exp} has not been fully optimized. It essentially | 4430 | @code{c-indent-exp} has not been fully optimized. It essentially |
| 3462 | equivalent to hitting @kbd{TAB} (@code{c-indent-command}) on every | 4431 | equivalent to hitting @kbd{TAB} (@code{c-indent-command}) on every |
| 3463 | line. Some information is cached from line to line, but such caching | 4432 | line. Some information is cached from line to line, but such caching |
| 3464 | invariable causes inaccuracies in analysis in some bizarre situations. | 4433 | invariable causes inaccuracies in analysis in some bizarre situations. |
| 3465 | 4434 | ||
| 4435 | @vindex signal-error-on-buffer-boundary | ||
| 4436 | @item | ||
| 4437 | XEmacs versions from 19.15 until (as of this writing 12-Mar-1998) 20.4 | ||
| 4438 | contain a variable called @code{signal-error-on-buffer-boundary}. This | ||
| 4439 | was intended as a solution to user interface problems associated with | ||
| 4440 | buffer movement and the @code{zmacs-region} deactivation on errors. | ||
| 4441 | However, setting this variable to a non-default value had the | ||
| 4442 | deleterious side effect of breaking many built-in primitive functions. | ||
| 4443 | Most users will not be affected since they never change the value of | ||
| 4444 | this variable. @strong{Do not set this variable to @code{nil}}; you | ||
| 4445 | will cause serious problems in @ccmode{} and probably other XEmacs | ||
| 4446 | packages! As of at least XEmacs 20.4, the effects this variable tried | ||
| 4447 | to correct have been fixed in other, better ways. | ||
| 4448 | |||
| 3466 | @end itemize | 4449 | @end itemize |
| 3467 | 4450 | ||
| 3468 | @c !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 4451 | |
| 3469 | @node Mailing Lists and Submitting Bug Reports, Concept Index, Limitations and Known Bugs, Top | 4452 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 3470 | @comment node-name, next, previous,up | 4453 | @node Mailing Lists and Submitting Bug Reports, Concept Index, Limitations and Known Bugs, Top |
| 3471 | @chapter Mailing Lists and Submitting Bug Reports | 4454 | @comment node-name, next, previous, up |
| 3472 | @cindex Mailing Lists and Submitting Bug Reports | 4455 | @chapter Mailing Lists and Submitting Bug Reports |
| 3473 | @c !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 4456 | @cindex mailing lists |
| 4457 | @cindex reporting bugs | ||
| 4458 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| 3474 | 4459 | ||
| 3475 | @kindex C-c C-b | 4460 | @kindex C-c C-b |
| 3476 | @findex c-submit-bug-report | 4461 | @findex c-submit-bug-report |
| 3477 | @findex submit-bug-report (c-) | 4462 | @findex submit-bug-report (c-) |
| 3478 | @cindex beta testers mailing list | ||
| 3479 | @cindex announcement mailing list | ||
| 3480 | To report bugs, use the @kbd{C-c C-b} (@code{c-submit-bug-report}) | 4463 | To report bugs, use the @kbd{C-c C-b} (@code{c-submit-bug-report}) |
| 3481 | command. This provides vital information I need to reproduce your | 4464 | command. This provides vital information we need to reproduce your |
| 3482 | problem. Make sure you include a concise, but complete code example. | 4465 | problem. Make sure you include a concise, but complete code example. |
| 3483 | Please try to boil your example down to just the essential code needed | 4466 | Please try to boil your example down to just the essential code needed |
| 3484 | to reproduce the problem, and include an exact recipe of steps needed to | 4467 | to reproduce the problem, and include an exact recipe of steps needed to |
| 3485 | expose the bug. Be especially sure to include any code that appears | 4468 | expose the bug. Be especially sure to include any code that appears |
| 3486 | @emph{before} your bug example, if you think it might affect my ability | 4469 | @emph{before} your bug example, if you think it might affect our ability |
| 3487 | to reproduce it. | 4470 | to reproduce it. |
| 3488 | 4471 | ||
| 4472 | Please try to produce the problem in an Emacs instance without any | ||
| 4473 | customizations loaded (i.e. start it with the @code{-q -no-site-file} | ||
| 4474 | arguments). If it works correctly there, the problem might be caused by | ||
| 4475 | faulty customizations in either your own or your site configuration. In | ||
| 4476 | that case, we'd appreciate if you isolate the Emacs Lisp code that trigs | ||
| 4477 | the bug and include it in your report. | ||
| 4478 | |||
| 3489 | Bug reports are now sent to the following email addresses: | 4479 | Bug reports are now sent to the following email addresses: |
| 3490 | @code{cc-mode-help@@python.org} and | 4480 | @email{bug-cc-mode@@gnu.org} and @email{bug-gnu-emacs@@gnu.org}; the |
| 3491 | @code{bug-gnu-emacs@@gnu.org}; the latter is mirrored on the | 4481 | latter is mirrored on the Usenet newsgroup @code{gnu.emacs.bug}. You |
| 3492 | Usenet newsgroup @code{gnu.emacs.bug}. You can send other questions and | 4482 | can send other questions and suggestions (kudos? @t{;-)} to |
| 3493 | suggestions (kudos? @code{;-)} to @code{cc-mode-help@@python.org}, or | 4483 | @email{bug-cc-mode@@gnu.org}, or @email{help-gnu-emacs@@gnu.org} which is |
| 3494 | @code{help-gnu-emacs@@gnu.org} which is mirrored on newsgroup | 4484 | mirrored on newsgroup @code{gnu.emacs.help}. The old contact address |
| 3495 | @code{gnu.emacs.help}. | 4485 | @email{cc-mode-help@@python.org} is still active, but its use is |
| 3496 | 4486 | discouraged. | |
| 3497 | If you want to get announcements of new CC Mode releases, send the | 4487 | |
| 3498 | word @emph{subscribe} in the body of a message to | 4488 | @cindex beta testers mailing list |
| 3499 | @code{cc-mode-announce-request@@python.org}. Announcements will also be | 4489 | @cindex announcement mailing list |
| 3500 | posted to the Usenet newsgroup @code{gnu.emacs.sources}. Note that the | 4490 | If you want to get announcements of new @ccmode{} releases, send the word |
| 3501 | @code{cc-mode-victims@@python.org} mailing list was recently | 4491 | @emph{subscribe} in the body of a message to |
| 4492 | @email{cc-mode-announce-request@@python.org}. Announcements will also | ||
| 4493 | be posted to the Usenet newsgroups @code{gnu.emacs.sources}, | ||
| 4494 | @code{comp.emacs}, @code{comp.emacs.xemacs}, and possibly some of the | ||
| 4495 | language oriented newsgroups. Note that the | ||
| 4496 | @code{cc-mode-victims@@python.org} mailing list has been | ||
| 3502 | decommissioned. | 4497 | decommissioned. |
| 3503 | 4498 | ||
| 3504 | @c !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 4499 | |
| 3505 | @node Concept Index, Command Index, Mailing Lists and Submitting Bug Reports, Top | 4500 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 3506 | @comment node-name, next, previous, up | 4501 | @node Concept Index, Command Index, Mailing Lists and Submitting Bug Reports, Top |
| 4502 | @comment node-name, next, previous, up | ||
| 3507 | @unnumbered Concept Index | 4503 | @unnumbered Concept Index |
| 3508 | @c !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 4504 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 3509 | 4505 | ||
| 3510 | @printindex cp | 4506 | @printindex cp |
| 3511 | 4507 | ||
| 3512 | 4508 | ||
| 3513 | @c !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 4509 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 3514 | @node Command Index, Key Index, Concept Index, Top | 4510 | @node Command Index, Key Index, Concept Index, Top |
| 3515 | @comment node-name, next, previous, up | 4511 | @comment node-name, next, previous, up |
| 3516 | @unnumbered Command Index | 4512 | @unnumbered Command Index |
| 3517 | @c !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 4513 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 3518 | |||
| 3519 | @ifinfo | ||
| 3520 | 4514 | ||
| 3521 | @end ifinfo | 4515 | Since most @ccmode{} commands are prepended with the string |
| 3522 | Since all @ccmode{} commands are prepended with the string | ||
| 3523 | @samp{c-}, each appears under its @code{c-@var{<thing>}} name and its | 4516 | @samp{c-}, each appears under its @code{c-@var{<thing>}} name and its |
| 3524 | @code{@var{<thing>} (c-)} name. | 4517 | @code{@var{<thing>} (c-)} name. |
| 3525 | @iftex | 4518 | @iftex |
| @@ -3528,25 +4521,22 @@ Since all @ccmode{} commands are prepended with the string | |||
| 3528 | @printindex fn | 4521 | @printindex fn |
| 3529 | 4522 | ||
| 3530 | 4523 | ||
| 3531 | @c !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 4524 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 3532 | @node Key Index, Variable Index, Command Index, Top | 4525 | @node Key Index, Variable Index, Command Index, Top |
| 3533 | @comment node-name, next, previous, up | 4526 | @comment node-name, next, previous, up |
| 3534 | @unnumbered Key Index | 4527 | @unnumbered Key Index |
| 3535 | @c !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 4528 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 3536 | 4529 | ||
| 3537 | @printindex ky | 4530 | @printindex ky |
| 3538 | 4531 | ||
| 3539 | 4532 | ||
| 3540 | @c !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 4533 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 3541 | @node Variable Index, , Key Index, Top | 4534 | @node Variable Index, , Key Index, Top |
| 3542 | @comment node-name, next, previous, up | 4535 | @comment node-name, next, previous, up |
| 3543 | @unnumbered Variable Index | 4536 | @unnumbered Variable Index |
| 3544 | @c !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 4537 | @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| 3545 | |||
| 3546 | @ifinfo | ||
| 3547 | 4538 | ||
| 3548 | @end ifinfo | 4539 | Since most @ccmode{} variables are prepended with the string |
| 3549 | Since all @ccmode{} variables are prepended with the string | ||
| 3550 | @samp{c-}, each appears under its @code{c-@var{<thing>}} name and its | 4540 | @samp{c-}, each appears under its @code{c-@var{<thing>}} name and its |
| 3551 | @code{@var{<thing>} (c-)} name. | 4541 | @code{@var{<thing>} (c-)} name. |
| 3552 | @iftex | 4542 | @iftex |
| @@ -3557,4 +4547,3 @@ Since all @ccmode{} variables are prepended with the string | |||
| 3557 | @summarycontents | 4547 | @summarycontents |
| 3558 | @contents | 4548 | @contents |
| 3559 | @bye | 4549 | @bye |
| 3560 | |||