comparison lisp/modes/cc-mode.el @ 2:ac2d302a0011 r19-15b2

Import from CVS: tag r19-15b2
author cvs
date Mon, 13 Aug 2007 08:46:35 +0200
parents 376386a54a3c
children b82b59fe008d
comparison
equal deleted inserted replaced
1:c0c6a60d29db 2:ac2d302a0011
1 ;;; cc-mode.el --- major mode for editing C, C++, and Objective-C 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 Free Software Foundation, Inc. 3 ;; Copyright (C) 1985, 87, 92, 93, 94, 95, 96 Free Software Foundation, Inc.
4 4
5 ;; Authors: 1992-1996 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.282 9 ;; Version: 4.315
10 ;; Last Modified: 1996/02/09 23:15:14 10 ;; Last Modified: 1996/08/20 21:08:13
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
43 ;; all known Emacsen, nice new features, and tons of bug fixes. This 43 ;; all known Emacsen, nice new features, and tons of bug fixes. This
44 ;; package is called "cc-mode" to distinguish it from its ancestors, 44 ;; package is called "cc-mode" to distinguish it from its ancestors,
45 ;; but there really is no top-level cc-mode. Usage and programming 45 ;; but there really is no top-level cc-mode. Usage and programming
46 ;; details are contained in an accompanying texinfo manual. 46 ;; details are contained in an accompanying texinfo manual.
47 47
48 ;; NOTE: This mode does not perform font-locking (a.k.a syntactic
49 ;; coloring, keyword highlighting, etc.). Typically this is done by a
50 ;; package called font-lock.el which I do *not* maintain. You should
51 ;; contact the Emacs maintainer for questions about coloring or
52 ;; highlighting in any language mode.
53
48 ;; 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
49 ;; bug-gnu-emacs@prep.ai.mit.edu and I'll read about them there (this 55 ;; bug-gnu-emacs@prep.ai.mit.edu as well as cc-mode-help@python.org,
50 ;; is mirrored as the Usenet newsgroup gnu.emacs.bug). Questions can 56 ;; and I'll read about them there (the former is mirrored as the
51 ;; sent to help-gnu-emacs@prep.ai.mit.edu (mirrored as 57 ;; Usenet newsgroup gnu.emacs.bug). Questions can sent to
52 ;; gnu.emacs.help). Please do not send bugs or questions to my 58 ;; help-gnu-emacs@prep.ai.mit.edu (mirrored as gnu.emacs.help) or
53 ;; personal account. 59 ;; cc-mode-help@python.org. Please do not send bugs or questions to
60 ;; my personal account.
54 61
55 ;; 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
56 ;; the multi-Emacsen support. Emacs 19 (from the FSF), XEmacs 19 63 ;; the multi-Emacsen support. Emacs 19 (from the FSF), XEmacs 19
57 ;; (formerly Lucid Emacs), and GNU Emacs 18 all do things differently 64 ;; (formerly Lucid Emacs), and GNU Emacs 18 all do things differently
58 ;; and there's no way to shut the byte-compiler up at the necessary 65 ;; and there's no way to shut the byte-compiler up at the necessary
68 ;; (makunbound 'c-mode-map) 75 ;; (makunbound 'c-mode-map)
69 ;; (fmakunbound 'c++-mode) 76 ;; (fmakunbound 'c++-mode)
70 ;; (makunbound 'c++-mode-map) 77 ;; (makunbound 'c++-mode-map)
71 ;; (makunbound 'c-style-alist) 78 ;; (makunbound 'c-style-alist)
72 79
73 ;; If your Emacs comes with cc-mode already (and as of 18-Jan-1996, 80 ;; If your Emacs comes with cc-mode already (and as of 5-Jul-1996
74 ;; XEmacs 19.13 and Emacs 19.30 both do), you only need to add the 81 ;; XEmacs 19.14 and Emacs 19.31 both do), you only need to add the
75 ;; following to use the latest version of cc-mode: 82 ;; following to use the latest version of cc-mode:
76 ;; 83 ;;
77 ;; (load "cc-mode") 84 ;; (load "cc-mode")
78 ;; 85 ;;
79 ;; Make sure the new version is earlier on your load-path. 86 ;; Make sure the new version is earlier on your load-path.
105 112
106 ;; 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.
107 ;; Without their patience, testing, insight, code contributions, and 114 ;; Without their patience, testing, insight, code contributions, and
108 ;; encouragement cc-mode.el would be a far inferior package. 115 ;; encouragement cc-mode.el would be a far inferior package.
109 116
110 ;; Anonymous ftp URL: 117 ;; You can get the latest version of cc-mode, including PostScript
118 ;; documentation and separate individual files from:
111 ;; 119 ;;
112 ;; ftp://ftp.python.org/pub/emacs/cc-mode.tar.gz 120 ;; http://www.python.org/ftp/emacs/
121
122 ;; Or if you don't have access to the World Wide Web, through
123 ;; anonymous ftp from:
124 ;;
125 ;; ftp://ftp.python.org/pub/emacs
113 126
114 ;;; Code: 127 ;;; Code:
115 128
116 129
117 ;; user definable variables 130 ;; user definable variables
180 (cpp-macro . -1000) 193 (cpp-macro . -1000)
181 (friend . 0) 194 (friend . 0)
182 (objc-method-intro . -1000) 195 (objc-method-intro . -1000)
183 (objc-method-args-cont . c-lineup-ObjC-method-args) 196 (objc-method-args-cont . c-lineup-ObjC-method-args)
184 (objc-method-call-cont . c-lineup-ObjC-method-call) 197 (objc-method-call-cont . c-lineup-ObjC-method-call)
198 (extern-lang-open . 0)
199 (extern-lang-close . 0)
200 (inextern-lang . +)
185 ) 201 )
186 "*Association list of syntactic element symbols and indentation offsets. 202 "*Association list of syntactic element symbols and indentation offsets.
187 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:
188 204
189 (SYNTACTIC-SYMBOL . OFFSET) 205 (SYNTACTIC-SYMBOL . OFFSET)
243 block-close -- statement block close brace 259 block-close -- statement block close brace
244 brace-list-open -- open brace of an enum or static array list 260 brace-list-open -- open brace of an enum or static array list
245 brace-list-close -- close brace of an enum or static array list 261 brace-list-close -- close brace of an enum or static array list
246 brace-list-intro -- first line in an enum or static array list 262 brace-list-intro -- first line in an enum or static array list
247 brace-list-entry -- subsequent lines in an enum or static array list 263 brace-list-entry -- subsequent lines in an enum or static array list
248 statement -- a C/C++/ObjC statement 264 statement -- a C (or like) statement
249 statement-cont -- a continuation of a C/C++/ObjC statement 265 statement-cont -- a continuation of a C (or like) statement
250 statement-block-intro -- the first line in a new statement block 266 statement-block-intro -- the first line in a new statement block
251 statement-case-intro -- the first line in a case `block' 267 statement-case-intro -- the first line in a case `block'
252 statement-case-open -- the first line in a case block starting with brace 268 statement-case-open -- the first line in a case block starting with brace
253 substatement -- the first line after an if/while/for/do/else 269 substatement -- the first line after an if/while/for/do/else
254 substatement-open -- the brace that opens a substatement block 270 substatement-open -- the brace that opens a substatement block
255 case-label -- a case or default label 271 case-label -- a case or default label
256 access-label -- C++ private/protected/public access label 272 access-label -- C++ private/protected/public access label
257 label -- any non-special C/C++/ObjC label 273 label -- any non-special C (or like) label
258 do-while-closure -- the `while' that ends a do/while construct 274 do-while-closure -- the `while' that ends a do/while construct
259 else-clause -- the `else' of an if/else construct 275 else-clause -- the `else' of an if/else construct
260 comment-intro -- a line containing only a comment introduction 276 comment-intro -- a line containing only a comment introduction
261 arglist-intro -- the first line in an argument list 277 arglist-intro -- the first line in an argument list
262 arglist-cont -- subsequent argument list lines when no 278 arglist-cont -- subsequent argument list lines when no
263 arguments follow on the same line as the 279 arguments follow on the same line as the
264 the arglist opening paren 280 arglist opening paren
265 arglist-cont-nonempty -- subsequent argument list lines when at 281 arglist-cont-nonempty -- subsequent argument list lines when at
266 least one argument follows on the same 282 least one argument follows on the same
267 line as the arglist opening paren 283 line as the arglist opening paren
268 arglist-close -- the solo close paren of an argument list 284 arglist-close -- the solo close paren of an argument list
269 stream-op -- lines continuing a stream operator construct 285 stream-op -- lines continuing a stream operator construct
271 cpp-macro -- the start of a cpp macro 287 cpp-macro -- the start of a cpp macro
272 friend -- a C++ friend declaration 288 friend -- a C++ friend declaration
273 objc-method-intro -- the first line of an Objective-C method definition 289 objc-method-intro -- the first line of an Objective-C method definition
274 objc-method-args-cont -- lines continuing an Objective-C method definition 290 objc-method-args-cont -- lines continuing an Objective-C method definition
275 objc-method-call-cont -- lines continuing an Objective-C method call 291 objc-method-call-cont -- lines continuing an Objective-C method call
292 extern-lang-open -- brace that opens an external language block
293 extern-lang-close -- brace that closes an external language block
294 inextern-lang -- analogous to `inclass' syntactic symbol
276 ") 295 ")
277 296
278 (defvar c-tab-always-indent t 297 (defvar c-tab-always-indent t
279 "*Controls the operation of the TAB key. 298 "*Controls the operation of the TAB key.
280 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,
281 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
282 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
283 If other than nil or t, then tab is inserted only within literals 302 \(see note\). If other than nil or t, then tab is inserted only within
284 -- defined as comments and strings -- and inside preprocessor 303 literals -- defined as comments and strings -- and inside preprocessor
285 directives, but line is always reindented. 304 directives, but line is always reindented.
286 305
287 Note that indentation of lines containing only comments is also 306 Note: The value of `indent-tabs-mode' will determine whether a real
288 controlled by the `c-comment-only-line-offset' variable.") 307 tab character will be inserted, or the equivalent number of space.
308 When inserting a tab, actually the function stored in the variable
309 `c-insert-tab-function' is called.
310
311 Note: indentation of lines containing only comments is also controlled
312 by the `c-comment-only-line-offset' variable.")
313
314 (defvar c-insert-tab-function 'insert-tab
315 "*Function used when inserting a tab for \\[TAB].
316 Only used when `c-tab-always-indent' indicates a `real' tab character
317 should be inserted. Value must be a function taking no arguments.")
289 318
290 (defvar c-comment-only-line-offset 0 319 (defvar c-comment-only-line-offset 0
291 "*Extra offset for line which contains only the start of a comment. 320 "*Extra offset for line which contains only the start of a comment.
292 Can contain an integer or a cons cell of the form: 321 Can contain an integer or a cons cell of the form:
293 322
353 whitespace between colons. Clean up occurs 382 whitespace between colons. Clean up occurs
354 when the second colon is typed.") 383 when the second colon is typed.")
355 384
356 (defvar c-hanging-braces-alist '((brace-list-open) 385 (defvar c-hanging-braces-alist '((brace-list-open)
357 (substatement-open after) 386 (substatement-open after)
358 (block-close . c-snug-do-while)) 387 (block-close . c-snug-do-while)
388 (extern-lang-open after)
389 )
359 "*Controls the insertion of newlines before and after braces. 390 "*Controls the insertion of newlines before and after braces.
360 This variable contains an association list with elements of the 391 This variable contains an association list with elements of the
361 following form: (SYNTACTIC-SYMBOL . ACTION). 392 following form: (SYNTACTIC-SYMBOL . ACTION).
362 393
363 When a brace (either opening or closing) is inserted, the syntactic 394 When a brace (either opening or closing) is inserted, the syntactic
366 If the context is not found, the default is to insert a newline both 397 If the context is not found, the default is to insert a newline both
367 before and after the brace. 398 before and after the brace.
368 399
369 SYNTACTIC-SYMBOL can be any of: defun-open, defun-close, class-open, 400 SYNTACTIC-SYMBOL can be any of: defun-open, defun-close, class-open,
370 class-close, inline-open, inline-close, block-open, block-close, 401 class-close, inline-open, inline-close, block-open, block-close,
371 substatement-open, statement-case-open, brace-list-open, 402 substatement-open, statement-case-open, extern-lang-open,
372 brace-list-close, brace-list-intro, or brace-list-entry. See 403 extern-lang-close, brace-list-open, brace-list-close,
373 `c-offsets-alist' for details. 404 brace-list-intro, or brace-list-entry. See `c-offsets-alist' for
405 details.
374 406
375 ACTION can be either a function symbol or a list containing any 407 ACTION can be either a function symbol or a list containing any
376 combination of the symbols `before' or `after'. If the list is empty, 408 combination of the symbols `before' or `after'. If the list is empty,
377 no newlines are inserted either before or after the brace. 409 no newlines are inserted either before or after the brace.
378 410
420 (defvar c-delete-function 'backward-delete-char-untabify 452 (defvar c-delete-function 'backward-delete-char-untabify
421 "*Function called by `c-electric-delete' when deleting characters.") 453 "*Function called by `c-electric-delete' when deleting characters.")
422 (defvar c-electric-pound-behavior nil 454 (defvar c-electric-pound-behavior nil
423 "*List of behaviors for electric pound insertion. 455 "*List of behaviors for electric pound insertion.
424 Only currently supported behavior is `alignleft'.") 456 Only currently supported behavior is `alignleft'.")
425 457 (defvar c-label-minimum-indentation 1
426 (defvar c-recognize-knr-p nil ; Emacs version uses t 458 "*Minimum indentation for labels and case tags in `gnu' style.")
427 "*If non-nil, `c-mode' and `objc-mode' will recognize K&R constructs.
428 This variable is needed because of ambiguities in C syntax that make
429 fast recognition of K&R constructs problematic, and slow. If you are
430 coding with ANSI prototypes, set this variable to nil to speed up
431 recognition of certain constructs. By setting this variable to nil, I
432 have seen an increase of 20 times under some circumstance.")
433 459
434 (defvar c-progress-interval 5 460 (defvar c-progress-interval 5
435 "*Interval used to update progress status during long re-indentation. 461 "*Interval used to update progress status during long re-indentation.
436 If a number, percentage complete gets updated after each interval of 462 If a number, percentage complete gets updated after each interval of
437 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
438 useful for Emacs 19.") 464 useful for Emacs 19.")
439 465
440 (defvar c-style-alist 466 (defconst c-style-alist
441 '(("gnu" 467 '(("gnu"
442 (c-basic-offset . 2) 468 (c-basic-offset . 2)
443 (c-comment-only-line-offset . (0 . 0)) 469 (c-comment-only-line-offset . (0 . 0))
444 (c-offsets-alist . ((statement-block-intro . +) 470 (c-offsets-alist . ((statement-block-intro . +)
445 (knr-argdecl-intro . 5) 471 (knr-argdecl-intro . 5)
448 (statement-case-open . +) 474 (statement-case-open . +)
449 (statement-cont . +) 475 (statement-cont . +)
450 (arglist-intro . c-lineup-arglist-intro-after-paren) 476 (arglist-intro . c-lineup-arglist-intro-after-paren)
451 (arglist-close . c-lineup-arglist) 477 (arglist-close . c-lineup-arglist)
452 )) 478 ))
479 (c-special-indent-hook . c-gnu-impose-minimum)
453 ) 480 )
454 ("k&r" 481 ("k&r"
455 (c-basic-offset . 5) 482 (c-basic-offset . 5)
456 (c-comment-only-line-offset . 0) 483 (c-comment-only-line-offset . 0)
457 (c-offsets-alist . ((statement-block-intro . +) 484 (c-offsets-alist . ((statement-block-intro . +)
578 "*Hook called by `objc-mode'.") 605 "*Hook called by `objc-mode'.")
579 (defvar java-mode-hook nil 606 (defvar java-mode-hook nil
580 "*Hook called by `java-mode'.") 607 "*Hook called by `java-mode'.")
581 608
582 (defvar c-mode-common-hook nil 609 (defvar c-mode-common-hook nil
583 "*Hook called by `c-mode', `c++-mode', and 'objc-mode' during common init.") 610 "*Hook called by all cc-mode modes for common initializations.")
584 611
585 (defvar c-mode-menu 612 (defvar c-mode-menu
586 '(["Comment Out Region" comment-region (mark)] 613 '(["Comment Out Region" comment-region (mark)]
587 ["Macro Expand Region" c-macro-expand (mark)] 614 ["Macro Expand Region" c-macro-expand (mark)]
588 ["Backslashify" c-backslash-region (mark)] 615 ["Backslashify" c-backslash-region (mark)]
682 ((= major 4) (setq major 'v18)) ;Epoch 4 709 ((= major 4) (setq major 'v18)) ;Epoch 4
683 ((= major 19) (setq major 'v19 ;Emacs 19 710 ((= major 19) (setq major 'v19 ;Emacs 19
684 flavor (if (or (string-match "Lucid" emacs-version) 711 flavor (if (or (string-match "Lucid" emacs-version)
685 (string-match "XEmacs" emacs-version)) 712 (string-match "XEmacs" emacs-version))
686 'XEmacs 'FSF))) 713 'XEmacs 'FSF)))
714 ((= major 20) (setq major 'v20 ;XEmacs 20
715 flavor 'XEmacs))
687 ;; I don't know 716 ;; I don't know
688 (t (error "Cannot recognize major version number: %s" major))) 717 (t (error "Cannot recognize major version number: %s" major)))
689 ;; Regular expression suites... 718 ;; Regular expression suites...
690 (if (and (eq major 'v19) 719 (if (or (eq major 'v20)
691 (or (and (eq flavor 'XEmacs) (>= minor 14)) 720 (and (eq major 'v19)
692 (and (eq flavor 'FSF) (>= minor 30)))) 721 (or (and (eq flavor 'XEmacs) (>= minor 14))
722 (and (eq flavor 'FSF) (>= minor 30)))))
693 (setq re-suite 'new-re)) 723 (setq re-suite 'new-re))
694 ;; XEmacs 19 uses 8-bit modify-syntax-entry flags, as do all 724 ;; XEmacs 19 uses 8-bit modify-syntax-entry flags, as do all
695 ;; patched Emacs 19, Emacs 18, Epoch 4's. Only Emacs 19 uses a 725 ;; patched Emacs 19, Emacs 18, Epoch 4's. Only Emacs 19 uses a
696 ;; 1-bit flag. Let's be as smart as we can about figuring this 726 ;; 1-bit flag. Let's be as smart as we can about figuring this
697 ;; out. 727 ;; out.
698 (if (eq major 'v19) 728 (if (or (eq major 'v20) (eq major 'v19))
699 (let ((table (copy-syntax-table))) 729 (let ((table (copy-syntax-table)))
700 (modify-syntax-entry ?a ". 12345678" table) 730 (modify-syntax-entry ?a ". 12345678" table)
701 (cond 731 (cond
702 ;; XEmacs pre 20 and Emacs pre 19.30 use vectors for syntax tables. 732 ;; XEmacs pre 20 and Emacs pre 19.30 use vectors for syntax tables.
703 ((vectorp table) 733 ((vectorp table)
765 supported list, along with the values for this variable: 795 supported list, along with the values for this variable:
766 796
767 Emacs 18/Epoch 4: (v18 no-dual-comments RS) 797 Emacs 18/Epoch 4: (v18 no-dual-comments RS)
768 Emacs 18/Epoch 4 (patch2): (v18 8-bit RS) 798 Emacs 18/Epoch 4 (patch2): (v18 8-bit RS)
769 XEmacs 19: (v19 8-bit RS) 799 XEmacs 19: (v19 8-bit RS)
800 XEmacs 20: (v20 8-bit RS)
770 Emacs 19: (v19 1-bit RS) 801 Emacs 19: (v19 1-bit RS)
771 802
772 RS is the regular expression suite to use. XEmacs versions after 803 RS is the regular expression suite to use. XEmacs versions after
773 19.13, and Emacs versions after 19.29 use the `new-re' regex suite. 804 19.13, and Emacs versions after 19.29 use the `new-re' regex suite.
774 All other Emacsen use the `old-re' suite.") 805 All other Emacsen use the `old-re' suite.")
844 ;; Lucid Emacs 19.9 defined these two, the second of which was 875 ;; Lucid Emacs 19.9 defined these two, the second of which was
845 ;; commented out... 876 ;; commented out...
846 ;; (define-key c-mode-map "\e{" 'c-insert-braces) 877 ;; (define-key c-mode-map "\e{" 'c-insert-braces)
847 ;; Commented out electric square brackets because nobody likes them. 878 ;; Commented out electric square brackets because nobody likes them.
848 ;; (define-key c-mode-map "[" 'c-insert-brackets) 879 ;; (define-key c-mode-map "[" 'c-insert-brackets)
849 (define-key c-mode-map "\e\C-h" 'c-mark-function) 880 (define-key c-mode-map "\C-c\C-m" 'c-mark-function)
850 (define-key c-mode-map "\e\C-q" 'c-indent-exp) 881 (define-key c-mode-map "\e\C-q" 'c-indent-exp)
851 (define-key c-mode-map "\ea" 'c-beginning-of-statement) 882 (define-key c-mode-map "\ea" 'c-beginning-of-statement)
852 (define-key c-mode-map "\ee" 'c-end-of-statement) 883 (define-key c-mode-map "\ee" 'c-end-of-statement)
853 ;; Emacs 19.30 introduces fill-paragraph-function, but it's not in 884 ;; Emacs 19.30 introduces fill-paragraph-function, but it's not in
854 ;; every version of Emacs cc-mode supports. 885 ;; every version of Emacs cc-mode supports.
892 (defvar c++-mode-map () 923 (defvar c++-mode-map ()
893 "Keymap used in c++-mode buffers.") 924 "Keymap used in c++-mode buffers.")
894 (if c++-mode-map 925 (if c++-mode-map
895 () 926 ()
896 ;; In Emacs 19, it makes more sense to inherit c-mode-map 927 ;; In Emacs 19, it makes more sense to inherit c-mode-map
897 (if (memq 'v19 c-emacs-features) 928 (if (or
929 (memq 'v19 c-emacs-features)
930 (memq 'v20 c-emacs-features))
898 ;; XEmacs and Emacs 19 do this differently 931 ;; XEmacs and Emacs 19 do this differently
899 (cond 932 (cond
900 ;; XEmacs 19.13 933 ;; XEmacs 19.13
901 ((fboundp 'set-keymap-parents) 934 ((fboundp 'set-keymap-parents)
902 (setq c++-mode-map (make-sparse-keymap)) 935 (setq c++-mode-map (make-sparse-keymap))
919 (defvar objc-mode-map () 952 (defvar objc-mode-map ()
920 "Keymap used in objc-mode buffers.") 953 "Keymap used in objc-mode buffers.")
921 (if objc-mode-map 954 (if objc-mode-map
922 () 955 ()
923 ;; In Emacs 19, it makes more sense to inherit c-mode-map 956 ;; In Emacs 19, it makes more sense to inherit c-mode-map
924 (if (memq 'v19 c-emacs-features) 957 (if (or (memq 'v19 c-emacs-features) (memq 'v20 c-emacs-features))
925 ;; XEmacs and Emacs 19 do this differently 958 ;; XEmacs and Emacs 19 do this differently
926 (cond 959 (cond
927 ;; XEmacs 19.13 960 ;; XEmacs 19.13
928 ((fboundp 'set-keymap-parents) 961 ((fboundp 'set-keymap-parents)
929 (setq objc-mode-map (make-sparse-keymap)) 962 (setq objc-mode-map (make-sparse-keymap))
943 (defvar java-mode-map () 976 (defvar java-mode-map ()
944 "Keymap used in java-mode buffers.") 977 "Keymap used in java-mode buffers.")
945 (if java-mode-map 978 (if java-mode-map
946 () 979 ()
947 ;; In Emacs 19, it makes more sense to inherit c-mode-map 980 ;; In Emacs 19, it makes more sense to inherit c-mode-map
948 (if (memq 'v19 c-emacs-features) 981 (if (or (memq 'v19 c-emacs-features) (memq 'v20 c-emacs-features))
949 ;; XEmacs and Emacs 19 do this differently 982 ;; XEmacs and Emacs 19 do this differently
950 (cond 983 (cond
951 ;; XEmacs 19.13 984 ;; XEmacs 19.13
952 ((fboundp 'set-keymap-parents) 985 ((fboundp 'set-keymap-parents)
953 (setq java-mode-map (make-sparse-keymap)) 986 (setq java-mode-map (make-sparse-keymap))
1082 (concat 1115 (concat
1083 ":?[ \t]*\\(virtual[ \t]+\\)?\\(" 1116 ":?[ \t]*\\(virtual[ \t]+\\)?\\("
1084 c-protection-key "[ \t]+\\)" c-symbol-key) 1117 c-protection-key "[ \t]+\\)" c-symbol-key)
1085 "Regexp describing C++ base classes in a derived class definition.") 1118 "Regexp describing C++ base classes in a derived class definition.")
1086 1119
1120 ;; defconst'd instead of defvar'd to override any old pre-loaded versions
1121 (defconst c-recognize-knr-p t
1122 "Non-nil means K&R style argument declarations are valid.")
1123
1087 ;; minor mode variables 1124 ;; minor mode variables
1088 (make-variable-buffer-local 'c-auto-newline) 1125 (make-variable-buffer-local 'c-auto-newline)
1089 (make-variable-buffer-local 'c-hungry-delete-key) 1126 (make-variable-buffer-local 'c-hungry-delete-key)
1090 (make-variable-buffer-local 'c-auto-hungry-string) 1127 (make-variable-buffer-local 'c-auto-hungry-string)
1091 ;; language differences 1128 ;; language differences
1120 "Regexp describing a class inheritance declaration.") 1157 "Regexp describing a class inheritance declaration.")
1121 (defconst c-switch-label-key 1158 (defconst c-switch-label-key
1122 "\\(\\(case[( \t]+\\S .*\\)\\|default[ \t]*\\):" 1159 "\\(\\(case[( \t]+\\S .*\\)\\|default[ \t]*\\):"
1123 "Regexp describing a switch's case or default label") 1160 "Regexp describing a switch's case or default label")
1124 (defconst c-C++-access-key 1161 (defconst c-C++-access-key
1125 (concat c-protection-key ":") 1162 (concat c-protection-key "[ \t]*:")
1126 "Regexp describing C++ access specification keywords.") 1163 "Regexp describing C++ access specification keywords.")
1127 (defconst c-label-key 1164 (defconst c-label-key
1128 (concat c-symbol-key ":\\([^:]\\|$\\)") 1165 (concat c-symbol-key ":\\([^:]\\|$\\)")
1129 "Regexp describing any label.") 1166 "Regexp describing any label.")
1167 (defconst c-C-conditionals '("for" "if" "do" "else" "while" "switch")
1168 "Shared conditional keywords for C-like languages.")
1130 (defconst c-C-conditional-key 1169 (defconst c-C-conditional-key
1131 "\\b\\(for\\|if\\|do\\|else\\|while\\|switch\\)\\b[^_]" 1170 (concat "\\b\\("
1132 "Regexp describing a conditional control.") 1171 (mapconcat 'identity c-C-conditionals "\\|")
1172 "\\)\\b[^_]")
1173 "Regexp describing a conditional control for C.")
1133 (defconst c-C++-conditional-key 1174 (defconst c-C++-conditional-key
1134 "\\b\\(for\\|if\\|do\\|else\\|while\\|switch\\|try\\|catch\\)\\b[^_]" 1175 (concat "\\b\\(" (mapconcat 'identity
1176 (append '("try" "catch") c-C-conditionals) "\\|")
1177 "\\)\\b[^_]")
1135 "Regexp describing a conditional control for C++.") 1178 "Regexp describing a conditional control for C++.")
1136 (defconst c-C++-friend-key 1179 (defconst c-C++-friend-key
1137 "friend[ \t]+\\|template[ \t]*<.+>[ \t]*friend[ \t]+" 1180 "friend[ \t]+\\|template[ \t]*<.+>[ \t]*friend[ \t]+"
1138 "Regexp describing friend declarations in C++ classes.") 1181 "Regexp describing friend declarations in C++ classes.")
1139 (defconst c-C++-comment-start-regexp "//\\|/\\*" 1182 (defconst c-C++-comment-start-regexp "//\\|/\\*"
1159 "\\(\\s *:\\s *" c-symbol-key "\\)?" ;maybe followed by the superclass 1202 "\\(\\s *:\\s *" c-symbol-key "\\)?" ;maybe followed by the superclass
1160 "\\(\\s *<[^>]+>\\)?" ;and maybe the adopted protocols list 1203 "\\(\\s *<[^>]+>\\)?" ;and maybe the adopted protocols list
1161 ) 1204 )
1162 "Regexp describing a class or protocol declaration for Objective-C.") 1205 "Regexp describing a class or protocol declaration for Objective-C.")
1163 1206
1164 (defconst c-Java-conditional-key
1165 "\\b\\(for\\|if\\|do\\|else\\|while\\|switch\\|try\\|catch\\|finally\\|synchronized\\)\\b[^_]"
1166 "Regexp describing a conditional control for Java.")
1167
1168 (defconst c-Java-method-key 1207 (defconst c-Java-method-key
1169 (concat 1208 (concat
1170 "^\\s *[+-]\\s *" 1209 "^\\s *[+-]\\s *"
1171 "\\(([^)]*)\\)?" ; return type 1210 "\\(([^)]*)\\)?" ; return type
1172 ;; \\s- in java syntax table does not include \n 1211 ;; \\s- in java syntax table does not include \n
1182 c-symbol-key ;name of the class 1221 c-symbol-key ;name of the class
1183 "\\(\\s *extends\\s *" c-symbol-key "\\)?" ;maybe followed by superclass 1222 "\\(\\s *extends\\s *" c-symbol-key "\\)?" ;maybe followed by superclass
1184 ;;"\\(\\s *implements *[^{]+{\\)?" ;and maybe the adopted protocols list 1223 ;;"\\(\\s *implements *[^{]+{\\)?" ;and maybe the adopted protocols list
1185 ) 1224 )
1186 "Regexp describing a class or protocol declaration for Java.") 1225 "Regexp describing a class or protocol declaration for Java.")
1226 (defconst c-Java-conditional-key
1227 (concat "\\b\\("
1228 (mapconcat 'identity
1229 (append '("try" "catch" "finally" "synchronized")
1230 c-C-conditionals) "\\|")
1231 "\\)\\b[^_]")
1232 "Regexp describing a conditional control for Java.")
1187 1233
1188 ;; KLUDGE ALERT. We default these variables to their `C' values so 1234 ;; KLUDGE ALERT. We default these variables to their `C' values so
1189 ;; that non-cc-mode-ized modes that depend on c-mode will still work 1235 ;; that non-cc-mode-ized modes that depend on c-mode will still work
1190 ;; out of the box. The most glaring example is awk-mode. There ought 1236 ;; out of the box. The most glaring example is awk-mode. There ought
1191 ;; to be a better way. 1237 ;; to be a better way.
1262 c-conditional-key c-C++-conditional-key 1308 c-conditional-key c-C++-conditional-key
1263 c-comment-start-regexp c-C++-comment-start-regexp 1309 c-comment-start-regexp c-C++-comment-start-regexp
1264 c-class-key c-C++-class-key 1310 c-class-key c-C++-class-key
1265 c-access-key c-C++-access-key 1311 c-access-key c-C++-access-key
1266 c-double-slash-is-comments-p t 1312 c-double-slash-is-comments-p t
1313 c-recognize-knr-p nil
1267 imenu-generic-expression cc-imenu-c++-generic-expression) 1314 imenu-generic-expression cc-imenu-c++-generic-expression)
1268 (run-hooks 'c-mode-common-hook) 1315 (run-hooks 'c-mode-common-hook)
1269 (run-hooks 'c++-mode-hook)) 1316 (run-hooks 'c++-mode-hook))
1270 (setq c-list-of-mode-names (cons "C++" c-list-of-mode-names)) 1317 (setq c-list-of-mode-names (cons "C++" c-list-of-mode-names))
1271 1318
1317 1364
1318 To see what version of cc-mode you are running, enter `\\[c-version]'. 1365 To see what version of cc-mode you are running, enter `\\[c-version]'.
1319 1366
1320 The hook variable `java-mode-hook' is run with no args, if that value 1367 The hook variable `java-mode-hook' is run with no args, if that value
1321 is bound and has a non-nil value. Also the common hook 1368 is bound and has a non-nil value. Also the common hook
1322 `c-mode-common-hook' is run first. 1369 `c-mode-common-hook' is run first. Note that this mode automatically
1370 sets the \"java\" style before calling any hooks so be careful if you
1371 set styles in `c-mode-common-hook'.
1323 1372
1324 Key bindings: 1373 Key bindings:
1325 \\{java-mode-map}" 1374 \\{java-mode-map}"
1326 (interactive) 1375 (interactive)
1327 (kill-all-local-variables) 1376 (kill-all-local-variables)
1338 c-comment-start-regexp c-C++-comment-start-regexp 1387 c-comment-start-regexp c-C++-comment-start-regexp
1339 c-class-key c-Java-class-key 1388 c-class-key c-Java-class-key
1340 c-method-key c-Java-method-key 1389 c-method-key c-Java-method-key
1341 c-double-slash-is-comments-p t 1390 c-double-slash-is-comments-p t
1342 c-baseclass-key nil 1391 c-baseclass-key nil
1392 c-recognize-knr-p nil
1343 c-access-key c-Java-access-key) 1393 c-access-key c-Java-access-key)
1344 (c-set-style "Java") 1394 (c-set-style "java")
1345 (run-hooks 'c-mode-common-hook) 1395 (run-hooks 'c-mode-common-hook)
1346 (run-hooks 'java-mode-hook)) 1396 (run-hooks 'java-mode-hook))
1347 (setq c-list-of-mode-names (cons "Java" c-list-of-mode-names)) 1397 (setq c-list-of-mode-names (cons "Java" c-list-of-mode-names))
1398
1399 (defun c-use-java-style ()
1400 "Institutes `java' indentation style.
1401 For use with the variable `java-mode-hook'."
1402 (c-set-style "java"))
1348 1403
1349 (defun c-common-init () 1404 (defun c-common-init ()
1350 ;; Common initializations for c++-mode and c-mode. 1405 ;; Common initializations for c++-mode and c-mode.
1351 ;; make local variables 1406 ;; make local variables
1352 (make-local-variable 'paragraph-start) 1407 (make-local-variable 'paragraph-start)
1636 (setq c-auto-hungry-string 1691 (setq c-auto-hungry-string
1637 (if c-auto-newline 1692 (if c-auto-newline
1638 (if c-hungry-delete-key "/ah" "/a") 1693 (if c-hungry-delete-key "/ah" "/a")
1639 (if c-hungry-delete-key "/h" nil))) 1694 (if c-hungry-delete-key "/h" nil)))
1640 ;; updates the modeline for all Emacsen 1695 ;; updates the modeline for all Emacsen
1641 (if (memq 'v19 c-emacs-features) 1696 (if (or (memq 'v19 c-emacs-features) (memq 'v20 c-emacs-features))
1642 (force-mode-line-update) 1697 (force-mode-line-update)
1643 (set-buffer-modified-p (buffer-modified-p)))) 1698 (set-buffer-modified-p (buffer-modified-p))))
1644 1699
1645 (defun c-calculate-state (arg prevstate) 1700 (defun c-calculate-state (arg prevstate)
1646 ;; Calculate the new state of PREVSTATE, t or nil, based on arg. If 1701 ;; Calculate the new state of PREVSTATE, t or nil, based on arg. If
1755 (not (looking-at "[ \t]*$"))) 1810 (not (looking-at "[ \t]*$")))
1756 (c-insert-special-chars arg) 1811 (c-insert-special-chars arg)
1757 (let* ((syms '(class-open class-close defun-open defun-close 1812 (let* ((syms '(class-open class-close defun-open defun-close
1758 inline-open inline-close brace-list-open brace-list-close 1813 inline-open inline-close brace-list-open brace-list-close
1759 brace-list-intro brace-list-entry block-open block-close 1814 brace-list-intro brace-list-entry block-open block-close
1760 substatement-open statement-case-open)) 1815 substatement-open statement-case-open
1816 extern-lang-open extern-lang-close))
1761 ;; we want to inhibit blinking the paren since this will 1817 ;; we want to inhibit blinking the paren since this will
1762 ;; be most disruptive. we'll blink it ourselves later on 1818 ;; be most disruptive. we'll blink it ourselves later on
1763 (old-blink-paren (if (boundp 'blink-paren-function) 1819 (old-blink-paren (if (boundp 'blink-paren-function)
1764 blink-paren-function 1820 blink-paren-function
1765 blink-paren-hook)) 1821 blink-paren-hook))
1786 (or (c-lookup-lists syms syntax c-hanging-braces-alist) 1842 (or (c-lookup-lists syms syntax c-hanging-braces-alist)
1787 '(ignore before after))))) 1843 '(ignore before after)))))
1788 ;; If syntax is a function symbol, then call it using the 1844 ;; If syntax is a function symbol, then call it using the
1789 ;; defined semantics. 1845 ;; defined semantics.
1790 (if (and (not (consp (cdr newlines))) 1846 (if (and (not (consp (cdr newlines)))
1791 (fboundp (cdr newlines))) 1847 (c-functionp (cdr newlines)))
1792 (let ((c-syntactic-context syntax)) 1848 (let ((c-syntactic-context syntax))
1793 (setq newlines 1849 (setq newlines
1794 (funcall (cdr newlines) (car newlines) insertion-point)))) 1850 (funcall (cdr newlines) (car newlines) insertion-point))))
1795 ;; does a newline go before the open brace? 1851 ;; does a newline go before the open brace?
1796 (if (memq 'before newlines) 1852 (if (memq 'before newlines)
2150 (defstr (format "(default %s): " oldoff)) 2206 (defstr (format "(default %s): " oldoff))
2151 (errmsg (concat "Offset must be int, func, var, " 2207 (errmsg (concat "Offset must be int, func, var, "
2152 "or in [+,-,++,--,*,/] " 2208 "or in [+,-,++,--,*,/] "
2153 defstr)) 2209 defstr))
2154 (prompt (concat "Offset " defstr)) 2210 (prompt (concat "Offset " defstr))
2155 offset input interned) 2211 offset input interned raw)
2156 (while (not offset) 2212 (while (not offset)
2157 (setq input (read-string prompt) 2213 (setq input (read-string prompt)
2158 offset (cond ((string-equal "" input) oldoff) ; default 2214 offset (cond ((string-equal "" input) oldoff) ; default
2159 ((string-equal "+" input) '+) 2215 ((string-equal "+" input) '+)
2160 ((string-equal "-" input) '-) 2216 ((string-equal "-" input) '-)
2162 ((string-equal "--" input) '--) 2218 ((string-equal "--" input) '--)
2163 ((string-equal "*" input) '*) 2219 ((string-equal "*" input) '*)
2164 ((string-equal "/" input) '/) 2220 ((string-equal "/" input) '/)
2165 ((string-match "^-?[0-9]+$" input) 2221 ((string-match "^-?[0-9]+$" input)
2166 (string-to-int input)) 2222 (string-to-int input))
2223 ;; a symbol with a function binding
2167 ((fboundp (setq interned (intern input))) 2224 ((fboundp (setq interned (intern input)))
2168 interned) 2225 interned)
2226 ;; a lambda function
2227 ((condition-case nil
2228 (c-functionp (setq raw (read input)))
2229 (error nil))
2230 raw)
2231 ;; a symbol with variable binding
2169 ((boundp interned) interned) 2232 ((boundp interned) interned)
2170 ;; error, but don't signal one, keep trying 2233 ;; error, but don't signal one, keep trying
2171 ;; to read an input value 2234 ;; to read an input value
2172 (t (ding) 2235 (t (ding)
2173 (setq prompt errmsg) 2236 (setq prompt errmsg)
2195 ;; on the syntactic analysis list for the current 2258 ;; on the syntactic analysis list for the current
2196 ;; line 2259 ;; line
2197 (let* ((syntax (c-guess-basic-syntax)) 2260 (let* ((syntax (c-guess-basic-syntax))
2198 (len (length syntax)) 2261 (len (length syntax))
2199 (ic (format "%s" (car (nth (1- len) syntax))))) 2262 (ic (format "%s" (car (nth (1- len) syntax)))))
2200 (if (memq 'v19 c-emacs-features) 2263 (if (or (memq 'v19 c-emacs-features)
2264 (memq 'v20 c-emacs-features))
2201 (cons ic 0) 2265 (cons ic 0)
2202 ic)) 2266 ic))
2203 ))) 2267 )))
2204 (offset (c-read-offset langelem))) 2268 (offset (c-read-offset langelem)))
2205 (list langelem offset current-prefix-arg))) 2269 (list langelem offset current-prefix-arg)))
2209 (eq offset '++) 2273 (eq offset '++)
2210 (eq offset '--) 2274 (eq offset '--)
2211 (eq offset '*) 2275 (eq offset '*)
2212 (eq offset '/) 2276 (eq offset '/)
2213 (integerp offset) 2277 (integerp offset)
2214 (fboundp offset) 2278 (c-functionp offset)
2215 (boundp offset) 2279 (boundp offset)
2216 (error "Offset must be int, func, var, or in [+,-,++,--,*,/]: %s" 2280 (error "Offset must be int, func, var, or in [+,-,++,--,*,/]: %s"
2217 offset)) 2281 offset))
2218 (let ((entry (assq symbol c-offsets-alist))) 2282 (let ((entry (assq symbol c-offsets-alist)))
2219 (if entry 2283 (if entry
2228 (mapcar 2292 (mapcar
2229 (function 2293 (function
2230 (lambda (conscell) 2294 (lambda (conscell)
2231 (let ((attr (car conscell)) 2295 (let ((attr (car conscell))
2232 (val (cdr conscell))) 2296 (val (cdr conscell)))
2233 ;; KLUDGE ALERT: special case for c-offsets-alist 2297 (cond
2234 (if (not (eq attr 'c-offsets-alist)) 2298 ((eq attr 'c-offsets-alist)
2235 (set attr val)
2236 (mapcar 2299 (mapcar
2237 (function 2300 (function
2238 (lambda (langentry) 2301 (lambda (langentry)
2239 (let ((langelem (car langentry)) 2302 (let ((langelem (car langentry))
2240 (offset (cdr langentry))) 2303 (offset (cdr langentry)))
2241 (c-set-offset langelem offset) 2304 (c-set-offset langelem offset)
2242 ))) 2305 )))
2243 val)) 2306 val))
2307 ((eq attr 'c-special-indent-hook)
2308 (if (listp val)
2309 (while val
2310 (add-hook 'c-special-indent-hook (car val))
2311 (setq val (cdr val)))
2312 (add-hook 'c-special-indent-hook val)))
2313 (t (set attr val)))
2244 ))) 2314 )))
2245 stylevars)) 2315 stylevars))
2246 2316
2247 (defun c-set-style (stylename) 2317 (defun c-set-style (stylename)
2248 "Set cc-mode variables to use one of several different indentation styles. 2318 "Set cc-mode variables to use one of several different indentation styles.
2252 (interactive (list (let ((completion-ignore-case t) 2322 (interactive (list (let ((completion-ignore-case t)
2253 (prompt (format "Which %s indentation style? " 2323 (prompt (format "Which %s indentation style? "
2254 mode-name))) 2324 mode-name)))
2255 (completing-read prompt c-style-alist nil t)))) 2325 (completing-read prompt c-style-alist nil t))))
2256 (let ((vars (cdr (or (assoc (downcase stylename) c-style-alist) 2326 (let ((vars (cdr (or (assoc (downcase stylename) c-style-alist)
2257 ;; backwards compatibility
2258 (assoc (upcase stylename) c-style-alist) 2327 (assoc (upcase stylename) c-style-alist)
2328 (assoc stylename c-style-alist)
2259 ))) 2329 )))
2260 (default (cdr (assoc "cc-mode" c-style-alist)))) 2330 (default (cdr (assoc "cc-mode" c-style-alist))))
2261 (or vars (error "Invalid indentation style `%s'" stylename)) 2331 (or vars (error "Invalid indentation style `%s'" stylename))
2262 (or default (error "No `cc-mode' style found!")) 2332 (or default (error "No `cc-mode' style found!"))
2263 ;; first reset the style to `cc-mode' to give every style a common 2333 ;; first reset the style to `cc-mode' to give every style a common
2321 (paragraph-separate (concat paragraph-separate re1))) 2391 (paragraph-separate (concat paragraph-separate re1)))
2322 (save-excursion 2392 (save-excursion
2323 (beginning-of-line) 2393 (beginning-of-line)
2324 ;; Move up to first line of this comment. 2394 ;; Move up to first line of this comment.
2325 (while (and (not (bobp)) 2395 (while (and (not (bobp))
2326 (looking-at "[ \t]*//")) 2396 (looking-at "[ \t]*//[ \t]*[^ \t\n]"))
2327 (forward-line -1)) 2397 (forward-line -1))
2328 (if (not (looking-at ".*//")) 2398 (if (not (looking-at ".*//[ \t]*[^ \t\n]"))
2329 (forward-line 1)) 2399 (forward-line 1))
2330 ;; Find the comment start in this line. 2400 ;; Find the comment start in this line.
2331 (re-search-forward "[ \t]*//[ \t]*") 2401 (re-search-forward "[ \t]*//[ \t]*")
2332 ;; Set the fill-prefix to be what all lines except the first 2402 ;; Set the fill-prefix to be what all lines except the first
2333 ;; should start with. 2403 ;; should start with.
2455 (let ((fill-column (+ fill-column 9999))) 2525 (let ((fill-column (+ fill-column 9999)))
2456 (forward-line -1) 2526 (forward-line -1)
2457 (fill-region-as-paragraph (point) (point-max)))))) 2527 (fill-region-as-paragraph (point) (point-max))))))
2458 t))))) 2528 t)))))
2459 2529
2530
2460 ;; better movement routines for ThisStyleOfVariablesCommonInCPlusPlus 2531 ;; better movement routines for ThisStyleOfVariablesCommonInCPlusPlus
2461 ;; originally contributed by Terry_Glanfield.Southern@rxuk.xerox.com 2532 ;; originally contributed by Terry_Glanfield.Southern@rxuk.xerox.com
2462 (defun c-forward-into-nomenclature (&optional arg) 2533 (defun c-forward-into-nomenclature (&optional arg)
2463 "Move forward to end of a nomenclature section or word. 2534 "Move forward to end of a nomenclature section or word.
2464 With arg, to it arg times." 2535 With arg, to it arg times."
2543 (interactive (list (prefix-numeric-value current-prefix-arg) 2614 (interactive (list (prefix-numeric-value current-prefix-arg)
2544 nil t)) 2615 nil t))
2545 (c-beginning-of-statement (- (or count 1)) lim sentence-flag) 2616 (c-beginning-of-statement (- (or count 1)) lim sentence-flag)
2546 (c-keep-region-active)) 2617 (c-keep-region-active))
2547 2618
2619 ;; WARNING: Be *exceptionally* careful about modifications to this
2620 ;; function! Much of cc-mode depends on this Doing The Right Thing.
2621 ;; If you break it you will be sorry.
2548 (defun c-beginning-of-statement-1 (&optional lim) 2622 (defun c-beginning-of-statement-1 (&optional lim)
2549 ;; move to the start of the current statement, or the previous 2623 ;; move to the start of the current statement, or the previous
2550 ;; statement if already at the beginning of one. 2624 ;; statement if already at the beginning of one.
2551 (let ((firstp t) 2625 (let ((firstp t)
2552 (substmt-p t) 2626 (substmt-p t)
2828 ;; otherwise insert a tab 2902 ;; otherwise insert a tab
2829 ((not c-tab-always-indent) 2903 ((not c-tab-always-indent)
2830 (if (save-excursion 2904 (if (save-excursion
2831 (skip-chars-backward " \t") 2905 (skip-chars-backward " \t")
2832 (not (bolp))) 2906 (not (bolp)))
2833 (insert-tab) 2907 (funcall c-insert-tab-function)
2834 (c-indent-line))) 2908 (c-indent-line)))
2835 ;; CASE 2: just indent the line 2909 ;; CASE 2: just indent the line
2836 ((eq c-tab-always-indent t) 2910 ((eq c-tab-always-indent t)
2837 (c-indent-line)) 2911 (c-indent-line))
2838 ;; CASE 3: if in a literal, insert a tab, but always indent the 2912 ;; CASE 3: if in a literal, insert a tab, but always indent the
2839 ;; line 2913 ;; line
2840 (t 2914 (t
2841 (if (c-in-literal bod) 2915 (if (c-in-literal bod)
2842 (insert-tab)) 2916 (funcall c-insert-tab-function))
2843 (c-indent-line) 2917 (c-indent-line)
2844 ))))) 2918 )))))
2845 2919
2846 (defun c-indent-exp (&optional shutup-p) 2920 (defun c-indent-exp (&optional shutup-p)
2847 "Indent each line in balanced expression following point. 2921 "Indent each line in balanced expression following point.
3449 t))) 3523 t)))
3450 3524
3451 (defun c-skip-conditional () 3525 (defun c-skip-conditional ()
3452 ;; skip forward over conditional at point, including any predicate 3526 ;; skip forward over conditional at point, including any predicate
3453 ;; statements in parentheses. No error checking is performed. 3527 ;; statements in parentheses. No error checking is performed.
3454 (forward-sexp 3528 (forward-sexp (cond
3455 ;; else if() 3529 ;; else if()
3456 (if (looking-at "\\<else\\>[ \t]+\\<if\\>") 3530 ((looking-at "\\<else\\>[ \t]+\\<if\\>") 3)
3457 3 3531 ;; do, else, try, finally
3458 ;; do and else aren't followed by parens 3532 ((looking-at "\\<\\(do\\|else\\|try\\|finally\\)\\>") 1)
3459 (if (looking-at "\\<\\(do\\|else\\)\\>") 3533 ;; for, if, while, switch, catch, synchronized
3460 1 2)))) 3534 (t 2))))
3461 3535
3462 (defun c-skip-case-statement-forward (state &optional lim) 3536 (defun c-skip-case-statement-forward (state &optional lim)
3463 ;; skip forward over case/default bodies, with optional maximal 3537 ;; skip forward over case/default bodies, with optional maximal
3464 ;; limit. if no next case body is found, nil is returned and point 3538 ;; limit. if no next case body is found, nil is returned and point
3465 ;; is not moved 3539 ;; is not moved
3534 ;; search-end and see if we can find a class key. watch for 3608 ;; search-end and see if we can find a class key. watch for
3535 ;; class like strings in literals 3609 ;; class like strings in literals
3536 (save-excursion 3610 (save-excursion
3537 (save-restriction 3611 (save-restriction
3538 (goto-char search-start) 3612 (goto-char search-start)
3539 (let (foundp class match-end) 3613 (let ((search-key (concat c-class-key "\\|extern[^_]"))
3614 foundp class match-end)
3540 (while (and (not foundp) 3615 (while (and (not foundp)
3541 (progn 3616 (progn
3542 (c-forward-syntactic-ws) 3617 (c-forward-syntactic-ws)
3543 (> search-end (point))) 3618 (> search-end (point)))
3544 (re-search-forward c-class-key search-end t)) 3619 (re-search-forward search-key search-end t))
3545 (setq class (match-beginning 0) 3620 (setq class (match-beginning 0)
3546 match-end (match-end 0)) 3621 match-end (match-end 0))
3547 (if (c-in-literal search-start) 3622 (if (c-in-literal search-start)
3548 nil ; its in a comment or string, ignore 3623 nil ; its in a comment or string, ignore
3549 (goto-char class) 3624 (goto-char class)
3708 (state fullstate) 3783 (state fullstate)
3709 (in-method-intro-p (and c-method-key 3784 (in-method-intro-p (and c-method-key
3710 (looking-at c-method-key))) 3785 (looking-at c-method-key)))
3711 literal containing-sexp char-before-ip char-after-ip lim 3786 literal containing-sexp char-before-ip char-after-ip lim
3712 syntax placeholder c-in-literal-cache inswitch-p 3787 syntax placeholder c-in-literal-cache inswitch-p
3713 ;; narrow out any enclosing class 3788 ;; narrow out any enclosing class or extern "C" block
3714 (inclass-p (c-narrow-out-enclosing-class state indent-point)) 3789 (inclass-p (c-narrow-out-enclosing-class state indent-point))
3790 (inextern-p (and inclass-p
3791 (save-excursion
3792 (save-restriction
3793 (widen)
3794 (goto-char (aref inclass-p 0))
3795 (looking-at "extern[^_]")))))
3715 ) 3796 )
3716 3797
3717 ;; get the buffer position of the most nested opening brace, 3798 ;; get the buffer position of the most nested opening brace,
3718 ;; if there is one, and it hasn't been narrowed out 3799 ;; if there is one, and it hasn't been narrowed out
3719 (save-excursion 3800 (save-excursion
3780 (cond 3861 (cond
3781 ;; CASE 5A: we are looking at a defun, class, or 3862 ;; CASE 5A: we are looking at a defun, class, or
3782 ;; inline-inclass method opening brace 3863 ;; inline-inclass method opening brace
3783 ((= char-after-ip ?{) 3864 ((= char-after-ip ?{)
3784 (cond 3865 (cond
3785 ;; CASE 5A.1: we are looking at a class opening brace 3866 ;; CASE 5A.1: extern declaration
3867 ((save-excursion
3868 (goto-char indent-point)
3869 (skip-chars-forward " \t")
3870 (and (c-safe (progn (backward-sexp 2) t))
3871 (looking-at "extern[^_]")
3872 (progn
3873 (setq placeholder (point))
3874 (forward-sexp 1)
3875 (c-forward-syntactic-ws)
3876 (= (following-char) ?\"))))
3877 (goto-char placeholder)
3878 (c-add-syntax 'extern-lang-open (c-point 'boi)))
3879 ;; CASE 5A.2: we are looking at a class opening brace
3786 ((save-excursion 3880 ((save-excursion
3787 (goto-char indent-point) 3881 (goto-char indent-point)
3788 (skip-chars-forward " \t{") 3882 (skip-chars-forward " \t{")
3789 ;; TBD: watch out! there could be a bogus 3883 ;; TBD: watch out! there could be a bogus
3790 ;; c-state-cache in place when we get here. we have 3884 ;; c-state-cache in place when we get here. we have
3801 ))) 3895 )))
3802 (and decl 3896 (and decl
3803 (setq placeholder (aref decl 0))) 3897 (setq placeholder (aref decl 0)))
3804 )) 3898 ))
3805 (c-add-syntax 'class-open placeholder)) 3899 (c-add-syntax 'class-open placeholder))
3806 ;; CASE 5A.2: brace list open 3900 ;; CASE 5A.3: brace list open
3807 ((save-excursion 3901 ((save-excursion
3808 (c-beginning-of-statement-1 lim) 3902 (c-beginning-of-statement-1 lim)
3809 ;; c-b-o-s could have left us at point-min 3903 ;; c-b-o-s could have left us at point-min
3810 (and (bobp) 3904 (and (bobp)
3811 (c-forward-syntactic-ws indent-point)) 3905 (c-forward-syntactic-ws indent-point))
3815 (save-excursion 3909 (save-excursion
3816 (skip-chars-forward "^;(" indent-point) 3910 (skip-chars-forward "^;(" indent-point)
3817 (not (memq (following-char) '(?\; ?\())) 3911 (not (memq (following-char) '(?\; ?\()))
3818 ))) 3912 )))
3819 (c-add-syntax 'brace-list-open placeholder)) 3913 (c-add-syntax 'brace-list-open placeholder))
3820 ;; CASE 5A.3: inline defun open 3914 ;; CASE 5A.4: inline defun open
3821 (inclass-p 3915 ((and inclass-p (not inextern-p))
3822 (c-add-syntax 'inline-open (aref inclass-p 0))) 3916 (c-add-syntax 'inline-open)
3823 ;; CASE 5A.4: ordinary defun open 3917 (c-add-syntax 'inclass (aref inclass-p 0)))
3918 ;; CASE 5A.5: ordinary defun open
3824 (t 3919 (t
3825 (goto-char placeholder) 3920 (goto-char placeholder)
3826 (c-add-syntax 'defun-open (c-point 'bol)) 3921 (c-add-syntax 'defun-open (c-point 'bol))
3827 ))) 3922 )))
3828 ;; CASE 5B: first K&R arg decl or member init 3923 ;; CASE 5B: first K&R arg decl or member init
3953 ((and inclass-p 4048 ((and inclass-p
3954 c-access-key 4049 c-access-key
3955 (looking-at c-access-key)) 4050 (looking-at c-access-key))
3956 (c-add-syntax 'access-label (c-point 'bonl)) 4051 (c-add-syntax 'access-label (c-point 'bonl))
3957 (c-add-syntax 'inclass (aref inclass-p 0))) 4052 (c-add-syntax 'inclass (aref inclass-p 0)))
3958 ;; CASE 5F: we are looking at the brace which closes the 4053 ;; CASE 5F: extern-lang-close?
4054 ((and inextern-p
4055 (= char-after-ip ?}))
4056 (c-add-syntax 'extern-lang-close (aref inclass-p 1)))
4057 ;; CASE 5G: we are looking at the brace which closes the
3959 ;; enclosing nested class decl 4058 ;; enclosing nested class decl
3960 ((and inclass-p 4059 ((and inclass-p
3961 (= char-after-ip ?}) 4060 (= char-after-ip ?})
3962 (save-excursion 4061 (save-excursion
3963 (save-restriction 4062 (save-restriction
3971 )))) 4070 ))))
3972 (save-restriction 4071 (save-restriction
3973 (widen) 4072 (widen)
3974 (goto-char (aref inclass-p 0)) 4073 (goto-char (aref inclass-p 0))
3975 (c-add-syntax 'class-close (c-point 'boi)))) 4074 (c-add-syntax 'class-close (c-point 'boi))))
3976 ;; CASE 5G: we could be looking at subsequent knr-argdecls 4075 ;; CASE 5H: we could be looking at subsequent knr-argdecls
3977 ((and c-recognize-knr-p 4076 ((and c-recognize-knr-p
3978 (save-excursion 4077 ;; here we essentially use the hack that is used in
3979 (c-backward-syntactic-ws lim) 4078 ;; Emacs' c-mode.el to limit how far back we should
3980 (while (memq (preceding-char) '(?\; ?,)) 4079 ;; look. The assumption is made that argdecls are
3981 (beginning-of-line) 4080 ;; indented at least one space and that function
3982 (setq placeholder (point)) 4081 ;; headers are not indented.
3983 (c-backward-syntactic-ws lim)) 4082 (let ((limit (save-excursion
3984 (and (= (preceding-char) ?\)) 4083 (re-search-backward "^[^ \^L\t\n#]" nil 'move)
3985 (or (not c-method-key) 4084 (point))))
3986 (progn 4085 (save-excursion
3987 (forward-sexp -1) 4086 (c-backward-syntactic-ws limit)
3988 (forward-char -1) 4087 (while (and (memq (preceding-char) '(?\; ?,))
3989 (c-backward-syntactic-ws) 4088 (> (point) limit))
3990 (not (or (= (preceding-char) ?-) 4089 (beginning-of-line)
3991 (= (preceding-char) ?+) 4090 (setq placeholder (point))
3992 ;; or a class category 4091 (c-backward-syntactic-ws limit))
3993 (progn 4092 (and (= (preceding-char) ?\))
3994 (forward-sexp -2) 4093 (or (not c-method-key)
3995 (looking-at c-class-key)) 4094 (progn
3996 ))))) 4095 (forward-sexp -1)
3997 ) 4096 (forward-char -1)
4097 (c-backward-syntactic-ws)
4098 (not (or (= (preceding-char) ?-)
4099 (= (preceding-char) ?+)
4100 ;; or a class category
4101 (progn
4102 (forward-sexp -2)
4103 (looking-at c-class-key))
4104 )))))
4105 ))
3998 (save-excursion 4106 (save-excursion
3999 (c-beginning-of-statement-1) 4107 (c-beginning-of-statement-1)
4000 (not (looking-at "typedef[ \t\n]+")))) 4108 (not (looking-at "typedef[ \t\n]+"))))
4001 (goto-char placeholder) 4109 (goto-char placeholder)
4002 (c-add-syntax 'knr-argdecl (c-point 'boi))) 4110 (c-add-syntax 'knr-argdecl (c-point 'boi)))
4003 ;; CASE 5H: we are at the topmost level, make sure we skip 4111 ;; CASE 5I: we are at the topmost level, make sure we skip
4004 ;; back past any access specifiers 4112 ;; back past any access specifiers
4005 ((progn 4113 ((progn
4006 (c-backward-syntactic-ws lim) 4114 (c-backward-syntactic-ws lim)
4007 (while (and inclass-p 4115 (while (and inclass-p
4008 c-access-key 4116 c-access-key
4020 (widen) 4128 (widen)
4021 (c-add-syntax 'topmost-intro (c-point 'bol)) 4129 (c-add-syntax 'topmost-intro (c-point 'bol))
4022 (if inclass-p 4130 (if inclass-p
4023 (progn 4131 (progn
4024 (goto-char (aref inclass-p 1)) 4132 (goto-char (aref inclass-p 1))
4025 (c-add-syntax 'inclass (c-point 'boi)))))) 4133 (if inextern-p
4026 ;; CASE 5I: we are at an ObjC or Java method definition 4134 (c-add-syntax 'inextern-lang)
4135 (c-add-syntax 'inclass (c-point 'boi)))))
4136 ))
4137 ;; CASE 5J: we are at an ObjC or Java method definition
4027 ;; continuation line. 4138 ;; continuation line.
4028 ((and c-method-key 4139 ((and c-method-key
4029 (progn 4140 (progn
4030 (c-beginning-of-statement-1 lim) 4141 (c-beginning-of-statement-1 lim)
4031 (beginning-of-line) 4142 (beginning-of-line)
4032 (looking-at c-method-key))) 4143 (looking-at c-method-key)))
4033 (c-add-syntax 'objc-method-args-cont (point))) 4144 (c-add-syntax 'objc-method-args-cont (point)))
4034 ;; CASE 5J: we are at a topmost continuation line 4145 ;; CASE 5K: we are at a topmost continuation line
4035 (t 4146 (t
4036 (c-beginning-of-statement-1 lim) 4147 (c-beginning-of-statement-1 lim)
4037 (c-forward-syntactic-ws) 4148 (c-forward-syntactic-ws)
4038 (c-add-syntax 'topmost-intro-cont (c-point 'boi))) 4149 (c-add-syntax 'topmost-intro-cont (c-point 'boi)))
4039 )) ; end CASE 5 4150 )) ; end CASE 5
4278 (if (/= (point) (c-point 'boi)) 4389 (if (/= (point) (c-point 'boi))
4279 (c-beginning-of-statement-1 lim)) 4390 (c-beginning-of-statement-1 lim))
4280 (c-point 'boi)))) 4391 (c-point 'boi))))
4281 (cond 4392 (cond
4282 ;; CASE 14A: does this close an inline? 4393 ;; CASE 14A: does this close an inline?
4283 ((progn 4394 ((let ((inclass-p (progn
4284 (goto-char containing-sexp) 4395 (goto-char containing-sexp)
4285 (c-search-uplist-for-classkey state)) 4396 (c-search-uplist-for-classkey state))))
4397 ;; inextern-p in higher level let*
4398 (setq inextern-p (and inclass-p
4399 (progn
4400 (goto-char (aref inclass-p 0))
4401 (looking-at "extern[^_]"))))
4402 (and inclass-p (not inextern-p)))
4286 (c-add-syntax 'inline-close relpos)) 4403 (c-add-syntax 'inline-close relpos))
4287 ;; CASE 14B: if there an enclosing brace that hasn't 4404 ;; CASE 14B: if there an enclosing brace that hasn't
4288 ;; been narrowed out by a class, then this is a 4405 ;; been narrowed out by a class, then this is a
4289 ;; block-close 4406 ;; block-close
4290 ((c-most-enclosing-brace state) 4407 ((and (not inextern-p)
4408 (c-most-enclosing-brace state))
4291 (c-add-syntax 'block-close relpos)) 4409 (c-add-syntax 'block-close relpos))
4292 ;; CASE 14C: find out whether we're closing a top-level 4410 ;; CASE 14C: find out whether we're closing a top-level
4293 ;; class or a defun 4411 ;; class or a defun
4294 (t 4412 (t
4295 (save-restriction 4413 (save-restriction
4428 ((not match) 4546 ((not match)
4429 (if c-strict-syntax-p 4547 (if c-strict-syntax-p
4430 (error "don't know how to indent a %s" symbol) 4548 (error "don't know how to indent a %s" symbol)
4431 (setq offset 0 4549 (setq offset 0
4432 relpos 0))) 4550 relpos 0)))
4433 ((eq offset '+) (setq offset c-basic-offset)) 4551 ((eq offset '+) (setq offset c-basic-offset))
4434 ((eq offset '-) (setq offset (- c-basic-offset))) 4552 ((eq offset '-) (setq offset (- c-basic-offset)))
4435 ((eq offset '++) (setq offset (* 2 c-basic-offset))) 4553 ((eq offset '++) (setq offset (* 2 c-basic-offset)))
4436 ((eq offset '--) (setq offset (* 2 (- c-basic-offset)))) 4554 ((eq offset '--) (setq offset (* 2 (- c-basic-offset))))
4437 ((eq offset '*) (setq offset (/ c-basic-offset 2))) 4555 ((eq offset '*) (setq offset (/ c-basic-offset 2)))
4438 ((eq offset '/) (setq offset (/ (- c-basic-offset) 2))) 4556 ((eq offset '/) (setq offset (/ (- c-basic-offset) 2)))
4439 ((and (not (numberp offset)) 4557 ((c-functionp offset) (setq offset (funcall offset langelem)))
4440 (fboundp offset)) 4558 ((not (numberp offset)) (setq offset (symbol-value offset)))
4441 (setq offset (funcall offset langelem)))
4442 ((not (numberp offset))
4443 (setq offset (eval offset)))
4444 ) 4559 )
4445 (+ (if (and relpos 4560 (+ (if (and relpos
4446 (< relpos (c-point 'bol))) 4561 (< relpos (c-point 'bol)))
4447 (save-excursion 4562 (save-excursion
4448 (goto-char relpos) 4563 (goto-char relpos)
4473 (goto-char (- (point-max) pos))) 4588 (goto-char (- (point-max) pos)))
4474 ) 4589 )
4475 (run-hooks 'c-special-indent-hook) 4590 (run-hooks 'c-special-indent-hook)
4476 shift-amt)) 4591 shift-amt))
4477 4592
4478 (defun c-show-syntactic-information () 4593 (defun c-show-syntactic-information (arg)
4479 "Show syntactic information for current line." 4594 "Show syntactic information for current line.
4480 (interactive) 4595 With universal argument, inserts the analysis as a comment on that line."
4481 (message "syntactic analysis: %s" (c-guess-basic-syntax)) 4596 (interactive "P")
4597 (let ((syntax (c-guess-basic-syntax)))
4598 (if (not (consp arg))
4599 (message "syntactic analysis: %s" (c-guess-basic-syntax))
4600 (indent-for-comment)
4601 (insert (format "%s" syntax))
4602 ))
4482 (c-keep-region-active)) 4603 (c-keep-region-active))
4483 4604
4484 4605
4485 ;; Standard indentation line-ups 4606 ;; Standard indentation line-ups
4486 (defun c-lineup-arglist (langelem) 4607 (defun c-lineup-arglist (langelem)
4537 (backward-up-list 1) 4658 (backward-up-list 1)
4538 (skip-chars-forward " \t" (c-point 'eol)) 4659 (skip-chars-forward " \t" (c-point 'eol))
4539 (current-column)))) 4660 (current-column))))
4540 (- ce-curcol cs-curcol -1)))) 4661 (- ce-curcol cs-curcol -1))))
4541 4662
4663 (defun c-lineup-arglist-close-under-paren (langelem)
4664 ;; lineup an arglist-intro line to just after the open paren
4665 (save-excursion
4666 (let ((cs-curcol (save-excursion
4667 (goto-char (cdr langelem))
4668 (current-column)))
4669 (ce-curcol (save-excursion
4670 (beginning-of-line)
4671 (backward-up-list 1)
4672 (current-column))))
4673 (- ce-curcol cs-curcol))))
4674
4542 (defun c-lineup-streamop (langelem) 4675 (defun c-lineup-streamop (langelem)
4543 ;; lineup stream operators 4676 ;; lineup stream operators
4544 (save-excursion 4677 (save-excursion
4545 (let* ((relpos (cdr langelem)) 4678 (let* ((relpos (cdr langelem))
4546 (curcol (progn (goto-char relpos) 4679 (curcol (progn (goto-char relpos)
4590 ;; support old behavior for comment indentation. we look at 4723 ;; support old behavior for comment indentation. we look at
4591 ;; c-comment-only-line-offset to decide how to indent comment 4724 ;; c-comment-only-line-offset to decide how to indent comment
4592 ;; only-lines 4725 ;; only-lines
4593 (save-excursion 4726 (save-excursion
4594 (back-to-indentation) 4727 (back-to-indentation)
4595 ;; indent as specified by c-comment-only-line-offset 4728 ;; this highly kludgiforous flag prevents the mapcar over
4596 (if (not (bolp)) 4729 ;; c-syntactic-context from entering an infinite loop
4730 (let ((recurse-prevention-flag (boundp 'recurse-prevention-flag)))
4731 (cond
4732 ;; CASE 1: preserve comment-column
4733 (recurse-prevention-flag 0)
4734 ((= (current-column) comment-column)
4735 ;; we have to subtract out all other indentation
4736 (- comment-column (apply '+ (mapcar 'c-get-offset
4737 c-syntactic-context))))
4738 ;; indent as specified by c-comment-only-line-offset
4739 ((not (bolp))
4597 (or (car-safe c-comment-only-line-offset) 4740 (or (car-safe c-comment-only-line-offset)
4598 c-comment-only-line-offset) 4741 c-comment-only-line-offset))
4599 (or (cdr-safe c-comment-only-line-offset) 4742 (t
4600 (car-safe c-comment-only-line-offset) 4743 (or (cdr-safe c-comment-only-line-offset)
4601 -1000 ;jam it against the left side 4744 (car-safe c-comment-only-line-offset)
4602 )))) 4745 -1000)) ;jam it against the left side
4746 ))))
4603 4747
4604 (defun c-lineup-runin-statements (langelem) 4748 (defun c-lineup-runin-statements (langelem)
4605 ;; line up statements in coding standards which place the first 4749 ;; line up statements in coding standards which place the first
4606 ;; statement on the same line as the block opening brace. 4750 ;; statement on the same line as the block opening brace.
4607 (if (= (char-after (cdr langelem)) ?{) 4751 (if (= (char-after (cdr langelem)) ?{)
4730 (if (= (following-char) ?{) 4874 (if (= (following-char) ?{)
4731 (c-safe (forward-sexp -1))) 4875 (c-safe (forward-sexp -1)))
4732 (looking-at "\\<do\\>[^_]"))) 4876 (looking-at "\\<do\\>[^_]")))
4733 '(before) 4877 '(before)
4734 '(before after))))) 4878 '(before after)))))
4879
4880 (defun c-gnu-impose-minimum ()
4881 "Imposes a minimum indentation for labels and case tags.
4882 The variable `c-label-minimum-indentation' specifies the minimum
4883 indentation amount."
4884 (let ((non-top-levels '(defun-block-intro statement statement-cont
4885 statement-block-intro statement-case-intro
4886 statement-case-open substatement substatement-open
4887 case-label label do-while-closure else-clause
4888 ))
4889 (syntax c-syntactic-context)
4890 langelem)
4891 (while syntax
4892 (setq langelem (car (car syntax))
4893 syntax (cdr syntax))
4894 ;; don't adjust comment-only lines
4895 (cond ((eq langelem 'comment-intro)
4896 (setq syntax nil))
4897 ((memq langelem non-top-levels)
4898 (save-excursion
4899 (setq syntax nil)
4900 (back-to-indentation)
4901 (if (zerop (current-column))
4902 (insert (make-string c-label-minimum-indentation 32)))
4903 ))
4904 ))))
4735 4905
4736 4906
4737 ;;; This page handles insertion and removal of backslashes for C macros. 4907 ;;; This page handles insertion and removal of backslashes for C macros.
4738 4908
4739 (defun c-backslash-region (from to delete-flag) 4909 (defun c-backslash-region (from to delete-flag)
4794 4964
4795 (defun c-delete-backslash () 4965 (defun c-delete-backslash ()
4796 (end-of-line) 4966 (end-of-line)
4797 (or (bolp) 4967 (or (bolp)
4798 (progn 4968 (progn
4799 (forward-char -1) 4969 (forward-char -1)
4800 (if (looking-at "\\\\") 4970 (if (looking-at "\\\\")
4801 (delete-region (1+ (point)) 4971 (delete-region (1+ (point))
4802 (progn (skip-chars-backward " \t") (point))))))) 4972 (progn (skip-chars-backward " \t") (point)))))))
4803 4973
4804 4974
4805 ;; defuns for submitting bug reports 4975 ;; defuns for submitting bug reports
4806 4976
4807 (defconst c-version "4.282" 4977 (defconst c-version "4.315"
4808 "cc-mode version number.") 4978 "cc-mode version number.")
4809 (defconst c-mode-help-address "bug-gnu-emacs@prep.ai.mit.edu" 4979 (defconst c-mode-help-address
4980 "bug-gnu-emacs@prep.ai.mit.edu, cc-mode-help@python.org"
4810 "Address for cc-mode bug reports.") 4981 "Address for cc-mode bug reports.")
4811 4982
4812 (defun c-version () 4983 (defun c-version ()
4813 "Echo the current version of cc-mode in the minibuffer." 4984 "Echo the current version of cc-mode in the minibuffer."
4814 (interactive) 4985 (interactive)
4851 'c-hanging-braces-alist 5022 'c-hanging-braces-alist
4852 'c-hanging-colons-alist 5023 'c-hanging-colons-alist
4853 'c-hanging-comment-ender-p 5024 'c-hanging-comment-ender-p
4854 'c-tab-always-indent 5025 'c-tab-always-indent
4855 'c-recognize-knr-p 5026 'c-recognize-knr-p
5027 'c-label-minimum-indentation
4856 'defun-prompt-regexp 5028 'defun-prompt-regexp
4857 'tab-width 5029 'tab-width
4858 ))) 5030 )))
4859 (if (not (boundp 'defun-prompt-regexp)) 5031 (if (not (boundp 'defun-prompt-regexp))
4860 (delq 'defun-prompt-regexp vars) 5032 (delq 'defun-prompt-regexp vars)
4882 (interactive "@e") 5054 (interactive "@e")
4883 (popup-menu (cons (concat mode-name " Mode Commands") c-mode-menu)) 5055 (popup-menu (cons (concat mode-name " Mode Commands") c-mode-menu))
4884 (c-keep-region-active)) 5056 (c-keep-region-active))
4885 5057
4886 5058
5059 ;; Emacs/XEmacs Compatibility
5060 ;; XEmacs has these, Emacs (even 19.31) does not
5061
5062 ;; Lift XEmacs 19.13's functionp from subr.el
5063 (defun c-functionp (obj)
5064 "Returns t if OBJ is a function, nil otherwise."
5065 (cond
5066 ((symbolp obj) (fboundp obj))
5067 ((subrp obj))
5068 ((compiled-function-p obj))
5069 ((consp obj)
5070 (if (eq (car obj) 'lambda) (listp (car (cdr obj)))))
5071 (t nil)))
5072
4887 (defun c-copy-tree (tree) 5073 (defun c-copy-tree (tree)
4888 ;; Lift XEmacs 19.12's copy-tree 5074 ;; Lift XEmacs 19.12's copy-tree
4889 (if (consp tree) 5075 (if (consp tree)
4890 (cons (c-copy-tree (car tree)) 5076 (cons (c-copy-tree (car tree))
4891 (c-copy-tree (cdr tree))) 5077 (c-copy-tree (cdr tree)))
4907 ;; Emacs 19 and Emacs 18 5093 ;; Emacs 19 and Emacs 18
4908 (c-copy-tree val) 5094 (c-copy-tree val)
4909 ))) 5095 )))
4910 )) 5096 ))
4911 5097
5098
5099
4912 ;; Dynamically append the default value of most variables. This is 5100 ;; Dynamically append the default value of most variables. This is
4913 ;; crucial because future c-set-style calls will always reset the 5101 ;; crucial because future c-set-style calls will always reset the
4914 ;; variables first to the `cc-mode' style before instituting the new 5102 ;; variables first to the `cc-mode' style before instituting the new
4915 ;; style. Only do this once! 5103 ;; style. Only do this once!
4916 (or (assoc "cc-mode" c-style-alist) 5104 (or (assoc "cc-mode" c-style-alist)
4926 c-electric-pound-behavior 5114 c-electric-pound-behavior
4927 c-hanging-braces-alist 5115 c-hanging-braces-alist
4928 c-hanging-colons-alist 5116 c-hanging-colons-alist
4929 c-hanging-comment-ender-p 5117 c-hanging-comment-ender-p
4930 c-offsets-alist 5118 c-offsets-alist
4931 c-recognize-knr-p
4932 c-strict-syntax-p 5119 c-strict-syntax-p
4933 c-tab-always-indent 5120 c-tab-always-indent
4934 c-inhibit-startup-warnings-p 5121 c-inhibit-startup-warnings-p
4935 ))) 5122 )))
4936 ;; the default style is now GNU. This can be overridden in 5123 ;; the default style is now GNU. This can be overridden in
4937 ;; c-mode-common-hook or {c,c++,objc}-mode-hook. 5124 ;; c-mode-common-hook or {c,c++,objc,java}-mode-hook.
4938 (c-set-style c-site-default-style))) 5125 (c-set-style c-site-default-style)))
4939 5126
4940 ;; style variables 5127 ;; style variables
4941 (make-variable-buffer-local 'c-offsets-alist) 5128 (make-variable-buffer-local 'c-offsets-alist)
4942 (make-variable-buffer-local 'c-basic-offset) 5129 (make-variable-buffer-local 'c-basic-offset)
4947 (make-variable-buffer-local 'c-cleanup-list) 5134 (make-variable-buffer-local 'c-cleanup-list)
4948 (make-variable-buffer-local 'c-hanging-braces-alist) 5135 (make-variable-buffer-local 'c-hanging-braces-alist)
4949 (make-variable-buffer-local 'c-hanging-colons-alist) 5136 (make-variable-buffer-local 'c-hanging-colons-alist)
4950 (make-variable-buffer-local 'c-hanging-comment-ender-p) 5137 (make-variable-buffer-local 'c-hanging-comment-ender-p)
4951 (make-variable-buffer-local 'c-backslash-column) 5138 (make-variable-buffer-local 'c-backslash-column)
4952 5139 (make-variable-buffer-local 'c-label-minimum-indentation)
5140 (make-variable-buffer-local 'c-special-indent-hook)
4953 5141
4954 5142
4955 ;; fsets for compatibility with BOCM 5143 ;; fsets for compatibility with BOCM
4956 (fset 'electric-c-brace 'c-electric-brace) 5144 (fset 'electric-c-brace 'c-electric-brace)
4957 (fset 'electric-c-semi 'c-electric-semi&comma) 5145 (fset 'electric-c-semi 'c-electric-semi&comma)
4965 (fset 'c++-end-of-defun 'end-of-defun) 5153 (fset 'c++-end-of-defun 'end-of-defun)
4966 5154
4967 ;; set up bc warnings for obsolete variables, but for now lets not 5155 ;; set up bc warnings for obsolete variables, but for now lets not
4968 ;; worry about obsolete functions. maybe later some will be important 5156 ;; worry about obsolete functions. maybe later some will be important
4969 ;; to flag 5157 ;; to flag
4970 (and (memq 'v19 c-emacs-features) 5158 (and (or (memq 'v19 c-emacs-features) (memq 'v20 c-emacs-features))
4971 (let* ((na "Nothing appropriate.") 5159 (let* ((na "Nothing appropriate.")
4972 (vars 5160 (vars
4973 (list 5161 (list
4974 (cons 'c++-c-mode-syntax-table 'c-mode-syntax-table) 5162 (cons 'c++-c-mode-syntax-table 'c-mode-syntax-table)
4975 (cons 'c++-tab-always-indent 'c-tab-always-indent) 5163 (cons 'c++-tab-always-indent 'c-tab-always-indent)