165
|
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
|
187
|
10 ;; Version: 5.17
|
165
|
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++,
|
177
|
36 ;; Objective-C, Java and IDL code. As of the latest Emacs and XEmacs
|
165
|
37 ;; releases, it is the default package for editing these languages.
|
|
38 ;; This package is called "CC Mode", and should be spelled exactly
|
177
|
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.
|
165
|
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 ;; 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
|
171
|
80 (eval-when-compile
|
|
81 (require 'cc-menus))
|
|
82 (require 'cc-defs)
|
165
|
83
|
183
|
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'
|
|
89 \(e.g. `awk-mode').")
|
|
90 (make-variable-buffer-local 'c-buffer-is-cc-mode)
|
|
91 (put 'c-buffer-is-cc-mode 'permanent-local t)
|
|
92
|
165
|
93
|
175
|
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
|
|
96 ;; use:
|
|
97 ;;
|
|
98 ;; (require 'cc-mode)
|
|
99 ;; (c-initialize-cc-mode)
|
|
100
|
177
|
101 ;;;###autoload
|
175
|
102 (defun c-initialize-cc-mode ()
|
181
|
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))
|
175
|
110 ;; make sure all necessary components of CC Mode are loaded in.
|
177
|
111 (let ((initprop 'cc-mode-is-initialized))
|
|
112 (require 'cc-vars)
|
|
113 (require 'cc-engine)
|
|
114 (require 'cc-langs)
|
|
115 (require 'cc-menus)
|
|
116 (require 'cc-align)
|
|
117 (require 'cc-styles)
|
|
118 (require 'cc-cmds)
|
|
119 ;; run the initialization hook, but only once
|
|
120 (or (get 'c-initialize-cc-mode initprop)
|
|
121 (progn
|
|
122 (c-initialize-builtin-style)
|
|
123 (run-hooks 'c-initialization-hook)
|
|
124 (put 'c-initialize-cc-mode initprop t)))
|
|
125 ))
|
175
|
126
|
|
127
|
165
|
128 ;;;###autoload
|
|
129 (defun c-mode ()
|
|
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.
|
|
135
|
|
136 To see what version of CC Mode you are running, enter `\\[c-version]'.
|
|
137
|
|
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
|
|
140 run first.
|
|
141
|
|
142 Key bindings:
|
|
143 \\{c-mode-map}"
|
|
144 (interactive)
|
175
|
145 (c-initialize-cc-mode)
|
165
|
146 (kill-all-local-variables)
|
|
147 (set-syntax-table c-mode-syntax-table)
|
|
148 (setq major-mode 'c-mode
|
|
149 mode-name "C"
|
|
150 local-abbrev-table c-mode-abbrev-table)
|
|
151 (use-local-map c-mode-map)
|
|
152 (c-common-init)
|
|
153 (setq comment-start "/* "
|
|
154 comment-end " */"
|
|
155 c-conditional-key c-C-conditional-key
|
|
156 c-class-key c-C-class-key
|
|
157 c-baseclass-key nil
|
181
|
158 c-comment-start-regexp c-C++-comment-start-regexp
|
165
|
159 imenu-generic-expression cc-imenu-c-generic-expression)
|
|
160 (run-hooks 'c-mode-common-hook)
|
|
161 (run-hooks 'c-mode-hook)
|
|
162 (c-update-modeline))
|
|
163
|
|
164
|
|
165 ;;;###autoload
|
|
166 (defun c++-mode ()
|
|
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
|
|
172 message.
|
|
173
|
|
174 To see what version of CC Mode you are running, enter `\\[c-version]'.
|
|
175
|
|
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.
|
|
179
|
|
180 Key bindings:
|
|
181 \\{c++-mode-map}"
|
|
182 (interactive)
|
175
|
183 (c-initialize-cc-mode)
|
165
|
184 (kill-all-local-variables)
|
|
185 (set-syntax-table c++-mode-syntax-table)
|
|
186 (setq major-mode 'c++-mode
|
|
187 mode-name "C++"
|
|
188 local-abbrev-table c++-mode-abbrev-table)
|
|
189 (use-local-map c++-mode-map)
|
|
190 (c-common-init)
|
|
191 (setq comment-start "// "
|
|
192 comment-end ""
|
|
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)
|
|
201 (c-update-modeline))
|
|
202
|
|
203
|
|
204 ;;;###autoload
|
|
205 (defun objc-mode ()
|
|
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
|
|
211 message.
|
|
212
|
|
213 To see what version of CC Mode you are running, enter `\\[c-version]'.
|
|
214
|
|
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'
|
|
217 is run first.
|
|
218
|
|
219 Key bindings:
|
|
220 \\{objc-mode-map}"
|
|
221 (interactive)
|
175
|
222 (c-initialize-cc-mode)
|
165
|
223 (kill-all-local-variables)
|
|
224 (set-syntax-table objc-mode-syntax-table)
|
|
225 (setq major-mode 'objc-mode
|
|
226 mode-name "ObjC"
|
|
227 local-abbrev-table objc-mode-abbrev-table)
|
|
228 (use-local-map objc-mode-map)
|
|
229 (c-common-init)
|
|
230 (setq comment-start "// "
|
|
231 comment-end ""
|
|
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
|
|
235 c-baseclass-key nil
|
|
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)
|
|
240 (c-update-modeline))
|
|
241
|
|
242
|
|
243 ;;;###autoload
|
|
244 (defun java-mode ()
|
|
245 "Major mode for editing Java code.
|
187
|
246 To submit a problem report, enter `\\[c-submit-bug-report]' from a
|
165
|
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
|
|
250 message.
|
|
251
|
|
252 To see what version of CC Mode you are running, enter `\\[c-version]'.
|
|
253
|
|
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'.
|
|
259
|
|
260 Key bindings:
|
|
261 \\{java-mode-map}"
|
|
262 (interactive)
|
175
|
263 (c-initialize-cc-mode)
|
165
|
264 (kill-all-local-variables)
|
|
265 (set-syntax-table java-mode-syntax-table)
|
|
266 (setq major-mode 'java-mode
|
|
267 mode-name "Java"
|
|
268 local-abbrev-table java-mode-abbrev-table)
|
|
269 (use-local-map java-mode-map)
|
|
270 (c-common-init)
|
|
271 (setq comment-start "// "
|
|
272 comment-end ""
|
|
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
|
|
277 c-baseclass-key nil
|
|
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
|
|
282 )
|
|
283 (c-set-style "java")
|
|
284 (run-hooks 'c-mode-common-hook)
|
|
285 (run-hooks 'java-mode-hook)
|
|
286 (c-update-modeline))
|
|
287
|
|
288
|
177
|
289 ;;;###autoload
|
|
290 (defun idl-mode ()
|
|
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
|
|
296 message.
|
|
297
|
|
298 To see what version of CC Mode you are running, enter `\\[c-version]'.
|
|
299
|
|
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.
|
|
303
|
|
304 Key bindings:
|
|
305 \\{idl-mode-map}"
|
|
306 (interactive)
|
|
307 (c-initialize-cc-mode)
|
|
308 (kill-all-local-variables)
|
|
309 (set-syntax-table idl-mode-syntax-table)
|
|
310 (setq major-mode 'idl-mode
|
|
311 mode-name "IDL"
|
|
312 local-abbrev-table idl-mode-abbrev-table)
|
|
313 (use-local-map idl-mode-map)
|
|
314 (c-common-init)
|
|
315 (setq comment-start "// "
|
|
316 comment-end ""
|
|
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)
|
|
325 (c-update-modeline))
|
|
326
|
|
327
|
165
|
328 ;; defuns for submitting bug reports
|
187
|
329 (defconst c-version "5.17"
|
165
|
330 "CC Mode version number.")
|
|
331
|
|
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.")
|
|
335
|
|
336 (defun c-version ()
|
|
337 "Echo the current version of CC Mode in the minibuffer."
|
|
338 (interactive)
|
|
339 (message "Using CC Mode version %s" c-version)
|
|
340 (c-keep-region-active))
|
|
341
|
|
342 ;; Get reporter-submit-bug-report when byte-compiling
|
|
343 (eval-when-compile
|
|
344 (require 'reporter))
|
|
345
|
|
346 (defun c-submit-bug-report ()
|
|
347 "Submit via mail a bug report on CC Mode."
|
|
348 (interactive)
|
|
349 (require 'cc-vars)
|
|
350 ;; load in reporter
|
|
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))
|
|
356 (and
|
|
357 (if (y-or-n-p "Do you want to submit a report on CC Mode? ")
|
|
358 t (message "") nil)
|
|
359 (require 'reporter)
|
|
360 (reporter-submit-bug-report
|
|
361 c-mode-help-address
|
|
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")
|
|
367 )
|
|
368 ")")
|
|
369 (let ((vars (list
|
|
370 ;; report only the vars that affect indentation
|
|
371 'c-basic-offset
|
|
372 'c-offsets-alist
|
|
373 'c-cleanup-list
|
|
374 'c-comment-only-line-offset
|
|
375 'c-backslash-column
|
|
376 'c-delete-function
|
|
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
|
|
383 'c-tab-always-indent
|
|
384 'c-recognize-knr-p
|
|
385 'c-label-minimum-indentation
|
|
386 'defun-prompt-regexp
|
|
387 'tab-width
|
|
388 )))
|
|
389 (if (not (boundp 'defun-prompt-regexp))
|
|
390 (delq 'defun-prompt-regexp vars)
|
|
391 vars))
|
|
392 (function
|
|
393 (lambda ()
|
|
394 (insert
|
|
395 "Buffer Style: " style "\n\n"
|
|
396 (if hook
|
|
397 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
|
|
398 "c-special-indent-hook is set to '"
|
|
399 (format "%s" hook)
|
|
400 ".\nPerhaps this is your problem?\n"
|
|
401 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
|
|
402 "\n")
|
|
403 (format "c-emacs-features: %s\n" c-features)
|
|
404 )))
|
|
405 nil
|
|
406 "Dear Barry,"
|
|
407 ))))
|
|
408
|
|
409
|
|
410 (provide 'cc-mode)
|
|
411 ;;; cc-mode.el ends here
|