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