]> code.delx.au - gnu-emacs/blob - lisp/progmodes/cc-mode.el
(grep-mode-font-lock-keywords): Use the font-lock-face property to
[gnu-emacs] / lisp / progmodes / cc-mode.el
1 ;;; cc-mode.el --- major mode for editing C and similar languages
2
3 ;; Copyright (C) 1985,1987,1992-2003 Free Software Foundation, Inc.
4
5 ;; Authors: 2003- Alan Mackenzie
6 ;; 1998- Martin Stjernholm
7 ;; 1992-1999 Barry A. Warsaw
8 ;; 1987 Dave Detlefs and Stewart Clamen
9 ;; 1985 Richard M. Stallman
10 ;; Maintainer: bug-cc-mode@gnu.org
11 ;; Created: a long, long, time ago. adapted from the original c-mode.el
12 ;; Keywords: c languages oop
13
14 ;; This file is part of GNU Emacs.
15
16 ;; GNU Emacs is free software; you can redistribute it and/or modify
17 ;; it under the terms of the GNU General Public License as published by
18 ;; the Free Software Foundation; either version 2, or (at your option)
19 ;; any later version.
20
21 ;; GNU Emacs is distributed in the hope that it will be useful,
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;; GNU General Public License for more details.
25
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs; see the file COPYING. If not, write to
28 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
29 ;; Boston, MA 02111-1307, USA.
30
31 ;;; Commentary:
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!
35 ;; Note: The version string is in cc-defs.
36
37 ;; This package provides GNU Emacs major modes for editing C, C++,
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.
42
43 ;; CC Mode supports K&R and ANSI C, ANSI C++, Objective-C, Java,
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.
49
50 ;; CC Mode's immediate ancestors were, c++-mode.el, cplus-md.el, and
51 ;; cplus-md1.el..
52
53 ;; To submit bug reports, type "C-c C-b". These will be sent to
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
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!
60
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 ;;
68 ;; http://cc-mode.sourceforge.net/
69 ;;
70 ;; You can join a moderated CC Mode announcement-only mailing list by
71 ;; visiting
72 ;;
73 ;; http://lists.sourceforge.net/mailman/listinfo/cc-mode-announce
74
75 ;;; Code:
76
77 (eval-when-compile
78 (let ((load-path
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)
82 load-path)))
83 (load "cc-bytecomp" nil t)))
84
85 (cc-require 'cc-defs)
86 (cc-require-when-compile 'cc-langs)
87 (cc-require 'cc-vars)
88 (cc-require 'cc-engine)
89 (cc-require 'cc-styles)
90 (cc-require 'cc-cmds)
91 (cc-require 'cc-align)
92 (cc-require 'cc-menus)
93
94 ;; SILENCE the compiler.
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
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
104 ;; Menu support for both XEmacs and Emacs. If you don't have easymenu
105 ;; with your version of Emacs, you are incompatible!
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)
117
118 \f
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)
124 ;;
125 ;; And in the major mode function:
126 ;;
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 ;; 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 ;;
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>.
144
145 (defun c-leave-cc-mode-mode ()
146 (setq c-buffer-is-cc-mode nil))
147
148 (defun c-init-language-vars-for (mode)
149 "Initialize the language variables for one of the language modes
150 directly 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
152 those, rather than a derived language defined through the language
153 variable 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
164 ;;;###autoload
165 (defun c-initialize-cc-mode (&optional new-style-init)
166 "Initialize CC Mode for use in the current buffer.
167 If the optional NEW-STYLE-INIT is nil or left out then all necessary
168 initialization to run CC Mode for the C language is done. Otherwise
169 only 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
171 control). See \"cc-mode.el\" for more info."
172 ;;
173 ;; This function does not do any hidden buffer changes.
174
175 (setq c-buffer-is-cc-mode t)
176
177 (let ((initprop 'cc-mode-is-initialized)
178 c-initialization-ok)
179 (unless (get 'c-initialize-cc-mode initprop)
180 (unwind-protect
181 (progn
182 (put 'c-initialize-cc-mode initprop t)
183 (c-initialize-builtin-style)
184 (run-hooks 'c-initialization-hook)
185 ;; Fix obsolete variables.
186 (if (boundp 'c-comment-continuation-stars)
187 (setq c-block-comment-prefix c-comment-continuation-stars))
188 (add-hook 'change-major-mode-hook 'c-leave-cc-mode-mode)
189 (setq c-initialization-ok t))
190 ;; Will try initialization hooks again if they failed.
191 (put 'c-initialize-cc-mode initprop c-initialization-ok))))
192
193 (unless new-style-init
194 (c-init-language-vars-for 'c-mode)))
195
196 \f
197 ;;; Common routines.
198
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
205 ;; XEmacs
206 ((fboundp 'set-keymap-parents)
207 (set-keymap-parents map c-mode-base-map))
208 ;; Emacs
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
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).
219 (let ((table (or (symbol-value name)
220 (progn (define-abbrev-table name nil)
221 (symbol-value name)))))
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)))))
228 (put 'c-define-abbrev-table 'lisp-indent-function 1)
229
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)
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))
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)
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.
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)
287
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))
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)
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
318 ;; We don't require the outline package, but we configure it a bit anyway.
319 (cc-bytecomp-defvar outline-level)
320
321 (defun c-mode-menu (modestr)
322 "Return a menu spec suitable for `easy-menu-define' that is exactly
323 like the C mode menu except that the menu bar item name is MODESTR
324 instead of \"C\".
325
326 This function is provided for compatibility only; derived modes should
327 preferably 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
368 and the line breaking/filling code. Intended to be used by other
369 packages that embed CC Mode.
370
371 MODE is the CC Mode flavor to set up, e.g. 'c-mode or 'java-mode.
372 DEFAULT-STYLE tells which indentation style to install. It has the
373 same format as `c-default-style'.
374
375 Note that `c-init-language-vars' must be called before this function.
376 This function cannot do that since `c-init-language-vars' is a macro
377 that requires a literal mode spec at compile time."
378 ;;
379 ;; This function does not do any hidden buffer changes.
380
381 (setq c-buffer-is-cc-mode mode)
382
383 ;; these variables should always be buffer local; they do not affect
384 ;; indentation style.
385 (make-local-variable 'parse-sexp-ignore-comments)
386 (make-local-variable 'indent-line-function)
387 (make-local-variable 'indent-region-function)
388 (make-local-variable 'normal-auto-fill-function)
389 (make-local-variable 'comment-start)
390 (make-local-variable 'comment-end)
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)
398
399 ;; now set their values
400 (setq parse-sexp-ignore-comments t
401 indent-line-function 'c-indent-line
402 indent-region-function 'c-indent-region
403 normal-auto-fill-function 'c-do-auto-fill
404 comment-multi-line t)
405
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
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))
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)))))))
476 (c-setup-paragraph-variables)
477
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))
481
482 ;; setup the comment indent variable in a Emacs version portable way
483 (make-local-variable 'comment-indent-function)
484 (setq comment-indent-function 'c-comment-indent)
485
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)))
491
492 ;; Install the functions that ensure that various internal caches
493 ;; don't become invalid due to buffer changes.
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.
503 This 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)))
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.
531 In addition to the work done by `c-basic-common-init' and
532 `c-font-lock-init', this function sets up various other things as
533 customary in CC Mode modes but which aren't strictly necessary for CC
534 Mode to operate correctly.
535
536 MODE 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
538 compatible with old code; callers should always specify it.
539
540 This 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.
545 (c-init-language-vars-for 'c-mode))
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)
560 (and (cdr rfn)
561 (setq require-final-newline mode-require-final-newline)))))
562
563 (defun c-postprocess-file-styles ()
564 "Function that post processes relevant file local variables in CC Mode.
565 Currently, this function simply applies any style and offset settings
566 found in the file's Local Variable list. It first applies any style
567 setting found in `c-file-style', then it applies any offset settings
568 it finds in `c-file-offsets'.
569
570 Note that the style variables are always made local to the buffer."
571 ;;
572 ;; This function does not do any hidden buffer changes.
573
574 ;; apply file styles and offsets
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))))
587
588 (add-hook 'hack-local-variables-hook 'c-postprocess-file-styles)
589
590 \f
591 ;; Support for C
592
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
600 (defvar c-mode-abbrev-table nil
601 "Abbreviation table used in c-mode buffers.")
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)))
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"
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.
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
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
642 (defvar cc-define-alist nil "Alist of #define directives for GUD tooltips.")
643
644 (defun cc-create-define-alist ()
645 (let* ((file (buffer-file-name))
646 (output
647 (with-output-to-string
648 (with-current-buffer standard-output
649 (call-process "/lib/cpp"
650 file t nil "-dM"))))
651 (define-list (split-string output "\n" t))
652 (name))
653 (dolist (define define-list)
654 (setq name (nth 1 (split-string define "[( ]")))
655 (push (cons name define) cc-define-alist))))
656
657 ;;;###autoload
658 (defun c-mode ()
659 "Major mode for editing K&R and ANSI C code.
660 To submit a problem report, enter `\\[c-submit-bug-report]' from a
661 c-mode buffer. This automatically sets up a mail buffer with version
662 information already added. You just need to add a description of the
663 problem, including a reproducible test case, and send the message.
664
665 To see what version of CC Mode you are running, enter `\\[c-version]'.
666
667 The hook `c-mode-common-hook' is run with no args at mode
668 initialization, then `c-mode-hook'.
669
670 Key bindings:
671 \\{c-mode-map}"
672 (interactive)
673 (kill-all-local-variables)
674 (c-initialize-cc-mode t)
675 (set-syntax-table c-mode-syntax-table)
676 (setq major-mode 'c-mode
677 mode-name "C"
678 local-abbrev-table c-mode-abbrev-table
679 abbrev-mode t)
680 (make-local-variable 'cc-define-alist)
681 (use-local-map c-mode-map)
682 (c-init-language-vars-for 'c-mode)
683 (c-common-init 'c-mode)
684 (easy-menu-add c-c-menu)
685 (cc-imenu-init cc-imenu-c-generic-expression)
686 (cc-create-define-alist)
687 (run-mode-hooks 'c-mode-common-hook 'c-mode-hook)
688 (c-update-modeline))
689
690 \f
691 ;; Support for C++
692
693 ;;;###autoload
694 (defvar c++-mode-syntax-table nil
695 "Syntax table used in c++-mode buffers.")
696 (or c++-mode-syntax-table
697 (setq c++-mode-syntax-table
698 (funcall (c-lang-const c-make-mode-syntax-table c++))))
699
700 (defvar c++-mode-abbrev-table nil
701 "Abbreviation table used in c++-mode buffers.")
702 (c-define-abbrev-table 'c++-mode-abbrev-table
703 '(("else" "else" c-electric-continued-statement 0)
704 ("while" "while" c-electric-continued-statement 0)
705 ("catch" "catch" c-electric-continued-statement 0)))
706
707 (defvar c++-mode-map ()
708 "Keymap used in c++-mode buffers.")
709 (if c++-mode-map
710 nil
711 (setq c++-mode-map (c-make-inherited-keymap))
712 ;; add bindings which are only useful for C++
713 (define-key c++-mode-map "\C-c\C-e" 'c-macro-expand)
714 (define-key c++-mode-map "\C-c:" 'c-scope-operator)
715 (define-key c++-mode-map "<" 'c-electric-lt-gt)
716 (define-key c++-mode-map ">" 'c-electric-lt-gt))
717
718 (easy-menu-define c-c++-menu c++-mode-map "C++ Mode Commands"
719 (cons "C++" (c-lang-const c-mode-menu c++)))
720
721 ;;;###autoload
722 (defun c++-mode ()
723 "Major mode for editing C++ code.
724 To submit a problem report, enter `\\[c-submit-bug-report]' from a
725 c++-mode buffer. This automatically sets up a mail buffer with
726 version information already added. You just need to add a description
727 of the problem, including a reproducible test case, and send the
728 message.
729
730 To see what version of CC Mode you are running, enter `\\[c-version]'.
731
732 The hook `c-mode-common-hook' is run with no args at mode
733 initialization, then `c++-mode-hook'.
734
735 Key bindings:
736 \\{c++-mode-map}"
737 (interactive)
738 (kill-all-local-variables)
739 (c-initialize-cc-mode t)
740 (set-syntax-table c++-mode-syntax-table)
741 (setq major-mode 'c++-mode
742 mode-name "C++"
743 local-abbrev-table c++-mode-abbrev-table
744 abbrev-mode t)
745 (use-local-map c++-mode-map)
746 (c-init-language-vars-for 'c++-mode)
747 (c-common-init 'c++-mode)
748 (easy-menu-add c-c++-menu)
749 (cc-imenu-init cc-imenu-c++-generic-expression)
750 (run-mode-hooks 'c-mode-common-hook 'c++-mode-hook)
751 (c-update-modeline))
752
753 \f
754 ;; Support for Objective-C
755
756 ;;;###autoload
757 (defvar objc-mode-syntax-table nil
758 "Syntax table used in objc-mode buffers.")
759 (or objc-mode-syntax-table
760 (setq objc-mode-syntax-table
761 (funcall (c-lang-const c-make-mode-syntax-table objc))))
762
763 (defvar objc-mode-abbrev-table nil
764 "Abbreviation table used in objc-mode buffers.")
765 (c-define-abbrev-table 'objc-mode-abbrev-table
766 '(("else" "else" c-electric-continued-statement 0)
767 ("while" "while" c-electric-continued-statement 0)))
768
769 (defvar objc-mode-map ()
770 "Keymap used in objc-mode buffers.")
771 (if objc-mode-map
772 nil
773 (setq objc-mode-map (c-make-inherited-keymap))
774 ;; add bindings which are only useful for Objective-C
775 (define-key objc-mode-map "\C-c\C-e" 'c-macro-expand))
776
777 (easy-menu-define c-objc-menu objc-mode-map "ObjC Mode Commands"
778 (cons "ObjC" (c-lang-const c-mode-menu objc)))
779
780 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.m\\'" . objc-mode))
781
782 ;;;###autoload
783 (defun objc-mode ()
784 "Major mode for editing Objective C code.
785 To submit a problem report, enter `\\[c-submit-bug-report]' from an
786 objc-mode buffer. This automatically sets up a mail buffer with
787 version information already added. You just need to add a description
788 of the problem, including a reproducible test case, and send the
789 message.
790
791 To see what version of CC Mode you are running, enter `\\[c-version]'.
792
793 The hook `c-mode-common-hook' is run with no args at mode
794 initialization, then `objc-mode-hook'.
795
796 Key bindings:
797 \\{objc-mode-map}"
798 (interactive)
799 (kill-all-local-variables)
800 (c-initialize-cc-mode t)
801 (set-syntax-table objc-mode-syntax-table)
802 (setq major-mode 'objc-mode
803 mode-name "ObjC"
804 local-abbrev-table objc-mode-abbrev-table
805 abbrev-mode t)
806 ;; The `c-type' text property with `c-decl-end' is used to mark the
807 ;; end of the @-style directives.
808 (setq c-type-decl-end-used t)
809 (use-local-map objc-mode-map)
810 (c-init-language-vars-for 'objc-mode)
811 (c-common-init 'objc-mode)
812 (easy-menu-add c-objc-menu)
813 (cc-imenu-init nil 'cc-imenu-objc-function)
814 (run-mode-hooks 'c-mode-common-hook 'objc-mode-hook)
815 (c-update-modeline))
816
817 \f
818 ;; Support for Java
819
820 ;;;###autoload
821 (defvar java-mode-syntax-table nil
822 "Syntax table used in java-mode buffers.")
823 (or java-mode-syntax-table
824 (setq java-mode-syntax-table
825 (funcall (c-lang-const c-make-mode-syntax-table java))))
826
827 (defvar java-mode-abbrev-table nil
828 "Abbreviation table used in java-mode buffers.")
829 (c-define-abbrev-table 'java-mode-abbrev-table
830 '(("else" "else" c-electric-continued-statement 0)
831 ("while" "while" c-electric-continued-statement 0)
832 ("catch" "catch" c-electric-continued-statement 0)
833 ("finally" "finally" c-electric-continued-statement 0)))
834
835 (defvar java-mode-map ()
836 "Keymap used in java-mode buffers.")
837 (if java-mode-map
838 nil
839 (setq java-mode-map (c-make-inherited-keymap))
840 ;; add bindings which are only useful for Java
841 )
842
843 ;; Regexp trying to describe the beginning of a Java top-level
844 ;; definition. This is not used by CC Mode, nor is it maintained
845 ;; since it's practically impossible to write a regexp that reliably
846 ;; matches such a construct. Other tools are necessary.
847 (defconst c-Java-defun-prompt-regexp
848 "^[ \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-*")
849
850 (easy-menu-define c-java-menu java-mode-map "Java Mode Commands"
851 (cons "Java" (c-lang-const c-mode-menu java)))
852
853 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.java\\'" . java-mode))
854
855 ;;;###autoload
856 (defun java-mode ()
857 "Major mode for editing Java code.
858 To submit a problem report, enter `\\[c-submit-bug-report]' from a
859 java-mode buffer. This automatically sets up a mail buffer with
860 version information already added. You just need to add a description
861 of the problem, including a reproducible test case, and send the
862 message.
863
864 To see what version of CC Mode you are running, enter `\\[c-version]'.
865
866 The hook `c-mode-common-hook' is run with no args at mode
867 initialization, then `java-mode-hook'.
868
869 Key bindings:
870 \\{java-mode-map}"
871 (interactive)
872 (kill-all-local-variables)
873 (c-initialize-cc-mode t)
874 (set-syntax-table java-mode-syntax-table)
875 (setq major-mode 'java-mode
876 mode-name "Java"
877 local-abbrev-table java-mode-abbrev-table
878 abbrev-mode t)
879 (use-local-map java-mode-map)
880 (c-init-language-vars-for 'java-mode)
881 (c-common-init 'java-mode)
882 (easy-menu-add c-java-menu)
883 (cc-imenu-init cc-imenu-java-generic-expression)
884 (run-mode-hooks 'c-mode-common-hook 'java-mode-hook)
885 (c-update-modeline))
886
887 \f
888 ;; Support for CORBA's IDL language
889
890 ;;;###autoload
891 (defvar idl-mode-syntax-table nil
892 "Syntax table used in idl-mode buffers.")
893 (or idl-mode-syntax-table
894 (setq idl-mode-syntax-table
895 (funcall (c-lang-const c-make-mode-syntax-table idl))))
896
897 (defvar idl-mode-abbrev-table nil
898 "Abbreviation table used in idl-mode buffers.")
899 (c-define-abbrev-table 'idl-mode-abbrev-table nil)
900
901 (defvar idl-mode-map ()
902 "Keymap used in idl-mode buffers.")
903 (if idl-mode-map
904 nil
905 (setq idl-mode-map (c-make-inherited-keymap))
906 ;; add bindings which are only useful for IDL
907 )
908
909 (easy-menu-define c-idl-menu idl-mode-map "IDL Mode Commands"
910 (cons "IDL" (c-lang-const c-mode-menu idl)))
911
912 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.idl\\'" . idl-mode))
913
914 ;;;###autoload
915 (defun idl-mode ()
916 "Major mode for editing CORBA's IDL, PSDL and CIDL code.
917 To submit a problem report, enter `\\[c-submit-bug-report]' from an
918 idl-mode buffer. This automatically sets up a mail buffer with
919 version information already added. You just need to add a description
920 of the problem, including a reproducible test case, and send the
921 message.
922
923 To see what version of CC Mode you are running, enter `\\[c-version]'.
924
925 The hook `c-mode-common-hook' is run with no args at mode
926 initialization, then `idl-mode-hook'.
927
928 Key bindings:
929 \\{idl-mode-map}"
930 (interactive)
931 (kill-all-local-variables)
932 (c-initialize-cc-mode t)
933 (set-syntax-table idl-mode-syntax-table)
934 (setq major-mode 'idl-mode
935 mode-name "IDL"
936 local-abbrev-table idl-mode-abbrev-table)
937 (use-local-map idl-mode-map)
938 (c-init-language-vars-for 'idl-mode)
939 (c-common-init 'idl-mode)
940 (easy-menu-add c-idl-menu)
941 ;;(cc-imenu-init cc-imenu-idl-generic-expression) ;TODO
942 (run-mode-hooks 'c-mode-common-hook 'idl-mode-hook)
943 (c-update-modeline))
944
945 \f
946 ;; Support for Pike
947
948 ;;;###autoload
949 (defvar pike-mode-syntax-table nil
950 "Syntax table used in pike-mode buffers.")
951 (or pike-mode-syntax-table
952 (setq pike-mode-syntax-table
953 (funcall (c-lang-const c-make-mode-syntax-table pike))))
954
955 (defvar pike-mode-abbrev-table nil
956 "Abbreviation table used in pike-mode buffers.")
957 (c-define-abbrev-table 'pike-mode-abbrev-table
958 '(("else" "else" c-electric-continued-statement 0)
959 ("while" "while" c-electric-continued-statement 0)))
960
961 (defvar pike-mode-map ()
962 "Keymap used in pike-mode buffers.")
963 (if pike-mode-map
964 nil
965 (setq pike-mode-map (c-make-inherited-keymap))
966 ;; additional bindings
967 (define-key pike-mode-map "\C-c\C-e" 'c-macro-expand))
968
969 (easy-menu-define c-pike-menu pike-mode-map "Pike Mode Commands"
970 (cons "Pike" (c-lang-const c-mode-menu pike)))
971
972 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.\\(u?lpc\\|pike\\|pmod\\(.in\\)?\\)\\'" . pike-mode))
973 ;;;###autoload (add-to-list 'interpreter-mode-alist '("pike" . pike-mode))
974
975 ;;;###autoload
976 (defun pike-mode ()
977 "Major mode for editing Pike code.
978 To submit a problem report, enter `\\[c-submit-bug-report]' from a
979 pike-mode buffer. This automatically sets up a mail buffer with
980 version information already added. You just need to add a description
981 of the problem, including a reproducible test case, and send the
982 message.
983
984 To see what version of CC Mode you are running, enter `\\[c-version]'.
985
986 The hook `c-mode-common-hook' is run with no args at mode
987 initialization, then `pike-mode-hook'.
988
989 Key bindings:
990 \\{pike-mode-map}"
991 (interactive)
992 (kill-all-local-variables)
993 (c-initialize-cc-mode t)
994 (set-syntax-table pike-mode-syntax-table)
995 (setq major-mode 'pike-mode
996 mode-name "Pike"
997 local-abbrev-table pike-mode-abbrev-table
998 abbrev-mode t)
999 (use-local-map pike-mode-map)
1000 (c-init-language-vars-for 'pike-mode)
1001 (c-common-init 'pike-mode)
1002 (easy-menu-add c-pike-menu)
1003 ;;(cc-imenu-init cc-imenu-pike-generic-expression) ;TODO
1004 (run-mode-hooks 'c-mode-common-hook 'pike-mode-hook)
1005 (c-update-modeline))
1006
1007 \f
1008 ;; Support for awk. This is purposely disabled for older (X)Emacsen which
1009 ;; don't support syntax-table properties.
1010
1011 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.awk\\'" . awk-mode))
1012 ;;;###autoload (add-to-list 'interpreter-mode-alist '("awk" . awk-mode))
1013 ;;;###autoload (add-to-list 'interpreter-mode-alist '("mawk" . awk-mode))
1014 ;;;###autoload (add-to-list 'interpreter-mode-alist '("nawk" . awk-mode))
1015 ;;;###autoload (add-to-list 'interpreter-mode-alist '("gawk" . awk-mode))
1016
1017 ;;; Autoload directives must be on the top level, so we construct an
1018 ;;; autoload form instead.
1019 ;;;###autoload (autoload 'awk-mode "cc-mode" "Major mode for editing AWK code." t)
1020
1021 (if (not (memq 'syntax-properties c-emacs-features))
1022 (autoload 'awk-mode "awk-mode" "Major mode for editing AWK code." t)
1023
1024 (defvar awk-mode-abbrev-table nil
1025 "Abbreviation table used in awk-mode buffers.")
1026 (c-define-abbrev-table 'awk-mode-abbrev-table
1027 '(("else" "else" c-electric-continued-statement 0)
1028 ("while" "while" c-electric-continued-statement 0)))
1029
1030 (defvar awk-mode-map ()
1031 "Keymap used in awk-mode buffers.")
1032 (if awk-mode-map
1033 nil
1034 (setq awk-mode-map (c-make-inherited-keymap))
1035 ;; add bindings which are only useful for awk.
1036 (define-key awk-mode-map "#" 'self-insert-command)
1037 (define-key awk-mode-map "/" 'self-insert-command)
1038 (define-key awk-mode-map "*" 'self-insert-command)
1039 (define-key awk-mode-map "\C-c\C-n" 'undefined) ; #if doesn't exist in awk.
1040 (define-key awk-mode-map "\C-c\C-p" 'undefined)
1041 (define-key awk-mode-map "\C-c\C-u" 'undefined)
1042 (define-key awk-mode-map "\M-a" 'undefined) ; c-awk-beginning-of-statement isn't yet implemented.
1043 (define-key awk-mode-map "\M-e" 'undefined) ; c-awk-end-of-statement isn't yet implemented.
1044 (define-key awk-mode-map "\C-\M-a" 'c-awk-beginning-of-defun)
1045 (define-key awk-mode-map "\C-\M-e" 'c-awk-end-of-defun))
1046
1047 (easy-menu-define c-awk-menu awk-mode-map "AWK Mode Commands"
1048 (cons "AWK" (c-lang-const c-mode-menu awk)))
1049
1050 (defun awk-mode ()
1051 "Major mode for editing AWK code.
1052 To submit a problem report, enter `\\[c-submit-bug-report]' from an
1053 awk-mode buffer. This automatically sets up a mail buffer with version
1054 information already added. You just need to add a description of the
1055 problem, including a reproducible test case, and send the message.
1056
1057 To see what version of CC Mode you are running, enter `\\[c-version]'.
1058
1059 The hook `c-mode-common-hook' is run with no args at mode
1060 initialization, then `awk-mode-hook'.
1061
1062 Key bindings:
1063 \\{awk-mode-map}"
1064 (interactive)
1065 (require 'cc-awk) ; Added 2003/6/10.
1066 (kill-all-local-variables)
1067 (c-initialize-cc-mode t)
1068 (set-syntax-table awk-mode-syntax-table)
1069 (setq major-mode 'awk-mode
1070 mode-name "AWK"
1071 local-abbrev-table awk-mode-abbrev-table
1072 abbrev-mode t)
1073 (use-local-map awk-mode-map)
1074 (c-init-language-vars-for 'awk-mode)
1075 (c-common-init 'awk-mode)
1076 ;; The rest of CC Mode does not (yet) use `font-lock-syntactic-keywords',
1077 ;; so it's not set by `c-font-lock-init'.
1078 (make-local-variable 'font-lock-syntactic-keywords)
1079 (setq font-lock-syntactic-keywords
1080 '((c-awk-set-syntax-table-properties
1081 0 (0) ; Everything on this line is a dummy.
1082 nil t)))
1083 (c-awk-unstick-NL-prop)
1084 (add-hook 'before-change-functions 'c-awk-before-change nil t)
1085 (add-hook 'after-change-functions 'c-awk-after-change nil t)
1086 (c-save-buffer-state nil
1087 (save-restriction
1088 (widen)
1089 (c-awk-clear-NL-props (point-min) (point-max))
1090 (c-awk-after-change (point-min) (point-max) 0))) ; Set syntax-table props.
1091
1092 ;; Prevent Xemacs's buffer-syntactic-context being used. See the comment
1093 ;; in cc-engine.el, just before (defun c-fast-in-literal ...
1094 (defalias 'c-in-literal 'c-slow-in-literal)
1095
1096 (run-mode-hooks 'c-mode-common-hook 'awk-mode-hook)
1097 (c-update-modeline))
1098 ) ;; closes the (if (not (memq 'syntax-properties c-emacs-features))
1099
1100 \f
1101 ;; bug reporting
1102
1103 (defconst c-mode-help-address
1104 "bug-cc-mode@gnu.org"
1105 "Address(es) for CC Mode bug reports.")
1106
1107 (defun c-version ()
1108 "Echo the current version of CC Mode in the minibuffer."
1109 (interactive)
1110 (message "Using CC Mode version %s" c-version)
1111 (c-keep-region-active))
1112
1113 (defvar c-prepare-bug-report-hooks nil)
1114
1115 ;; Dynamic variables used by reporter.
1116 (defvar reporter-prompt-for-summary-p)
1117 (defvar reporter-dont-compact-list)
1118
1119 (defun c-submit-bug-report ()
1120 "Submit via mail a bug report on CC Mode."
1121 (interactive)
1122 (require 'reporter)
1123 ;; load in reporter
1124 (let ((reporter-prompt-for-summary-p t)
1125 (reporter-dont-compact-list '(c-offsets-alist))
1126 (style c-indentation-style)
1127 (c-features c-emacs-features))
1128 (and
1129 (if (y-or-n-p "Do you want to submit a report on CC Mode? ")
1130 t (message "") nil)
1131 (reporter-submit-bug-report
1132 c-mode-help-address
1133 (concat "CC Mode " c-version " (" mode-name ")")
1134 (let ((vars (append
1135 c-style-variables
1136 '(c-buffer-is-cc-mode
1137 c-tab-always-indent
1138 c-syntactic-indentation
1139 c-syntactic-indentation-in-macros
1140 c-ignore-auto-fill
1141 c-auto-align-backslashes
1142 c-backspace-function
1143 c-delete-function
1144 c-electric-pound-behavior
1145 c-default-style
1146 c-enable-xemacs-performance-kludge-p
1147 c-old-style-variable-behavior
1148 defun-prompt-regexp
1149 tab-width
1150 comment-column
1151 parse-sexp-ignore-comments
1152 parse-sexp-lookup-properties
1153 lookup-syntax-properties
1154 ;; A brain-damaged XEmacs only variable that, if
1155 ;; set to nil can cause all kinds of chaos.
1156 signal-error-on-buffer-boundary
1157 ;; Variables that affect line breaking and comments.
1158 auto-fill-mode
1159 auto-fill-function
1160 filladapt-mode
1161 comment-multi-line
1162 comment-start-skip
1163 fill-prefix
1164 fill-column
1165 paragraph-start
1166 adaptive-fill-mode
1167 adaptive-fill-regexp)
1168 nil)))
1169 (mapcar (lambda (var) (unless (boundp var)
1170 (setq vars (delq var vars))))
1171 '(signal-error-on-buffer-boundary
1172 filladapt-mode
1173 defun-prompt-regexp
1174 font-lock-mode
1175 font-lock-maximum-decoration
1176 parse-sexp-lookup-properties
1177 lookup-syntax-properties))
1178 vars)
1179 (lambda ()
1180 (run-hooks 'c-prepare-bug-report-hooks)
1181 (insert (format "Buffer Style: %s\nc-emacs-features: %s\n"
1182 style c-features)))))))
1183
1184 \f
1185 (cc-provide 'cc-mode)
1186
1187 ;;; arch-tag: 7825e5c4-fd09-439f-a04d-4c13208ba3d7
1188 ;;; cc-mode.el ends here