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"
118 '(require 'cc-fonts
))
120 ;; cc-langs isn't loaded when we're byte compiled, so add autoload
121 ;; directives for the interface functions.
122 (autoload 'c-make-init-lang-vars-fun
"cc-langs")
123 (autoload 'c-init-language-vars
"cc-langs" nil nil
'macro
)
126 ;; Other modes and packages which depend on CC Mode should do the
127 ;; following to make sure everything is loaded and available for their
130 ;; (require 'cc-mode)
132 ;; And in the major mode function:
134 ;; (c-initialize-cc-mode t)
135 ;; (c-init-language-vars some-mode)
136 ;; (c-common-init 'some-mode) ; Or perhaps (c-basic-common-init 'some-mode)
138 ;; If you're not writing a derived mode using the language variable
139 ;; system, then some-mode is one of the language modes directly
140 ;; supported by CC Mode. You can then use (c-init-language-vars-for
141 ;; 'some-mode) instead of `c-init-language-vars'.
142 ;; `c-init-language-vars-for' is a function that avoids the rather
143 ;; large expansion of `c-init-language-vars'.
145 ;; If you use `c-basic-common-init' then you might want to call
146 ;; `c-font-lock-init' too to set up CC Mode's font lock support.
148 ;; See cc-langs.el for further info. A small example of a derived mode
149 ;; is also available at <http://cc-mode.sourceforge.net/
150 ;; derived-mode-ex.el>.
152 (defun c-leave-cc-mode-mode ()
153 (setq c-buffer-is-cc-mode nil
))
155 (defun c-init-language-vars-for (mode)
156 "Initialize the language variables for one of the language modes
157 directly supported by CC Mode. This can be used instead of the
158 `c-init-language-vars' macro if the language you want to use is one of
159 those, rather than a derived language defined through the language
160 variable system (see \"cc-langs.el\")."
161 (cond ((eq mode
'c-mode
) (c-init-language-vars c-mode
))
162 ((eq mode
'c
++-mode
) (c-init-language-vars c
++-mode
))
163 ((eq mode
'objc-mode
) (c-init-language-vars objc-mode
))
164 ((eq mode
'java-mode
) (c-init-language-vars java-mode
))
165 ((eq mode
'idl-mode
) (c-init-language-vars idl-mode
))
166 ((eq mode
'pike-mode
) (c-init-language-vars pike-mode
))
167 ((eq mode
'awk-mode
) (c-init-language-vars awk-mode
))
168 (t (error "Unsupported mode %s" mode
))))
171 (defun c-initialize-cc-mode (&optional new-style-init
)
172 "Initialize CC Mode for use in the current buffer.
173 If the optional NEW-STYLE-INIT is nil or left out then all necessary
174 initialization to run CC Mode for the C language is done. Otherwise
175 only some basic setup is done, and a call to `c-init-language-vars' or
176 `c-init-language-vars-for' is necessary too (which gives more
177 control). See \"cc-mode.el\" for more info."
179 (setq c-buffer-is-cc-mode t
)
181 (let ((initprop 'cc-mode-is-initialized
)
183 (unless (get 'c-initialize-cc-mode initprop
)
186 (put 'c-initialize-cc-mode initprop t
)
187 (c-initialize-builtin-style)
188 (run-hooks 'c-initialization-hook
)
189 ;; Fix obsolete variables.
190 (if (boundp 'c-comment-continuation-stars
)
191 (setq c-block-comment-prefix c-comment-continuation-stars
))
192 (add-hook 'change-major-mode-hook
'c-leave-cc-mode-mode
)
193 (setq c-initialization-ok t
))
194 ;; Will try initialization hooks again if they failed.
195 (put 'c-initialize-cc-mode initprop c-initialization-ok
))))
197 (unless new-style-init
198 (c-init-language-vars-for 'c-mode
)))
203 (defvar c-mode-base-map
()
204 "Keymap shared by all CC Mode related modes.")
206 (defun c-make-inherited-keymap ()
207 (let ((map (make-sparse-keymap)))
208 ;; Necessary to use `cc-bytecomp-fboundp' below since this
209 ;; function is called from top-level forms that are evaluated
210 ;; while cc-bytecomp is active when one does M-x eval-buffer.
213 ((cc-bytecomp-fboundp 'set-keymap-parents
)
214 (set-keymap-parents map c-mode-base-map
))
216 ((cc-bytecomp-fboundp 'set-keymap-parent
)
217 (set-keymap-parent map c-mode-base-map
))
219 (t (error "CC Mode is incompatible with this version of Emacs")))
222 (defun c-define-abbrev-table (name defs
)
223 ;; Compatibility wrapper for `define-abbrev' which passes a non-nil
224 ;; sixth argument for SYSTEM-FLAG in emacsen that support it
225 ;; (currently only Emacs >= 21.2).
226 (let ((table (or (symbol-value name
)
227 (progn (define-abbrev-table name nil
)
228 (symbol-value name
)))))
231 (apply 'define-abbrev table
(append (car defs
) '(t)))
232 (wrong-number-of-arguments
233 (apply 'define-abbrev table
(car defs
))))
234 (setq defs
(cdr defs
)))))
235 (put 'c-define-abbrev-table
'lisp-indent-function
1)
237 (defun c-bind-special-erase-keys ()
238 ;; Only used in Emacs to bind C-c C-<delete> and C-c C-<backspace>
239 ;; to the proper keys depending on `normal-erase-is-backspace'.
240 (if normal-erase-is-backspace
242 (define-key c-mode-base-map
(kbd "C-c C-<delete>")
243 'c-hungry-delete-forward
)
244 (define-key c-mode-base-map
(kbd "C-c C-<backspace>")
245 'c-hungry-delete-backwards
))
246 (define-key c-mode-base-map
(kbd "C-c C-<delete>")
247 'c-hungry-delete-backwards
)
248 (define-key c-mode-base-map
(kbd "C-c C-<backspace>")
249 'c-hungry-delete-forward
)))
254 (setq c-mode-base-map
(make-sparse-keymap))
256 ;; Separate M-BS from C-M-h. The former should remain
257 ;; backward-kill-word.
258 (define-key c-mode-base-map
[(control meta h
)] 'c-mark-function
)
259 (define-key c-mode-base-map
"\e\C-q" 'c-indent-exp
)
260 (substitute-key-definition 'backward-sentence
261 'c-beginning-of-statement
262 c-mode-base-map global-map
)
263 (substitute-key-definition 'forward-sentence
265 c-mode-base-map global-map
)
266 (substitute-key-definition 'indent-new-comment-line
267 'c-indent-new-comment-line
268 c-mode-base-map global-map
)
269 (substitute-key-definition 'indent-for-tab-command
271 c-mode-base-map global-map
)
272 (when (fboundp 'comment-indent-new-line
)
273 ;; indent-new-comment-line has changed name to
274 ;; comment-indent-new-line in Emacs 21.
275 (substitute-key-definition 'comment-indent-new-line
276 'c-indent-new-comment-line
277 c-mode-base-map global-map
))
279 ;; RMS says don't make these the default.
280 ;; (define-key c-mode-base-map "\e\C-a" 'c-beginning-of-defun)
281 ;; (define-key c-mode-base-map "\e\C-e" 'c-end-of-defun)
283 (define-key c-mode-base-map
"\C-c\C-n" 'c-forward-conditional
)
284 (define-key c-mode-base-map
"\C-c\C-p" 'c-backward-conditional
)
285 (define-key c-mode-base-map
"\C-c\C-u" 'c-up-conditional
)
287 ;; It doesn't suffice to put `c-fill-paragraph' on
288 ;; `fill-paragraph-function' since `c-fill-paragraph' must be called
289 ;; before any fill prefix adaption is done. E.g. `filladapt-mode'
290 ;; replaces `fill-paragraph' and does the adaption before calling
291 ;; `fill-paragraph-function', and we have to mask comments etc
292 ;; before that. Also, `c-fill-paragraph' chains on to
293 ;; `fill-paragraph' and the value on `fill-parapgraph-function' to
294 ;; do the actual filling work.
295 (substitute-key-definition 'fill-paragraph
'c-fill-paragraph
296 c-mode-base-map global-map
)
297 ;; In XEmacs the default fill function is called
298 ;; fill-paragraph-or-region.
299 (substitute-key-definition 'fill-paragraph-or-region
'c-fill-paragraph
300 c-mode-base-map global-map
)
302 ;; We bind the forward deletion key and (implicitly) C-d to
303 ;; `c-electric-delete-forward', and the backward deletion key to
304 ;; `c-electric-backspace'. The hungry variants are bound to the
305 ;; same keys but prefixed with C-c. This implies that C-c C-d is
306 ;; `c-hungry-delete-forward'. For consistency, we bind not only C-c
307 ;; <backspace> to `c-hungry-delete-backwards' but also
308 ;; C-c C-<backspace>, so that the Ctrl key can be held down during
309 ;; the whole sequence regardless of the direction. This in turn
310 ;; implies that we bind C-c C-<delete> to `c-hungry-delete-forward',
311 ;; for the same reason.
313 ;; Bind the electric deletion functions to C-d and DEL. Emacs 21
314 ;; automatically maps the [delete] and [backspace] keys to these two
315 ;; depending on window system and user preferences. (In earlier
316 ;; versions it's possible to do the same by using `function-key-map'.)
317 (define-key c-mode-base-map
"\C-d" 'c-electric-delete-forward
)
318 (define-key c-mode-base-map
"\177" 'c-electric-backspace
)
319 (define-key c-mode-base-map
"\C-c\C-d" 'c-hungry-delete-forward
)
320 (define-key c-mode-base-map
[?\C-c ?\d
] 'c-hungry-delete-backwards
)
321 (define-key c-mode-base-map
[?\C-c ?\C-\d
] 'c-hungry-delete-backwards
)
322 (define-key c-mode-base-map
[?\C-c deletechar
] 'c-hungry-delete-forward
) ; C-c <delete> on a tty.
323 (define-key c-mode-base-map
[?\C-c
(control deletechar
)] ; C-c C-<delete> on a tty.
324 'c-hungry-delete-forward
)
325 (when (boundp 'normal-erase-is-backspace
)
326 ;; The automatic C-d and DEL mapping functionality doesn't extend
327 ;; to special combinations like C-c C-<delete>, so we have to hook
328 ;; into the `normal-erase-is-backspace' system to bind it directly
330 (add-hook 'normal-erase-is-backspace-hook
'c-bind-special-erase-keys
)
331 (c-bind-special-erase-keys))
333 (when (fboundp 'delete-forward-p
)
334 ;; In XEmacs we fix the forward and backward deletion behavior by
335 ;; binding the keysyms for the [delete] and [backspace] keys
336 ;; directly, and use `delete-forward-p' to decide what [delete]
337 ;; should do. That's done in the XEmacs specific
338 ;; `c-electric-delete' and `c-hungry-delete' functions.
339 (define-key c-mode-base-map
[delete] 'c-electric-delete)
340 (define-key c-mode-base-map [backspace] 'c-electric-backspace)
341 (define-key c-mode-base-map (kbd "C-c <delete>") 'c-hungry-delete)
342 (define-key c-mode-base-map (kbd "C-c C-<delete>") 'c-hungry-delete)
343 (define-key c-mode-base-map (kbd "C-c <backspace>")
344 'c-hungry-delete-backwards)
345 (define-key c-mode-base-map (kbd "C-c C-<backspace>")
346 'c-hungry-delete-backwards))
348 (define-key c-mode-base-map "#" 'c-electric-pound)
349 (define-key c-mode-base-map "{" 'c-electric-brace)
350 (define-key c-mode-base-map "}" 'c-electric-brace)
351 (define-key c-mode-base-map "/" 'c-electric-slash)
352 (define-key c-mode-base-map "*" 'c-electric-star)
353 (define-key c-mode-base-map ";" 'c-electric-semi&comma)
354 (define-key c-mode-base-map "," 'c-electric-semi&comma)
355 (define-key c-mode-base-map ":" 'c-electric-colon)
356 (define-key c-mode-base-map "(" 'c-electric-paren)
357 (define-key c-mode-base-map ")" 'c-electric-paren)
359 (define-key c-mode-base-map "\C-c\C-\\" 'c-backslash-region)
360 (define-key c-mode-base-map "\C-c\C-a" 'c-toggle-auto-newline)
361 (define-key c-mode-base-map "\C-c\C-b" 'c-submit-bug-report)
362 (define-key c-mode-base-map "\C-c\C-c" 'comment-region)
363 (define-key c-mode-base-map "\C-c\C-l" 'c-toggle-electric-state)
364 (define-key c-mode-base-map "\C-c\C-o" 'c-set-offset)
365 (define-key c-mode-base-map "\C-c\C-q" 'c-indent-defun)
366 (define-key c-mode-base-map "\C-c\C-s" 'c-show-syntactic-information)
367 ;; (define-key c-mode-base-map "\C-c\C-t" 'c-toggle-auto-hungry-state) Commented out by ACM, 2005-03-05.
368 (define-key c-mode-base-map "\C-c." 'c-set-style)
369 ;; conflicts with OOBR
370 ;;(define-key c-mode-base-map "\C-c\C-v" 'c-version)
371 ;; (define-key c-mode-base-map "\C-c\C-y" 'c-toggle-hungry-state) Commented out by ACM, 2005-11-22.
372 (define-key c-mode-base-map "\C-c\C-w" 'c-subword-mode)
375 ;; We don't require the outline package, but we configure it a bit anyway.
376 (cc-bytecomp-defvar outline-level)
378 (defun c-mode-menu (modestr)
379 "Return a menu spec suitable for `easy-menu-define' that is exactly
380 like the C mode menu except that the menu bar item name is MODESTR
383 This function is provided for compatibility only; derived modes should
384 preferably use the `c-mode-menu' language constant directly."
385 (cons modestr (c-lang-const c-mode-menu c)))
387 ;; Ugly hack to pull in the definition of `c-populate-syntax-table'
388 ;; from cc-langs to make it available at runtime. It's either this or
389 ;; moving the definition for it to cc-defs, but that would mean to
390 ;; break up the syntax table setup over two files.
391 (defalias 'c-populate-syntax-table
392 (cc-eval-when-compile
393 (let ((f (symbol-function 'c-populate-syntax-table)))
394 (if (byte-code-function-p f) f (byte-compile f)))))
396 ;; CAUTION: Try to avoid installing things on
397 ;; `before-change-functions'. The macro `combine-after-change-calls'
398 ;; is used and it doesn't work if there are things on that hook. That
399 ;; can cause font lock functions to run in inconvenient places during
400 ;; temporary changes in some font lock support modes, causing extra
401 ;; unnecessary work and font lock glitches due to interactions between
402 ;; various text properties.
404 (defun c-after-change (beg end len)
405 ;; Function put on `after-change-functions' to adjust various caches
406 ;; etc. Prefer speed to finesse here, since there will be an order
407 ;; of magnitude more calls to this function than any of the
408 ;; functions that use the caches.
410 ;; Note that care must be taken so that this is called before any
411 ;; font-lock callbacks since we might get calls to functions using
412 ;; these caches from inside them, and we must thus be sure that this
413 ;; has already been executed.
415 (c-save-buffer-state ()
416 ;; When `combine-after-change-calls' is used we might get calls
417 ;; with regions outside the current narrowing. This has been
418 ;; observed in Emacs 20.7.
420 (save-match-data ; c-recognize-<>-arglists changes match-data
423 (when (> end (point-max))
424 ;; Some emacsen might return positions past the end. This has been
425 ;; observed in Emacs 20.7 when rereading a buffer changed on disk
426 ;; (haven't been able to minimize it, but Emacs 21.3 appears to
428 (setq end (point-max))
432 (c-invalidate-sws-region-after beg end)
433 (c-invalidate-state-cache beg)
434 (c-invalidate-find-decl-cache beg)
436 (when c-recognize-<>-arglists
437 (c-after-change-check-<>-operators beg end))))))
439 (defun c-basic-common-init (mode default-style)
440 "Do the necessary initialization for the syntax handling routines
441 and the line breaking/filling code. Intended to be used by other
442 packages that embed CC Mode.
444 MODE is the CC Mode flavor to set up, e.g. 'c-mode or 'java-mode.
445 DEFAULT-STYLE tells which indentation style to install. It has the
446 same format as `c-default-style'.
448 Note that `c-init-language-vars' must be called before this function.
449 This function cannot do that since `c-init-language-vars' is a macro
450 that requires a literal mode spec at compile time."
452 (setq c-buffer-is-cc-mode mode)
454 ;; these variables should always be buffer local; they do not affect
455 ;; indentation style.
456 (make-local-variable 'parse-sexp-ignore-comments)
457 (make-local-variable 'indent-line-function)
458 (make-local-variable 'indent-region-function)
459 (make-local-variable 'normal-auto-fill-function)
460 (make-local-variable 'comment-start)
461 (make-local-variable 'comment-end)
462 (make-local-variable 'comment-start-skip)
463 (make-local-variable 'comment-multi-line)
464 (make-local-variable 'comment-line-break-function)
465 (make-local-variable 'paragraph-start)
466 (make-local-variable 'paragraph-separate)
467 (make-local-variable 'paragraph-ignore-fill-prefix)
468 (make-local-variable 'adaptive-fill-mode)
469 (make-local-variable 'adaptive-fill-regexp)
471 ;; now set their values
472 (setq parse-sexp-ignore-comments t
473 indent-line-function 'c-indent-line
474 indent-region-function 'c-indent-region
475 normal-auto-fill-function 'c-do-auto-fill
477 comment-line-break-function 'c-indent-new-comment-line)
479 ;; Install `c-fill-paragraph' on `fill-paragraph-function' so that a
480 ;; direct call to `fill-paragraph' behaves better. This still
481 ;; doesn't work with filladapt but it's better than nothing.
482 (make-local-variable 'fill-paragraph-function)
483 (setq fill-paragraph-function 'c-fill-paragraph)
485 (when (or c-recognize-<>-arglists
486 (c-major-mode-is 'awk-mode))
487 ;; We'll use the syntax-table text property to change the syntax
488 ;; of some chars for this language, so do the necessary setup for
491 ;; Note to other package developers: It's ok to turn this on in CC
492 ;; Mode buffers when CC Mode doesn't, but it's not ok to turn it
493 ;; off if CC Mode has turned it on.
496 (when (boundp 'parse-sexp-lookup-properties)
497 (make-local-variable 'parse-sexp-lookup-properties)
498 (setq parse-sexp-lookup-properties t))
500 ;; Same as above for XEmacs.
501 (when (boundp 'lookup-syntax-properties)
502 (make-local-variable 'lookup-syntax-properties)
503 (setq lookup-syntax-properties t)))
505 ;; Use this in Emacs 21 to avoid meddling with the rear-nonsticky
506 ;; property on each character.
507 (when (boundp 'text-property-default-nonsticky)
508 (make-local-variable 'text-property-default-nonsticky)
509 (let ((elem (assq 'syntax-table text-property-default-nonsticky)))
512 (setq text-property-default-nonsticky
513 (cons '(syntax-table . t)
514 text-property-default-nonsticky))))
515 (setq text-property-default-nonsticky
517 text-property-default-nonsticky)))
519 ;; In Emacs 21 and later it's possible to turn off the ad-hoc
520 ;; heuristic that open parens in column 0 are defun starters. Since
521 ;; we have c-state-cache, that heuristic isn't useful and only causes
522 ;; trouble, so turn it off.
523 (when (memq 'col-0-paren c-emacs-features)
524 (make-local-variable 'open-paren-in-column-0-is-defun-start)
525 (setq open-paren-in-column-0-is-defun-start nil))
527 (c-clear-found-types)
529 ;; now set the mode style based on default-style
530 (let ((style (if (stringp default-style)
532 (or (cdr (assq mode default-style))
533 (cdr (assq 'other default-style))
535 ;; Override style variables if `c-old-style-variable-behavior' is
536 ;; set. Also override if we are using global style variables,
537 ;; have already initialized a style once, and are switching to a
538 ;; different style. (It's doubtful whether this is desirable, but
539 ;; the whole situation with nonlocal style variables is a bit
540 ;; awkward. It's at least the most compatible way with the old
541 ;; style init procedure.)
542 (c-set-style style (not (or c-old-style-variable-behavior
543 (and (not c-style-variables-are-local-p)
545 (not (string-equal c-indentation-style
547 (c-setup-paragraph-variables)
549 ;; we have to do something special for c-offsets-alist so that the
550 ;; buffer local value has its own alist structure.
551 (setq c-offsets-alist (copy-alist c-offsets-alist))
553 ;; setup the comment indent variable in a Emacs version portable way
554 (make-local-variable 'comment-indent-function)
555 (setq comment-indent-function 'c-comment-indent)
557 ;; ;; Put submode indicators onto minor-mode-alist, but only once.
558 ;; (or (assq 'c-submode-indicators minor-mode-alist)
559 ;; (setq minor-mode-alist
560 ;; (cons '(c-submode-indicators c-submode-indicators)
561 ;; minor-mode-alist)))
564 ;; Install the functions that ensure that various internal caches
565 ;; don't become invalid due to buffer changes.
566 (make-local-hook 'after-change-functions)
567 (add-hook 'after-change-functions 'c-after-change nil t))
569 (defun c-after-font-lock-init ()
570 ;; Put on `font-lock-mode-hook'.
571 (remove-hook 'after-change-functions 'c-after-change t)
572 (add-hook 'after-change-functions 'c-after-change nil t))
574 (defun c-font-lock-init ()
575 "Set up the font-lock variables for using the font-lock support in CC Mode.
576 This does not load the font-lock package. Use after
577 `c-basic-common-init' and after cc-fonts has been loaded."
579 (make-local-variable 'font-lock-defaults)
580 (setq font-lock-defaults
581 `(,(if (c-major-mode-is 'awk-mode)
582 ;; awk-mode currently has only one font lock level.
583 'awk-font-lock-keywords
584 (mapcar 'c-mode-symbol
585 '("font-lock-keywords" "font-lock-keywords-1"
586 "font-lock-keywords-2" "font-lock-keywords-3")))
588 ,c-identifier-syntax-modifications
589 c-beginning-of-syntax
590 (font-lock-lines-before . 1)
591 (font-lock-mark-block-function
594 (make-local-hook 'font-lock-mode-hook)
595 (add-hook 'font-lock-mode-hook 'c-after-font-lock-init nil t))
597 (defun c-setup-doc-comment-style ()
598 "Initialize the variables that depend on the value of `c-doc-comment-style'."
599 (when (and (featurep 'font-lock)
600 (symbol-value 'font-lock-mode))
601 ;; Force font lock mode to reinitialize itself.
605 (defun c-common-init (&optional mode)
606 "Common initialization for all CC Mode modes.
607 In addition to the work done by `c-basic-common-init' and
608 `c-font-lock-init', this function sets up various other things as
609 customary in CC Mode modes but which aren't strictly necessary for CC
610 Mode to operate correctly.
612 MODE is the symbol for the mode to initialize, like 'c-mode. See
613 `c-basic-common-init' for details. It's only optional to be
614 compatible with old code; callers should always specify it."
617 ;; Called from an old third party package. The fallback is to
619 (c-init-language-vars-for 'c-mode))
621 (c-basic-common-init mode c-default-style)
623 ;; Only initialize font locking if we aren't called from an old package.
626 (make-local-variable 'outline-regexp)
627 (make-local-variable 'outline-level)
628 (setq outline-regexp "[^#\n\^M]"
629 outline-level 'c-outline-level)
631 (let ((rfn (assq mode c-require-final-newline)))
633 (make-local-variable 'require-final-newline)
635 (setq require-final-newline mode-require-final-newline)))))
637 (defun c-remove-any-local-eval-or-mode-variables ()
638 ;; If the buffer specifies `mode' or `eval' in its File Local Variable list
639 ;; or on the first line, remove all occurrences. See
640 ;; `c-postprocess-file-styles' for justification. There is no need to save
641 ;; point here, or even bother too much about the buffer contents.
643 ;; Most of the code here is derived from Emacs 21.3's `hack-local-variables'
645 (goto-char (point-max))
646 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move)
647 (let (lv-point (prefix "") (suffix ""))
648 (when (let ((case-fold-search t))
649 (search-forward "Local Variables:" nil t))
650 (setq lv-point (point))
651 ;; The prefix is what comes before "local variables:" in its line.
652 ;; The suffix is what comes after "local variables:" in its line.
653 (skip-chars-forward " \t")
655 (setq suffix (buffer-substring (point)
656 (progn (end-of-line) (point)))))
657 (goto-char (match-beginning 0))
660 (buffer-substring (point)
661 (progn (beginning-of-line) (point)))))
663 (while (search-forward-regexp
665 (regexp-quote prefix)
666 "\\(mode\\|eval\\):.*"
667 (regexp-quote suffix)
673 ;; Delete the first line, if we've got one, in case it contains a mode spec.
674 (unless (and lv-point
675 (progn (goto-char lv-point)
678 (goto-char (point-min))
682 (defun c-postprocess-file-styles ()
683 "Function that post processes relevant file local variables in CC Mode.
684 Currently, this function simply applies any style and offset settings
685 found in the file's Local Variable list. It first applies any style
686 setting found in `c-file-style', then it applies any offset settings
687 it finds in `c-file-offsets'.
689 Note that the style variables are always made local to the buffer."
691 ;; apply file styles and offsets
692 (when c-buffer-is-cc-mode
693 (if (or c-file-style c-file-offsets)
694 (c-make-styles-buffer-local t))
696 (c-set-style c-file-style))
700 (let ((langelem (car langentry))
701 (offset (cdr langentry)))
702 (c-set-offset langelem offset)))
704 ;; Problem: The file local variable block might have explicitly set a
705 ;; style variable. The `c-set-style' or `mapcar' call might have
706 ;; overwritten this. So we run `hack-local-variables' again to remedy
707 ;; this. There are no guarantees this will work properly, particularly as
708 ;; we have no control over what the other hook functions on
709 ;; `hack-local-variables-hook' would have done. We now (2006/2/1) remove
710 ;; any `eval' or `mode' expressions before we evaluate again (see below).
713 ;; Problem (bug reported by Gustav Broberg): if one of the variables is
714 ;; `mode', this will invoke c-mode (etc.) again, setting up the style etc.
715 ;; We prevent this by temporarily removing `mode' from the Local Variables
717 (if (or c-file-style c-file-offsets)
718 (c-tentative-buffer-changes
719 (let ((hack-local-variables-hook nil))
720 (c-remove-any-local-eval-or-mode-variables)
721 (hack-local-variables))
724 (add-hook 'hack-local-variables-hook 'c-postprocess-file-styles)
726 (defmacro c-run-mode-hooks (&rest hooks)
727 ;; Emacs 21.1 has introduced a system with delayed mode hooks that
728 ;; require the use of the new function `run-mode-hooks'.
729 (if (cc-bytecomp-fboundp 'run-mode-hooks)
730 `(run-mode-hooks ,@hooks)
731 `(progn ,@(mapcar (lambda (hook) `(run-hooks ,hook)) hooks))))
737 (defvar c-mode-syntax-table nil
738 "Syntax table used in c-mode buffers.")
739 (or c-mode-syntax-table
740 (setq c-mode-syntax-table
741 (funcall (c-lang-const c-make-mode-syntax-table c))))
743 (defvar c-mode-abbrev-table nil
744 "Abbreviation table used in c-mode buffers.")
745 (c-define-abbrev-table 'c-mode-abbrev-table
746 '(("else" "else" c-electric-continued-statement 0)
747 ("while" "while" c-electric-continued-statement 0)))
749 (defvar c-mode-map ()
750 "Keymap used in c-mode buffers.")
753 (setq c-mode-map (c-make-inherited-keymap))
754 ;; add bindings which are only useful for C
755 (define-key c-mode-map "\C-c\C-e" 'c-macro-expand)
758 (easy-menu-define c-c-menu c-mode-map "C Mode Commands"
759 (cons "C" (c-lang-const c-mode-menu c)))
761 ;; In XEmacs >= 21.5 modes should add their own entries to
762 ;; `auto-mode-alist'. The comment form of autoload is used to avoid
763 ;; doing this on load. That since `add-to-list' prepends the value
764 ;; which could cause it to clobber user settings. Later emacsen have
765 ;; an append option, but it's not safe to use.
767 ;; The the extension ".C" is associated to C++ while the lowercase
768 ;; variant goes to C. On case insensitive file systems, this means
769 ;; that ".c" files also might open C++ mode if the C++ entry comes
770 ;; first on `auto-mode-alist'. Thus we try to ensure that ".C" comes
771 ;; after ".c", and since `add-to-list' adds the entry first we have to
772 ;; add the ".C" entry first.
773 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.\\(cc\\|hh\\)\\'" . c++-mode))
774 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.[ch]\\(pp\\|xx\\|\\+\\+\\)\\'" . c++-mode))
775 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.\\(CC?\\|HH?\\)\\'" . c++-mode))
777 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.[ch]\\'" . c-mode))
779 ;; NB: The following two associate yacc and lex files to C Mode, which
780 ;; is not really suitable for those formats. Anyway, afaik there's
781 ;; currently no better mode for them, and besides this is legacy.
782 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.y\\(acc\\)?\\'" . c-mode))
783 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.lex\\'" . c-mode))
787 "Major mode for editing K&R and ANSI C code.
788 To submit a problem report, enter `\\[c-submit-bug-report]' from a
789 c-mode buffer. This automatically sets up a mail buffer with version
790 information already added. You just need to add a description of the
791 problem, including a reproducible test case, and send the message.
793 To see what version of CC Mode you are running, enter `\\[c-version]'.
795 The hook `c-mode-common-hook' is run with no args at mode
796 initialization, then `c-mode-hook'.
801 (kill-all-local-variables)
802 (c-initialize-cc-mode t)
803 (set-syntax-table c-mode-syntax-table)
804 (setq major-mode 'c-mode
806 local-abbrev-table c-mode-abbrev-table
808 (use-local-map c-mode-map)
809 (c-init-language-vars-for 'c-mode)
810 (c-common-init 'c-mode)
811 (easy-menu-add c-c-menu)
812 (cc-imenu-init cc-imenu-c-generic-expression)
813 (c-run-mode-hooks 'c-mode-common-hook 'c-mode-hook)
820 (defvar c++-mode-syntax-table nil
821 "Syntax table used in c++-mode buffers.")
822 (or c++-mode-syntax-table
823 (setq c++-mode-syntax-table
824 (funcall (c-lang-const c-make-mode-syntax-table c++))))
826 (defvar c++-mode-abbrev-table nil
827 "Abbreviation table used in c++-mode buffers.")
828 (c-define-abbrev-table 'c++-mode-abbrev-table
829 '(("else" "else" c-electric-continued-statement 0)
830 ("while" "while" c-electric-continued-statement 0)
831 ("catch" "catch" c-electric-continued-statement 0)))
833 (defvar c++-mode-map ()
834 "Keymap used in c++-mode buffers.")
837 (setq c++-mode-map (c-make-inherited-keymap))
838 ;; add bindings which are only useful for C++
839 (define-key c++-mode-map "\C-c\C-e" 'c-macro-expand)
840 (define-key c++-mode-map "\C-c:" 'c-scope-operator)
841 (define-key c++-mode-map "<" 'c-electric-lt-gt)
842 (define-key c++-mode-map ">" 'c-electric-lt-gt))
844 (easy-menu-define c-c++-menu c++-mode-map "C++ Mode Commands"
845 (cons "C++" (c-lang-const c-mode-menu c++)))
849 "Major mode for editing C++ code.
850 To submit a problem report, enter `\\[c-submit-bug-report]' from a
851 c++-mode buffer. This automatically sets up a mail buffer with
852 version information already added. You just need to add a description
853 of the problem, including a reproducible test case, and send the
856 To see what version of CC Mode you are running, enter `\\[c-version]'.
858 The hook `c-mode-common-hook' is run with no args at mode
859 initialization, then `c++-mode-hook'.
864 (kill-all-local-variables)
865 (c-initialize-cc-mode t)
866 (set-syntax-table c++-mode-syntax-table)
867 (setq major-mode 'c++-mode
869 local-abbrev-table c++-mode-abbrev-table
871 (use-local-map c++-mode-map)
872 (c-init-language-vars-for 'c++-mode)
873 (c-common-init 'c++-mode)
874 (easy-menu-add c-c++-menu)
875 (cc-imenu-init cc-imenu-c++-generic-expression)
876 (c-run-mode-hooks 'c-mode-common-hook 'c++-mode-hook)
880 ;; Support for Objective-C
883 (defvar objc-mode-syntax-table nil
884 "Syntax table used in objc-mode buffers.")
885 (or objc-mode-syntax-table
886 (setq objc-mode-syntax-table
887 (funcall (c-lang-const c-make-mode-syntax-table objc))))
889 (defvar objc-mode-abbrev-table nil
890 "Abbreviation table used in objc-mode buffers.")
891 (c-define-abbrev-table 'objc-mode-abbrev-table
892 '(("else" "else" c-electric-continued-statement 0)
893 ("while" "while" c-electric-continued-statement 0)))
895 (defvar objc-mode-map ()
896 "Keymap used in objc-mode buffers.")
899 (setq objc-mode-map (c-make-inherited-keymap))
900 ;; add bindings which are only useful for Objective-C
901 (define-key objc-mode-map "\C-c\C-e" 'c-macro-expand))
903 (easy-menu-define c-objc-menu objc-mode-map "ObjC Mode Commands"
904 (cons "ObjC" (c-lang-const c-mode-menu objc)))
906 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.m\\'" . objc-mode))
910 "Major mode for editing Objective C code.
911 To submit a problem report, enter `\\[c-submit-bug-report]' from an
912 objc-mode buffer. This automatically sets up a mail buffer with
913 version information already added. You just need to add a description
914 of the problem, including a reproducible test case, and send the
917 To see what version of CC Mode you are running, enter `\\[c-version]'.
919 The hook `c-mode-common-hook' is run with no args at mode
920 initialization, then `objc-mode-hook'.
925 (kill-all-local-variables)
926 (c-initialize-cc-mode t)
927 (set-syntax-table objc-mode-syntax-table)
928 (setq major-mode 'objc-mode
930 local-abbrev-table objc-mode-abbrev-table
932 (use-local-map objc-mode-map)
933 (c-init-language-vars-for 'objc-mode)
934 (c-common-init 'objc-mode)
935 (easy-menu-add c-objc-menu)
936 (cc-imenu-init nil 'cc-imenu-objc-function)
937 (c-run-mode-hooks 'c-mode-common-hook 'objc-mode-hook)
944 (defvar java-mode-syntax-table nil
945 "Syntax table used in java-mode buffers.")
946 (or java-mode-syntax-table
947 (setq java-mode-syntax-table
948 (funcall (c-lang-const c-make-mode-syntax-table java))))
950 (defvar java-mode-abbrev-table nil
951 "Abbreviation table used in java-mode buffers.")
952 (c-define-abbrev-table 'java-mode-abbrev-table
953 '(("else" "else" c-electric-continued-statement 0)
954 ("while" "while" c-electric-continued-statement 0)
955 ("catch" "catch" c-electric-continued-statement 0)
956 ("finally" "finally" c-electric-continued-statement 0)))
958 (defvar java-mode-map ()
959 "Keymap used in java-mode buffers.")
962 (setq java-mode-map (c-make-inherited-keymap))
963 ;; add bindings which are only useful for Java
966 ;; Regexp trying to describe the beginning of a Java top-level
967 ;; definition. This is not used by CC Mode, nor is it maintained
968 ;; since it's practically impossible to write a regexp that reliably
969 ;; matches such a construct. Other tools are necessary.
970 (defconst c-Java-defun-prompt-regexp
971 "^[ \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:;.,{}()\x7f=]*\\|\\([_$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-*")
973 (easy-menu-define c-java-menu java-mode-map "Java Mode Commands"
974 (cons "Java" (c-lang-const c-mode-menu java)))
976 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.java\\'" . java-mode))
980 "Major mode for editing Java code.
981 To submit a problem report, enter `\\[c-submit-bug-report]' from a
982 java-mode buffer. This automatically sets up a mail buffer with
983 version information already added. You just need to add a description
984 of the problem, including a reproducible test case, and send the
987 To see what version of CC Mode you are running, enter `\\[c-version]'.
989 The hook `c-mode-common-hook' is run with no args at mode
990 initialization, then `java-mode-hook'.
995 (kill-all-local-variables)
996 (c-initialize-cc-mode t)
997 (set-syntax-table java-mode-syntax-table)
998 (setq major-mode 'java-mode
1000 local-abbrev-table java-mode-abbrev-table
1002 (use-local-map java-mode-map)
1003 (c-init-language-vars-for 'java-mode)
1004 (c-common-init 'java-mode)
1005 (easy-menu-add c-java-menu)
1006 (cc-imenu-init cc-imenu-java-generic-expression)
1007 (c-run-mode-hooks 'c-mode-common-hook 'java-mode-hook)
1008 (c-update-modeline))
1011 ;; Support for CORBA's IDL language
1014 (defvar idl-mode-syntax-table nil
1015 "Syntax table used in idl-mode buffers.")
1016 (or idl-mode-syntax-table
1017 (setq idl-mode-syntax-table
1018 (funcall (c-lang-const c-make-mode-syntax-table idl))))
1020 (defvar idl-mode-abbrev-table nil
1021 "Abbreviation table used in idl-mode buffers.")
1022 (c-define-abbrev-table 'idl-mode-abbrev-table nil)
1024 (defvar idl-mode-map ()
1025 "Keymap used in idl-mode buffers.")
1028 (setq idl-mode-map (c-make-inherited-keymap))
1029 ;; add bindings which are only useful for IDL
1032 (easy-menu-define c-idl-menu idl-mode-map "IDL Mode Commands"
1033 (cons "IDL" (c-lang-const c-mode-menu idl)))
1035 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.idl\\'" . idl-mode))
1039 "Major mode for editing CORBA's IDL, PSDL and CIDL code.
1040 To submit a problem report, enter `\\[c-submit-bug-report]' from an
1041 idl-mode buffer. This automatically sets up a mail buffer with
1042 version information already added. You just need to add a description
1043 of the problem, including a reproducible test case, and send the
1046 To see what version of CC Mode you are running, enter `\\[c-version]'.
1048 The hook `c-mode-common-hook' is run with no args at mode
1049 initialization, then `idl-mode-hook'.
1054 (kill-all-local-variables)
1055 (c-initialize-cc-mode t)
1056 (set-syntax-table idl-mode-syntax-table)
1057 (setq major-mode 'idl-mode
1059 local-abbrev-table idl-mode-abbrev-table)
1060 (use-local-map idl-mode-map)
1061 (c-init-language-vars-for 'idl-mode)
1062 (c-common-init 'idl-mode)
1063 (easy-menu-add c-idl-menu)
1064 ;;(cc-imenu-init cc-imenu-idl-generic-expression) ;TODO
1065 (c-run-mode-hooks 'c-mode-common-hook 'idl-mode-hook)
1066 (c-update-modeline))
1072 (defvar pike-mode-syntax-table nil
1073 "Syntax table used in pike-mode buffers.")
1074 (or pike-mode-syntax-table
1075 (setq pike-mode-syntax-table
1076 (funcall (c-lang-const c-make-mode-syntax-table pike))))
1078 (defvar pike-mode-abbrev-table nil
1079 "Abbreviation table used in pike-mode buffers.")
1080 (c-define-abbrev-table 'pike-mode-abbrev-table
1081 '(("else" "else" c-electric-continued-statement 0)
1082 ("while" "while" c-electric-continued-statement 0)))
1084 (defvar pike-mode-map ()
1085 "Keymap used in pike-mode buffers.")
1088 (setq pike-mode-map (c-make-inherited-keymap))
1089 ;; additional bindings
1090 (define-key pike-mode-map "\C-c\C-e" 'c-macro-expand))
1092 (easy-menu-define c-pike-menu pike-mode-map "Pike Mode Commands"
1093 (cons "Pike" (c-lang-const c-mode-menu pike)))
1095 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.\\(u?lpc\\|pike\\|pmod\\(.in\\)?\\)\\'" . pike-mode))
1096 ;;;###autoload (add-to-list 'interpreter-mode-alist '("pike" . pike-mode))
1100 "Major mode for editing Pike code.
1101 To submit a problem report, enter `\\[c-submit-bug-report]' from a
1102 pike-mode buffer. This automatically sets up a mail buffer with
1103 version information already added. You just need to add a description
1104 of the problem, including a reproducible test case, and send the
1107 To see what version of CC Mode you are running, enter `\\[c-version]'.
1109 The hook `c-mode-common-hook' is run with no args at mode
1110 initialization, then `pike-mode-hook'.
1115 (kill-all-local-variables)
1116 (c-initialize-cc-mode t)
1117 (set-syntax-table pike-mode-syntax-table)
1118 (setq major-mode 'pike-mode
1120 local-abbrev-table pike-mode-abbrev-table
1122 (use-local-map pike-mode-map)
1123 (c-init-language-vars-for 'pike-mode)
1124 (c-common-init 'pike-mode)
1125 (easy-menu-add c-pike-menu)
1126 ;;(cc-imenu-init cc-imenu-pike-generic-expression) ;TODO
1127 (c-run-mode-hooks 'c-mode-common-hook 'pike-mode-hook)
1128 (c-update-modeline))
1133 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.awk\\'" . awk-mode))
1134 ;;;###autoload (add-to-list 'interpreter-mode-alist '("awk" . awk-mode))
1135 ;;;###autoload (add-to-list 'interpreter-mode-alist '("mawk" . awk-mode))
1136 ;;;###autoload (add-to-list 'interpreter-mode-alist '("nawk" . awk-mode))
1137 ;;;###autoload (add-to-list 'interpreter-mode-alist '("gawk" . awk-mode))
1139 ;;; Autoload directives must be on the top level, so we construct an
1140 ;;; autoload form instead.
1141 ;;;###autoload (autoload 'awk-mode "cc-mode" "Major mode for editing AWK code." t)
1143 (defvar awk-mode-abbrev-table nil
1144 "Abbreviation table used in awk-mode buffers.")
1145 (c-define-abbrev-table 'awk-mode-abbrev-table
1146 '(("else" "else" c-electric-continued-statement 0)
1147 ("while" "while" c-electric-continued-statement 0)))
1149 (defvar awk-mode-map ()
1150 "Keymap used in awk-mode buffers.")
1153 (setq awk-mode-map (c-make-inherited-keymap))
1154 ;; add bindings which are only useful for awk.
1155 (define-key awk-mode-map "#" 'self-insert-command)
1156 (define-key awk-mode-map "/" 'self-insert-command)
1157 (define-key awk-mode-map "*" 'self-insert-command)
1158 (define-key awk-mode-map "\C-c\C-n" 'undefined) ; #if doesn't exist in awk.
1159 (define-key awk-mode-map "\C-c\C-p" 'undefined)
1160 (define-key awk-mode-map "\C-c\C-u" 'undefined)
1161 (define-key awk-mode-map "\M-a" 'c-beginning-of-statement) ; 2003/10/7
1162 (define-key awk-mode-map "\M-e" 'c-end-of-statement) ; 2003/10/7
1163 (define-key awk-mode-map "\C-\M-a" 'c-awk-beginning-of-defun)
1164 (define-key awk-mode-map "\C-\M-e" 'c-awk-end-of-defun))
1166 (easy-menu-define c-awk-menu awk-mode-map "AWK Mode Commands"
1167 (cons "AWK" (c-lang-const c-mode-menu awk)))
1170 "Major mode for editing AWK code.
1171 To submit a problem report, enter `\\[c-submit-bug-report]' from an
1172 awk-mode buffer. This automatically sets up a mail buffer with version
1173 information already added. You just need to add a description of the
1174 problem, including a reproducible test case, and send the message.
1176 To see what version of CC Mode you are running, enter `\\[c-version]'.
1178 The hook `c-mode-common-hook' is run with no args at mode
1179 initialization, then `awk-mode-hook'.
1184 (require 'cc-awk) ; Added 2003/6/10.
1185 (kill-all-local-variables)
1186 (c-initialize-cc-mode t)
1187 (set-syntax-table awk-mode-syntax-table)
1188 (setq major-mode 'awk-mode
1190 local-abbrev-table awk-mode-abbrev-table
1192 (use-local-map awk-mode-map)
1193 (c-init-language-vars-for 'awk-mode)
1194 (c-common-init 'awk-mode)
1195 ;; The rest of CC Mode does not (yet) use `font-lock-syntactic-keywords',
1196 ;; so it's not set by `c-font-lock-init'.
1197 (make-local-variable 'font-lock-syntactic-keywords)
1198 (setq font-lock-syntactic-keywords
1199 '((c-awk-set-syntax-table-properties
1200 0 (0) ; Everything on this line is a dummy.
1202 (c-awk-unstick-NL-prop)
1203 (add-hook 'before-change-functions 'c-awk-before-change nil t)
1204 (add-hook 'after-change-functions 'c-awk-after-change nil t)
1205 (c-save-buffer-state nil
1208 (c-awk-clear-NL-props (point-min) (point-max))
1209 (c-awk-after-change (point-min) (point-max) 0))) ; Set syntax-table props.
1211 ;; Prevent Xemacs's buffer-syntactic-context being used. See the comment
1212 ;; in cc-engine.el, just before (defun c-fast-in-literal ...
1213 (defalias 'c-in-literal 'c-slow-in-literal)
1215 (c-run-mode-hooks 'c-mode-common-hook 'awk-mode-hook)
1216 (c-update-modeline))
1221 (defconst c-mode-help-address
1222 "bug-cc-mode@gnu.org"
1223 "Address(es) for CC Mode bug reports.")
1226 "Echo the current version of CC Mode in the minibuffer."
1228 (message "Using CC Mode version %s" c-version)
1229 (c-keep-region-active))
1231 (defvar c-prepare-bug-report-hooks nil)
1233 ;; Dynamic variables used by reporter.
1234 (defvar reporter-prompt-for-summary-p)
1235 (defvar reporter-dont-compact-list)
1237 (defun c-submit-bug-report ()
1238 "Submit via mail a bug report on CC Mode."
1242 (let ((reporter-prompt-for-summary-p t)
1243 (reporter-dont-compact-list '(c-offsets-alist))
1244 (style c-indentation-style)
1245 (c-features c-emacs-features))
1247 (if (y-or-n-p "Do you want to submit a report on CC Mode? ")
1249 (reporter-submit-bug-report
1251 (concat "CC Mode " c-version " (" mode-name ")")
1254 '(c-buffer-is-cc-mode
1256 c-syntactic-indentation
1257 c-syntactic-indentation-in-macros
1259 c-auto-align-backslashes
1260 c-backspace-function
1262 c-electric-pound-behavior
1264 c-enable-xemacs-performance-kludge-p
1265 c-old-style-variable-behavior
1269 parse-sexp-ignore-comments
1270 parse-sexp-lookup-properties
1271 lookup-syntax-properties
1272 ;; A brain-damaged XEmacs only variable that, if
1273 ;; set to nil can cause all kinds of chaos.
1274 signal-error-on-buffer-boundary
1275 ;; Variables that affect line breaking and comments.
1285 adaptive-fill-regexp)
1287 (mapcar (lambda (var) (unless (boundp var)
1288 (setq vars (delq var vars))))
1289 '(signal-error-on-buffer-boundary
1293 font-lock-maximum-decoration
1294 parse-sexp-lookup-properties
1295 lookup-syntax-properties))
1298 (run-hooks 'c-prepare-bug-report-hooks)
1299 (insert (format "Buffer Style: %s\nc-emacs-features: %s\n"
1300 style c-features)))))))
1303 (cc-provide 'cc-mode)
1305 ;;; arch-tag: 7825e5c4-fd09-439f-a04d-4c13208ba3d7
1306 ;;; cc-mode.el ends here