Commit | Line | Data |
---|---|---|
785eecbb RS |
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 | |
611c76a7 | 10 | ;; Version: 5.15 |
785eecbb RS |
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++, | |
aac90c52 | 36 | ;; Objective-C, Java and IDL code. As of the latest Emacs and XEmacs |
785eecbb RS |
37 | ;; releases, it is the default package for editing these languages. |
38 | ;; This package is called "CC Mode", and should be spelled exactly | |
aac90c52 RS |
39 | ;; this way. It supports K&R and ANSI C, ANSI C++, Objective-C, Java, |
40 | ;; and CORBA's IDL with a consistent indentation model across all | |
41 | ;; modes. This indentation model is intuitive and very flexible, so | |
42 | ;; that almost any desired style of indentation can be supported. | |
43 | ;; Installation, usage, and programming details are contained in an | |
44 | ;; accompanying texinfo manual. | |
785eecbb RS |
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 | ||
785eecbb RS |
64 | ;; Many, many thanks go out to all the folks on the beta test list. |
65 | ;; Without their patience, testing, insight, code contributions, and | |
66 | ;; encouragement CC Mode would be a far inferior package. | |
67 | ||
68 | ;; You can get the latest version of CC Mode, including PostScript | |
69 | ;; documentation and separate individual files from: | |
70 | ;; | |
71 | ;; http://www.python.org/ftp/emacs/ | |
72 | ||
73 | ;; Or if you don't have access to the World Wide Web, through | |
74 | ;; anonymous ftp from: | |
75 | ;; | |
76 | ;; ftp://ftp.python.org/pub/emacs | |
77 | ||
78 | ;;; Code: | |
79 | ||
80 | (eval-when-compile | |
81 | (require 'cc-menus)) | |
82 | (require 'cc-defs) | |
83 | ||
84 | \f | |
1dad6919 RS |
85 | ;; Other modes and packages which depend on CC Mode should do the |
86 | ;; following to make sure everything is loaded and available for their | |
87 | ;; use: | |
88 | ;; | |
89 | ;; (require 'cc-mode) | |
90 | ;; (c-initialize-cc-mode) | |
91 | ||
aac90c52 | 92 | ;;;###autoload |
1dad6919 | 93 | (defun c-initialize-cc-mode () |
611c76a7 RS |
94 | (setq c-buffer-is-cc-mode t) |
95 | ;; sigh. give in to the pressure, but make really sure all the | |
96 | ;; definitions we need are here | |
97 | (if (or (not (fboundp 'functionp)) | |
98 | (not (fboundp 'char-before)) | |
99 | (not (c-safe (char-after) t))) | |
100 | (require 'cc-mode-19)) | |
1dad6919 | 101 | ;; make sure all necessary components of CC Mode are loaded in. |
aac90c52 RS |
102 | (let ((initprop 'cc-mode-is-initialized)) |
103 | (require 'cc-vars) | |
104 | (require 'cc-engine) | |
105 | (require 'cc-langs) | |
106 | (require 'cc-menus) | |
107 | (require 'cc-align) | |
108 | (require 'cc-styles) | |
109 | (require 'cc-cmds) | |
110 | ;; run the initialization hook, but only once | |
111 | (or (get 'c-initialize-cc-mode initprop) | |
112 | (progn | |
113 | (c-initialize-builtin-style) | |
114 | (run-hooks 'c-initialization-hook) | |
115 | (put 'c-initialize-cc-mode initprop t))) | |
116 | )) | |
1dad6919 RS |
117 | |
118 | \f | |
785eecbb RS |
119 | ;;;###autoload |
120 | (defun c-mode () | |
121 | "Major mode for editing K&R and ANSI C code. | |
122 | To submit a problem report, enter `\\[c-submit-bug-report]' from a | |
123 | c-mode buffer. This automatically sets up a mail buffer with version | |
124 | information already added. You just need to add a description of the | |
125 | problem, including a reproducible test case and send the message. | |
126 | ||
127 | To see what version of CC Mode you are running, enter `\\[c-version]'. | |
128 | ||
129 | The hook variable `c-mode-hook' is run with no args, if that value is | |
130 | bound and has a non-nil value. Also the hook `c-mode-common-hook' is | |
131 | run first. | |
132 | ||
133 | Key bindings: | |
134 | \\{c-mode-map}" | |
135 | (interactive) | |
1dad6919 | 136 | (c-initialize-cc-mode) |
785eecbb RS |
137 | (kill-all-local-variables) |
138 | (set-syntax-table c-mode-syntax-table) | |
139 | (setq major-mode 'c-mode | |
140 | mode-name "C" | |
141 | local-abbrev-table c-mode-abbrev-table) | |
142 | (use-local-map c-mode-map) | |
143 | (c-common-init) | |
144 | (setq comment-start "/* " | |
145 | comment-end " */" | |
785eecbb RS |
146 | c-conditional-key c-C-conditional-key |
147 | c-class-key c-C-class-key | |
148 | c-baseclass-key nil | |
611c76a7 | 149 | c-comment-start-regexp c-C++-comment-start-regexp |
785eecbb RS |
150 | imenu-generic-expression cc-imenu-c-generic-expression) |
151 | (run-hooks 'c-mode-common-hook) | |
152 | (run-hooks 'c-mode-hook) | |
153 | (c-update-modeline)) | |
154 | ||
155 | \f | |
156 | ;;;###autoload | |
157 | (defun c++-mode () | |
158 | "Major mode for editing C++ code. | |
159 | To submit a problem report, enter `\\[c-submit-bug-report]' from a | |
160 | c++-mode buffer. This automatically sets up a mail buffer with | |
161 | version information already added. You just need to add a description | |
162 | of the problem, including a reproducible test case, and send the | |
163 | message. | |
164 | ||
165 | To see what version of CC Mode you are running, enter `\\[c-version]'. | |
166 | ||
167 | The hook variable `c++-mode-hook' is run with no args, if that | |
168 | variable is bound and has a non-nil value. Also the hook | |
169 | `c-mode-common-hook' is run first. | |
170 | ||
171 | Key bindings: | |
172 | \\{c++-mode-map}" | |
173 | (interactive) | |
1dad6919 | 174 | (c-initialize-cc-mode) |
785eecbb RS |
175 | (kill-all-local-variables) |
176 | (set-syntax-table c++-mode-syntax-table) | |
177 | (setq major-mode 'c++-mode | |
178 | mode-name "C++" | |
179 | local-abbrev-table c++-mode-abbrev-table) | |
180 | (use-local-map c++-mode-map) | |
181 | (c-common-init) | |
182 | (setq comment-start "// " | |
183 | comment-end "" | |
785eecbb RS |
184 | c-conditional-key c-C++-conditional-key |
185 | c-comment-start-regexp c-C++-comment-start-regexp | |
186 | c-class-key c-C++-class-key | |
187 | c-access-key c-C++-access-key | |
188 | c-double-slash-is-comments-p t | |
189 | c-recognize-knr-p nil | |
190 | imenu-generic-expression cc-imenu-c++-generic-expression) | |
191 | (run-hooks 'c-mode-common-hook) | |
192 | (run-hooks 'c++-mode-hook) | |
193 | (c-update-modeline)) | |
194 | ||
195 | \f | |
196 | ;;;###autoload | |
197 | (defun objc-mode () | |
198 | "Major mode for editing Objective C code. | |
199 | To submit a problem report, enter `\\[c-submit-bug-report]' from an | |
200 | objc-mode buffer. This automatically sets up a mail buffer with | |
201 | version information already added. You just need to add a description | |
202 | of the problem, including a reproducible test case, and send the | |
203 | message. | |
204 | ||
205 | To see what version of CC Mode you are running, enter `\\[c-version]'. | |
206 | ||
207 | The hook variable `objc-mode-hook' is run with no args, if that value | |
208 | is bound and has a non-nil value. Also the hook `c-mode-common-hook' | |
209 | is run first. | |
210 | ||
211 | Key bindings: | |
212 | \\{objc-mode-map}" | |
213 | (interactive) | |
1dad6919 | 214 | (c-initialize-cc-mode) |
785eecbb RS |
215 | (kill-all-local-variables) |
216 | (set-syntax-table objc-mode-syntax-table) | |
217 | (setq major-mode 'objc-mode | |
218 | mode-name "ObjC" | |
219 | local-abbrev-table objc-mode-abbrev-table) | |
220 | (use-local-map objc-mode-map) | |
221 | (c-common-init) | |
222 | (setq comment-start "// " | |
223 | comment-end "" | |
785eecbb RS |
224 | c-conditional-key c-C-conditional-key |
225 | c-comment-start-regexp c-C++-comment-start-regexp | |
226 | c-class-key c-ObjC-class-key | |
227 | c-baseclass-key nil | |
228 | c-access-key c-ObjC-access-key | |
229 | c-double-slash-is-comments-p t | |
230 | c-method-key c-ObjC-method-key) | |
231 | (run-hooks 'c-mode-common-hook) | |
232 | (run-hooks 'objc-mode-hook) | |
233 | (c-update-modeline)) | |
234 | ||
235 | \f | |
236 | ;;;###autoload | |
237 | (defun java-mode () | |
238 | "Major mode for editing Java code. | |
239 | To submit a problem report, enter `\\[c-submit-bug-report]' from an | |
240 | java-mode buffer. This automatically sets up a mail buffer with | |
241 | version information already added. You just need to add a description | |
242 | of the problem, including a reproducible test case and send the | |
243 | message. | |
244 | ||
245 | To see what version of CC Mode you are running, enter `\\[c-version]'. | |
246 | ||
247 | The hook variable `java-mode-hook' is run with no args, if that value | |
248 | is bound and has a non-nil value. Also the common hook | |
249 | `c-mode-common-hook' is run first. Note that this mode automatically | |
250 | sets the \"java\" style before calling any hooks so be careful if you | |
251 | set styles in `c-mode-common-hook'. | |
252 | ||
253 | Key bindings: | |
254 | \\{java-mode-map}" | |
255 | (interactive) | |
1dad6919 | 256 | (c-initialize-cc-mode) |
785eecbb RS |
257 | (kill-all-local-variables) |
258 | (set-syntax-table java-mode-syntax-table) | |
259 | (setq major-mode 'java-mode | |
260 | mode-name "Java" | |
261 | local-abbrev-table java-mode-abbrev-table) | |
262 | (use-local-map java-mode-map) | |
263 | (c-common-init) | |
264 | (setq comment-start "// " | |
265 | comment-end "" | |
785eecbb RS |
266 | c-conditional-key c-Java-conditional-key |
267 | c-comment-start-regexp c-Java-comment-start-regexp | |
268 | c-class-key c-Java-class-key | |
269 | c-method-key c-Java-method-key | |
270 | c-double-slash-is-comments-p t | |
271 | c-baseclass-key nil | |
272 | c-recognize-knr-p nil | |
273 | c-access-key c-Java-access-key | |
274 | ;defun-prompt-regexp c-Java-defun-prompt-regexp | |
275 | imenu-generic-expression cc-imenu-java-generic-expression | |
276 | ) | |
277 | (c-set-style "java") | |
278 | (run-hooks 'c-mode-common-hook) | |
279 | (run-hooks 'java-mode-hook) | |
280 | (c-update-modeline)) | |
281 | ||
282 | \f | |
aac90c52 RS |
283 | ;;;###autoload |
284 | (defun idl-mode () | |
285 | "Major mode for editing CORBA's IDL code. | |
286 | To submit a problem report, enter `\\[c-submit-bug-report]' from an | |
287 | idl-mode buffer. This automatically sets up a mail buffer with | |
288 | version information already added. You just need to add a description | |
289 | of the problem, including a reproducible test case, and send the | |
290 | message. | |
291 | ||
292 | To see what version of CC Mode you are running, enter `\\[c-version]'. | |
293 | ||
294 | The hook variable `idl-mode-hook' is run with no args, if that | |
295 | variable is bound and has a non-nil value. Also the hook | |
296 | `c-mode-common-hook' is run first. | |
297 | ||
298 | Key bindings: | |
299 | \\{idl-mode-map}" | |
300 | (interactive) | |
301 | (c-initialize-cc-mode) | |
302 | (kill-all-local-variables) | |
303 | (set-syntax-table idl-mode-syntax-table) | |
304 | (setq major-mode 'idl-mode | |
305 | mode-name "IDL" | |
306 | local-abbrev-table idl-mode-abbrev-table) | |
307 | (use-local-map idl-mode-map) | |
308 | (c-common-init) | |
309 | (setq comment-start "// " | |
310 | comment-end "" | |
aac90c52 RS |
311 | c-conditional-key c-C++-conditional-key |
312 | c-comment-start-regexp c-C++-comment-start-regexp | |
313 | c-class-key c-C++-class-key | |
314 | c-access-key c-C++-access-key | |
315 | c-double-slash-is-comments-p t | |
316 | c-recognize-knr-p nil) | |
317 | ;; imenu-generic-expression cc-imenu-c++-generic-expression) | |
318 | (run-hooks 'c-mode-common-hook) | |
319 | (run-hooks 'idl-mode-hook) | |
320 | (c-update-modeline)) | |
321 | ||
322 | \f | |
785eecbb | 323 | ;; defuns for submitting bug reports |
611c76a7 | 324 | (defconst c-version "5.15" |
785eecbb RS |
325 | "CC Mode version number.") |
326 | ||
327 | (defconst c-mode-help-address | |
328 | "bug-gnu-emacs@prep.ai.mit.edu, cc-mode-help@python.org" | |
329 | "Address for CC Mode bug reports.") | |
330 | ||
331 | (defun c-version () | |
332 | "Echo the current version of CC Mode in the minibuffer." | |
333 | (interactive) | |
334 | (message "Using CC Mode version %s" c-version) | |
335 | (c-keep-region-active)) | |
336 | ||
337 | ;; Get reporter-submit-bug-report when byte-compiling | |
338 | (eval-when-compile | |
339 | (require 'reporter)) | |
340 | ||
341 | (defun c-submit-bug-report () | |
342 | "Submit via mail a bug report on CC Mode." | |
343 | (interactive) | |
344 | (require 'cc-vars) | |
345 | ;; load in reporter | |
346 | (let ((reporter-prompt-for-summary-p t) | |
347 | (reporter-dont-compact-list '(c-offsets-alist)) | |
348 | (style c-indentation-style) | |
349 | (hook c-special-indent-hook) | |
350 | (c-features c-emacs-features)) | |
351 | (and | |
352 | (if (y-or-n-p "Do you want to submit a report on CC Mode? ") | |
353 | t (message "") nil) | |
354 | (require 'reporter) | |
355 | (reporter-submit-bug-report | |
356 | c-mode-help-address | |
357 | (concat "CC Mode " c-version " (" | |
358 | (cond ((eq major-mode 'c++-mode) "C++") | |
359 | ((eq major-mode 'c-mode) "C") | |
360 | ((eq major-mode 'objc-mode) "ObjC") | |
361 | ((eq major-mode 'java-mode) "Java") | |
362 | ) | |
363 | ")") | |
364 | (let ((vars (list | |
365 | ;; report only the vars that affect indentation | |
366 | 'c-basic-offset | |
367 | 'c-offsets-alist | |
368 | 'c-cleanup-list | |
369 | 'c-comment-only-line-offset | |
370 | 'c-backslash-column | |
371 | 'c-delete-function | |
372 | 'c-electric-pound-behavior | |
373 | 'c-hanging-braces-alist | |
374 | 'c-hanging-colons-alist | |
375 | 'c-hanging-comment-starter-p | |
376 | 'c-hanging-comment-ender-p | |
377 | 'c-indent-comments-syntactically-p | |
378 | 'c-tab-always-indent | |
379 | 'c-recognize-knr-p | |
380 | 'c-label-minimum-indentation | |
381 | 'defun-prompt-regexp | |
382 | 'tab-width | |
383 | ))) | |
384 | (if (not (boundp 'defun-prompt-regexp)) | |
385 | (delq 'defun-prompt-regexp vars) | |
386 | vars)) | |
387 | (function | |
388 | (lambda () | |
389 | (insert | |
390 | "Buffer Style: " style "\n\n" | |
391 | (if hook | |
392 | (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" | |
393 | "c-special-indent-hook is set to '" | |
394 | (format "%s" hook) | |
395 | ".\nPerhaps this is your problem?\n" | |
396 | "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n") | |
397 | "\n") | |
398 | (format "c-emacs-features: %s\n" c-features) | |
399 | ))) | |
400 | nil | |
401 | "Dear Barry," | |
402 | )))) | |
403 | ||
404 | \f | |
405 | (provide 'cc-mode) | |
406 | ;;; cc-mode.el ends here |