comparison lisp/modes/cc-mode.el @ 40:7e54bd776075 r19-15b103

Import from CVS: tag r19-15b103
author cvs
date Mon, 13 Aug 2007 08:54:25 +0200
parents c53a95d3c46d
children 8d2a9b52c682
comparison
equal deleted inserted replaced
39:06f275776fba 40:7e54bd776075
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.381 9 ;; Version: 4.387
10 ;; Last Modified: 1997/03/18 16:43:13 10 ;; Last Modified: 1997/03/21 20:25:33
11 ;; Keywords: c languages oop 11 ;; Keywords: c languages oop
12 12
13 ;; NOTE: Read the commentary below for the right way to submit bug reports! 13 ;; NOTE: Read the commentary below for the right way to submit bug reports!
14 ;; NOTE: See the accompanying texinfo manual for details on using this mode! 14 ;; NOTE: See the accompanying texinfo manual for details on using this mode!
15 15
30 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 30 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
31 ;; Boston, MA 02111-1307, USA. 31 ;; Boston, MA 02111-1307, USA.
32 32
33 ;;; Commentary: 33 ;;; Commentary:
34 34
35 ;; This package provides modes in GNU Emacs for editing C, C++, 35 ;; This package provides GNU Emacs major modes for editing C, C++,
36 ;; Objective-C, and Java code. It is intended to be a replacement for 36 ;; Objective-C, and Java code. As of the latest Emacs and XEmacs
37 ;; c-mode.el (a.k.a. BOCM -- Boring Old C-Mode), c++-mode.el, 37 ;; releases, it is the default package for editing these languages.
38 ;; cplus-md.el, and cplus-md1.el, all of which are in some way 38 ;; This package is called "CC Mode", and should be spelled exactly
39 ;; ancestors of this file. A number of important improvements have 39 ;; this way. It supports K&R and ANSI C, ANSI C++, Objective-C, and
40 ;; been made, briefly: complete K&R C, ANSI C, `ARM' C++, Objective-C, 40 ;; Java, with a consistent indentation model across all modes. This
41 ;; and Java support with consistent indentation across all modes, more 41 ;; indentation model is intuitive and very flexible, so that almost
42 ;; intuitive indentation controlling variables, compatibility across 42 ;; any desired style of indentation can be supported. Installation,
43 ;; all known Emacsen, nice new features, and tons of bug fixes. This 43 ;; usage, and programming details are contained in an accompanying
44 ;; package is called "CC Mode" to distinguish it from its ancestors, 44 ;; texinfo manual.
45 ;; but there is no cc-mode command. Usage and programming details are 45
46 ;; contained in an accompanying texinfo manual. 46 ;; CC Mode's immediate ancestors were, c++-mode.el, cplus-md.el, and
47 ;; cplus-md1.el..
47 48
48 ;; NOTE: This mode does not perform font-locking (a.k.a syntactic 49 ;; NOTE: This mode does not perform font-locking (a.k.a syntactic
49 ;; coloring, keyword highlighting, etc.) for any of the supported 50 ;; coloring, keyword highlighting, etc.) for any of the supported
50 ;; modes. Typically this is done by a package called font-lock.el 51 ;; modes. Typically this is done by a package called font-lock.el
51 ;; which I do *not* maintain. You should contact the Emacs 52 ;; which I do *not* maintain. You should contact the Emacs
65 ;; 19 (formerly Lucid Emacs), and GNU Emacs 18 all do things 66 ;; 19 (formerly Lucid Emacs), and GNU Emacs 18 all do things
66 ;; differently and there's no way to shut the byte-compiler up at the 67 ;; differently and there's no way to shut the byte-compiler up at the
67 ;; necessary granularity. Let me say this again: YOU CAN IGNORE ALL 68 ;; necessary granularity. Let me say this again: YOU CAN IGNORE ALL
68 ;; BYTE-COMPILER WARNINGS (you'd be surprised at how many people don't 69 ;; BYTE-COMPILER WARNINGS (you'd be surprised at how many people don't
69 ;; follow this advice :-). 70 ;; follow this advice :-).
70
71 ;; As of this writing (24-Feb-1997), CC Mode comes with the latest
72 ;; Emacs and XEmacs distributions (19.34 and 19.14 respectively), but
73 ;; is no longer pre-loaded by default. To use the latest version of
74 ;; CC Mode, you need only make sure that this copy of cc-mode.el is
75 ;; found first on your load-path.
76
77 ;; If your Emacs is pre-loaded with any version of cc-mode.el,
78 ;; c-mode.el, or c++-mode.el, you will need to consult the
79 ;; cc-mode.texinfo manual for details on upgrading your Emacs.
80
81 ;; There are four major mode entry points provided by this package,
82 ;; one for editing C++ code, one for editing C code (both K&R and
83 ;; ANSI), one for editing Objective-C code, and one for editing Java
84 ;; code. The commands are M-x c-mode, M-x c++-mode, M-x objc-mode,
85 ;; and M-x java-mode.
86 71
87 ;; Many, many thanks go out to all the folks on the beta test list. 72 ;; Many, many thanks go out to all the folks on the beta test list.
88 ;; Without their patience, testing, insight, code contributions, and 73 ;; Without their patience, testing, insight, code contributions, and
89 ;; encouragement CC Mode would be a far inferior package. 74 ;; encouragement CC Mode would be a far inferior package.
90 75
419 (defvar c-delete-function 'backward-delete-char-untabify 404 (defvar c-delete-function 'backward-delete-char-untabify
420 "*Function called by `c-electric-delete' when deleting characters.") 405 "*Function called by `c-electric-delete' when deleting characters.")
421 (defvar c-electric-pound-behavior nil 406 (defvar c-electric-pound-behavior nil
422 "*List of behaviors for electric pound insertion. 407 "*List of behaviors for electric pound insertion.
423 Only currently supported behavior is `alignleft'.") 408 Only currently supported behavior is `alignleft'.")
409
424 (defvar c-label-minimum-indentation 1 410 (defvar c-label-minimum-indentation 1
425 "*Minimum indentation for labels and case tags in `gnu' style.") 411 "*Minimum indentation for lines inside of top-level constructs.
412 This variable typically only affects code using the `gnu' style, which
413 mandates a minimum of one space in front of every line inside
414 top-level constructs. Specifically, the function
415 `c-gnu-impose-minimum' on your `c-special-indent-hook' is what
416 enforces this.")
426 417
427 (defvar c-progress-interval 5 418 (defvar c-progress-interval 5
428 "*Interval used to update progress status during long re-indentation. 419 "*Interval used to update progress status during long re-indentation.
429 If a number, percentage complete gets updated after each interval of 420 If a number, percentage complete gets updated after each interval of
430 that many seconds. Set to nil to inhibit updating. This is only 421 that many seconds. Set to nil to inhibit updating. This is only
1237 "\\)\\b[^_]") 1228 "\\)\\b[^_]")
1238 "Regexp describing a conditional control for C++.") 1229 "Regexp describing a conditional control for C++.")
1239 (defconst c-C++-friend-key 1230 (defconst c-C++-friend-key
1240 "friend[ \t]+\\|template[ \t]*<.+>[ \t]*friend[ \t]+" 1231 "friend[ \t]+\\|template[ \t]*<.+>[ \t]*friend[ \t]+"
1241 "Regexp describing friend declarations in C++ classes.") 1232 "Regexp describing friend declarations in C++ classes.")
1242 (defconst c-C++-comment-start-regexp "/[/*]" 1233
1243 "Dual comment value for `c-comment-start-regexp'.") 1234 ;; comment starter definitions for various languages. the language
1244 (defconst c-C-comment-start-regexp "/\\*" 1235 ;; modes will set c-comment-start-regexp to this value.
1245 "Single comment style value for `c-comment-start-regexp'.") 1236 (defconst c-C++-comment-start-regexp "/[/*]")
1237 (defconst c-C-comment-start-regexp "/[*]")
1238 ;; We need to match all 3 Java style comments
1239 ;; 1) Traditional C block; 2) javadoc /** ...; 3) C++ style
1240 (defconst c-Java-comment-start-regexp "/\\(/\\|[*][*]?\\)")
1246 1241
1247 (defconst c-ObjC-method-key 1242 (defconst c-ObjC-method-key
1248 (concat 1243 (concat
1249 "^\\s *[+-]\\s *" 1244 "^\\s *[+-]\\s *"
1250 "\\(([^)]*)\\)?" ; return type 1245 "\\(([^)]*)\\)?" ; return type
1451 (c-common-init) 1446 (c-common-init)
1452 (setq comment-start "// " 1447 (setq comment-start "// "
1453 comment-end "" 1448 comment-end ""
1454 comment-multi-line nil 1449 comment-multi-line nil
1455 c-conditional-key c-Java-conditional-key 1450 c-conditional-key c-Java-conditional-key
1456 c-comment-start-regexp c-C++-comment-start-regexp 1451 c-comment-start-regexp c-Java-comment-start-regexp
1457 c-class-key c-Java-class-key 1452 c-class-key c-Java-class-key
1458 c-method-key c-Java-method-key 1453 c-method-key c-Java-method-key
1459 c-double-slash-is-comments-p t 1454 c-double-slash-is-comments-p t
1460 c-baseclass-key nil 1455 c-baseclass-key nil
1461 c-recognize-knr-p nil 1456 c-recognize-knr-p nil
1595 (c-setup-dual-comments c-mode-syntax-table) 1590 (c-setup-dual-comments c-mode-syntax-table)
1596 (setq-default c-C-comment-start-regexp c-C++-comment-start-regexp)) 1591 (setq-default c-C-comment-start-regexp c-C++-comment-start-regexp))
1597 1592
1598 1593
1599 ;; macros must be defined before first use 1594 ;; macros must be defined before first use
1595 (defmacro c-add-syntax (symbol &optional relpos)
1596 ;; a simple macro to append the syntax in symbol to the syntax list.
1597 ;; try to increase performance by using this macro
1598 (` (setq syntax (cons (cons (, symbol) (, relpos)) syntax))))
1599
1600 (defmacro c-point (position) 1600 (defmacro c-point (position)
1601 ;; Returns the value of point at certain commonly referenced POSITIONs. 1601 ;; Returns the value of point at certain commonly referenced POSITIONs.
1602 ;; POSITION can be one of the following symbols: 1602 ;; POSITION can be one of the following symbols:
1603 ;; 1603 ;;
1604 ;; bol -- beginning of line 1604 ;; bol -- beginning of line
2609 (narrow-to-region (save-excursion 2609 (narrow-to-region (save-excursion
2610 (if comment-start-place 2610 (if comment-start-place
2611 (goto-char comment-start-place) 2611 (goto-char comment-start-place)
2612 (search-backward "/*")) 2612 (search-backward "/*"))
2613 (if (and (not c-hanging-comment-starter-p) 2613 (if (and (not c-hanging-comment-starter-p)
2614 (looking-at "/\\*[ \t]*$")) 2614 (looking-at
2615 (concat c-comment-start-regexp
2616 "[ \t]*$")))
2615 (forward-line 1)) 2617 (forward-line 1))
2616 ;; Protect text before the comment 2618 ;; Protect text before the comment
2617 ;; start by excluding it. Add 2619 ;; start by excluding it. Add
2618 ;; spaces to bring back proper 2620 ;; spaces to bring back proper
2619 ;; indentation of that point. 2621 ;; indentation of that point.
3855 )) 3857 ))
3856 3858
3857 3859
3858 ;; defuns for calculating the syntactic state and indenting a single 3860 ;; defuns for calculating the syntactic state and indenting a single
3859 ;; line of C/C++/ObjC code 3861 ;; line of C/C++/ObjC code
3860 (defmacro c-add-syntax (symbol &optional relpos)
3861 ;; a simple macro to append the syntax in symbol to the syntax list.
3862 ;; try to increase performance by using this macro
3863 (` (setq syntax (cons (cons (, symbol) (, relpos)) syntax))))
3864
3865 (defun c-most-enclosing-brace (state) 3862 (defun c-most-enclosing-brace (state)
3866 ;; return the bufpos of the most enclosing brace that hasn't been 3863 ;; return the bufpos of the most enclosing brace that hasn't been
3867 ;; narrowed out by any enclosing class, or nil if none was found 3864 ;; narrowed out by any enclosing class, or nil if none was found
3868 (let (enclosingp) 3865 (let (enclosingp)
3869 (while (and state (not enclosingp)) 3866 (while (and state (not enclosingp))
4935 (if (not (looking-at "[*]+")) 4932 (if (not (looking-at "[*]+"))
4936 (progn 4933 (progn
4937 ;; we now have to figure out where this comment begins. 4934 ;; we now have to figure out where this comment begins.
4938 (goto-char here) 4935 (goto-char here)
4939 (back-to-indentation) 4936 (back-to-indentation)
4940 (if (re-search-forward "[*]+/" (c-point 'eol) t) 4937 (if (looking-at "[*]+/")
4941 (forward-comment -1) 4938 (progn (goto-char (match-end 0))
4939 (forward-comment -1))
4942 (goto-char (cdr langelem)) 4940 (goto-char (cdr langelem))
4943 (back-to-indentation)))) 4941 (back-to-indentation))))
4944 (- (current-column) cs-curcol)) 4942 (- (current-column) cs-curcol))
4945 (if (zerop stars) 4943 (if (zerop stars)
4946 (skip-chars-forward " \t")) 4944 (skip-chars-forward " \t"))
5203 (progn (skip-chars-backward " \t") (point))))))) 5201 (progn (skip-chars-backward " \t") (point)))))))
5204 5202
5205 5203
5206 ;; defuns for submitting bug reports 5204 ;; defuns for submitting bug reports
5207 5205
5208 (defconst c-version "4.381" 5206 (defconst c-version "4.387"
5209 "CC Mode version number.") 5207 "CC Mode version number.")
5210 (defconst c-mode-help-address 5208 (defconst c-mode-help-address
5211 "bug-gnu-emacs@prep.ai.mit.edu, cc-mode-help@python.org" 5209 "bug-gnu-emacs@prep.ai.mit.edu, cc-mode-help@python.org"
5212 "Address for CC Mode bug reports.") 5210 "Address for CC Mode bug reports.")
5213 5211
5224 (defun c-submit-bug-report () 5222 (defun c-submit-bug-report ()
5225 "Submit via mail a bug report on CC Mode." 5223 "Submit via mail a bug report on CC Mode."
5226 (interactive) 5224 (interactive)
5227 ;; load in reporter 5225 ;; load in reporter
5228 (let ((reporter-prompt-for-summary-p t) 5226 (let ((reporter-prompt-for-summary-p t)
5229 (reporter-dont-compact-list '(c-offsets-alist))) 5227 (reporter-dont-compact-list '(c-offsets-alist))
5228 (style c-indentation-style)
5229 (hook c-special-indent-hook)
5230 (c-features c-emacs-features))
5230 (and 5231 (and
5231 (if (y-or-n-p "Do you want to submit a report on CC Mode? ") 5232 (if (y-or-n-p "Do you want to submit a report on CC Mode? ")
5232 t (message "") nil) 5233 t (message "") nil)
5233 (require 'reporter) 5234 (require 'reporter)
5234 (reporter-submit-bug-report 5235 (reporter-submit-bug-report
5251 'c-electric-pound-behavior 5252 'c-electric-pound-behavior
5252 'c-hanging-braces-alist 5253 'c-hanging-braces-alist
5253 'c-hanging-colons-alist 5254 'c-hanging-colons-alist
5254 'c-hanging-comment-starter-p 5255 'c-hanging-comment-starter-p
5255 'c-hanging-comment-ender-p 5256 'c-hanging-comment-ender-p
5257 'c-indent-comments-syntactically-p
5256 'c-tab-always-indent 5258 'c-tab-always-indent
5257 'c-recognize-knr-p 5259 'c-recognize-knr-p
5258 'c-label-minimum-indentation 5260 'c-label-minimum-indentation
5259 'defun-prompt-regexp 5261 'defun-prompt-regexp
5260 'tab-width 5262 'tab-width
5263 (delq 'defun-prompt-regexp vars) 5265 (delq 'defun-prompt-regexp vars)
5264 vars)) 5266 vars))
5265 (function 5267 (function
5266 (lambda () 5268 (lambda ()
5267 (insert 5269 (insert
5268 "Buffer Style: " c-indentation-style "\n\n" 5270 "Buffer Style: " style "\n\n"
5269 (if c-special-indent-hook 5271 (if hook
5270 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" 5272 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
5271 "c-special-indent-hook is set to '" 5273 "c-special-indent-hook is set to '"
5272 (format "%s" c-special-indent-hook) 5274 (format "%s" hook)
5273 ".\nPerhaps this is your problem?\n" 5275 ".\nPerhaps this is your problem?\n"
5274 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n") 5276 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
5275 "\n") 5277 "\n")
5276 (format "c-emacs-features: %s\n" c-emacs-features) 5278 (format "c-emacs-features: %s\n" c-features)
5277 ))) 5279 )))
5278 nil 5280 nil
5279 "Dear Barry," 5281 "Dear Barry,"
5280 )))) 5282 ))))
5281 5283