Mercurial > emacs
comparison lisp/progmodes/cc-mode.el @ 18720:fc6d08b9bbe2
Initial revision
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 10 Jul 1997 07:54:06 +0000 |
parents | |
children | dd7615d21a97 |
comparison
equal
deleted
inserted
replaced
18719:de8249499f33 | 18720:fc6d08b9bbe2 |
---|---|
1 ;;; cc-mode.el --- major mode for editing C, C++, Objective-C, and Java code | |
2 | |
3 ;; Copyright (C) 1985,87,92,93,94,95,96,97 Free Software Foundation, Inc. | |
4 | |
5 ;; Authors: 1992-1997 Barry A. Warsaw | |
6 ;; 1987 Dave Detlefs and Stewart Clamen | |
7 ;; 1985 Richard M. Stallman | |
8 ;; Maintainer: cc-mode-help@python.org | |
9 ;; Created: a long, long, time ago. adapted from the original c-mode.el | |
10 ;; Version: 5.12 | |
11 ;; Keywords: c languages oop | |
12 | |
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! | |
15 | |
16 ;; This file is part of GNU Emacs. | |
17 | |
18 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
19 ;; it under the terms of the GNU General Public License as published by | |
20 ;; the Free Software Foundation; either version 2, or (at your option) | |
21 ;; any later version. | |
22 | |
23 ;; GNU Emacs is distributed in the hope that it will be useful, | |
24 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
26 ;; GNU General Public License for more details. | |
27 | |
28 ;; You should have received a copy of the GNU General Public License | |
29 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
30 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
31 ;; Boston, MA 02111-1307, USA. | |
32 | |
33 ;;; Commentary: | |
34 | |
35 ;; This package provides GNU Emacs major modes for editing C, C++, | |
36 ;; Objective-C, and Java code. As of the latest Emacs and XEmacs | |
37 ;; releases, it is the default package for editing these languages. | |
38 ;; This package is called "CC Mode", and should be spelled exactly | |
39 ;; this way. It supports K&R and ANSI C, ANSI C++, Objective-C, and | |
40 ;; Java, with a consistent indentation model across all modes. This | |
41 ;; indentation model is intuitive and very flexible, so that almost | |
42 ;; any desired style of indentation can be supported. Installation, | |
43 ;; usage, and programming details are contained in an accompanying | |
44 ;; texinfo manual. | |
45 | |
46 ;; CC Mode's immediate ancestors were, c++-mode.el, cplus-md.el, and | |
47 ;; cplus-md1.el.. | |
48 | |
49 ;; NOTE: This mode does not perform font-locking (a.k.a syntactic | |
50 ;; coloring, keyword highlighting, etc.) for any of the supported | |
51 ;; modes. Typically this is done by a package called font-lock.el | |
52 ;; which I do *not* maintain. You should contact the Emacs | |
53 ;; maintainers for questions about coloring or highlighting in any | |
54 ;; language mode. | |
55 | |
56 ;; To submit bug reports, type "C-c C-b". These will be sent to | |
57 ;; bug-gnu-emacs@prep.ai.mit.edu as well as cc-mode-help@python.org, | |
58 ;; and I'll read about them there (the former is mirrored as the | |
59 ;; Usenet newsgroup gnu.emacs.bug). Questions can sent to | |
60 ;; help-gnu-emacs@prep.ai.mit.edu (mirrored as gnu.emacs.help) and/or | |
61 ;; cc-mode-help@python.org. Please do not send bugs or questions to | |
62 ;; my personal account. | |
63 | |
64 ;; YOU CAN IGNORE ALL BYTE-COMPILER WARNINGS. They are the result of | |
65 ;; the cross-Emacsen support. GNU Emacs 19 (from the FSF), GNU XEmacs | |
66 ;; 19 (formerly Lucid Emacs), and GNU Emacs 18 all do things | |
67 ;; differently and there's no way to shut the byte-compiler up at the | |
68 ;; necessary granularity. Let me say this again: YOU CAN IGNORE ALL | |
69 ;; BYTE-COMPILER WARNINGS (you'd be surprised at how many people don't | |
70 ;; follow this advice :-). | |
71 | |
72 ;; Many, many thanks go out to all the folks on the beta test list. | |
73 ;; Without their patience, testing, insight, code contributions, and | |
74 ;; encouragement CC Mode would be a far inferior package. | |
75 | |
76 ;; You can get the latest version of CC Mode, including PostScript | |
77 ;; documentation and separate individual files from: | |
78 ;; | |
79 ;; http://www.python.org/ftp/emacs/ | |
80 | |
81 ;; Or if you don't have access to the World Wide Web, through | |
82 ;; anonymous ftp from: | |
83 ;; | |
84 ;; ftp://ftp.python.org/pub/emacs | |
85 | |
86 ;;; Code: | |
87 | |
88 (eval-when-compile | |
89 (require 'cc-menus)) | |
90 (require 'cc-defs) | |
91 | |
92 | |
93 ;;;###autoload | |
94 (defun c-mode () | |
95 "Major mode for editing K&R and ANSI C code. | |
96 To submit a problem report, enter `\\[c-submit-bug-report]' from a | |
97 c-mode buffer. This automatically sets up a mail buffer with version | |
98 information already added. You just need to add a description of the | |
99 problem, including a reproducible test case and send the message. | |
100 | |
101 To see what version of CC Mode you are running, enter `\\[c-version]'. | |
102 | |
103 The hook variable `c-mode-hook' is run with no args, if that value is | |
104 bound and has a non-nil value. Also the hook `c-mode-common-hook' is | |
105 run first. | |
106 | |
107 Key bindings: | |
108 \\{c-mode-map}" | |
109 (interactive) | |
110 (c-load-all) | |
111 (kill-all-local-variables) | |
112 (set-syntax-table c-mode-syntax-table) | |
113 (setq major-mode 'c-mode | |
114 mode-name "C" | |
115 local-abbrev-table c-mode-abbrev-table) | |
116 (use-local-map c-mode-map) | |
117 (c-common-init) | |
118 (setq comment-start "/* " | |
119 comment-end " */" | |
120 comment-multi-line t | |
121 c-conditional-key c-C-conditional-key | |
122 c-class-key c-C-class-key | |
123 c-baseclass-key nil | |
124 c-comment-start-regexp c-C-comment-start-regexp | |
125 imenu-generic-expression cc-imenu-c-generic-expression) | |
126 (run-hooks 'c-mode-common-hook) | |
127 (run-hooks 'c-mode-hook) | |
128 (c-update-modeline)) | |
129 | |
130 | |
131 ;;;###autoload | |
132 (defun c++-mode () | |
133 "Major mode for editing C++ code. | |
134 To submit a problem report, enter `\\[c-submit-bug-report]' from a | |
135 c++-mode buffer. This automatically sets up a mail buffer with | |
136 version information already added. You just need to add a description | |
137 of the problem, including a reproducible test case, and send the | |
138 message. | |
139 | |
140 To see what version of CC Mode you are running, enter `\\[c-version]'. | |
141 | |
142 The hook variable `c++-mode-hook' is run with no args, if that | |
143 variable is bound and has a non-nil value. Also the hook | |
144 `c-mode-common-hook' is run first. | |
145 | |
146 Key bindings: | |
147 \\{c++-mode-map}" | |
148 (interactive) | |
149 (c-load-all) | |
150 (kill-all-local-variables) | |
151 (set-syntax-table c++-mode-syntax-table) | |
152 (setq major-mode 'c++-mode | |
153 mode-name "C++" | |
154 local-abbrev-table c++-mode-abbrev-table) | |
155 (use-local-map c++-mode-map) | |
156 (c-common-init) | |
157 (setq comment-start "// " | |
158 comment-end "" | |
159 comment-multi-line nil | |
160 c-conditional-key c-C++-conditional-key | |
161 c-comment-start-regexp c-C++-comment-start-regexp | |
162 c-class-key c-C++-class-key | |
163 c-access-key c-C++-access-key | |
164 c-double-slash-is-comments-p t | |
165 c-recognize-knr-p nil | |
166 imenu-generic-expression cc-imenu-c++-generic-expression) | |
167 (run-hooks 'c-mode-common-hook) | |
168 (run-hooks 'c++-mode-hook) | |
169 (c-update-modeline)) | |
170 | |
171 | |
172 ;;;###autoload | |
173 (defun objc-mode () | |
174 "Major mode for editing Objective C code. | |
175 To submit a problem report, enter `\\[c-submit-bug-report]' from an | |
176 objc-mode buffer. This automatically sets up a mail buffer with | |
177 version information already added. You just need to add a description | |
178 of the problem, including a reproducible test case, and send the | |
179 message. | |
180 | |
181 To see what version of CC Mode you are running, enter `\\[c-version]'. | |
182 | |
183 The hook variable `objc-mode-hook' is run with no args, if that value | |
184 is bound and has a non-nil value. Also the hook `c-mode-common-hook' | |
185 is run first. | |
186 | |
187 Key bindings: | |
188 \\{objc-mode-map}" | |
189 (interactive) | |
190 (c-load-all) | |
191 (kill-all-local-variables) | |
192 (set-syntax-table objc-mode-syntax-table) | |
193 (setq major-mode 'objc-mode | |
194 mode-name "ObjC" | |
195 local-abbrev-table objc-mode-abbrev-table) | |
196 (use-local-map objc-mode-map) | |
197 (c-common-init) | |
198 (setq comment-start "// " | |
199 comment-end "" | |
200 comment-multi-line nil | |
201 c-conditional-key c-C-conditional-key | |
202 c-comment-start-regexp c-C++-comment-start-regexp | |
203 c-class-key c-ObjC-class-key | |
204 c-baseclass-key nil | |
205 c-access-key c-ObjC-access-key | |
206 c-double-slash-is-comments-p t | |
207 c-method-key c-ObjC-method-key) | |
208 (run-hooks 'c-mode-common-hook) | |
209 (run-hooks 'objc-mode-hook) | |
210 (c-update-modeline)) | |
211 | |
212 | |
213 ;;;###autoload | |
214 (defun java-mode () | |
215 "Major mode for editing Java code. | |
216 To submit a problem report, enter `\\[c-submit-bug-report]' from an | |
217 java-mode buffer. This automatically sets up a mail buffer with | |
218 version information already added. You just need to add a description | |
219 of the problem, including a reproducible test case and send the | |
220 message. | |
221 | |
222 To see what version of CC Mode you are running, enter `\\[c-version]'. | |
223 | |
224 The hook variable `java-mode-hook' is run with no args, if that value | |
225 is bound and has a non-nil value. Also the common hook | |
226 `c-mode-common-hook' is run first. Note that this mode automatically | |
227 sets the \"java\" style before calling any hooks so be careful if you | |
228 set styles in `c-mode-common-hook'. | |
229 | |
230 Key bindings: | |
231 \\{java-mode-map}" | |
232 (interactive) | |
233 (c-load-all) | |
234 (kill-all-local-variables) | |
235 (set-syntax-table java-mode-syntax-table) | |
236 (setq major-mode 'java-mode | |
237 mode-name "Java" | |
238 local-abbrev-table java-mode-abbrev-table) | |
239 (use-local-map java-mode-map) | |
240 (c-common-init) | |
241 (setq comment-start "// " | |
242 comment-end "" | |
243 comment-multi-line nil | |
244 c-conditional-key c-Java-conditional-key | |
245 c-comment-start-regexp c-Java-comment-start-regexp | |
246 c-class-key c-Java-class-key | |
247 c-method-key c-Java-method-key | |
248 c-double-slash-is-comments-p t | |
249 c-baseclass-key nil | |
250 c-recognize-knr-p nil | |
251 c-access-key c-Java-access-key | |
252 ;defun-prompt-regexp c-Java-defun-prompt-regexp | |
253 imenu-generic-expression cc-imenu-java-generic-expression | |
254 ) | |
255 (c-set-style "java") | |
256 (run-hooks 'c-mode-common-hook) | |
257 (run-hooks 'java-mode-hook) | |
258 (c-update-modeline)) | |
259 | |
260 | |
261 ;; defuns for submitting bug reports | |
262 (defconst c-version "5.12" | |
263 "CC Mode version number.") | |
264 | |
265 (defconst c-mode-help-address | |
266 "bug-gnu-emacs@prep.ai.mit.edu, cc-mode-help@python.org" | |
267 "Address for CC Mode bug reports.") | |
268 | |
269 (defun c-version () | |
270 "Echo the current version of CC Mode in the minibuffer." | |
271 (interactive) | |
272 (message "Using CC Mode version %s" c-version) | |
273 (c-keep-region-active)) | |
274 | |
275 ;; Get reporter-submit-bug-report when byte-compiling | |
276 (eval-when-compile | |
277 (require 'reporter)) | |
278 | |
279 (defun c-submit-bug-report () | |
280 "Submit via mail a bug report on CC Mode." | |
281 (interactive) | |
282 (require 'cc-vars) | |
283 ;; load in reporter | |
284 (let ((reporter-prompt-for-summary-p t) | |
285 (reporter-dont-compact-list '(c-offsets-alist)) | |
286 (style c-indentation-style) | |
287 (hook c-special-indent-hook) | |
288 (c-features c-emacs-features)) | |
289 (and | |
290 (if (y-or-n-p "Do you want to submit a report on CC Mode? ") | |
291 t (message "") nil) | |
292 (require 'reporter) | |
293 (reporter-submit-bug-report | |
294 c-mode-help-address | |
295 (concat "CC Mode " c-version " (" | |
296 (cond ((eq major-mode 'c++-mode) "C++") | |
297 ((eq major-mode 'c-mode) "C") | |
298 ((eq major-mode 'objc-mode) "ObjC") | |
299 ((eq major-mode 'java-mode) "Java") | |
300 ) | |
301 ")") | |
302 (let ((vars (list | |
303 ;; report only the vars that affect indentation | |
304 'c-basic-offset | |
305 'c-offsets-alist | |
306 'c-cleanup-list | |
307 'c-comment-only-line-offset | |
308 'c-backslash-column | |
309 'c-delete-function | |
310 'c-electric-pound-behavior | |
311 'c-hanging-braces-alist | |
312 'c-hanging-colons-alist | |
313 'c-hanging-comment-starter-p | |
314 'c-hanging-comment-ender-p | |
315 'c-indent-comments-syntactically-p | |
316 'c-tab-always-indent | |
317 'c-recognize-knr-p | |
318 'c-label-minimum-indentation | |
319 'defun-prompt-regexp | |
320 'tab-width | |
321 ))) | |
322 (if (not (boundp 'defun-prompt-regexp)) | |
323 (delq 'defun-prompt-regexp vars) | |
324 vars)) | |
325 (function | |
326 (lambda () | |
327 (insert | |
328 "Buffer Style: " style "\n\n" | |
329 (if hook | |
330 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" | |
331 "c-special-indent-hook is set to '" | |
332 (format "%s" hook) | |
333 ".\nPerhaps this is your problem?\n" | |
334 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n") | |
335 "\n") | |
336 (format "c-emacs-features: %s\n" c-features) | |
337 ))) | |
338 nil | |
339 "Dear Barry," | |
340 )))) | |
341 | |
342 | |
343 (provide 'cc-mode) | |
344 ;;; cc-mode.el ends here |