Convert consecutive FSF copyright years to ranges.
[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-2011 Free Software Foundation, Inc.
4
5 ;; Authors: 2003- Alan Mackenzie
6 ;; 1998- Martin Stjernholm
7 ;; 1992-1999 Barry A. Warsaw
8 ;; 1987 Dave Detlefs
9 ;; 1987 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
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 3 of the License, or
20 ;; (at your option) 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
29
30 ;;; Commentary:
31
32 ;; NOTE: Read the commentary below for the right way to submit bug reports!
33 ;; NOTE: See the accompanying texinfo manual for details on using this mode!
34 ;; Note: The version string is in cc-defs.
35
36 ;; This package provides GNU Emacs major modes for editing C, C++,
37 ;; Objective-C, Java, CORBA's IDL, Pike and AWK code. As of the
38 ;; latest Emacs and XEmacs releases, it is the default package for
39 ;; editing these languages. This package is called "CC Mode", and
40 ;; should be spelled exactly this way.
41
42 ;; CC Mode supports K&R and ANSI C, ANSI C++, Objective-C, Java,
43 ;; CORBA's IDL, Pike and AWK with a consistent indentation model
44 ;; across all modes. This indentation model is intuitive and very
45 ;; flexible, so that almost any desired style of indentation can be
46 ;; supported. Installation, usage, and programming details are
47 ;; contained in an accompanying texinfo manual.
48
49 ;; CC Mode's immediate ancestors were, c++-mode.el, cplus-md.el, and
50 ;; cplus-md1.el..
51
52 ;; To submit bug reports, type "C-c C-b". These will be sent to
53 ;; bug-gnu-emacs@gnu.org (mirrored as the Usenet newsgroup
54 ;; gnu.emacs.bug) as well as bug-cc-mode@gnu.org, which directly
55 ;; contacts the CC Mode maintainers. Questions can sent to
56 ;; help-gnu-emacs@gnu.org (mirrored as gnu.emacs.help) and/or
57 ;; bug-cc-mode@gnu.org. Please do not send bugs or questions to our
58 ;; personal accounts; we reserve the right to ignore such email!
59
60 ;; Many, many thanks go out to all the folks on the beta test list.
61 ;; Without their patience, testing, insight, code contributions, and
62 ;; encouragement CC Mode would be a far inferior package.
63
64 ;; You can get the latest version of CC Mode, including PostScript
65 ;; documentation and separate individual files from:
66 ;;
67 ;; http://cc-mode.sourceforge.net/
68 ;;
69 ;; You can join a moderated CC Mode announcement-only mailing list by
70 ;; visiting
71 ;;
72 ;; http://lists.sourceforge.net/mailman/listinfo/cc-mode-announce
73
74 ;;; Code:
75
76 ;; For Emacs < 22.2.
77 (eval-and-compile
78 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
79
80 (eval-when-compile
81 (let ((load-path
82 (if (and (boundp 'byte-compile-dest-file)
83 (stringp byte-compile-dest-file))
84 (cons (file-name-directory byte-compile-dest-file) load-path)
85 load-path)))
86 (load "cc-bytecomp" nil t)))
87
88 (cc-require 'cc-defs)
89 (cc-require-when-compile 'cc-langs)
90 (cc-require 'cc-vars)
91 (cc-require 'cc-engine)
92 (cc-require 'cc-styles)
93 (cc-require 'cc-cmds)
94 (cc-require 'cc-align)
95 (cc-require 'cc-menus)
96
97 ;; Silence the compiler.
98 (cc-bytecomp-defvar adaptive-fill-first-line-regexp) ; Emacs
99 (cc-bytecomp-defun set-keymap-parents) ; XEmacs
100 (cc-bytecomp-defun run-mode-hooks) ; Emacs 21.1
101
102 ;; We set these variables during mode init, yet we don't require
103 ;; font-lock.
104 (cc-bytecomp-defvar font-lock-defaults)
105 (cc-bytecomp-defvar font-lock-syntactic-keywords)
106
107 ;; Menu support for both XEmacs and Emacs. If you don't have easymenu
108 ;; with your version of Emacs, you are incompatible!
109 (cc-external-require 'easymenu)
110
111 ;; Autoload directive for emacsen that doesn't have an older CC Mode
112 ;; version in the dist.
113 (autoload 'subword-mode "subword"
114 "Mode enabling subword movement and editing keys." t)
115
116 ;; Load cc-fonts first after font-lock is loaded, since it isn't
117 ;; necessary until font locking is requested.
118 ; (eval-after-load "font-lock" ; 2006-07-09: font-lock is now preloaded.
119 ; '
120 (require 'cc-fonts) ;)
121
122 ;; cc-langs isn't loaded when we're byte compiled, so add autoload
123 ;; directives for the interface functions.
124 (autoload 'c-make-init-lang-vars-fun "cc-langs")
125 (autoload 'c-init-language-vars "cc-langs" nil nil 'macro)
126
127 \f
128 ;; Other modes and packages which depend on CC Mode should do the
129 ;; following to make sure everything is loaded and available for their
130 ;; use:
131 ;;
132 ;; (require 'cc-mode)
133 ;;
134 ;; And in the major mode function:
135 ;;
136 ;; (c-initialize-cc-mode t)
137 ;; (c-init-language-vars some-mode)
138 ;; (c-common-init 'some-mode) ; Or perhaps (c-basic-common-init 'some-mode)
139 ;;
140 ;; If you're not writing a derived mode using the language variable
141 ;; system, then some-mode is one of the language modes directly
142 ;; supported by CC Mode. You can then use (c-init-language-vars-for
143 ;; 'some-mode) instead of `c-init-language-vars'.
144 ;; `c-init-language-vars-for' is a function that avoids the rather
145 ;; large expansion of `c-init-language-vars'.
146 ;;
147 ;; If you use `c-basic-common-init' then you might want to call
148 ;; `c-font-lock-init' too to set up CC Mode's font lock support.
149 ;;
150 ;; See cc-langs.el for further info. A small example of a derived mode
151 ;; is also available at <http://cc-mode.sourceforge.net/
152 ;; derived-mode-ex.el>.
153
154 (defun c-leave-cc-mode-mode ()
155 (setq c-buffer-is-cc-mode nil))
156
157 (defun c-init-language-vars-for (mode)
158 "Initialize the language variables for one of the language modes
159 directly supported by CC Mode. This can be used instead of the
160 `c-init-language-vars' macro if the language you want to use is one of
161 those, rather than a derived language defined through the language
162 variable system (see \"cc-langs.el\")."
163 (cond ((eq mode 'c-mode) (c-init-language-vars c-mode))
164 ((eq mode 'c++-mode) (c-init-language-vars c++-mode))
165 ((eq mode 'objc-mode) (c-init-language-vars objc-mode))
166 ((eq mode 'java-mode) (c-init-language-vars java-mode))
167 ((eq mode 'idl-mode) (c-init-language-vars idl-mode))
168 ((eq mode 'pike-mode) (c-init-language-vars pike-mode))
169 ((eq mode 'awk-mode) (c-init-language-vars awk-mode))
170 (t (error "Unsupported mode %s" mode))))
171
172 ;;;###autoload
173 (defun c-initialize-cc-mode (&optional new-style-init)
174 "Initialize CC Mode for use in the current buffer.
175 If the optional NEW-STYLE-INIT is nil or left out then all necessary
176 initialization to run CC Mode for the C language is done. Otherwise
177 only some basic setup is done, and a call to `c-init-language-vars' or
178 `c-init-language-vars-for' is necessary too (which gives more
179 control). See \"cc-mode.el\" for more info."
180
181 (setq c-buffer-is-cc-mode t)
182
183 (let ((initprop 'cc-mode-is-initialized)
184 c-initialization-ok)
185 (unless (get 'c-initialize-cc-mode initprop)
186 (unwind-protect
187 (progn
188 (put 'c-initialize-cc-mode initprop t)
189 (c-initialize-builtin-style)
190 (run-hooks 'c-initialization-hook)
191 ;; Fix obsolete variables.
192 (if (boundp 'c-comment-continuation-stars)
193 (setq c-block-comment-prefix
194 (symbol-value 'c-comment-continuation-stars)))
195 (add-hook 'change-major-mode-hook 'c-leave-cc-mode-mode)
196 (setq c-initialization-ok t))
197 ;; Will try initialization hooks again if they failed.
198 (put 'c-initialize-cc-mode initprop c-initialization-ok))))
199
200 (unless new-style-init
201 (c-init-language-vars-for 'c-mode)))
202
203 \f
204 ;;; Common routines.
205
206 (defvar c-mode-base-map ()
207 "Keymap shared by all CC Mode related modes.")
208
209 (defun c-make-inherited-keymap ()
210 (let ((map (make-sparse-keymap)))
211 ;; Necessary to use `cc-bytecomp-fboundp' below since this
212 ;; function is called from top-level forms that are evaluated
213 ;; while cc-bytecomp is active when one does M-x eval-buffer.
214 (cond
215 ;; Emacs
216 ((cc-bytecomp-fboundp 'set-keymap-parent)
217 (set-keymap-parent map c-mode-base-map))
218 ;; XEmacs
219 ((cc-bytecomp-fboundp 'set-keymap-parents)
220 (set-keymap-parents map c-mode-base-map))
221 ;; incompatible
222 (t (error "CC Mode is incompatible with this version of Emacs")))
223 map))
224
225 (defun c-define-abbrev-table (name defs)
226 ;; Compatibility wrapper for `define-abbrev' which passes a non-nil
227 ;; sixth argument for SYSTEM-FLAG in emacsen that support it
228 ;; (currently only Emacs >= 21.2).
229 (let ((table (or (symbol-value name)
230 (progn (define-abbrev-table name nil)
231 (symbol-value name)))))
232 (while defs
233 (condition-case nil
234 (apply 'define-abbrev table (append (car defs) '(t)))
235 (wrong-number-of-arguments
236 (apply 'define-abbrev table (car defs))))
237 (setq defs (cdr defs)))))
238 (put 'c-define-abbrev-table 'lisp-indent-function 1)
239
240 (defun c-bind-special-erase-keys ()
241 ;; Only used in Emacs to bind C-c C-<delete> and C-c C-<backspace>
242 ;; to the proper keys depending on `normal-erase-is-backspace'.
243 (if normal-erase-is-backspace
244 (progn
245 (define-key c-mode-base-map (kbd "C-c C-<delete>")
246 'c-hungry-delete-forward)
247 (define-key c-mode-base-map (kbd "C-c C-<backspace>")
248 'c-hungry-delete-backwards))
249 (define-key c-mode-base-map (kbd "C-c C-<delete>")
250 'c-hungry-delete-backwards)
251 (define-key c-mode-base-map (kbd "C-c C-<backspace>")
252 'c-hungry-delete-forward)))
253
254 (if c-mode-base-map
255 nil
256
257 (setq c-mode-base-map (make-sparse-keymap))
258
259 ;; Separate M-BS from C-M-h. The former should remain
260 ;; backward-kill-word.
261 (define-key c-mode-base-map [(control meta h)] 'c-mark-function)
262 (define-key c-mode-base-map "\e\C-q" 'c-indent-exp)
263 (substitute-key-definition 'backward-sentence
264 'c-beginning-of-statement
265 c-mode-base-map global-map)
266 (substitute-key-definition 'forward-sentence
267 'c-end-of-statement
268 c-mode-base-map global-map)
269 (substitute-key-definition 'indent-new-comment-line
270 'c-indent-new-comment-line
271 c-mode-base-map global-map)
272 (substitute-key-definition 'indent-for-tab-command
273 ;; XXX Is this the right thing to do
274 ;; here?
275 'c-indent-line-or-region
276 c-mode-base-map global-map)
277 (when (fboundp 'comment-indent-new-line)
278 ;; indent-new-comment-line has changed name to
279 ;; comment-indent-new-line in Emacs 21.
280 (substitute-key-definition 'comment-indent-new-line
281 'c-indent-new-comment-line
282 c-mode-base-map global-map))
283
284 ;; RMS says don't make these the default.
285 ;; (April 2006): RMS has now approved these commands as defaults.
286 (unless (memq 'argumentative-bod-function c-emacs-features)
287 (define-key c-mode-base-map "\e\C-a" 'c-beginning-of-defun)
288 (define-key c-mode-base-map "\e\C-e" 'c-end-of-defun))
289
290 (define-key c-mode-base-map "\C-c\C-n" 'c-forward-conditional)
291 (define-key c-mode-base-map "\C-c\C-p" 'c-backward-conditional)
292 (define-key c-mode-base-map "\C-c\C-u" 'c-up-conditional)
293
294 ;; It doesn't suffice to put `c-fill-paragraph' on
295 ;; `fill-paragraph-function' since `c-fill-paragraph' must be called
296 ;; before any fill prefix adaption is done. E.g. `filladapt-mode'
297 ;; replaces `fill-paragraph' and does the adaption before calling
298 ;; `fill-paragraph-function', and we have to mask comments etc
299 ;; before that. Also, `c-fill-paragraph' chains on to
300 ;; `fill-paragraph' and the value on `fill-parapgraph-function' to
301 ;; do the actual filling work.
302 (substitute-key-definition 'fill-paragraph 'c-fill-paragraph
303 c-mode-base-map global-map)
304 ;; In XEmacs the default fill function is called
305 ;; fill-paragraph-or-region.
306 (substitute-key-definition 'fill-paragraph-or-region 'c-fill-paragraph
307 c-mode-base-map global-map)
308
309 ;; We bind the forward deletion key and (implicitly) C-d to
310 ;; `c-electric-delete-forward', and the backward deletion key to
311 ;; `c-electric-backspace'. The hungry variants are bound to the
312 ;; same keys but prefixed with C-c. This implies that C-c C-d is
313 ;; `c-hungry-delete-forward'. For consistency, we bind not only C-c
314 ;; <backspace> to `c-hungry-delete-backwards' but also
315 ;; C-c C-<backspace>, so that the Ctrl key can be held down during
316 ;; the whole sequence regardless of the direction. This in turn
317 ;; implies that we bind C-c C-<delete> to `c-hungry-delete-forward',
318 ;; for the same reason.
319
320 ;; Bind the electric deletion functions to C-d and DEL. Emacs 21
321 ;; automatically maps the [delete] and [backspace] keys to these two
322 ;; depending on window system and user preferences. (In earlier
323 ;; versions it's possible to do the same by using `function-key-map'.)
324 (define-key c-mode-base-map "\C-d" 'c-electric-delete-forward)
325 (define-key c-mode-base-map "\177" 'c-electric-backspace)
326 (define-key c-mode-base-map "\C-c\C-d" 'c-hungry-delete-forward)
327 (define-key c-mode-base-map [?\C-c ?\d] 'c-hungry-delete-backwards)
328 (define-key c-mode-base-map [?\C-c ?\C-\d] 'c-hungry-delete-backwards)
329 (define-key c-mode-base-map [?\C-c deletechar] 'c-hungry-delete-forward) ; C-c <delete> on a tty.
330 (define-key c-mode-base-map [?\C-c (control deletechar)] ; C-c C-<delete> on a tty.
331 'c-hungry-delete-forward)
332 (when (boundp 'normal-erase-is-backspace)
333 ;; The automatic C-d and DEL mapping functionality doesn't extend
334 ;; to special combinations like C-c C-<delete>, so we have to hook
335 ;; into the `normal-erase-is-backspace' system to bind it directly
336 ;; as appropriate.
337 (add-hook 'normal-erase-is-backspace-hook 'c-bind-special-erase-keys)
338 (c-bind-special-erase-keys))
339
340 (when (fboundp 'delete-forward-p)
341 ;; In XEmacs we fix the forward and backward deletion behavior by
342 ;; binding the keysyms for the [delete] and [backspace] keys
343 ;; directly, and use `delete-forward-p' to decide what [delete]
344 ;; should do. That's done in the XEmacs specific
345 ;; `c-electric-delete' and `c-hungry-delete' functions.
346 (define-key c-mode-base-map [delete] 'c-electric-delete)
347 (define-key c-mode-base-map [backspace] 'c-electric-backspace)
348 (define-key c-mode-base-map (kbd "C-c <delete>") 'c-hungry-delete)
349 (define-key c-mode-base-map (kbd "C-c C-<delete>") 'c-hungry-delete)
350 (define-key c-mode-base-map (kbd "C-c <backspace>")
351 'c-hungry-delete-backwards)
352 (define-key c-mode-base-map (kbd "C-c C-<backspace>")
353 'c-hungry-delete-backwards))
354
355 (define-key c-mode-base-map "#" 'c-electric-pound)
356 (define-key c-mode-base-map "{" 'c-electric-brace)
357 (define-key c-mode-base-map "}" 'c-electric-brace)
358 (define-key c-mode-base-map "/" 'c-electric-slash)
359 (define-key c-mode-base-map "*" 'c-electric-star)
360 (define-key c-mode-base-map ";" 'c-electric-semi&comma)
361 (define-key c-mode-base-map "," 'c-electric-semi&comma)
362 (define-key c-mode-base-map ":" 'c-electric-colon)
363 (define-key c-mode-base-map "(" 'c-electric-paren)
364 (define-key c-mode-base-map ")" 'c-electric-paren)
365
366 (define-key c-mode-base-map "\C-c\C-\\" 'c-backslash-region)
367 (define-key c-mode-base-map "\C-c\C-a" 'c-toggle-auto-newline)
368 (define-key c-mode-base-map "\C-c\C-b" 'c-submit-bug-report)
369 (define-key c-mode-base-map "\C-c\C-c" 'comment-region)
370 (define-key c-mode-base-map "\C-c\C-l" 'c-toggle-electric-state)
371 (define-key c-mode-base-map "\C-c\C-o" 'c-set-offset)
372 (define-key c-mode-base-map "\C-c\C-q" 'c-indent-defun)
373 (define-key c-mode-base-map "\C-c\C-s" 'c-show-syntactic-information)
374 ;; (define-key c-mode-base-map "\C-c\C-t" 'c-toggle-auto-hungry-state) Commented out by ACM, 2005-03-05.
375 (define-key c-mode-base-map "\C-c." 'c-set-style)
376 ;; conflicts with OOBR
377 ;;(define-key c-mode-base-map "\C-c\C-v" 'c-version)
378 ;; (define-key c-mode-base-map "\C-c\C-y" 'c-toggle-hungry-state) Commented out by ACM, 2005-11-22.
379 (define-key c-mode-base-map "\C-c\C-w" 'subword-mode)
380 )
381
382 ;; We don't require the outline package, but we configure it a bit anyway.
383 (cc-bytecomp-defvar outline-level)
384
385 (defun c-mode-menu (modestr)
386 "Return a menu spec suitable for `easy-menu-define' that is exactly
387 like the C mode menu except that the menu bar item name is MODESTR
388 instead of \"C\".
389
390 This function is provided for compatibility only; derived modes should
391 preferably use the `c-mode-menu' language constant directly."
392 (cons modestr (c-lang-const c-mode-menu c)))
393
394 ;; Ugly hack to pull in the definition of `c-populate-syntax-table'
395 ;; from cc-langs to make it available at runtime. It's either this or
396 ;; moving the definition for it to cc-defs, but that would mean to
397 ;; break up the syntax table setup over two files.
398 (defalias 'c-populate-syntax-table
399 (cc-eval-when-compile
400 (let ((f (symbol-function 'c-populate-syntax-table)))
401 (if (byte-code-function-p f) f (byte-compile f)))))
402
403 ;; CAUTION: Try to avoid installing things on
404 ;; `before-change-functions'. The macro `combine-after-change-calls'
405 ;; is used and it doesn't work if there are things on that hook. That
406 ;; can cause font lock functions to run in inconvenient places during
407 ;; temporary changes in some font lock support modes, causing extra
408 ;; unnecessary work and font lock glitches due to interactions between
409 ;; various text properties.
410 ;;
411 ;; (2007-02-12): The macro `combine-after-change-calls' ISN'T used any
412 ;; more.
413
414 (defun c-unfind-enclosing-token (pos)
415 ;; If POS is wholly inside a token, remove that id from
416 ;; `c-found-types', should it be present. Return t if we were in an
417 ;; id, else nil.
418 (save-excursion
419 (let ((tok-beg (progn (goto-char pos)
420 (and (c-beginning-of-current-token) (point))))
421 (tok-end (progn (goto-char pos)
422 (and (c-end-of-current-token) (point)))))
423 (when (and tok-beg tok-end)
424 (c-unfind-type (buffer-substring-no-properties tok-beg tok-end))
425 t))))
426
427 (defun c-unfind-coalesced-tokens (beg end)
428 ;; unless the non-empty region (beg end) is entirely WS and there's at
429 ;; least one character of WS just before or after this region, remove
430 ;; the tokens which touch the region from `c-found-types' should they
431 ;; be present.
432 (or (c-partial-ws-p beg end)
433 (save-excursion
434 (progn
435 (goto-char beg)
436 (or (eq beg (point-min))
437 (c-skip-ws-backward (1- beg))
438 (/= (point) beg)
439 (= (c-backward-token-2) 1)
440 (c-unfind-type (buffer-substring-no-properties
441 (point) beg)))
442 (goto-char end)
443 (or (eq end (point-max))
444 (c-skip-ws-forward (1+ end))
445 (/= (point) end)
446 (progn (forward-char) (c-end-of-current-token) nil)
447 (c-unfind-type (buffer-substring-no-properties
448 end (point))))))))
449
450 ;; c-maybe-stale-found-type records a place near the region being
451 ;; changed where an element of `found-types' might become stale. It
452 ;; is set in c-before-change and is either nil, or has the form:
453 ;;
454 ;; (c-decl-id-start "foo" 97 107 " (* ooka) " "o"), where
455 ;;
456 ;; o - `c-decl-id-start' is the c-type text property value at buffer
457 ;; pos 96.
458 ;;
459 ;; o - 97 107 is the region potentially containing the stale type -
460 ;; this is delimited by a non-nil c-type text property at 96 and
461 ;; either another one or a ";", "{", or "}" at 107.
462 ;;
463 ;; o - " (* ooka) " is the (before change) buffer portion containing
464 ;; the suspect type (here "ooka").
465 ;;
466 ;; o - "o" is the buffer contents which is about to be deleted. This
467 ;; would be the empty string for an insertion.
468 (defvar c-maybe-stale-found-type nil)
469 (make-variable-buffer-local 'c-maybe-stale-found-type)
470
471 (defun c-basic-common-init (mode default-style)
472 "Do the necessary initialization for the syntax handling routines
473 and the line breaking/filling code. Intended to be used by other
474 packages that embed CC Mode.
475
476 MODE is the CC Mode flavor to set up, e.g. 'c-mode or 'java-mode.
477 DEFAULT-STYLE tells which indentation style to install. It has the
478 same format as `c-default-style'.
479
480 Note that `c-init-language-vars' must be called before this function.
481 This function cannot do that since `c-init-language-vars' is a macro
482 that requires a literal mode spec at compile time."
483
484 (setq c-buffer-is-cc-mode mode)
485
486 ;; these variables should always be buffer local; they do not affect
487 ;; indentation style.
488 (make-local-variable 'comment-start)
489 (make-local-variable 'comment-end)
490 (make-local-variable 'comment-start-skip)
491
492 (make-local-variable 'paragraph-start)
493 (make-local-variable 'paragraph-separate)
494 (make-local-variable 'paragraph-ignore-fill-prefix)
495 (make-local-variable 'adaptive-fill-mode)
496 (make-local-variable 'adaptive-fill-regexp)
497
498 ;; now set their values
499 (set (make-local-variable 'parse-sexp-ignore-comments) t)
500 (set (make-local-variable 'indent-line-function) 'c-indent-line)
501 (set (make-local-variable 'indent-region-function) 'c-indent-region)
502 (set (make-local-variable 'normal-auto-fill-function) 'c-do-auto-fill)
503 (set (make-local-variable 'comment-multi-line) t)
504 (set (make-local-variable 'comment-line-break-function)
505 'c-indent-new-comment-line)
506
507 ;; Install `c-fill-paragraph' on `fill-paragraph-function' so that a
508 ;; direct call to `fill-paragraph' behaves better. This still
509 ;; doesn't work with filladapt but it's better than nothing.
510 (set (make-local-variable 'fill-paragraph-function) 'c-fill-paragraph)
511
512 ;; Initialise the cache of brace pairs, and opening braces/brackets/parens.
513 (c-state-cache-init)
514
515 (when (or c-recognize-<>-arglists
516 (c-major-mode-is 'awk-mode)
517 (c-major-mode-is '(java-mode c-mode c++-mode objc-mode)))
518 ;; We'll use the syntax-table text property to change the syntax
519 ;; of some chars for this language, so do the necessary setup for
520 ;; that.
521 ;;
522 ;; Note to other package developers: It's ok to turn this on in CC
523 ;; Mode buffers when CC Mode doesn't, but it's not ok to turn it
524 ;; off if CC Mode has turned it on.
525
526 ;; Emacs.
527 (when (boundp 'parse-sexp-lookup-properties)
528 (set (make-local-variable 'parse-sexp-lookup-properties) t))
529
530 ;; Same as above for XEmacs.
531 (when (boundp 'lookup-syntax-properties)
532 (set (make-local-variable 'lookup-syntax-properties) t)))
533
534 ;; Use this in Emacs 21+ to avoid meddling with the rear-nonsticky
535 ;; property on each character.
536 (when (boundp 'text-property-default-nonsticky)
537 (mapc (lambda (tprop)
538 (unless (assq tprop text-property-default-nonsticky)
539 (set (make-local-variable 'text-property-default-nonsticky)
540 (cons `(,tprop . t) text-property-default-nonsticky))))
541 '(syntax-table category c-type)))
542
543 ;; In Emacs 21 and later it's possible to turn off the ad-hoc
544 ;; heuristic that open parens in column 0 are defun starters. Since
545 ;; we have c-state-cache, that heuristic isn't useful and only causes
546 ;; trouble, so turn it off.
547 ;; 2006/12/17: This facility is somewhat confused, and doesn't really seem
548 ;; helpful. Comment it out for now.
549 ;; (when (memq 'col-0-paren c-emacs-features)
550 ;; (make-local-variable 'open-paren-in-column-0-is-defun-start)
551 ;; (setq open-paren-in-column-0-is-defun-start nil))
552
553 (c-clear-found-types)
554
555 ;; now set the mode style based on default-style
556 (let ((style (if (stringp default-style)
557 default-style
558 (or (cdr (assq mode default-style))
559 (cdr (assq 'other default-style))
560 "gnu"))))
561 ;; Override style variables if `c-old-style-variable-behavior' is
562 ;; set. Also override if we are using global style variables,
563 ;; have already initialized a style once, and are switching to a
564 ;; different style. (It's doubtful whether this is desirable, but
565 ;; the whole situation with nonlocal style variables is a bit
566 ;; awkward. It's at least the most compatible way with the old
567 ;; style init procedure.)
568 (c-set-style style (not (or c-old-style-variable-behavior
569 (and (not c-style-variables-are-local-p)
570 c-indentation-style
571 (not (string-equal c-indentation-style
572 style)))))))
573 (c-setup-paragraph-variables)
574
575 ;; we have to do something special for c-offsets-alist so that the
576 ;; buffer local value has its own alist structure.
577 (setq c-offsets-alist (copy-alist c-offsets-alist))
578
579 ;; setup the comment indent variable in a Emacs version portable way
580 (set (make-local-variable 'comment-indent-function) 'c-comment-indent)
581
582 ;; ;; Put submode indicators onto minor-mode-alist, but only once.
583 ;; (or (assq 'c-submode-indicators minor-mode-alist)
584 ;; (setq minor-mode-alist
585 ;; (cons '(c-submode-indicators c-submode-indicators)
586 ;; minor-mode-alist)))
587 (c-update-modeline)
588
589 ;; Install the functions that ensure that various internal caches
590 ;; don't become invalid due to buffer changes.
591 (when (featurep 'xemacs)
592 (make-local-hook 'before-change-functions)
593 (make-local-hook 'after-change-functions))
594 (add-hook 'before-change-functions 'c-before-change nil t)
595 (add-hook 'after-change-functions 'c-after-change nil t)
596 (set (make-local-variable 'font-lock-extend-after-change-region-function)
597 'c-extend-after-change-region)) ; Currently (2009-05) used by all
598 ; lanaguages with #define (C, C++,; ObjC), and by AWK.
599
600 (defun c-setup-doc-comment-style ()
601 "Initialize the variables that depend on the value of `c-doc-comment-style'."
602 (when (and (featurep 'font-lock)
603 (symbol-value 'font-lock-mode))
604 ;; Force font lock mode to reinitialize itself.
605 (font-lock-mode 0)
606 (font-lock-mode 1)))
607
608 ;; Buffer local variables defining the region to be fontified by a font lock
609 ;; after-change function. They are set in c-after-change to
610 ;; after-change-function's BEG and END, and may be modified by a
611 ;; `c-before-font-lock-function'.
612 (defvar c-new-BEG 0)
613 (make-variable-buffer-local 'c-new-BEG)
614 (defvar c-new-END 0)
615 (make-variable-buffer-local 'c-new-END)
616
617 (defun c-common-init (&optional mode)
618 "Common initialization for all CC Mode modes.
619 In addition to the work done by `c-basic-common-init' and
620 `c-font-lock-init', this function sets up various other things as
621 customary in CC Mode modes but which aren't strictly necessary for CC
622 Mode to operate correctly.
623
624 MODE is the symbol for the mode to initialize, like 'c-mode. See
625 `c-basic-common-init' for details. It's only optional to be
626 compatible with old code; callers should always specify it."
627
628 (unless mode
629 ;; Called from an old third party package. The fallback is to
630 ;; initialize for C.
631 (c-init-language-vars-for 'c-mode))
632
633 (c-basic-common-init mode c-default-style)
634 (when mode
635 ;; Only initialize font locking if we aren't called from an old package.
636 (c-font-lock-init))
637
638 ;; Starting a mode is a sort of "change". So call the change functions...
639 (save-restriction
640 (widen)
641 (setq c-new-BEG (point-min))
642 (setq c-new-END (point-max))
643 (save-excursion
644 (if c-get-state-before-change-functions
645 (mapc (lambda (fn)
646 (funcall fn (point-min) (point-max)))
647 c-get-state-before-change-functions))
648 (if c-before-font-lock-function
649 (funcall c-before-font-lock-function (point-min) (point-max)
650 (- (point-max) (point-min))))))
651
652 (set (make-local-variable 'outline-regexp) "[^#\n\^M]")
653 (set (make-local-variable 'outline-level) 'c-outline-level)
654
655 (let ((rfn (assq mode c-require-final-newline)))
656 (when rfn
657 (and (cdr rfn)
658 (set (make-local-variable 'require-final-newline)
659 mode-require-final-newline)))))
660
661 (defun c-count-cfss (lv-alist)
662 ;; LV-ALIST is an alist like `file-local-variables-alist'. Count how many
663 ;; elements with the key `c-file-style' there are in it.
664 (let ((elt-ptr lv-alist) elt (cownt 0))
665 (while elt-ptr
666 (setq elt (car elt-ptr)
667 elt-ptr (cdr elt-ptr))
668 (when (eq (car elt) 'c-file-style)
669 (setq cownt (1+ cownt))))
670 cownt))
671
672 (defun c-before-hack-hook ()
673 "Set the CC Mode style and \"offsets\" when in the buffer's local variables.
674 They are set only when, respectively, the pseudo variables
675 `c-file-style' and `c-file-offsets' are present in the list.
676
677 This function is called from the hook `before-hack-local-variables-hook'."
678 (when c-buffer-is-cc-mode
679 (let ((mode-cons (assq 'mode file-local-variables-alist))
680 (stile (cdr (assq 'c-file-style file-local-variables-alist)))
681 (offsets (cdr (assq 'c-file-offsets file-local-variables-alist))))
682 (when mode-cons
683 (hack-one-local-variable (car mode-cons) (cdr mode-cons))
684 (setq file-local-variables-alist
685 (delq mode-cons file-local-variables-alist)))
686 (when stile
687 (or (stringp stile) (error "c-file-style is not a string"))
688 (if (boundp 'dir-local-variables-alist)
689 ;; Determine whether `c-file-style' was set in the file's local
690 ;; variables or in a .dir-locals.el (a directory setting).
691 (let ((cfs-in-file-and-dir-count
692 (c-count-cfss file-local-variables-alist))
693 (cfs-in-dir-count (c-count-cfss dir-local-variables-alist)))
694 (c-set-style stile
695 (= cfs-in-file-and-dir-count cfs-in-dir-count)))
696 (c-set-style stile)))
697 (when offsets
698 (mapc
699 (lambda (langentry)
700 (let ((langelem (car langentry))
701 (offset (cdr langentry)))
702 (c-set-offset langelem offset)))
703 offsets)))))
704
705 (defun c-remove-any-local-eval-or-mode-variables ()
706 ;; If the buffer specifies `mode' or `eval' in its File Local Variable list
707 ;; or on the first line, remove all occurrences. See
708 ;; `c-postprocess-file-styles' for justification. There is no need to save
709 ;; point here, or even bother too much about the buffer contents. However,
710 ;; DON'T mess up the kill-ring.
711 ;;
712 ;; Most of the code here is derived from Emacs 21.3's `hack-local-variables'
713 ;; in files.el.
714 (goto-char (point-max))
715 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move)
716 (let (lv-point (prefix "") (suffix ""))
717 (when (let ((case-fold-search t))
718 (search-forward "Local Variables:" nil t))
719 (setq lv-point (point))
720 ;; The prefix is what comes before "local variables:" in its line.
721 ;; The suffix is what comes after "local variables:" in its line.
722 (skip-chars-forward " \t")
723 (or (eolp)
724 (setq suffix (buffer-substring (point)
725 (progn (end-of-line) (point)))))
726 (goto-char (match-beginning 0))
727 (or (bolp)
728 (setq prefix
729 (buffer-substring (point)
730 (progn (beginning-of-line) (point)))))
731
732 (while (search-forward-regexp
733 (concat "^[ \t]*"
734 (regexp-quote prefix)
735 "\\(mode\\|eval\\):.*"
736 (regexp-quote suffix)
737 "$")
738 nil t)
739 (forward-line 0)
740 (delete-region (point) (progn (forward-line) (point)))))
741
742 ;; Delete the first line, if we've got one, in case it contains a mode spec.
743 (unless (and lv-point
744 (progn (goto-char lv-point)
745 (forward-line 0)
746 (bobp)))
747 (goto-char (point-min))
748 (unless (eobp)
749 (delete-region (point) (progn (forward-line) (point)))))))
750
751 (defun c-postprocess-file-styles ()
752 "Function that post processes relevant file local variables in CC Mode.
753 Currently, this function simply applies any style and offset settings
754 found in the file's Local Variable list. It first applies any style
755 setting found in `c-file-style', then it applies any offset settings
756 it finds in `c-file-offsets'.
757
758 Note that the style variables are always made local to the buffer."
759
760 ;; apply file styles and offsets
761 (when c-buffer-is-cc-mode
762 (if (or c-file-style c-file-offsets)
763 (c-make-styles-buffer-local t))
764 (when c-file-style
765 (or (stringp c-file-style)
766 (error "c-file-style is not a string"))
767 (c-set-style c-file-style))
768
769 (and c-file-offsets
770 (mapc
771 (lambda (langentry)
772 (let ((langelem (car langentry))
773 (offset (cdr langentry)))
774 (c-set-offset langelem offset)))
775 c-file-offsets))
776 ;; Problem: The file local variable block might have explicitly set a
777 ;; style variable. The `c-set-style' or `mapcar' call might have
778 ;; overwritten this. So we run `hack-local-variables' again to remedy
779 ;; this. There are no guarantees this will work properly, particularly as
780 ;; we have no control over what the other hook functions on
781 ;; `hack-local-variables-hook' would have done. We now (2006/2/1) remove
782 ;; any `eval' or `mode' expressions before we evaluate again (see below).
783 ;; ACM, 2005/11/2.
784 ;;
785 ;; Problem (bug reported by Gustav Broberg): if one of the variables is
786 ;; `mode', this will invoke c-mode (etc.) again, setting up the style etc.
787 ;; We prevent this by temporarily removing `mode' from the Local Variables
788 ;; section.
789 (if (or c-file-style c-file-offsets)
790 (let ((hack-local-variables-hook nil) (inhibit-read-only t))
791 (c-tentative-buffer-changes
792 (c-remove-any-local-eval-or-mode-variables)
793 (hack-local-variables))
794 nil))))
795
796 (if (boundp 'before-hack-local-variables-hook)
797 (add-hook 'before-hack-local-variables-hook 'c-before-hack-hook)
798 (add-hook 'hack-local-variables-hook 'c-postprocess-file-styles))
799
800 (defmacro c-run-mode-hooks (&rest hooks)
801 ;; Emacs 21.1 has introduced a system with delayed mode hooks that
802 ;; requires the use of the new function `run-mode-hooks'.
803 (if (cc-bytecomp-fboundp 'run-mode-hooks)
804 `(run-mode-hooks ,@hooks)
805 `(progn ,@(mapcar (lambda (hook) `(run-hooks ,hook)) hooks))))
806
807 \f
808 ;;; Change hooks, linking with Font Lock.
809
810 ;; Buffer local variables recording Beginning/End-of-Macro position before a
811 ;; change, when a macro straddles, respectively, the BEG or END (or both) of
812 ;; the change region. Otherwise these have the values BEG/END.
813 (defvar c-old-BOM 0)
814 (make-variable-buffer-local 'c-old-BOM)
815 (defvar c-old-EOM 0)
816 (make-variable-buffer-local 'c-old-EOM)
817
818 (defun c-extend-region-for-CPP (beg end)
819 ;; Set c-old-BOM or c-old-EOM respectively to BEG, END, each extended to the
820 ;; beginning/end of any preprocessor construct they may be in.
821 ;;
822 ;; Point is undefined both before and after this function call; the buffer
823 ;; has already been widened, and match-data saved. The return value is
824 ;; meaningless.
825 ;;
826 ;; This function is in the C/C++/ObjC values of
827 ;; `c-get-state-before-change-functions' and is called exclusively as a
828 ;; before change function.
829 (goto-char beg)
830 (c-beginning-of-macro)
831 (setq c-old-BOM (point))
832
833 (goto-char end)
834 (when (c-beginning-of-macro)
835 (c-end-of-macro)
836 (or (eobp) (forward-char))) ; Over the terminating NL which may be marked
837 ; with a c-cpp-delimiter category property
838 (setq c-old-EOM (point)))
839
840 (defun c-neutralize-CPP-line (beg end)
841 ;; BEG and END bound a region, typically a preprocessor line. Put a
842 ;; "punctuation" syntax-table property on syntactically obtrusive
843 ;; characters, ones which would interact syntactically with stuff outside
844 ;; this region.
845 ;;
846 ;; These are unmatched string delimiters, or unmatched
847 ;; parens/brackets/braces. An unclosed comment is regarded as valid, NOT
848 ;; obtrusive.
849 (save-excursion
850 (let (s)
851 (while
852 (progn
853 (setq s (parse-partial-sexp beg end -1))
854 (cond
855 ((< (nth 0 s) 0) ; found an unmated ),},]
856 (c-put-char-property (1- (point)) 'syntax-table '(1))
857 t)
858 ((nth 3 s) ; In a string
859 (c-put-char-property (nth 8 s) 'syntax-table '(1))
860 t)
861 ((> (nth 0 s) 0) ; In a (,{,[
862 (c-put-char-property (nth 1 s) 'syntax-table '(1))
863 t)
864 (t nil)))))))
865
866 (defun c-neutralize-syntax-in-and-mark-CPP (begg endd old-len)
867 ;; (i) Extend the font lock region to cover all changed preprocessor
868 ;; regions; it does this by setting the variables `c-new-BEG' and
869 ;; `c-new-END' to the new boundaries.
870 ;;
871 ;; (ii) "Neutralize" every preprocessor line wholly or partially in the
872 ;; extended changed region. "Restore" lines which were CPP lines before the
873 ;; change and are no longer so; these can be located from the Buffer local
874 ;; variables `c-old-BOM' and `c-old-EOM'.
875 ;;
876 ;; (iii) Mark every CPP construct by placing a `category' property value
877 ;; `c-cpp-delimiter' at its start and end. The marked characters are the
878 ;; opening # and usually the terminating EOL, but sometimes the character
879 ;; before a comment/string delimiter.
880 ;;
881 ;; That is, set syntax-table properties on characters that would otherwise
882 ;; interact syntactically with those outside the CPP line(s).
883 ;;
884 ;; This function is called from an after-change function, BEGG ENDD and
885 ;; OLD-LEN being the standard parameters. It prepares the buffer for font
886 ;; locking, hence must get called before `font-lock-after-change-function'.
887 ;;
888 ;; Point is undefined both before and after this function call, the buffer
889 ;; has been widened, and match-data saved. The return value is ignored.
890 ;;
891 ;; This function is the C/C++/ObjC value of `c-before-font-lock-function'.
892 ;;
893 ;; Note: SPEED _MATTERS_ IN THIS FUNCTION!!!
894 ;;
895 ;; This function might make hidden buffer changes.
896 (c-save-buffer-state (limits)
897 ;; First determine the region, (c-new-BEG c-new-END), which will get font
898 ;; locked. It might need "neutralizing". This region may not start
899 ;; inside a string, comment, or macro.
900 (goto-char c-old-BOM) ; already set to old start of macro or begg.
901 (setq c-new-BEG
902 (min c-new-BEG
903 (if (setq limits (c-state-literal-at (point)))
904 (cdr limits) ; go forward out of any string or comment.
905 (point))))
906
907 (goto-char endd)
908 (if (setq limits (c-state-literal-at (point)))
909 (goto-char (car limits))) ; go backward out of any string or comment.
910 (if (c-beginning-of-macro)
911 (c-end-of-macro))
912 (setq c-new-END (max c-new-END
913 (+ (- c-old-EOM old-len) (- endd begg))
914 (point)))
915
916 ;; Clear all old relevant properties.
917 (c-clear-char-property-with-value c-new-BEG c-new-END 'syntax-table '(1))
918 (c-clear-char-property-with-value c-new-BEG c-new-END 'category 'c-cpp-delimiter)
919 ;; FIXME!!! What about the "<" and ">" category properties? 2009-11-16
920
921 ;; Add needed properties to each CPP construct in the region.
922 (goto-char c-new-BEG)
923 (let ((pps-position c-new-BEG) pps-state mbeg)
924 (while (and (< (point) c-new-END)
925 (search-forward-regexp c-anchored-cpp-prefix c-new-END t))
926 ;; If we've found a "#" inside a string/comment, ignore it.
927 (setq pps-state
928 (parse-partial-sexp pps-position (point) nil nil pps-state)
929 pps-position (point))
930 (unless (or (nth 3 pps-state) ; in a string?
931 (nth 4 pps-state)) ; in a comment?
932 (goto-char (match-beginning 0))
933 (setq mbeg (point))
934 (if (> (c-syntactic-end-of-macro) mbeg)
935 (progn
936 (c-neutralize-CPP-line mbeg (point))
937 (c-set-cpp-delimiters mbeg (point))
938 ;(setq pps-position (point))
939 )
940 (forward-line)) ; no infinite loop with, e.g., "#//"
941 )))))
942
943 (defun c-before-change (beg end)
944 ;; Function to be put on `before-change-functions'. Primarily, this calls
945 ;; the language dependent `c-get-state-before-change-functions'. It is
946 ;; otherwise used only to remove stale entries from the `c-found-types'
947 ;; cache, and to record entries which a `c-after-change' function might
948 ;; confirm as stale.
949 ;;
950 ;; Note that this function must be FAST rather than accurate. Note
951 ;; also that it only has any effect when font locking is enabled.
952 ;; We exploit this by checking for font-lock-*-face instead of doing
953 ;; rigourous syntactic analysis.
954
955 ;; If either change boundary is wholly inside an identifier, delete
956 ;; it/them from the cache. Don't worry about being inside a string
957 ;; or a comment - "wrongly" removing a symbol from `c-found-types'
958 ;; isn't critical.
959 (setq c-maybe-stale-found-type nil)
960 (save-restriction
961 (save-match-data
962 (widen)
963 (save-excursion
964 ;; Are we inserting/deleting stuff in the middle of an identifier?
965 (c-unfind-enclosing-token beg)
966 (c-unfind-enclosing-token end)
967 ;; Are we coalescing two tokens together, e.g. "fo o" -> "foo"?
968 (when (< beg end)
969 (c-unfind-coalesced-tokens beg end))
970 ;; Are we (potentially) disrupting the syntactic context which
971 ;; makes a type a type? E.g. by inserting stuff after "foo" in
972 ;; "foo bar;", or before "foo" in "typedef foo *bar;"?
973 ;;
974 ;; We search for appropriate c-type properties "near" the change.
975 ;; First, find an appropriate boundary for this property search.
976 (let (lim
977 type type-pos
978 marked-id term-pos
979 (end1
980 (or (and (eq (get-text-property end 'face) 'font-lock-comment-face)
981 (previous-single-property-change end 'face))
982 end)))
983 (when (>= end1 beg) ; Don't hassle about changes entirely in comments.
984 ;; Find a limit for the search for a `c-type' property
985 (while
986 (and (/= (skip-chars-backward "^;{}") 0)
987 (> (point) (point-min))
988 (memq (c-get-char-property (1- (point)) 'face)
989 '(font-lock-comment-face font-lock-string-face))))
990 (setq lim (max (point-min) (1- (point))))
991
992 ;; Look for the latest `c-type' property before end1
993 (when (and (> end1 (point-min))
994 (setq type-pos
995 (if (get-text-property (1- end1) 'c-type)
996 end1
997 (previous-single-property-change end1 'c-type nil lim))))
998 (setq type (get-text-property (max (1- type-pos) lim) 'c-type))
999
1000 (when (memq type '(c-decl-id-start c-decl-type-start))
1001 ;; Get the identifier, if any, that the property is on.
1002 (goto-char (1- type-pos))
1003 (setq marked-id
1004 (when (looking-at "\\(\\sw\\|\\s_\\)")
1005 (c-beginning-of-current-token)
1006 (buffer-substring-no-properties (point) type-pos)))
1007
1008 (goto-char end1)
1009 (skip-chars-forward "^;{}") ; FIXME!!! loop for comment, maybe
1010 (setq lim (point))
1011 (setq term-pos
1012 (or (next-single-property-change end 'c-type nil lim) lim))
1013 (setq c-maybe-stale-found-type
1014 (list type marked-id
1015 type-pos term-pos
1016 (buffer-substring-no-properties type-pos term-pos)
1017 (buffer-substring-no-properties beg end)))))))
1018
1019 (if c-get-state-before-change-functions
1020 (mapc (lambda (fn)
1021 (funcall fn beg end))
1022 c-get-state-before-change-functions))
1023 ))))
1024
1025 (defun c-after-change (beg end old-len)
1026 ;; Function put on `after-change-functions' to adjust various caches
1027 ;; etc. Prefer speed to finesse here, since there will be an order
1028 ;; of magnitude more calls to this function than any of the
1029 ;; functions that use the caches.
1030 ;;
1031 ;; Note that care must be taken so that this is called before any
1032 ;; font-lock callbacks since we might get calls to functions using
1033 ;; these caches from inside them, and we must thus be sure that this
1034 ;; has already been executed.
1035 ;;
1036 ;; This calls the language variable c-before-font-lock-function, if non nil.
1037 ;; This typically sets `syntax-table' properties.
1038
1039 (c-save-buffer-state ()
1040 ;; When `combine-after-change-calls' is used we might get calls
1041 ;; with regions outside the current narrowing. This has been
1042 ;; observed in Emacs 20.7.
1043 (save-restriction
1044 (save-match-data ; c-recognize-<>-arglists changes match-data
1045 (widen)
1046
1047 (when (> end (point-max))
1048 ;; Some emacsen might return positions past the end. This has been
1049 ;; observed in Emacs 20.7 when rereading a buffer changed on disk
1050 ;; (haven't been able to minimize it, but Emacs 21.3 appears to
1051 ;; work).
1052 (setq end (point-max))
1053 (when (> beg end)
1054 (setq beg end)))
1055
1056 ;; C-y is capable of spuriously converting category properties
1057 ;; c-</>-as-paren-syntax into hard syntax-table properties. Remove
1058 ;; these when it happens.
1059 (c-clear-char-property-with-value beg end 'syntax-table
1060 c-<-as-paren-syntax)
1061 (c-clear-char-property-with-value beg end 'syntax-table
1062 c->-as-paren-syntax)
1063
1064 (c-trim-found-types beg end old-len) ; maybe we don't need all of these.
1065 (c-invalidate-sws-region-after beg end)
1066 (c-invalidate-state-cache beg)
1067 (c-invalidate-find-decl-cache beg)
1068
1069 (when c-recognize-<>-arglists
1070 (c-after-change-check-<>-operators beg end))
1071
1072 ;; (c-new-BEG c-new-END) will be the region to fontify. It may become
1073 ;; larger than (beg end).
1074 (setq c-new-BEG beg
1075 c-new-END end)
1076 (if c-before-font-lock-function
1077 (save-excursion
1078 (funcall c-before-font-lock-function beg end old-len)))))))
1079
1080 (defun c-after-font-lock-init ()
1081 ;; Put on `font-lock-mode-hook'.
1082 (remove-hook 'after-change-functions 'c-after-change t)
1083 (add-hook 'after-change-functions 'c-after-change nil t))
1084
1085 (defun c-font-lock-init ()
1086 "Set up the font-lock variables for using the font-lock support in CC Mode.
1087 This does not load the font-lock package. Use after
1088 `c-basic-common-init' and after cc-fonts has been loaded."
1089
1090 (set (make-local-variable 'font-lock-defaults)
1091 `(,(if (c-major-mode-is 'awk-mode)
1092 ;; awk-mode currently has only one font lock level.
1093 'awk-font-lock-keywords
1094 (mapcar 'c-mode-symbol
1095 '("font-lock-keywords" "font-lock-keywords-1"
1096 "font-lock-keywords-2" "font-lock-keywords-3")))
1097 nil nil
1098 ,c-identifier-syntax-modifications
1099 c-beginning-of-syntax
1100 (font-lock-mark-block-function
1101 . c-mark-function)))
1102 (if (featurep 'xemacs)
1103 (make-local-hook 'font-lock-mode-hook))
1104 (add-hook 'font-lock-mode-hook 'c-after-font-lock-init nil t))
1105
1106 (defun c-extend-after-change-region (beg end old-len)
1107 "Extend the region to be fontified, if necessary."
1108 ;; Note: the parameters are ignored here. This somewhat indirect
1109 ;; implementation exists because it is minimally different from the
1110 ;; stand-alone CC Mode which, lacking
1111 ;; font-lock-extend-after-change-region-function, is forced to use advice
1112 ;; instead.
1113 ;;
1114 ;; Of the seven CC Mode languages, currently (2009-05) only C, C++, Objc
1115 ;; (the languages with #define) and AWK Mode make non-null use of this
1116 ;; function.
1117 (cons c-new-BEG c-new-END))
1118
1119 \f
1120 ;; Support for C
1121
1122 ;;;###autoload
1123 (defvar c-mode-syntax-table nil
1124 "Syntax table used in c-mode buffers.")
1125 (or c-mode-syntax-table
1126 (setq c-mode-syntax-table
1127 (funcall (c-lang-const c-make-mode-syntax-table c))))
1128
1129 (defvar c-mode-abbrev-table nil
1130 "Abbreviation table used in c-mode buffers.")
1131 (c-define-abbrev-table 'c-mode-abbrev-table
1132 '(("else" "else" c-electric-continued-statement 0)
1133 ("while" "while" c-electric-continued-statement 0)))
1134
1135 (defvar c-mode-map ()
1136 "Keymap used in c-mode buffers.")
1137 (if c-mode-map
1138 nil
1139 (setq c-mode-map (c-make-inherited-keymap))
1140 ;; add bindings which are only useful for C
1141 (define-key c-mode-map "\C-c\C-e" 'c-macro-expand)
1142 )
1143
1144 (easy-menu-define c-c-menu c-mode-map "C Mode Commands"
1145 (cons "C" (c-lang-const c-mode-menu c)))
1146
1147 ;; In XEmacs >= 21.5 modes should add their own entries to
1148 ;; `auto-mode-alist'. The comment form of autoload is used to avoid
1149 ;; doing this on load. That since `add-to-list' prepends the value
1150 ;; which could cause it to clobber user settings. Later emacsen have
1151 ;; an append option, but it's not safe to use.
1152
1153 ;; The extension ".C" is associated with C++ while the lowercase
1154 ;; variant goes with C. On case insensitive file systems, this means
1155 ;; that ".c" files also might open C++ mode if the C++ entry comes
1156 ;; first on `auto-mode-alist'. Thus we try to ensure that ".C" comes
1157 ;; after ".c", and since `add-to-list' adds the entry first we have to
1158 ;; add the ".C" entry first.
1159 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.\\(cc\\|hh\\)\\'" . c++-mode))
1160 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.[ch]\\(pp\\|xx\\|\\+\\+\\)\\'" . c++-mode))
1161 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.\\(CC?\\|HH?\\)\\'" . c++-mode))
1162
1163 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.[ch]\\'" . c-mode))
1164
1165 ;; NB: The following two associate yacc and lex files to C Mode, which
1166 ;; is not really suitable for those formats. Anyway, afaik there's
1167 ;; currently no better mode for them, and besides this is legacy.
1168 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.y\\(acc\\)?\\'" . c-mode))
1169 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.lex\\'" . c-mode))
1170
1171 ;; Preprocessed files generated by C and C++ compilers.
1172 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.i\\'" . c-mode))
1173 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.ii\\'" . c++-mode))
1174
1175
1176 ;;;###autoload
1177 (defun c-mode ()
1178 "Major mode for editing K&R and ANSI C code.
1179 To submit a problem report, enter `\\[c-submit-bug-report]' from a
1180 c-mode buffer. This automatically sets up a mail buffer with version
1181 information already added. You just need to add a description of the
1182 problem, including a reproducible test case, and send the message.
1183
1184 To see what version of CC Mode you are running, enter `\\[c-version]'.
1185
1186 The hook `c-mode-common-hook' is run with no args at mode
1187 initialization, then `c-mode-hook'.
1188
1189 Key bindings:
1190 \\{c-mode-map}"
1191 (interactive)
1192 (kill-all-local-variables)
1193 (c-initialize-cc-mode t)
1194 (set-syntax-table c-mode-syntax-table)
1195 (setq major-mode 'c-mode ; FIXME: Use define-derived-mode.
1196 mode-name "C"
1197 local-abbrev-table c-mode-abbrev-table
1198 abbrev-mode t)
1199 (use-local-map c-mode-map)
1200 (c-init-language-vars-for 'c-mode)
1201 (c-common-init 'c-mode)
1202 (easy-menu-add c-c-menu)
1203 (cc-imenu-init cc-imenu-c-generic-expression)
1204 (c-run-mode-hooks 'c-mode-common-hook 'c-mode-hook)
1205 (c-update-modeline))
1206
1207 \f
1208 ;; Support for C++
1209
1210 ;;;###autoload
1211 (defvar c++-mode-syntax-table nil
1212 "Syntax table used in c++-mode buffers.")
1213 (or c++-mode-syntax-table
1214 (setq c++-mode-syntax-table
1215 (funcall (c-lang-const c-make-mode-syntax-table c++))))
1216
1217 (defvar c++-mode-abbrev-table nil
1218 "Abbreviation table used in c++-mode buffers.")
1219 (c-define-abbrev-table 'c++-mode-abbrev-table
1220 '(("else" "else" c-electric-continued-statement 0)
1221 ("while" "while" c-electric-continued-statement 0)
1222 ("catch" "catch" c-electric-continued-statement 0)))
1223
1224 (defvar c++-mode-map ()
1225 "Keymap used in c++-mode buffers.")
1226 (if c++-mode-map
1227 nil
1228 (setq c++-mode-map (c-make-inherited-keymap))
1229 ;; add bindings which are only useful for C++
1230 (define-key c++-mode-map "\C-c\C-e" 'c-macro-expand)
1231 (define-key c++-mode-map "\C-c:" 'c-scope-operator)
1232 (define-key c++-mode-map "<" 'c-electric-lt-gt)
1233 (define-key c++-mode-map ">" 'c-electric-lt-gt))
1234
1235 (easy-menu-define c-c++-menu c++-mode-map "C++ Mode Commands"
1236 (cons "C++" (c-lang-const c-mode-menu c++)))
1237
1238 ;;;###autoload
1239 (defun c++-mode ()
1240 "Major mode for editing C++ code.
1241 To submit a problem report, enter `\\[c-submit-bug-report]' from a
1242 c++-mode buffer. This automatically sets up a mail buffer with
1243 version information already added. You just need to add a description
1244 of the problem, including a reproducible test case, and send the
1245 message.
1246
1247 To see what version of CC Mode you are running, enter `\\[c-version]'.
1248
1249 The hook `c-mode-common-hook' is run with no args at mode
1250 initialization, then `c++-mode-hook'.
1251
1252 Key bindings:
1253 \\{c++-mode-map}"
1254 (interactive)
1255 (kill-all-local-variables)
1256 (c-initialize-cc-mode t)
1257 (set-syntax-table c++-mode-syntax-table)
1258 (setq major-mode 'c++-mode ; FIXME: Use define-derived-mode.
1259 mode-name "C++"
1260 local-abbrev-table c++-mode-abbrev-table
1261 abbrev-mode t)
1262 (use-local-map c++-mode-map)
1263 (c-init-language-vars-for 'c++-mode)
1264 (c-common-init 'c++-mode)
1265 (easy-menu-add c-c++-menu)
1266 (cc-imenu-init cc-imenu-c++-generic-expression)
1267 (c-run-mode-hooks 'c-mode-common-hook 'c++-mode-hook)
1268 (c-update-modeline))
1269
1270 \f
1271 ;; Support for Objective-C
1272
1273 ;;;###autoload
1274 (defvar objc-mode-syntax-table nil
1275 "Syntax table used in objc-mode buffers.")
1276 (or objc-mode-syntax-table
1277 (setq objc-mode-syntax-table
1278 (funcall (c-lang-const c-make-mode-syntax-table objc))))
1279
1280 (defvar objc-mode-abbrev-table nil
1281 "Abbreviation table used in objc-mode buffers.")
1282 (c-define-abbrev-table 'objc-mode-abbrev-table
1283 '(("else" "else" c-electric-continued-statement 0)
1284 ("while" "while" c-electric-continued-statement 0)))
1285
1286 (defvar objc-mode-map ()
1287 "Keymap used in objc-mode buffers.")
1288 (if objc-mode-map
1289 nil
1290 (setq objc-mode-map (c-make-inherited-keymap))
1291 ;; add bindings which are only useful for Objective-C
1292 (define-key objc-mode-map "\C-c\C-e" 'c-macro-expand))
1293
1294 (easy-menu-define c-objc-menu objc-mode-map "ObjC Mode Commands"
1295 (cons "ObjC" (c-lang-const c-mode-menu objc)))
1296
1297 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.m\\'" . objc-mode))
1298
1299 ;;;###autoload
1300 (defun objc-mode ()
1301 "Major mode for editing Objective C code.
1302 To submit a problem report, enter `\\[c-submit-bug-report]' from an
1303 objc-mode buffer. This automatically sets up a mail buffer with
1304 version information already added. You just need to add a description
1305 of the problem, including a reproducible test case, and send the
1306 message.
1307
1308 To see what version of CC Mode you are running, enter `\\[c-version]'.
1309
1310 The hook `c-mode-common-hook' is run with no args at mode
1311 initialization, then `objc-mode-hook'.
1312
1313 Key bindings:
1314 \\{objc-mode-map}"
1315 (interactive)
1316 (kill-all-local-variables)
1317 (c-initialize-cc-mode t)
1318 (set-syntax-table objc-mode-syntax-table)
1319 (setq major-mode 'objc-mode ; FIXME: Use define-derived-mode.
1320 mode-name "ObjC"
1321 local-abbrev-table objc-mode-abbrev-table
1322 abbrev-mode t)
1323 (use-local-map objc-mode-map)
1324 (c-init-language-vars-for 'objc-mode)
1325 (c-common-init 'objc-mode)
1326 (easy-menu-add c-objc-menu)
1327 (cc-imenu-init nil 'cc-imenu-objc-function)
1328 (c-run-mode-hooks 'c-mode-common-hook 'objc-mode-hook)
1329 (c-update-modeline))
1330
1331 \f
1332 ;; Support for Java
1333
1334 ;;;###autoload
1335 (defvar java-mode-syntax-table nil
1336 "Syntax table used in java-mode buffers.")
1337 (or java-mode-syntax-table
1338 (setq java-mode-syntax-table
1339 (funcall (c-lang-const c-make-mode-syntax-table java))))
1340
1341 (defvar java-mode-abbrev-table nil
1342 "Abbreviation table used in java-mode buffers.")
1343 (c-define-abbrev-table 'java-mode-abbrev-table
1344 '(("else" "else" c-electric-continued-statement 0)
1345 ("while" "while" c-electric-continued-statement 0)
1346 ("catch" "catch" c-electric-continued-statement 0)
1347 ("finally" "finally" c-electric-continued-statement 0)))
1348
1349 (defvar java-mode-map ()
1350 "Keymap used in java-mode buffers.")
1351 (if java-mode-map
1352 nil
1353 (setq java-mode-map (c-make-inherited-keymap))
1354 ;; add bindings which are only useful for Java
1355 )
1356
1357 ;; Regexp trying to describe the beginning of a Java top-level
1358 ;; definition. This is not used by CC Mode, nor is it maintained
1359 ;; since it's practically impossible to write a regexp that reliably
1360 ;; matches such a construct. Other tools are necessary.
1361 (defconst c-Java-defun-prompt-regexp
1362 "^[ \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-*")
1363
1364 (easy-menu-define c-java-menu java-mode-map "Java Mode Commands"
1365 (cons "Java" (c-lang-const c-mode-menu java)))
1366
1367 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.java\\'" . java-mode))
1368
1369 ;;;###autoload
1370 (defun java-mode ()
1371 "Major mode for editing Java code.
1372 To submit a problem report, enter `\\[c-submit-bug-report]' from a
1373 java-mode buffer. This automatically sets up a mail buffer with
1374 version information already added. You just need to add a description
1375 of the problem, including a reproducible test case, and send the
1376 message.
1377
1378 To see what version of CC Mode you are running, enter `\\[c-version]'.
1379
1380 The hook `c-mode-common-hook' is run with no args at mode
1381 initialization, then `java-mode-hook'.
1382
1383 Key bindings:
1384 \\{java-mode-map}"
1385 (interactive)
1386 (kill-all-local-variables)
1387 (c-initialize-cc-mode t)
1388 (set-syntax-table java-mode-syntax-table)
1389 (setq major-mode 'java-mode ; FIXME: Use define-derived-mode.
1390 mode-name "Java"
1391 local-abbrev-table java-mode-abbrev-table
1392 abbrev-mode t)
1393 (use-local-map java-mode-map)
1394 (c-init-language-vars-for 'java-mode)
1395 (c-common-init 'java-mode)
1396 (easy-menu-add c-java-menu)
1397 (cc-imenu-init cc-imenu-java-generic-expression)
1398 (c-run-mode-hooks 'c-mode-common-hook 'java-mode-hook)
1399 (c-update-modeline))
1400
1401 \f
1402 ;; Support for CORBA's IDL language
1403
1404 ;;;###autoload
1405 (defvar idl-mode-syntax-table nil
1406 "Syntax table used in idl-mode buffers.")
1407 (or idl-mode-syntax-table
1408 (setq idl-mode-syntax-table
1409 (funcall (c-lang-const c-make-mode-syntax-table idl))))
1410
1411 (defvar idl-mode-abbrev-table nil
1412 "Abbreviation table used in idl-mode buffers.")
1413 (c-define-abbrev-table 'idl-mode-abbrev-table nil)
1414
1415 (defvar idl-mode-map ()
1416 "Keymap used in idl-mode buffers.")
1417 (if idl-mode-map
1418 nil
1419 (setq idl-mode-map (c-make-inherited-keymap))
1420 ;; add bindings which are only useful for IDL
1421 )
1422
1423 (easy-menu-define c-idl-menu idl-mode-map "IDL Mode Commands"
1424 (cons "IDL" (c-lang-const c-mode-menu idl)))
1425
1426 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.idl\\'" . idl-mode))
1427
1428 ;;;###autoload
1429 (defun idl-mode ()
1430 "Major mode for editing CORBA's IDL, PSDL and CIDL code.
1431 To submit a problem report, enter `\\[c-submit-bug-report]' from an
1432 idl-mode buffer. This automatically sets up a mail buffer with
1433 version information already added. You just need to add a description
1434 of the problem, including a reproducible test case, and send the
1435 message.
1436
1437 To see what version of CC Mode you are running, enter `\\[c-version]'.
1438
1439 The hook `c-mode-common-hook' is run with no args at mode
1440 initialization, then `idl-mode-hook'.
1441
1442 Key bindings:
1443 \\{idl-mode-map}"
1444 (interactive)
1445 (kill-all-local-variables)
1446 (c-initialize-cc-mode t)
1447 (set-syntax-table idl-mode-syntax-table)
1448 (setq major-mode 'idl-mode ; FIXME: Use define-derived-mode.
1449 mode-name "IDL"
1450 local-abbrev-table idl-mode-abbrev-table)
1451 (use-local-map idl-mode-map)
1452 (c-init-language-vars-for 'idl-mode)
1453 (c-common-init 'idl-mode)
1454 (easy-menu-add c-idl-menu)
1455 ;;(cc-imenu-init cc-imenu-idl-generic-expression) ;TODO
1456 (c-run-mode-hooks 'c-mode-common-hook 'idl-mode-hook)
1457 (c-update-modeline))
1458
1459 \f
1460 ;; Support for Pike
1461
1462 ;;;###autoload
1463 (defvar pike-mode-syntax-table nil
1464 "Syntax table used in pike-mode buffers.")
1465 (or pike-mode-syntax-table
1466 (setq pike-mode-syntax-table
1467 (funcall (c-lang-const c-make-mode-syntax-table pike))))
1468
1469 (defvar pike-mode-abbrev-table nil
1470 "Abbreviation table used in pike-mode buffers.")
1471 (c-define-abbrev-table 'pike-mode-abbrev-table
1472 '(("else" "else" c-electric-continued-statement 0)
1473 ("while" "while" c-electric-continued-statement 0)))
1474
1475 (defvar pike-mode-map ()
1476 "Keymap used in pike-mode buffers.")
1477 (if pike-mode-map
1478 nil
1479 (setq pike-mode-map (c-make-inherited-keymap))
1480 ;; additional bindings
1481 (define-key pike-mode-map "\C-c\C-e" 'c-macro-expand))
1482
1483 (easy-menu-define c-pike-menu pike-mode-map "Pike Mode Commands"
1484 (cons "Pike" (c-lang-const c-mode-menu pike)))
1485
1486 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.\\(u?lpc\\|pike\\|pmod\\(.in\\)?\\)\\'" . pike-mode))
1487 ;;;###autoload (add-to-list 'interpreter-mode-alist '("pike" . pike-mode))
1488
1489 ;;;###autoload
1490 (defun pike-mode ()
1491 "Major mode for editing Pike code.
1492 To submit a problem report, enter `\\[c-submit-bug-report]' from a
1493 pike-mode buffer. This automatically sets up a mail buffer with
1494 version information already added. You just need to add a description
1495 of the problem, including a reproducible test case, and send the
1496 message.
1497
1498 To see what version of CC Mode you are running, enter `\\[c-version]'.
1499
1500 The hook `c-mode-common-hook' is run with no args at mode
1501 initialization, then `pike-mode-hook'.
1502
1503 Key bindings:
1504 \\{pike-mode-map}"
1505 (interactive)
1506 (kill-all-local-variables)
1507 (c-initialize-cc-mode t)
1508 (set-syntax-table pike-mode-syntax-table)
1509 (setq major-mode 'pike-mode ; FIXME: Use define-derived-mode.
1510 mode-name "Pike"
1511 local-abbrev-table pike-mode-abbrev-table
1512 abbrev-mode t)
1513 (use-local-map pike-mode-map)
1514 (c-init-language-vars-for 'pike-mode)
1515 (c-common-init 'pike-mode)
1516 (easy-menu-add c-pike-menu)
1517 ;;(cc-imenu-init cc-imenu-pike-generic-expression) ;TODO
1518 (c-run-mode-hooks 'c-mode-common-hook 'pike-mode-hook)
1519 (c-update-modeline))
1520
1521 \f
1522 ;; Support for AWK
1523
1524 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.awk\\'" . awk-mode))
1525 ;;;###autoload (add-to-list 'interpreter-mode-alist '("awk" . awk-mode))
1526 ;;;###autoload (add-to-list 'interpreter-mode-alist '("mawk" . awk-mode))
1527 ;;;###autoload (add-to-list 'interpreter-mode-alist '("nawk" . awk-mode))
1528 ;;;###autoload (add-to-list 'interpreter-mode-alist '("gawk" . awk-mode))
1529
1530 ;;; Autoload directives must be on the top level, so we construct an
1531 ;;; autoload form instead.
1532 ;;;###autoload (autoload 'awk-mode "cc-mode" "Major mode for editing AWK code." t)
1533
1534 (defvar awk-mode-abbrev-table nil
1535 "Abbreviation table used in awk-mode buffers.")
1536 (c-define-abbrev-table 'awk-mode-abbrev-table
1537 '(("else" "else" c-electric-continued-statement 0)
1538 ("while" "while" c-electric-continued-statement 0)))
1539
1540 (defvar awk-mode-map ()
1541 "Keymap used in awk-mode buffers.")
1542 (if awk-mode-map
1543 nil
1544 (setq awk-mode-map (c-make-inherited-keymap))
1545 ;; add bindings which are only useful for awk.
1546 (define-key awk-mode-map "#" 'self-insert-command)
1547 (define-key awk-mode-map "/" 'self-insert-command)
1548 (define-key awk-mode-map "*" 'self-insert-command)
1549 (define-key awk-mode-map "\C-c\C-n" 'undefined) ; #if doesn't exist in awk.
1550 (define-key awk-mode-map "\C-c\C-p" 'undefined)
1551 (define-key awk-mode-map "\C-c\C-u" 'undefined)
1552 (define-key awk-mode-map "\M-a" 'c-beginning-of-statement) ; 2003/10/7
1553 (define-key awk-mode-map "\M-e" 'c-end-of-statement) ; 2003/10/7
1554 (define-key awk-mode-map "\C-\M-a" 'c-awk-beginning-of-defun)
1555 (define-key awk-mode-map "\C-\M-e" 'c-awk-end-of-defun))
1556
1557 (easy-menu-define c-awk-menu awk-mode-map "AWK Mode Commands"
1558 (cons "AWK" (c-lang-const c-mode-menu awk)))
1559
1560 ;; (require 'cc-awk) brings these in.
1561 (defvar awk-mode-syntax-table)
1562 (declare-function c-awk-unstick-NL-prop "cc-awk" ())
1563
1564 (defun awk-mode ()
1565 "Major mode for editing AWK code.
1566 To submit a problem report, enter `\\[c-submit-bug-report]' from an
1567 awk-mode buffer. This automatically sets up a mail buffer with version
1568 information already added. You just need to add a description of the
1569 problem, including a reproducible test case, and send the message.
1570
1571 To see what version of CC Mode you are running, enter `\\[c-version]'.
1572
1573 The hook `c-mode-common-hook' is run with no args at mode
1574 initialization, then `awk-mode-hook'.
1575
1576 Key bindings:
1577 \\{awk-mode-map}"
1578 (interactive)
1579 (require 'cc-awk) ; Added 2003/6/10.
1580 (kill-all-local-variables)
1581 (c-initialize-cc-mode t)
1582 (set-syntax-table awk-mode-syntax-table)
1583 (setq major-mode 'awk-mode ; FIXME: Use define-derived-mode.
1584 mode-name "AWK"
1585 local-abbrev-table awk-mode-abbrev-table
1586 abbrev-mode t)
1587 (use-local-map awk-mode-map)
1588 (c-init-language-vars-for 'awk-mode)
1589 (c-common-init 'awk-mode)
1590 (c-awk-unstick-NL-prop)
1591
1592 ;; Prevent Xemacs's buffer-syntactic-context being used. See the comment
1593 ;; in cc-engine.el, just before (defun c-fast-in-literal ...
1594 (defalias 'c-in-literal 'c-slow-in-literal)
1595
1596 (c-run-mode-hooks 'c-mode-common-hook 'awk-mode-hook)
1597 (c-update-modeline))
1598
1599 \f
1600 ;; bug reporting
1601
1602 (defconst c-mode-help-address
1603 "bug-cc-mode@gnu.org"
1604 "Address(es) for CC Mode bug reports.")
1605
1606 (defun c-version ()
1607 "Echo the current version of CC Mode in the minibuffer."
1608 (interactive)
1609 (message "Using CC Mode version %s" c-version)
1610 (c-keep-region-active))
1611
1612 (defvar c-prepare-bug-report-hooks nil)
1613
1614 ;; Dynamic variables used by reporter.
1615 (defvar reporter-prompt-for-summary-p)
1616 (defvar reporter-dont-compact-list)
1617
1618 (defun c-submit-bug-report ()
1619 "Submit via mail a bug report on CC Mode."
1620 (interactive)
1621 (require 'reporter)
1622 ;; load in reporter
1623 (let ((reporter-prompt-for-summary-p t)
1624 (reporter-dont-compact-list '(c-offsets-alist))
1625 (style c-indentation-style)
1626 (c-features c-emacs-features))
1627 (and
1628 (if (y-or-n-p "Do you want to submit a report on CC Mode? ")
1629 t (message "") nil)
1630 (reporter-submit-bug-report
1631 c-mode-help-address
1632 (concat "CC Mode " c-version " (" mode-name ")")
1633 (let ((vars (append
1634 c-style-variables
1635 '(c-buffer-is-cc-mode
1636 c-tab-always-indent
1637 c-syntactic-indentation
1638 c-syntactic-indentation-in-macros
1639 c-ignore-auto-fill
1640 c-auto-align-backslashes
1641 c-backspace-function
1642 c-delete-function
1643 c-electric-pound-behavior
1644 c-default-style
1645 c-enable-xemacs-performance-kludge-p
1646 c-old-style-variable-behavior
1647 defun-prompt-regexp
1648 tab-width
1649 comment-column
1650 parse-sexp-ignore-comments
1651 parse-sexp-lookup-properties
1652 lookup-syntax-properties
1653 ;; A brain-damaged XEmacs only variable that, if
1654 ;; set to nil can cause all kinds of chaos.
1655 signal-error-on-buffer-boundary
1656 ;; Variables that affect line breaking and comments.
1657 auto-fill-mode
1658 auto-fill-function
1659 filladapt-mode
1660 comment-multi-line
1661 comment-start-skip
1662 fill-prefix
1663 fill-column
1664 paragraph-start
1665 adaptive-fill-mode
1666 adaptive-fill-regexp)
1667 nil)))
1668 (mapc (lambda (var) (unless (boundp var)
1669 (setq vars (delq var vars))))
1670 '(signal-error-on-buffer-boundary
1671 filladapt-mode
1672 defun-prompt-regexp
1673 font-lock-mode
1674 font-lock-maximum-decoration
1675 parse-sexp-lookup-properties
1676 lookup-syntax-properties))
1677 vars)
1678 (lambda ()
1679 (run-hooks 'c-prepare-bug-report-hooks)
1680 (insert (format "Buffer Style: %s\nc-emacs-features: %s\n"
1681 style c-features)))))))
1682
1683 \f
1684 (cc-provide 'cc-mode)
1685
1686 ;;; cc-mode.el ends here