]> code.delx.au - gnu-emacs/blob - lisp/progmodes/cc-mode.el
(c-require-final-newline): Added a variable to make the initialization of
[gnu-emacs] / lisp / progmodes / cc-mode.el
1 ;;; cc-mode.el --- major mode for editing C, C++, Objective-C, and Java code
2
3 ;; Copyright (C) 1985,1987,1992-2001 Free Software Foundation, Inc.
4
5 ;; Authors: 2000- Martin Stjernholm
6 ;; 1998-1999 Barry A. Warsaw and Martin Stjernholm
7 ;; 1992-1997 Barry A. Warsaw
8 ;; 1987 Dave Detlefs and Stewart Clamen
9 ;; 1985 Richard M. Stallman
10 ;; Maintainer: bug-cc-mode@gnu.org
11 ;; Created: a long, long, time ago. adapted from the original c-mode.el
12 ;; Keywords: c languages oop
13
14 ;; This file is part of GNU Emacs.
15
16 ;; GNU Emacs is free software; you can redistribute it and/or modify
17 ;; it under the terms of the GNU General Public License as published by
18 ;; the Free Software Foundation; either version 2, or (at your option)
19 ;; any later version.
20
21 ;; GNU Emacs is distributed in the hope that it will be useful,
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;; GNU General Public License for more details.
25
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs; see the file COPYING. If not, write to
28 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
29 ;; Boston, MA 02111-1307, USA.
30
31 (defconst c-version "5.29"
32 "CC Mode version number.")
33
34 ;; NOTE: Read the commentary below for the right way to submit bug reports!
35 ;; NOTE: See the accompanying texinfo manual for details on using this mode!
36
37 ;;; Commentary:
38
39 ;; This package provides GNU Emacs major modes for editing C, C++,
40 ;; Objective-C, Java, IDL and Pike code. As of the latest Emacs and
41 ;; XEmacs releases, it is the default package for editing these
42 ;; languages. This package is called "CC Mode", and should be spelled
43 ;; exactly this way.
44
45 ;; CC Mode supports K&R and ANSI C, ANSI C++, Objective-C, Java,
46 ;; CORBA's IDL, and Pike with a consistent indentation model across
47 ;; all modes. This indentation model is intuitive and very flexible,
48 ;; so that almost any desired style of indentation can be supported.
49 ;; Installation, usage, and programming details are contained in an
50 ;; accompanying texinfo manual.
51
52 ;; CC Mode's immediate ancestors were, c++-mode.el, cplus-md.el, and
53 ;; cplus-md1.el..
54
55 ;; NOTE: This mode does not perform font-locking (a.k.a syntactic
56 ;; coloring, keyword highlighting, etc.) for any of the supported
57 ;; modes. Typically this is done by a package called font-lock.el
58 ;; which we do *not* maintain. You should contact the Emacs or XEmacs
59 ;; maintainers for questions about coloring or highlighting in any
60 ;; language mode.
61
62 ;; To submit bug reports, type "C-c C-b". These will be sent to
63 ;; bug-gnu-emacs@gnu.org (mirrored as the Usenet newsgroup
64 ;; gnu.emacs.bug) as well as bug-cc-mode@gnu.org, which directly
65 ;; contacts the CC Mode maintainers. Questions can sent to
66 ;; help-gnu-emacs@gnu.org (mirrored as gnu.emacs.help) and/or
67 ;; bug-cc-mode@gnu.org. Please do not send bugs or questions to our
68 ;; personal accounts; we reserve the right to ignore such email!
69
70 ;; Many, many thanks go out to all the folks on the beta test list.
71 ;; Without their patience, testing, insight, code contributions, and
72 ;; encouragement CC Mode would be a far inferior package.
73
74 ;; You can get the latest version of CC Mode, including PostScript
75 ;; documentation and separate individual files from:
76 ;;
77 ;; http://cc-mode.sourceforge.net/
78 ;;
79 ;; You can join a moderated CC Mode announcement-only mailing list by
80 ;; visiting
81 ;;
82 ;; http://lists.sourceforge.net/mailman/listinfo/cc-mode-announce
83
84 ;;; Code:
85
86 (eval-when-compile
87 (let ((load-path
88 (if (and (boundp 'byte-compile-dest-file)
89 (stringp byte-compile-dest-file))
90 (cons (file-name-directory byte-compile-dest-file) load-path)
91 load-path)))
92 (require 'cc-bytecomp)))
93
94 (cc-require 'cc-defs)
95 (cc-require 'cc-menus)
96 (cc-require 'cc-vars)
97 (cc-require 'cc-langs)
98 (cc-require 'cc-styles)
99 (cc-require 'cc-engine)
100 (cc-require 'cc-cmds)
101 (cc-require 'cc-align)
102
103 ;; Silence the compiler.
104 (cc-bytecomp-defvar comment-line-break-function) ; (X)Emacs 20+
105 (cc-bytecomp-defvar adaptive-fill-first-line-regexp) ; Emacs 20+
106 (cc-bytecomp-defun set-keymap-parents) ; XEmacs
107
108 ;; Menu support for both XEmacs and Emacs. If you don't have easymenu
109 ;; with your version of Emacs, you are incompatible!
110 (require 'easymenu)
111
112 \f
113 ;; Other modes and packages which depend on CC Mode should do the
114 ;; following to make sure everything is loaded and available for their
115 ;; use:
116 ;;
117 ;; (require 'cc-mode)
118 ;;
119 ;; And in the major mode function:
120 ;;
121 ;; (c-initialize-cc-mode)
122
123 (defun c-leave-cc-mode-mode ()
124 (setq c-buffer-is-cc-mode nil))
125
126 ;;;###autoload
127 (defun c-initialize-cc-mode ()
128 (setq c-buffer-is-cc-mode t)
129 (let ((initprop 'cc-mode-is-initialized)
130 c-initialization-ok)
131 (unless (get 'c-initialize-cc-mode initprop)
132 (unwind-protect
133 (progn
134 (put 'c-initialize-cc-mode initprop t)
135 (c-initialize-builtin-style)
136 (run-hooks 'c-initialization-hook)
137 ;; Fix obsolete variables.
138 (if (boundp 'c-comment-continuation-stars)
139 (setq c-block-comment-prefix c-comment-continuation-stars))
140 (add-hook 'change-major-mode-hook 'c-leave-cc-mode-mode)
141 (setq c-initialization-ok t))
142 ;; Will try initialization hooks again if they failed.
143 (put 'c-initialize-cc-mode initprop c-initialization-ok)))
144 ))
145
146 \f
147 ;; Common routines
148 (defvar c-mode-base-map ()
149 "Keymap shared by all CC Mode related modes.")
150
151 (defun c-make-inherited-keymap ()
152 (let ((map (make-sparse-keymap)))
153 (cond
154 ;; XEmacs 19 & 20
155 ((fboundp 'set-keymap-parents)
156 (set-keymap-parents map c-mode-base-map))
157 ;; Emacs 19
158 ((fboundp 'set-keymap-parent)
159 (set-keymap-parent map c-mode-base-map))
160 ;; incompatible
161 (t (error "CC Mode is incompatible with this version of Emacs")))
162 map))
163
164 (defun c-define-abbrev-table (name defs)
165 ;; Compatibility wrapper for `define-abbrev' which passes a non-nil
166 ;; sixth argument for SYSTEM-FLAG in emacsen that support it
167 ;; (currently only Emacs 21.2).
168 (define-abbrev-table name nil)
169 (let ((table (symbol-value name)))
170 (while defs
171 (condition-case nil
172 (apply 'define-abbrev table (append (car defs) '(t)))
173 (wrong-number-of-arguments
174 (apply 'define-abbrev table (car defs))))
175 (setq defs (cdr defs)))))
176
177 (if c-mode-base-map
178 nil
179 ;; TBD: should we even worry about naming this keymap. My vote: no,
180 ;; because Emacs and XEmacs do it differently.
181 (setq c-mode-base-map (make-sparse-keymap))
182 ;; put standard keybindings into MAP
183 ;; the following mappings correspond more or less directly to BOCM
184 (define-key c-mode-base-map "{" 'c-electric-brace)
185 (define-key c-mode-base-map "}" 'c-electric-brace)
186 (define-key c-mode-base-map ";" 'c-electric-semi&comma)
187 (define-key c-mode-base-map "#" 'c-electric-pound)
188 (define-key c-mode-base-map ":" 'c-electric-colon)
189 (define-key c-mode-base-map "(" 'c-electric-paren)
190 (define-key c-mode-base-map ")" 'c-electric-paren)
191 ;; Separate M-BS from C-M-h. The former should remain
192 ;; backward-kill-word.
193 (define-key c-mode-base-map [(control meta h)] 'c-mark-function)
194 (define-key c-mode-base-map "\e\C-q" 'c-indent-exp)
195 (substitute-key-definition 'backward-sentence
196 'c-beginning-of-statement
197 c-mode-base-map global-map)
198 (substitute-key-definition 'forward-sentence
199 'c-end-of-statement
200 c-mode-base-map global-map)
201 (substitute-key-definition 'indent-new-comment-line
202 'c-indent-new-comment-line
203 c-mode-base-map global-map)
204 (when (fboundp 'comment-indent-new-line)
205 ;; indent-new-comment-line has changed name to
206 ;; comment-indent-new-line in Emacs 21.
207 (substitute-key-definition 'comment-indent-new-line
208 'c-indent-new-comment-line
209 c-mode-base-map global-map))
210 ;; RMS says don't make these the default.
211 ;; (define-key c-mode-base-map "\e\C-a" 'c-beginning-of-defun)
212 ;; (define-key c-mode-base-map "\e\C-e" 'c-end-of-defun)
213 (define-key c-mode-base-map "\C-c\C-n" 'c-forward-conditional)
214 (define-key c-mode-base-map "\C-c\C-p" 'c-backward-conditional)
215 (define-key c-mode-base-map "\C-c\C-u" 'c-up-conditional)
216 (substitute-key-definition 'indent-for-tab-command
217 'c-indent-command
218 c-mode-base-map global-map)
219 ;; It doesn't suffice to put c-fill-paragraph on
220 ;; fill-paragraph-function due to the way it works.
221 (substitute-key-definition 'fill-paragraph 'c-fill-paragraph
222 c-mode-base-map global-map)
223 ;; In XEmacs the default fill function is called
224 ;; fill-paragraph-or-region.
225 (substitute-key-definition 'fill-paragraph-or-region 'c-fill-paragraph
226 c-mode-base-map global-map)
227 ;; Bind the electric deletion functions to C-d and DEL. Emacs 21
228 ;; automatically maps the [delete] and [backspace] keys to these two
229 ;; depending on window system and user preferences. (In earlier
230 ;; versions it's possible to do the same by using `function-key-map'.)
231 (define-key c-mode-base-map "\C-d" 'c-electric-delete-forward)
232 (define-key c-mode-base-map "\177" 'c-electric-backspace)
233 (when (boundp 'delete-key-deletes-forward)
234 ;; In XEmacs 20 and later we fix the forward and backward deletion
235 ;; behavior by binding the keysyms for the [delete] and
236 ;; [backspace] keys directly, and use `delete-forward-p' or
237 ;; `delete-key-deletes-forward' to decide what [delete] should do.
238 (define-key c-mode-base-map [delete] 'c-electric-delete)
239 (define-key c-mode-base-map [backspace] 'c-electric-backspace))
240 ;; these are new keybindings, with no counterpart to BOCM
241 (define-key c-mode-base-map "," 'c-electric-semi&comma)
242 (define-key c-mode-base-map "*" 'c-electric-star)
243 (define-key c-mode-base-map "/" 'c-electric-slash)
244 (define-key c-mode-base-map "\C-c\C-q" 'c-indent-defun)
245 (define-key c-mode-base-map "\C-c\C-\\" 'c-backslash-region)
246 ;; TBD: where if anywhere, to put c-backward|forward-into-nomenclature
247 (define-key c-mode-base-map "\C-c\C-a" 'c-toggle-auto-state)
248 (define-key c-mode-base-map "\C-c\C-b" 'c-submit-bug-report)
249 (define-key c-mode-base-map "\C-c\C-c" 'comment-region)
250 (define-key c-mode-base-map "\C-c\C-d" 'c-toggle-hungry-state)
251 (define-key c-mode-base-map "\C-c\C-o" 'c-set-offset)
252 (define-key c-mode-base-map "\C-c\C-s" 'c-show-syntactic-information)
253 (define-key c-mode-base-map "\C-c\C-t" 'c-toggle-auto-hungry-state)
254 (define-key c-mode-base-map "\C-c." 'c-set-style)
255 ;; conflicts with OOBR
256 ;;(define-key c-mode-base-map "\C-c\C-v" 'c-version)
257 )
258
259 (defvar c-c-menu nil)
260 (defvar c-c++-menu nil)
261 (defvar c-objc-menu nil)
262 (defvar c-java-menu nil)
263 (defvar c-pike-menu nil)
264
265 (defun c-mode-menu (modestr)
266 (let ((m
267 '(["Comment Out Region" comment-region (c-fn-region-is-active-p)]
268 ["Uncomment Region"
269 (comment-region (region-beginning) (region-end) '(4))
270 (c-fn-region-is-active-p)]
271 ["Fill Comment Paragraph" c-fill-paragraph t]
272 "----"
273 ["Indent Expression" c-indent-exp
274 (memq (char-after) '(?\( ?\[ ?\{))]
275 ["Indent Line or Region" c-indent-line-or-region t]
276 ["Up Conditional" c-up-conditional t]
277 ["Backward Conditional" c-backward-conditional t]
278 ["Forward Conditional" c-forward-conditional t]
279 ["Backward Statement" c-beginning-of-statement t]
280 ["Forward Statement" c-end-of-statement t]
281 "----"
282 ["Macro Expand Region" c-macro-expand (c-fn-region-is-active-p)]
283 ["Backslashify" c-backslash-region
284 (c-fn-region-is-active-p)]
285 "----"
286 ("Toggle..."
287 ["Syntactic indentation" c-toggle-syntactic-indentation t]
288 ["Auto newline" c-toggle-auto-state t]
289 ["Hungry delete" c-toggle-hungry-state t])
290 )))
291 (cons modestr m)))
292
293 ;; We don't require the outline package, but we configure it a bit anyway.
294 (cc-bytecomp-defvar outline-level)
295
296 (defun c-common-init (mode)
297 ;; Common initializations for all modes.
298 (setq c-buffer-is-cc-mode mode)
299
300 ;; these variables should always be buffer local; they do not affect
301 ;; indentation style.
302 (make-local-variable 'require-final-newline)
303 (make-local-variable 'parse-sexp-ignore-comments)
304 (make-local-variable 'indent-line-function)
305 (make-local-variable 'indent-region-function)
306 (make-local-variable 'outline-regexp)
307 (make-local-variable 'outline-level)
308 (make-local-variable 'normal-auto-fill-function)
309 (make-local-variable 'comment-start)
310 (make-local-variable 'comment-end)
311 (make-local-variable 'comment-column)
312 (make-local-variable 'comment-start-skip)
313 (make-local-variable 'comment-multi-line)
314 (make-local-variable 'paragraph-start)
315 (make-local-variable 'paragraph-separate)
316 (make-local-variable 'paragraph-ignore-fill-prefix)
317 (make-local-variable 'adaptive-fill-mode)
318 (make-local-variable 'adaptive-fill-regexp)
319 (make-local-variable 'imenu-generic-expression) ;set in the mode functions
320
321 ;; X/Emacs 20 only
322 (and (boundp 'comment-line-break-function)
323 (progn
324 (make-local-variable 'comment-line-break-function)
325 (setq comment-line-break-function
326 'c-indent-new-comment-line)))
327
328 ;; now set their values
329 (setq require-final-newline c-require-final-newline
330 parse-sexp-ignore-comments t
331 indent-line-function 'c-indent-line
332 indent-region-function 'c-indent-region
333 outline-regexp "[^#\n\^M]"
334 outline-level 'c-outline-level
335 normal-auto-fill-function 'c-do-auto-fill
336 comment-column 32
337 comment-start-skip "/\\*+ *\\|//+ *"
338 comment-multi-line t)
339
340 ;; Fix keyword regexps.
341 (c-init-language-vars)
342
343 ;; now set the mode style based on c-default-style
344 (let ((style (if (stringp c-default-style)
345 c-default-style
346 (or (cdr (assq mode c-default-style))
347 (cdr (assq 'other c-default-style))
348 "gnu"))))
349 ;; Override style variables if `c-old-style-variable-behavior' is
350 ;; set. Also override if we are using global style variables,
351 ;; have already initialized a style once, and are switching to a
352 ;; different style. (It's doubtful whether this is desirable, but
353 ;; the whole situation with nonlocal style variables is a bit
354 ;; awkward. It's at least the most compatible way with the old
355 ;; style init procedure.)
356 (c-set-style style (not (or c-old-style-variable-behavior
357 (and (not c-style-variables-are-local-p)
358 c-indentation-style
359 (not (string-equal c-indentation-style
360 style)))))))
361 (c-setup-paragraph-variables)
362
363 ;; we have to do something special for c-offsets-alist so that the
364 ;; buffer local value has its own alist structure.
365 (setq c-offsets-alist (copy-alist c-offsets-alist))
366
367 ;; setup the comment indent variable in a Emacs version portable way
368 (make-local-variable 'comment-indent-function)
369 (setq comment-indent-function 'c-comment-indent)
370
371 ;; add menus to menubar
372 (easy-menu-add (c-mode-menu mode-name))
373
374 ;; put auto-hungry designators onto minor-mode-alist, but only once
375 (or (assq 'c-auto-hungry-string minor-mode-alist)
376 (setq minor-mode-alist
377 (cons '(c-auto-hungry-string c-auto-hungry-string)
378 minor-mode-alist)))
379
380 ;; Install the function that ensures `c-state-cache' doesn't become
381 ;; invalid.
382 (make-local-variable 'after-change-functions)
383 (add-hook 'after-change-functions 'c-check-state-cache))
384
385 (defun c-postprocess-file-styles ()
386 "Function that post processes relevant file local variables.
387 Currently, this function simply applies any style and offset settings
388 found in the file's Local Variable list. It first applies any style
389 setting found in `c-file-style', then it applies any offset settings
390 it finds in `c-file-offsets'.
391
392 Note that the style variables are always made local to the buffer."
393 ;; apply file styles and offsets
394 (when c-buffer-is-cc-mode
395 (if (or c-file-style c-file-offsets)
396 (c-make-styles-buffer-local t))
397 (and c-file-style
398 (c-set-style c-file-style))
399 (and c-file-offsets
400 (mapcar
401 (lambda (langentry)
402 (let ((langelem (car langentry))
403 (offset (cdr langentry)))
404 (c-set-offset langelem offset)))
405 c-file-offsets))))
406
407 (add-hook 'hack-local-variables-hook 'c-postprocess-file-styles)
408
409 \f
410 ;; Support for C
411
412 (defvar c-mode-abbrev-table nil
413 "Abbreviation table used in c-mode buffers.")
414 (c-define-abbrev-table 'c-mode-abbrev-table
415 '(("else" "else" c-electric-continued-statement 0)
416 ("while" "while" c-electric-continued-statement 0)))
417
418 (defvar c-mode-map ()
419 "Keymap used in c-mode buffers.")
420 (if c-mode-map
421 nil
422 (setq c-mode-map (c-make-inherited-keymap))
423 ;; add bindings which are only useful for C
424 (define-key c-mode-map "\C-c\C-e" 'c-macro-expand)
425 )
426
427 (easy-menu-define c-c-menu c-mode-map "C Mode Commands"
428 (c-mode-menu "C"))
429
430 ;;;###autoload
431 (defun c-mode ()
432 "Major mode for editing K&R and ANSI C code.
433 To submit a problem report, enter `\\[c-submit-bug-report]' from a
434 c-mode buffer. This automatically sets up a mail buffer with version
435 information already added. You just need to add a description of the
436 problem, including a reproducible test case and send the message.
437
438 To see what version of CC Mode you are running, enter `\\[c-version]'.
439
440 The hook variable `c-mode-hook' is run with no args, if that value is
441 bound and has a non-nil value. Also the hook `c-mode-common-hook' is
442 run first.
443
444 Key bindings:
445 \\{c-mode-map}"
446 (interactive)
447 (kill-all-local-variables)
448 (c-initialize-cc-mode)
449 (set-syntax-table c-mode-syntax-table)
450 (setq major-mode 'c-mode
451 mode-name "C"
452 local-abbrev-table c-mode-abbrev-table
453 abbrev-mode t)
454 (use-local-map c-mode-map)
455 (c-common-init 'c-mode)
456 (cc-imenu-init cc-imenu-c-generic-expression)
457 (run-hooks 'c-mode-common-hook)
458 (run-hooks 'c-mode-hook)
459 (c-update-modeline))
460
461 \f
462 ;; Support for C++
463
464 (defvar c++-mode-abbrev-table nil
465 "Abbreviation table used in c++-mode buffers.")
466 (c-define-abbrev-table 'c++-mode-abbrev-table
467 '(("else" "else" c-electric-continued-statement 0)
468 ("while" "while" c-electric-continued-statement 0)
469 ("catch" "catch" c-electric-continued-statement 0)))
470
471 (defvar c++-mode-map ()
472 "Keymap used in c++-mode buffers.")
473 (if c++-mode-map
474 nil
475 (setq c++-mode-map (c-make-inherited-keymap))
476 ;; add bindings which are only useful for C++
477 (define-key c++-mode-map "\C-c\C-e" 'c-macro-expand)
478 (define-key c++-mode-map "\C-c:" 'c-scope-operator)
479 (define-key c++-mode-map "<" 'c-electric-lt-gt)
480 (define-key c++-mode-map ">" 'c-electric-lt-gt))
481
482 (easy-menu-define c-c++-menu c++-mode-map "C++ Mode Commands"
483 (c-mode-menu "C++"))
484
485 ;;;###autoload
486 (defun c++-mode ()
487 "Major mode for editing C++ code.
488 To submit a problem report, enter `\\[c-submit-bug-report]' from a
489 c++-mode buffer. This automatically sets up a mail buffer with
490 version information already added. You just need to add a description
491 of the problem, including a reproducible test case, and send the
492 message.
493
494 To see what version of CC Mode you are running, enter `\\[c-version]'.
495
496 The hook variable `c++-mode-hook' is run with no args, if that
497 variable is bound and has a non-nil value. Also the hook
498 `c-mode-common-hook' is run first.
499
500 Key bindings:
501 \\{c++-mode-map}"
502 (interactive)
503 (kill-all-local-variables)
504 (c-initialize-cc-mode)
505 (set-syntax-table c++-mode-syntax-table)
506 (setq major-mode 'c++-mode
507 mode-name "C++"
508 local-abbrev-table c++-mode-abbrev-table
509 abbrev-mode t)
510 (use-local-map c++-mode-map)
511 (c-common-init 'c++-mode)
512 (cc-imenu-init cc-imenu-c++-generic-expression)
513 (run-hooks 'c-mode-common-hook)
514 (run-hooks 'c++-mode-hook)
515 (c-update-modeline))
516
517 \f
518 ;; Support for Objective-C
519
520 (defvar objc-mode-abbrev-table nil
521 "Abbreviation table used in objc-mode buffers.")
522 (c-define-abbrev-table 'objc-mode-abbrev-table
523 '(("else" "else" c-electric-continued-statement 0)
524 ("while" "while" c-electric-continued-statement 0)))
525
526 (defvar objc-mode-map ()
527 "Keymap used in objc-mode buffers.")
528 (if objc-mode-map
529 nil
530 (setq objc-mode-map (c-make-inherited-keymap))
531 ;; add bindings which are only useful for Objective-C
532 (define-key objc-mode-map "\C-c\C-e" 'c-macro-expand))
533
534 (easy-menu-define c-objc-menu objc-mode-map "ObjC Mode Commands"
535 (c-mode-menu "ObjC"))
536
537 ;;;###autoload
538 (defun objc-mode ()
539 "Major mode for editing Objective C code.
540 To submit a problem report, enter `\\[c-submit-bug-report]' from an
541 objc-mode buffer. This automatically sets up a mail buffer with
542 version information already added. You just need to add a description
543 of the problem, including a reproducible test case, and send the
544 message.
545
546 To see what version of CC Mode you are running, enter `\\[c-version]'.
547
548 The hook variable `objc-mode-hook' is run with no args, if that value
549 is bound and has a non-nil value. Also the hook `c-mode-common-hook'
550 is run first.
551
552 Key bindings:
553 \\{objc-mode-map}"
554 (interactive)
555 (kill-all-local-variables)
556 (c-initialize-cc-mode)
557 (set-syntax-table objc-mode-syntax-table)
558 (setq major-mode 'objc-mode
559 mode-name "ObjC"
560 local-abbrev-table objc-mode-abbrev-table
561 abbrev-mode t)
562 (use-local-map objc-mode-map)
563 (c-common-init 'objc-mode)
564 (cc-imenu-init cc-imenu-objc-generic-expression)
565 (run-hooks 'c-mode-common-hook)
566 (run-hooks 'objc-mode-hook)
567 (c-update-modeline))
568
569 \f
570 ;; Support for Java
571
572 (defvar java-mode-abbrev-table nil
573 "Abbreviation table used in java-mode buffers.")
574 (c-define-abbrev-table 'java-mode-abbrev-table
575 '(("else" "else" c-electric-continued-statement 0)
576 ("while" "while" c-electric-continued-statement 0)
577 ("catch" "catch" c-electric-continued-statement 0)
578 ("finally" "finally" c-electric-continued-statement 0)))
579
580 (defvar java-mode-map ()
581 "Keymap used in java-mode buffers.")
582 (if java-mode-map
583 nil
584 (setq java-mode-map (c-make-inherited-keymap))
585 ;; add bindings which are only useful for Java
586 )
587
588 (easy-menu-define c-java-menu java-mode-map "Java Mode Commands"
589 (c-mode-menu "Java"))
590
591 ;;;###autoload
592 (defun java-mode ()
593 "Major mode for editing Java code.
594 To submit a problem report, enter `\\[c-submit-bug-report]' from a
595 java-mode buffer. This automatically sets up a mail buffer with
596 version information already added. You just need to add a description
597 of the problem, including a reproducible test case and send the
598 message.
599
600 To see what version of CC Mode you are running, enter `\\[c-version]'.
601
602 The hook variable `java-mode-hook' is run with no args, if that value
603 is bound and has a non-nil value. Also the common hook
604 `c-mode-common-hook' is run first. Note that this mode automatically
605 sets the \"java\" style before calling any hooks so be careful if you
606 set styles in `c-mode-common-hook'.
607
608 Key bindings:
609 \\{java-mode-map}"
610 (interactive)
611 (kill-all-local-variables)
612 (c-initialize-cc-mode)
613 (set-syntax-table java-mode-syntax-table)
614 (setq major-mode 'java-mode
615 mode-name "Java"
616 local-abbrev-table java-mode-abbrev-table
617 abbrev-mode t)
618 (use-local-map java-mode-map)
619 (c-common-init 'java-mode)
620 (cc-imenu-init cc-imenu-java-generic-expression)
621 (run-hooks 'c-mode-common-hook)
622 (run-hooks 'java-mode-hook)
623 (c-update-modeline))
624
625 \f
626 ;; Support for CORBA's IDL language
627
628 (defvar idl-mode-abbrev-table nil
629 "Abbreviation table used in idl-mode buffers.")
630 (c-define-abbrev-table 'idl-mode-abbrev-table nil)
631
632 (defvar idl-mode-map ()
633 "Keymap used in idl-mode buffers.")
634 (if idl-mode-map
635 nil
636 (setq idl-mode-map (c-make-inherited-keymap))
637 ;; add bindings which are only useful for IDL
638 )
639
640 (easy-menu-define c-idl-menu idl-mode-map "IDL Mode Commands"
641 (c-mode-menu "IDL"))
642
643 ;;;###autoload
644 (defun idl-mode ()
645 "Major mode for editing CORBA's IDL code.
646 To submit a problem report, enter `\\[c-submit-bug-report]' from an
647 idl-mode buffer. This automatically sets up a mail buffer with
648 version information already added. You just need to add a description
649 of the problem, including a reproducible test case, and send the
650 message.
651
652 To see what version of CC Mode you are running, enter `\\[c-version]'.
653
654 The hook variable `idl-mode-hook' is run with no args, if that
655 variable is bound and has a non-nil value. Also the hook
656 `c-mode-common-hook' is run first.
657
658 Key bindings:
659 \\{idl-mode-map}"
660 (interactive)
661 (kill-all-local-variables)
662 (c-initialize-cc-mode)
663 (set-syntax-table idl-mode-syntax-table)
664 (setq major-mode 'idl-mode
665 mode-name "IDL"
666 local-abbrev-table idl-mode-abbrev-table)
667 (use-local-map idl-mode-map)
668 (c-common-init 'idl-mode)
669 ;;(cc-imenu-init cc-imenu-idl-generic-expression) ;FIXME
670 (run-hooks 'c-mode-common-hook)
671 (run-hooks 'idl-mode-hook)
672 (c-update-modeline))
673
674 \f
675 ;; Support for Pike
676
677 (defvar pike-mode-abbrev-table nil
678 "Abbreviation table used in pike-mode buffers.")
679 (c-define-abbrev-table 'pike-mode-abbrev-table
680 '(("else" "else" c-electric-continued-statement 0)
681 ("while" "while" c-electric-continued-statement 0)))
682
683 (defvar pike-mode-map ()
684 "Keymap used in pike-mode buffers.")
685 (if pike-mode-map
686 nil
687 (setq pike-mode-map (c-make-inherited-keymap))
688 ;; additional bindings
689 (define-key pike-mode-map "\C-c\C-e" 'c-macro-expand))
690
691 (easy-menu-define c-pike-menu pike-mode-map "Pike Mode Commands"
692 (c-mode-menu "Pike"))
693
694 ;;;###autoload
695 (defun pike-mode ()
696 "Major mode for editing Pike code.
697 To submit a problem report, enter `\\[c-submit-bug-report]' from a
698 pike-mode buffer. This automatically sets up a mail buffer with
699 version information already added. You just need to add a description
700 of the problem, including a reproducible test case, and send the
701 message.
702
703 To see what version of CC Mode you are running, enter `\\[c-version]'.
704
705 The hook variable `pike-mode-hook' is run with no args, if that value
706 is bound and has a non-nil value. Also the common hook
707 `c-mode-common-hook' is run first.
708
709 Key bindings:
710 \\{pike-mode-map}"
711 (interactive)
712 (kill-all-local-variables)
713 (c-initialize-cc-mode)
714 (set-syntax-table pike-mode-syntax-table)
715 (setq major-mode 'pike-mode
716 mode-name "Pike"
717 local-abbrev-table pike-mode-abbrev-table
718 abbrev-mode t)
719 (use-local-map pike-mode-map)
720 (c-common-init 'pike-mode)
721 ;;(cc-imenu-init cc-imenu-pike-generic-expression) ;FIXME
722 (run-hooks 'c-mode-common-hook)
723 (run-hooks 'pike-mode-hook)
724 (c-update-modeline))
725
726 \f
727 ;; bug reporting
728
729 (defconst c-mode-help-address
730 "bug-cc-mode@gnu.org"
731 "Address(es) for CC Mode bug reports.")
732
733 (defun c-version ()
734 "Echo the current version of CC Mode in the minibuffer."
735 (interactive)
736 (message "Using CC Mode version %s" c-version)
737 (c-keep-region-active))
738
739 (defvar c-prepare-bug-report-hooks nil)
740
741 ;; Dynamic variables used by reporter.
742 (defvar reporter-prompt-for-summary-p)
743 (defvar reporter-dont-compact-list)
744
745 (defun c-submit-bug-report ()
746 "Submit via mail a bug report on CC Mode."
747 (interactive)
748 (require 'reporter)
749 ;; load in reporter
750 (let ((reporter-prompt-for-summary-p t)
751 (reporter-dont-compact-list '(c-offsets-alist))
752 (style c-indentation-style)
753 (c-features c-emacs-features))
754 (and
755 (if (y-or-n-p "Do you want to submit a report on CC Mode? ")
756 t (message "") nil)
757 (require 'reporter)
758 (reporter-submit-bug-report
759 c-mode-help-address
760 (concat "CC Mode " c-version " ("
761 (cond ((eq major-mode 'c++-mode) "C++")
762 ((eq major-mode 'c-mode) "C")
763 ((eq major-mode 'objc-mode) "ObjC")
764 ((eq major-mode 'java-mode) "Java")
765 ((eq major-mode 'idl-mode) "IDL")
766 ((eq major-mode 'pike-mode) "Pike")
767 )
768 ")")
769 (let ((vars (append
770 ;; report only the vars that affect indentation
771 c-style-variables
772 '(c-delete-function
773 c-electric-pound-behavior
774 c-indent-comments-syntactically-p
775 c-tab-always-indent
776 defun-prompt-regexp
777 tab-width
778 comment-column
779 parse-sexp-ignore-comments
780 ;; A brain-damaged XEmacs only variable that, if
781 ;; set to nil can cause all kinds of chaos.
782 signal-error-on-buffer-boundary
783 ;; Variables that affect line breaking and comments.
784 auto-fill-function
785 filladapt-mode
786 comment-multi-line
787 comment-start-skip
788 fill-prefix
789 paragraph-start
790 adaptive-fill-mode
791 adaptive-fill-regexp)
792 nil)))
793 (delq 'c-special-indent-hook vars)
794 (mapcar (lambda (var) (unless (boundp var) (delq var vars)))
795 '(signal-error-on-buffer-boundary
796 filladapt-mode
797 defun-prompt-regexp))
798 vars)
799 (lambda ()
800 (run-hooks 'c-prepare-bug-report-hooks)
801 (insert (format "Buffer Style: %s\n\nc-emacs-features: %s\n"
802 style c-features)))))))
803
804 \f
805 (cc-provide 'cc-mode)
806 ;;; cc-mode.el ends here