(gud-menu-map): Put gud-finish back on the
[bpt/emacs.git] / lisp / progmodes / cc-mode.el
CommitLineData
d9e94c22 1;;; cc-mode.el --- major mode for editing C and similar languages
785eecbb 2
034babe1 3;; Copyright (C) 1985,1987,1992-2003, 2004, 2005 Free Software Foundation, Inc.
785eecbb 4
d9e94c22
MS
5;; Authors: 2003- Alan Mackenzie
6;; 1998- Martin Stjernholm
7;; 1992-1999 Barry A. Warsaw
785eecbb
RS
8;; 1987 Dave Detlefs and Stewart Clamen
9;; 1985 Richard M. Stallman
0ec8351b 10;; Maintainer: bug-cc-mode@gnu.org
785eecbb 11;; Created: a long, long, time ago. adapted from the original c-mode.el
785eecbb
RS
12;; Keywords: c languages oop
13
785eecbb
RS
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
3efc2cd7
MS
27;; along with this program; see the file COPYING. If not, write to
28;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
29;; Boston, MA 02110-1301, USA.
785eecbb 30
d9e94c22 31;;; Commentary:
130c507e
GM
32
33;; NOTE: Read the commentary below for the right way to submit bug reports!
34;; NOTE: See the accompanying texinfo manual for details on using this mode!
d9e94c22 35;; Note: The version string is in cc-defs.
785eecbb
RS
36
37;; This package provides GNU Emacs major modes for editing C, C++,
d9e94c22
MS
38;; Objective-C, Java, CORBA's IDL, Pike and AWK code. As of the
39;; latest Emacs and XEmacs releases, it is the default package for
40;; editing these languages. This package is called "CC Mode", and
41;; should be spelled exactly this way.
0ec8351b
BW
42
43;; CC Mode supports K&R and ANSI C, ANSI C++, Objective-C, Java,
d9e94c22
MS
44;; CORBA's IDL, Pike and AWK with a consistent indentation model
45;; across all modes. This indentation model is intuitive and very
46;; flexible, so that almost any desired style of indentation can be
47;; supported. Installation, usage, and programming details are
48;; contained in an accompanying texinfo manual.
785eecbb
RS
49
50;; CC Mode's immediate ancestors were, c++-mode.el, cplus-md.el, and
51;; cplus-md1.el..
52
785eecbb 53;; To submit bug reports, type "C-c C-b". These will be sent to
0ec8351b
BW
54;; bug-gnu-emacs@gnu.org (mirrored as the Usenet newsgroup
55;; gnu.emacs.bug) as well as bug-cc-mode@gnu.org, which directly
56;; contacts the CC Mode maintainers. Questions can sent to
57;; help-gnu-emacs@gnu.org (mirrored as gnu.emacs.help) and/or
130c507e
GM
58;; bug-cc-mode@gnu.org. Please do not send bugs or questions to our
59;; personal accounts; we reserve the right to ignore such email!
785eecbb 60
785eecbb
RS
61;; Many, many thanks go out to all the folks on the beta test list.
62;; Without their patience, testing, insight, code contributions, and
63;; encouragement CC Mode would be a far inferior package.
64
65;; You can get the latest version of CC Mode, including PostScript
66;; documentation and separate individual files from:
67;;
91b807c9 68;; http://cc-mode.sourceforge.net/
0ec8351b
BW
69;;
70;; You can join a moderated CC Mode announcement-only mailing list by
71;; visiting
785eecbb 72;;
91b807c9 73;; http://lists.sourceforge.net/mailman/listinfo/cc-mode-announce
785eecbb
RS
74
75;;; Code:
76
51f606de
GM
77(eval-when-compile
78 (let ((load-path
130c507e
GM
79 (if (and (boundp 'byte-compile-dest-file)
80 (stringp byte-compile-dest-file))
81 (cons (file-name-directory byte-compile-dest-file) load-path)
51f606de 82 load-path)))
d9e94c22 83 (load "cc-bytecomp" nil t)))
130c507e
GM
84
85(cc-require 'cc-defs)
d9e94c22 86(cc-require-when-compile 'cc-langs)
130c507e 87(cc-require 'cc-vars)
130c507e 88(cc-require 'cc-engine)
d9e94c22 89(cc-require 'cc-styles)
130c507e
GM
90(cc-require 'cc-cmds)
91(cc-require 'cc-align)
d9e94c22 92(cc-require 'cc-menus)
130c507e 93
3efc2cd7 94;; Silence the compiler.
130c507e
GM
95(cc-bytecomp-defvar comment-line-break-function) ; (X)Emacs 20+
96(cc-bytecomp-defvar adaptive-fill-first-line-regexp) ; Emacs 20+
97(cc-bytecomp-defun set-keymap-parents) ; XEmacs
3efc2cd7
MS
98(cc-bytecomp-defun run-mode-hooks) ; Emacs 21.1+
99(cc-bytecomp-obsolete-fun make-local-hook) ; Marked obsolete in Emacs 21.1.
130c507e 100
d9e94c22
MS
101;; We set these variables during mode init, yet we don't require
102;; font-lock.
103(cc-bytecomp-defvar font-lock-defaults)
104(cc-bytecomp-defvar font-lock-syntactic-keywords)
105
130c507e
GM
106;; Menu support for both XEmacs and Emacs. If you don't have easymenu
107;; with your version of Emacs, you are incompatible!
d9e94c22
MS
108(cc-external-require 'easymenu)
109
110;; Load cc-fonts first after font-lock is loaded, since it isn't
111;; necessary until font locking is requested.
112(eval-after-load "font-lock"
113 '(require 'cc-fonts))
114
115;; cc-langs isn't loaded when we're byte compiled, so add autoload
116;; directives for the interface functions.
117(autoload 'c-make-init-lang-vars-fun "cc-langs")
118(autoload 'c-init-language-vars "cc-langs" nil nil 'macro)
785eecbb
RS
119
120\f
1dad6919
RS
121;; Other modes and packages which depend on CC Mode should do the
122;; following to make sure everything is loaded and available for their
123;; use:
124;;
125;; (require 'cc-mode)
a66cd3ee
MS
126;;
127;; And in the major mode function:
128;;
d9e94c22
MS
129;; (c-initialize-cc-mode t)
130;; (c-init-language-vars some-mode)
131;; (c-common-init 'some-mode) ; Or perhaps (c-basic-common-init 'some-mode)
132;;
28d88c16
MS
133;; If you're not writing a derived mode using the language variable
134;; system, then some-mode is one of the language modes directly
135;; supported by CC Mode. You can then use (c-init-language-vars-for
136;; 'some-mode) instead of `c-init-language-vars'.
137;; `c-init-language-vars-for' is a function that avoids the rather
138;; large expansion of `c-init-language-vars'.
139;;
140;; If you use `c-basic-common-init' then you might want to call
141;; `c-font-lock-init' too to set up CC Mode's font lock support.
142;;
d9e94c22
MS
143;; See cc-langs.el for further info. A small example of a derived mode
144;; is also available at <http://cc-mode.sourceforge.net/
145;; derived-mode-ex.el>.
1dad6919 146
a66cd3ee
MS
147(defun c-leave-cc-mode-mode ()
148 (setq c-buffer-is-cc-mode nil))
149
28d88c16
MS
150(defun c-init-language-vars-for (mode)
151 "Initialize the language variables for one of the language modes
152directly supported by CC Mode. This can be used instead of the
153`c-init-language-vars' macro if the language you want to use is one of
154those, rather than a derived language defined through the language
155variable system (see \"cc-langs.el\")."
156 ;; This function does not do any hidden buffer changes.
157 (cond ((eq mode 'c-mode) (c-init-language-vars c-mode))
158 ((eq mode 'c++-mode) (c-init-language-vars c++-mode))
159 ((eq mode 'objc-mode) (c-init-language-vars objc-mode))
160 ((eq mode 'java-mode) (c-init-language-vars java-mode))
161 ((eq mode 'idl-mode) (c-init-language-vars idl-mode))
162 ((eq mode 'pike-mode) (c-init-language-vars pike-mode))
163 ((eq mode 'awk-mode) (c-init-language-vars awk-mode))
164 (t (error "Unsupported mode %s" mode))))
165
aac90c52 166;;;###autoload
d9e94c22
MS
167(defun c-initialize-cc-mode (&optional new-style-init)
168 "Initialize CC Mode for use in the current buffer.
169If the optional NEW-STYLE-INIT is nil or left out then all necessary
170initialization to run CC Mode for the C language is done. Otherwise
28d88c16
MS
171only some basic setup is done, and a call to `c-init-language-vars' or
172`c-init-language-vars-for' is necessary too (which gives more
173control). See \"cc-mode.el\" for more info."
d9e94c22
MS
174 ;;
175 ;; This function does not do any hidden buffer changes.
176
611c76a7 177 (setq c-buffer-is-cc-mode t)
d9e94c22 178
0ec8351b
BW
179 (let ((initprop 'cc-mode-is-initialized)
180 c-initialization-ok)
181 (unless (get 'c-initialize-cc-mode initprop)
0ec8351b
BW
182 (unwind-protect
183 (progn
51f606de
GM
184 (put 'c-initialize-cc-mode initprop t)
185 (c-initialize-builtin-style)
0ec8351b 186 (run-hooks 'c-initialization-hook)
51f606de
GM
187 ;; Fix obsolete variables.
188 (if (boundp 'c-comment-continuation-stars)
189 (setq c-block-comment-prefix c-comment-continuation-stars))
a66cd3ee 190 (add-hook 'change-major-mode-hook 'c-leave-cc-mode-mode)
0ec8351b
BW
191 (setq c-initialization-ok t))
192 ;; Will try initialization hooks again if they failed.
d9e94c22
MS
193 (put 'c-initialize-cc-mode initprop c-initialization-ok))))
194
195 (unless new-style-init
28d88c16 196 (c-init-language-vars-for 'c-mode)))
1dad6919
RS
197
198\f
d9e94c22
MS
199;;; Common routines.
200
130c507e
GM
201(defvar c-mode-base-map ()
202 "Keymap shared by all CC Mode related modes.")
203
204(defun c-make-inherited-keymap ()
205 (let ((map (make-sparse-keymap)))
3efc2cd7
MS
206 ;; Necessary to use `cc-bytecomp-fboundp' below since this
207 ;; function is called from top-level forms that are evaluated
208 ;; while cc-bytecomp is active when one does M-x eval-buffer.
130c507e 209 (cond
d9e94c22 210 ;; XEmacs
3efc2cd7 211 ((cc-bytecomp-fboundp 'set-keymap-parents)
130c507e 212 (set-keymap-parents map c-mode-base-map))
d9e94c22 213 ;; Emacs
3efc2cd7 214 ((cc-bytecomp-fboundp 'set-keymap-parent)
130c507e
GM
215 (set-keymap-parent map c-mode-base-map))
216 ;; incompatible
217 (t (error "CC Mode is incompatible with this version of Emacs")))
218 map))
219
a66cd3ee
MS
220(defun c-define-abbrev-table (name defs)
221 ;; Compatibility wrapper for `define-abbrev' which passes a non-nil
222 ;; sixth argument for SYSTEM-FLAG in emacsen that support it
223 ;; (currently only Emacs 21.2).
d9e94c22
MS
224 (let ((table (or (symbol-value name)
225 (progn (define-abbrev-table name nil)
226 (symbol-value name)))))
a66cd3ee
MS
227 (while defs
228 (condition-case nil
229 (apply 'define-abbrev table (append (car defs) '(t)))
230 (wrong-number-of-arguments
231 (apply 'define-abbrev table (car defs))))
232 (setq defs (cdr defs)))))
d9e94c22 233(put 'c-define-abbrev-table 'lisp-indent-function 1)
a66cd3ee 234
130c507e
GM
235(if c-mode-base-map
236 nil
237 ;; TBD: should we even worry about naming this keymap. My vote: no,
238 ;; because Emacs and XEmacs do it differently.
239 (setq c-mode-base-map (make-sparse-keymap))
240 ;; put standard keybindings into MAP
241 ;; the following mappings correspond more or less directly to BOCM
242 (define-key c-mode-base-map "{" 'c-electric-brace)
243 (define-key c-mode-base-map "}" 'c-electric-brace)
244 (define-key c-mode-base-map ";" 'c-electric-semi&comma)
245 (define-key c-mode-base-map "#" 'c-electric-pound)
246 (define-key c-mode-base-map ":" 'c-electric-colon)
247 (define-key c-mode-base-map "(" 'c-electric-paren)
248 (define-key c-mode-base-map ")" 'c-electric-paren)
249 ;; Separate M-BS from C-M-h. The former should remain
250 ;; backward-kill-word.
251 (define-key c-mode-base-map [(control meta h)] 'c-mark-function)
252 (define-key c-mode-base-map "\e\C-q" 'c-indent-exp)
253 (substitute-key-definition 'backward-sentence
254 'c-beginning-of-statement
255 c-mode-base-map global-map)
256 (substitute-key-definition 'forward-sentence
257 'c-end-of-statement
258 c-mode-base-map global-map)
259 (substitute-key-definition 'indent-new-comment-line
260 'c-indent-new-comment-line
261 c-mode-base-map global-map)
a66cd3ee
MS
262 (when (fboundp 'comment-indent-new-line)
263 ;; indent-new-comment-line has changed name to
264 ;; comment-indent-new-line in Emacs 21.
265 (substitute-key-definition 'comment-indent-new-line
266 'c-indent-new-comment-line
267 c-mode-base-map global-map))
130c507e
GM
268 ;; RMS says don't make these the default.
269;; (define-key c-mode-base-map "\e\C-a" 'c-beginning-of-defun)
270;; (define-key c-mode-base-map "\e\C-e" 'c-end-of-defun)
271 (define-key c-mode-base-map "\C-c\C-n" 'c-forward-conditional)
272 (define-key c-mode-base-map "\C-c\C-p" 'c-backward-conditional)
273 (define-key c-mode-base-map "\C-c\C-u" 'c-up-conditional)
274 (substitute-key-definition 'indent-for-tab-command
275 'c-indent-command
276 c-mode-base-map global-map)
d9e94c22
MS
277
278 ;; It doesn't suffice to put `c-fill-paragraph' on
279 ;; `fill-paragraph-function' since `c-fill-paragraph' must be called
280 ;; before any fill prefix adaption is done. E.g. `filladapt-mode'
281 ;; replaces `fill-paragraph' and does the adaption before calling
282 ;; `fill-paragraph-function', and we have to mask comments etc
283 ;; before that. Also, `c-fill-paragraph' chains on to
284 ;; `fill-paragraph' and the value on `fill-parapgraph-function' to
285 ;; do the actual filling work.
130c507e
GM
286 (substitute-key-definition 'fill-paragraph 'c-fill-paragraph
287 c-mode-base-map global-map)
288 ;; In XEmacs the default fill function is called
289 ;; fill-paragraph-or-region.
290 (substitute-key-definition 'fill-paragraph-or-region 'c-fill-paragraph
291 c-mode-base-map global-map)
d9e94c22 292
6d28be1d
EZ
293 ;; Bind the electric deletion functions to C-d and DEL. Emacs 21
294 ;; automatically maps the [delete] and [backspace] keys to these two
295 ;; depending on window system and user preferences. (In earlier
296 ;; versions it's possible to do the same by using `function-key-map'.)
297 (define-key c-mode-base-map "\C-d" 'c-electric-delete-forward)
298 (define-key c-mode-base-map "\177" 'c-electric-backspace)
299 (when (boundp 'delete-key-deletes-forward)
300 ;; In XEmacs 20 and later we fix the forward and backward deletion
301 ;; behavior by binding the keysyms for the [delete] and
302 ;; [backspace] keys directly, and use `delete-forward-p' or
303 ;; `delete-key-deletes-forward' to decide what [delete] should do.
304 (define-key c-mode-base-map [delete] 'c-electric-delete)
305 (define-key c-mode-base-map [backspace] 'c-electric-backspace))
130c507e
GM
306 (define-key c-mode-base-map "," 'c-electric-semi&comma)
307 (define-key c-mode-base-map "*" 'c-electric-star)
308 (define-key c-mode-base-map "/" 'c-electric-slash)
309 (define-key c-mode-base-map "\C-c\C-q" 'c-indent-defun)
310 (define-key c-mode-base-map "\C-c\C-\\" 'c-backslash-region)
130c507e
GM
311 (define-key c-mode-base-map "\C-c\C-a" 'c-toggle-auto-state)
312 (define-key c-mode-base-map "\C-c\C-b" 'c-submit-bug-report)
313 (define-key c-mode-base-map "\C-c\C-c" 'comment-region)
314 (define-key c-mode-base-map "\C-c\C-d" 'c-toggle-hungry-state)
315 (define-key c-mode-base-map "\C-c\C-o" 'c-set-offset)
316 (define-key c-mode-base-map "\C-c\C-s" 'c-show-syntactic-information)
317 (define-key c-mode-base-map "\C-c\C-t" 'c-toggle-auto-hungry-state)
318 (define-key c-mode-base-map "\C-c." 'c-set-style)
319 ;; conflicts with OOBR
320 ;;(define-key c-mode-base-map "\C-c\C-v" 'c-version)
321 )
322
130c507e
GM
323;; We don't require the outline package, but we configure it a bit anyway.
324(cc-bytecomp-defvar outline-level)
325
d9e94c22
MS
326(defun c-mode-menu (modestr)
327 "Return a menu spec suitable for `easy-menu-define' that is exactly
328like the C mode menu except that the menu bar item name is MODESTR
329instead of \"C\".
330
331This function is provided for compatibility only; derived modes should
332preferably use the `c-mode-menu' language constant directly."
333 (cons modestr (c-lang-const c-mode-menu c)))
334
335;; Ugly hack to pull in the definition of `c-populate-syntax-table'
336;; from cc-langs to make it available at runtime. It's either this or
337;; moving the definition for it to cc-defs, but that would mean to
338;; break up the syntax table setup over two files.
339(defalias 'c-populate-syntax-table
340 (cc-eval-when-compile
341 (let ((f (symbol-function 'c-populate-syntax-table)))
342 (if (byte-code-function-p f) f (byte-compile f)))))
343
344(defun c-after-change (beg end len)
345 ;; Function put on `after-change-functions' to adjust various
346 ;; caches. Prefer speed to finesse here, since there will be an
347 ;; order of magnitude more calls to this function than any of the
348 ;; functions that use the caches.
349 ;;
350 ;; Note that care must be taken so that this is called before any
351 ;; font-lock callbacks since we might get calls to functions using
352 ;; these caches from inside them, and we must thus be sure that this
353 ;; has already been executed.
354 ;;
355 ;; This function does not do any hidden buffer changes.
356
357 (c-save-buffer-state ()
358 (when (> end (point-max))
359 ;; Some emacsen might return positions past the end. This has been
360 ;; observed in Emacs 20.7 when rereading a buffer changed on disk
361 ;; (haven't been able to minimize it, but Emacs 21.3 appears to
362 ;; work).
363 (setq end (point-max))
364 (when (> beg end)
365 (setq beg end)))
366
367 (c-invalidate-sws-region-after beg end)
368 (c-invalidate-state-cache beg)
369 (c-invalidate-find-decl-cache beg)))
370
371(defun c-basic-common-init (mode default-style)
372 "Do the necessary initialization for the syntax handling routines
373and the line breaking/filling code. Intended to be used by other
374packages that embed CC Mode.
375
376MODE is the CC Mode flavor to set up, e.g. 'c-mode or 'java-mode.
377DEFAULT-STYLE tells which indentation style to install. It has the
378same format as `c-default-style'.
379
380Note that `c-init-language-vars' must be called before this function.
381This function cannot do that since `c-init-language-vars' is a macro
382that requires a literal mode spec at compile time."
383 ;;
384 ;; This function does not do any hidden buffer changes.
385
a66cd3ee
MS
386 (setq c-buffer-is-cc-mode mode)
387
130c507e
GM
388 ;; these variables should always be buffer local; they do not affect
389 ;; indentation style.
130c507e
GM
390 (make-local-variable 'parse-sexp-ignore-comments)
391 (make-local-variable 'indent-line-function)
392 (make-local-variable 'indent-region-function)
130c507e
GM
393 (make-local-variable 'normal-auto-fill-function)
394 (make-local-variable 'comment-start)
395 (make-local-variable 'comment-end)
130c507e
GM
396 (make-local-variable 'comment-start-skip)
397 (make-local-variable 'comment-multi-line)
a66cd3ee 398
130c507e 399 ;; now set their values
e2c21e66 400 (setq parse-sexp-ignore-comments t
130c507e
GM
401 indent-line-function 'c-indent-line
402 indent-region-function 'c-indent-region
130c507e 403 normal-auto-fill-function 'c-do-auto-fill
130c507e 404 comment-multi-line t)
a66cd3ee 405
fd8771f5
MS
406 ;; Install `c-fill-paragraph' on `fill-paragraph-function' so that a
407 ;; direct call to `fill-paragraph' behaves better. This still
408 ;; doesn't work with filladapt but it's better than nothing.
409 (make-local-variable 'fill-paragraph-function)
410 (setq fill-paragraph-function 'c-fill-paragraph)
411
d9e94c22
MS
412 ;; (X)Emacs 20 and later.
413 (when (boundp 'comment-line-break-function)
414 (make-local-variable 'comment-line-break-function)
415 (setq comment-line-break-function
416 'c-indent-new-comment-line))
417
418 ;; Emacs 20 and later.
419 (when (boundp 'parse-sexp-lookup-properties)
420 (make-local-variable 'parse-sexp-lookup-properties)
421 (setq parse-sexp-lookup-properties t))
422
423 ;; Same as above for XEmacs 21 (although currently undocumented).
424 (when (boundp 'lookup-syntax-properties)
425 (make-local-variable 'lookup-syntax-properties)
426 (setq lookup-syntax-properties t))
427
428 ;; Use this in Emacs 21 to avoid meddling with the rear-nonsticky
429 ;; property on each character.
430 (when (boundp 'text-property-default-nonsticky)
431 (make-local-variable 'text-property-default-nonsticky)
432 (let ((elem (assq 'syntax-table text-property-default-nonsticky)))
433 (if elem
434 (setcdr elem t)
435 (setq text-property-default-nonsticky
436 (cons '(syntax-table . t)
437 text-property-default-nonsticky))))
438 (setq text-property-default-nonsticky
439 (cons '(c-type . t)
440 text-property-default-nonsticky)))
441
442 ;; In Emacs 21 and later it's possible to turn off the ad-hoc
443 ;; heuristic that open parens in column 0 are defun starters. Since
444 ;; we have c-state-cache that isn't useful and only causes trouble
445 ;; so turn it off.
446 (when (memq 'col-0-paren c-emacs-features)
447 (make-local-variable 'open-paren-in-column-0-is-defun-start)
448 (setq open-paren-in-column-0-is-defun-start nil))
449
450 ;; The `c-type' text property with `c-decl-end' is used to mark the
451 ;; ends of access keys to make interactive refontification work
452 ;; better.
453 (when c-opt-access-key
454 (setq c-type-decl-end-used t))
455
456 (c-clear-found-types)
457
458 ;; now set the mode style based on default-style
459 (let ((style (if (stringp default-style)
460 default-style
461 (or (cdr (assq mode default-style))
462 (cdr (assq 'other default-style))
130c507e
GM
463 "gnu"))))
464 ;; Override style variables if `c-old-style-variable-behavior' is
465 ;; set. Also override if we are using global style variables,
466 ;; have already initialized a style once, and are switching to a
467 ;; different style. (It's doubtful whether this is desirable, but
468 ;; the whole situation with nonlocal style variables is a bit
469 ;; awkward. It's at least the most compatible way with the old
470 ;; style init procedure.)
471 (c-set-style style (not (or c-old-style-variable-behavior
472 (and (not c-style-variables-are-local-p)
473 c-indentation-style
474 (not (string-equal c-indentation-style
475 style)))))))
a66cd3ee
MS
476 (c-setup-paragraph-variables)
477
130c507e
GM
478 ;; we have to do something special for c-offsets-alist so that the
479 ;; buffer local value has its own alist structure.
480 (setq c-offsets-alist (copy-alist c-offsets-alist))
a66cd3ee 481
130c507e 482 ;; setup the comment indent variable in a Emacs version portable way
130c507e
GM
483 (make-local-variable 'comment-indent-function)
484 (setq comment-indent-function 'c-comment-indent)
a66cd3ee 485
130c507e
GM
486 ;; put auto-hungry designators onto minor-mode-alist, but only once
487 (or (assq 'c-auto-hungry-string minor-mode-alist)
488 (setq minor-mode-alist
489 (cons '(c-auto-hungry-string c-auto-hungry-string)
490 minor-mode-alist)))
a66cd3ee 491
d9e94c22
MS
492 ;; Install the functions that ensure that various internal caches
493 ;; don't become invalid due to buffer changes.
d9e94c22
MS
494 (add-hook 'after-change-functions 'c-after-change nil t))
495
496(defun c-after-font-lock-init ()
497 ;; Put on `font-lock-mode-hook'.
498 (remove-hook 'after-change-functions 'c-after-change t)
499 (add-hook 'after-change-functions 'c-after-change nil t))
500
501(defun c-font-lock-init ()
502 "Set up the font-lock variables for using the font-lock support in CC Mode.
503This does not load the font-lock package. Use after
504`c-basic-common-init' and after cc-fonts has been loaded."
505
506 (make-local-variable 'font-lock-defaults)
507 (setq font-lock-defaults
508 `(,(if (c-mode-is-new-awk-p)
509 ;; awk-mode currently has only one font lock level.
510 'awk-font-lock-keywords
511 (mapcar 'c-mode-symbol
512 '("font-lock-keywords" "font-lock-keywords-1"
513 "font-lock-keywords-2" "font-lock-keywords-3")))
514 nil nil
515 ,c-identifier-syntax-modifications
516 c-beginning-of-syntax
5ac71a6a 517 (font-lock-lines-before . 1)
d9e94c22
MS
518 (font-lock-mark-block-function
519 . c-mark-function)))
d9e94c22
MS
520 (add-hook 'font-lock-mode-hook 'c-after-font-lock-init nil t))
521
522(defun c-setup-doc-comment-style ()
523 "Initialize the variables that depend on the value of `c-doc-comment-style'."
524 (when (and (featurep 'font-lock)
525 (symbol-value 'font-lock-mode))
526 ;; Force font lock mode to reinitialize itself.
527 (font-lock-mode 0)
528 (font-lock-mode 1)))
529
530(defun c-common-init (&optional mode)
531 "Common initialization for all CC Mode modes.
532In addition to the work done by `c-basic-common-init' and
533`c-font-lock-init', this function sets up various other things as
534customary in CC Mode modes but which aren't strictly necessary for CC
535Mode to operate correctly.
536
537MODE is the symbol for the mode to initialize, like 'c-mode. See
538`c-basic-common-init' for details. It's only optional to be
539compatible with old code; callers should always specify it.
540
541This function does not do any hidden buffer changes."
542
543 (unless mode
544 ;; Called from an old third party package. The fallback is to
545 ;; initialize for C.
28d88c16 546 (c-init-language-vars-for 'c-mode))
d9e94c22
MS
547
548 (c-basic-common-init mode c-default-style)
549 (when mode
550 ;; Only initialize font locking if we aren't called from an old package.
551 (c-font-lock-init))
552
553 (make-local-variable 'outline-regexp)
554 (make-local-variable 'outline-level)
555 (setq outline-regexp "[^#\n\^M]"
556 outline-level 'c-outline-level)
557
558 (let ((rfn (assq mode c-require-final-newline)))
559 (when rfn
560 (make-local-variable 'require-final-newline)
1750e02f
RS
561 (and (cdr rfn)
562 (setq require-final-newline mode-require-final-newline)))))
130c507e
GM
563
564(defun c-postprocess-file-styles ()
d9e94c22 565 "Function that post processes relevant file local variables in CC Mode.
130c507e
GM
566Currently, this function simply applies any style and offset settings
567found in the file's Local Variable list. It first applies any style
568setting found in `c-file-style', then it applies any offset settings
569it finds in `c-file-offsets'.
570
571Note that the style variables are always made local to the buffer."
d9e94c22
MS
572 ;;
573 ;; This function does not do any hidden buffer changes.
574
130c507e 575 ;; apply file styles and offsets
09f90d2c
RS
576 (when c-buffer-is-cc-mode
577 (if (or c-file-style c-file-offsets)
578 (c-make-styles-buffer-local t))
579 (and c-file-style
580 (c-set-style c-file-style))
581 (and c-file-offsets
582 (mapcar
583 (lambda (langentry)
584 (let ((langelem (car langentry))
585 (offset (cdr langentry)))
586 (c-set-offset langelem offset)))
587 c-file-offsets))))
130c507e
GM
588
589(add-hook 'hack-local-variables-hook 'c-postprocess-file-styles)
590
3efc2cd7
MS
591(defmacro c-run-mode-hooks (&rest hooks)
592 ;; Emacs 21.1 has introduced a system with delayed mode hooks that
593 ;; require the use of the new function `run-mode-hooks'.
594 (if (cc-bytecomp-fboundp 'run-mode-hooks)
595 `(run-mode-hooks ,@hooks)
596 `(progn ,@(mapcar (lambda (hook) `(run-hooks ,hook)) hooks))))
597
130c507e
GM
598\f
599;; Support for C
600
d9e94c22
MS
601;;;###autoload
602(defvar c-mode-syntax-table nil
603 "Syntax table used in c-mode buffers.")
604(or c-mode-syntax-table
605 (setq c-mode-syntax-table
606 (funcall (c-lang-const c-make-mode-syntax-table c))))
607
130c507e
GM
608(defvar c-mode-abbrev-table nil
609 "Abbreviation table used in c-mode buffers.")
a66cd3ee
MS
610(c-define-abbrev-table 'c-mode-abbrev-table
611 '(("else" "else" c-electric-continued-statement 0)
612 ("while" "while" c-electric-continued-statement 0)))
130c507e
GM
613
614(defvar c-mode-map ()
615 "Keymap used in c-mode buffers.")
616(if c-mode-map
617 nil
618 (setq c-mode-map (c-make-inherited-keymap))
619 ;; add bindings which are only useful for C
620 (define-key c-mode-map "\C-c\C-e" 'c-macro-expand)
621 )
622
623(easy-menu-define c-c-menu c-mode-map "C Mode Commands"
d9e94c22
MS
624 (cons "C" (c-lang-const c-mode-menu c)))
625
626;; In XEmacs >= 21.5 modes should add their own entries to
627;; `auto-mode-alist'. The comment form of autoload is used to avoid
628;; doing this on load. That since `add-to-list' prepends the value
629;; which could cause it to clobber user settings. Later emacsen have
630;; an append option, but it's not safe to use.
50fdde0e
MS
631
632;; The the extension ".C" is associated to C++ while the lowercase
633;; variant goes to C. On case insensitive file systems, this means
634;; that ".c" files also might open C++ mode if the C++ entry comes
635;; first on `auto-mode-alist'. Thus we try to ensure that ".C" comes
636;; after ".c", and since `add-to-list' adds the entry first we have to
637;; add the ".C" entry first.
638;;;###autoload (add-to-list 'auto-mode-alist '("\\.\\(cc\\|hh\\)\\'" . c++-mode))
639;;;###autoload (add-to-list 'auto-mode-alist '("\\.[ch]\\(pp\\|xx\\|\\+\\+\\)\\'" . c++-mode))
640;;;###autoload (add-to-list 'auto-mode-alist '("\\.\\(CC?\\|HH?\\)\\'" . c++-mode))
641
d9e94c22
MS
642;;;###autoload (add-to-list 'auto-mode-alist '("\\.[ch]\\'" . c-mode))
643
644;; NB: The following two associate yacc and lex files to C Mode, which
645;; is not really suitable for those formats. Anyway, afaik there's
646;; currently no better mode for them, and besides this is legacy.
647;;;###autoload (add-to-list 'auto-mode-alist '("\\.y\\(acc\\)?\\'" . c-mode))
648;;;###autoload (add-to-list 'auto-mode-alist '("\\.lex\\'" . c-mode))
649
785eecbb
RS
650;;;###autoload
651(defun c-mode ()
652 "Major mode for editing K&R and ANSI C code.
653To submit a problem report, enter `\\[c-submit-bug-report]' from a
654c-mode buffer. This automatically sets up a mail buffer with version
655information already added. You just need to add a description of the
50fdde0e 656problem, including a reproducible test case, and send the message.
785eecbb
RS
657
658To see what version of CC Mode you are running, enter `\\[c-version]'.
659
d9e94c22
MS
660The hook `c-mode-common-hook' is run with no args at mode
661initialization, then `c-mode-hook'.
785eecbb
RS
662
663Key bindings:
664\\{c-mode-map}"
665 (interactive)
785eecbb 666 (kill-all-local-variables)
d9e94c22 667 (c-initialize-cc-mode t)
785eecbb
RS
668 (set-syntax-table c-mode-syntax-table)
669 (setq major-mode 'c-mode
670 mode-name "C"
130c507e
GM
671 local-abbrev-table c-mode-abbrev-table
672 abbrev-mode t)
785eecbb 673 (use-local-map c-mode-map)
28d88c16 674 (c-init-language-vars-for 'c-mode)
a66cd3ee 675 (c-common-init 'c-mode)
d9e94c22 676 (easy-menu-add c-c-menu)
51f606de 677 (cc-imenu-init cc-imenu-c-generic-expression)
3efc2cd7 678 (c-run-mode-hooks 'c-mode-common-hook 'c-mode-hook)
785eecbb
RS
679 (c-update-modeline))
680
681\f
130c507e
GM
682;; Support for C++
683
d9e94c22
MS
684;;;###autoload
685(defvar c++-mode-syntax-table nil
686 "Syntax table used in c++-mode buffers.")
687(or c++-mode-syntax-table
688 (setq c++-mode-syntax-table
689 (funcall (c-lang-const c-make-mode-syntax-table c++))))
690
130c507e
GM
691(defvar c++-mode-abbrev-table nil
692 "Abbreviation table used in c++-mode buffers.")
a66cd3ee
MS
693(c-define-abbrev-table 'c++-mode-abbrev-table
694 '(("else" "else" c-electric-continued-statement 0)
695 ("while" "while" c-electric-continued-statement 0)
696 ("catch" "catch" c-electric-continued-statement 0)))
130c507e
GM
697
698(defvar c++-mode-map ()
699 "Keymap used in c++-mode buffers.")
700(if c++-mode-map
701 nil
702 (setq c++-mode-map (c-make-inherited-keymap))
703 ;; add bindings which are only useful for C++
704 (define-key c++-mode-map "\C-c\C-e" 'c-macro-expand)
705 (define-key c++-mode-map "\C-c:" 'c-scope-operator)
706 (define-key c++-mode-map "<" 'c-electric-lt-gt)
707 (define-key c++-mode-map ">" 'c-electric-lt-gt))
708
709(easy-menu-define c-c++-menu c++-mode-map "C++ Mode Commands"
d9e94c22
MS
710 (cons "C++" (c-lang-const c-mode-menu c++)))
711
785eecbb
RS
712;;;###autoload
713(defun c++-mode ()
714 "Major mode for editing C++ code.
715To submit a problem report, enter `\\[c-submit-bug-report]' from a
716c++-mode buffer. This automatically sets up a mail buffer with
717version information already added. You just need to add a description
718of the problem, including a reproducible test case, and send the
719message.
720
721To see what version of CC Mode you are running, enter `\\[c-version]'.
722
d9e94c22
MS
723The hook `c-mode-common-hook' is run with no args at mode
724initialization, then `c++-mode-hook'.
785eecbb
RS
725
726Key bindings:
727\\{c++-mode-map}"
728 (interactive)
785eecbb 729 (kill-all-local-variables)
d9e94c22 730 (c-initialize-cc-mode t)
785eecbb
RS
731 (set-syntax-table c++-mode-syntax-table)
732 (setq major-mode 'c++-mode
733 mode-name "C++"
130c507e
GM
734 local-abbrev-table c++-mode-abbrev-table
735 abbrev-mode t)
785eecbb 736 (use-local-map c++-mode-map)
28d88c16 737 (c-init-language-vars-for 'c++-mode)
a66cd3ee 738 (c-common-init 'c++-mode)
d9e94c22 739 (easy-menu-add c-c++-menu)
51f606de 740 (cc-imenu-init cc-imenu-c++-generic-expression)
3efc2cd7 741 (c-run-mode-hooks 'c-mode-common-hook 'c++-mode-hook)
785eecbb
RS
742 (c-update-modeline))
743
744\f
130c507e
GM
745;; Support for Objective-C
746
d9e94c22
MS
747;;;###autoload
748(defvar objc-mode-syntax-table nil
749 "Syntax table used in objc-mode buffers.")
750(or objc-mode-syntax-table
751 (setq objc-mode-syntax-table
752 (funcall (c-lang-const c-make-mode-syntax-table objc))))
753
130c507e
GM
754(defvar objc-mode-abbrev-table nil
755 "Abbreviation table used in objc-mode buffers.")
a66cd3ee
MS
756(c-define-abbrev-table 'objc-mode-abbrev-table
757 '(("else" "else" c-electric-continued-statement 0)
758 ("while" "while" c-electric-continued-statement 0)))
130c507e
GM
759
760(defvar objc-mode-map ()
761 "Keymap used in objc-mode buffers.")
762(if objc-mode-map
763 nil
764 (setq objc-mode-map (c-make-inherited-keymap))
765 ;; add bindings which are only useful for Objective-C
766 (define-key objc-mode-map "\C-c\C-e" 'c-macro-expand))
767
768(easy-menu-define c-objc-menu objc-mode-map "ObjC Mode Commands"
d9e94c22
MS
769 (cons "ObjC" (c-lang-const c-mode-menu objc)))
770
771;;;###autoload (add-to-list 'auto-mode-alist '("\\.m\\'" . objc-mode))
130c507e 772
785eecbb
RS
773;;;###autoload
774(defun objc-mode ()
775 "Major mode for editing Objective C code.
776To submit a problem report, enter `\\[c-submit-bug-report]' from an
777objc-mode buffer. This automatically sets up a mail buffer with
778version information already added. You just need to add a description
779of the problem, including a reproducible test case, and send the
780message.
781
782To see what version of CC Mode you are running, enter `\\[c-version]'.
783
d9e94c22
MS
784The hook `c-mode-common-hook' is run with no args at mode
785initialization, then `objc-mode-hook'.
785eecbb
RS
786
787Key bindings:
788\\{objc-mode-map}"
789 (interactive)
785eecbb 790 (kill-all-local-variables)
d9e94c22 791 (c-initialize-cc-mode t)
785eecbb
RS
792 (set-syntax-table objc-mode-syntax-table)
793 (setq major-mode 'objc-mode
794 mode-name "ObjC"
130c507e
GM
795 local-abbrev-table objc-mode-abbrev-table
796 abbrev-mode t)
d9e94c22
MS
797 ;; The `c-type' text property with `c-decl-end' is used to mark the
798 ;; end of the @-style directives.
799 (setq c-type-decl-end-used t)
785eecbb 800 (use-local-map objc-mode-map)
28d88c16 801 (c-init-language-vars-for 'objc-mode)
a66cd3ee 802 (c-common-init 'objc-mode)
d9e94c22
MS
803 (easy-menu-add c-objc-menu)
804 (cc-imenu-init nil 'cc-imenu-objc-function)
3efc2cd7 805 (c-run-mode-hooks 'c-mode-common-hook 'objc-mode-hook)
785eecbb
RS
806 (c-update-modeline))
807
808\f
130c507e
GM
809;; Support for Java
810
d9e94c22
MS
811;;;###autoload
812(defvar java-mode-syntax-table nil
813 "Syntax table used in java-mode buffers.")
814(or java-mode-syntax-table
815 (setq java-mode-syntax-table
816 (funcall (c-lang-const c-make-mode-syntax-table java))))
817
130c507e
GM
818(defvar java-mode-abbrev-table nil
819 "Abbreviation table used in java-mode buffers.")
a66cd3ee
MS
820(c-define-abbrev-table 'java-mode-abbrev-table
821 '(("else" "else" c-electric-continued-statement 0)
822 ("while" "while" c-electric-continued-statement 0)
823 ("catch" "catch" c-electric-continued-statement 0)
824 ("finally" "finally" c-electric-continued-statement 0)))
130c507e
GM
825
826(defvar java-mode-map ()
827 "Keymap used in java-mode buffers.")
828(if java-mode-map
829 nil
830 (setq java-mode-map (c-make-inherited-keymap))
831 ;; add bindings which are only useful for Java
832 )
833
d9e94c22
MS
834;; Regexp trying to describe the beginning of a Java top-level
835;; definition. This is not used by CC Mode, nor is it maintained
836;; since it's practically impossible to write a regexp that reliably
837;; matches such a construct. Other tools are necessary.
838(defconst c-Java-defun-prompt-regexp
839 "^[ \t]*\\(\\(\\(public\\|protected\\|private\\|const\\|abstract\\|synchronized\\|final\\|static\\|threadsafe\\|transient\\|native\\|volatile\\)\\s-+\\)*\\(\\(\\([[a-zA-Z][][_$.a-zA-Z0-9]*[][_$.a-zA-Z0-9]+\\|[[a-zA-Z]\\)\\s-*\\)\\s-+\\)\\)?\\(\\([[a-zA-Z][][_$.a-zA-Z0-9]*\\s-+\\)\\s-*\\)?\\([_a-zA-Z][^][ \t:;.,{}()\7f=]*\\|\\([_$a-zA-Z][_$.a-zA-Z0-9]*\\)\\)\\s-*\\(([^);{}]*)\\)?\\([] \t]*\\)\\(\\s-*\\<throws\\>\\s-*\\(\\([_$a-zA-Z][_$.a-zA-Z0-9]*\\)[, \t\n\r\f\v]*\\)+\\)?\\s-*")
840
130c507e 841(easy-menu-define c-java-menu java-mode-map "Java Mode Commands"
d9e94c22
MS
842 (cons "Java" (c-lang-const c-mode-menu java)))
843
844;;;###autoload (add-to-list 'auto-mode-alist '("\\.java\\'" . java-mode))
130c507e 845
785eecbb
RS
846;;;###autoload
847(defun java-mode ()
848 "Major mode for editing Java code.
dc2b4c5f 849To submit a problem report, enter `\\[c-submit-bug-report]' from a
785eecbb
RS
850java-mode buffer. This automatically sets up a mail buffer with
851version information already added. You just need to add a description
50fdde0e 852of the problem, including a reproducible test case, and send the
785eecbb
RS
853message.
854
855To see what version of CC Mode you are running, enter `\\[c-version]'.
856
d9e94c22
MS
857The hook `c-mode-common-hook' is run with no args at mode
858initialization, then `java-mode-hook'.
785eecbb
RS
859
860Key bindings:
861\\{java-mode-map}"
862 (interactive)
785eecbb 863 (kill-all-local-variables)
d9e94c22 864 (c-initialize-cc-mode t)
785eecbb
RS
865 (set-syntax-table java-mode-syntax-table)
866 (setq major-mode 'java-mode
867 mode-name "Java"
91b807c9 868 local-abbrev-table java-mode-abbrev-table
a66cd3ee 869 abbrev-mode t)
785eecbb 870 (use-local-map java-mode-map)
28d88c16 871 (c-init-language-vars-for 'java-mode)
a66cd3ee 872 (c-common-init 'java-mode)
d9e94c22 873 (easy-menu-add c-java-menu)
51f606de 874 (cc-imenu-init cc-imenu-java-generic-expression)
3efc2cd7 875 (c-run-mode-hooks 'c-mode-common-hook 'java-mode-hook)
785eecbb
RS
876 (c-update-modeline))
877
878\f
130c507e
GM
879;; Support for CORBA's IDL language
880
d9e94c22
MS
881;;;###autoload
882(defvar idl-mode-syntax-table nil
883 "Syntax table used in idl-mode buffers.")
884(or idl-mode-syntax-table
885 (setq idl-mode-syntax-table
886 (funcall (c-lang-const c-make-mode-syntax-table idl))))
887
130c507e
GM
888(defvar idl-mode-abbrev-table nil
889 "Abbreviation table used in idl-mode buffers.")
a66cd3ee 890(c-define-abbrev-table 'idl-mode-abbrev-table nil)
130c507e
GM
891
892(defvar idl-mode-map ()
893 "Keymap used in idl-mode buffers.")
894(if idl-mode-map
895 nil
896 (setq idl-mode-map (c-make-inherited-keymap))
897 ;; add bindings which are only useful for IDL
898 )
899
900(easy-menu-define c-idl-menu idl-mode-map "IDL Mode Commands"
d9e94c22
MS
901 (cons "IDL" (c-lang-const c-mode-menu idl)))
902
903;;;###autoload (add-to-list 'auto-mode-alist '("\\.idl\\'" . idl-mode))
130c507e 904
aac90c52
RS
905;;;###autoload
906(defun idl-mode ()
d9e94c22 907 "Major mode for editing CORBA's IDL, PSDL and CIDL code.
aac90c52
RS
908To submit a problem report, enter `\\[c-submit-bug-report]' from an
909idl-mode buffer. This automatically sets up a mail buffer with
910version information already added. You just need to add a description
911of the problem, including a reproducible test case, and send the
912message.
913
914To see what version of CC Mode you are running, enter `\\[c-version]'.
915
d9e94c22
MS
916The hook `c-mode-common-hook' is run with no args at mode
917initialization, then `idl-mode-hook'.
aac90c52
RS
918
919Key bindings:
920\\{idl-mode-map}"
921 (interactive)
aac90c52 922 (kill-all-local-variables)
d9e94c22 923 (c-initialize-cc-mode t)
aac90c52
RS
924 (set-syntax-table idl-mode-syntax-table)
925 (setq major-mode 'idl-mode
926 mode-name "IDL"
927 local-abbrev-table idl-mode-abbrev-table)
928 (use-local-map idl-mode-map)
28d88c16 929 (c-init-language-vars-for 'idl-mode)
a66cd3ee 930 (c-common-init 'idl-mode)
d9e94c22
MS
931 (easy-menu-add c-idl-menu)
932 ;;(cc-imenu-init cc-imenu-idl-generic-expression) ;TODO
3efc2cd7 933 (c-run-mode-hooks 'c-mode-common-hook 'idl-mode-hook)
aac90c52
RS
934 (c-update-modeline))
935
936\f
130c507e
GM
937;; Support for Pike
938
d9e94c22
MS
939;;;###autoload
940(defvar pike-mode-syntax-table nil
941 "Syntax table used in pike-mode buffers.")
942(or pike-mode-syntax-table
943 (setq pike-mode-syntax-table
944 (funcall (c-lang-const c-make-mode-syntax-table pike))))
945
130c507e
GM
946(defvar pike-mode-abbrev-table nil
947 "Abbreviation table used in pike-mode buffers.")
a66cd3ee
MS
948(c-define-abbrev-table 'pike-mode-abbrev-table
949 '(("else" "else" c-electric-continued-statement 0)
950 ("while" "while" c-electric-continued-statement 0)))
130c507e
GM
951
952(defvar pike-mode-map ()
953 "Keymap used in pike-mode buffers.")
954(if pike-mode-map
955 nil
956 (setq pike-mode-map (c-make-inherited-keymap))
957 ;; additional bindings
958 (define-key pike-mode-map "\C-c\C-e" 'c-macro-expand))
959
960(easy-menu-define c-pike-menu pike-mode-map "Pike Mode Commands"
d9e94c22
MS
961 (cons "Pike" (c-lang-const c-mode-menu pike)))
962
50fdde0e
MS
963;;;###autoload (add-to-list 'auto-mode-alist '("\\.\\(u?lpc\\|pike\\|pmod\\(.in\\)?\\)\\'" . pike-mode))
964;;;###autoload (add-to-list 'interpreter-mode-alist '("pike" . pike-mode))
130c507e 965
0ec8351b
BW
966;;;###autoload
967(defun pike-mode ()
968 "Major mode for editing Pike code.
a66cd3ee
MS
969To submit a problem report, enter `\\[c-submit-bug-report]' from a
970pike-mode buffer. This automatically sets up a mail buffer with
0ec8351b
BW
971version information already added. You just need to add a description
972of the problem, including a reproducible test case, and send the
973message.
974
975To see what version of CC Mode you are running, enter `\\[c-version]'.
976
d9e94c22
MS
977The hook `c-mode-common-hook' is run with no args at mode
978initialization, then `pike-mode-hook'.
0ec8351b
BW
979
980Key bindings:
981\\{pike-mode-map}"
982 (interactive)
0ec8351b 983 (kill-all-local-variables)
d9e94c22 984 (c-initialize-cc-mode t)
0ec8351b
BW
985 (set-syntax-table pike-mode-syntax-table)
986 (setq major-mode 'pike-mode
987 mode-name "Pike"
130c507e 988 local-abbrev-table pike-mode-abbrev-table
a66cd3ee 989 abbrev-mode t)
0ec8351b 990 (use-local-map pike-mode-map)
28d88c16 991 (c-init-language-vars-for 'pike-mode)
a66cd3ee 992 (c-common-init 'pike-mode)
d9e94c22
MS
993 (easy-menu-add c-pike-menu)
994 ;;(cc-imenu-init cc-imenu-pike-generic-expression) ;TODO
3efc2cd7 995 (c-run-mode-hooks 'c-mode-common-hook 'pike-mode-hook)
0ec8351b
BW
996 (c-update-modeline))
997
998\f
d9e94c22
MS
999;; Support for awk. This is purposely disabled for older (X)Emacsen which
1000;; don't support syntax-table properties.
1001
50fdde0e
MS
1002;;;###autoload (add-to-list 'auto-mode-alist '("\\.awk\\'" . awk-mode))
1003;;;###autoload (add-to-list 'interpreter-mode-alist '("awk" . awk-mode))
1004;;;###autoload (add-to-list 'interpreter-mode-alist '("mawk" . awk-mode))
1005;;;###autoload (add-to-list 'interpreter-mode-alist '("nawk" . awk-mode))
1006;;;###autoload (add-to-list 'interpreter-mode-alist '("gawk" . awk-mode))
d9e94c22 1007
50fdde0e
MS
1008;;; Autoload directives must be on the top level, so we construct an
1009;;; autoload form instead.
791887d9 1010;;;###autoload (autoload 'awk-mode "cc-mode" "Major mode for editing AWK code." t)
50fdde0e
MS
1011
1012(if (not (memq 'syntax-properties c-emacs-features))
1013 (autoload 'awk-mode "awk-mode" "Major mode for editing AWK code." t)
d9e94c22 1014
d9e94c22
MS
1015 (defvar awk-mode-abbrev-table nil
1016 "Abbreviation table used in awk-mode buffers.")
1017 (c-define-abbrev-table 'awk-mode-abbrev-table
1018 '(("else" "else" c-electric-continued-statement 0)
1019 ("while" "while" c-electric-continued-statement 0)))
1020
1021 (defvar awk-mode-map ()
1022 "Keymap used in awk-mode buffers.")
1023 (if awk-mode-map
1024 nil
1025 (setq awk-mode-map (c-make-inherited-keymap))
1026 ;; add bindings which are only useful for awk.
1027 (define-key awk-mode-map "#" 'self-insert-command)
1028 (define-key awk-mode-map "/" 'self-insert-command)
1029 (define-key awk-mode-map "*" 'self-insert-command)
1030 (define-key awk-mode-map "\C-c\C-n" 'undefined) ; #if doesn't exist in awk.
1031 (define-key awk-mode-map "\C-c\C-p" 'undefined)
1032 (define-key awk-mode-map "\C-c\C-u" 'undefined)
1033 (define-key awk-mode-map "\M-a" 'undefined) ; c-awk-beginning-of-statement isn't yet implemented.
1034 (define-key awk-mode-map "\M-e" 'undefined) ; c-awk-end-of-statement isn't yet implemented.
1035 (define-key awk-mode-map "\C-\M-a" 'c-awk-beginning-of-defun)
1036 (define-key awk-mode-map "\C-\M-e" 'c-awk-end-of-defun))
1037
1038 (easy-menu-define c-awk-menu awk-mode-map "AWK Mode Commands"
1039 (cons "AWK" (c-lang-const c-mode-menu awk)))
1040
d9e94c22
MS
1041 (defun awk-mode ()
1042 "Major mode for editing AWK code.
1043To submit a problem report, enter `\\[c-submit-bug-report]' from an
1044awk-mode buffer. This automatically sets up a mail buffer with version
1045information already added. You just need to add a description of the
50fdde0e 1046problem, including a reproducible test case, and send the message.
d9e94c22
MS
1047
1048To see what version of CC Mode you are running, enter `\\[c-version]'.
1049
1050The hook `c-mode-common-hook' is run with no args at mode
1051initialization, then `awk-mode-hook'.
1052
1053Key bindings:
1054\\{awk-mode-map}"
1055 (interactive)
1056 (require 'cc-awk) ; Added 2003/6/10.
1057 (kill-all-local-variables)
1058 (c-initialize-cc-mode t)
1059 (set-syntax-table awk-mode-syntax-table)
1060 (setq major-mode 'awk-mode
1061 mode-name "AWK"
1062 local-abbrev-table awk-mode-abbrev-table
1063 abbrev-mode t)
1064 (use-local-map awk-mode-map)
28d88c16 1065 (c-init-language-vars-for 'awk-mode)
d9e94c22
MS
1066 (c-common-init 'awk-mode)
1067 ;; The rest of CC Mode does not (yet) use `font-lock-syntactic-keywords',
1068 ;; so it's not set by `c-font-lock-init'.
1069 (make-local-variable 'font-lock-syntactic-keywords)
1070 (setq font-lock-syntactic-keywords
1071 '((c-awk-set-syntax-table-properties
1072 0 (0) ; Everything on this line is a dummy.
1073 nil t)))
1074 (c-awk-unstick-NL-prop)
1075 (add-hook 'before-change-functions 'c-awk-before-change nil t)
1076 (add-hook 'after-change-functions 'c-awk-after-change nil t)
1077 (c-save-buffer-state nil
1078 (save-restriction
1079 (widen)
1080 (c-awk-clear-NL-props (point-min) (point-max))
1081 (c-awk-after-change (point-min) (point-max) 0))) ; Set syntax-table props.
1082
1083 ;; Prevent Xemacs's buffer-syntactic-context being used. See the comment
1084 ;; in cc-engine.el, just before (defun c-fast-in-literal ...
1085 (defalias 'c-in-literal 'c-slow-in-literal)
1086
3efc2cd7 1087 (c-run-mode-hooks 'c-mode-common-hook 'awk-mode-hook)
d9e94c22
MS
1088 (c-update-modeline))
1089) ;; closes the (if (not (memq 'syntax-properties c-emacs-features))
1090
1091\f
c2efc1d0 1092;; bug reporting
785eecbb
RS
1093
1094(defconst c-mode-help-address
a66cd3ee
MS
1095 "bug-cc-mode@gnu.org"
1096 "Address(es) for CC Mode bug reports.")
785eecbb
RS
1097
1098(defun c-version ()
1099 "Echo the current version of CC Mode in the minibuffer."
1100 (interactive)
1101 (message "Using CC Mode version %s" c-version)
1102 (c-keep-region-active))
1103
130c507e
GM
1104(defvar c-prepare-bug-report-hooks nil)
1105
1106;; Dynamic variables used by reporter.
1107(defvar reporter-prompt-for-summary-p)
1108(defvar reporter-dont-compact-list)
1109
785eecbb
RS
1110(defun c-submit-bug-report ()
1111 "Submit via mail a bug report on CC Mode."
1112 (interactive)
77e31a8d 1113 (require 'reporter)
785eecbb
RS
1114 ;; load in reporter
1115 (let ((reporter-prompt-for-summary-p t)
1116 (reporter-dont-compact-list '(c-offsets-alist))
1117 (style c-indentation-style)
785eecbb
RS
1118 (c-features c-emacs-features))
1119 (and
1120 (if (y-or-n-p "Do you want to submit a report on CC Mode? ")
1121 t (message "") nil)
785eecbb
RS
1122 (reporter-submit-bug-report
1123 c-mode-help-address
d9e94c22 1124 (concat "CC Mode " c-version " (" mode-name ")")
51f606de 1125 (let ((vars (append
51f606de 1126 c-style-variables
d9e94c22 1127 '(c-buffer-is-cc-mode
51f606de 1128 c-tab-always-indent
d9e94c22
MS
1129 c-syntactic-indentation
1130 c-syntactic-indentation-in-macros
1131 c-ignore-auto-fill
1132 c-auto-align-backslashes
1133 c-backspace-function
1134 c-delete-function
1135 c-electric-pound-behavior
1136 c-default-style
1137 c-enable-xemacs-performance-kludge-p
1138 c-old-style-variable-behavior
51f606de
GM
1139 defun-prompt-regexp
1140 tab-width
1141 comment-column
1142 parse-sexp-ignore-comments
d9e94c22
MS
1143 parse-sexp-lookup-properties
1144 lookup-syntax-properties
51f606de
GM
1145 ;; A brain-damaged XEmacs only variable that, if
1146 ;; set to nil can cause all kinds of chaos.
1147 signal-error-on-buffer-boundary
1148 ;; Variables that affect line breaking and comments.
d9e94c22 1149 auto-fill-mode
91b807c9 1150 auto-fill-function
51f606de
GM
1151 filladapt-mode
1152 comment-multi-line
1153 comment-start-skip
1154 fill-prefix
d9e94c22 1155 fill-column
51f606de
GM
1156 paragraph-start
1157 adaptive-fill-mode
1158 adaptive-fill-regexp)
1159 nil)))
d9e94c22
MS
1160 (mapcar (lambda (var) (unless (boundp var)
1161 (setq vars (delq var vars))))
91b807c9
GM
1162 '(signal-error-on-buffer-boundary
1163 filladapt-mode
d9e94c22
MS
1164 defun-prompt-regexp
1165 font-lock-mode
1166 font-lock-maximum-decoration
1167 parse-sexp-lookup-properties
1168 lookup-syntax-properties))
51f606de 1169 vars)
9714ec23 1170 (lambda ()
a66cd3ee 1171 (run-hooks 'c-prepare-bug-report-hooks)
d9e94c22 1172 (insert (format "Buffer Style: %s\nc-emacs-features: %s\n"
a66cd3ee 1173 style c-features)))))))
785eecbb
RS
1174
1175\f
130c507e 1176(cc-provide 'cc-mode)
ab5796a9 1177
6d1f4dc4 1178;; arch-tag: 7825e5c4-fd09-439f-a04d-4c13208ba3d7
785eecbb 1179;;; cc-mode.el ends here