comparison lisp/modes/cc-mode.el @ 70:131b0175ea99 r20-0b30

Import from CVS: tag r20-0b30
author cvs
date Mon, 13 Aug 2007 09:02:59 +0200
parents 05472e90ae02
children 54cc21c15cbb
comparison
equal deleted inserted replaced
69:804d1389bcd6 70:131b0175ea99
1 ;;; cc-mode.el --- major mode for editing C, C++, Objective-C, and Java code 1 ;;; cc-mode.el --- major mode for editing C, C++, Objective-C, and Java code
2 2
3 ;; Copyright (C) 1985,87,92,93,94,95,96,97 Free Software Foundation, Inc. 3 ;; Copyright (C) 1985, 87, 92, 93, 94, 95, 96 Free Software Foundation, Inc.
4 4
5 ;; Authors: 1992-1997 Barry A. Warsaw 5 ;; Authors: 1992-1996 Barry A. Warsaw
6 ;; 1987 Dave Detlefs and Stewart Clamen 6 ;; 1987 Dave Detlefs and Stewart Clamen
7 ;; 1985 Richard M. Stallman 7 ;; 1985 Richard M. Stallman
8 ;; Created: a long, long, time ago. adapted from the original c-mode.el 8 ;; Created: a long, long, time ago. adapted from the original c-mode.el
9 ;; Version: 4.389 9 ;; Version: 4.322
10 ;; Last Modified: 1997/03/28 16:48:31 10 ;; Last Modified: 1996/10/04 20:28:14
11 ;; Keywords: c languages oop 11 ;; Keywords: c languages oop
12 12
13 ;; NOTE: Read the commentary below for the right way to submit bug reports! 13 ;; NOTE: Read the commentary below for the right way to submit bug reports!
14 ;; NOTE: See the accompanying texinfo manual for details on using this mode! 14 ;; NOTE: See the accompanying texinfo manual for details on using this mode!
15 15
30 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 30 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
31 ;; Boston, MA 02111-1307, USA. 31 ;; Boston, MA 02111-1307, USA.
32 32
33 ;;; Commentary: 33 ;;; Commentary:
34 34
35 ;; This package provides GNU Emacs major modes for editing C, C++, 35 ;; This package provides modes in GNU Emacs for editing C, C++,
36 ;; Objective-C, and Java code. As of the latest Emacs and XEmacs 36 ;; Objective-C, and Java code. It is intended to be a replacement for
37 ;; releases, it is the default package for editing these languages. 37 ;; c-mode.el (a.k.a. BOCM -- Boring Old C-Mode), and c++-mode.el
38 ;; This package is called "CC Mode", and should be spelled exactly 38 ;; (a.k.a cplus-md.el and cplus-md1.el), both of which are ancestors
39 ;; this way. It supports K&R and ANSI C, ANSI C++, Objective-C, and 39 ;; of this file. A number of important improvements have been made,
40 ;; Java, with a consistent indentation model across all modes. This 40 ;; briefly: complete K&R C, ANSI C, `ARM' C++, Objective-C, and Java
41 ;; indentation model is intuitive and very flexible, so that almost 41 ;; support with consistent indentation across all modes, more
42 ;; any desired style of indentation can be supported. Installation, 42 ;; intuitive indentation controlling variables, compatibility across
43 ;; usage, and programming details are contained in an accompanying 43 ;; all known Emacsen, nice new features, and tons of bug fixes. This
44 ;; texinfo manual. 44 ;; package is called "cc-mode" to distinguish it from its ancestors,
45 45 ;; but there really is no top-level cc-mode. Usage and programming
46 ;; CC Mode's immediate ancestors were, c++-mode.el, cplus-md.el, and 46 ;; details are contained in an accompanying texinfo manual.
47 ;; cplus-md1.el..
48 47
49 ;; NOTE: This mode does not perform font-locking (a.k.a syntactic 48 ;; NOTE: This mode does not perform font-locking (a.k.a syntactic
50 ;; coloring, keyword highlighting, etc.) for any of the supported 49 ;; coloring, keyword highlighting, etc.). Typically this is done by a
51 ;; modes. Typically this is done by a package called font-lock.el 50 ;; package called font-lock.el which I do *not* maintain. You should
52 ;; which I do *not* maintain. You should contact the Emacs 51 ;; contact the Emacs maintainer for questions about coloring or
53 ;; maintainers for questions about coloring or highlighting in any 52 ;; highlighting in any language mode.
54 ;; language mode.
55 53
56 ;; To submit bug reports, type "C-c C-b". These will be sent to 54 ;; To submit bug reports, type "C-c C-b". These will be sent to
57 ;; bug-gnu-emacs@prep.ai.mit.edu as well as cc-mode-help@python.org, 55 ;; bug-gnu-emacs@prep.ai.mit.edu as well as cc-mode-help@python.org,
58 ;; and I'll read about them there (the former is mirrored as the 56 ;; and I'll read about them there (the former is mirrored as the
59 ;; Usenet newsgroup gnu.emacs.bug). Questions can sent to 57 ;; Usenet newsgroup gnu.emacs.bug). Questions can sent to
60 ;; help-gnu-emacs@prep.ai.mit.edu (mirrored as gnu.emacs.help) and/or 58 ;; help-gnu-emacs@prep.ai.mit.edu (mirrored as gnu.emacs.help) or
61 ;; cc-mode-help@python.org. Please do not send bugs or questions to 59 ;; cc-mode-help@python.org. Please do not send bugs or questions to
62 ;; my personal account. 60 ;; my personal account.
63 61
64 ;; YOU CAN IGNORE ALL BYTE-COMPILER WARNINGS. They are the result of 62 ;; YOU CAN IGNORE ALL BYTE-COMPILER WARNINGS. They are the result of
65 ;; the cross-Emacsen support. GNU Emacs 19 (from the FSF), GNU XEmacs 63 ;; the multi-Emacsen support. Emacs 19 (from the FSF), XEmacs 19
66 ;; 19 (formerly Lucid Emacs), and GNU Emacs 18 all do things 64 ;; (formerly Lucid Emacs), and GNU Emacs 18 all do things differently
67 ;; differently and there's no way to shut the byte-compiler up at the 65 ;; and there's no way to shut the byte-compiler up at the necessary
68 ;; necessary granularity. Let me say this again: YOU CAN IGNORE ALL 66 ;; granularity. Let me say this again: YOU CAN IGNORE ALL
69 ;; BYTE-COMPILER WARNINGS (you'd be surprised at how many people don't 67 ;; BYTE-COMPILER WARNINGS (you'd be surprised at how many people don't
70 ;; follow this advice :-). 68 ;; follow this advice :-).
71 69
70 ;; If your Emacs is dumped with c-mode.el and/or c++-mode.el, you will
71 ;; need to add the following to your .emacs file before any other
72 ;; reference to c-mode or c++-mode:
73 ;;
74 ;; (fmakunbound 'c-mode)
75 ;; (makunbound 'c-mode-map)
76 ;; (fmakunbound 'c++-mode)
77 ;; (makunbound 'c++-mode-map)
78 ;; (makunbound 'c-style-alist)
79
80 ;; If your Emacs comes with cc-mode already (and as of 5-Jul-1996
81 ;; XEmacs 19.14 and Emacs 19.31 both do), you only need to add the
82 ;; following to use the latest version of cc-mode:
83 ;;
84 ;; (load "cc-mode")
85 ;;
86 ;; Make sure the new version is earlier on your load-path.
87
88 ;; There are four major mode entry points provided by this package,
89 ;; one for editing C++ code, one for editing C code (both K&R and
90 ;; ANSI), one for editing Objective-C code, and one for editing Java
91 ;; code. The commands are M-x c-mode, M-x c++-mode, M-x objc-mode,
92 ;; and M-x java-mode.
93
94 ;; If you are using an old version of Emacs which does not come
95 ;; with cc-mode.el, you will need to do these things
96 ;; to use it:
97 ;;
98 ;; (autoload 'c++-mode "cc-mode" "C++ Editing Mode" t)
99 ;; (autoload 'c-mode "cc-mode" "C Editing Mode" t)
100 ;; (autoload 'objc-mode "cc-mode" "Objective-C Editing Mode" t)
101 ;; (autoload 'java-mode "cc-mode" "Java Editing Mode" t)
102 ;; (setq auto-mode-alist
103 ;; (append '(("\\.C$" . c++-mode)
104 ;; ("\\.cc$" . c++-mode)
105 ;; ("\\.c$" . c-mode)
106 ;; ("\\.h$" . c-mode)
107 ;; ("\\.m$" . objc-mode)
108 ;; ("\\.java$" . java-mode)
109 ;; ) auto-mode-alist))
110 ;;
111 ;; You do not need these changes in Emacs versions that come with cc-mode.
112
72 ;; Many, many thanks go out to all the folks on the beta test list. 113 ;; Many, many thanks go out to all the folks on the beta test list.
73 ;; Without their patience, testing, insight, code contributions, and 114 ;; Without their patience, testing, insight, code contributions, and
74 ;; encouragement CC Mode would be a far inferior package. 115 ;; encouragement cc-mode.el would be a far inferior package.
75 116
76 ;; You can get the latest version of CC Mode, including PostScript 117 ;; You can get the latest version of cc-mode, including PostScript
77 ;; documentation and separate individual files from: 118 ;; documentation and separate individual files from:
78 ;; 119 ;;
79 ;; http://www.python.org/ftp/emacs/ 120 ;; http://www.python.org/ftp/emacs/
80 121
81 ;; Or if you don't have access to the World Wide Web, through 122 ;; Or if you don't have access to the World Wide Web, through
99 (defvar c-echo-syntactic-information-p nil 140 (defvar c-echo-syntactic-information-p nil
100 "*If non-nil, syntactic info is echoed when the line is indented.") 141 "*If non-nil, syntactic info is echoed when the line is indented.")
101 (defvar c-basic-offset 4 142 (defvar c-basic-offset 4
102 "*Amount of basic offset used by + and - symbols in `c-offsets-alist'.") 143 "*Amount of basic offset used by + and - symbols in `c-offsets-alist'.")
103 144
104 (defconst c-offsets-alist 145 (defvar c-offsets-alist
105 '((string . -1000) 146 '((string . -1000)
106 (c . c-lineup-C-comments) 147 (c . c-lineup-C-comments)
107 (defun-open . 0) 148 (defun-open . 0)
108 (defun-close . 0) 149 (defun-close . 0)
109 (defun-block-intro . +) 150 (defun-block-intro . +)
110 (class-open . 0) 151 (class-open . 0)
111 (class-close . 0) 152 (class-close . 0)
112 (inline-open . +) 153 (inline-open . +)
113 (inline-close . 0) 154 (inline-close . 0)
114 (func-decl-cont . +) 155 (ansi-funcdecl-cont . +)
115 (knr-argdecl-intro . +) 156 (knr-argdecl-intro . +)
116 (knr-argdecl . 0) 157 (knr-argdecl . 0)
117 (topmost-intro . 0) 158 (topmost-intro . 0)
118 (topmost-intro-cont . 0) 159 (topmost-intro-cont . 0)
119 (member-init-intro . +) 160 (member-init-intro . +)
161 "*Association list of syntactic element symbols and indentation offsets. 202 "*Association list of syntactic element symbols and indentation offsets.
162 As described below, each cons cell in this list has the form: 203 As described below, each cons cell in this list has the form:
163 204
164 (SYNTACTIC-SYMBOL . OFFSET) 205 (SYNTACTIC-SYMBOL . OFFSET)
165 206
166 When a line is indented, CC Mode first determines the syntactic 207 When a line is indented, cc-mode first determines the syntactic
167 context of the line by generating a list of symbols called syntactic 208 context of the line by generating a list of symbols called syntactic
168 elements. This list can contain more than one syntactic element and 209 elements. This list can contain more than one syntactic element and
169 the global variable `c-syntactic-context' contains the context list 210 the global variable `c-syntactic-context' contains the context list
170 for the line being indented. Each element in this list is actually a 211 for the line being indented. Each element in this list is actually a
171 cons cell of the syntactic symbol and a buffer position. This buffer 212 cons cell of the syntactic symbol and a buffer position. This buffer
172 position is called the relative indent point for the line. Some 213 position is called the relative indent point for the line. Some
173 syntactic symbols may not have a relative indent point associated with 214 syntactic symbols may not have a relative indent point associated with
174 them. 215 them.
175 216
176 After the syntactic context list for a line is generated, CC Mode 217 After the syntactic context list for a line is generated, cc-mode
177 calculates the absolute indentation for the line by looking at each 218 calculates the absolute indentation for the line by looking at each
178 syntactic element in the list. First, it compares the syntactic 219 syntactic element in the list. First, it compares the syntactic
179 element against the SYNTACTIC-SYMBOL's in `c-offsets-alist'. When it 220 element against the SYNTACTIC-SYMBOL's in `c-offsets-alist'. When it
180 finds a match, it adds the OFFSET to the column of the relative indent 221 finds a match, it adds the OFFSET to the column of the relative indent
181 point. The sum of this calculation for each element in the syntactic 222 point. The sum of this calculation for each element in the syntactic
182 list is the absolute offset for line being indented. 223 list is the absolute offset for line being indented.
183 224
184 If the syntactic element does not match any in the `c-offsets-alist', 225 If the syntactic element does not match any in the `c-offsets-alist',
185 an error is generated if `c-strict-syntax-p' is non-nil, otherwise the 226 an error is generated if `c-strict-syntax-p' is non-nil, otherwise
186 element is ignored. 227 the element is ignored.
187 228
188 Actually, OFFSET can be an integer, a function, a variable, or one of 229 Actually, OFFSET can be an integer, a function, a variable, or one of
189 the following symbols: `+', `-', `++', `--', `*', or `/'. These 230 the following symbols: `+', `-', `++', `--', `*', or `/'. These
190 latter designate positive or negative multiples of `c-basic-offset', 231 latter designate positive or negative multiples of `c-basic-offset',
191 respectively: *1, *-1, *2, *-2, *0.5, and *-0.5. If OFFSET is a 232 respectively: *1, *-1, *2, *-2, *0.5, and *-0.5. If OFFSET is a
202 defun-block-intro -- the first line in a top-level defun 243 defun-block-intro -- the first line in a top-level defun
203 class-open -- brace that opens a class definition 244 class-open -- brace that opens a class definition
204 class-close -- brace that closes a class definition 245 class-close -- brace that closes a class definition
205 inline-open -- brace that opens an in-class inline method 246 inline-open -- brace that opens an in-class inline method
206 inline-close -- brace that closes an in-class inline method 247 inline-close -- brace that closes an in-class inline method
207 func-decl-cont -- the nether region between a function 248 ansi-funcdecl-cont -- the nether region between an ANSI function
208 declaration and the defun opening brace. 249 declaration and the defun opening brace
209 In C++ and Java, this can include `throws'
210 declarations
211 knr-argdecl-intro -- first line of a K&R C argument declaration 250 knr-argdecl-intro -- first line of a K&R C argument declaration
212 knr-argdecl -- subsequent lines in a K&R C argument declaration 251 knr-argdecl -- subsequent lines in a K&R C argument declaration
213 topmost-intro -- the first line in a topmost construct definition 252 topmost-intro -- the first line in a topmost construct definition
214 topmost-intro-cont -- topmost definition continuation lines 253 topmost-intro-cont -- topmost definition continuation lines
215 member-init-intro -- first line in a member initialization list 254 member-init-intro -- first line in a member initialization list
258 (defvar c-tab-always-indent t 297 (defvar c-tab-always-indent t
259 "*Controls the operation of the TAB key. 298 "*Controls the operation of the TAB key.
260 If t, hitting TAB always just indents the current line. If nil, 299 If t, hitting TAB always just indents the current line. If nil,
261 hitting TAB indents the current line if point is at the left margin or 300 hitting TAB indents the current line if point is at the left margin or
262 in the line's indentation, otherwise it insert a `real' tab character 301 in the line's indentation, otherwise it insert a `real' tab character
263 \(see note\). If other than nil or t, then tab is inserted only 302 \(see note\). If other than nil or t, then tab is inserted only within
264 within literals -- defined as comments and strings -- and inside 303 literals -- defined as comments and strings -- and inside preprocessor
265 preprocessor directives, but line is always reindented. 304 directives, but line is always reindented.
266 305
267 Note: The value of `indent-tabs-mode' will determine whether a real 306 Note: The value of `indent-tabs-mode' will determine whether a real
268 tab character will be inserted, or the equivalent number of space. 307 tab character will be inserted, or the equivalent number of space.
269 When inserting a tab, actually the function stored in the variable 308 When inserting a tab, actually the function stored in the variable
270 `c-insert-tab-function' is called. 309 `c-insert-tab-function' is called.
292 "*Specifies how comment-only lines should be indented. 331 "*Specifies how comment-only lines should be indented.
293 When this variable is non-nil, comment-only lines are indented 332 When this variable is non-nil, comment-only lines are indented
294 according to syntactic analysis via `c-offsets-alist', even when 333 according to syntactic analysis via `c-offsets-alist', even when
295 \\[indent-for-comment] is used.") 334 \\[indent-for-comment] is used.")
296 335
336 (defvar c-block-comments-indent-p nil
337 "*Specifies how to re-indent C style block comments.
338
339 Examples of the supported styles of C block comment indentation are
340 shown below. When this variable is nil, block comments are indented
341 as shown in styles 1 through 4. If this variable is non-nil, block
342 comments are indented as shown in style 5.
343
344 Note that cc-mode does not automatically insert any stars or block
345 comment delimiters. You must type these in manually. This variable
346 only controls how the lines within the block comment are indented when
347 you hit ``\\[c-indent-command]''.
348
349 style 1: style 2 (GNU): style 3: style 4: style 5:
350 /* /* Blah /* /* /*
351 blah blah. */ * blah ** blah blah
352 blah * blah ** blah blah
353 */ */ */ */")
354
297 (defvar c-cleanup-list '(scope-operator) 355 (defvar c-cleanup-list '(scope-operator)
298 "*List of various C/C++/ObjC constructs to \"clean up\". 356 "*List of various C/C++/ObjC constructs to \"clean up\".
299 These clean ups only take place when the auto-newline feature is 357 These clean ups only take place when the auto-newline feature is turned
300 turned on, as evidenced by the `/a' or `/ah' appearing next to the 358 on, as evidenced by the `/a' or `/ah' appearing next to the mode name.
301 mode name. Valid symbols are: 359 Valid symbols are:
302 360
303 brace-else-brace -- cleans up `} else {' constructs by placing entire 361 brace-else-brace -- cleans up `} else {' constructs by placing entire
304 construct on a single line. This clean up 362 construct on a single line. This clean up only
305 only takes place when there is nothing but 363 takes place when there is nothing but white
306 white space between the braces and the `else'. 364 space between the braces and the `else'. Clean
307 Clean up occurs when the open-brace after the 365 up occurs when the open-brace after the `else'
308 `else' is typed. 366 is typed.
309 brace-elseif-brace -- similar to brace-else-brace, but cleans up
310 `} else if {' constructs.
311 empty-defun-braces -- cleans up empty defun braces by placing the 367 empty-defun-braces -- cleans up empty defun braces by placing the
312 braces on the same line. Clean up occurs when 368 braces on the same line. Clean up occurs when
313 the defun closing brace is typed. 369 the defun closing brace is typed.
314 defun-close-semi -- cleans up the terminating semi-colon on defuns 370 defun-close-semi -- cleans up the terminating semi-colon on defuns
315 by placing the semi-colon on the same line as 371 by placing the semi-colon on the same line as
382 438
383 If every function in the list is called with no determination made, 439 If every function in the list is called with no determination made,
384 then no newline is inserted.") 440 then no newline is inserted.")
385 441
386 (defvar c-hanging-comment-ender-p t 442 (defvar c-hanging-comment-ender-p t
387 "*Controls what \\[fill-paragraph] does to C block comment enders. 443 "*If nil, `c-fill-paragraph' leaves C block comment enders on their own line.
388 When set to nil, C block comment enders are left on their own line. 444 Default value is t, which inhibits leaving block comment ending string
389 When set to t, block comment enders will be placed at the end of the 445 `*/' on a line by itself. This is BOCM's sole behavior.")
390 previous line (i.e. they `hang' on that line).")
391
392 (defvar c-hanging-comment-starter-p t
393 "*Controls what \\[fill-paragraph] does to C block comment starters.
394 When set to nil, C block comment starters are left on their own line.
395 When set to t, text that follows a block comment starter will be
396 placed on the same line as the block comment starter (i.e. the text
397 `hangs' on that line).")
398 446
399 (defvar c-backslash-column 48 447 (defvar c-backslash-column 48
400 "*Column to insert backslashes when macroizing a region.") 448 "*Column to insert backslashes when macroizing a region.")
401 (defvar c-special-indent-hook nil 449 (defvar c-special-indent-hook nil
402 "*Hook for user defined special indentation adjustments. 450 "*Hook for user defined special indentation adjustments.
404 (defvar c-delete-function 'backward-delete-char-untabify 452 (defvar c-delete-function 'backward-delete-char-untabify
405 "*Function called by `c-electric-delete' when deleting characters.") 453 "*Function called by `c-electric-delete' when deleting characters.")
406 (defvar c-electric-pound-behavior nil 454 (defvar c-electric-pound-behavior nil
407 "*List of behaviors for electric pound insertion. 455 "*List of behaviors for electric pound insertion.
408 Only currently supported behavior is `alignleft'.") 456 Only currently supported behavior is `alignleft'.")
409
410 (defvar c-label-minimum-indentation 1 457 (defvar c-label-minimum-indentation 1
411 "*Minimum indentation for lines inside of top-level constructs. 458 "*Minimum indentation for labels and case tags in `gnu' style.")
412 This variable typically only affects code using the `gnu' style, which
413 mandates a minimum of one space in front of every line inside
414 top-level constructs. Specifically, the function
415 `c-gnu-impose-minimum' on your `c-special-indent-hook' is what
416 enforces this.")
417 459
418 (defvar c-progress-interval 5 460 (defvar c-progress-interval 5
419 "*Interval used to update progress status during long re-indentation. 461 "*Interval used to update progress status during long re-indentation.
420 If a number, percentage complete gets updated after each interval of 462 If a number, percentage complete gets updated after each interval of
421 that many seconds. Set to nil to inhibit updating. This is only 463 that many seconds. Set to nil to inhibit updating. This is only
422 useful for Emacs 19.") 464 useful for Emacs 19.")
423 465
424 (defconst c-style-alist 466 (defconst c-style-alist
425 '(("gnu" 467 '(("gnu"
426 (c-basic-offset . 2) 468 (c-basic-offset . 2)
480 (c-basic-offset . 3) 522 (c-basic-offset . 3)
481 (c-comment-only-line-offset . 0) 523 (c-comment-only-line-offset . 0)
482 (c-hanging-braces-alist . ((substatement-open before after))) 524 (c-hanging-braces-alist . ((substatement-open before after)))
483 (c-offsets-alist . ((topmost-intro . 0) 525 (c-offsets-alist . ((topmost-intro . 0)
484 (topmost-intro-cont . 0) 526 (topmost-intro-cont . 0)
485 (substatement . +) 527 (substatement . 3)
486 (substatement-open . 0) 528 (substatement-open . 0)
529 (statement-case-intro . 0)
487 (case-label . +) 530 (case-label . +)
488 (access-label . -) 531 (access-label . -3)
489 (inclass . ++) 532 (inclass . 6)
490 (inline-open . 0) 533 (inline-open . 0)
491 )) 534 ))
492 ) 535 )
493 ("linux" 536 ("linux"
494 (c-basic-offset . 8) 537 (c-basic-offset . 8)
502 (substatement-open . 0) 545 (substatement-open . 0)
503 (label . 0) 546 (label . 0)
504 (statement-cont . +) 547 (statement-cont . +)
505 )) 548 ))
506 ) 549 )
507 ("python"
508 (indent-tabs-mode . t)
509 (c-basic-offset . 8)
510 (c-offsets-alist . ((substatement-open . 0)
511 ))
512 (c-hanging-braces-alist . ((brace-list-open)
513 (brace-list-intro)
514 (brace-list-close)
515 (substatement-open after)
516 (block-close . c-snug-do-while)
517 ))
518 )
519 ("java" 550 ("java"
520 (c-basic-offset . 2) 551 (c-basic-offset . 2)
521 (c-comment-only-line-offset . (0 . 0)) 552 (c-comment-only-line-offset . (0 . 0))
522 (c-offsets-alist . ((statement-block-intro . +) 553 (c-offsets-alist . ((statement-block-intro . +)
523 (knr-argdecl-intro . 5) 554 (knr-argdecl-intro . 5)
526 (statement-case-open . +) 557 (statement-case-open . +)
527 (statement-cont . +) 558 (statement-cont . +)
528 (arglist-intro . c-lineup-arglist-intro-after-paren) 559 (arglist-intro . c-lineup-arglist-intro-after-paren)
529 (arglist-close . c-lineup-arglist) 560 (arglist-close . c-lineup-arglist)
530 (access-label . 0) 561 (access-label . 0)
531 (inher-cont . c-lineup-java-inher)
532 )) 562 ))
533 563
534 ) 564 )
535 ) 565 )
536 "Styles of Indentation. 566 "Styles of Indentation.
537 Elements of this alist are of the form: 567 Elements of this alist are of the form:
538 568
539 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...]) 569 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
540 570
541 where STYLE-STRING is a short descriptive string used to select a 571 where STYLE-STRING is a short descriptive string used to select a
542 style, VARIABLE is any CC Mode variable, and VALUE is the intended 572 style, VARIABLE is any cc-mode variable, and VALUE is the intended
543 value for that variable when using the selected style. 573 value for that variable when using the selected style.
544 574
545 There is one special case when VARIABLE is `c-offsets-alist'. In this 575 There is one special case when VARIABLE is `c-offsets-alist'. In this
546 case, the VALUE is a list containing elements of the form: 576 case, the VALUE is a list containing elements of the form:
547 577
555 computed at the time the mode is loaded.") 585 computed at the time the mode is loaded.")
556 586
557 (defvar c-file-style nil 587 (defvar c-file-style nil
558 "*Variable interface for setting style via File Local Variables. 588 "*Variable interface for setting style via File Local Variables.
559 In a file's Local Variable section, you can set this variable to a 589 In a file's Local Variable section, you can set this variable to a
560 string suitable for `c-set-style'. When the file is visited, CC Mode 590 string suitable for `c-set-style'. When the file is visited, cc-mode
561 will set the style of the file to this value automatically. 591 will set the style of the file to this value automatically.
562 592
563 Note that file style settings are applied before file offset settings 593 Note that file style settings are applied before file offset settings
564 as designated in the variable `c-file-offsets'.") 594 as designated in the variable `c-file-offsets'.")
565 595
566 (defvar c-file-offsets nil 596 (defvar c-file-offsets nil
567 "*Variable interface for setting offsets via File Local Variables. 597 "*Variable interface for setting offsets via File Local Variables.
568 In a file's Local Variable section, you can set this variable to an 598 In a file's Local Variable section, you can set this variable to an
569 association list similar to the values allowed in `c-offsets-alist'. 599 association list similar to the values allowed in `c-offsets-alist'.
570 When the file is visited, CC Mode will institute these offset settings 600 When the file is visited, cc-mode will institute these offset settings
571 automatically. 601 automatically.
572 602
573 Note that file offset settings are applied after file style settings 603 Note that file offset settings are applied after file style settings
574 as designated in the variable `c-file-style'.") 604 as designated in the variable `c-file-style'.")
575 605
576 (defvar c-site-default-style "gnu" 606 (defvar c-site-default-style "gnu"
577 "Default style for your site. 607 "Default style for your site.
578 To change the default style at your site, you can set this variable to 608 To change the default style at your site, you can set this variable to
579 any style defined in `c-style-alist'. However, if CC Mode is usually 609 any style defined in `c-style-alist'. However, if cc-mode is usually
580 loaded into your Emacs at compile time, you will need to set this 610 loaded into your Emacs at compile time, you will need to set this
581 variable in the `site-init.el' file before CC Mode is loaded, then 611 variable in the `site-init.el' file before cc-mode is loaded, then
582 re-dump Emacs.") 612 re-dump Emacs.")
583 613
584 (defvar c-style-variables-are-local-p t
585 "*Whether style variables should be buffer local by default.
586 If non-nil, then all indentation style related variables will be made
587 buffer local by default. If nil, they will remain global. Variables
588 are made buffer local when this file is loaded, and once buffer
589 localized, they cannot be made global again.
590
591 The list of variables to buffer localize are:
592 c-offsets-alist
593 c-basic-offset
594 c-file-style
595 c-file-offsets
596 c-comment-only-line-offset
597 c-cleanup-list
598 c-hanging-braces-alist
599 c-hanging-colons-alist
600 c-hanging-comment-starter-p
601 c-hanging-comment-ender-p
602 c-backslash-column
603 c-label-minimum-indentation
604 c-special-indent-hook
605 c-indentation-style")
606
607
608 (defvar c-mode-hook nil 614 (defvar c-mode-hook nil
609 "*Hook called by `c-mode'.") 615 "*Hook called by `c-mode'.")
610 (defvar c++-mode-hook nil 616 (defvar c++-mode-hook nil
611 "*Hook called by `c++-mode'.") 617 "*Hook called by `c++-mode'.")
612 (defvar objc-mode-hook nil 618 (defvar objc-mode-hook nil
613 "*Hook called by `objc-mode'.") 619 "*Hook called by `objc-mode'.")
614 (defvar java-mode-hook nil 620 (defvar java-mode-hook nil
615 "*Hook called by `java-mode'.") 621 "*Hook called by `java-mode'.")
616 622
617 (defvar c-mode-common-hook nil 623 (defvar c-mode-common-hook nil
618 "*Hook called by all CC Mode modes for common initializations.") 624 "*Hook called by all cc-mode modes for common initializations.")
619 625
620 (defvar c-mode-menu 626 (defvar c-mode-menu
621 '(["Comment Out Region" comment-region (mark)] 627 '(["Comment Out Region" comment-region (mark)]
622 ["Macro Expand Region" c-macro-expand (mark)] 628 ["Macro Expand Region" c-macro-expand (mark)]
623 ["Backslashify" c-backslash-region (mark)] 629 ["Backslashify" c-backslash-region (mark)]
629 ["Backward Conditional" c-backward-conditional t] 635 ["Backward Conditional" c-backward-conditional t]
630 ["Forward Conditional" c-forward-conditional t] 636 ["Forward Conditional" c-forward-conditional t]
631 ["Backward Statement" c-beginning-of-statement t] 637 ["Backward Statement" c-beginning-of-statement t]
632 ["Forward Statement" c-end-of-statement t] 638 ["Forward Statement" c-end-of-statement t]
633 ) 639 )
634 "Basic XEmacs 19 menu for C/C++/ObjC/Java modes.") 640 "XEmacs 19 menu for C/C++/ObjC/Java modes.")
635 641
636 642 ;; Sadly we need this for a macro in Emacs 19.
637 ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 643 (eval-when-compile
638 ;; NO USER DEFINABLE VARIABLES BEYOND THIS POINT 644 ;; Imenu isn't used in XEmacs, so just ignore load errors.
639 645 (condition-case ()
640 ;; imenu integration 646 (require 'imenu)
647 (error nil)))
648
641 (defvar cc-imenu-c++-generic-expression 649 (defvar cc-imenu-c++-generic-expression
642 (` 650 (`
643 ((nil 651 ((nil
644 (, 652 (,
645 (concat 653 (concat
646 "^" ; beginning of line is required 654 "^" ; beginning of line is required
647 "\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a "template <...>" 655 "\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a "template <...>"
648 "\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; type specs; there can be no 656 "\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; type specs; there can be no
649 "\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; more than 3 tokens, right? 657 "\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; more than 3 tokens, right?
650 658
651 "\\(" ; last type spec including */& 659 "\\(" ; last type spec including */&
652 "[a-zA-Z0-9_:]+" 660 "[a-zA-Z0-9_:]+"
653 "\\([ \t]*[*&]+[ \t]*\\|[ \t]+\\)" ; either ptr/ref sign or ws 661 "\\([ \t]*[*&]+[ \t]*\\|[ \t]+\\)" ; either pointer/ref sign or whitespace
654 "\\)?" ; if there is a last type spec 662 "\\)?" ; if there is a last type spec
655 "\\(" ; name, take into the imenu entry 663 "\\(" ; name; take that into the imenu entry
656 "[a-zA-Z0-9_:~]+" ; member func, ctor or dtor... 664 "[a-zA-Z0-9_:~]+" ; member function, ctor or dtor...
657 ; (may not contain * because then 665 ; (may not contain * because then
658 ; "a::operator char*" would 666 ; "a::operator char*" would become "char*"!)
659 ; become "char*"!)
660 "\\|" 667 "\\|"
661 "\\([a-zA-Z0-9_:~]*::\\)?operator" 668 "\\([a-zA-Z0-9_:~]*::\\)?operator"
662 "[^a-zA-Z1-9_][^(]*" ; ...or operator 669 "[^a-zA-Z1-9_][^(]*" ; ...or operator
663 " \\)" 670 " \\)"
664 "[ \t]*([^)]*)[ \t\n]*[^ ;]" ; require something other than 671 "[ \t]*([^)]*)[ \t\n]*[^ ;]" ; require something other than a ; after
665 ; a `;' after the (...) to 672 ; the (...) to avoid prototypes. Can't
666 ; avoid prototypes. Can't 673 ; catch cases with () inside the parentheses
667 ; catch cases with () inside 674 ; surrounding the parameters
668 ; the parentheses surrounding 675 ; (like "int foo(int a=bar()) {...}"
669 ; the parameters. e.g.:
670 ; "int foo(int a=bar()) {...}"
671 676
672 )) 6) 677 )) 6)
673 ("Class" 678 ("Class"
674 (, (concat 679 (, (concat
675 "^" ; beginning of line is required 680 "^" ; beginning of line is required
676 "\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a "template <...>" 681 "\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a "template <...>"
677 "class[ \t]+" 682 "class[ \t]+"
678 "\\([a-zA-Z0-9_]+\\)" ; the string we want to get 683 "\\([a-zA-Z0-9_]+\\)" ; this is the string we want to get
679 "[ \t]*[:{]" 684 "[ \t]*[:{]"
680 )) 2))) 685 )) 2)))
681 "Imenu generic expression for C++ mode. See `imenu-generic-expression'.") 686 "Imenu generic expression for C++ mode. See `imenu-generic-expression'.")
682 687
683 (defvar cc-imenu-c-generic-expression 688 (defvar cc-imenu-c-generic-expression
684 cc-imenu-c++-generic-expression 689 cc-imenu-c++-generic-expression
685 "Imenu generic expression for C mode. See `imenu-generic-expression'.") 690 "Imenu generic expression for C mode. See `imenu-generic-expression'.")
686 691
687 ;(defvar cc-imenu-objc-generic-expression
688 ; ())
689 ; Please contribute one!
690
691 (defvar cc-imenu-java-generic-expression
692 (`
693 ((nil
694 (,
695 (concat
696 "^\\([ \t]\\)*"
697 "\\([A-Za-z0-9_-]+[ \t]+\\)?" ; type specs; there can be
698 "\\([A-Za-z0-9_-]+[ \t]+\\)?" ; more than 3 tokens, right?
699 "\\([A-Za-z0-9_-]+[ \t]*[[]?[]]?\\)"
700 "\\([ \t]\\)"
701 "\\([A-Za-z0-9_-]+\\)" ; the string we want to get
702 "\\([ \t]*\\)+("
703 "\\([a-zA-Z,_1-9\n \t]*[[]?[]]?\\)*" ; arguments
704 ")[ \t]*"
705 "[^;(]"
706 "[,a-zA-Z_1-9\n \t]*{"
707 )) 6)))
708 "Imenu generic expression for Java mode. See `imenu-generic-expression'.")
709
710
711 692
693 ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
694 ;; NO USER DEFINABLE VARIABLES BEYOND THIS POINT
695
712 ;; Shut the byte-compiler up. Requires Emacs 19 or JWZ's improved 696 ;; Shut the byte-compiler up. Requires Emacs 19 or JWZ's improved
713 ;; byte-compiler. Otherwise, comment this line out and ignore 697 ;; byte-compiler. Otherwise, comment this line out and ignore
714 ;; any warnings. 698 ;; any warnings.
715 ;;(byte-compiler-options (warnings nil)) 699 ;;(byte-compiler-options (warnings nil))
716 700
719 (let ((major (and (boundp 'emacs-major-version) 703 (let ((major (and (boundp 'emacs-major-version)
720 emacs-major-version)) 704 emacs-major-version))
721 (minor (and (boundp 'emacs-minor-version) 705 (minor (and (boundp 'emacs-minor-version)
722 emacs-minor-version)) 706 emacs-minor-version))
723 (re-suite 'old-re) 707 (re-suite 'old-re)
724 flavor comments infodock-p) 708 flavor comments)
725 ;; figure out version numbers if not already discovered 709 ;; figure out version numbers if not already discovered
726 (and (or (not major) (not minor)) 710 (and (or (not major) (not minor))
727 (string-match "\\([0-9]+\\).\\([0-9]+\\)" emacs-version) 711 (string-match "\\([0-9]+\\).\\([0-9]+\\)" emacs-version)
728 (setq major (string-to-int (substring emacs-version 712 (setq major (string-to-int (substring emacs-version
729 (match-beginning 1) 713 (match-beginning 1)
738 ((= major 18) (setq major 'v18)) ;Emacs 18 722 ((= major 18) (setq major 'v18)) ;Emacs 18
739 ((= major 4) (setq major 'v18)) ;Epoch 4 723 ((= major 4) (setq major 'v18)) ;Epoch 4
740 ((= major 19) (setq major 'v19 ;Emacs 19 724 ((= major 19) (setq major 'v19 ;Emacs 19
741 flavor (if (or (string-match "Lucid" emacs-version) 725 flavor (if (or (string-match "Lucid" emacs-version)
742 (string-match "XEmacs" emacs-version)) 726 (string-match "XEmacs" emacs-version))
743 'XEmacs 'FSF) 727 'XEmacs 'FSF)))
744 infodock-p (boundp 'infodock-version)))
745 ((= major 20) (setq major 'v20 ;XEmacs 20 728 ((= major 20) (setq major 'v20 ;XEmacs 20
746 flavor 'XEmacs)) 729 flavor 'XEmacs))
747 ;; I don't know 730 ;; I don't know
748 (t (error "Cannot recognize major version number: %s" major))) 731 (t (error "Cannot recognize major version number: %s" major)))
749 ;; Regular expression suites... 732 ;; Regular expression suites...
783 (not c-inhibit-startup-warnings-p)) 766 (not c-inhibit-startup-warnings-p))
784 (with-output-to-temp-buffer "*cc-mode warnings*" 767 (with-output-to-temp-buffer "*cc-mode warnings*"
785 (print (format 768 (print (format
786 "The version of Emacs that you are running, %s, 769 "The version of Emacs that you are running, %s,
787 has known bugs in its syntax.c parsing routines which will affect the 770 has known bugs in its syntax.c parsing routines which will affect the
788 performance of CC Mode. You should strongly consider upgrading to the 771 performance of cc-mode. You should strongly consider upgrading to the
789 latest available version. CC Mode may continue to work, after a 772 latest available version. cc-mode may continue to work, after a
790 fashion, but strange indentation errors could be encountered." 773 fashion, but strange indentation errors could be encountered."
791 emacs-version)))) 774 emacs-version))))
792 ;; Emacs 18, with no patch is not too good 775 ;; Emacs 18, with no patch is not too good
793 (if (and (eq major 'v18) (eq comments 'no-dual-comments) 776 (if (and (eq major 'v18) (eq comments 'no-dual-comments)
794 (not c-inhibit-startup-warnings-p)) 777 (not c-inhibit-startup-warnings-p))
801 if you are doing much C++ editing, you should strongly consider 784 if you are doing much C++ editing, you should strongly consider
802 upgrading to one of the latest Emacs 19's. In Emacs 18, you may also 785 upgrading to one of the latest Emacs 19's. In Emacs 18, you may also
803 experience performance degradations. Emacs 19 has some new built-in 786 experience performance degradations. Emacs 19 has some new built-in
804 routines which will speed things up for you. 787 routines which will speed things up for you.
805 788
806 Because of these inherent problems, CC Mode is no longer being 789 Because of these inherent problems, cc-mode is no longer being
807 actively maintained for Emacs 18, however, until you can upgrade to 790 actively maintained for Emacs 18, however, until you can upgrade to
808 Emacs 19, you may want to look at cc-mode-18.el in the CC Mode 791 Emacs 19, you may want to look at cc-mode-18.el in the cc-mode
809 distribution. THIS FILE IS COMPLETELY UNSUPPORTED! If you use it, 792 distribution. THIS FILE IS COMPLETELY UNSUPPORTED! If you use it,
810 you are on your own, although patch contributions will be folded into 793 you are on your own, although patch contributions will be folded into
811 the main release." 794 the main release."
812 emacs-version)))) 795 emacs-version))))
813 ;; Emacs 18 with the syntax patches are no longer supported 796 ;; Emacs 18 with the syntax patches are no longer supported
816 (with-output-to-temp-buffer "*cc-mode warnings*" 799 (with-output-to-temp-buffer "*cc-mode warnings*"
817 (print (format 800 (print (format
818 "You are running a syntax patched Emacs 18 variant. While this should 801 "You are running a syntax patched Emacs 18 variant. While this should
819 work for you, you may want to consider upgrading to Emacs 19. The 802 work for you, you may want to consider upgrading to Emacs 19. The
820 syntax patches are no longer supported either for syntax.c or 803 syntax patches are no longer supported either for syntax.c or
821 CC Mode.")))) 804 cc-mode."))))
822 (if infodock-p 805 (list major comments re-suite))
823 (list major comments re-suite 'infodock)
824 (list major comments re-suite)))
825 "A list of features extant in the Emacs you are using. 806 "A list of features extant in the Emacs you are using.
826 There are many flavors of Emacs out there, each with different 807 There are many flavors of Emacs out there, each with different
827 features supporting those needed by CC Mode. Here's the current 808 features supporting those needed by cc-mode. Here's the current
828 supported list, along with the values for this variable: 809 supported list, along with the values for this variable:
829 810
830 Emacs 18/Epoch 4: (v18 no-dual-comments RS) 811 Emacs 18/Epoch 4: (v18 no-dual-comments RS)
831 Emacs 18/Epoch 4 (patch2): (v18 8-bit RS) 812 Emacs 18/Epoch 4 (patch2): (v18 8-bit RS)
832 XEmacs 19: (v19 8-bit RS) 813 XEmacs 19: (v19 8-bit RS)
833 XEmacs 20: (v20 8-bit RS) 814 XEmacs 20: (v20 8-bit RS)
834 Emacs 19: (v19 1-bit RS) 815 Emacs 19: (v19 1-bit RS)
835 816
836 RS is the regular expression suite to use. XEmacs versions after 817 RS is the regular expression suite to use. XEmacs versions after
837 19.13, and Emacs versions after 19.29 use the `new-re' regex suite. 818 19.13, and Emacs versions after 19.29 use the `new-re' regex suite.
838 All other Emacsen use the `old-re' suite. 819 All other Emacsen use the `old-re' suite.")
839
840 Infodock (based on XEmacs) has an additional symbol on this list:
841 'infodock")
842 820
843 (defvar c++-mode-abbrev-table nil 821 (defvar c++-mode-abbrev-table nil
844 "Abbrev table in use in c++-mode buffers.") 822 "Abbrev table in use in c++-mode buffers.")
845 (define-abbrev-table 'c++-mode-abbrev-table ()) 823 (define-abbrev-table 'c++-mode-abbrev-table ())
846 824
855 (defvar java-mode-abbrev-table nil 833 (defvar java-mode-abbrev-table nil
856 "Abbrev table in use in java-mode buffers.") 834 "Abbrev table in use in java-mode buffers.")
857 (define-abbrev-table 'java-mode-abbrev-table ()) 835 (define-abbrev-table 'java-mode-abbrev-table ())
858 836
859 (defun c-mode-fsf-menu (name map) 837 (defun c-mode-fsf-menu (name map)
860 ;; Add menu to a keymap, but don't add them for XEmacs. This 838 ;; Add menu to a keymap. FSF menus suck. Don't add them for
861 ;; feature test will fail on other than Emacs 19. 839 ;; XEmacs. This feature test will fail on other than Emacs 19.
862 (condition-case nil 840 (condition-case nil
863 (progn 841 (progn
864 (define-key map [menu-bar] (make-sparse-keymap)) 842 (define-key map [menu-bar] (make-sparse-keymap))
865 (define-key map [menu-bar c] (cons name (make-sparse-keymap name))) 843 (define-key map [menu-bar c] (cons name (make-sparse-keymap name)))
866 844
874 '("Indent Expression" . c-indent-exp)) 852 '("Indent Expression" . c-indent-exp))
875 (define-key map [menu-bar c indent-line] 853 (define-key map [menu-bar c indent-line]
876 '("Indent Line" . c-indent-command)) 854 '("Indent Line" . c-indent-command))
877 (define-key map [menu-bar c fill] 855 (define-key map [menu-bar c fill]
878 '("Fill Comment Paragraph" . c-fill-paragraph)) 856 '("Fill Comment Paragraph" . c-fill-paragraph))
879 (define-key map [menu-bar c separator2]
880 '("----"))
881 (define-key map [menu-bar c up] 857 (define-key map [menu-bar c up]
882 '("Up Conditional" . c-up-conditional)) 858 '("Up Conditional" . c-up-conditional))
883 (define-key map [menu-bar c backward] 859 (define-key map [menu-bar c backward]
884 '("Backward Conditional" . c-backward-conditional)) 860 '("Backward Conditional" . c-backward-conditional))
885 (define-key map [menu-bar c forward] 861 (define-key map [menu-bar c forward]
919 (define-key c-mode-map "\C-c\C-m" 'c-mark-function) 895 (define-key c-mode-map "\C-c\C-m" 'c-mark-function)
920 (define-key c-mode-map "\e\C-q" 'c-indent-exp) 896 (define-key c-mode-map "\e\C-q" 'c-indent-exp)
921 (define-key c-mode-map "\ea" 'c-beginning-of-statement) 897 (define-key c-mode-map "\ea" 'c-beginning-of-statement)
922 (define-key c-mode-map "\ee" 'c-end-of-statement) 898 (define-key c-mode-map "\ee" 'c-end-of-statement)
923 ;; Emacs 19.30 introduces fill-paragraph-function, but it's not in 899 ;; Emacs 19.30 introduces fill-paragraph-function, but it's not in
924 ;; every version of Emacs CC Mode supports. 900 ;; every version of Emacs cc-mode supports.
925 (if (not (boundp 'fill-paragraph-function)) 901 (if (not (boundp 'fill-paragraph-function))
926 ;; I'd rather use an adaptive fill program instead of this. 902 ;; I'd rather use an adaptive fill program instead of this.
927 (define-key c-mode-map "\eq" 'c-fill-paragraph)) 903 (define-key c-mode-map "\eq" 'c-fill-paragraph))
928 (define-key c-mode-map "\C-c\C-n" 'c-forward-conditional) 904 (define-key c-mode-map "\C-c\C-n" 'c-forward-conditional)
929 (define-key c-mode-map "\C-c\C-p" 'c-backward-conditional) 905 (define-key c-mode-map "\C-c\C-p" 'c-backward-conditional)
942 (define-key c-mode-map "\C-c\C-d" 'c-toggle-hungry-state) 918 (define-key c-mode-map "\C-c\C-d" 'c-toggle-hungry-state)
943 (define-key c-mode-map "\C-c\C-e" 'c-macro-expand) 919 (define-key c-mode-map "\C-c\C-e" 'c-macro-expand)
944 (define-key c-mode-map "\C-c\C-o" 'c-set-offset) 920 (define-key c-mode-map "\C-c\C-o" 'c-set-offset)
945 (define-key c-mode-map "\C-c\C-s" 'c-show-syntactic-information) 921 (define-key c-mode-map "\C-c\C-s" 'c-show-syntactic-information)
946 (define-key c-mode-map "\C-c\C-t" 'c-toggle-auto-hungry-state) 922 (define-key c-mode-map "\C-c\C-t" 'c-toggle-auto-hungry-state)
947 (define-key c-mode-map "\C-c." 'c-set-style)
948 ;; conflicts with OOBR 923 ;; conflicts with OOBR
949 ;;(define-key c-mode-map "\C-c\C-v" 'c-version) 924 ;;(define-key c-mode-map "\C-c\C-v" 'c-version)
950 ;; 925 ;;
951 (if (and 926 ;; Emacs 19 defines menus in the mode map. This call will return
952 ;; Infodock has it's own menu 927 ;; t on Emacs 19, otherwise no-op and return nil.
953 (not (memq 'infodock c-emacs-features)) 928 (if (and (not (c-mode-fsf-menu "CC-Mode" c-mode-map))
954 ;; Emacs 19 defines menus in the mode map. This call will 929 ;; in XEmacs 19, we want the menu to popup when the 3rd
955 ;; return t on Emacs 19, otherwise no-op and return nil. 930 ;; button is hit. In Lucid Emacs 19.10 and beyond this is
956 (not (c-mode-fsf-menu "CC Mode" c-mode-map)) 931 ;; done automatically if we put the menu on mode-popup-menu
957 ;; In XEmacs 19, we want the menu to popup when the 3rd button 932 ;; variable, see c-common-init. Emacs 19 uses C-Mouse-3 for
958 ;; is hit. In Lucid Emacs 19.10 and beyond this is done 933 ;; this, and it works with no special effort.
959 ;; automatically if we put the menu on mode-popup-menu 934 (boundp 'current-menubar)
960 ;; variable, see c-common-init. Emacs 19 uses C-Mouse-3 for 935 (not (boundp 'mode-popup-menu)))
961 ;; this, and it works with no special effort.
962 (boundp 'current-menubar)
963 (not (boundp 'mode-popup-menu)))
964 (define-key c-mode-map 'button3 'c-popup-menu))) 936 (define-key c-mode-map 'button3 'c-popup-menu)))
965 937
966 (defvar c++-mode-map () 938 (defvar c++-mode-map ()
967 "Keymap used in c++-mode buffers.") 939 "Keymap used in c++-mode buffers.")
968 (if c++-mode-map 940 (if c++-mode-map
1164 "Regexp describing C++ base classes in a derived class definition.") 1136 "Regexp describing C++ base classes in a derived class definition.")
1165 1137
1166 ;; defconst'd instead of defvar'd to override any old pre-loaded versions 1138 ;; defconst'd instead of defvar'd to override any old pre-loaded versions
1167 (defconst c-recognize-knr-p t 1139 (defconst c-recognize-knr-p t
1168 "Non-nil means K&R style argument declarations are valid.") 1140 "Non-nil means K&R style argument declarations are valid.")
1169 (defvar c-indentation-style c-site-default-style 1141
1170 "Name of style installed in the current buffer.")
1171
1172 ;; these variables should always be buffer local. they do not affect
1173 ;; indentation styles.
1174 ;;
1175 ;; minor mode variables 1142 ;; minor mode variables
1176 (make-variable-buffer-local 'c-auto-newline) 1143 (make-variable-buffer-local 'c-auto-newline)
1177 (make-variable-buffer-local 'c-hungry-delete-key) 1144 (make-variable-buffer-local 'c-hungry-delete-key)
1178 (make-variable-buffer-local 'c-auto-hungry-string) 1145 (make-variable-buffer-local 'c-auto-hungry-string)
1179 ;; language differences 1146 ;; language differences
1188 ;; style variables are made buffer local at tail end of this file. 1155 ;; style variables are made buffer local at tail end of this file.
1189 1156
1190 ;; cmacexp is lame because it uses no preprocessor symbols. 1157 ;; cmacexp is lame because it uses no preprocessor symbols.
1191 ;; It isn't very extensible either -- hardcodes /lib/cpp. 1158 ;; It isn't very extensible either -- hardcodes /lib/cpp.
1192 ;; [I add it here only because c-mode has it -- BAW] 1159 ;; [I add it here only because c-mode has it -- BAW]
1193 (autoload 'c-macro-expand "cmacexp" 1160 ;(autoload 'c-macro-expand "cmacexp"
1194 "Display the result of expanding all C macros occurring in the region. 1161 ; "Display the result of expanding all C macros occurring in the region.
1195 The expansion is entirely correct because it uses the C preprocessor." 1162 ;The expansion is entirely correct because it uses the C preprocessor."
1196 t) 1163 ; t)
1197 1164
1198 1165
1199 ;; constant regular expressions for looking at various constructs 1166 ;; constant regular expressions for looking at various constructs
1200 (defconst c-C++-class-key "\\(class\\|struct\\|union\\)" 1167 (defconst c-C++-class-key "\\(class\\|struct\\|union\\)"
1201 "Regexp describing a C++ class declaration, including templates.") 1168 "Regexp describing a C++ class declaration, including templates.")
1202 (defconst c-C-class-key "\\(struct\\|union\\)" 1169 (defconst c-C-class-key "\\(struct\\|union\\)"
1203 "Regexp describing a C struct declaration.") 1170 "Regexp describing a C struct declaration.")
1204 (defconst c-inher-key 1171 (defconst c-inher-key
1205 (concat "\\(\\<static\\>\\s +\\)?" 1172 (concat "\\(\\<static\\>\\s +\\)?"
1206 c-C++-class-key "[ \t]+" c-symbol-key 1173 c-C++-class-key "[ \t]+" c-symbol-key
1207 "\\([ \t]*:[ \t]*\\)\\s *[^;]") 1174 "\\([ \t]*:[ \t]*\\)?\\s *[^;]")
1208 "Regexp describing a class inheritance declaration.") 1175 "Regexp describing a class inheritance declaration.")
1209 (defconst c-switch-label-key 1176 (defconst c-switch-label-key
1210 "\\(\\(case[( \t]+\\S .*\\)\\|default[ \t]*\\):" 1177 "\\(\\(case[( \t]+\\S .*\\)\\|default[ \t]*\\):"
1211 "Regexp describing a switch's case or default label") 1178 "Regexp describing a switch's case or default label")
1212 (defconst c-C++-access-key 1179 (defconst c-C++-access-key
1228 "\\)\\b[^_]") 1195 "\\)\\b[^_]")
1229 "Regexp describing a conditional control for C++.") 1196 "Regexp describing a conditional control for C++.")
1230 (defconst c-C++-friend-key 1197 (defconst c-C++-friend-key
1231 "friend[ \t]+\\|template[ \t]*<.+>[ \t]*friend[ \t]+" 1198 "friend[ \t]+\\|template[ \t]*<.+>[ \t]*friend[ \t]+"
1232 "Regexp describing friend declarations in C++ classes.") 1199 "Regexp describing friend declarations in C++ classes.")
1233 1200 (defconst c-C++-comment-start-regexp "//\\|/\\*"
1234 ;; comment starter definitions for various languages. the language 1201 "Dual comment value for `c-comment-start-regexp'.")
1235 ;; modes will set c-comment-start-regexp to this value. 1202 (defconst c-C-comment-start-regexp "/\\*"
1236 (defconst c-C++-comment-start-regexp "/[/*]") 1203 "Single comment style value for `c-comment-start-regexp'.")
1237 (defconst c-C-comment-start-regexp "/[*]")
1238 ;; We need to match all 3 Java style comments
1239 ;; 1) Traditional C block; 2) javadoc /** ...; 3) C++ style
1240 (defconst c-Java-comment-start-regexp "/\\(/\\|[*][*]?\\)")
1241 1204
1242 (defconst c-ObjC-method-key 1205 (defconst c-ObjC-method-key
1243 (concat 1206 (concat
1244 "^\\s *[+-]\\s *" 1207 "^\\s *[+-]\\s *"
1245 "\\(([^)]*)\\)?" ; return type 1208 "\\(([^)]*)\\)?" ; return type
1265 "\\(([^)]*)\\)?" ; return type 1228 "\\(([^)]*)\\)?" ; return type
1266 ;; \\s- in java syntax table does not include \n 1229 ;; \\s- in java syntax table does not include \n
1267 ;; since it is considered the end of //-comments. 1230 ;; since it is considered the end of //-comments.
1268 "[ \t\n]*" c-symbol-key) 1231 "[ \t\n]*" c-symbol-key)
1269 "Regexp describing a Java method intro.") 1232 "Regexp describing a Java method intro.")
1270 (defconst c-Java-access-key nil 1233 (defconst c-Java-access-key
1271 "Regexp describing access labels for Java.") 1234 (concat c-protection-key)
1235 "Regexp describing access specification keywords for Java.")
1272 (defconst c-Java-class-key 1236 (defconst c-Java-class-key
1273 (concat 1237 (concat
1274 "\\(" c-protection-key "\\s +\\)?"
1275 "\\(interface\\|class\\)\\s +" 1238 "\\(interface\\|class\\)\\s +"
1276 c-symbol-key ;name of the class 1239 c-symbol-key ;name of the class
1277 "\\(\\s *extends\\s *" c-symbol-key "\\)?" ;maybe followed by superclass 1240 "\\(\\s *extends\\s *" c-symbol-key "\\)?" ;maybe followed by superclass
1278 ;;"\\(\\s *implements *[^{]+{\\)?" ;and maybe the adopted protocols list 1241 ;;"\\(\\s *implements *[^{]+{\\)?" ;and maybe the adopted protocols list
1279 ) 1242 )
1280 "Regexp describing a class or protocol declaration for Java.") 1243 "Regexp describing a class or protocol declaration for Java.")
1281 (defconst c-Java-special-key "\\(implements\\|extends\\|throws\\)[^_]"
1282 "Regexp describing Java inheritance and throws clauses.")
1283 (defconst c-Java-conditional-key 1244 (defconst c-Java-conditional-key
1284 (concat "\\b\\(" 1245 (concat "\\b\\("
1285 (mapconcat 'identity 1246 (mapconcat 'identity
1286 (append '("try" "catch" "finally" "synchronized") 1247 (append '("try" "catch" "finally" "synchronized")
1287 c-C-conditionals) "\\|") 1248 c-C-conditionals) "\\|")
1288 "\\)\\b[^_]") 1249 "\\)\\b[^_]")
1289 "Regexp describing a conditional control for Java.") 1250 "Regexp describing a conditional control for Java.")
1290 (defconst c-Java-defun-prompt-regexp
1291 "^[ \t]*\\(\\(\\(public\\|protected\\|private\\|const\\|abstract\\|synchronized\\|final\\|static\\|threadsafe\\|transient\\|native\\|volatile\\)\\s-+\\)*\\(\\(\\([[a-zA-Z][][_$.a-zA-Z0-9]*[][_$.a-zA-Z0-9]+\\|[[a-zA-Z]\\)\\s-*\\)\\s-+\\)\\)?\\(\\([[a-zA-Z][][_$.a-zA-Z0-9]*\\s-+\\)\\s-*\\)?\\([_a-zA-Z][^][ \t:;.,{}()=]*\\|\\([_$a-zA-Z][_$.a-zA-Z0-9]*\\)\\)\\s-*\\(([^);{}]*)\\)?\\([] \t]*\\)\\(\\s-*\\<throws\\>\\s-*\\(\\([_$a-zA-Z][_$.a-zA-Z0-9]*\\)[, \t\n\r\f]*\\)+\\)?\\s-*"
1292 "Regexp describing the beginning of a Java top-level definition.")
1293 1251
1294 ;; KLUDGE ALERT. We default these variables to their `C' values so 1252 ;; KLUDGE ALERT. We default these variables to their `C' values so
1295 ;; that non-cc-mode-ized modes that depend on c-mode will still work 1253 ;; that non-cc-mode-ized modes that depend on c-mode will still work
1296 ;; out of the box. The most glaring example is awk-mode. There ought 1254 ;; out of the box. The most glaring example is awk-mode. There ought
1297 ;; to be a better way. 1255 ;; to be a better way.
1301 1259
1302 1260
1303 ;; main entry points for the modes 1261 ;; main entry points for the modes
1304 (defconst c-list-of-mode-names nil) 1262 (defconst c-list-of-mode-names nil)
1305 1263
1306 ;;;###autoload
1307 (defun c-mode () 1264 (defun c-mode ()
1308 "Major mode for editing K&R and ANSI C code. 1265 "Major mode for editing K&R and ANSI C code.
1309 To submit a problem report, enter `\\[c-submit-bug-report]' from a 1266 To submit a problem report, enter `\\[c-submit-bug-report]' from a
1310 c-mode buffer. This automatically sets up a mail buffer with version 1267 c-mode buffer. This automatically sets up a mail buffer with version
1311 information already added. You just need to add a description of the 1268 information already added. You just need to add a description of the
1312 problem, including a reproducible test case and send the message. 1269 problem, including a reproducible test case and send the message.
1313 1270
1314 To see what version of CC Mode you are running, enter `\\[c-version]'. 1271 To see what version of cc-mode you are running, enter `\\[c-version]'.
1315 1272
1316 The hook variable `c-mode-hook' is run with no args, if that value is 1273 The hook variable `c-mode-hook' is run with no args, if that value is
1317 bound and has a non-nil value. Also the hook `c-mode-common-hook' is 1274 bound and has a non-nil value. Also the hook `c-mode-common-hook' is
1318 run first. 1275 run first.
1319 1276
1337 imenu-generic-expression cc-imenu-c-generic-expression) 1294 imenu-generic-expression cc-imenu-c-generic-expression)
1338 (run-hooks 'c-mode-common-hook) 1295 (run-hooks 'c-mode-common-hook)
1339 (run-hooks 'c-mode-hook)) 1296 (run-hooks 'c-mode-hook))
1340 (setq c-list-of-mode-names (cons "C" c-list-of-mode-names)) 1297 (setq c-list-of-mode-names (cons "C" c-list-of-mode-names))
1341 1298
1342 ;;;###autoload
1343 (defun c++-mode () 1299 (defun c++-mode ()
1344 "Major mode for editing C++ code. 1300 "Major mode for editing C++ code.
1345 To submit a problem report, enter `\\[c-submit-bug-report]' from a 1301 To submit a problem report, enter `\\[c-submit-bug-report]' from a
1346 c++-mode buffer. This automatically sets up a mail buffer with 1302 c++-mode buffer. This automatically sets up a mail buffer with
1347 version information already added. You just need to add a description 1303 version information already added. You just need to add a description
1348 of the problem, including a reproducible test case, and send the 1304 of the problem, including a reproducible test case, and send the
1349 message. 1305 message.
1350 1306
1351 To see what version of CC Mode you are running, enter `\\[c-version]'. 1307 To see what version of cc-mode you are running, enter `\\[c-version]'.
1352 1308
1353 The hook variable `c++-mode-hook' is run with no args, if that 1309 The hook variable `c++-mode-hook' is run with no args, if that
1354 variable is bound and has a non-nil value. Also the hook 1310 variable is bound and has a non-nil value. Also the hook
1355 `c-mode-common-hook' is run first. 1311 `c-mode-common-hook' is run first.
1356 1312
1376 imenu-generic-expression cc-imenu-c++-generic-expression) 1332 imenu-generic-expression cc-imenu-c++-generic-expression)
1377 (run-hooks 'c-mode-common-hook) 1333 (run-hooks 'c-mode-common-hook)
1378 (run-hooks 'c++-mode-hook)) 1334 (run-hooks 'c++-mode-hook))
1379 (setq c-list-of-mode-names (cons "C++" c-list-of-mode-names)) 1335 (setq c-list-of-mode-names (cons "C++" c-list-of-mode-names))
1380 1336
1381 ;;;###autoload
1382 (defun objc-mode () 1337 (defun objc-mode ()
1383 "Major mode for editing Objective C code. 1338 "Major mode for editing Objective C code.
1384 To submit a problem report, enter `\\[c-submit-bug-report]' from an 1339 To submit a problem report, enter `\\[c-submit-bug-report]' from an
1385 objc-mode buffer. This automatically sets up a mail buffer with 1340 objc-mode buffer. This automatically sets up a mail buffer with
1386 version information already added. You just need to add a description 1341 version information already added. You just need to add a description
1387 of the problem, including a reproducible test case, and send the 1342 of the problem, including a reproducible test case, and send the
1388 message. 1343 message.
1389 1344
1390 To see what version of CC Mode you are running, enter `\\[c-version]'. 1345 To see what version of cc-mode you are running, enter `\\[c-version]'.
1391 1346
1392 The hook variable `objc-mode-hook' is run with no args, if that value 1347 The hook variable `objc-mode-hook' is run with no args, if that value
1393 is bound and has a non-nil value. Also the hook `c-mode-common-hook' 1348 is bound and has a non-nil value. Also the hook `c-mode-common-hook'
1394 is run first. 1349 is run first.
1395 1350
1415 c-method-key c-ObjC-method-key) 1370 c-method-key c-ObjC-method-key)
1416 (run-hooks 'c-mode-common-hook) 1371 (run-hooks 'c-mode-common-hook)
1417 (run-hooks 'objc-mode-hook)) 1372 (run-hooks 'objc-mode-hook))
1418 (setq c-list-of-mode-names (cons "ObjC" c-list-of-mode-names)) 1373 (setq c-list-of-mode-names (cons "ObjC" c-list-of-mode-names))
1419 1374
1420 ;;;###autoload
1421 (defun java-mode () 1375 (defun java-mode ()
1422 "Major mode for editing Java code. 1376 "Major mode for editing Java code.
1423 To submit a problem report, enter `\\[c-submit-bug-report]' from an 1377 To submit a problem report, enter `\\[c-submit-bug-report]' from an
1424 java-mode buffer. This automatically sets up a mail buffer with 1378 java-mode buffer. This automatically sets up a mail buffer with
1425 version information already added. You just need to add a description 1379 version information already added. You just need to add a description
1426 of the problem, including a reproducible test case and send the 1380 of the problem, including a reproducible test case and send the
1427 message. 1381 message.
1428 1382
1429 To see what version of CC Mode you are running, enter `\\[c-version]'. 1383 To see what version of cc-mode you are running, enter `\\[c-version]'.
1430 1384
1431 The hook variable `java-mode-hook' is run with no args, if that value 1385 The hook variable `java-mode-hook' is run with no args, if that value
1432 is bound and has a non-nil value. Also the common hook 1386 is bound and has a non-nil value. Also the common hook
1433 `c-mode-common-hook' is run first. Note that this mode automatically 1387 `c-mode-common-hook' is run first. Note that this mode automatically
1434 sets the \"java\" style before calling any hooks so be careful if you 1388 sets the \"java\" style before calling any hooks so be careful if you
1446 (c-common-init) 1400 (c-common-init)
1447 (setq comment-start "// " 1401 (setq comment-start "// "
1448 comment-end "" 1402 comment-end ""
1449 comment-multi-line nil 1403 comment-multi-line nil
1450 c-conditional-key c-Java-conditional-key 1404 c-conditional-key c-Java-conditional-key
1451 c-comment-start-regexp c-Java-comment-start-regexp 1405 c-comment-start-regexp c-C++-comment-start-regexp
1452 c-class-key c-Java-class-key 1406 c-class-key c-Java-class-key
1453 c-method-key c-Java-method-key 1407 c-method-key c-Java-method-key
1454 c-double-slash-is-comments-p t 1408 c-double-slash-is-comments-p t
1455 c-baseclass-key nil 1409 c-baseclass-key nil
1456 c-recognize-knr-p nil 1410 c-recognize-knr-p nil
1457 c-access-key c-Java-access-key 1411 c-access-key c-Java-access-key)
1458 ;defun-prompt-regexp c-Java-defun-prompt-regexp
1459 imenu-generic-expression cc-imenu-java-generic-expression
1460 )
1461 (c-set-style "java") 1412 (c-set-style "java")
1462 (run-hooks 'c-mode-common-hook) 1413 (run-hooks 'c-mode-common-hook)
1463 (run-hooks 'java-mode-hook)) 1414 (run-hooks 'java-mode-hook))
1464 (setq c-list-of-mode-names (cons "Java" c-list-of-mode-names)) 1415 (setq c-list-of-mode-names (cons "Java" c-list-of-mode-names))
1465 1416
1468 For use with the variable `java-mode-hook'." 1419 For use with the variable `java-mode-hook'."
1469 (c-set-style "java")) 1420 (c-set-style "java"))
1470 1421
1471 (defun c-common-init () 1422 (defun c-common-init ()
1472 ;; Common initializations for c++-mode and c-mode. 1423 ;; Common initializations for c++-mode and c-mode.
1473 ;; 1424 ;; make local variables
1474 ;; these variables should always be buffer local; they do not affect
1475 ;; indentation style.
1476 (make-local-variable 'paragraph-start) 1425 (make-local-variable 'paragraph-start)
1477 (make-local-variable 'paragraph-separate) 1426 (make-local-variable 'paragraph-separate)
1478 (make-local-variable 'paragraph-ignore-fill-prefix) 1427 (make-local-variable 'paragraph-ignore-fill-prefix)
1479 (make-local-variable 'require-final-newline) 1428 (make-local-variable 'require-final-newline)
1480 (make-local-variable 'parse-sexp-ignore-comments) 1429 (make-local-variable 'parse-sexp-ignore-comments)
1506 indent-region-function 'c-indent-region 1455 indent-region-function 'c-indent-region
1507 outline-regexp "[^#\n\^M]" 1456 outline-regexp "[^#\n\^M]"
1508 outline-level 'c-outline-level 1457 outline-level 'c-outline-level
1509 comment-column 32 1458 comment-column 32
1510 comment-start-skip "/\\*+ *\\|// *" 1459 comment-start-skip "/\\*+ *\\|// *"
1511 ;; For all but XEmacs 19.13, the default should be nil 1460 adaptive-fill-regexp nil)
1512 adaptive-fill-regexp (and (memq 'v19 c-emacs-features)
1513 (= emacs-minor-version 13)
1514 "[ \t]*\\([#;>*]+ +\\)?")
1515 )
1516 ;; we have to do something special for c-offsets-alist so that the 1461 ;; we have to do something special for c-offsets-alist so that the
1517 ;; buffer local value has its own alist structure. 1462 ;; buffer local value has its own alist structure.
1518 (setq c-offsets-alist (copy-alist c-offsets-alist)) 1463 (setq c-offsets-alist (copy-alist c-offsets-alist))
1519 ;; setup the comment indent variable in a Emacs version portable way 1464 ;; setup the comment indent variable in a Emacs version portable way
1520 ;; ignore any byte compiler warnings you might get here 1465 ;; ignore any byte compiler warnings you might get here
1523 (make-local-variable 'comment-indent-function) 1468 (make-local-variable 'comment-indent-function)
1524 (setq comment-indent-function 'c-comment-indent)) 1469 (setq comment-indent-function 'c-comment-indent))
1525 (make-local-variable 'comment-indent-hook) 1470 (make-local-variable 'comment-indent-hook)
1526 (setq comment-indent-hook 'c-comment-indent)) 1471 (setq comment-indent-hook 'c-comment-indent))
1527 ;; Put C menu into menubar and on popup menu for XEmacs 19. I think 1472 ;; Put C menu into menubar and on popup menu for XEmacs 19. I think
1528 ;; this happens automatically for Emacs 19. Skip it for Infodock. 1473 ;; this happens automatically for Emacs 19.
1529 (if (and (not (memq 'infodock c-emacs-features)) 1474 (if (and (boundp 'current-menubar)
1530 (boundp 'current-menubar)
1531 current-menubar 1475 current-menubar
1532 (not (assoc mode-name current-menubar))) 1476 (not (assoc mode-name current-menubar)))
1533 ;; its possible that this buffer has changed modes from one of 1477 ;; its possible that this buffer has changed modes from one of
1534 ;; the other CC Mode modes. In that case, only the menubar 1478 ;; the other cc-mode modes. In that case, only the menubar
1535 ;; title of the menu changes. 1479 ;; title of the menu changes.
1536 (let ((modes (copy-sequence c-list-of-mode-names)) 1480 (let ((modes (copy-sequence c-list-of-mode-names))
1537 changed-p) 1481 changed-p)
1538 (setq modes (delete major-mode modes)) 1482 (setq modes (delete major-mode modes))
1539 (while modes 1483 (while modes
1543 (setq modes nil 1487 (setq modes nil
1544 changed-p t))) 1488 changed-p t)))
1545 (if (not changed-p) 1489 (if (not changed-p)
1546 (progn 1490 (progn
1547 (set-buffer-menubar (copy-sequence current-menubar)) 1491 (set-buffer-menubar (copy-sequence current-menubar))
1548 (if (fboundp 'add-submenu) 1492 (add-menu nil mode-name c-mode-menu)))))
1549 (add-submenu nil (c-mode-menu))
1550 (add-menu nil mode-name c-mode-menu)
1551 )))))
1552 (if (boundp 'mode-popup-menu) 1493 (if (boundp 'mode-popup-menu)
1553 (setq mode-popup-menu (c-mode-menu))) 1494 (setq mode-popup-menu
1495 (cons (concat mode-name " Mode Commands") c-mode-menu)))
1554 ;; put auto-hungry designators onto minor-mode-alist, but only once 1496 ;; put auto-hungry designators onto minor-mode-alist, but only once
1555 (or (assq 'c-auto-hungry-string minor-mode-alist) 1497 (or (assq 'c-auto-hungry-string minor-mode-alist)
1556 (setq minor-mode-alist 1498 (setq minor-mode-alist
1557 (cons '(c-auto-hungry-string c-auto-hungry-string) 1499 (cons '(c-auto-hungry-string c-auto-hungry-string)
1558 minor-mode-alist)))) 1500 minor-mode-alist))))
1590 (c-setup-dual-comments c-mode-syntax-table) 1532 (c-setup-dual-comments c-mode-syntax-table)
1591 (setq-default c-C-comment-start-regexp c-C++-comment-start-regexp)) 1533 (setq-default c-C-comment-start-regexp c-C++-comment-start-regexp))
1592 1534
1593 1535
1594 ;; macros must be defined before first use 1536 ;; macros must be defined before first use
1595 (defmacro c-add-syntax (symbol &optional relpos)
1596 ;; a simple macro to append the syntax in symbol to the syntax list.
1597 ;; try to increase performance by using this macro
1598 (` (setq syntax (cons (cons (, symbol) (, relpos)) syntax))))
1599
1600 (defmacro c-point (position) 1537 (defmacro c-point (position)
1601 ;; Returns the value of point at certain commonly referenced POSITIONs. 1538 ;; Returns the value of point at certain commonly referenced POSITIONs.
1602 ;; POSITION can be one of the following symbols: 1539 ;; POSITION can be one of the following symbols:
1603 ;; 1540 ;;
1604 ;; bol -- beginning of line 1541 ;; bol -- beginning of line
1773 (if c-auto-newline 1710 (if c-auto-newline
1774 (if c-hungry-delete-key "/ah" "/a") 1711 (if c-hungry-delete-key "/ah" "/a")
1775 (if c-hungry-delete-key "/h" nil))) 1712 (if c-hungry-delete-key "/h" nil)))
1776 ;; updates the modeline for all Emacsen 1713 ;; updates the modeline for all Emacsen
1777 (if (or (memq 'v19 c-emacs-features) (memq 'v20 c-emacs-features)) 1714 (if (or (memq 'v19 c-emacs-features) (memq 'v20 c-emacs-features))
1778 (if (boundp 'redraw-modeline) 1715 (force-mode-line-update)
1779 (redraw-modeline)
1780 (force-mode-line-update))
1781 (set-buffer-modified-p (buffer-modified-p)))) 1716 (set-buffer-modified-p (buffer-modified-p))))
1782 1717
1783 (defun c-calculate-state (arg prevstate) 1718 (defun c-calculate-state (arg prevstate)
1784 ;; Calculate the new state of PREVSTATE, t or nil, based on arg. If 1719 ;; Calculate the new state of PREVSTATE, t or nil, based on arg. If
1785 ;; arg is nil or zero, toggle the state. If arg is negative, turn 1720 ;; arg is nil or zero, toggle the state. If arg is negative, turn
2025 (= mend here)) 1960 (= mend here))
2026 (not (c-in-literal))) 1961 (not (c-in-literal)))
2027 (progn 1962 (progn
2028 (delete-region mbeg mend) 1963 (delete-region mbeg mend)
2029 (insert "} else {"))) 1964 (insert "} else {")))
2030 ;; clean up brace-elseif-brace
2031 (if (and c-auto-newline
2032 (memq 'brace-elseif-brace c-cleanup-list)
2033 (= last-command-char ?\{)
2034 (re-search-backward "}[ \t\n]*else[ \t\n]+if[ \t\n]*" nil t)
2035 (save-excursion
2036 (goto-char (match-end 0))
2037 (c-safe (forward-sexp 1))
2038 (skip-chars-forward " \t\n")
2039 (setq mbeg (match-beginning 0)
2040 mend (match-end 0))
2041 (= here (1+ (point))))
2042 (not (c-in-literal)))
2043 (progn
2044 (delete-region mbeg mend)
2045 (insert "} else if ")))
2046 (goto-char (- (point-max) pos)) 1965 (goto-char (- (point-max) pos))
2047 ) 1966 )
2048 ;; does a newline go after the brace? 1967 ;; does a newline go after the brace?
2049 (if (memq 'after newlines) 1968 (if (memq 'after newlines)
2050 (progn 1969 (progn
2296 (put 'c-electric-delete 'delete-selection 'supersede) ; delsel 2215 (put 'c-electric-delete 'delete-selection 'supersede) ; delsel
2297 (put 'c-electric-delete 'pending-delete 'supersede) ; pending-del 2216 (put 'c-electric-delete 'pending-delete 'supersede) ; pending-del
2298 2217
2299 2218
2300 2219
2301 (defvar c-read-offset-history nil)
2302
2303 (defun c-read-offset (langelem) 2220 (defun c-read-offset (langelem)
2304 ;; read new offset value for LANGELEM from minibuffer. return a 2221 ;; read new offset value for LANGELEM from minibuffer. return a
2305 ;; legal value only 2222 ;; legal value only
2306 (let* ((oldoff (cdr-safe (assq langelem c-offsets-alist))) 2223 (let* ((oldoff (cdr-safe (assq langelem c-offsets-alist)))
2307 (defstr (format "(default %s): " oldoff)) 2224 (defstr (format "(default %s): " oldoff))
2309 "or in [+,-,++,--,*,/] " 2226 "or in [+,-,++,--,*,/] "
2310 defstr)) 2227 defstr))
2311 (prompt (concat "Offset " defstr)) 2228 (prompt (concat "Offset " defstr))
2312 offset input interned raw) 2229 offset input interned raw)
2313 (while (not offset) 2230 (while (not offset)
2314 (setq input (completing-read prompt obarray 'fboundp nil nil 2231 (setq input (read-string prompt)
2315 'c-read-offset-history)
2316 offset (cond ((string-equal "" input) oldoff) ; default 2232 offset (cond ((string-equal "" input) oldoff) ; default
2317 ((string-equal "+" input) '+) 2233 ((string-equal "+" input) '+)
2318 ((string-equal "-" input) '-) 2234 ((string-equal "-" input) '-)
2319 ((string-equal "++" input) '++) 2235 ((string-equal "++" input) '++)
2320 ((string-equal "--" input) '--) 2236 ((string-equal "--" input) '--)
2414 (add-hook 'c-special-indent-hook val))) 2330 (add-hook 'c-special-indent-hook val)))
2415 (t (set attr val))) 2331 (t (set attr val)))
2416 ))) 2332 )))
2417 stylevars)) 2333 stylevars))
2418 2334
2419 (defvar c-set-style-history nil)
2420
2421 ;;;###autoload
2422 (defun c-set-style (stylename) 2335 (defun c-set-style (stylename)
2423 "Set CC Mode variables to use one of several different indentation styles. 2336 "Set cc-mode variables to use one of several different indentation styles.
2424 STYLENAME is a string representing the desired style from the list of 2337 STYLENAME is a string representing the desired style from the list of
2425 styles described in the variable `c-style-alist'. See that variable 2338 styles described in the variable `c-style-alist'. See that variable
2426 for details of setting up styles. 2339 for details of setting up styles."
2427
2428 The variable `c-indentation-style' always contains the buffer's current
2429 style name."
2430 (interactive (list (let ((completion-ignore-case t) 2340 (interactive (list (let ((completion-ignore-case t)
2431 (prompt (format "Which %s indentation style? " 2341 (prompt (format "Which %s indentation style? "
2432 mode-name))) 2342 mode-name)))
2433 (completing-read prompt c-style-alist nil t 2343 (completing-read prompt c-style-alist nil t))))
2434 (cons c-indentation-style 0)
2435 'c-set-style-history))))
2436 (let ((vars (cdr (or (assoc (downcase stylename) c-style-alist) 2344 (let ((vars (cdr (or (assoc (downcase stylename) c-style-alist)
2437 (assoc (upcase stylename) c-style-alist) 2345 (assoc (upcase stylename) c-style-alist)
2438 (assoc stylename c-style-alist) 2346 (assoc stylename c-style-alist)
2439 ))) 2347 )))
2440 (default (cdr (assoc "cc-mode" c-style-alist)))) 2348 (default (cdr (assoc "cc-mode" c-style-alist))))
2441 (or vars (error "Invalid indentation style `%s'" stylename)) 2349 (or vars (error "Invalid indentation style `%s'" stylename))
2442 (or default (error "No `cc-mode' style found!")) 2350 (or default (error "No `cc-mode' style found!"))
2443 ;; first reset the style to `cc-mode' to give every style a common 2351 ;; first reset the style to `cc-mode' to give every style a common
2444 ;; base. Then institute the new style. 2352 ;; base. Then institute the new style.
2445 (c-set-style-1 default) 2353 (c-set-style-1 default)
2446 (setq c-indentation-style stylename)
2447 (if (not (string= stylename "cc-mode")) 2354 (if (not (string= stylename "cc-mode"))
2448 (c-set-style-1 vars))) 2355 (c-set-style-1 vars)))
2449 (c-keep-region-active)) 2356 (c-keep-region-active))
2450 2357
2451 (defun c-add-style (style descrip &optional set-p) 2358 (defun c-add-style (style descrip &optional set-p)
2561 ;; How shall we decide where the end of the 2468 ;; How shall we decide where the end of the
2562 ;; fill-prefix is? 2469 ;; fill-prefix is?
2563 (progn 2470 (progn
2564 (beginning-of-line) 2471 (beginning-of-line)
2565 (skip-chars-forward " \t*" (c-point 'eol)) 2472 (skip-chars-forward " \t*" (c-point 'eol))
2566 ;; kludge alert, watch out for */, in
2567 ;; which case fill-prefix should *not*
2568 ;; be "*"!
2569 (if (and (= (following-char) ?/)
2570 (= (preceding-char) ?*))
2571 (forward-char -1))
2572 (point))) 2473 (point)))
2573 2474
2574 ;; If the comment is only one line followed 2475 ;; If the comment is only one line followed
2575 ;; by a blank line, calling move-to-column 2476 ;; by a blank line, calling move-to-column
2576 ;; above may have added some spaces and tabs 2477 ;; above may have added some spaces and tabs
2595 ;; Lines containing just a comment start or just an end 2496 ;; Lines containing just a comment start or just an end
2596 ;; should not be filled into paragraphs they are next 2497 ;; should not be filled into paragraphs they are next
2597 ;; to. 2498 ;; to.
2598 (paragraph-start (concat paragraph-start re1)) 2499 (paragraph-start (concat paragraph-start re1))
2599 (paragraph-separate (concat paragraph-separate re1)) 2500 (paragraph-separate (concat paragraph-separate re1))
2600 (chars-to-delete 0) 2501 (chars-to-delete 0))
2601 )
2602 (save-restriction 2502 (save-restriction
2603 ;; Don't fill the comment together with the code 2503 ;; Don't fill the comment together with the code
2604 ;; following it. So temporarily exclude everything 2504 ;; following it. So temporarily exclude everything
2605 ;; before the comment start, and everything after the 2505 ;; before the comment start, and everything after the
2606 ;; line where the comment ends. If comment-start-place 2506 ;; line where the comment ends. If comment-start-place
2608 ;; point is inside the comment. 2508 ;; point is inside the comment.
2609 (narrow-to-region (save-excursion 2509 (narrow-to-region (save-excursion
2610 (if comment-start-place 2510 (if comment-start-place
2611 (goto-char comment-start-place) 2511 (goto-char comment-start-place)
2612 (search-backward "/*")) 2512 (search-backward "/*"))
2613 (if (and (not c-hanging-comment-starter-p)
2614 (looking-at
2615 (concat c-comment-start-regexp
2616 "[ \t]*$")))
2617 (forward-line 1))
2618 ;; Protect text before the comment 2513 ;; Protect text before the comment
2619 ;; start by excluding it. Add 2514 ;; start by excluding it. Add
2620 ;; spaces to bring back proper 2515 ;; spaces to bring back proper
2621 ;; indentation of that point. 2516 ;; indentation of that point.
2622 (let ((column (current-column))) 2517 (let ((column (current-column)))
2705 (goto-char lim) 2600 (goto-char lim)
2706 (setq state (parse-partial-sexp (point) here nil nil))) 2601 (setq state (parse-partial-sexp (point) here nil nil)))
2707 (if (and sentence-flag 2602 (if (and sentence-flag
2708 (or (nth 3 state) 2603 (or (nth 3 state)
2709 (nth 4 state) 2604 (nth 4 state)
2710 ; (looking-at (concat "[ \t]*" comment-start-skip)) 2605 (looking-at (concat "[ \t]*" comment-start-skip))
2711 (save-excursion 2606 (save-excursion
2712 (skip-chars-backward " \t") 2607 (skip-chars-backward " \t")
2713 (goto-char (- (point) 2)) 2608 (goto-char (- (point) 2))
2714 (looking-at "\\*/")))) 2609 (looking-at "\\*/"))))
2715 (forward-sentence (- count)) 2610 (forward-sentence (- count))
2739 nil t)) 2634 nil t))
2740 (c-beginning-of-statement (- (or count 1)) lim sentence-flag) 2635 (c-beginning-of-statement (- (or count 1)) lim sentence-flag)
2741 (c-keep-region-active)) 2636 (c-keep-region-active))
2742 2637
2743 ;; WARNING: Be *exceptionally* careful about modifications to this 2638 ;; WARNING: Be *exceptionally* careful about modifications to this
2744 ;; function! Much of CC Mode depends on this Doing The Right Thing. 2639 ;; function! Much of cc-mode depends on this Doing The Right Thing.
2745 ;; If you break it you will be sorry. 2640 ;; If you break it you will be sorry.
2746 (defun c-beginning-of-statement-1 (&optional lim) 2641 (defun c-beginning-of-statement-1 (&optional lim)
2747 ;; move to the start of the current statement, or the previous 2642 ;; move to the start of the current statement, or the previous
2748 ;; statement if already at the beginning of one. 2643 ;; statement if already at the beginning of one.
2749 (let ((firstp t) 2644 (let ((firstp t)
2751 donep c-in-literal-cache 2646 donep c-in-literal-cache
2752 ;; KLUDGE ALERT: maybe-labelp is used to pass information 2647 ;; KLUDGE ALERT: maybe-labelp is used to pass information
2753 ;; between c-crosses-statement-barrier-p and 2648 ;; between c-crosses-statement-barrier-p and
2754 ;; c-beginning-of-statement-1. A better way should be 2649 ;; c-beginning-of-statement-1. A better way should be
2755 ;; implemented. 2650 ;; implemented.
2756 maybe-labelp saved 2651 maybe-labelp
2757 (last-begin (point))) 2652 (last-begin (point)))
2758 ;; first check for bare semicolon 2653 (while (not donep)
2759 (if (and (progn (c-backward-syntactic-ws lim) 2654 ;; stop at beginning of buffer
2760 (= (preceding-char) ?\;)) 2655 (if (bobp) (setq donep t)
2761 (c-safe (progn (forward-char -1) 2656 ;; go backwards one balanced expression, but be careful of
2762 (setq saved (point)) 2657 ;; unbalanced paren being reached
2763 t)) 2658 (if (not (c-safe (progn (backward-sexp 1) t)))
2764 (progn (c-backward-syntactic-ws lim) 2659 (progn
2765 (memq (preceding-char) '(?\; ?{ ?} ?:))) 2660 (if firstp
2766 ) 2661 (backward-up-list 1)
2767 (setq last-begin saved) 2662 (goto-char last-begin))
2768 (goto-char last-begin) 2663 ;; skip over any unary operators, or other special
2769 (while (not donep) 2664 ;; characters appearing at front of identifier
2770 ;; stop at beginning of buffer 2665 (save-excursion
2771 (if (bobp) (setq donep t) 2666 (c-backward-syntactic-ws lim)
2772 ;; go backwards one balanced expression, but be careful of 2667 (skip-chars-backward "-+!*&:.~ \t\n")
2773 ;; unbalanced paren being reached 2668 (if (= (preceding-char) ?\()
2774 (if (not (c-safe (progn (backward-sexp 1) t))) 2669 (setq last-begin (point))))
2670 (goto-char last-begin)
2671 (setq last-begin (point)
2672 donep t)))
2673
2674 (setq maybe-labelp nil)
2675 ;; see if we're in a literal. if not, then this bufpos may be
2676 ;; a candidate for stopping
2677 (cond
2678 ;; CASE 0: did we hit the error condition above?
2679 (donep)
2680 ;; CASE 1: are we in a literal?
2681 ((eq (c-in-literal lim) 'pound)
2682 (beginning-of-line))
2683 ;; CASE 2: some other kind of literal?
2684 ((c-in-literal lim))
2685 ;; CASE 3: are we looking at a conditional keyword?
2686 ((or (looking-at c-conditional-key)
2687 (and (= (following-char) ?\()
2688 (save-excursion
2689 (forward-sexp 1)
2690 (c-forward-syntactic-ws)
2691 (/= (following-char) ?\;))
2692 (let ((here (point))
2693 (foundp (progn
2694 (c-backward-syntactic-ws lim)
2695 (forward-word -1)
2696 (and lim
2697 (<= lim (point))
2698 (not (c-in-literal lim))
2699 (looking-at c-conditional-key)
2700 ))))
2701 ;; did we find a conditional?
2702 (if (not foundp)
2703 (goto-char here))
2704 foundp)))
2705 ;; are we in the middle of an else-if clause?
2706 (if (save-excursion
2707 (and (not substmt-p)
2708 (c-safe (progn (forward-sexp -1) t))
2709 (looking-at "\\<else\\>[ \t\n]+\\<if\\>")
2710 (not (c-in-literal lim))))
2775 (progn 2711 (progn
2776 (if firstp 2712 (forward-sexp -1)
2777 (backward-up-list 1) 2713 (c-backward-to-start-of-if lim)))
2778 (goto-char last-begin)) 2714 ;; are we sitting at an else clause, that we are not a
2779 ;; skip over any unary operators, or other special 2715 ;; substatement of?
2780 ;; characters appearing at front of identifier 2716 (if (and (not substmt-p)
2781 (save-excursion 2717 (looking-at "\\<else\\>[^_]"))
2782 (c-backward-syntactic-ws lim) 2718 (c-backward-to-start-of-if lim))
2783 (skip-chars-backward "-+!*&:.~ \t\n") 2719 ;; are we sitting at the while of a do-while?
2784 (if (= (preceding-char) ?\() 2720 (if (and (looking-at "\\<while\\>[^_]")
2785 (setq last-begin (point)))) 2721 (c-backward-to-start-of-do lim))
2786 (goto-char last-begin) 2722 (setq substmt-p nil))
2787 (setq last-begin (point) 2723 (setq last-begin (point)
2788 donep t))) 2724 donep substmt-p))
2789 2725 ;; CASE 4: are we looking at a label?
2790 (setq maybe-labelp nil) 2726 ((looking-at c-label-key))
2791 ;; see if we're in a literal. if not, then this bufpos may be 2727 ;; CASE 5: is this the first time we're checking?
2792 ;; a candidate for stopping 2728 (firstp (setq firstp nil
2793 (cond 2729 substmt-p (not (c-crosses-statement-barrier-p
2794 ;; CASE 0: did we hit the error condition above? 2730 (point) last-begin))
2795 (donep) 2731 last-begin (point)))
2796 ;; CASE 1: are we in a literal? 2732 ;; CASE 6: have we crossed a statement barrier?
2797 ((eq (c-in-literal lim) 'pound) 2733 ((c-crosses-statement-barrier-p (point) last-begin)
2798 (beginning-of-line)) 2734 (setq donep t))
2799 ;; CASE 2: some other kind of literal? 2735 ;; CASE 7: ignore labels
2800 ((c-in-literal lim)) 2736 ((and maybe-labelp
2801 ;; CASE 3: are we looking at a conditional keyword? 2737 (or (and c-access-key (looking-at c-access-key))
2802 ((or (looking-at c-conditional-key) 2738 ;; with switch labels, we have to go back further
2803 (and (= (following-char) ?\() 2739 ;; to try to pick up the case or default
2804 (save-excursion 2740 ;; keyword. Potential bogosity alert: we assume
2805 (forward-sexp 1) 2741 ;; `case' or `default' is first thing on line
2806 (c-forward-syntactic-ws) 2742 (let ((here (point)))
2807 (/= (following-char) ?\;)) 2743 (beginning-of-line)
2808 (let ((here (point)) 2744 (c-forward-syntactic-ws)
2809 (foundp (progn 2745 (if (looking-at c-switch-label-key)
2810 (c-backward-syntactic-ws lim) 2746 t
2811 (forward-word -1) 2747 (goto-char here)
2812 (and lim 2748 nil))
2813 (<= lim (point)) 2749 (looking-at c-label-key))))
2814 (not (c-in-literal lim)) 2750 ;; CASE 8: ObjC or Java method def
2815 (looking-at c-conditional-key) 2751 ((and c-method-key
2816 )))) 2752 (setq last-begin (c-in-method-def-p)))
2817 ;; did we find a conditional? 2753 (setq donep t))
2818 (if (not foundp) 2754 ;; CASE 9: nothing special
2819 (goto-char here)) 2755 (t (setq last-begin (point)))
2820 foundp))) 2756 )))
2821 ;; are we in the middle of an else-if clause?
2822 (if (save-excursion
2823 (and (not substmt-p)
2824 (c-safe (progn (forward-sexp -1) t))
2825 (looking-at "\\<else\\>[ \t\n]+\\<if\\>")
2826 (not (c-in-literal lim))))
2827 (progn
2828 (forward-sexp -1)
2829 (c-backward-to-start-of-if lim)))
2830 ;; are we sitting at an else clause, that we are not a
2831 ;; substatement of?
2832 (if (and (not substmt-p)
2833 (looking-at "\\<else\\>[^_]"))
2834 (c-backward-to-start-of-if lim))
2835 ;; are we sitting at the while of a do-while?
2836 (if (and (looking-at "\\<while\\>[^_]")
2837 (c-backward-to-start-of-do lim))
2838 (setq substmt-p nil))
2839 (setq last-begin (point)
2840 donep substmt-p))
2841 ;; CASE 4: are we looking at a label?
2842 ((looking-at c-label-key))
2843 ;; CASE 5: is this the first time we're checking?
2844 (firstp (setq firstp nil
2845 substmt-p (not (c-crosses-statement-barrier-p
2846 (point) last-begin))
2847 last-begin (point)))
2848 ;; CASE 6: have we crossed a statement barrier?
2849 ((c-crosses-statement-barrier-p (point) last-begin)
2850 (setq donep t))
2851 ;; CASE 7: ignore labels
2852 ((and maybe-labelp
2853 (or (and c-access-key (looking-at c-access-key))
2854 ;; with switch labels, we have to go back further
2855 ;; to try to pick up the case or default
2856 ;; keyword. Potential bogosity alert: we assume
2857 ;; `case' or `default' is first thing on line
2858 (let ((here (point)))
2859 (beginning-of-line)
2860 (c-forward-syntactic-ws)
2861 (if (looking-at c-switch-label-key)
2862 t
2863 (goto-char here)
2864 nil))
2865 (looking-at c-label-key))))
2866 ;; CASE 8: ObjC or Java method def
2867 ((and c-method-key
2868 (setq last-begin (c-in-method-def-p)))
2869 (setq donep t))
2870 ;; CASE 9: nothing special
2871 (t (setq last-begin (point)))
2872 ))))
2873 (goto-char last-begin) 2757 (goto-char last-begin)
2874 ;; we always do want to skip over non-whitespace modifier 2758 ;; we always do want to skip over non-whitespace modifier
2875 ;; characters that didn't get skipped above 2759 ;; characters that didn't get skipped above
2876 (skip-chars-backward "-+!*&:.~" (c-point 'boi)))) 2760 (skip-chars-backward "-+!*&:.~" (c-point 'boi))))
2877 2761
3144 (beginning-of-line) 3028 (beginning-of-line)
3145 (let (endmark) 3029 (let (endmark)
3146 (unwind-protect 3030 (unwind-protect
3147 (let ((c-tab-always-indent t) 3031 (let ((c-tab-always-indent t)
3148 ;; shut up any echo msgs on indiv lines 3032 ;; shut up any echo msgs on indiv lines
3149 (c-echo-syntactic-information-p nil) 3033 (c-echo-syntactic-information-p nil))
3150 fence)
3151 (c-progress-init start end 'c-indent-region) 3034 (c-progress-init start end 'c-indent-region)
3152 (setq endmark (copy-marker end)) 3035 (setq endmark (copy-marker end))
3153 (while (and (bolp) 3036 (while (and (bolp)
3154 (not (eobp)) 3037 (not (eobp))
3155 (< (point) endmark)) 3038 (< (point) endmark))
3160 ;; skip blank lines 3043 ;; skip blank lines
3161 (skip-chars-forward " \t\n") 3044 (skip-chars-forward " \t\n")
3162 (beginning-of-line) 3045 (beginning-of-line)
3163 ;; indent the current line 3046 ;; indent the current line
3164 (c-indent-line) 3047 (c-indent-line)
3165 (setq fence (point))
3166 (if (save-excursion 3048 (if (save-excursion
3167 (beginning-of-line) 3049 (beginning-of-line)
3168 (looking-at "[ \t]*#")) 3050 (looking-at "[ \t]*#"))
3169 (forward-line 1) 3051 (forward-line 1)
3170 (save-excursion 3052 (save-excursion
3186 ;; make sure the sexp we found really starts on the 3068 ;; make sure the sexp we found really starts on the
3187 ;; current line and extends past it 3069 ;; current line and extends past it
3188 (goto-char sexpend) 3070 (goto-char sexpend)
3189 (setq sexpend (point-marker)) 3071 (setq sexpend (point-marker))
3190 (c-safe (backward-sexp 1)) 3072 (c-safe (backward-sexp 1))
3191 (setq sexpbeg (point)))) 3073 (setq sexpbeg (point)))))
3192 (if (and sexpbeg (< sexpbeg fence))
3193 (setq sexpbeg fence)))
3194 ;; check to see if the next line starts a 3074 ;; check to see if the next line starts a
3195 ;; comment-only line 3075 ;; comment-only line
3196 (save-excursion 3076 (save-excursion
3197 (forward-line 1) 3077 (forward-line 1)
3198 (skip-chars-forward " \t") 3078 (skip-chars-forward " \t")
3214 (c-indent-line))) 3094 (c-indent-line)))
3215 ;; Move to following line and try again. 3095 ;; Move to following line and try again.
3216 (and sexpend 3096 (and sexpend
3217 (markerp sexpend) 3097 (markerp sexpend)
3218 (set-marker sexpend nil)) 3098 (set-marker sexpend nil))
3219 (forward-line 1) 3099 (forward-line 1)))))
3220 (setq fence (point))))))
3221 (set-marker endmark nil) 3100 (set-marker endmark nil)
3222 (c-progress-fini 'c-indent-region) 3101 (c-progress-fini 'c-indent-region)
3223 )))) 3102 ))))
3224 3103
3225 (defun c-mark-function () 3104 (defun c-mark-function ()
3857 )) 3736 ))
3858 3737
3859 3738
3860 ;; defuns for calculating the syntactic state and indenting a single 3739 ;; defuns for calculating the syntactic state and indenting a single
3861 ;; line of C/C++/ObjC code 3740 ;; line of C/C++/ObjC code
3741 (defmacro c-add-syntax (symbol &optional relpos)
3742 ;; a simple macro to append the syntax in symbol to the syntax list.
3743 ;; try to increase performance by using this macro
3744 (` (setq syntax (cons (cons (, symbol) (, relpos)) syntax))))
3745
3862 (defun c-most-enclosing-brace (state) 3746 (defun c-most-enclosing-brace (state)
3863 ;; return the bufpos of the most enclosing brace that hasn't been 3747 ;; return the bufpos of the most enclosing brace that hasn't been
3864 ;; narrowed out by any enclosing class, or nil if none was found 3748 ;; narrowed out by any enclosing class, or nil if none was found
3865 (let (enclosingp) 3749 (let (enclosingp)
3866 (while (and state (not enclosingp)) 3750 (while (and state (not enclosingp))
3926 (state fullstate) 3810 (state fullstate)
3927 (in-method-intro-p (and c-method-key 3811 (in-method-intro-p (and c-method-key
3928 (looking-at c-method-key))) 3812 (looking-at c-method-key)))
3929 literal containing-sexp char-before-ip char-after-ip lim 3813 literal containing-sexp char-before-ip char-after-ip lim
3930 syntax placeholder c-in-literal-cache inswitch-p 3814 syntax placeholder c-in-literal-cache inswitch-p
3931 injava-inher
3932 ;; narrow out any enclosing class or extern "C" block 3815 ;; narrow out any enclosing class or extern "C" block
3933 (inclass-p (c-narrow-out-enclosing-class state indent-point)) 3816 (inclass-p (c-narrow-out-enclosing-class state indent-point))
3934 (inextern-p (and inclass-p 3817 (inextern-p (and inclass-p
3935 (save-excursion 3818 (save-excursion
3936 (save-restriction 3819 (save-restriction
3990 ;; CASE 2: in a C or C++ style comment. 3873 ;; CASE 2: in a C or C++ style comment.
3991 ((memq literal '(c c++)) 3874 ((memq literal '(c c++))
3992 ;; we need to catch multi-paragraph C comments 3875 ;; we need to catch multi-paragraph C comments
3993 (while (and (zerop (forward-line -1)) 3876 (while (and (zerop (forward-line -1))
3994 (looking-at "^[ \t]*$"))) 3877 (looking-at "^[ \t]*$")))
3995 (c-add-syntax literal (c-point 'boi))) 3878 (c-add-syntax literal (c-point 'bol)))
3996 ;; CASE 3: in a cpp preprocessor 3879 ;; CASE 3: in a cpp preprocessor
3997 ((eq literal 'pound) 3880 ((eq literal 'pound)
3998 (c-beginning-of-macro lim) 3881 (c-beginning-of-macro lim)
3999 (c-add-syntax 'cpp-macro (c-point 'boi))) 3882 (c-add-syntax 'cpp-macro (c-point 'boi)))
4000 ;; CASE 4: in an objective-c method intro 3883 ;; CASE 4: in an objective-c method intro
4045 ((save-excursion 3928 ((save-excursion
4046 (c-beginning-of-statement-1 lim) 3929 (c-beginning-of-statement-1 lim)
4047 ;; c-b-o-s could have left us at point-min 3930 ;; c-b-o-s could have left us at point-min
4048 (and (bobp) 3931 (and (bobp)
4049 (c-forward-syntactic-ws indent-point)) 3932 (c-forward-syntactic-ws indent-point))
4050 (if (looking-at "typedef[^_]") 3933 (setq placeholder (point))
4051 (progn (forward-sexp 1)
4052 (c-forward-syntactic-ws indent-point)))
4053 (setq placeholder (c-point 'boi))
4054 (and (or (looking-at "enum[ \t\n]+") 3934 (and (or (looking-at "enum[ \t\n]+")
4055 (= char-before-ip ?=)) 3935 (= char-before-ip ?=))
4056 (save-excursion 3936 (save-excursion
4057 (skip-chars-forward "^;(" indent-point) 3937 (skip-chars-forward "^;(" indent-point)
4058 (not (memq (following-char) '(?\; ?\())) 3938 (not (memq (following-char) '(?\; ?\()))
4084 (if (= (preceding-char) ?:) 3964 (if (= (preceding-char) ?:)
4085 (progn (forward-char -1) 3965 (progn (forward-char -1)
4086 (c-backward-syntactic-ws lim))) 3966 (c-backward-syntactic-ws lim)))
4087 (if (= (preceding-char) ?\)) 3967 (if (= (preceding-char) ?\))
4088 (backward-sexp 1)) 3968 (backward-sexp 1))
4089 (setq placeholder (point))
4090 (save-excursion
4091 (and (c-safe (backward-sexp 1) t)
4092 (looking-at "throw[^_]")
4093 (c-safe (backward-sexp 1) t)
4094 (setq placeholder (point))))
4095 (goto-char placeholder)
4096 (c-add-syntax 'member-init-intro (c-point 'boi)) 3969 (c-add-syntax 'member-init-intro (c-point 'boi))
4097 ;; we don't need to add any class offset since this 3970 ;; we don't need to add any class offset since this
4098 ;; should be relative to the ctor's indentation 3971 ;; should be relative to the ctor's indentation
4099 ) 3972 )
4100 ;; CASE 5B.2: K&R arg decl intro 3973 ;; CASE 5B.2: K&R arg decl intro
4101 (c-recognize-knr-p 3974 (c-recognize-knr-p
4102 (c-add-syntax 'knr-argdecl-intro (c-point 'boi)) 3975 (c-add-syntax 'knr-argdecl-intro (c-point 'boi))
4103 (and inclass-p (c-add-syntax 'inclass (aref inclass-p 0)))) 3976 (and inclass-p (c-add-syntax 'inclass (aref inclass-p 0))))
4104 ;; CASE 5B.3: Nether region after a C++ or Java func 3977 ;; CASE 5B.3: Nether region after a C++ func decl, which
4105 ;; decl, which could include a `throws' declaration. 3978 ;; could include a `throw' declaration.
4106 (t 3979 (t
4107 (c-beginning-of-statement-1 lim) 3980 (c-beginning-of-statement-1 lim)
4108 (c-add-syntax 'func-decl-cont (c-point 'boi)) 3981 (c-add-syntax 'ansi-funcdecl-cont (c-point 'boi))
4109 ))) 3982 )))
4110 ;; CASE 5C: inheritance line. could be first inheritance 3983 ;; CASE 5C: inheritance line. could be first inheritance
4111 ;; line, or continuation of a multiple inheritance 3984 ;; line, or continuation of a multiple inheritance
4112 ((or (and c-baseclass-key (looking-at c-baseclass-key)) 3985 ((or (and c-baseclass-key (looking-at c-baseclass-key))
4113 (and (or (= char-before-ip ?:) 3986 (and (or (= char-before-ip ?:)
4114 ;; watch out for scope operator 3987 (= char-after-ip ?:))
4115 (save-excursion
4116 (and (= char-after-ip ?:)
4117 (c-safe (progn (forward-char 1) t))
4118 (/= (following-char) ?:)
4119 )))
4120 (save-excursion 3988 (save-excursion
4121 (c-backward-syntactic-ws lim) 3989 (c-backward-syntactic-ws lim)
4122 (if (= char-before-ip ?:) 3990 (if (= char-before-ip ?:)
4123 (progn 3991 (progn
4124 (forward-char -1) 3992 (forward-char -1)
4125 (c-backward-syntactic-ws lim))) 3993 (c-backward-syntactic-ws lim)))
4126 (back-to-indentation) 3994 (back-to-indentation)
4127 (looking-at c-class-key))) 3995 (looking-at c-class-key))))
4128 ;; for Java
4129 (and (eq major-mode 'java-mode)
4130 (let ((fence (save-excursion
4131 (c-beginning-of-statement-1 lim)
4132 (point)))
4133 cont done)
4134 (save-excursion
4135 (while (not done)
4136 (cond ((looking-at c-Java-special-key)
4137 (setq injava-inher (cons cont (point))
4138 done t))
4139 ((or (not (c-safe (forward-sexp -1) t))
4140 (<= (point) fence))
4141 (setq done t))
4142 )
4143 (setq cont t)))
4144 injava-inher)
4145 (not (c-crosses-statement-barrier-p (cdr injava-inher)
4146 (point)))
4147 ))
4148 (cond 3996 (cond
4149 ;; CASE 5C.1: non-hanging colon on an inher intro 3997 ;; CASE 5C.1: non-hanging colon on an inher intro
4150 ((= char-after-ip ?:) 3998 ((= char-after-ip ?:)
4151 (c-backward-syntactic-ws lim) 3999 (c-backward-syntactic-ws lim)
4152 (c-add-syntax 'inher-intro (c-point 'boi)) 4000 (c-add-syntax 'inher-intro (c-point 'boi))
4155 ) 4003 )
4156 ;; CASE 5C.2: hanging colon on an inher intro 4004 ;; CASE 5C.2: hanging colon on an inher intro
4157 ((= char-before-ip ?:) 4005 ((= char-before-ip ?:)
4158 (c-add-syntax 'inher-intro (c-point 'boi)) 4006 (c-add-syntax 'inher-intro (c-point 'boi))
4159 (and inclass-p (c-add-syntax 'inclass (aref inclass-p 0)))) 4007 (and inclass-p (c-add-syntax 'inclass (aref inclass-p 0))))
4160 ;; CASE 5C.3: in a Java implements/extends 4008 ;; CASE 5C.3: a continued inheritance line
4161 (injava-inher
4162 (let ((where (cdr injava-inher))
4163 (cont (car injava-inher))
4164 (here (point)))
4165 (goto-char where)
4166 (cond ((looking-at "throws[^_]")
4167 (c-add-syntax 'func-decl-cont
4168 (progn (c-beginning-of-statement-1 lim)
4169 (c-point 'boi))))
4170 (cont (c-add-syntax 'inher-cont where))
4171 (t (c-add-syntax 'inher-intro
4172 (progn (goto-char (cdr injava-inher))
4173 (c-beginning-of-statement-1 lim)
4174 (point))))
4175 )))
4176 ;; CASE 5C.4: a continued inheritance line
4177 (t 4009 (t
4178 (c-beginning-of-inheritance-list lim) 4010 (c-beginning-of-inheritance-list lim)
4179 (c-add-syntax 'inher-cont (point)) 4011 (c-add-syntax 'inher-cont (point))
4180 ;; don't add inclass symbol since relative point already 4012 ;; don't add inclass symbol since relative point already
4181 ;; contains any class offset 4013 ;; contains any class offset
4277 (let ((limit (save-excursion 4109 (let ((limit (save-excursion
4278 (re-search-backward "^[^ \^L\t\n#]" nil 'move) 4110 (re-search-backward "^[^ \^L\t\n#]" nil 'move)
4279 (point)))) 4111 (point))))
4280 (save-excursion 4112 (save-excursion
4281 (c-backward-syntactic-ws limit) 4113 (c-backward-syntactic-ws limit)
4282 (setq placeholder (point))
4283 (while (and (memq (preceding-char) '(?\; ?,)) 4114 (while (and (memq (preceding-char) '(?\; ?,))
4284 (> (point) limit)) 4115 (> (point) limit))
4285 (beginning-of-line) 4116 (beginning-of-line)
4286 (setq placeholder (point)) 4117 (setq placeholder (point))
4287 (c-backward-syntactic-ws limit)) 4118 (c-backward-syntactic-ws limit))
4664 ;; watch out for scope operator 4495 ;; watch out for scope operator
4665 (not (looking-at "::"))))) 4496 (not (looking-at "::")))))
4666 (c-add-syntax 'statement-cont (c-point 'boi))) 4497 (c-add-syntax 'statement-cont (c-point 'boi)))
4667 ;; CASE 15D: any old statement 4498 ;; CASE 15D: any old statement
4668 ((< (point) indent-point) 4499 ((< (point) indent-point)
4669 (let ((safepos (c-most-enclosing-brace fullstate)) 4500 (let ((safepos (c-most-enclosing-brace fullstate)))
4670 relpos done)
4671 (goto-char indent-point) 4501 (goto-char indent-point)
4672 (c-beginning-of-statement-1 safepos) 4502 (c-beginning-of-statement-1 safepos)
4673 ;; It is possible we're on the brace that opens a nested 4503 ;; It is possible we're on the brace that opens a nested
4674 ;; function. 4504 ;; function.
4675 (if (and (= (following-char) ?{) 4505 (if (and (= (following-char) ?{)
4676 (save-excursion 4506 (save-excursion
4677 (c-backward-syntactic-ws safepos) 4507 (c-backward-syntactic-ws safepos)
4678 (/= (preceding-char) ?\;))) 4508 (/= (preceding-char) ?\;)))
4679 (c-beginning-of-statement-1 safepos)) 4509 (c-beginning-of-statement-1 safepos))
4680 (if (and inswitch-p 4510 (c-add-syntax 'statement (c-point 'boi))
4681 (looking-at c-switch-label-key))
4682 (progn
4683 (goto-char placeholder)
4684 (end-of-line)
4685 (forward-sexp -1)))
4686 (setq relpos (c-point 'boi))
4687 (while (and (not done)
4688 (<= safepos (point))
4689 (/= relpos (point)))
4690 (c-beginning-of-statement-1 safepos)
4691 (if (= relpos (c-point 'boi))
4692 (setq done t))
4693 (setq relpos (c-point 'boi)))
4694 (c-add-syntax 'statement relpos)
4695 (if (= char-after-ip ?{) 4511 (if (= char-after-ip ?{)
4696 (c-add-syntax 'block-open)))) 4512 (c-add-syntax 'block-open))))
4697 ;; CASE 15E: first statement in an inline, or first 4513 ;; CASE 15E: first statement in an inline, or first
4698 ;; statement in a top-level defun. we can tell this is it 4514 ;; statement in a top-level defun. we can tell this is it
4699 ;; if there are no enclosing braces that haven't been 4515 ;; if there are no enclosing braces that haven't been
4907 (looking-at c-comment-start-regexp)) 4723 (looking-at c-comment-start-regexp))
4908 (c-forward-syntactic-ws here)) 4724 (c-forward-syntactic-ws here))
4909 (- (current-column) cs-curcol) 4725 (- (current-column) cs-curcol)
4910 ))) 4726 )))
4911 4727
4912 (defun c-lineup-java-inher (langelem)
4913 ;; line up Java implements and extends continuations
4914 (save-excursion
4915 (let ((cs-curcol (progn (goto-char (cdr langelem))
4916 (current-column))))
4917 (forward-word 1)
4918 (if (looking-at "[ \t]*$")
4919 cs-curcol
4920 (c-forward-syntactic-ws)
4921 (- (current-column) cs-curcol)))))
4922
4923 (defun c-lineup-C-comments (langelem) 4728 (defun c-lineup-C-comments (langelem)
4924 ;; line up C block comment continuation lines 4729 ;; line up C block comment continuation lines
4925 (save-excursion 4730 (save-excursion
4926 (let ((here (point)) 4731 (let ((stars (progn
4927 (stars (progn (back-to-indentation) 4732 (beginning-of-line)
4928 (skip-chars-forward "*"))) 4733 (skip-chars-forward " \t")
4734 (if (looking-at "\\*\\*?")
4735 (- (match-end 0) (match-beginning 0))
4736 0)))
4929 (cs-curcol (progn (goto-char (cdr langelem)) 4737 (cs-curcol (progn (goto-char (cdr langelem))
4930 (current-column)))) 4738 (current-column))))
4931 (back-to-indentation) 4739 (back-to-indentation)
4932 (if (not (re-search-forward "/[*]+" (c-point 'eol) t)) 4740 (if (re-search-forward "/\\*[ \t]*" (c-point 'eol) t)
4933 (progn 4741 (goto-char (+ (match-beginning 0)
4934 (if (not (looking-at "[*]+")) 4742 (cond
4935 (progn 4743 (c-block-comments-indent-p 0)
4936 ;; we now have to figure out where this comment begins. 4744 ((= stars 1) 1)
4937 (goto-char here) 4745 ((= stars 2) 0)
4938 (back-to-indentation) 4746 (t (- (match-end 0) (match-beginning 0)))))))
4939 (if (looking-at "[*]+/") 4747 (- (current-column) cs-curcol))))
4940 (progn (goto-char (match-end 0))
4941 (forward-comment -1))
4942 (goto-char (cdr langelem))
4943 (back-to-indentation))))
4944 (- (current-column) cs-curcol))
4945 (if (zerop stars)
4946 (skip-chars-forward " \t"))
4947 (- (current-column) stars cs-curcol))
4948 )))
4949 4748
4950 (defun c-lineup-comment (langelem) 4749 (defun c-lineup-comment (langelem)
4951 ;; support old behavior for comment indentation. we look at 4750 ;; support old behavior for comment indentation. we look at
4952 ;; c-comment-only-line-offset to decide how to indent comment 4751 ;; c-comment-only-line-offset to decide how to indent comment
4953 ;; only-lines 4752 ;; only-lines
5104 (looking-at "\\<do\\>[^_]"))) 4903 (looking-at "\\<do\\>[^_]")))
5105 '(before) 4904 '(before)
5106 '(before after))))) 4905 '(before after)))))
5107 4906
5108 (defun c-gnu-impose-minimum () 4907 (defun c-gnu-impose-minimum ()
5109 "Imposes a minimum indentation for lines inside a top-level construct. 4908 "Imposes a minimum indentation for labels and case tags.
5110 The variable `c-label-minimum-indentation' specifies the minimum 4909 The variable `c-label-minimum-indentation' specifies the minimum
5111 indentation amount." 4910 indentation amount."
5112 (let ((non-top-levels '(defun-block-intro statement statement-cont 4911 (let ((non-top-levels '(defun-block-intro statement statement-cont
5113 statement-block-intro statement-case-intro 4912 statement-block-intro statement-case-intro
5114 statement-case-open substatement substatement-open 4913 statement-case-open substatement substatement-open
5203 (progn (skip-chars-backward " \t") (point))))))) 5002 (progn (skip-chars-backward " \t") (point)))))))
5204 5003
5205 5004
5206 ;; defuns for submitting bug reports 5005 ;; defuns for submitting bug reports
5207 5006
5208 (defconst c-version "4.389" 5007 (defconst c-version "4.322"
5209 "CC Mode version number.") 5008 "cc-mode version number.")
5210 (defconst c-mode-help-address 5009 (defconst c-mode-help-address
5211 "bug-gnu-emacs@prep.ai.mit.edu, cc-mode-help@python.org" 5010 "bug-gnu-emacs@prep.ai.mit.edu, cc-mode-help@python.org"
5212 "Address for CC Mode bug reports.") 5011 "Address for cc-mode bug reports.")
5213 5012
5214 (defun c-version () 5013 (defun c-version ()
5215 "Echo the current version of CC Mode in the minibuffer." 5014 "Echo the current version of cc-mode in the minibuffer."
5216 (interactive) 5015 (interactive)
5217 (message "Using CC Mode version %s" c-version) 5016 (message "Using cc-mode version %s" c-version)
5218 (c-keep-region-active)) 5017 (c-keep-region-active))
5219 5018
5220 ;; get reporter-submit-bug-report when byte-compiling 5019 ;; get reporter-submit-bug-report when byte-compiling
5221 (eval-when-compile 5020 (eval-when-compile
5222 (require 'reporter)) 5021 (require 'reporter))
5223 5022
5224 (defun c-submit-bug-report () 5023 (defun c-submit-bug-report ()
5225 "Submit via mail a bug report on CC Mode." 5024 "Submit via mail a bug report on cc-mode."
5226 (interactive) 5025 (interactive)
5227 ;; load in reporter 5026 ;; load in reporter
5228 (let ((reporter-prompt-for-summary-p t) 5027 (let ((reporter-prompt-for-summary-p t)
5229 (reporter-dont-compact-list '(c-offsets-alist)) 5028 (reporter-dont-compact-list '(c-offsets-alist)))
5230 (style c-indentation-style)
5231 (hook c-special-indent-hook)
5232 (c-features c-emacs-features))
5233 (and 5029 (and
5234 (if (y-or-n-p "Do you want to submit a report on CC Mode? ") 5030 (if (y-or-n-p "Do you want to submit a report on cc-mode? ")
5235 t (message "") nil) 5031 t (message "") nil)
5236 (require 'reporter) 5032 (require 'reporter)
5237 (reporter-submit-bug-report 5033 (reporter-submit-bug-report
5238 c-mode-help-address 5034 c-mode-help-address
5239 (concat "CC Mode " c-version " (" 5035 (concat "cc-mode " c-version " ("
5240 (cond ((eq major-mode 'c++-mode) "C++") 5036 (cond ((eq major-mode 'c++-mode) "C++")
5241 ((eq major-mode 'c-mode) "C") 5037 ((eq major-mode 'c-mode) "C")
5242 ((eq major-mode 'objc-mode) "ObjC") 5038 ((eq major-mode 'objc-mode) "ObjC")
5243 ((eq major-mode 'java-mode) "Java") 5039 ((eq major-mode 'java-mode) "Java")
5244 ) 5040 )
5245 ")") 5041 ")")
5246 (let ((vars (list 5042 (let ((vars (list
5247 ;; report only the vars that affect indentation 5043 ;; report only the vars that affect indentation
5248 'c-basic-offset 5044 'c-basic-offset
5249 'c-offsets-alist 5045 'c-offsets-alist
5046 'c-block-comments-indent-p
5250 'c-cleanup-list 5047 'c-cleanup-list
5251 'c-comment-only-line-offset 5048 'c-comment-only-line-offset
5252 'c-backslash-column 5049 'c-backslash-column
5253 'c-delete-function 5050 'c-delete-function
5254 'c-electric-pound-behavior 5051 'c-electric-pound-behavior
5255 'c-hanging-braces-alist 5052 'c-hanging-braces-alist
5256 'c-hanging-colons-alist 5053 'c-hanging-colons-alist
5257 'c-hanging-comment-starter-p
5258 'c-hanging-comment-ender-p 5054 'c-hanging-comment-ender-p
5259 'c-indent-comments-syntactically-p
5260 'c-tab-always-indent 5055 'c-tab-always-indent
5261 'c-recognize-knr-p 5056 'c-recognize-knr-p
5262 'c-label-minimum-indentation 5057 'c-label-minimum-indentation
5263 'defun-prompt-regexp 5058 'defun-prompt-regexp
5264 'tab-width 5059 'tab-width
5267 (delq 'defun-prompt-regexp vars) 5062 (delq 'defun-prompt-regexp vars)
5268 vars)) 5063 vars))
5269 (function 5064 (function
5270 (lambda () 5065 (lambda ()
5271 (insert 5066 (insert
5272 "Buffer Style: " style "\n\n" 5067 (if c-special-indent-hook
5273 (if hook
5274 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" 5068 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
5275 "c-special-indent-hook is set to '" 5069 "c-special-indent-hook is set to '"
5276 (format "%s" hook) 5070 (format "%s" c-special-indent-hook)
5277 ".\nPerhaps this is your problem?\n" 5071 ".\nPerhaps this is your problem?\n"
5278 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n") 5072 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
5279 "\n") 5073 "\n")
5280 (format "c-emacs-features: %s\n" c-features) 5074 (format "c-emacs-features: %s\n" c-emacs-features)
5281 ))) 5075 )))
5282 nil 5076 nil
5283 "Dear Barry," 5077 "Dear Barry,"
5284 )))) 5078 ))))
5285 5079
5286 5080
5287 ;; menus for XEmacs 19 5081 ;; menus for XEmacs 19
5288 (defun c-mode-menu ()
5289 (cons (concat mode-name " Mode Commands") c-mode-menu))
5290
5291 (defun c-popup-menu (e) 5082 (defun c-popup-menu (e)
5292 "Pops up the C/C++/ObjC menu." 5083 "Pops up the C/C++/ObjC menu."
5293 (interactive "@e") 5084 (interactive "@e")
5294 (popup-menu (c-mode-menu)) 5085 (popup-menu (cons (concat mode-name " Mode Commands") c-mode-menu))
5295 (c-keep-region-active)) 5086 (c-keep-region-active))
5296 5087
5297 5088
5298 ;; Emacs/XEmacs Compatibility 5089 ;; Emacs/XEmacs Compatibility
5299 ;; XEmacs has these, Emacs does not 5090 ;; XEmacs has these, Emacs (even 19.31) does not
5300 5091
5301 (if (fboundp 'functionp) 5092 ;; Lift XEmacs 19.13's functionp from subr.el
5302 (defalias 'c-functionp 'functionp) 5093 (defun c-functionp (obj)
5303 ;; Lift XEmacs 19.13's functionp from subr.el 5094 "Returns t if OBJ is a function, nil otherwise."
5304 (defun c-functionp (obj) 5095 (cond
5305 "Returns t if OBJ is a function, nil otherwise." 5096 ((symbolp obj) (fboundp obj))
5306 (cond 5097 ((subrp obj))
5307 ((symbolp obj) (fboundp obj)) 5098 ((compiled-function-p obj))
5308 ((subrp obj)) 5099 ((consp obj)
5309 ((compiled-function-p obj)) 5100 (if (eq (car obj) 'lambda) (listp (car (cdr obj)))))
5310 ((consp obj) 5101 (t nil)))
5311 (if (eq (car obj) 'lambda) (listp (car (cdr obj))))) 5102
5312 (t nil)))) 5103 (defun c-copy-tree (tree)
5313
5314 (if (fboundp 'copy-tree)
5315 (defalias 'c-copy-tree 'copy-tree)
5316 ;; Lift XEmacs 19.12's copy-tree 5104 ;; Lift XEmacs 19.12's copy-tree
5317 (defun c-copy-tree (tree) 5105 (if (consp tree)
5318 (if (consp tree) 5106 (cons (c-copy-tree (car tree))
5319 (cons (c-copy-tree (car tree)) 5107 (c-copy-tree (cdr tree)))
5320 (c-copy-tree (cdr tree))) 5108 (if (vectorp tree)
5321 (if (vectorp tree) 5109 (let* ((new (copy-sequence tree))
5322 (let* ((new (copy-sequence tree)) 5110 (i (1- (length new))))
5323 (i (1- (length new)))) 5111 (while (>= i 0)
5324 (while (>= i 0) 5112 (aset new i (c-copy-tree (aref new i)))
5325 (aset new i (c-copy-tree (aref new i))) 5113 (setq i (1- i)))
5326 (setq i (1- i))) 5114 new)
5327 new) 5115 tree)))
5328 tree)))) 5116
5117 (defun c-mapcar-defun (var)
5118 (let ((val (symbol-value var)))
5119 (cons var (if (atom val) val
5120 ;; XEmacs 19.12 and Emacs 19 + lucid.el have this
5121 (if (fboundp 'copy-tree)
5122 (copy-tree val)
5123 ;; Emacs 19 and Emacs 18
5124 (c-copy-tree val)
5125 )))
5126 ))
5127
5329 5128
5330 5129
5331 ;; Dynamically append the default value of most variables. This is 5130 ;; Dynamically append the default value of most variables. This is
5332 ;; crucial because future c-set-style calls will always reset the 5131 ;; crucial because future c-set-style calls will always reset the
5333 ;; variables first to the `cc-mode' style before instituting the new 5132 ;; variables first to the `cc-mode' style before instituting the new
5334 ;; style. Only do this once! 5133 ;; style. Only do this once!
5335 (or (assoc "cc-mode" c-style-alist) 5134 (or (assoc "cc-mode" c-style-alist)
5336 (progn 5135 (progn
5337 (c-add-style "cc-mode" 5136 (c-add-style "cc-mode"
5338 (mapcar 5137 (mapcar 'c-mapcar-defun
5339 (function 5138 '(c-backslash-column
5340 (lambda (var) 5139 c-basic-offset
5341 (let ((val (symbol-value var))) 5140 c-block-comments-indent-p
5342 (cons var (if (atom val) val 5141 c-cleanup-list
5343 (c-copy-tree val) 5142 c-comment-only-line-offset
5344 )) 5143 c-electric-pound-behavior
5345 ))) 5144 c-hanging-braces-alist
5346 '(c-backslash-column 5145 c-hanging-colons-alist
5347 c-basic-offset 5146 c-hanging-comment-ender-p
5348 c-cleanup-list 5147 c-offsets-alist
5349 c-comment-only-line-offset 5148 )))
5350 c-electric-pound-behavior
5351 c-hanging-braces-alist
5352 c-hanging-colons-alist
5353 c-hanging-comment-starter-p
5354 c-hanging-comment-ender-p
5355 c-offsets-alist
5356 )))
5357 ;; the default style is now GNU. This can be overridden in 5149 ;; the default style is now GNU. This can be overridden in
5358 ;; c-mode-common-hook or {c,c++,objc,java}-mode-hook. 5150 ;; c-mode-common-hook or {c,c++,objc,java}-mode-hook.
5359 (c-set-style c-site-default-style))) 5151 (c-set-style c-site-default-style)))
5360 5152
5361 (if c-style-variables-are-local-p 5153 ;; style variables
5362 (progn 5154 (make-variable-buffer-local 'c-offsets-alist)
5363 ;; style variables 5155 (make-variable-buffer-local 'c-basic-offset)
5364 (make-variable-buffer-local 'c-offsets-alist) 5156 (make-variable-buffer-local 'c-file-style)
5365 (make-variable-buffer-local 'c-basic-offset) 5157 (make-variable-buffer-local 'c-file-offsets)
5366 (make-variable-buffer-local 'c-file-style) 5158 (make-variable-buffer-local 'c-comment-only-line-offset)
5367 (make-variable-buffer-local 'c-file-offsets) 5159 (make-variable-buffer-local 'c-block-comments-indent-p)
5368 (make-variable-buffer-local 'c-comment-only-line-offset) 5160 (make-variable-buffer-local 'c-cleanup-list)
5369 (make-variable-buffer-local 'c-cleanup-list) 5161 (make-variable-buffer-local 'c-hanging-braces-alist)
5370 (make-variable-buffer-local 'c-hanging-braces-alist) 5162 (make-variable-buffer-local 'c-hanging-colons-alist)
5371 (make-variable-buffer-local 'c-hanging-colons-alist) 5163 (make-variable-buffer-local 'c-hanging-comment-ender-p)
5372 (make-variable-buffer-local 'c-hanging-comment-starter-p) 5164 (make-variable-buffer-local 'c-backslash-column)
5373 (make-variable-buffer-local 'c-hanging-comment-ender-p) 5165 (make-variable-buffer-local 'c-label-minimum-indentation)
5374 (make-variable-buffer-local 'c-backslash-column) 5166 (make-variable-buffer-local 'c-special-indent-hook)
5375 (make-variable-buffer-local 'c-label-minimum-indentation)
5376 (make-variable-buffer-local 'c-special-indent-hook)
5377 (make-variable-buffer-local 'c-indentation-style)))
5378 5167
5379 5168
5380 ;; fsets for compatibility with BOCM 5169 ;; fsets for compatibility with BOCM
5381 (fset 'electric-c-brace 'c-electric-brace) 5170 (fset 'electric-c-brace 'c-electric-brace)
5382 (fset 'electric-c-semi 'c-electric-semi&comma) 5171 (fset 'electric-c-semi 'c-electric-semi&comma)
5383 (fset 'electric-c-sharp-sign 'c-electric-pound) 5172 (fset 'electric-c-sharp-sign 'c-electric-pound)
5384 ;; there is no CC Mode equivalent for electric-c-terminator 5173 ;; there is no cc-mode equivalent for electric-c-terminator
5385 (fset 'mark-c-function 'c-mark-function) 5174 (fset 'mark-c-function 'c-mark-function)
5386 (fset 'indent-c-exp 'c-indent-exp) 5175 (fset 'indent-c-exp 'c-indent-exp)
5387 ;;;###autoload (fset 'set-c-style 'c-set-style) 5176 ;;;###autoload (fset 'set-c-style 'c-set-style)
5388 ;; Lucid Emacs 19.9 + font-lock + CC Mode - c++-mode lossage 5177 ;; Lucid Emacs 19.9 + font-lock + cc-mode - c++-mode lossage
5389 (fset 'c++-beginning-of-defun 'beginning-of-defun) 5178 (fset 'c++-beginning-of-defun 'beginning-of-defun)
5390 (fset 'c++-end-of-defun 'end-of-defun) 5179 (fset 'c++-end-of-defun 'end-of-defun)
5391 5180
5392 ;; set up bc warnings for obsolete variables, but for now lets not 5181 ;; set up bc warnings for obsolete variables, but for now lets not
5393 ;; worry about obsolete functions. maybe later some will be important 5182 ;; worry about obsolete functions. maybe later some will be important
5405 (cons 'c++-member-init-indent 'c-offsets-alist) 5194 (cons 'c++-member-init-indent 'c-offsets-alist)
5406 (cons 'c++-friend-offset na) 5195 (cons 'c++-friend-offset na)
5407 (cons 'c++-access-specifier-offset 'c-offsets-alist) 5196 (cons 'c++-access-specifier-offset 'c-offsets-alist)
5408 (cons 'c++-empty-arglist-indent 'c-offsets-alist) 5197 (cons 'c++-empty-arglist-indent 'c-offsets-alist)
5409 (cons 'c++-comment-only-line-offset 'c-comment-only-line-offset) 5198 (cons 'c++-comment-only-line-offset 'c-comment-only-line-offset)
5410 (cons 'c++-C-block-comments-indent-p na) 5199 (cons 'c++-C-block-comments-indent-p 'c-block-comments-indent-p)
5411 (cons 'c++-cleanup-list 'c-cleanup-list) 5200 (cons 'c++-cleanup-list 'c-cleanup-list)
5412 (cons 'c++-hanging-braces 'c-hanging-braces-alist) 5201 (cons 'c++-hanging-braces 'c-hanging-braces-alist)
5413 (cons 'c++-hanging-member-init-colon 'c-hanging-colons-alist) 5202 (cons 'c++-hanging-member-init-colon 'c-hanging-colons-alist)
5414 (cons 'c++-auto-hungry-initial-state 5203 (cons 'c++-auto-hungry-initial-state
5415 "Use `c-auto-newline' and `c-hungry-delete-key' instead.") 5204 "Use `c-auto-newline' and `c-hungry-delete-key' instead.")
5431 (cons 'c-label-offset 'c-offsets-alist) 5220 (cons 'c-label-offset 'c-offsets-alist)
5432 (cons 'c-continued-statement-offset 'c-offsets-alist) 5221 (cons 'c-continued-statement-offset 'c-offsets-alist)
5433 (cons 'c-continued-brace-offset 'c-offsets-alist) 5222 (cons 'c-continued-brace-offset 'c-offsets-alist)
5434 (cons 'c-default-macroize-column 'c-backslash-column) 5223 (cons 'c-default-macroize-column 'c-backslash-column)
5435 (cons 'c++-default-macroize-column 'c-backslash-column) 5224 (cons 'c++-default-macroize-column 'c-backslash-column)
5436 (cons 'c-block-comments-indent-p na)
5437 ))) 5225 )))
5438 (mapcar 5226 (mapcar
5439 (function 5227 (function
5440 (lambda (elt) 5228 (lambda (elt)
5441 (make-obsolete-variable (car elt) (cdr elt)))) 5229 (make-obsolete-variable (car elt) (cdr elt))))