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