1 ;;; cc-mode.el --- major mode for editing C and similar languages
3 ;; Copyright (C) 1985,1987,1992-2003, 2004, 2005, 2006 Free Software
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
15 ;; This file is part of GNU Emacs.
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)
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.
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.
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.
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.
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.
51 ;; CC Mode's immediate ancestors were, c++-mode.el, cplus-md.el, and
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!
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.
66 ;; You can get the latest version of CC Mode, including PostScript
67 ;; documentation and separate individual files from:
69 ;; http://cc-mode.sourceforge.net/
71 ;; You can join a moderated CC Mode announcement-only mailing list by
74 ;; http://lists.sourceforge.net/mailman/listinfo/cc-mode-announce
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)
84 (load "cc-bytecomp" nil t)))
87 (cc-require-when-compile 'cc-langs)
89 (cc-require 'cc-engine)
90 (cc-require 'cc-styles)
92 (cc-require 'cc-align)
93 (cc-require 'cc-menus)
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.
101 ;; We set these variables during mode init, yet we don't require
103 (cc-bytecomp-defvar font-lock-defaults)
104 (cc-bytecomp-defvar font-lock-syntactic-keywords)
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)
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)
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" ; 2006-07-09: font-lock is now preloaded.
119 (require 'cc-fonts) ;)
121 ;; cc-langs isn't loaded when we're byte compiled, so add autoload
122 ;; directives for the interface functions.
123 (autoload 'c-make-init-lang-vars-fun "cc-langs")
124 (autoload 'c-init-language-vars "cc-langs" nil nil 'macro)
127 ;; Other modes and packages which depend on CC Mode should do the
128 ;; following to make sure everything is loaded and available for their
131 ;; (require 'cc-mode)
133 ;; And in the major mode function:
135 ;; (c-initialize-cc-mode t)
136 ;; (c-init-language-vars some-mode)
137 ;; (c-common-init 'some-mode) ; Or perhaps (c-basic-common-init 'some-mode)
139 ;; If you're not writing a derived mode using the language variable
140 ;; system, then some-mode is one of the language modes directly
141 ;; supported by CC Mode. You can then use (c-init-language-vars-for
142 ;; 'some-mode) instead of `c-init-language-vars'.
143 ;; `c-init-language-vars-for' is a function that avoids the rather
144 ;; large expansion of `c-init-language-vars'.
146 ;; If you use `c-basic-common-init' then you might want to call
147 ;; `c-font-lock-init' too to set up CC Mode's font lock support.
149 ;; See cc-langs.el for further info. A small example of a derived mode
150 ;; is also available at <http://cc-mode.sourceforge.net/
151 ;; derived-mode-ex.el>.
153 (defun c-leave-cc-mode-mode ()
154 (setq c-buffer-is-cc-mode nil))
156 ;; Make the `c-lang-setvar' variables buffer local in the current buffer.
157 ;; These are typically standard emacs variables such as `comment-start'.
158 (defmacro c-make-emacs-variables-local ()
160 ,@(mapcan (lambda (init)
161 `((make-local-variable ',(car init))))
162 (cdr c-emacs-variable-inits))))
164 (defun c-init-language-vars-for (mode)
165 "Initialize the language variables for one of the language modes
166 directly supported by CC Mode. This can be used instead of the
167 `c-init-language-vars' macro if the language you want to use is one of
168 those, rather than a derived language defined through the language
169 variable system (see \"cc-langs.el\")."
170 (c-make-emacs-variables-local)
171 (cond ((eq mode 'c-mode) (c-init-language-vars c-mode))
172 ((eq mode 'c++-mode) (c-init-language-vars c++-mode))
173 ((eq mode 'objc-mode) (c-init-language-vars objc-mode))
174 ((eq mode 'java-mode) (c-init-language-vars java-mode))
175 ((eq mode 'idl-mode) (c-init-language-vars idl-mode))
176 ((eq mode 'pike-mode) (c-init-language-vars pike-mode))
177 ((eq mode 'awk-mode) (c-init-language-vars awk-mode))
178 (t (error "Unsupported mode %s" mode))))
181 (defun c-initialize-cc-mode (&optional new-style-init)
182 "Initialize CC Mode for use in the current buffer.
183 If the optional NEW-STYLE-INIT is nil or left out then all necessary
184 initialization to run CC Mode for the C language is done. Otherwise
185 only some basic setup is done, and a call to `c-init-language-vars' or
186 `c-init-language-vars-for' is necessary too (which gives more
187 control). See \"cc-mode.el\" for more info."
189 (setq c-buffer-is-cc-mode t)
191 (let ((initprop 'cc-mode-is-initialized)
193 (unless (get 'c-initialize-cc-mode initprop)
196 (put 'c-initialize-cc-mode initprop t)
197 (c-initialize-builtin-style)
198 (run-hooks 'c-initialization-hook)
199 ;; Fix obsolete variables.
200 (if (boundp 'c-comment-continuation-stars)
201 (setq c-block-comment-prefix c-comment-continuation-stars))
202 (add-hook 'change-major-mode-hook 'c-leave-cc-mode-mode)
203 (setq c-initialization-ok t))
204 ;; Will try initialization hooks again if they failed.
205 (put 'c-initialize-cc-mode initprop c-initialization-ok))))
207 (unless new-style-init
208 (c-init-language-vars-for 'c-mode)))
213 (defvar c-mode-base-map ()
214 "Keymap shared by all CC Mode related modes.")
216 (defun c-make-inherited-keymap ()
217 (let ((map (make-sparse-keymap)))
218 ;; Necessary to use `cc-bytecomp-fboundp' below since this
219 ;; function is called from top-level forms that are evaluated
220 ;; while cc-bytecomp is active when one does M-x eval-buffer.
223 ((cc-bytecomp-fboundp 'set-keymap-parents)
224 (set-keymap-parents map c-mode-base-map))
226 ((cc-bytecomp-fboundp 'set-keymap-parent)
227 (set-keymap-parent map c-mode-base-map))
229 (t (error "CC Mode is incompatible with this version of Emacs")))
232 (defun c-define-abbrev-table (name defs)
233 ;; Compatibility wrapper for `define-abbrev' which passes a non-nil
234 ;; sixth argument for SYSTEM-FLAG in emacsen that support it
235 ;; (currently only Emacs >= 21.2).
236 (let ((table (or (symbol-value name)
237 (progn (define-abbrev-table name nil)
238 (symbol-value name)))))
241 (apply 'define-abbrev table (append (car defs) '(t)))
242 (wrong-number-of-arguments
243 (apply 'define-abbrev table (car defs))))
244 (setq defs (cdr defs)))))
245 (put 'c-define-abbrev-table 'lisp-indent-function 1)
247 (defun c-bind-special-erase-keys ()
248 ;; Only used in Emacs to bind C-c C-<delete> and C-c C-<backspace>
249 ;; to the proper keys depending on `normal-erase-is-backspace'.
250 (if normal-erase-is-backspace
252 (define-key c-mode-base-map (kbd "C-c C-<delete>")
253 'c-hungry-delete-forward)
254 (define-key c-mode-base-map (kbd "C-c C-<backspace>")
255 'c-hungry-delete-backwards))
256 (define-key c-mode-base-map (kbd "C-c C-<delete>")
257 'c-hungry-delete-backwards)
258 (define-key c-mode-base-map (kbd "C-c C-<backspace>")
259 'c-hungry-delete-forward)))
264 (setq c-mode-base-map (make-sparse-keymap))
266 ;; Separate M-BS from C-M-h. The former should remain
267 ;; backward-kill-word.
268 (define-key c-mode-base-map [(control meta h)] 'c-mark-function)
269 (define-key c-mode-base-map "\e\C-q" 'c-indent-exp)
270 (substitute-key-definition 'backward-sentence
271 'c-beginning-of-statement
272 c-mode-base-map global-map)
273 (substitute-key-definition 'forward-sentence
275 c-mode-base-map global-map)
276 (substitute-key-definition 'indent-new-comment-line
277 'c-indent-new-comment-line
278 c-mode-base-map global-map)
279 (substitute-key-definition 'indent-for-tab-command
281 c-mode-base-map global-map)
282 (when (fboundp 'comment-indent-new-line)
283 ;; indent-new-comment-line has changed name to
284 ;; comment-indent-new-line in Emacs 21.
285 (substitute-key-definition 'comment-indent-new-line
286 'c-indent-new-comment-line
287 c-mode-base-map global-map))
289 ;; RMS says don't make these the default.
290 ;; (define-key c-mode-base-map "\e\C-a" 'c-beginning-of-defun)
291 ;; (define-key c-mode-base-map "\e\C-e" 'c-end-of-defun)
293 (define-key c-mode-base-map "\C-c\C-n" 'c-forward-conditional)
294 (define-key c-mode-base-map "\C-c\C-p" 'c-backward-conditional)
295 (define-key c-mode-base-map "\C-c\C-u" 'c-up-conditional)
297 ;; It doesn't suffice to put `c-fill-paragraph' on
298 ;; `fill-paragraph-function' since `c-fill-paragraph' must be called
299 ;; before any fill prefix adaption is done. E.g. `filladapt-mode'
300 ;; replaces `fill-paragraph' and does the adaption before calling
301 ;; `fill-paragraph-function', and we have to mask comments etc
302 ;; before that. Also, `c-fill-paragraph' chains on to
303 ;; `fill-paragraph' and the value on `fill-parapgraph-function' to
304 ;; do the actual filling work.
305 (substitute-key-definition 'fill-paragraph 'c-fill-paragraph
306 c-mode-base-map global-map)
307 ;; In XEmacs the default fill function is called
308 ;; fill-paragraph-or-region.
309 (substitute-key-definition 'fill-paragraph-or-region 'c-fill-paragraph
310 c-mode-base-map global-map)
312 ;; We bind the forward deletion key and (implicitly) C-d to
313 ;; `c-electric-delete-forward', and the backward deletion key to
314 ;; `c-electric-backspace'. The hungry variants are bound to the
315 ;; same keys but prefixed with C-c. This implies that C-c C-d is
316 ;; `c-hungry-delete-forward'. For consistency, we bind not only C-c
317 ;; <backspace> to `c-hungry-delete-backwards' but also
318 ;; C-c C-<backspace>, so that the Ctrl key can be held down during
319 ;; the whole sequence regardless of the direction. This in turn
320 ;; implies that we bind C-c C-<delete> to `c-hungry-delete-forward',
321 ;; for the same reason.
323 ;; Bind the electric deletion functions to C-d and DEL. Emacs 21
324 ;; automatically maps the [delete] and [backspace] keys to these two
325 ;; depending on window system and user preferences. (In earlier
326 ;; versions it's possible to do the same by using `function-key-map'.)
327 (define-key c-mode-base-map "\C-d" 'c-electric-delete-forward)
328 (define-key c-mode-base-map "\177" 'c-electric-backspace)
329 (define-key c-mode-base-map "\C-c\C-d" 'c-hungry-delete-forward)
330 (define-key c-mode-base-map [?\C-c ?\d] 'c-hungry-delete-backwards)
331 (define-key c-mode-base-map [?\C-c ?\C-\d] 'c-hungry-delete-backwards)
332 (define-key c-mode-base-map [?\C-c deletechar] 'c-hungry-delete-forward) ; C-c <delete> on a tty.
333 (define-key c-mode-base-map [?\C-c (control deletechar)] ; C-c C-<delete> on a tty.
334 'c-hungry-delete-forward)
335 (when (boundp 'normal-erase-is-backspace)
336 ;; The automatic C-d and DEL mapping functionality doesn't extend
337 ;; to special combinations like C-c C-<delete>, so we have to hook
338 ;; into the `normal-erase-is-backspace' system to bind it directly
340 (add-hook 'normal-erase-is-backspace-hook 'c-bind-special-erase-keys)
341 (c-bind-special-erase-keys))
343 (when (fboundp 'delete-forward-p)
344 ;; In XEmacs we fix the forward and backward deletion behavior by
345 ;; binding the keysyms for the [delete] and [backspace] keys
346 ;; directly, and use `delete-forward-p' to decide what [delete]
347 ;; should do. That's done in the XEmacs specific
348 ;; `c-electric-delete' and `c-hungry-delete' functions.
349 (define-key c-mode-base-map [delete] 'c-electric-delete)
350 (define-key c-mode-base-map [backspace] 'c-electric-backspace)
351 (define-key c-mode-base-map (kbd "C-c <delete>") 'c-hungry-delete)
352 (define-key c-mode-base-map (kbd "C-c C-<delete>") 'c-hungry-delete)
353 (define-key c-mode-base-map (kbd "C-c <backspace>")
354 'c-hungry-delete-backwards)
355 (define-key c-mode-base-map (kbd "C-c C-<backspace>")
356 'c-hungry-delete-backwards))
358 (define-key c-mode-base-map "#" 'c-electric-pound)
359 (define-key c-mode-base-map "{" 'c-electric-brace)
360 (define-key c-mode-base-map "}" 'c-electric-brace)
361 (define-key c-mode-base-map "/" 'c-electric-slash)
362 (define-key c-mode-base-map "*" 'c-electric-star)
363 (define-key c-mode-base-map ";" 'c-electric-semi&comma)
364 (define-key c-mode-base-map "," 'c-electric-semi&comma)
365 (define-key c-mode-base-map ":" 'c-electric-colon)
366 (define-key c-mode-base-map "(" 'c-electric-paren)
367 (define-key c-mode-base-map ")" 'c-electric-paren)
369 (define-key c-mode-base-map "\C-c\C-\\" 'c-backslash-region)
370 (define-key c-mode-base-map "\C-c\C-a" 'c-toggle-auto-newline)
371 (define-key c-mode-base-map "\C-c\C-b" 'c-submit-bug-report)
372 (define-key c-mode-base-map "\C-c\C-c" 'comment-region)
373 (define-key c-mode-base-map "\C-c\C-l" 'c-toggle-electric-state)
374 (define-key c-mode-base-map "\C-c\C-o" 'c-set-offset)
375 (define-key c-mode-base-map "\C-c\C-q" 'c-indent-defun)
376 (define-key c-mode-base-map "\C-c\C-s" 'c-show-syntactic-information)
377 ;; (define-key c-mode-base-map "\C-c\C-t" 'c-toggle-auto-hungry-state) Commented out by ACM, 2005-03-05.
378 (define-key c-mode-base-map "\C-c." 'c-set-style)
379 ;; conflicts with OOBR
380 ;;(define-key c-mode-base-map "\C-c\C-v" 'c-version)
381 ;; (define-key c-mode-base-map "\C-c\C-y" 'c-toggle-hungry-state) Commented out by ACM, 2005-11-22.
382 (define-key c-mode-base-map "\C-c\C-w" 'c-subword-mode)
385 ;; We don't require the outline package, but we configure it a bit anyway.
386 (cc-bytecomp-defvar outline-level)
388 (defun c-mode-menu (modestr)
389 "Return a menu spec suitable for `easy-menu-define' that is exactly
390 like the C mode menu except that the menu bar item name is MODESTR
393 This function is provided for compatibility only; derived modes should
394 preferably use the `c-mode-menu' language constant directly."
395 (cons modestr (c-lang-const c-mode-menu c)))
397 ;; Ugly hack to pull in the definition of `c-populate-syntax-table'
398 ;; from cc-langs to make it available at runtime. It's either this or
399 ;; moving the definition for it to cc-defs, but that would mean to
400 ;; break up the syntax table setup over two files.
401 (defalias 'c-populate-syntax-table
402 (cc-eval-when-compile
403 (let ((f (symbol-function 'c-populate-syntax-table)))
404 (if (byte-code-function-p f) f (byte-compile f)))))
406 ;; CAUTION: Try to avoid installing things on
407 ;; `before-change-functions'. The macro `combine-after-change-calls'
408 ;; is used and it doesn't work if there are things on that hook. That
409 ;; can cause font lock functions to run in inconvenient places during
410 ;; temporary changes in some font lock support modes, causing extra
411 ;; unnecessary work and font lock glitches due to interactions between
412 ;; various text properties.
414 (defun c-after-change (beg end len)
415 ;; Function put on `after-change-functions' to adjust various caches
416 ;; etc. Prefer speed to finesse here, since there will be an order
417 ;; of magnitude more calls to this function than any of the
418 ;; functions that use the caches.
420 ;; Note that care must be taken so that this is called before any
421 ;; font-lock callbacks since we might get calls to functions using
422 ;; these caches from inside them, and we must thus be sure that this
423 ;; has already been executed.
425 (c-save-buffer-state ()
426 ;; When `combine-after-change-calls' is used we might get calls
427 ;; with regions outside the current narrowing. This has been
428 ;; observed in Emacs 20.7.
430 (save-match-data ; c-recognize-<>-arglists changes match-data
433 (when (> end (point-max))
434 ;; Some emacsen might return positions past the end. This has been
435 ;; observed in Emacs 20.7 when rereading a buffer changed on disk
436 ;; (haven't been able to minimize it, but Emacs 21.3 appears to
438 (setq end (point-max))
442 (c-invalidate-sws-region-after beg end)
443 (c-invalidate-state-cache beg)
444 (c-invalidate-find-decl-cache beg)
446 (when c-recognize-<>-arglists
447 (c-after-change-check-<>-operators beg end))))))
449 (defun c-basic-common-init (mode default-style)
450 "Do the necessary initialization for the syntax handling routines
451 and the line breaking/filling code. Intended to be used by other
452 packages that embed CC Mode.
454 MODE is the CC Mode flavor to set up, e.g. 'c-mode or 'java-mode.
455 DEFAULT-STYLE tells which indentation style to install. It has the
456 same format as `c-default-style'.
458 Note that `c-init-language-vars' must be called before this function.
459 This function cannot do that since `c-init-language-vars' is a macro
460 that requires a literal mode spec at compile time."
462 (setq c-buffer-is-cc-mode mode)
464 ;; these variables should always be buffer local; they do not affect
465 ;; indentation style.
466 (make-local-variable 'parse-sexp-ignore-comments)
467 (make-local-variable 'indent-line-function)
468 (make-local-variable 'indent-region-function)
469 (make-local-variable 'normal-auto-fill-function)
470 (make-local-variable 'comment-start)
471 (make-local-variable 'comment-end)
472 (make-local-variable 'comment-start-skip)
473 (make-local-variable 'comment-multi-line)
474 (make-local-variable 'comment-line-break-function)
475 (make-local-variable 'paragraph-start)
476 (make-local-variable 'paragraph-separate)
477 (make-local-variable 'paragraph-ignore-fill-prefix)
478 (make-local-variable 'adaptive-fill-mode)
479 (make-local-variable 'adaptive-fill-regexp)
481 ;; now set their values
482 (setq parse-sexp-ignore-comments t
483 indent-line-function 'c-indent-line
484 indent-region-function 'c-indent-region
485 normal-auto-fill-function 'c-do-auto-fill
487 comment-line-break-function 'c-indent-new-comment-line)
489 ;; Install `c-fill-paragraph' on `fill-paragraph-function' so that a
490 ;; direct call to `fill-paragraph' behaves better. This still
491 ;; doesn't work with filladapt but it's better than nothing.
492 (make-local-variable 'fill-paragraph-function)
493 (setq fill-paragraph-function 'c-fill-paragraph)
495 (when (or c-recognize-<>-arglists
496 (c-major-mode-is 'awk-mode))
497 ;; We'll use the syntax-table text property to change the syntax
498 ;; of some chars for this language, so do the necessary setup for
501 ;; Note to other package developers: It's ok to turn this on in CC
502 ;; Mode buffers when CC Mode doesn't, but it's not ok to turn it
503 ;; off if CC Mode has turned it on.
506 (when (boundp 'parse-sexp-lookup-properties)
507 (make-local-variable 'parse-sexp-lookup-properties)
508 (setq parse-sexp-lookup-properties t))
510 ;; Same as above for XEmacs.
511 (when (boundp 'lookup-syntax-properties)
512 (make-local-variable 'lookup-syntax-properties)
513 (setq lookup-syntax-properties t)))
515 ;; Use this in Emacs 21 to avoid meddling with the rear-nonsticky
516 ;; property on each character.
517 (when (boundp 'text-property-default-nonsticky)
518 (make-local-variable 'text-property-default-nonsticky)
519 (let ((elem (assq 'syntax-table text-property-default-nonsticky)))
522 (setq text-property-default-nonsticky
523 (cons '(syntax-table . t)
524 text-property-default-nonsticky))))
525 (setq text-property-default-nonsticky
527 text-property-default-nonsticky)))
529 ;; In Emacs 21 and later it's possible to turn off the ad-hoc
530 ;; heuristic that open parens in column 0 are defun starters. Since
531 ;; we have c-state-cache, that heuristic isn't useful and only causes
532 ;; trouble, so turn it off.
533 (when (memq 'col-0-paren c-emacs-features)
534 (make-local-variable 'open-paren-in-column-0-is-defun-start)
535 (setq open-paren-in-column-0-is-defun-start nil))
537 (c-clear-found-types)
539 ;; now set the mode style based on default-style
540 (let ((style (if (stringp default-style)
542 (or (cdr (assq mode default-style))
543 (cdr (assq 'other default-style))
545 ;; Override style variables if `c-old-style-variable-behavior' is
546 ;; set. Also override if we are using global style variables,
547 ;; have already initialized a style once, and are switching to a
548 ;; different style. (It's doubtful whether this is desirable, but
549 ;; the whole situation with nonlocal style variables is a bit
550 ;; awkward. It's at least the most compatible way with the old
551 ;; style init procedure.)
552 (c-set-style style (not (or c-old-style-variable-behavior
553 (and (not c-style-variables-are-local-p)
555 (not (string-equal c-indentation-style
557 (c-setup-paragraph-variables)
559 ;; we have to do something special for c-offsets-alist so that the
560 ;; buffer local value has its own alist structure.
561 (setq c-offsets-alist (copy-alist c-offsets-alist))
563 ;; setup the comment indent variable in a Emacs version portable way
564 (make-local-variable 'comment-indent-function)
565 (setq comment-indent-function 'c-comment-indent)
567 ;; ;; Put submode indicators onto minor-mode-alist, but only once.
568 ;; (or (assq 'c-submode-indicators minor-mode-alist)
569 ;; (setq minor-mode-alist
570 ;; (cons '(c-submode-indicators c-submode-indicators)
571 ;; minor-mode-alist)))
574 ;; Install the functions that ensure that various internal caches
575 ;; don't become invalid due to buffer changes.
576 (make-local-hook 'after-change-functions)
577 (add-hook 'after-change-functions 'c-after-change nil t))
579 (defun c-after-font-lock-init ()
580 ;; Put on `font-lock-mode-hook'.
581 (remove-hook 'after-change-functions 'c-after-change t)
582 (add-hook 'after-change-functions 'c-after-change nil t))
584 (defun c-font-lock-init ()
585 "Set up the font-lock variables for using the font-lock support in CC Mode.
586 This does not load the font-lock package. Use after
587 `c-basic-common-init' and after cc-fonts has been loaded."
589 (make-local-variable 'font-lock-defaults)
590 (setq font-lock-defaults
591 `(,(if (c-major-mode-is 'awk-mode)
592 ;; awk-mode currently has only one font lock level.
593 'awk-font-lock-keywords
594 (mapcar 'c-mode-symbol
595 '("font-lock-keywords" "font-lock-keywords-1"
596 "font-lock-keywords-2" "font-lock-keywords-3")))
598 ,c-identifier-syntax-modifications
599 c-beginning-of-syntax
600 (font-lock-lines-before . 1)
601 (font-lock-mark-block-function
604 (make-local-hook 'font-lock-mode-hook)
605 (add-hook 'font-lock-mode-hook 'c-after-font-lock-init nil t))
607 (defun c-setup-doc-comment-style ()
608 "Initialize the variables that depend on the value of `c-doc-comment-style'."
609 (when (and (featurep 'font-lock)
610 (symbol-value 'font-lock-mode))
611 ;; Force font lock mode to reinitialize itself.
615 (defun c-common-init (&optional mode)
616 "Common initialization for all CC Mode modes.
617 In addition to the work done by `c-basic-common-init' and
618 `c-font-lock-init', this function sets up various other things as
619 customary in CC Mode modes but which aren't strictly necessary for CC
620 Mode to operate correctly.
622 MODE is the symbol for the mode to initialize, like 'c-mode. See
623 `c-basic-common-init' for details. It's only optional to be
624 compatible with old code; callers should always specify it."
627 ;; Called from an old third party package. The fallback is to
629 (c-init-language-vars-for 'c-mode))
631 (c-basic-common-init mode c-default-style)
633 ;; Only initialize font locking if we aren't called from an old package.
636 (make-local-variable 'outline-regexp)
637 (make-local-variable 'outline-level)
638 (setq outline-regexp "[^#\n\^M]"
639 outline-level 'c-outline-level)
641 (let ((rfn (assq mode c-require-final-newline)))
643 (make-local-variable 'require-final-newline)
645 (setq require-final-newline mode-require-final-newline)))))
647 (defun c-remove-any-local-eval-or-mode-variables ()
648 ;; If the buffer specifies `mode' or `eval' in its File Local Variable list
649 ;; or on the first line, remove all occurrences. See
650 ;; `c-postprocess-file-styles' for justification. There is no need to save
651 ;; point here, or even bother too much about the buffer contents.
653 ;; Most of the code here is derived from Emacs 21.3's `hack-local-variables'
655 (goto-char (point-max))
656 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move)
657 (let (lv-point (prefix "") (suffix ""))
658 (when (let ((case-fold-search t))
659 (search-forward "Local Variables:" nil t))
660 (setq lv-point (point))
661 ;; The prefix is what comes before "local variables:" in its line.
662 ;; The suffix is what comes after "local variables:" in its line.
663 (skip-chars-forward " \t")
665 (setq suffix (buffer-substring (point)
666 (progn (end-of-line) (point)))))
667 (goto-char (match-beginning 0))
670 (buffer-substring (point)
671 (progn (beginning-of-line) (point)))))
673 (while (search-forward-regexp
675 (regexp-quote prefix)
676 "\\(mode\\|eval\\):.*"
677 (regexp-quote suffix)
683 ;; Delete the first line, if we've got one, in case it contains a mode spec.
684 (unless (and lv-point
685 (progn (goto-char lv-point)
688 (goto-char (point-min))
692 (defun c-postprocess-file-styles ()
693 "Function that post processes relevant file local variables in CC Mode.
694 Currently, this function simply applies any style and offset settings
695 found in the file's Local Variable list. It first applies any style
696 setting found in `c-file-style', then it applies any offset settings
697 it finds in `c-file-offsets'.
699 Note that the style variables are always made local to the buffer."
701 ;; apply file styles and offsets
702 (when c-buffer-is-cc-mode
703 (if (or c-file-style c-file-offsets)
704 (c-make-styles-buffer-local t))
706 (c-set-style c-file-style))
710 (let ((langelem (car langentry))
711 (offset (cdr langentry)))
712 (c-set-offset langelem offset)))
714 ;; Problem: The file local variable block might have explicitly set a
715 ;; style variable. The `c-set-style' or `mapcar' call might have
716 ;; overwritten this. So we run `hack-local-variables' again to remedy
717 ;; this. There are no guarantees this will work properly, particularly as
718 ;; we have no control over what the other hook functions on
719 ;; `hack-local-variables-hook' would have done. We now (2006/2/1) remove
720 ;; any `eval' or `mode' expressions before we evaluate again (see below).
723 ;; Problem (bug reported by Gustav Broberg): if one of the variables is
724 ;; `mode', this will invoke c-mode (etc.) again, setting up the style etc.
725 ;; We prevent this by temporarily removing `mode' from the Local Variables
727 (if (or c-file-style c-file-offsets)
728 (c-tentative-buffer-changes
729 (let ((hack-local-variables-hook nil))
730 (c-remove-any-local-eval-or-mode-variables)
731 (hack-local-variables))
734 (add-hook 'hack-local-variables-hook 'c-postprocess-file-styles)
736 (defmacro c-run-mode-hooks (&rest hooks)
737 ;; Emacs 21.1 has introduced a system with delayed mode hooks that
738 ;; require the use of the new function `run-mode-hooks'.
739 (if (cc-bytecomp-fboundp 'run-mode-hooks)
740 `(run-mode-hooks ,@hooks)
741 `(progn ,@(mapcar (lambda (hook) `(run-hooks ,hook)) hooks))))
747 (defvar c-mode-syntax-table nil
748 "Syntax table used in c-mode buffers.")
749 (or c-mode-syntax-table
750 (setq c-mode-syntax-table
751 (funcall (c-lang-const c-make-mode-syntax-table c))))
753 (defvar c-mode-abbrev-table nil
754 "Abbreviation table used in c-mode buffers.")
755 (c-define-abbrev-table 'c-mode-abbrev-table
756 '(("else" "else" c-electric-continued-statement 0)
757 ("while" "while" c-electric-continued-statement 0)))
759 (defvar c-mode-map ()
760 "Keymap used in c-mode buffers.")
763 (setq c-mode-map (c-make-inherited-keymap))
764 ;; add bindings which are only useful for C
765 (define-key c-mode-map "\C-c\C-e" 'c-macro-expand)
768 (easy-menu-define c-c-menu c-mode-map "C Mode Commands"
769 (cons "C" (c-lang-const c-mode-menu c)))
771 ;; In XEmacs >= 21.5 modes should add their own entries to
772 ;; `auto-mode-alist'. The comment form of autoload is used to avoid
773 ;; doing this on load. That since `add-to-list' prepends the value
774 ;; which could cause it to clobber user settings. Later emacsen have
775 ;; an append option, but it's not safe to use.
777 ;; The the extension ".C" is associated to C++ while the lowercase
778 ;; variant goes to C. On case insensitive file systems, this means
779 ;; that ".c" files also might open C++ mode if the C++ entry comes
780 ;; first on `auto-mode-alist'. Thus we try to ensure that ".C" comes
781 ;; after ".c", and since `add-to-list' adds the entry first we have to
782 ;; add the ".C" entry first.
783 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.\\(cc\\|hh\\)\\'" . c++-mode))
784 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.[ch]\\(pp\\|xx\\|\\+\\+\\)\\'" . c++-mode))
785 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.\\(CC?\\|HH?\\)\\'" . c++-mode))
787 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.[ch]\\'" . c-mode))
789 ;; NB: The following two associate yacc and lex files to C Mode, which
790 ;; is not really suitable for those formats. Anyway, afaik there's
791 ;; currently no better mode for them, and besides this is legacy.
792 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.y\\(acc\\)?\\'" . c-mode))
793 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.lex\\'" . c-mode))
797 "Major mode for editing K&R and ANSI C code.
798 To submit a problem report, enter `\\[c-submit-bug-report]' from a
799 c-mode buffer. This automatically sets up a mail buffer with version
800 information already added. You just need to add a description of the
801 problem, including a reproducible test case, and send the message.
803 To see what version of CC Mode you are running, enter `\\[c-version]'.
805 The hook `c-mode-common-hook' is run with no args at mode
806 initialization, then `c-mode-hook'.
811 (kill-all-local-variables)
812 (c-initialize-cc-mode t)
813 (set-syntax-table c-mode-syntax-table)
814 (setq major-mode 'c-mode
816 local-abbrev-table c-mode-abbrev-table
818 (use-local-map c-mode-map)
819 (c-init-language-vars-for 'c-mode)
820 (c-common-init 'c-mode)
821 (easy-menu-add c-c-menu)
822 (cc-imenu-init cc-imenu-c-generic-expression)
823 (c-run-mode-hooks 'c-mode-common-hook 'c-mode-hook)
830 (defvar c++-mode-syntax-table nil
831 "Syntax table used in c++-mode buffers.")
832 (or c++-mode-syntax-table
833 (setq c++-mode-syntax-table
834 (funcall (c-lang-const c-make-mode-syntax-table c++))))
836 (defvar c++-mode-abbrev-table nil
837 "Abbreviation table used in c++-mode buffers.")
838 (c-define-abbrev-table 'c++-mode-abbrev-table
839 '(("else" "else" c-electric-continued-statement 0)
840 ("while" "while" c-electric-continued-statement 0)
841 ("catch" "catch" c-electric-continued-statement 0)))
843 (defvar c++-mode-map ()
844 "Keymap used in c++-mode buffers.")
847 (setq c++-mode-map (c-make-inherited-keymap))
848 ;; add bindings which are only useful for C++
849 (define-key c++-mode-map "\C-c\C-e" 'c-macro-expand)
850 (define-key c++-mode-map "\C-c:" 'c-scope-operator)
851 (define-key c++-mode-map "<" 'c-electric-lt-gt)
852 (define-key c++-mode-map ">" 'c-electric-lt-gt))
854 (easy-menu-define c-c++-menu c++-mode-map "C++ Mode Commands"
855 (cons "C++" (c-lang-const c-mode-menu c++)))
859 "Major mode for editing C++ code.
860 To submit a problem report, enter `\\[c-submit-bug-report]' from a
861 c++-mode buffer. This automatically sets up a mail buffer with
862 version information already added. You just need to add a description
863 of the problem, including a reproducible test case, and send the
866 To see what version of CC Mode you are running, enter `\\[c-version]'.
868 The hook `c-mode-common-hook' is run with no args at mode
869 initialization, then `c++-mode-hook'.
874 (kill-all-local-variables)
875 (c-initialize-cc-mode t)
876 (set-syntax-table c++-mode-syntax-table)
877 (setq major-mode 'c++-mode
879 local-abbrev-table c++-mode-abbrev-table
881 (use-local-map c++-mode-map)
882 (c-init-language-vars-for 'c++-mode)
883 (c-common-init 'c++-mode)
884 (easy-menu-add c-c++-menu)
885 (cc-imenu-init cc-imenu-c++-generic-expression)
886 (c-run-mode-hooks 'c-mode-common-hook 'c++-mode-hook)
890 ;; Support for Objective-C
893 (defvar objc-mode-syntax-table nil
894 "Syntax table used in objc-mode buffers.")
895 (or objc-mode-syntax-table
896 (setq objc-mode-syntax-table
897 (funcall (c-lang-const c-make-mode-syntax-table objc))))
899 (defvar objc-mode-abbrev-table nil
900 "Abbreviation table used in objc-mode buffers.")
901 (c-define-abbrev-table 'objc-mode-abbrev-table
902 '(("else" "else" c-electric-continued-statement 0)
903 ("while" "while" c-electric-continued-statement 0)))
905 (defvar objc-mode-map ()
906 "Keymap used in objc-mode buffers.")
909 (setq objc-mode-map (c-make-inherited-keymap))
910 ;; add bindings which are only useful for Objective-C
911 (define-key objc-mode-map "\C-c\C-e" 'c-macro-expand))
913 (easy-menu-define c-objc-menu objc-mode-map "ObjC Mode Commands"
914 (cons "ObjC" (c-lang-const c-mode-menu objc)))
916 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.m\\'" . objc-mode))
920 "Major mode for editing Objective C code.
921 To submit a problem report, enter `\\[c-submit-bug-report]' from an
922 objc-mode buffer. This automatically sets up a mail buffer with
923 version information already added. You just need to add a description
924 of the problem, including a reproducible test case, and send the
927 To see what version of CC Mode you are running, enter `\\[c-version]'.
929 The hook `c-mode-common-hook' is run with no args at mode
930 initialization, then `objc-mode-hook'.
935 (kill-all-local-variables)
936 (c-initialize-cc-mode t)
937 (set-syntax-table objc-mode-syntax-table)
938 (setq major-mode 'objc-mode
940 local-abbrev-table objc-mode-abbrev-table
942 (use-local-map objc-mode-map)
943 (c-init-language-vars-for 'objc-mode)
944 (c-common-init 'objc-mode)
945 (easy-menu-add c-objc-menu)
946 (cc-imenu-init nil 'cc-imenu-objc-function)
947 (c-run-mode-hooks 'c-mode-common-hook 'objc-mode-hook)
954 (defvar java-mode-syntax-table nil
955 "Syntax table used in java-mode buffers.")
956 (or java-mode-syntax-table
957 (setq java-mode-syntax-table
958 (funcall (c-lang-const c-make-mode-syntax-table java))))
960 (defvar java-mode-abbrev-table nil
961 "Abbreviation table used in java-mode buffers.")
962 (c-define-abbrev-table 'java-mode-abbrev-table
963 '(("else" "else" c-electric-continued-statement 0)
964 ("while" "while" c-electric-continued-statement 0)
965 ("catch" "catch" c-electric-continued-statement 0)
966 ("finally" "finally" c-electric-continued-statement 0)))
968 (defvar java-mode-map ()
969 "Keymap used in java-mode buffers.")
972 (setq java-mode-map (c-make-inherited-keymap))
973 ;; add bindings which are only useful for Java
976 ;; Regexp trying to describe the beginning of a Java top-level
977 ;; definition. This is not used by CC Mode, nor is it maintained
978 ;; since it's practically impossible to write a regexp that reliably
979 ;; matches such a construct. Other tools are necessary.
980 (defconst c-Java-defun-prompt-regexp
981 "^[ \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-*")
983 (easy-menu-define c-java-menu java-mode-map "Java Mode Commands"
984 (cons "Java" (c-lang-const c-mode-menu java)))
986 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.java\\'" . java-mode))
990 "Major mode for editing Java code.
991 To submit a problem report, enter `\\[c-submit-bug-report]' from a
992 java-mode buffer. This automatically sets up a mail buffer with
993 version information already added. You just need to add a description
994 of the problem, including a reproducible test case, and send the
997 To see what version of CC Mode you are running, enter `\\[c-version]'.
999 The hook `c-mode-common-hook' is run with no args at mode
1000 initialization, then `java-mode-hook'.
1005 (kill-all-local-variables)
1006 (c-initialize-cc-mode t)
1007 (set-syntax-table java-mode-syntax-table)
1008 (setq major-mode 'java-mode
1010 local-abbrev-table java-mode-abbrev-table
1012 (use-local-map java-mode-map)
1013 (c-init-language-vars-for 'java-mode)
1014 (c-common-init 'java-mode)
1015 (easy-menu-add c-java-menu)
1016 (cc-imenu-init cc-imenu-java-generic-expression)
1017 (c-run-mode-hooks 'c-mode-common-hook 'java-mode-hook)
1018 (c-update-modeline))
1021 ;; Support for CORBA's IDL language
1024 (defvar idl-mode-syntax-table nil
1025 "Syntax table used in idl-mode buffers.")
1026 (or idl-mode-syntax-table
1027 (setq idl-mode-syntax-table
1028 (funcall (c-lang-const c-make-mode-syntax-table idl))))
1030 (defvar idl-mode-abbrev-table nil
1031 "Abbreviation table used in idl-mode buffers.")
1032 (c-define-abbrev-table 'idl-mode-abbrev-table nil)
1034 (defvar idl-mode-map ()
1035 "Keymap used in idl-mode buffers.")
1038 (setq idl-mode-map (c-make-inherited-keymap))
1039 ;; add bindings which are only useful for IDL
1042 (easy-menu-define c-idl-menu idl-mode-map "IDL Mode Commands"
1043 (cons "IDL" (c-lang-const c-mode-menu idl)))
1045 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.idl\\'" . idl-mode))
1049 "Major mode for editing CORBA's IDL, PSDL and CIDL code.
1050 To submit a problem report, enter `\\[c-submit-bug-report]' from an
1051 idl-mode buffer. This automatically sets up a mail buffer with
1052 version information already added. You just need to add a description
1053 of the problem, including a reproducible test case, and send the
1056 To see what version of CC Mode you are running, enter `\\[c-version]'.
1058 The hook `c-mode-common-hook' is run with no args at mode
1059 initialization, then `idl-mode-hook'.
1064 (kill-all-local-variables)
1065 (c-initialize-cc-mode t)
1066 (set-syntax-table idl-mode-syntax-table)
1067 (setq major-mode 'idl-mode
1069 local-abbrev-table idl-mode-abbrev-table)
1070 (use-local-map idl-mode-map)
1071 (c-init-language-vars-for 'idl-mode)
1072 (c-common-init 'idl-mode)
1073 (easy-menu-add c-idl-menu)
1074 ;;(cc-imenu-init cc-imenu-idl-generic-expression) ;TODO
1075 (c-run-mode-hooks 'c-mode-common-hook 'idl-mode-hook)
1076 (c-update-modeline))
1082 (defvar pike-mode-syntax-table nil
1083 "Syntax table used in pike-mode buffers.")
1084 (or pike-mode-syntax-table
1085 (setq pike-mode-syntax-table
1086 (funcall (c-lang-const c-make-mode-syntax-table pike))))
1088 (defvar pike-mode-abbrev-table nil
1089 "Abbreviation table used in pike-mode buffers.")
1090 (c-define-abbrev-table 'pike-mode-abbrev-table
1091 '(("else" "else" c-electric-continued-statement 0)
1092 ("while" "while" c-electric-continued-statement 0)))
1094 (defvar pike-mode-map ()
1095 "Keymap used in pike-mode buffers.")
1098 (setq pike-mode-map (c-make-inherited-keymap))
1099 ;; additional bindings
1100 (define-key pike-mode-map "\C-c\C-e" 'c-macro-expand))
1102 (easy-menu-define c-pike-menu pike-mode-map "Pike Mode Commands"
1103 (cons "Pike" (c-lang-const c-mode-menu pike)))
1105 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.\\(u?lpc\\|pike\\|pmod\\(.in\\)?\\)\\'" . pike-mode))
1106 ;;;###autoload (add-to-list 'interpreter-mode-alist '("pike" . pike-mode))
1110 "Major mode for editing Pike code.
1111 To submit a problem report, enter `\\[c-submit-bug-report]' from a
1112 pike-mode buffer. This automatically sets up a mail buffer with
1113 version information already added. You just need to add a description
1114 of the problem, including a reproducible test case, and send the
1117 To see what version of CC Mode you are running, enter `\\[c-version]'.
1119 The hook `c-mode-common-hook' is run with no args at mode
1120 initialization, then `pike-mode-hook'.
1125 (kill-all-local-variables)
1126 (c-initialize-cc-mode t)
1127 (set-syntax-table pike-mode-syntax-table)
1128 (setq major-mode 'pike-mode
1130 local-abbrev-table pike-mode-abbrev-table
1132 (use-local-map pike-mode-map)
1133 (c-init-language-vars-for 'pike-mode)
1134 (c-common-init 'pike-mode)
1135 (easy-menu-add c-pike-menu)
1136 ;;(cc-imenu-init cc-imenu-pike-generic-expression) ;TODO
1137 (c-run-mode-hooks 'c-mode-common-hook 'pike-mode-hook)
1138 (c-update-modeline))
1143 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.awk\\'" . awk-mode))
1144 ;;;###autoload (add-to-list 'interpreter-mode-alist '("awk" . awk-mode))
1145 ;;;###autoload (add-to-list 'interpreter-mode-alist '("mawk" . awk-mode))
1146 ;;;###autoload (add-to-list 'interpreter-mode-alist '("nawk" . awk-mode))
1147 ;;;###autoload (add-to-list 'interpreter-mode-alist '("gawk" . awk-mode))
1149 ;;; Autoload directives must be on the top level, so we construct an
1150 ;;; autoload form instead.
1151 ;;;###autoload (autoload 'awk-mode "cc-mode" "Major mode for editing AWK code." t)
1153 (defvar awk-mode-abbrev-table nil
1154 "Abbreviation table used in awk-mode buffers.")
1155 (c-define-abbrev-table 'awk-mode-abbrev-table
1156 '(("else" "else" c-electric-continued-statement 0)
1157 ("while" "while" c-electric-continued-statement 0)))
1159 (defvar awk-mode-map ()
1160 "Keymap used in awk-mode buffers.")
1163 (setq awk-mode-map (c-make-inherited-keymap))
1164 ;; add bindings which are only useful for awk.
1165 (define-key awk-mode-map "#" 'self-insert-command)
1166 (define-key awk-mode-map "/" 'self-insert-command)
1167 (define-key awk-mode-map "*" 'self-insert-command)
1168 (define-key awk-mode-map "\C-c\C-n" 'undefined) ; #if doesn't exist in awk.
1169 (define-key awk-mode-map "\C-c\C-p" 'undefined)
1170 (define-key awk-mode-map "\C-c\C-u" 'undefined)
1171 (define-key awk-mode-map "\M-a" 'c-beginning-of-statement) ; 2003/10/7
1172 (define-key awk-mode-map "\M-e" 'c-end-of-statement) ; 2003/10/7
1173 (define-key awk-mode-map "\C-\M-a" 'c-awk-beginning-of-defun)
1174 (define-key awk-mode-map "\C-\M-e" 'c-awk-end-of-defun))
1176 (easy-menu-define c-awk-menu awk-mode-map "AWK Mode Commands"
1177 (cons "AWK" (c-lang-const c-mode-menu awk)))
1180 "Major mode for editing AWK code.
1181 To submit a problem report, enter `\\[c-submit-bug-report]' from an
1182 awk-mode buffer. This automatically sets up a mail buffer with version
1183 information already added. You just need to add a description of the
1184 problem, including a reproducible test case, and send the message.
1186 To see what version of CC Mode you are running, enter `\\[c-version]'.
1188 The hook `c-mode-common-hook' is run with no args at mode
1189 initialization, then `awk-mode-hook'.
1194 (require 'cc-awk) ; Added 2003/6/10.
1195 (kill-all-local-variables)
1196 (c-initialize-cc-mode t)
1197 (set-syntax-table awk-mode-syntax-table)
1198 (setq major-mode 'awk-mode
1200 local-abbrev-table awk-mode-abbrev-table
1202 (use-local-map awk-mode-map)
1203 (c-init-language-vars-for 'awk-mode)
1204 (c-common-init 'awk-mode)
1205 ;; The rest of CC Mode does not (yet) use `font-lock-syntactic-keywords',
1206 ;; so it's not set by `c-font-lock-init'.
1207 (make-local-variable 'font-lock-syntactic-keywords)
1208 (setq font-lock-syntactic-keywords
1209 '((c-awk-set-syntax-table-properties
1210 0 (0) ; Everything on this line is a dummy.
1212 (c-awk-unstick-NL-prop)
1213 (add-hook 'before-change-functions 'c-awk-before-change nil t)
1214 (add-hook 'after-change-functions 'c-awk-after-change nil t)
1215 (c-save-buffer-state nil
1218 (c-awk-clear-NL-props (point-min) (point-max))
1219 (c-awk-after-change (point-min) (point-max) 0))) ; Set syntax-table props.
1221 ;; Prevent Xemacs's buffer-syntactic-context being used. See the comment
1222 ;; in cc-engine.el, just before (defun c-fast-in-literal ...
1223 (defalias 'c-in-literal 'c-slow-in-literal)
1225 (c-run-mode-hooks 'c-mode-common-hook 'awk-mode-hook)
1226 (c-update-modeline))
1231 (defconst c-mode-help-address
1232 "bug-cc-mode@gnu.org"
1233 "Address(es) for CC Mode bug reports.")
1236 "Echo the current version of CC Mode in the minibuffer."
1238 (message "Using CC Mode version %s" c-version)
1239 (c-keep-region-active))
1241 (defvar c-prepare-bug-report-hooks nil)
1243 ;; Dynamic variables used by reporter.
1244 (defvar reporter-prompt-for-summary-p)
1245 (defvar reporter-dont-compact-list)
1247 (defun c-submit-bug-report ()
1248 "Submit via mail a bug report on CC Mode."
1252 (let ((reporter-prompt-for-summary-p t)
1253 (reporter-dont-compact-list '(c-offsets-alist))
1254 (style c-indentation-style)
1255 (c-features c-emacs-features))
1257 (if (y-or-n-p "Do you want to submit a report on CC Mode? ")
1259 (reporter-submit-bug-report
1261 (concat "CC Mode " c-version " (" mode-name ")")
1264 '(c-buffer-is-cc-mode
1266 c-syntactic-indentation
1267 c-syntactic-indentation-in-macros
1269 c-auto-align-backslashes
1270 c-backspace-function
1272 c-electric-pound-behavior
1274 c-enable-xemacs-performance-kludge-p
1275 c-old-style-variable-behavior
1279 parse-sexp-ignore-comments
1280 parse-sexp-lookup-properties
1281 lookup-syntax-properties
1282 ;; A brain-damaged XEmacs only variable that, if
1283 ;; set to nil can cause all kinds of chaos.
1284 signal-error-on-buffer-boundary
1285 ;; Variables that affect line breaking and comments.
1295 adaptive-fill-regexp)
1297 (mapcar (lambda (var) (unless (boundp var)
1298 (setq vars (delq var vars))))
1299 '(signal-error-on-buffer-boundary
1303 font-lock-maximum-decoration
1304 parse-sexp-lookup-properties
1305 lookup-syntax-properties))
1308 (run-hooks 'c-prepare-bug-report-hooks)
1309 (insert (format "Buffer Style: %s\nc-emacs-features: %s\n"
1310 style c-features)))))))
1313 (cc-provide 'cc-mode)
1315 ;;; arch-tag: 7825e5c4-fd09-439f-a04d-4c13208ba3d7
1316 ;;; cc-mode.el ends here