Mercurial > emacs
comparison lisp/progmodes/cc-mode.el @ 24282:5b0864259a4b Release_5_25
Installed CC Mode 5.25.
author | Barry A. Warsaw <barry@zope.org> |
---|---|
date | Mon, 08 Feb 1999 16:53:18 +0000 |
parents | a0eda86dd0be |
children | 03befb219d03 |
comparison
equal
deleted
inserted
replaced
24281:d03b1e915af1 | 24282:5b0864259a4b |
---|---|
1 ;;; cc-mode.el --- major mode for editing C, C++, Objective-C, and Java code | 1 ;;; cc-mode.el --- major mode for editing C, C++, Objective-C, and Java code |
2 | 2 |
3 ;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Authors: 1992-1997 Barry A. Warsaw | 5 ;; Authors: 1998 Barry A. Warsaw and Martin Stjernholm |
6 ;; 1992-1997 Barry A. Warsaw | |
6 ;; 1987 Dave Detlefs and Stewart Clamen | 7 ;; 1987 Dave Detlefs and Stewart Clamen |
7 ;; 1985 Richard M. Stallman | 8 ;; 1985 Richard M. Stallman |
8 ;; Maintainer: cc-mode-help@python.org | 9 ;; Maintainer: bug-cc-mode@gnu.org |
9 ;; Created: a long, long, time ago. adapted from the original c-mode.el | 10 ;; Created: a long, long, time ago. adapted from the original c-mode.el |
10 ;; Keywords: c languages oop | 11 ;; Keywords: c languages oop |
11 | 12 |
12 (defconst c-version "5.21" | 13 (defconst c-version "5.25" |
13 "CC Mode version number.") | 14 "CC Mode version number.") |
14 | 15 |
15 ;; NOTE: Read the commentary below for the right way to submit bug reports! | 16 ;; NOTE: Read the commentary below for the right way to submit bug reports! |
16 ;; NOTE: See the accompanying texinfo manual for details on using this mode! | 17 ;; NOTE: See the accompanying texinfo manual for details on using this mode! |
17 | 18 |
33 ;; Boston, MA 02111-1307, USA. | 34 ;; Boston, MA 02111-1307, USA. |
34 | 35 |
35 ;;; Commentary: | 36 ;;; Commentary: |
36 | 37 |
37 ;; This package provides GNU Emacs major modes for editing C, C++, | 38 ;; This package provides GNU Emacs major modes for editing C, C++, |
38 ;; Objective-C, Java and IDL code. As of the latest Emacs and XEmacs | 39 ;; Objective-C, Java, IDL and Pike code. As of the latest Emacs and |
39 ;; releases, it is the default package for editing these languages. | 40 ;; XEmacs releases, it is the default package for editing these |
40 ;; This package is called "CC Mode", and should be spelled exactly | 41 ;; languages. This package is called "CC Mode", and should be spelled |
41 ;; this way. It supports K&R and ANSI C, ANSI C++, Objective-C, Java, | 42 ;; exactly this way. |
42 ;; and CORBA's IDL with a consistent indentation model across all | 43 |
43 ;; modes. This indentation model is intuitive and very flexible, so | 44 ;; CC Mode supports K&R and ANSI C, ANSI C++, Objective-C, Java, |
44 ;; that almost any desired style of indentation can be supported. | 45 ;; CORBA's IDL, and Pike with a consistent indentation model across |
46 ;; all modes. This indentation model is intuitive and very flexible, | |
47 ;; so that almost any desired style of indentation can be supported. | |
45 ;; Installation, usage, and programming details are contained in an | 48 ;; Installation, usage, and programming details are contained in an |
46 ;; accompanying texinfo manual. | 49 ;; accompanying texinfo manual. |
47 | 50 |
48 ;; CC Mode's immediate ancestors were, c++-mode.el, cplus-md.el, and | 51 ;; CC Mode's immediate ancestors were, c++-mode.el, cplus-md.el, and |
49 ;; cplus-md1.el.. | 52 ;; cplus-md1.el.. |
50 | 53 |
51 ;; NOTE: This mode does not perform font-locking (a.k.a syntactic | 54 ;; NOTE: This mode does not perform font-locking (a.k.a syntactic |
52 ;; coloring, keyword highlighting, etc.) for any of the supported | 55 ;; coloring, keyword highlighting, etc.) for any of the supported |
53 ;; modes. Typically this is done by a package called font-lock.el | 56 ;; modes. Typically this is done by a package called font-lock.el |
54 ;; which I do *not* maintain. You should contact the Emacs | 57 ;; which we do *not* maintain. You should contact the Emacs or XEmacs |
55 ;; maintainers for questions about coloring or highlighting in any | 58 ;; maintainers for questions about coloring or highlighting in any |
56 ;; language mode. | 59 ;; language mode. |
57 | 60 |
58 ;; To submit bug reports, type "C-c C-b". These will be sent to | 61 ;; To submit bug reports, type "C-c C-b". These will be sent to |
59 ;; bug-gnu-emacs@prep.ai.mit.edu as well as cc-mode-help@python.org, | 62 ;; bug-gnu-emacs@gnu.org (mirrored as the Usenet newsgroup |
60 ;; and I'll read about them there (the former is mirrored as the | 63 ;; gnu.emacs.bug) as well as bug-cc-mode@gnu.org, which directly |
61 ;; Usenet newsgroup gnu.emacs.bug). Questions can sent to | 64 ;; contacts the CC Mode maintainers. Questions can sent to |
62 ;; help-gnu-emacs@prep.ai.mit.edu (mirrored as gnu.emacs.help) and/or | 65 ;; help-gnu-emacs@gnu.org (mirrored as gnu.emacs.help) and/or |
63 ;; cc-mode-help@python.org. Please do not send bugs or questions to | 66 ;; bug-cc-mode@gnu.org. The old CC Mode contact address, |
64 ;; my personal account. | 67 ;; cc-mode-help@python.org is currently still active, but its use is |
68 ;; discouraged. Please use bug-cc-mode@gnu.org instead. Please do | |
69 ;; not send bugs or questions to our personal accounts; we reserve the | |
70 ;; right to ignore such email! | |
65 | 71 |
66 ;; 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. |
67 ;; Without their patience, testing, insight, code contributions, and | 73 ;; Without their patience, testing, insight, code contributions, and |
68 ;; encouragement CC Mode would be a far inferior package. | 74 ;; encouragement CC Mode would be a far inferior package. |
69 | 75 |
70 ;; You can get the latest version of CC Mode, including PostScript | 76 ;; You can get the latest version of CC Mode, including PostScript |
71 ;; documentation and separate individual files from: | 77 ;; documentation and separate individual files from: |
72 ;; | 78 ;; |
73 ;; http://www.python.org/ftp/emacs/ | 79 ;; http://www.python.org/emacs/cc-mode/ |
74 | |
75 ;; Or if you don't have access to the World Wide Web, through | |
76 ;; anonymous ftp from: | |
77 ;; | 80 ;; |
78 ;; ftp://ftp.python.org/pub/emacs | 81 ;; You can join a moderated CC Mode announcement-only mailing list by |
82 ;; visiting | |
83 ;; | |
84 ;; http://www.python.org/mailman/listinfo/cc-mode-announce | |
79 | 85 |
80 ;;; Code: | 86 ;;; Code: |
81 | 87 |
82 | 88 |
83 (require 'cc-defs) | 89 (defvar c-buffer-is-cc-mode nil |
84 | 90 "Non-nil for all buffers with a `major-mode' derived from CC Mode. |
85 ;; sigh. give in to the pressure, but make really sure all the | 91 Otherwise, this variable is nil. I.e. this variable is non-nil for |
86 ;; definitions we need are here | 92 `c-mode', `c++-mode', `objc-mode', `java-mode', `idl-mode', |
87 (if (or (not (fboundp 'functionp)) | 93 `pike-mode', and any other non-CC Mode mode that calls |
88 (not (fboundp 'char-before)) | 94 `c-initialize-cc-mode' (e.g. `awk-mode').") |
89 (not (c-safe (char-after) t)) | 95 (make-variable-buffer-local 'c-buffer-is-cc-mode) |
90 (not (fboundp 'when)) | 96 (put 'c-buffer-is-cc-mode 'permanent-local t) |
91 (not (fboundp 'unless))) | 97 |
92 (require 'cc-mode-19)) | 98 (eval-and-compile |
93 | 99 (require 'cc-defs)) |
94 (require 'cc-menus) | 100 (require 'cc-menus) |
95 (require 'cc-vars) | 101 (require 'cc-vars) |
96 (require 'cc-engine) | 102 (require 'cc-engine) |
97 (require 'cc-langs) | 103 (require 'cc-langs) |
98 (require 'cc-align) | 104 (require 'cc-align) |
99 (require 'cc-styles) | 105 (require 'cc-styles) |
100 (require 'cc-cmds) | 106 (require 'cc-cmds) |
101 | 107 |
102 (defvar c-buffer-is-cc-mode nil | |
103 "Non-nil for all buffers with a `major-mode' derived from CC Mode. | |
104 Otherwise, this variable is nil. I.e. this variable is non-nil for | |
105 `c-mode', `c++-mode', `objc-mode', `java-mode', `idl-mode', and any | |
106 other non-CC Mode mode that calls `c-initialize-cc-mode' | |
107 \(e.g. `awk-mode').") | |
108 (make-variable-buffer-local 'c-buffer-is-cc-mode) | |
109 (put 'c-buffer-is-cc-mode 'permanent-local t) | |
110 | |
111 | 108 |
112 | 109 |
113 ;; Other modes and packages which depend on CC Mode should do the | 110 ;; Other modes and packages which depend on CC Mode should do the |
114 ;; following to make sure everything is loaded and available for their | 111 ;; following to make sure everything is loaded and available for their |
115 ;; use: | 112 ;; use: |
116 ;; | 113 ;; |
117 ;; (require 'cc-mode) | 114 ;; (require 'cc-mode) |
118 ;; (c-initialize-cc-mode) | 115 ;; (c-initialize-cc-mode) |
119 | 116 |
120 ;;;###autoload | 117 ;;;###autoload |
121 (defun c-initialize-cc-mode (&optional skip-styles) | 118 (defun c-initialize-cc-mode () |
122 (setq c-buffer-is-cc-mode t) | 119 (setq c-buffer-is-cc-mode t) |
123 (let ((initprop 'cc-mode-is-initialized)) | 120 (let ((initprop 'cc-mode-is-initialized) |
124 ;; run the initialization hook, but only once | 121 c-initialization-ok) |
125 (or (get 'c-initialize-cc-mode initprop) | 122 (unless (get 'c-initialize-cc-mode initprop) |
126 (progn | 123 (put 'c-initialize-cc-mode initprop t) |
127 (or skip-styles | 124 (c-initialize-builtin-style) |
128 (c-initialize-builtin-style)) | 125 (unwind-protect |
129 (run-hooks 'c-initialization-hook) | 126 (progn |
130 (put 'c-initialize-cc-mode initprop t))) | 127 (run-hooks 'c-initialization-hook) |
128 (setq c-initialization-ok t)) | |
129 ;; Will try initialization hooks again if they failed. | |
130 (unless c-initialization-ok | |
131 (put 'c-initialize-cc-mode initprop nil)))) | |
131 )) | 132 )) |
132 | 133 |
133 | 134 |
134 ;;;###autoload | 135 ;;;###autoload |
135 (defun c-mode () | 136 (defun c-mode () |
161 c-conditional-key c-C-conditional-key | 162 c-conditional-key c-C-conditional-key |
162 c-class-key c-C-class-key | 163 c-class-key c-C-class-key |
163 c-baseclass-key nil | 164 c-baseclass-key nil |
164 c-comment-start-regexp c-C++-comment-start-regexp | 165 c-comment-start-regexp c-C++-comment-start-regexp |
165 imenu-generic-expression cc-imenu-c-generic-expression | 166 imenu-generic-expression cc-imenu-c-generic-expression |
166 imenu-case-fold-search nil) | 167 imenu-case-fold-search nil |
168 ) | |
167 (run-hooks 'c-mode-common-hook) | 169 (run-hooks 'c-mode-common-hook) |
168 (run-hooks 'c-mode-hook) | 170 (run-hooks 'c-mode-hook) |
169 (c-update-modeline)) | 171 (c-update-modeline)) |
170 | 172 |
171 | 173 |
198 (setq comment-start "// " | 200 (setq comment-start "// " |
199 comment-end "" | 201 comment-end "" |
200 c-conditional-key c-C++-conditional-key | 202 c-conditional-key c-C++-conditional-key |
201 c-comment-start-regexp c-C++-comment-start-regexp | 203 c-comment-start-regexp c-C++-comment-start-regexp |
202 c-class-key c-C++-class-key | 204 c-class-key c-C++-class-key |
205 c-extra-toplevel-key c-C++-extra-toplevel-key | |
203 c-access-key c-C++-access-key | 206 c-access-key c-C++-access-key |
204 c-recognize-knr-p nil | 207 c-recognize-knr-p nil |
205 imenu-generic-expression cc-imenu-c++-generic-expression | 208 imenu-generic-expression cc-imenu-c++-generic-expression |
206 imenu-case-fold-search nil) | 209 imenu-case-fold-search nil |
210 ) | |
207 (run-hooks 'c-mode-common-hook) | 211 (run-hooks 'c-mode-common-hook) |
208 (run-hooks 'c++-mode-hook) | 212 (run-hooks 'c++-mode-hook) |
209 (c-update-modeline)) | 213 (c-update-modeline)) |
210 | 214 |
211 | 215 |
286 c-class-key c-Java-class-key | 290 c-class-key c-Java-class-key |
287 c-method-key nil | 291 c-method-key nil |
288 c-baseclass-key nil | 292 c-baseclass-key nil |
289 c-recognize-knr-p nil | 293 c-recognize-knr-p nil |
290 c-access-key c-Java-access-key | 294 c-access-key c-Java-access-key |
295 c-inexpr-class-key c-Java-inexpr-class-key | |
291 ;defun-prompt-regexp c-Java-defun-prompt-regexp | 296 ;defun-prompt-regexp c-Java-defun-prompt-regexp |
292 imenu-generic-expression cc-imenu-java-generic-expression | 297 imenu-generic-expression cc-imenu-java-generic-expression |
293 imenu-case-fold-search nil | 298 imenu-case-fold-search nil |
294 ) | 299 ) |
295 (c-set-style "java") | |
296 (run-hooks 'c-mode-common-hook) | 300 (run-hooks 'c-mode-common-hook) |
297 (run-hooks 'java-mode-hook) | 301 (run-hooks 'java-mode-hook) |
298 (c-update-modeline)) | 302 (c-update-modeline)) |
299 | 303 |
300 | 304 |
326 (c-common-init) | 330 (c-common-init) |
327 (setq comment-start "// " | 331 (setq comment-start "// " |
328 comment-end "" | 332 comment-end "" |
329 c-conditional-key c-C++-conditional-key | 333 c-conditional-key c-C++-conditional-key |
330 c-comment-start-regexp c-C++-comment-start-regexp | 334 c-comment-start-regexp c-C++-comment-start-regexp |
331 c-class-key c-C++-class-key | 335 c-class-key c-IDL-class-key |
336 c-extra-toplevel-key c-IDL-extra-toplevel-key | |
332 c-access-key c-C++-access-key | 337 c-access-key c-C++-access-key |
333 c-recognize-knr-p nil | 338 c-recognize-knr-p nil |
334 ;; imenu-generic-expression cc-imenu-c++-generic-expression | 339 ;; imenu-generic-expression cc-imenu-c++-generic-expression |
335 ;; imenu-case-fold-search nil | 340 ;; imenu-case-fold-search nil |
336 ) | 341 ) |
337 (run-hooks 'c-mode-common-hook) | 342 (run-hooks 'c-mode-common-hook) |
338 (run-hooks 'idl-mode-hook) | 343 (run-hooks 'idl-mode-hook) |
339 (c-update-modeline)) | 344 (c-update-modeline)) |
340 | 345 |
341 | 346 |
347 ;;;###autoload | |
348 (defun pike-mode () | |
349 "Major mode for editing Pike code. | |
350 To submit a problem report, enter `\\[c-submit-bug-report]' from an | |
351 idl-mode buffer. This automatically sets up a mail buffer with | |
352 version information already added. You just need to add a description | |
353 of the problem, including a reproducible test case, and send the | |
354 message. | |
355 | |
356 To see what version of CC Mode you are running, enter `\\[c-version]'. | |
357 | |
358 The hook variable `pike-mode-hook' is run with no args, if that value | |
359 is bound and has a non-nil value. Also the common hook | |
360 `c-mode-common-hook' is run first. | |
361 | |
362 Key bindings: | |
363 \\{pike-mode-map}" | |
364 (interactive) | |
365 (c-initialize-cc-mode) | |
366 (kill-all-local-variables) | |
367 (set-syntax-table pike-mode-syntax-table) | |
368 (setq major-mode 'pike-mode | |
369 mode-name "Pike" | |
370 local-abbrev-table pike-mode-abbrev-table) | |
371 (use-local-map pike-mode-map) | |
372 (c-common-init) | |
373 (setq comment-start "// " | |
374 comment-end "" | |
375 c-conditional-key c-Pike-conditional-key | |
376 c-class-key c-Pike-class-key | |
377 c-method-key nil | |
378 c-baseclass-key nil | |
379 c-recognize-knr-p nil | |
380 c-access-key c-Pike-access-key | |
381 c-lambda-key c-Pike-lambda-key | |
382 c-inexpr-block-key c-Pike-inexpr-block-key | |
383 c-special-brace-lists c-Pike-special-brace-lists | |
384 ;imenu-generic-expression cc-imenu-java-generic-expression ;FIXME | |
385 ;imenu-case-fold-search nil ;FIXME | |
386 ) | |
387 (run-hooks 'c-mode-common-hook) | |
388 (run-hooks 'pike-mode-hook) | |
389 (c-update-modeline)) | |
390 | |
391 | |
342 ;; bug reporting | 392 ;; bug reporting |
343 | 393 |
344 (defconst c-mode-help-address | 394 (defconst c-mode-help-address |
345 "bug-gnu-emacs@prep.ai.mit.edu, cc-mode-help@python.org" | 395 "bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org" |
346 "Address for CC Mode bug reports.") | 396 "Addresses for CC Mode bug reports.") |
347 | 397 |
348 (defun c-version () | 398 (defun c-version () |
349 "Echo the current version of CC Mode in the minibuffer." | 399 "Echo the current version of CC Mode in the minibuffer." |
350 (interactive) | 400 (interactive) |
351 (message "Using CC Mode version %s" c-version) | 401 (message "Using CC Mode version %s" c-version) |
371 (concat "CC Mode " c-version " (" | 421 (concat "CC Mode " c-version " (" |
372 (cond ((eq major-mode 'c++-mode) "C++") | 422 (cond ((eq major-mode 'c++-mode) "C++") |
373 ((eq major-mode 'c-mode) "C") | 423 ((eq major-mode 'c-mode) "C") |
374 ((eq major-mode 'objc-mode) "ObjC") | 424 ((eq major-mode 'objc-mode) "ObjC") |
375 ((eq major-mode 'java-mode) "Java") | 425 ((eq major-mode 'java-mode) "Java") |
426 ((eq major-mode 'pike-mode) "Pike") | |
376 ) | 427 ) |
377 ")") | 428 ")") |
378 (let ((vars (list | 429 (let ((vars (list |
379 ;; report only the vars that affect indentation | 430 ;; report only the vars that affect indentation |
380 'c-basic-offset | 431 'c-basic-offset |
392 'c-tab-always-indent | 443 'c-tab-always-indent |
393 'c-comment-continuation-stars | 444 'c-comment-continuation-stars |
394 'c-label-minimum-indentation | 445 'c-label-minimum-indentation |
395 'defun-prompt-regexp | 446 'defun-prompt-regexp |
396 'tab-width | 447 'tab-width |
448 'comment-column | |
449 ;; A brain-damaged XEmacs only variable that, if | |
450 ;; set to nil can cause all kinds of chaos. | |
451 'signal-error-on-buffer-boundary | |
397 ))) | 452 ))) |
398 (if (not (boundp 'defun-prompt-regexp)) | 453 (if (not (boundp 'defun-prompt-regexp)) |
399 (delq 'defun-prompt-regexp vars) | 454 (delq 'defun-prompt-regexp vars) |
400 vars)) | 455 vars)) |
401 (function | 456 (function |
402 (lambda () | 457 (lambda () |
403 (insert | 458 (insert |
404 "Buffer Style: " style "\n\n" | 459 "Buffer Style: " style "\n\n" |
405 (if hook | 460 (if (and hook |
461 (or (/= (length hook) 1) | |
462 (not (eq (car hook) 'c-gnu-impose-minimum)) | |
463 )) | |
406 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" | 464 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" |
407 "c-special-indent-hook is set to '" | 465 "c-special-indent-hook is set to '" |
408 (format "%s" hook) | 466 (format "%s" hook) |
409 ".\nPerhaps this is your problem?\n" | 467 ".\nPerhaps this is your problem?\n" |
410 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n") | 468 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n") |