comparison lisp/cc-mode/cc-langs.el @ 181:bfd6434d15b3 r20-3b17

Import from CVS: tag r20-3b17
author cvs
date Mon, 13 Aug 2007 09:53:19 +0200
parents 6075d714658b
children e121b013d1f0
comparison
equal deleted inserted replaced
180:add28d59e586 181:bfd6434d15b3
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 ;; Maintainer: cc-mode-help@python.org 8 ;; Maintainer: cc-mode-help@python.org
9 ;; Created: 22-Apr-1997 (split from cc-mode.el) 9 ;; Created: 22-Apr-1997 (split from cc-mode.el)
10 ;; Version: 5.14 10 ;; Version: 5.15
11 ;; Keywords: c languages oop 11 ;; Keywords: c languages oop
12 12
13 ;; This file is part of GNU Emacs. 13 ;; This file is part of GNU Emacs.
14 14
15 ;; GNU Emacs is free software; you can redistribute it and/or modify 15 ;; GNU Emacs is free software; you can redistribute it and/or modify
121 ;; since it is considered the end of //-comments. 121 ;; since it is considered the end of //-comments.
122 "[ \t\n]*" c-symbol-key)) 122 "[ \t\n]*" c-symbol-key))
123 123
124 124
125 ;; comment starter definitions for various languages. language specific 125 ;; comment starter definitions for various languages. language specific
126 (defconst c-C-comment-start-regexp "/[*]")
127 (defconst c-C++-comment-start-regexp "/[/*]") 126 (defconst c-C++-comment-start-regexp "/[/*]")
128 ;; We need to match all 3 Java style comments 127 ;; We need to match all 3 Java style comments
129 ;; 1) Traditional C block; 2) javadoc /** ...; 3) C++ style 128 ;; 1) Traditional C block; 2) javadoc /** ...; 3) C++ style
130 (defconst c-Java-comment-start-regexp "/\\(/\\|[*][*]?\\)") 129 (defconst c-Java-comment-start-regexp "/\\(/\\|[*][*]?\\)")
131 (defvar c-comment-start-regexp c-C-comment-start-regexp) 130 (defvar c-comment-start-regexp c-C++-comment-start-regexp)
132 (make-variable-buffer-local 'c-comment-start-regexp) 131 (make-variable-buffer-local 'c-comment-start-regexp)
133 132
134 133
135 134
136 ;; Regexp describing a switch's case or default label for all languages 135 ;; Regexp describing a switch's case or default label for all languages
213 (make-local-variable 'comment-multi-line) 212 (make-local-variable 'comment-multi-line)
214 (make-local-variable 'outline-regexp) 213 (make-local-variable 'outline-regexp)
215 (make-local-variable 'outline-level) 214 (make-local-variable 'outline-level)
216 (make-local-variable 'adaptive-fill-regexp) 215 (make-local-variable 'adaptive-fill-regexp)
217 (make-local-variable 'imenu-generic-expression) ;set in the mode functions 216 (make-local-variable 'imenu-generic-expression) ;set in the mode functions
217 ;; X/Emacs 20 only
218 (and (boundp 'comment-line-break-function)
219 (make-local-variable 'comment-line-break-function))
218 ;; Emacs 19.30 and beyond only, AFAIK 220 ;; Emacs 19.30 and beyond only, AFAIK
219 (if (boundp 'fill-paragraph-function) 221 (if (boundp 'fill-paragraph-function)
220 (progn 222 (progn
221 (make-local-variable 'fill-paragraph-function) 223 (make-local-variable 'fill-paragraph-function)
222 (setq fill-paragraph-function 'c-fill-paragraph))) 224 (setq fill-paragraph-function 'c-fill-paragraph)))
230 indent-region-function 'c-indent-region 232 indent-region-function 'c-indent-region
231 outline-regexp "[^#\n\^M]" 233 outline-regexp "[^#\n\^M]"
232 outline-level 'c-outline-level 234 outline-level 'c-outline-level
233 comment-column 32 235 comment-column 32
234 comment-start-skip "/\\*+ *\\|// *" 236 comment-start-skip "/\\*+ *\\|// *"
237 comment-multi-line nil
238 comment-line-break-function 'c-comment-line-break-function
235 adaptive-fill-regexp nil) 239 adaptive-fill-regexp nil)
236 ;; we have to do something special for c-offsets-alist so that the 240 ;; we have to do something special for c-offsets-alist so that the
237 ;; buffer local value has its own alist structure. 241 ;; buffer local value has its own alist structure.
238 (setq c-offsets-alist (copy-alist c-offsets-alist)) 242 (setq c-offsets-alist (copy-alist c-offsets-alist))
239 ;; setup the comment indent variable in a Emacs version portable way 243 ;; setup the comment indent variable in a Emacs version portable way
295 (modify-syntax-entry ?% "." table) 299 (modify-syntax-entry ?% "." table)
296 (modify-syntax-entry ?< "." table) 300 (modify-syntax-entry ?< "." table)
297 (modify-syntax-entry ?> "." table) 301 (modify-syntax-entry ?> "." table)
298 (modify-syntax-entry ?& "." table) 302 (modify-syntax-entry ?& "." table)
299 (modify-syntax-entry ?| "." table) 303 (modify-syntax-entry ?| "." table)
300 (modify-syntax-entry ?\' "\"" table)) 304 (modify-syntax-entry ?\' "\"" table)
301 305 ;; Set up block and line oriented comments. The new C standard
302 (defun c-setup-dual-comments (table) 306 ;; mandates both comment styles even in C, so since all languages
303 ;; Set up TABLE to handle block and line style comments 307 ;; now require dual comments, we make this the default.
304 (cond 308 (cond
305 ;; XEmacs 19 & 20 309 ;; XEmacs 19 & 20
306 ((memq '8-bit c-emacs-features) 310 ((memq '8-bit c-emacs-features)
307 (modify-syntax-entry ?/ ". 1456" table) 311 (modify-syntax-entry ?/ ". 1456" table)
308 (modify-syntax-entry ?* ". 23" table) 312 (modify-syntax-entry ?* ". 23" table))
309 (modify-syntax-entry ?\n "> b" table) 313 ;; Emacs 19 & 20
310 ;; Give CR the same syntax as newline, for selective-display
311 (modify-syntax-entry ?\^m "> b" table))
312 ;; Emacs 19
313 ((memq '1-bit c-emacs-features) 314 ((memq '1-bit c-emacs-features)
314 (modify-syntax-entry ?/ ". 124b" table) 315 (modify-syntax-entry ?/ ". 124b" table)
315 (modify-syntax-entry ?* ". 23" table) 316 (modify-syntax-entry ?* ". 23" table))
316 (modify-syntax-entry ?\n "> b" table)
317 ;; Give CR the same syntax as newline, for selective-display
318 (modify-syntax-entry ?\^m "> b" table))
319 ;; incompatible 317 ;; incompatible
320 (t (error "CC Mode is incompatible with this version of Emacs")) 318 (t (error "CC Mode is incompatible with this version of Emacs"))
321 )) 319 )
320 (modify-syntax-entry ?\n "> b" table)
321 ;; Give CR the same syntax as newline, for selective-display
322 (modify-syntax-entry ?\^m "> b" table))
323
322 324
323 (defvar c-mode-base-map () 325 (defvar c-mode-base-map ()
324 "Keymap shared by all CC Mode related modes.") 326 "Keymap shared by all CC Mode related modes.")
325 327
326 (if c-mode-base-map 328 (if c-mode-base-map
365 (define-key c-mode-base-map [delete] 'c-electric-delete) 367 (define-key c-mode-base-map [delete] 'c-electric-delete)
366 (define-key c-mode-base-map [backspace] 'c-electric-backspace)) 368 (define-key c-mode-base-map [backspace] 'c-electric-backspace))
367 ;; these are new keybindings, with no counterpart to BOCM 369 ;; these are new keybindings, with no counterpart to BOCM
368 (define-key c-mode-base-map "," 'c-electric-semi&comma) 370 (define-key c-mode-base-map "," 'c-electric-semi&comma)
369 (define-key c-mode-base-map "*" 'c-electric-star) 371 (define-key c-mode-base-map "*" 'c-electric-star)
372 (define-key c-mode-base-map "/" 'c-electric-slash)
370 (define-key c-mode-base-map "\C-c\C-q" 'c-indent-defun) 373 (define-key c-mode-base-map "\C-c\C-q" 'c-indent-defun)
371 (define-key c-mode-base-map "\C-c\C-\\" 'c-backslash-region) 374 (define-key c-mode-base-map "\C-c\C-\\" 'c-backslash-region)
372 ;; TBD: where if anywhere, to put c-backward|forward-into-nomenclature 375 ;; TBD: where if anywhere, to put c-backward|forward-into-nomenclature
373 (define-key c-mode-base-map "\C-c\C-a" 'c-toggle-auto-state) 376 (define-key c-mode-base-map "\C-c\C-a" 'c-toggle-auto-state)
374 (define-key c-mode-base-map "\C-c\C-b" 'c-submit-bug-report) 377 (define-key c-mode-base-map "\C-c\C-b" 'c-submit-bug-report)
434 (defvar c-mode-syntax-table nil 437 (defvar c-mode-syntax-table nil
435 "Syntax table used in c-mode buffers.") 438 "Syntax table used in c-mode buffers.")
436 (if c-mode-syntax-table 439 (if c-mode-syntax-table
437 () 440 ()
438 (setq c-mode-syntax-table (make-syntax-table)) 441 (setq c-mode-syntax-table (make-syntax-table))
439 (c-populate-syntax-table c-mode-syntax-table) 442 (c-populate-syntax-table c-mode-syntax-table))
440 ;; add extra comment syntax
441 (modify-syntax-entry ?/ ". 14" c-mode-syntax-table)
442 (modify-syntax-entry ?* ". 23" c-mode-syntax-table))
443
444 (defun c-enable-//-in-c-mode ()
445 "Enables // as a comment delimiter in `c-mode'.
446 ANSI C currently does *not* allow this, although many C compilers
447 support optional C++ style comments. To use, call this function from
448 your `.emacs' file before you visit any C files. The changes are
449 global and affect all future `c-mode' buffers."
450 (c-setup-dual-comments c-mode-syntax-table)
451 (setq-default c-C-comment-start-regexp c-C++-comment-start-regexp))
452 443
453 (easy-menu-define c-c-menu c-mode-map "C Mode Commands" 444 (easy-menu-define c-c-menu c-mode-map "C Mode Commands"
454 (c-mode-menu "C")) 445 (c-mode-menu "C"))
455 446
456 447
465 (if c++-mode-map 456 (if c++-mode-map
466 nil 457 nil
467 (setq c++-mode-map (c-make-inherited-keymap)) 458 (setq c++-mode-map (c-make-inherited-keymap))
468 ;; add bindings which are only useful for C++ 459 ;; add bindings which are only useful for C++
469 (define-key c++-mode-map "\C-c:" 'c-scope-operator) 460 (define-key c++-mode-map "\C-c:" 'c-scope-operator)
470 (define-key c++-mode-map "/" 'c-electric-slash)
471 (define-key c++-mode-map "<" 'c-electric-lt-gt) 461 (define-key c++-mode-map "<" 'c-electric-lt-gt)
472 (define-key c++-mode-map ">" 'c-electric-lt-gt)) 462 (define-key c++-mode-map ">" 'c-electric-lt-gt))
473 463
464 ;;;###autoload
474 (defvar c++-mode-syntax-table nil 465 (defvar c++-mode-syntax-table nil
475 "Syntax table used in c++-mode buffers.") 466 "Syntax table used in c++-mode buffers.")
476 (if c++-mode-syntax-table 467 (if c++-mode-syntax-table
477 () 468 ()
478 (setq c++-mode-syntax-table (make-syntax-table)) 469 (setq c++-mode-syntax-table (make-syntax-table))
479 (c-populate-syntax-table c++-mode-syntax-table) 470 (c-populate-syntax-table c++-mode-syntax-table)
480 ;; add extra comment syntax
481 (c-setup-dual-comments c++-mode-syntax-table)
482 ;; TBD: does it make sense for colon to be symbol class in C++? 471 ;; TBD: does it make sense for colon to be symbol class in C++?
483 ;; I'm not so sure, since c-label-key is busted on lines like: 472 ;; I'm not so sure, since c-label-key is busted on lines like:
484 ;; Foo::bar( i ); 473 ;; Foo::bar( i );
485 ;; maybe c-label-key should be fixed instead of commenting this out, 474 ;; maybe c-label-key should be fixed instead of commenting this out,
486 ;; but it also bothers me that this only seems appropriate for C++ 475 ;; but it also bothers me that this only seems appropriate for C++
504 nil 493 nil
505 (setq objc-mode-map (c-make-inherited-keymap)) 494 (setq objc-mode-map (c-make-inherited-keymap))
506 ;; add bindings which are only useful for Objective-C 495 ;; add bindings which are only useful for Objective-C
507 (define-key objc-mode-map "/" 'c-electric-slash)) 496 (define-key objc-mode-map "/" 'c-electric-slash))
508 497
498 ;;;###autoload
509 (defvar objc-mode-syntax-table nil 499 (defvar objc-mode-syntax-table nil
510 "Syntax table used in objc-mode buffers.") 500 "Syntax table used in objc-mode buffers.")
511 (if objc-mode-syntax-table 501 (if objc-mode-syntax-table
512 () 502 ()
513 (setq objc-mode-syntax-table (make-syntax-table)) 503 (setq objc-mode-syntax-table (make-syntax-table))
514 (c-populate-syntax-table objc-mode-syntax-table) 504 (c-populate-syntax-table objc-mode-syntax-table)
515 ;; add extra comment syntax 505 ;; add extra Objective-C only syntax
516 (c-setup-dual-comments objc-mode-syntax-table) 506 (modify-syntax-entry ?@ "_" objc-mode-syntax-table))
517 ;; everyone gets these
518 (modify-syntax-entry ?@ "_" objc-mode-syntax-table)
519 )
520 507
521 (easy-menu-define c-objc-menu objc-mode-map "ObjC Mode Commands" 508 (easy-menu-define c-objc-menu objc-mode-map "ObjC Mode Commands"
522 (c-mode-menu "ObjC")) 509 (c-mode-menu "ObjC"))
523 510
524 511
534 nil 521 nil
535 (setq java-mode-map (c-make-inherited-keymap)) 522 (setq java-mode-map (c-make-inherited-keymap))
536 ;; add bindings which are only useful for Java 523 ;; add bindings which are only useful for Java
537 (define-key java-mode-map "/" 'c-electric-slash)) 524 (define-key java-mode-map "/" 'c-electric-slash))
538 525
526 ;;;###autoload
539 (defvar java-mode-syntax-table nil 527 (defvar java-mode-syntax-table nil
540 "Syntax table used in java-mode buffers.") 528 "Syntax table used in java-mode buffers.")
541 (if java-mode-syntax-table 529 (if java-mode-syntax-table
542 () 530 ()
543 (setq java-mode-syntax-table (make-syntax-table)) 531 (setq java-mode-syntax-table (make-syntax-table))
544 (c-populate-syntax-table java-mode-syntax-table) 532 (c-populate-syntax-table java-mode-syntax-table))
545 ;; add extra comment syntax
546 (c-setup-dual-comments java-mode-syntax-table)
547 ;; everyone gets these
548 (modify-syntax-entry ?@ "_" java-mode-syntax-table)
549 )
550 533
551 (easy-menu-define c-java-menu java-mode-map "Java Mode Commands" 534 (easy-menu-define c-java-menu java-mode-map "Java Mode Commands"
552 (c-mode-menu "Java")) 535 (c-mode-menu "Java"))
553 536
554 537
564 nil 547 nil
565 (setq idl-mode-map (c-make-inherited-keymap)) 548 (setq idl-mode-map (c-make-inherited-keymap))
566 ;; additional bindings 549 ;; additional bindings
567 (define-key idl-mode-map "/" 'c-electric-slash)) 550 (define-key idl-mode-map "/" 'c-electric-slash))
568 551
552 ;;;###autoload
569 (defvar idl-mode-syntax-table nil 553 (defvar idl-mode-syntax-table nil
570 "Syntax table used in idl-mode buffers.") 554 "Syntax table used in idl-mode buffers.")
571 (if idl-mode-syntax-table 555 (if idl-mode-syntax-table
572 nil 556 nil
573 (setq idl-mode-syntax-table (make-syntax-table)) 557 (setq idl-mode-syntax-table (make-syntax-table))
574 (c-populate-syntax-table idl-mode-syntax-table) 558 (c-populate-syntax-table idl-mode-syntax-table))
575 ;; add extra comment syntax
576 (c-setup-dual-comments idl-mode-syntax-table)
577 )
578 559
579 (easy-menu-define c-idl-menu idl-mode-map "IDL Mode Commands" 560 (easy-menu-define c-idl-menu idl-mode-map "IDL Mode Commands"
580 (c-mode-menu "IDL")) 561 (c-mode-menu "IDL"))
581 562
582 563