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