1 ;;; cc-mode.el --- major mode for editing C, C++, Objective-C, and Java code
3 ;; Copyright (C) 1985,87,92,93,94,95,96,97 Free Software Foundation, Inc.
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
11 ;; Keywords: c languages oop
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!
16 ;; This file is part of GNU Emacs.
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)
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.
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.
35 ;; This package provides GNU Emacs major modes for editing C, C++,
36 ;; Objective-C, Java and IDL 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, 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.
46 ;; CC Mode's immediate ancestors were, c++-mode.el, cplus-md.el, and
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
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.
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.
68 ;; You can get the latest version of CC Mode, including PostScript
69 ;; documentation and separate individual files from:
71 ;; http://www.python.org/ftp/emacs/
73 ;; Or if you don't have access to the World Wide Web, through
74 ;; anonymous ftp from:
76 ;; ftp://ftp.python.org/pub/emacs
84 (defvar c-buffer-is-cc-mode nil
85 "Non-nil for all buffers with a `major-mode' derived from CC Mode.
86 Otherwise, this variable is nil. I.e. this variable is non-nil for
87 `c-mode', `c++-mode', `objc-mode', `java-mode', `idl-mode', and any
88 other non-CC Mode mode that calls `c-initialize-cc-mode'
90 (make-variable-buffer-local 'c-buffer-is-cc-mode)
91 (put 'c-buffer-is-cc-mode 'permanent-local t)
94 ;; Other modes and packages which depend on CC Mode should do the
95 ;; following to make sure everything is loaded and available for their
99 ;; (c-initialize-cc-mode)
102 (defun c-initialize-cc-mode ()
103 (setq c-buffer-is-cc-mode t)
104 ;; sigh. give in to the pressure, but make really sure all the
105 ;; definitions we need are here
106 (if (or (not (fboundp 'functionp))
107 (not (fboundp 'char-before))
108 (not (c-safe (char-after) t)))
109 (require 'cc-mode-19))
110 ;; make sure all necessary components of CC Mode are loaded in.
111 (let ((initprop 'cc-mode-is-initialized))
119 ;; run the initialization hook, but only once
120 (or (get 'c-initialize-cc-mode initprop)
122 (c-initialize-builtin-style)
123 (run-hooks 'c-initialization-hook)
124 (put 'c-initialize-cc-mode initprop t)))
130 "Major mode for editing K&R and ANSI C code.
131 To submit a problem report, enter `\\[c-submit-bug-report]' from a
132 c-mode buffer. This automatically sets up a mail buffer with version
133 information already added. You just need to add a description of the
134 problem, including a reproducible test case and send the message.
136 To see what version of CC Mode you are running, enter `\\[c-version]'.
138 The hook variable `c-mode-hook' is run with no args, if that value is
139 bound and has a non-nil value. Also the hook `c-mode-common-hook' is
145 (c-initialize-cc-mode)
146 (kill-all-local-variables)
147 (set-syntax-table c-mode-syntax-table)
148 (setq major-mode 'c-mode
150 local-abbrev-table c-mode-abbrev-table)
151 (use-local-map c-mode-map)
153 (setq comment-start "/* "
155 c-conditional-key c-C-conditional-key
156 c-class-key c-C-class-key
158 c-comment-start-regexp c-C++-comment-start-regexp
159 imenu-generic-expression cc-imenu-c-generic-expression)
160 (run-hooks 'c-mode-common-hook)
161 (run-hooks 'c-mode-hook)
167 "Major mode for editing C++ code.
168 To submit a problem report, enter `\\[c-submit-bug-report]' from a
169 c++-mode buffer. This automatically sets up a mail buffer with
170 version information already added. You just need to add a description
171 of the problem, including a reproducible test case, and send the
174 To see what version of CC Mode you are running, enter `\\[c-version]'.
176 The hook variable `c++-mode-hook' is run with no args, if that
177 variable is bound and has a non-nil value. Also the hook
178 `c-mode-common-hook' is run first.
183 (c-initialize-cc-mode)
184 (kill-all-local-variables)
185 (set-syntax-table c++-mode-syntax-table)
186 (setq major-mode 'c++-mode
188 local-abbrev-table c++-mode-abbrev-table)
189 (use-local-map c++-mode-map)
191 (setq comment-start "// "
193 c-conditional-key c-C++-conditional-key
194 c-comment-start-regexp c-C++-comment-start-regexp
195 c-class-key c-C++-class-key
196 c-access-key c-C++-access-key
197 c-recognize-knr-p nil
198 imenu-generic-expression cc-imenu-c++-generic-expression)
199 (run-hooks 'c-mode-common-hook)
200 (run-hooks 'c++-mode-hook)
206 "Major mode for editing Objective C code.
207 To submit a problem report, enter `\\[c-submit-bug-report]' from an
208 objc-mode buffer. This automatically sets up a mail buffer with
209 version information already added. You just need to add a description
210 of the problem, including a reproducible test case, and send the
213 To see what version of CC Mode you are running, enter `\\[c-version]'.
215 The hook variable `objc-mode-hook' is run with no args, if that value
216 is bound and has a non-nil value. Also the hook `c-mode-common-hook'
222 (c-initialize-cc-mode)
223 (kill-all-local-variables)
224 (set-syntax-table objc-mode-syntax-table)
225 (setq major-mode 'objc-mode
227 local-abbrev-table objc-mode-abbrev-table)
228 (use-local-map objc-mode-map)
230 (setq comment-start "// "
232 c-conditional-key c-C-conditional-key
233 c-comment-start-regexp c-C++-comment-start-regexp
234 c-class-key c-ObjC-class-key
236 c-access-key c-ObjC-access-key
237 c-method-key c-ObjC-method-key)
238 (run-hooks 'c-mode-common-hook)
239 (run-hooks 'objc-mode-hook)
245 "Major mode for editing Java code.
246 To submit a problem report, enter `\\[c-submit-bug-report]' from an
247 java-mode buffer. This automatically sets up a mail buffer with
248 version information already added. You just need to add a description
249 of the problem, including a reproducible test case and send the
252 To see what version of CC Mode you are running, enter `\\[c-version]'.
254 The hook variable `java-mode-hook' is run with no args, if that value
255 is bound and has a non-nil value. Also the common hook
256 `c-mode-common-hook' is run first. Note that this mode automatically
257 sets the \"java\" style before calling any hooks so be careful if you
258 set styles in `c-mode-common-hook'.
263 (c-initialize-cc-mode)
264 (kill-all-local-variables)
265 (set-syntax-table java-mode-syntax-table)
266 (setq major-mode 'java-mode
268 local-abbrev-table java-mode-abbrev-table)
269 (use-local-map java-mode-map)
271 (setq comment-start "// "
273 c-conditional-key c-Java-conditional-key
274 c-comment-start-regexp c-Java-comment-start-regexp
275 c-class-key c-Java-class-key
276 c-method-key c-Java-method-key
278 c-recognize-knr-p nil
279 c-access-key c-Java-access-key
280 ;defun-prompt-regexp c-Java-defun-prompt-regexp
281 imenu-generic-expression cc-imenu-java-generic-expression
284 (run-hooks 'c-mode-common-hook)
285 (run-hooks 'java-mode-hook)
291 "Major mode for editing CORBA's IDL code.
292 To submit a problem report, enter `\\[c-submit-bug-report]' from an
293 idl-mode buffer. This automatically sets up a mail buffer with
294 version information already added. You just need to add a description
295 of the problem, including a reproducible test case, and send the
298 To see what version of CC Mode you are running, enter `\\[c-version]'.
300 The hook variable `idl-mode-hook' is run with no args, if that
301 variable is bound and has a non-nil value. Also the hook
302 `c-mode-common-hook' is run first.
307 (c-initialize-cc-mode)
308 (kill-all-local-variables)
309 (set-syntax-table idl-mode-syntax-table)
310 (setq major-mode 'idl-mode
312 local-abbrev-table idl-mode-abbrev-table)
313 (use-local-map idl-mode-map)
315 (setq comment-start "// "
317 c-conditional-key c-C++-conditional-key
318 c-comment-start-regexp c-C++-comment-start-regexp
319 c-class-key c-C++-class-key
320 c-access-key c-C++-access-key
321 c-recognize-knr-p nil)
322 ;; imenu-generic-expression cc-imenu-c++-generic-expression)
323 (run-hooks 'c-mode-common-hook)
324 (run-hooks 'idl-mode-hook)
328 ;; defuns for submitting bug reports
329 (defconst c-version "5.17"
330 "CC Mode version number.")
332 (defconst c-mode-help-address
333 "bug-gnu-emacs@prep.ai.mit.edu, cc-mode-help@python.org"
334 "Address for CC Mode bug reports.")
337 "Echo the current version of CC Mode in the minibuffer."
339 (message "Using CC Mode version %s" c-version)
340 (c-keep-region-active))
342 ;; Get reporter-submit-bug-report when byte-compiling
346 (defun c-submit-bug-report ()
347 "Submit via mail a bug report on CC Mode."
351 (let ((reporter-prompt-for-summary-p t)
352 (reporter-dont-compact-list '(c-offsets-alist))
353 (style c-indentation-style)
354 (hook c-special-indent-hook)
355 (c-features c-emacs-features))
357 (if (y-or-n-p "Do you want to submit a report on CC Mode? ")
360 (reporter-submit-bug-report
362 (concat "CC Mode " c-version " ("
363 (cond ((eq major-mode 'c++-mode) "C++")
364 ((eq major-mode 'c-mode) "C")
365 ((eq major-mode 'objc-mode) "ObjC")
366 ((eq major-mode 'java-mode) "Java")
370 ;; report only the vars that affect indentation
374 'c-comment-only-line-offset
377 'c-electric-pound-behavior
378 'c-hanging-braces-alist
379 'c-hanging-colons-alist
380 'c-hanging-comment-starter-p
381 'c-hanging-comment-ender-p
382 'c-indent-comments-syntactically-p
385 'c-label-minimum-indentation
389 (if (not (boundp 'defun-prompt-regexp))
390 (delq 'defun-prompt-regexp vars)
395 "Buffer Style: " style "\n\n"
397 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
398 "c-special-indent-hook is set to '"
400 ".\nPerhaps this is your problem?\n"
401 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
403 (format "c-emacs-features: %s\n" c-features)
411 ;;; cc-mode.el ends here