comparison man/cc-mode.texi @ 165:5a88923fcbfe r20-3b9

Import from CVS: tag r20-3b9
author cvs
date Mon, 13 Aug 2007 09:44:42 +0200
parents fe104dbd9147
children 929b76928fce
comparison
equal deleted inserted replaced
164:4e0740e5aab2 165:5a88923fcbfe
3 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 3 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
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 cc-mode.info 7 @setfilename cc-mode.info
8 @settitle CC MODE Version 4 Documentation 8 @settitle CC MODE Version 5 Documentation
9 @footnotestyle end 9 @footnotestyle end
10 10
11 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 11 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12 @comment @setchapternewpage odd !! we don't want blank pages !! 12 @comment @setchapternewpage odd !! we don't want blank pages !!
13 @comment %**end of header (This is for running Texinfo on a region) 13 @comment %**end of header (This is for running Texinfo on a region)
14 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 14 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
15 15
16 16
17 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 17 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
18 @comment 18 @comment
19 @comment texinfo manual for @file{cc-mode.el} version 4 19 @comment TeXinfo manual for CC Mode
20 @comment manual version: 2.66 20 @comment Generated from the original README file by Krishna Padmasola
21 @comment generated from the original README file by Krishna Padmasola
22 @comment <krishna@earth-gw.njit.edu> 21 @comment <krishna@earth-gw.njit.edu>
23 @comment 22 @comment
24 @comment Barry A. Warsaw <bwarsaw@cnri.reston.va.us> 23 @comment Maintained by Barry A. Warsaw <cc-mode-help@python.org>
25 @comment Last modification: 1997/03/07 23:36:14
26 @comment 24 @comment
27 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 25 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
28 26
29 27
30 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 28 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
46 44
47 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 45 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
48 @comment The title is printed in a large font. 46 @comment The title is printed in a large font.
49 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 47 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
50 48
51 @center @titlefont{CC Mode Version 4} 49 @center @titlefont{CC Mode 5.11}
52 @sp 2 50 @sp 2
53 @center A GNU Emacs mode for editing C, C++, Objective-C, and Java code. 51 @center @subtitlefont{A GNU Emacs mode for editing C, C++, Objective-C, and Java code}
54 @center (manual revision: 2.66)
55 @sp 2 52 @sp 2
56 @center Barry A. Warsaw 53 @center Barry A. Warsaw
57 54
58 55
59 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 56 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
110 @macro ccmode 107 @macro ccmode
111 CC Mode 108 CC Mode
112 @end macro 109 @end macro
113 110
114 @cindex BOCM 111 @cindex BOCM
115 Welcome to @ccmode{}, version 4. This is a GNU Emacs mode for 112
116 editing files containing C, C++, Objective-C, and Java code. 113 Welcome to @ccmode{}. This is a GNU Emacs mode for editing files
117 This incarnation of the mode is descendant from @file{c-mode.el} (also 114 containing C, C++, Objective-C, and Java code. This incarnation of the
118 called "Boring Old C Mode" or BOCM @code{:-)}, and @file{c++-mode.el} 115 mode is descendant from @file{c-mode.el} (also called "Boring Old C
119 version 2, which I have been maintaining since 1992. @ccmode{} 116 Mode" or BOCM @code{:-)}, and @file{c++-mode.el} version 2, which I have
120 represents a significant milestone in the mode's life. It has been 117 been maintaining since 1992. @ccmode{} represents a significant
121 fully merged back with Emacs 19's @file{c-mode.el}. Also a new, more 118 milestone in the mode's life. It has been fully merged back with Emacs
122 intuitive and flexible mechanism for controlling indentation has been 119 19's @file{c-mode.el}. Also a new, more intuitive and flexible mechanism
123 developed. 120 for controlling indentation has been developed.
124 121
125 @ccmode{} version 4 supports the editing of K&R and ANSI C, @dfn{ARM} 122 @ccmode{} supports the editing of K&R and ANSI C, @dfn{ARM}
126 @footnote{``The Annotated C++ Reference Manual'', by Ellis and 123 @footnote{``The Annotated C++ Reference Manual'', by Ellis and
127 Stroustrup.} C++, Objective-C, and Java files. In this way, you can 124 Stroustrup.} C++, Objective-C, and Java files. In this way, you can
128 easily set up consistent coding styles for use in editing all C, C++, 125 easily set up consistent coding styles for use in editing all C, C++,
129 Objective-C, and Java programs. @ccmode{} does @emph{not} handle 126 Objective-C, and Java programs. @ccmode{} does @emph{not} handle
130 font-locking (a.k.a. syntax coloring, keyword highlighting) or anything 127 font-locking (a.k.a. syntax coloring, keyword highlighting) or anything
152 prefixed with @code{c-@var{<thing>}}, and @code{c-mode}, 149 prefixed with @code{c-@var{<thing>}}, and @code{c-mode},
153 @code{c++-mode}, @code{objc-mode}, and @code{java-mode} entry points are 150 @code{c++-mode}, @code{objc-mode}, and @code{java-mode} entry points are
154 provided. This file is intended to be a replacement for 151 provided. This file is intended to be a replacement for
155 @file{c-mode.el} and @file{c++-mode.el}. 152 @file{c-mode.el} and @file{c++-mode.el}.
156 153
157 @findex c-version
158 The major version number was incremented to 4 with the addition of
159 @code{objc-mode}. To find the minor revision number of this release, use
160 @kbd{M-x c-version RET}.
161
162 As of this writing (27-Feb-1997), Emacs 19.34, XEmacs 19.14, and XEmacs
163 20.0 are all distributed with @ccmode{}, but they may not have the
164 latest releases. You may therefore, want to upgrade your copy of
165 @ccmode{}. See @ref{Getting the latest CC Mode release}.
166
167 @cindex @file{cc-compat.el} file 154 @cindex @file{cc-compat.el} file
168 This distribution also contains a file called @file{cc-compat.el} which 155 This distribution also contains a file called @file{cc-compat.el} which
169 should ease your transition from BOCM to @ccmode{}. It currently 156 should ease your transition from BOCM to @ccmode{}. It currently
170 comes unguaranteed and unsupported, but this may change for future 157 comes unguaranteed and unsupported, but this may change for future
171 versions. If you have a BOCM configuration you are really happy with, 158 versions. If you have a BOCM configuration you are really happy with,
184 @chapter Getting Connected 171 @chapter Getting Connected
185 @cindex Getting Connected 172 @cindex Getting Connected
186 173
187 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 174 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
188 175
189 @file{cc-mode.el} works well with the three main branches of Emacs: 176 If you got this version of @ccmode{} with Emacs, it should work just
190 XEmacs 19 and XEmacs 20, both maintained by @code{xemacs.org}, and Emacs 177 fine right out of the box, and you can safely skip to the next chapter.
191 19 maintained by the Free Software Foundation. Emacs users will want to 178 Note however that you may not have the latest @ccmode{} release and may
192 use version 19.21 or better, XEmacs users will want 19.6 or better. 179 want to upgrade your copy. See the @file{README} file, or the @ccmode{}
193 Earlier versions of these Emacsen have deficiencies and/or bugs which 180 Web pages latest information on Emacs version compatibility,
194 will adversely affect the performance and usability of @ccmode{}. You 181 @ref{Getting the latest CC Mode release}.
195 are better off just getting the latest version of Emacs or XEmacs.
196 182
197 @cindex @file{cc-mode-18.el} file 183 @cindex @file{cc-mode-18.el} file
198 @file{cc-mode.el} will work with Emacs 18 if you use the 184 @emph{@ccmode{} no longer works with Emacs 18!} The
199 @file{cc-mode-18.el} compatibility file, but only moderately well. A 185 @file{cc-mode-18.el} file is no longer distributed with @ccmode{}. If
200 word of warning though, @emph{Emacs 18 lacks some fundamental 186 you haven't upgraded from Emacs 18 by now, you are out of luck. The
201 functionality and ultimately, using Emacs 18 is a losing 187 rest of these installation instructions assume you are using one of the
202 battle}. Hence @ccmode{} under Emacs 18 is no longer supported and 188 new Emacs or XEmacs releases, that already come with @ccmode{}. These
203 it is highly recommended that you upgrade to Emacs 19. If you use 189 instructions explain how to upgrade to use the latest @ccmode{}
204 @ccmode{} under Emacs 18, you're on your own. With @ccmode{} 190 release.
205 version 5, Emacs 18 support will be dropped altogether.
206
207 Note that as of XEmacs 19.13 and Emacs 19.30, your Emacs already comes
208 with @ccmode{} version 4 preconfigured for your use. You should be
209 able to safely skip the rest of the setup information in this chapter,
210 unless you want to install the latest version of @ccmode{} into one
211 of these Emacsen.
212 191
213 @cindex .emacs file 192 @cindex .emacs file
214 The first thing you will want to do is put @file{cc-mode.el} somewhere 193
215 on your @code{load-path} so Emacs can find it. Do a @kbd{C-h v 194 The first thing you will want to do is put the @ccmode{} source files in
216 load-path RET} to see all the directories Emacs looks at when loading a 195 a subdirectory somewhere on your @code{load-path} so Emacs can find it.
217 file. If none of these directories are appropriate, create a new 196 The distribution tarball unpacks into its own subdirectory tagged with
218 directory and add it to your @code{load-path}: 197 the version number of the release. E.g. @ccmode{} release 5.00 will
219 198 unpack into the @file{cc-mode-5.00} directory. Assuming you unpacked
220 @noindent 199 the distribution in your home directory, you should add the following to
221 @emph{[in the shell]} 200 your @file{.emacs} file in order to pick up the latest version of
222 @example 201 @ccmode{} over the one distributed with your Emacs:
223 @group 202
224 203 @example
225 % cd 204
226 % mkdir mylisp 205 (setq load-path (cons "~/cc-mode-5.00" load-path))
227 % mv cc-mode.el mylisp
228 % cd mylisp
229
230 @end group
231 @end example
232
233 @noindent
234 @emph{[in your .emacs file add]}
235 @example
236
237 (setq load-path (cons "~/mylisp" load-path))
238 206
239 @end example 207 @end example
240 208
241 @cindex byte compile 209 @cindex byte compile
242 Next you want to @dfn{byte compile} @file{cc-mode.el}. The mode uses a 210
243 lot of macros so if you don't byte compile it, things will be unbearably 211 Next you want to @dfn{byte compile} all the @ccmode{} source files.
244 slow. @emph{You can ignore all byte-compiler warnings!} They are the 212 @ccmode{} uses a lot of macros so if you don't byte compile it,
245 result of the supporting different versions of Emacs, and none of the 213 things will be unbearably slow. @emph{You can ignore all byte-compiler
246 warnings have any effect on operation. Let me say this again: 214 warnings!} They are the result of the supporting different versions of
247 @strong{You really can ignore all byte-compiler warnings!} 215 Emacs, and none of the warnings have any effect on operation. Let me say
248 216 this again: @strong{You really can ignore all byte-compiler warnings!}
249 Here's what to do to byte-compile the file [in emacs]: 217
250 @example 218 To byte-compile the source files, be sure you have access to the
251 219 @code{make(1)} program. In a shell, execute the following commands
252 M-x byte-compile-file RET ~/mylisp/cc-mode.el RET 220 (again, assuming you unpacked @ccmode{} version 5.00 in your home
253 221 directory@footnote{Of course, the version numbers will probably be
254 @end example 222 different.}):
255 223
256 If you are running a version of Emacs or XEmacs that comes with 224 @example
257 @ccmode{} by default, you can simply add the following to your 225
258 @file{.emacs} file in order to upgrade to the latest version of 226 % cd ~/cc-mode-5.00
259 @ccmode{}: 227 % make
260 @example 228
261 229 @end example
262 (load "cc-mode") 230
263 231 By default, the @file{Makefile} assumes you are using XEmacs. If you
264 @end example 232 are using Emacs, execute this instead:
265 233
266 Users of even older versions of Emacs 19, Emacs 18, or of the older 234 @example
267 Lucid Emacs will probably be running an Emacs that has BOCM 235
268 @file{c-mode.el} and possible @file{c++-mode.el} pre-dumped. If your 236 % make EMACS=emacs
269 Emacs is dumped with either of these files you first need to make Emacs 237
270 ``forget'' about those older modes. 238 @end example
271 239
272 If you can do a @kbd{C-h v c-mode-map RET} without getting an error, you 240 Next time you start up Emacs you should be using the latest @ccmode{}.
273 need to add these lines at the top of your @file{.emacs} file: 241 You can test this by visiting a C file and hitting @kbd{M-x c-version
274 @example 242 RET}; you should see this message in the echo area:
275 @group 243 @example
276 244
277 (fmakunbound 'c-mode) 245 Using CC Mode version 5.00
278 (makunbound 'c-mode-map) 246
279 (fmakunbound 'c++-mode) 247 @end example
280 (makunbound 'c++-mode-map)
281 (makunbound 'c-style-alist)
282
283 @end group
284 @end example
285
286 After those lines you will want to add the following autoloads to your
287 @file{.emacs} file so that @ccmode{} gets loaded at the right time:
288 @example
289 @group
290
291 (autoload 'c++-mode "cc-mode" "C++ Editing Mode" t)
292 (autoload 'c-mode "cc-mode" "C Editing Mode" t)
293 (autoload 'objc-mode "cc-mode" "Objective-C Editing Mode" t)
294 (autoload 'java-mode "cc-mode" "Java Editing Mode" t)
295
296 @end group
297 @end example
298
299 Alternatively, if you want to make sure @ccmode{} is loaded when
300 Emacs starts up, you could use this line instead of the autoloads
301 above:
302 @example
303
304 (require 'cc-mode)
305
306 @end example
307
308 Next, you will want to set up Emacs so that it edits C files in
309 @code{c-mode}, C++ files in @code{c++-mode}, Objective-C files in
310 @code{objc-mode}, and Java files in @code{java-mode}. You should
311 add the following to your @file{.emacs} file, which assumes
312 you'll be editing @code{.h} and @code{.c} files as C, @code{.hh},
313 @code{.cc}, @code{.H}, and @code{.C} files as C++, @code{.m} files as
314 Objective-C, and @code{.java} files as Java code. YMMV:
315 @example
316 @group
317
318 (setq auto-mode-alist
319 (append
320 '(("\\.C$" . c++-mode)
321 ("\\.H$" . c++-mode)
322 ("\\.cc$" . c++-mode)
323 ("\\.hh$" . c++-mode)
324 ("\\.c$" . c-mode)
325 ("\\.h$" . c-mode)
326 ("\\.m$" . objc-mode)
327 ("\\.java$" . java-mode)
328 ) auto-mode-alist))
329
330 @end group
331 @end example
332
333 You may already have some or all of these settings on your
334 @code{auto-mode-alist}, but it won't hurt to put them on there again.
335
336 That's all you need --- I know, I know, it sounds like a lot @code{:-)},
337 but after you've done all this, you should only need to quit and restart
338 Emacs. The next time you visit a C, C++, Objective-C, or Java file you
339 should be using @ccmode{}. You can check this easily by hitting
340 @kbd{M-x c-version RET}; you should see this message in the echo area:
341 @example
342
343 Using CC Mode version 4.@var{xxx}
344
345 @end example
346
347 @noindent
348 where @var{xxx} is the latest minor release number.
349 248
350 249
351 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 250 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
352 @node New Indentation Engine, Minor Modes, Getting Connected, Top 251 @node New Indentation Engine, Minor Modes, Getting Connected, Top
353 @comment node-name, next, previous, up 252 @comment node-name, next, previous, up
1142 @dfn{hungry-delete mode}, is a simple feature that some people find 1041 @dfn{hungry-delete mode}, is a simple feature that some people find
1143 extremely useful. In fact, you might find yourself wanting 1042 extremely useful. In fact, you might find yourself wanting
1144 hungry-delete in @strong{all} your editing modes! 1043 hungry-delete in @strong{all} your editing modes!
1145 1044
1146 @kindex DEL 1045 @kindex DEL
1147 In a nutshell, when hungry-delete mode is enabled, hitting the @kbd{DEL} 1046 @kindex Backspace
1148 character will consume all preceding whitespace, including newlines and 1047 In a nutshell, when hungry-delete mode is enabled, hitting the
1149 tabs. This can really cut down on the number of @kbd{DEL}'s you have to 1048 @kbd{Backspace} key@footnote{I say ``hit the @kbd{Backspace} key'' but
1150 type if, for example you made a mistake on the preceding line. 1049 what I really mean is ``when Emacs receives the @code{BackSpace} keysym
1050 event''. The difference usually isn't significant to most users, but
1051 advanced users will realize that under window systems such as X, any
1052 physical key (keycap) on the keyboard can be configured to generate any
1053 keysym. Also, the use of Emacs on TTYs will affect which keycap
1054 generates which keysym. From a pedantic point of view, here we are only
1055 concerned with the keysym event that Emacs receives.} will consume all
1056 preceding whitespace, including newlines and tabs. This can really cut
1057 down on the number of @kbd{Backspace}'s you have to type if, for example
1058 you made a mistake on the preceding line.
1059
1060 @findex c-electric-backspace
1061 @findex electric-backspace (c-)
1062 @vindex c-backspace-function
1063 @vindex backspace-function (c-)
1151 1064
1152 @findex c-electric-delete 1065 @findex c-electric-delete
1153 @findex electric-delete (c-) 1066 @findex electric-delete (c-)
1154 @vindex c-delete-function 1067 @vindex c-delete-function
1155 @vindex delete-function (c-) 1068 @vindex delete-function (c-)
1156 @cindex literal 1069 @cindex literal
1157 By default, @ccmode{} actually runs the command 1070
1158 @code{c-electric-delete} when you hit @kbd{DEL}. When this command is 1071 @findex backward-delete-char-untabify
1159 used to delete a single character (i.e. when it is called interactively 1072
1160 with no numeric argument), it really runs the function contained in the 1073 By default, when you hit the @kbd{Backspace} key
1161 variable @code{c-delete-function}. This function is called with a 1074 @ccmode{} runs the command @code{c-electric-backspace}, which deletes
1162 single argument, which is the number of characters to delete. 1075 text in the backwards direction. When deleting a single character, or
1163 @code{c-delete-function} is also called when the @kbd{DEL} key is typed 1076 when @kbd{Backspace} is hit in a literal
1164 inside a literal (see @ref{Auto-newline insertion}. Inside a literal, 1077 (see @ref{Auto-newline insertion}),
1165 @code{c-electric-delete} is not electric, which is typical of all the 1078 or when hungry-delete mode is disabled, the function
1166 so-called electric commands. 1079 contained in the @code{c-backspace-function} variable is called with one
1080 argument (the number of characters to delete). This variable is set to
1081 @code{backward-delete-char-untabify} by default.
1082
1083 @vindex delete-key-deletes-forward
1084 @findex delete-char
1085
1086 Similarly, hitting the @kbd{DEL} key runs the command
1087 @code{c-electric-delete}. Some versions of Emacs@footnote{As of this
1088 writing, 20-Jun-1997, only XEmacs 20 supports this.} support separation
1089 of the @kbd{Backspace} and @kbd{DEL} keys, so that @kbd{DEL} will delete
1090 in the forward direction when @code{delete-key-deletes-forward} is
1091 non-@code{nil}. If your Emacs supports this, and
1092 @code{delete-key-deletes-forward} is non-@code{nil}, and hungry-delete
1093 mode is enabled, then @kbd{DEL} will consume all whitespace following
1094 point. When deleting a single character, or when @kbd{DEL} is hit in a
1095 literal, or when hungry-delete mode is disabled, the function contained
1096 in the @code{c-delete-function} variable is called with one argument
1097 (the number of characters to delete). This variable is set to
1098 @code{delete-char} by default.
1099
1100 However, if @code{delete-key-deletes-forward} is @code{nil}, or your
1101 Emacs does not support separation of @kbd{Backspace} and @kbd{DEL}, then
1102 @code{c-electric-delete} simply calls @code{c-electric-backspace}.
1167 1103
1168 1104
1169 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 1105 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1170 @node Commands, Customizing Indentation, Minor Modes, Top 1106 @node Commands, Customizing Indentation, Minor Modes, Top
1171 @comment node-name, next, previous,up 1107 @comment node-name, next, previous,up
1474 @noindent 1410 @noindent
1475 So, for example, because most of the default offsets are defined in 1411 So, for example, because most of the default offsets are defined in
1476 terms of @code{+}, @code{-}, and @code{0}, if you like the general 1412 terms of @code{+}, @code{-}, and @code{0}, if you like the general
1477 indentation style, but you use 4 spaces instead of 2 spaces per level, 1413 indentation style, but you use 4 spaces instead of 2 spaces per level,
1478 you can probably achieve your style just by changing 1414 you can probably achieve your style just by changing
1479 @code{c-basic-offset} like so (in your @file{.emacs} file)@footnote{The 1415 @code{c-basic-offset} like so (in your @file{.emacs} file):
1480 reason you need to use @code{setq-default} instead of @code{setq} is 1416 @example
1481 that @code{c-basic-offset} is a buffer local variable, as are most 1417
1482 configuration variables. If you were to put this code in, e.g. your 1418 (setq c-basic-offset 4)
1483 @code{c-mode-common-hook} function, you could use @code{setq}.
1484 Alternatively, you can keep these variables global by setting
1485 @code{c-style-variables-are-local-p} to @code{nil}, but you must do this
1486 before @code{cc-mode.el} is loaded into your Emacs session.}:
1487 @example
1488
1489 (setq-default c-basic-offset 4)
1490 1419
1491 @end example 1420 @end example
1492 1421
1493 @noindent 1422 @noindent
1494 This would change 1423 This would change
1652 @vindex c-mode-hook 1581 @vindex c-mode-hook
1653 @vindex c++-mode-hook 1582 @vindex c++-mode-hook
1654 @vindex objc-mode-hook 1583 @vindex objc-mode-hook
1655 @vindex java-mode-hook 1584 @vindex java-mode-hook
1656 @cindex hooks 1585 @cindex hooks
1657 To make this change permanent, you need to add some lisp code to your 1586 To make your changes permanent, you need to add some lisp code to your
1658 @file{.emacs} file. @ccmode{} provides several hooks that you can 1587 @file{.emacs} file, but first you need to decide whether your styles
1588 should be global in every buffer, or local to each specific buffer.
1589
1590 If you edit primarily one style of C (or C++, Objective-C, Java) code,
1591 you may want to make the @ccmode{} style variables have global values so
1592 that every buffer will share the style settings. This will allow you to
1593 set the @ccmode{} variables at the top level of your @file{.emacs}
1594 file. This is the default way @ccmode{} works.
1595
1596 @vindex c-mode-common-hook
1597 @vindex mode-common-hook (c-)
1598 @vindex c-style-variables-are-local-p
1599 @vindex style-variables-are-local-p (c-)
1600 If you edit many different styles of C (or C++, Objective-C, Java) at
1601 the same time, you probably want to make the @ccmode{} style variables
1602 have buffer local values. If you do this, then you will need to set any
1603 @ccmode{} style variables in a hook function (e.g. off of
1604 @code{c-mode-common-hook} instead of at the top level of your
1605 @file{.emacs} file. The recommended way to do this is to set the
1606 variable @code{c-style-variables-are-local-p} to @code{t}
1607 @strong{before} @ccmode{} is loaded into your Emacs session.
1608
1609 @ccmode{} provides several hooks that you can
1659 use to customize the mode according to your coding style. Each language 1610 use to customize the mode according to your coding style. Each language
1660 mode has its own hook, adhering to standard Emacs major mode 1611 mode has its own hook, adhering to standard Emacs major mode
1661 conventions. There is also one general hook: 1612 conventions. There is also one general hook:
1662 1613
1663 @itemize @bullet 1614 @itemize @bullet
1690 Here's a simplified example of what you can add to your @file{.emacs} 1641 Here's a simplified example of what you can add to your @file{.emacs}
1691 file to make the changes described in the previous section 1642 file to make the changes described in the previous section
1692 (@ref{Interactive Customization}) more permanent. See the Emacs manuals 1643 (@ref{Interactive Customization}) more permanent. See the Emacs manuals
1693 for more information on customizing Emacs via hooks. @xref{Sample 1644 for more information on customizing Emacs via hooks. @xref{Sample
1694 .emacs File} for a more complete sample @file{.emacs} file. 1645 .emacs File} for a more complete sample @file{.emacs} file.
1695 @footnote{The use of @code{add-hook} in this example only works for
1696 Emacs 19 and beyond. Workarounds are available if you are using Emacs
1697 18.}
1698 @example 1646 @example
1699 @group 1647 @group
1700 1648
1701 (defun my-c-mode-common-hook () 1649 (defun my-c-mode-common-hook ()
1702 ;; my customizations for all of c-mode, c++-mode, objc-mode, java-mode 1650 ;; my customizations for all of c-mode, c++-mode, objc-mode, java-mode
1963 you will have to make the variables buffer local. The variable 1911 you will have to make the variables buffer local. The variable
1964 @code{c-style-variables-are-local-p} controls this. 1912 @code{c-style-variables-are-local-p} controls this.
1965 1913
1966 When @code{c-style-variables-are-local-p} is non-nil, then the style 1914 When @code{c-style-variables-are-local-p} is non-nil, then the style
1967 variables will have a different settable value for each buffer, 1915 variables will have a different settable value for each buffer,
1968 otherwise all buffers will share the same values. This variable only 1916 otherwise all buffers will share the same values. By default, its value
1969 takes effect when @ccmode{} is loaded into your Emacs session. By 1917 is @code{nil} (i.e. global values). You @strong{must} set this variable
1970 default (for backwards compatibility reasons), its value is @code{t}. 1918 before @ccmode{} is loaded into your Emacs session, and once the
1971 Note that once the variables are made buffer local, they will retain 1919 variables are made buffer local, they cannot be made global again
1972 this property for the remainder of the current Emacs session. To change 1920 (unless you restart Emacs of course!)
1973 this behavior, set @code{c-style-variables-are-local-p} to @code{nil}
1974 @emph{before} you load @file{cc-mode.el}.
1975 1921
1976 @menu 1922 @menu
1977 * Custom Indentation Functions:: 1923 * Custom Indentation Functions::
1978 * Custom Brace and Colon Hanging:: 1924 * Custom Brace and Colon Hanging::
1979 * Customizing Semi-colons and Commas:: 1925 * Customizing Semi-colons and Commas::
2388 @item 2334 @item
2389 @code{inline-open} --- brace that opens an in-class inline method 2335 @code{inline-open} --- brace that opens an in-class inline method
2390 @item 2336 @item
2391 @code{inline-close} --- brace that closes an in-class inline method 2337 @code{inline-close} --- brace that closes an in-class inline method
2392 @item 2338 @item
2393 @code{func-decl-cont} --- the nether region between a function 2339 @code{func-decl-cont} --- the region between a function definition's
2394 declaration's argument list and the defun opening brace. In C++ and 2340 argument list and the function opening brace (excluding K&R argument
2395 Java, this can include the @code{throws} clauses of a method 2341 declarations). In C, you cannot put anything but whitespace and comments
2396 declaration. 2342 between them; in C++ and Java, @code{throws} declarations and other
2343 things can appear in this context.
2397 @item 2344 @item
2398 @code{knr-argdecl-intro} --- first line of a K&R C argument declaration 2345 @code{knr-argdecl-intro} --- first line of a K&R C argument declaration
2399 @item 2346 @item
2400 @code{knr-argdecl} --- subsequent lines in a K&R C argument declaration 2347 @code{knr-argdecl} --- subsequent lines in a K&R C argument declaration
2401 @item 2348 @item
2677 2624
2678 @cindex friend syntactic symbol 2625 @cindex friend syntactic symbol
2679 Returning to the previous example, line 16 is given @code{inline-close} 2626 Returning to the previous example, line 16 is given @code{inline-close}
2680 syntax, while line 12 is given @code{defun-block-open} syntax, and lines 2627 syntax, while line 12 is given @code{defun-block-open} syntax, and lines
2681 13 through 15 are all given @code{statement} syntax. Line 17 is 2628 13 through 15 are all given @code{statement} syntax. Line 17 is
2682 interesting in that it's syntactic analysis list contains three 2629 interesting in that its syntactic analysis list contains three
2683 elements: 2630 elements:
2684 2631
2685 @example 2632 @example
2686 2633
2687 @code{((friend) (inclass . 58) (topmost-intro . 380))} 2634 @code{((friend) (inclass . 58) (topmost-intro . 380))}
3018 2965
3019 @chapter Performance Issues 2966 @chapter Performance Issues
3020 @cindex Performance Issues 2967 @cindex Performance Issues
3021 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 2968 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3022 2969
3023 C and it's derivative languages are highly complex creatures. Often, 2970 C and its derivative languages are highly complex creatures. Often,
3024 ambiguous code situations arise that require @ccmode{} to scan 2971 ambiguous code situations arise that require @ccmode{} to scan
3025 large portions of the buffer to determine syntactic context. Such 2972 large portions of the buffer to determine syntactic context. Such
3026 pathological code@footnote{such as the output of @code{lex(1)}!} 2973 pathological code@footnote{such as the output of @code{lex(1)}!}
3027 can cause @ccmode{} to perform fairly badly. 2974 can cause @ccmode{} to perform fairly badly.
3028 This section identifies some of the coding styles to watch out for, and 2975 This section identifies some of the coding styles to watch out for, and
3082 column zero! 3029 column zero!
3083 3030
3084 @cindex @file{cc-lobotomy.el} file 3031 @cindex @file{cc-lobotomy.el} file
3085 @vindex cc-lobotomy-pith-list 3032 @vindex cc-lobotomy-pith-list
3086 You might want to investigate the speed-ups contained in the 3033 You might want to investigate the speed-ups contained in the
3087 file @file{cc-lobotomy.el}, which is part of the @ccmode{} distribution. 3034 file @file{cc-lobotomy.el}, which comes as part of the @ccmode{}
3035 distribution, but is completely unsupported.
3088 As mentioned previous, @ccmode{} always trades accuracy for speed, 3036 As mentioned previous, @ccmode{} always trades accuracy for speed,
3089 however it is recognized that sometimes you need speed and can sacrifice 3037 however it is recognized that sometimes you need speed and can sacrifice
3090 some accuracy in indentation. The file @file{cc-lobotomy.el} contains 3038 some accuracy in indentation. The file @file{cc-lobotomy.el} contains
3091 hacks that will ``dumb down'' @ccmode{} in some specific ways, making 3039 hacks that will ``dumb down'' @ccmode{} in some specific ways, making
3092 that trade-off of speed for accuracy. I won't go into details of its 3040 that trade-off of speed for accuracy. I won't go into details of its
3108 @kindex ESC C-x 3056 @kindex ESC C-x
3109 @kindex C-c C-q 3057 @kindex C-c C-q
3110 @kindex ESC C-q 3058 @kindex ESC C-q
3111 @kindex ESC C-u 3059 @kindex ESC C-u
3112 @kindex RET 3060 @kindex RET
3113 @kindex LFD 3061 @kindex C-j
3114 @findex newline-and-indent 3062 @findex newline-and-indent
3115 @quotation 3063 @quotation
3116 3064
3117 @strong{Q.} @emph{How do I re-indent the whole file?} 3065 @strong{Q.} @emph{How do I re-indent the whole file?}
3118 3066
3136 3084
3137 @strong{Q.} @emph{Why doesn't the @key{RET} key indent the line to 3085 @strong{Q.} @emph{Why doesn't the @key{RET} key indent the line to
3138 where the new text should go after inserting the newline?} 3086 where the new text should go after inserting the newline?}
3139 3087
3140 @strong{A.} Emacs' convention is that @key{RET} just adds a newline, 3088 @strong{A.} Emacs' convention is that @key{RET} just adds a newline,
3141 and that @key{LFD} adds a newline and indents it. You can make 3089 and that @key{C-j} adds a newline and indents it. You can make
3142 @key{RET} do this too by adding this to your 3090 @key{RET} do this too by adding this to your
3143 @code{c-mode-common-hook} (see the sample @file{.emacs} file 3091 @code{c-mode-common-hook} (see the sample @file{.emacs} file
3144 @ref{Sample .emacs File}): 3092 @ref{Sample .emacs File}):
3145 @example 3093 @example
3146 3094
3175 @strong{Q.} @emph{How do I make strings, comments, keywords, and other 3123 @strong{Q.} @emph{How do I make strings, comments, keywords, and other
3176 constructs appear in different colors, or in bold face, etc.?} 3124 constructs appear in different colors, or in bold face, etc.?}
3177 3125
3178 @strong{A.} ``Syntax Colorization'' is an Emacs 19 feature, controlled 3126 @strong{A.} ``Syntax Colorization'' is an Emacs 19 feature, controlled
3179 by @code{font-lock-mode}. It is not part of @ccmode{}. 3127 by @code{font-lock-mode}. It is not part of @ccmode{}.
3180
3181 @sp 1
3182 @strong{Q.} @emph{I @code{setq} @code{c-basic-offset} to 4 in my
3183 @file{.emacs} file, but why does everything still get indented with only
3184 2 spaces?}
3185
3186 @vindex c-style-variables-are-local-p
3187 @vindex style-variables-are-local-p
3188 @strong{A.} It's because @code{c-basic-offset} is, by default, a
3189 ``buffer local variable'', meaning its value is unique to each buffer.
3190 The prefered way to customize this is to change its value in a ``mode
3191 hook'' (most likely @code{c-mode-common-hook}). Alternatively you can
3192 use @code{setq-default} to change its value globally. Better yet,
3193 before you load @file{cc-mode.el}, set the variable
3194 @code{c-style-variables-are-local-p} to @code{nil}. @xref{Advanced
3195 Customizations}.
3196 3128
3197 @end quotation 3129 @end quotation
3198 3130
3199 3131
3200 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 3132 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3305 ;; c-mode-map because c++-mode-map, objc-mode-map, and java-mode-map 3237 ;; c-mode-map because c++-mode-map, objc-mode-map, and java-mode-map
3306 ;; inherit from it. 3238 ;; inherit from it.
3307 (define-key c-mode-map "\C-m" 'newline-and-indent) 3239 (define-key c-mode-map "\C-m" 'newline-and-indent)
3308 ) 3240 )
3309 3241
3310 ;; the following only works in Emacs 19
3311 ;; Emacs 18ers can use (setq c-mode-common-hook 'my-c-mode-common-hook)
3312 (add-hook 'c-mode-common-hook 'my-c-mode-common-hook) 3242 (add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
3313 @end example 3243 @end example
3314 3244
3315 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 3245 @comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3316 @node Limitations and Known Bugs, Mailing Lists and Submitting Bug Reports, Sample .emacs File, Top 3246 @node Limitations and Known Bugs, Mailing Lists and Submitting Bug Reports, Sample .emacs File, Top
3324 @item 3254 @item
3325 Multi-line macros are not handled properly. 3255 Multi-line macros are not handled properly.
3326 3256
3327 @item 3257 @item
3328 Re-indenting large regions or expressions can be slow. 3258 Re-indenting large regions or expressions can be slow.
3329
3330 @item
3331 Use with Emacs 18 can be slow and annoying. You should seriously
3332 consider upgrading to Emacs 19.
3333 3259
3334 @item 3260 @item
3335 Add-on fill packages may not work as well as @ccmode{}'s built-in 3261 Add-on fill packages may not work as well as @ccmode{}'s built-in
3336 filling routines. I no longer recommend you use @code{filladapt} to 3262 filling routines. I no longer recommend you use @code{filladapt} to
3337 fill comments. 3263 fill comments.
3373 Usenet newsgroup @code{gnu.emacs.bug}. You can send other questions, 3299 Usenet newsgroup @code{gnu.emacs.bug}. You can send other questions,
3374 suggestions, and kudos to @code{cc-mode-help@@python.org}, or 3300 suggestions, and kudos to @code{cc-mode-help@@python.org}, or
3375 @code{help-gnu-emacs@@prep.ai.mit.edu} which is mirrored on newsgroup 3301 @code{help-gnu-emacs@@prep.ai.mit.edu} which is mirrored on newsgroup
3376 @code{gnu.emacs.help}. 3302 @code{gnu.emacs.help}.
3377 3303
3304 There are two mailing lists for @ccmode{}. One is a general discussion
3305 list and the other is an announce-only list. You do not need to
3306 subscribe to either list, but if you want to, only subscribe to one of
3307 these. Announcements of new releases get sent to both lists. To join
3308 the general discussion list, send a message with the word
3309 @emph{subscribe} in the body of the message to
3310 @code{cc-mode-victims-request@@python.org}. To join just the
3311 announce-only list, send a message with the word @emph{subscribe} in the
3312 body of the message to @code{cc-mode-announce-request@@python.org}.
3313 Both mailing lists are managed by Majordomo, and if you are successfully
3314 subscribed, you will receive an email message with more information on
3315 using the list.
3378 3316
3379 @c !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 3317 @c !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3380 @node Concept Index, Command Index, Mailing Lists and Submitting Bug Reports, Top 3318 @node Concept Index, Command Index, Mailing Lists and Submitting Bug Reports, Top
3381 @comment node-name, next, previous, up 3319 @comment node-name, next, previous, up
3382 @unnumbered Concept Index 3320 @unnumbered Concept Index