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