comparison lisp/modes/cc-mode.el @ 120:cca96a509cfe r20-1b12

Import from CVS: tag r20-1b12
author cvs
date Mon, 13 Aug 2007 09:25:29 +0200
parents 7d55a9ba150c
children 25f70ba0133c
comparison
equal deleted inserted replaced
119:d101af7320b8 120:cca96a509cfe
4 4
5 ;; Authors: 1992-1997 Barry A. Warsaw 5 ;; Authors: 1992-1997 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.390 9 ;; Version: 4.390-x
10 ;; Last Modified: 1997/04/02 15:46:35 10 ;; Last Modified: 1997/04/02 15:46:35
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!
81 ;; Or if you don't have access to the World Wide Web, through 81 ;; Or if you don't have access to the World Wide Web, through
82 ;; anonymous ftp from: 82 ;; anonymous ftp from:
83 ;; 83 ;;
84 ;; ftp://ftp.python.org/pub/emacs 84 ;; ftp://ftp.python.org/pub/emacs
85 85
86 ;; Customization added by Hrvoje Niksic <hniksic@srce.hr>
87
86 ;;; Code: 88 ;;; Code:
87 89
88 90
89 ;; user definable variables 91 ;; user definable variables
90 ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv 92 ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
91 93
92 (defvar c-inhibit-startup-warnings-p nil 94 (defgroup cc-mode nil
93 "*If non-nil, inhibits start up compatibility warnings.") 95 "Major mode for editing C, C++, Objective-C, and Java code"
94 (defvar c-strict-syntax-p nil 96 :group 'c
97 :prefix "c-")
98
99 (defgroup cc-style nil
100 "Styles for cc mode"
101 :prefix "c-"
102 :group 'cc-mode)
103
104 (defgroup cc-indent nil
105 "Indentation of cc-mode"
106 :prefix "c-"
107 :group 'cc-mode)
108
109 (defgroup cc-syntax nil
110 "Syntactical analysis performed by cc-mode"
111 :prefix "c-"
112 :group 'cc-mode)
113
114 (defgroup cc-comment nil
115 "Handling of comments by cc-mode"
116 :prefix "c-"
117 :group 'cc-mode)
118
119 (defgroup cc-auto nil
120 "Auto-insertion features of cc-mode"
121 :prefix "c-"
122 :group 'cc-mode)
123
124
125 (defcustom c-inhibit-startup-warnings-p nil
126 "*If non-nil, inhibits start up compatibility warnings."
127 :type 'boolean
128 :group 'cc-mode)
129 (defcustom c-strict-syntax-p nil
95 "*If non-nil, all syntactic symbols must be found in `c-offsets-alist'. 130 "*If non-nil, all syntactic symbols must be found in `c-offsets-alist'.
96 If the syntactic symbol for a particular line does not match a symbol 131 If the syntactic symbol for a particular line does not match a symbol
97 in the offsets alist, an error is generated, otherwise no error is 132 in the offsets alist, an error is generated, otherwise no error is
98 reported and the syntactic symbol is ignored.") 133 reported and the syntactic symbol is ignored."
99 (defvar c-echo-syntactic-information-p nil 134 :type 'boolean
100 "*If non-nil, syntactic info is echoed when the line is indented.") 135 :group 'cc-syntax)
101 (defvar c-basic-offset 4 136 (defcustom c-echo-syntactic-information-p nil
102 "*Amount of basic offset used by + and - symbols in `c-offsets-alist'.") 137 "*If non-nil, syntactic info is echoed when the line is indented."
103 138 :type 'boolean
104 (defconst c-offsets-alist 139 :group 'cc-syntax)
140 (defcustom c-basic-offset 4
141 "*Amount of basic offset used by + and - symbols in `c-offsets-alist'."
142 :type 'integer
143 :group 'cc-indent)
144
145 (defcustom 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 . +)
251 objc-method-args-cont -- lines continuing an Objective-C method definition 292 objc-method-args-cont -- lines continuing an Objective-C method definition
252 objc-method-call-cont -- lines continuing an Objective-C method call 293 objc-method-call-cont -- lines continuing an Objective-C method call
253 extern-lang-open -- brace that opens an external language block 294 extern-lang-open -- brace that opens an external language block
254 extern-lang-close -- brace that closes an external language block 295 extern-lang-close -- brace that closes an external language block
255 inextern-lang -- analogous to `inclass' syntactic symbol 296 inextern-lang -- analogous to `inclass' syntactic symbol
256 ") 297 "
257 298 :type '(repeat (cons symbol sexp))
258 (defvar c-tab-always-indent t 299 :group 'cc-syntax
300 :group 'cc-indent)
301
302 (defcustom c-tab-always-indent t
259 "*Controls the operation of the TAB key. 303 "*Controls the operation of the TAB key.
260 If t, hitting TAB always just indents the current line. If nil, 304 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 305 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 306 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 307 \(see note\). If other than nil or t, then tab is inserted only
268 tab character will be inserted, or the equivalent number of space. 312 tab character will be inserted, or the equivalent number of space.
269 When inserting a tab, actually the function stored in the variable 313 When inserting a tab, actually the function stored in the variable
270 `c-insert-tab-function' is called. 314 `c-insert-tab-function' is called.
271 315
272 Note: indentation of lines containing only comments is also controlled 316 Note: indentation of lines containing only comments is also controlled
273 by the `c-comment-only-line-offset' variable.") 317 by the `c-comment-only-line-offset' variable."
274 318 :type '(choice (const :tag "on" t)
275 (defvar c-insert-tab-function 'insert-tab 319 (const :tag "off" nil)
320 (const :tag "insert within literals" other))
321 :group 'cc-indent)
322
323 (defcustom c-insert-tab-function 'insert-tab
276 "*Function used when inserting a tab for \\[TAB]. 324 "*Function used when inserting a tab for \\[TAB].
277 Only used when `c-tab-always-indent' indicates a `real' tab character 325 Only used when `c-tab-always-indent' indicates a `real' tab character
278 should be inserted. Value must be a function taking no arguments.") 326 should be inserted. Value must be a function taking no arguments."
279 327 :type 'function
280 (defvar c-comment-only-line-offset 0 328 :group 'cc-indent)
329
330 (defcustom c-comment-only-line-offset 0
281 "*Extra offset for line which contains only the start of a comment. 331 "*Extra offset for line which contains only the start of a comment.
282 Can contain an integer or a cons cell of the form: 332 Can contain an integer or a cons cell of the form:
283 333
284 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET) 334 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
285 335
286 Where NON-ANCHORED-OFFSET is the amount of offset given to 336 Where NON-ANCHORED-OFFSET is the amount of offset given to
287 non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is 337 non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
288 the amount of offset to give column-zero anchored comment-only lines. 338 the amount of offset to give column-zero anchored comment-only lines.
289 Just an integer as value is equivalent to (<val> . -1000).") 339 Just an integer as value is equivalent to (<val> . -1000)."
290 340 :type '(choice integer
291 (defvar c-indent-comments-syntactically-p nil 341 (cons integer integer))
342 :group 'cc-comment)
343
344 (defcustom c-indent-comments-syntactically-p nil
292 "*Specifies how comment-only lines should be indented. 345 "*Specifies how comment-only lines should be indented.
293 When this variable is non-nil, comment-only lines are indented 346 When this variable is non-nil, comment-only lines are indented
294 according to syntactic analysis via `c-offsets-alist', even when 347 according to syntactic analysis via `c-offsets-alist', even when
295 \\[indent-for-comment] is used.") 348 \\[indent-for-comment] is used."
296 349 :type 'boolean
297 (defvar c-cleanup-list '(scope-operator) 350 :group 'cc-indent
351 :group 'cc-comment)
352
353 (defcustom c-cleanup-list '(scope-operator)
298 "*List of various C/C++/ObjC constructs to \"clean up\". 354 "*List of various C/C++/ObjC constructs to \"clean up\".
299 These clean ups only take place when the auto-newline feature is 355 These clean ups only take place when the auto-newline feature is
300 turned on, as evidenced by the `/a' or `/ah' appearing next to the 356 turned on, as evidenced by the `/a' or `/ah' appearing next to the
301 mode name. Valid symbols are: 357 mode name. Valid symbols are:
302 358
322 a C++ scope operator split across multiple 378 a C++ scope operator split across multiple
323 lines. Note that certain C++ constructs can 379 lines. Note that certain C++ constructs can
324 generate ambiguous situations. This clean up 380 generate ambiguous situations. This clean up
325 only takes place when there is nothing but 381 only takes place when there is nothing but
326 whitespace between colons. Clean up occurs 382 whitespace between colons. Clean up occurs
327 when the second colon is typed.") 383 when the second colon is typed."
328 384 :type '(repeat (choice (const brace-else-brace) (const brace-elseif-brace)
329 (defvar c-hanging-braces-alist '((brace-list-open) 385 (const empty-defun-braces) (const defun-close-semi)
330 (substatement-open after) 386 (const list-close-comma) (const scope-operator)))
331 (block-close . c-snug-do-while) 387 :group 'cc-auto)
332 (extern-lang-open after) 388
333 ) 389 (defcustom c-hanging-braces-alist '((brace-list-open)
390 (substatement-open after)
391 (block-close . c-snug-do-while)
392 (extern-lang-open after)
393 )
334 "*Controls the insertion of newlines before and after braces. 394 "*Controls the insertion of newlines before and after braces.
335 This variable contains an association list with elements of the 395 This variable contains an association list with elements of the
336 following form: (SYNTACTIC-SYMBOL . ACTION). 396 following form: (SYNTACTIC-SYMBOL . ACTION).
337 397
338 When a brace (either opening or closing) is inserted, the syntactic 398 When a brace (either opening or closing) is inserted, the syntactic
355 When ACTION is a function symbol, the function is called with a two 415 When ACTION is a function symbol, the function is called with a two
356 arguments: the syntactic symbol for the brace and the buffer position 416 arguments: the syntactic symbol for the brace and the buffer position
357 at which the brace was inserted. The function must return a list as 417 at which the brace was inserted. The function must return a list as
358 described in the preceding paragraph. Note that during the call to 418 described in the preceding paragraph. Note that during the call to
359 the function, the variable `c-syntactic-context' is set to the entire 419 the function, the variable `c-syntactic-context' is set to the entire
360 syntactic context for the brace line.") 420 syntactic context for the brace line."
361 421 :type '(repeat (cons symbol (choice (const nil)
362 (defvar c-hanging-colons-alist nil 422 (repeat (choice (const before)
423 (const after)))
424 function
425 )))
426 :group 'cc-auto)
427
428 (defcustom c-hanging-colons-alist nil
363 "*Controls the insertion of newlines before and after certain colons. 429 "*Controls the insertion of newlines before and after certain colons.
364 This variable contains an association list with elements of the 430 This variable contains an association list with elements of the
365 following form: (SYNTACTIC-SYMBOL . ACTION). 431 following form: (SYNTACTIC-SYMBOL . ACTION).
366 432
367 See the variable `c-hanging-braces-alist' for the semantics of this 433 See the variable `c-hanging-braces-alist' for the semantics of this
368 variable. Note however that making ACTION a function symbol is 434 variable. Note however that making ACTION a function symbol is
369 currently not supported for this variable.") 435 currently not supported for this variable."
370 436 :type '(repeat (cons symbol (choice (repeat (choice (const before)
371 (defvar c-hanging-semi&comma-criteria '(c-semi&comma-inside-parenlist) 437 (const after)))
438 )))
439 :group 'cc-auto)
440
441 (defcustom c-hanging-semi&comma-criteria '(c-semi&comma-inside-parenlist)
372 "*List of functions that decide whether to insert a newline or not. 442 "*List of functions that decide whether to insert a newline or not.
373 The functions in this list are called, in order, whenever the 443 The functions in this list are called, in order, whenever the
374 auto-newline minor mode is activated (as evidenced by a `/a' or `/ah' 444 auto-newline minor mode is activated (as evidenced by a `/a' or `/ah'
375 string in the mode line), and a semicolon or comma is typed (see 445 string in the mode line), and a semicolon or comma is typed (see
376 `c-electric-semi&comma'). Each function in this list is called with 446 `c-electric-semi&comma'). Each function in this list is called with
379 nil -- no determination made, continue checking 449 nil -- no determination made, continue checking
380 'stop -- do not insert a newline, and stop checking 450 'stop -- do not insert a newline, and stop checking
381 (anything else) -- insert a newline, and stop checking 451 (anything else) -- insert a newline, and stop checking
382 452
383 If every function in the list is called with no determination made, 453 If every function in the list is called with no determination made,
384 then no newline is inserted.") 454 then no newline is inserted."
385 455 :type '(repeat function)
386 (defvar c-hanging-comment-ender-p t 456 :group 'cc-auto)
457
458 (defcustom c-hanging-comment-ender-p t
387 "*Controls what \\[fill-paragraph] does to C block comment enders. 459 "*Controls what \\[fill-paragraph] does to C block comment enders.
388 When set to nil, C block comment enders are left on their own line. 460 When set to nil, C block comment enders are left on their own line.
389 When set to t, block comment enders will be placed at the end of the 461 When set to t, block comment enders will be placed at the end of the
390 previous line (i.e. they `hang' on that line).") 462 previous line (i.e. they `hang' on that line)."
391 463 :type 'boolean
392 (defvar c-hanging-comment-starter-p t 464 :group 'cc-comment)
465
466 (defcustom c-hanging-comment-starter-p t
393 "*Controls what \\[fill-paragraph] does to C block comment starters. 467 "*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. 468 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 469 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 470 placed on the same line as the block comment starter (i.e. the text
397 `hangs' on that line).") 471 `hangs' on that line)."
398 472 :type 'boolean
399 (defvar c-backslash-column 48 473 :group 'cc-comment)
400 "*Column to insert backslashes when macroizing a region.") 474
401 (defvar c-special-indent-hook nil 475 (defcustom c-backslash-column 48
476 "*Column to insert backslashes when macroizing a region."
477 :type 'integer
478 :group 'cc-mode)
479 (defcustom c-special-indent-hook nil
402 "*Hook for user defined special indentation adjustments. 480 "*Hook for user defined special indentation adjustments.
403 This hook gets called after a line is indented by the mode.") 481 This hook gets called after a line is indented by the mode."
404 (defvar c-delete-function 'backward-delete-char-untabify 482 :type 'hook
405 "*Function called by `c-electric-delete' when deleting characters.") 483 :group 'cc-indent)
406 (defvar c-electric-pound-behavior nil 484 (defcustom c-delete-function 'backward-delete-char-untabify
485 "*Function called by `c-electric-delete' when deleting characters."
486 :type 'function
487 :group 'cc-mode)
488 (defcustom c-electric-pound-behavior nil
407 "*List of behaviors for electric pound insertion. 489 "*List of behaviors for electric pound insertion.
408 Only currently supported behavior is `alignleft'.") 490 Only currently supported behavior is `alignleft'."
409 491 :type '(repeat (choice (const alignleft)))
410 (defvar c-label-minimum-indentation 1 492 :group 'cc-auto)
493
494 (defcustom c-label-minimum-indentation 1
411 "*Minimum indentation for lines inside of top-level constructs. 495 "*Minimum indentation for lines inside of top-level constructs.
412 This variable typically only affects code using the `gnu' style, which 496 This variable typically only affects code using the `gnu' style, which
413 mandates a minimum of one space in front of every line inside 497 mandates a minimum of one space in front of every line inside
414 top-level constructs. Specifically, the function 498 top-level constructs. Specifically, the function
415 `c-gnu-impose-minimum' on your `c-special-indent-hook' is what 499 `c-gnu-impose-minimum' on your `c-special-indent-hook' is what
416 enforces this.") 500 enforces this."
417 501 :type 'integer
418 (defvar c-progress-interval 5 502 :group 'cc-indent)
503
504 (defcustom c-progress-interval 5
419 "*Interval used to update progress status during long re-indentation. 505 "*Interval used to update progress status during long re-indentation.
420 If a number, percentage complete gets updated after each interval of 506 If a number, percentage complete gets updated after each interval of
421 that many seconds. Set to nil to inhibit updating. This is only 507 that many seconds. Set to nil to inhibit updating. This is only
422 useful for Emacs 19.") 508 useful for Emacs 19."
509 :type 'integer
510 :group 'cc-indent)
423 511
424 (defconst c-style-alist 512 (defconst c-style-alist
425 '(("gnu" 513 '(("gnu"
426 (c-basic-offset . 2) 514 (c-basic-offset . 2)
427 (c-comment-only-line-offset . (0 . 0)) 515 (c-comment-only-line-offset . (0 . 0))
552 your style, only those that are different from the default. 640 your style, only those that are different from the default.
553 641
554 Note that all styles inherit from the `cc-mode' style, which is 642 Note that all styles inherit from the `cc-mode' style, which is
555 computed at the time the mode is loaded.") 643 computed at the time the mode is loaded.")
556 644
557 (defvar c-file-style nil 645 (defcustom c-file-style nil
558 "*Variable interface for setting style via File Local Variables. 646 "*Variable interface for setting style via File Local Variables.
559 In a file's Local Variable section, you can set this variable to a 647 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 648 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. 649 will set the style of the file to this value automatically.
562 650
563 Note that file style settings are applied before file offset settings 651 Note that file style settings are applied before file offset settings
564 as designated in the variable `c-file-offsets'.") 652 as designated in the variable `c-file-offsets'."
565 653 :type '(repeat (cons regexp (string :tag "Style")))
566 (defvar c-file-offsets nil 654 :group 'cc-style)
655
656 (defcustom c-file-offsets nil
567 "*Variable interface for setting offsets via File Local Variables. 657 "*Variable interface for setting offsets via File Local Variables.
568 In a file's Local Variable section, you can set this variable to an 658 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'. 659 association list similar to the values allowed in `c-offsets-alist'.
570 When the file is visited, CC Mode will institute these offset settings 660 When the file is visited, CC Mode will institute these offset settings
571 automatically. 661 automatically.
572 662
573 Note that file offset settings are applied after file style settings 663 Note that file offset settings are applied after file style settings
574 as designated in the variable `c-file-style'.") 664 as designated in the variable `c-file-style'."
575 665 :type '(repeat (cons regexp (string :tag "Style")))
576 (defvar c-site-default-style "gnu" 666 :group 'cc-indent)
667
668 (defcustom c-site-default-style "gnu"
577 "Default style for your site. 669 "Default style for your site.
578 To change the default style at your site, you can set this variable to 670 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 671 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 672 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 673 variable in the `site-init.el' file before CC Mode is loaded, then
582 re-dump Emacs.") 674 re-dump Emacs."
583 675 :type 'string
584 (defvar c-style-variables-are-local-p t 676 :group 'cc-style)
677
678 (defcustom c-style-variables-are-local-p t
585 "*Whether style variables should be buffer local by default. 679 "*Whether style variables should be buffer local by default.
586 If non-nil, then all indentation style related variables will be made 680 If non-nil, then all indentation style related variables will be made
587 buffer local by default. If nil, they will remain global. Variables 681 buffer local by default. If nil, they will remain global. Variables
588 are made buffer local when this file is loaded, and once buffer 682 are made buffer local when this file is loaded, and once buffer
589 localized, they cannot be made global again. 683 localized, they cannot be made global again.
600 c-hanging-comment-starter-p 694 c-hanging-comment-starter-p
601 c-hanging-comment-ender-p 695 c-hanging-comment-ender-p
602 c-backslash-column 696 c-backslash-column
603 c-label-minimum-indentation 697 c-label-minimum-indentation
604 c-special-indent-hook 698 c-special-indent-hook
605 c-indentation-style") 699 c-indentation-style"
700 :type 'boolean
701 :group 'cc-style)
606 702
607 703
608 (defvar c-mode-hook nil 704 (defcustom c-mode-hook nil
609 "*Hook called by `c-mode'.") 705 "*Hook called by `c-mode'."
610 (defvar c++-mode-hook nil 706 :type 'hook
611 "*Hook called by `c++-mode'.") 707 :group 'cc-mode)
612 (defvar objc-mode-hook nil 708 (defcustom c++-mode-hook nil
613 "*Hook called by `objc-mode'.") 709 "*Hook called by `c++-mode'."
614 (defvar java-mode-hook nil 710 :type 'hook
615 "*Hook called by `java-mode'.") 711 :group 'cc-mode)
616 712 (defcustom objc-mode-hook nil
617 (defvar c-mode-common-hook nil 713 "*Hook called by `objc-mode'."
618 "*Hook called by all CC Mode modes for common initializations.") 714 :type 'hook
715 :group 'cc-mode)
716 (defcustom java-mode-hook nil
717 "*Hook called by `java-mode'."
718 :type 'hook
719 :group 'cc-mode)
720
721 (defcustom c-mode-common-hook nil
722 "*Hook called by all CC Mode modes for common initializations."
723 :type 'hook
724 :group 'cc-mode)
619 725
620 (defvar c-mode-menu 726 (defvar c-mode-menu
621 '(["Comment Out Region" comment-region (mark)] 727 '(["Comment Out Region" comment-region (mark)]
622 ["Macro Expand Region" c-macro-expand (mark)] 728 ["Macro Expand Region" c-macro-expand (mark)]
623 ["Backslashify" c-backslash-region (mark)] 729 ["Backslashify" c-backslash-region (mark)]