1 ;;; cc-mode.el --- major mode for editing C and similar languages
3 ;; Copyright (C) 1985, 1987, 1992-2014 Free Software Foundation, Inc.
5 ;; Authors: 2003- Alan Mackenzie
6 ;; 1998- Martin Stjernholm
7 ;; 1992-1999 Barry A. Warsaw
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
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 3 of the License, or
20 ;; (at your option) any later version.
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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
32 ;; NOTE: Read the commentary below for the right way to submit bug reports!
33 ;; NOTE: See the accompanying texinfo manual for details on using this mode!
34 ;; Note: The version string is in cc-defs.
36 ;; This package provides GNU Emacs major modes for editing C, C++,
37 ;; Objective-C, Java, CORBA's IDL, Pike and AWK code. As of the
38 ;; latest Emacs and XEmacs releases, it is the default package for
39 ;; editing these languages. This package is called "CC Mode", and
40 ;; should be spelled exactly this way.
42 ;; CC Mode supports K&R and ANSI C, ANSI C++, Objective-C, Java,
43 ;; CORBA's IDL, Pike and AWK with a consistent indentation model
44 ;; across all modes. This indentation model is intuitive and very
45 ;; flexible, so that almost any desired style of indentation can be
46 ;; supported. Installation, usage, and programming details are
47 ;; contained in an accompanying texinfo manual.
49 ;; CC Mode's immediate ancestors were, c++-mode.el, cplus-md.el, and
52 ;; To submit bug reports, type "C-c C-b". These will be sent to
53 ;; bug-gnu-emacs@gnu.org (mirrored as the Usenet newsgroup
54 ;; gnu.emacs.bug) as well as bug-cc-mode@gnu.org, which directly
55 ;; contacts the CC Mode maintainers. Questions can sent to
56 ;; help-gnu-emacs@gnu.org (mirrored as gnu.emacs.help) and/or
57 ;; bug-cc-mode@gnu.org. Please do not send bugs or questions to our
58 ;; personal accounts; we reserve the right to ignore such email!
60 ;; Many, many thanks go out to all the folks on the beta test list.
61 ;; Without their patience, testing, insight, code contributions, and
62 ;; encouragement CC Mode would be a far inferior package.
64 ;; You can get the latest version of CC Mode, including PostScript
65 ;; documentation and separate individual files from:
67 ;; http://cc-mode.sourceforge.net/
69 ;; You can join a moderated CC Mode announcement-only mailing list by
72 ;; http://lists.sourceforge.net/mailman/listinfo/cc-mode-announce
78 (unless (fboundp 'declare-function
) (defmacro declare-function
(&rest _r
))))
82 (if (and (boundp 'byte-compile-dest-file
)
83 (stringp byte-compile-dest-file
))
84 (cons (file-name-directory byte-compile-dest-file
) load-path
)
86 (load "cc-bytecomp" nil t
)))
90 (cc-require-when-compile 'cc-langs
)
91 (cc-require 'cc-engine
)
92 (cc-require 'cc-styles
)
94 (cc-require 'cc-align
)
95 (cc-require 'cc-menus
)
96 (cc-require 'cc-guess
)
98 ;; Silence the compiler.
99 (cc-bytecomp-defvar adaptive-fill-first-line-regexp
) ; Emacs
100 (cc-bytecomp-defun run-mode-hooks) ; Emacs 21.1
102 ;; We set these variables during mode init, yet we don't require
104 (cc-bytecomp-defvar font-lock-defaults
)
105 (cc-bytecomp-defvar font-lock-syntactic-keywords
)
107 ;; Menu support for both XEmacs and Emacs. If you don't have easymenu
108 ;; with your version of Emacs, you are incompatible!
109 (cc-external-require 'easymenu
)
111 ;; Autoload directive for emacsen that doesn't have an older CC Mode
112 ;; version in the dist.
113 (autoload 'subword-mode
"subword"
114 "Mode enabling subword movement and editing keys." t
)
116 ;; Load cc-fonts first after font-lock is loaded, since it isn't
117 ;; necessary until font locking is requested.
118 ; (eval-after-load "font-lock" ; 2006-07-09: font-lock is now preloaded.
120 (require 'cc-fonts
) ;)
123 ;; Other modes and packages which depend on CC Mode should do the
124 ;; following to make sure everything is loaded and available for their
127 ;; (require 'cc-mode)
129 ;; And in the major mode function:
131 ;; (c-initialize-cc-mode t)
132 ;; (c-init-language-vars some-mode)
133 ;; (c-common-init 'some-mode) ; Or perhaps (c-basic-common-init 'some-mode)
135 ;; If you're not writing a derived mode using the language variable
136 ;; system, then some-mode is one of the language modes directly
137 ;; supported by CC Mode. You can then use (c-init-language-vars-for
138 ;; 'some-mode) instead of `c-init-language-vars'.
139 ;; `c-init-language-vars-for' is a function that avoids the rather
140 ;; large expansion of `c-init-language-vars'.
142 ;; If you use `c-basic-common-init' then you might want to call
143 ;; `c-font-lock-init' too to set up CC Mode's font lock support.
145 ;; See cc-langs.el for further info. A small example of a derived mode
146 ;; is also available at <http://cc-mode.sourceforge.net/
147 ;; derived-mode-ex.el>.
149 (defun c-leave-cc-mode-mode ()
150 (setq c-buffer-is-cc-mode nil
))
152 (defun c-init-language-vars-for (mode)
153 "Initialize the language variables for one of the language modes
154 directly supported by CC Mode. This can be used instead of the
155 `c-init-language-vars' macro if the language you want to use is one of
156 those, rather than a derived language defined through the language
157 variable system (see \"cc-langs.el\")."
158 (cond ((eq mode
'c-mode
) (c-init-language-vars c-mode
))
159 ((eq mode
'c
++-mode
) (c-init-language-vars c
++-mode
))
160 ((eq mode
'objc-mode
) (c-init-language-vars objc-mode
))
161 ((eq mode
'java-mode
) (c-init-language-vars java-mode
))
162 ((eq mode
'idl-mode
) (c-init-language-vars idl-mode
))
163 ((eq mode
'pike-mode
) (c-init-language-vars pike-mode
))
164 ((eq mode
'awk-mode
) (c-init-language-vars awk-mode
))
165 (t (error "Unsupported mode %s" mode
))))
168 (defun c-initialize-cc-mode (&optional new-style-init
)
169 "Initialize CC Mode for use in the current buffer.
170 If the optional NEW-STYLE-INIT is nil or left out then all necessary
171 initialization to run CC Mode for the C language is done. Otherwise
172 only some basic setup is done, and a call to `c-init-language-vars' or
173 `c-init-language-vars-for' is necessary too (which gives more
174 control). See \"cc-mode.el\" for more info."
176 (setq c-buffer-is-cc-mode t
)
178 (let ((initprop 'cc-mode-is-initialized
)
180 (unless (get 'c-initialize-cc-mode initprop
)
183 (put 'c-initialize-cc-mode initprop t
)
184 (c-initialize-builtin-style)
185 (run-hooks 'c-initialization-hook
)
186 ;; Fix obsolete variables.
187 (if (boundp 'c-comment-continuation-stars
)
188 (setq c-block-comment-prefix c-comment-continuation-stars
))
189 (add-hook 'change-major-mode-hook
'c-leave-cc-mode-mode
)
190 (setq c-initialization-ok t
)
191 ;; Connect up with Emacs's electric-indent-mode, for >= Emacs 24.4
192 (when (fboundp 'electric-indent-local-mode
)
193 (add-hook 'electric-indent-mode-hook
'c-electric-indent-mode-hook
)
194 (add-hook 'electric-indent-local-mode-hook
195 'c-electric-indent-local-mode-hook
)))
196 ;; Will try initialization hooks again if they failed.
197 (put 'c-initialize-cc-mode initprop c-initialization-ok
))))
199 (unless new-style-init
200 (c-init-language-vars-for 'c-mode
)))
205 (defvar c-mode-base-map
()
206 "Keymap shared by all CC Mode related modes.")
208 (defun c-make-inherited-keymap ()
209 (let ((map (make-sparse-keymap)))
210 ;; Necessary to use `cc-bytecomp-fboundp' below since this
211 ;; function is called from top-level forms that are evaluated
212 ;; while cc-bytecomp is active when one does M-x eval-buffer.
215 ((cc-bytecomp-fboundp 'set-keymap-parent
)
216 (set-keymap-parent map c-mode-base-map
))
218 ((fboundp 'set-keymap-parents
)
219 (set-keymap-parents map c-mode-base-map
))
221 (t (error "CC Mode is incompatible with this version of Emacs")))
224 (defun c-define-abbrev-table (name defs
&optional doc
)
225 ;; Compatibility wrapper for `define-abbrev' which passes a non-nil
226 ;; sixth argument for SYSTEM-FLAG in emacsen that support it
227 ;; (currently only Emacs >= 21.2).
228 (let ((table (or (and (boundp name
) (symbol-value name
))
229 (progn (condition-case nil
230 (define-abbrev-table name nil doc
)
231 (wrong-number-of-arguments ;E.g. Emacs<23.
232 (eval `(defvar ,name nil
,doc
))
233 (define-abbrev-table name nil
)))
234 (symbol-value name
)))))
237 (apply 'define-abbrev table
(append (car defs
) '(t)))
238 (wrong-number-of-arguments
239 (apply 'define-abbrev table
(car defs
))))
240 (setq defs
(cdr defs
)))))
241 (put 'c-define-abbrev-table
'lisp-indent-function
1)
243 (defun c-bind-special-erase-keys ()
244 ;; Only used in Emacs to bind C-c C-<delete> and C-c C-<backspace>
245 ;; to the proper keys depending on `normal-erase-is-backspace'.
246 (if normal-erase-is-backspace
248 (define-key c-mode-base-map
(kbd "C-c C-<delete>")
249 'c-hungry-delete-forward
)
250 (define-key c-mode-base-map
(kbd "C-c C-<backspace>")
251 'c-hungry-delete-backwards
))
252 (define-key c-mode-base-map
(kbd "C-c C-<delete>")
253 'c-hungry-delete-backwards
)
254 (define-key c-mode-base-map
(kbd "C-c C-<backspace>")
255 'c-hungry-delete-forward
)))
260 (setq c-mode-base-map
(make-sparse-keymap))
262 ;; Separate M-BS from C-M-h. The former should remain
263 ;; backward-kill-word.
264 (define-key c-mode-base-map
[(control meta h
)] 'c-mark-function
)
265 (define-key c-mode-base-map
"\e\C-q" 'c-indent-exp
)
266 (substitute-key-definition 'backward-sentence
267 'c-beginning-of-statement
268 c-mode-base-map global-map
)
269 (substitute-key-definition 'forward-sentence
271 c-mode-base-map global-map
)
272 (substitute-key-definition 'indent-new-comment-line
273 'c-indent-new-comment-line
274 c-mode-base-map global-map
)
275 (substitute-key-definition 'indent-for-tab-command
276 ;; XXX Is this the right thing to do
278 'c-indent-line-or-region
279 c-mode-base-map global-map
)
280 (when (fboundp 'comment-indent-new-line
)
281 ;; indent-new-comment-line has changed name to
282 ;; comment-indent-new-line in Emacs 21.
283 (substitute-key-definition 'comment-indent-new-line
284 'c-indent-new-comment-line
285 c-mode-base-map global-map
))
287 ;; RMS says don't make these the default.
288 ;; (April 2006): RMS has now approved these commands as defaults.
289 (unless (memq 'argumentative-bod-function c-emacs-features
)
290 (define-key c-mode-base-map
"\e\C-a" 'c-beginning-of-defun
)
291 (define-key c-mode-base-map
"\e\C-e" 'c-end-of-defun
))
293 (define-key c-mode-base-map
"\C-c\C-n" 'c-forward-conditional
)
294 (define-key c-mode-base-map
"\C-c\C-p" 'c-backward-conditional
)
295 (define-key c-mode-base-map
"\C-c\C-u" 'c-up-conditional
)
297 ;; It doesn't suffice to put `c-fill-paragraph' on
298 ;; `fill-paragraph-function' since `c-fill-paragraph' must be called
299 ;; before any fill prefix adaption is done. E.g. `filladapt-mode'
300 ;; replaces `fill-paragraph' and does the adaption before calling
301 ;; `fill-paragraph-function', and we have to mask comments etc
302 ;; before that. Also, `c-fill-paragraph' chains on to
303 ;; `fill-paragraph' and the value on `fill-paragraph-function' to
304 ;; do the actual filling work.
305 (substitute-key-definition 'fill-paragraph
'c-fill-paragraph
306 c-mode-base-map global-map
)
307 ;; In XEmacs the default fill function is called
308 ;; fill-paragraph-or-region.
309 (substitute-key-definition 'fill-paragraph-or-region
'c-fill-paragraph
310 c-mode-base-map global-map
)
312 ;; We bind the forward deletion key and (implicitly) C-d to
313 ;; `c-electric-delete-forward', and the backward deletion key to
314 ;; `c-electric-backspace'. The hungry variants are bound to the
315 ;; same keys but prefixed with C-c. This implies that C-c C-d is
316 ;; `c-hungry-delete-forward'. For consistency, we bind not only C-c
317 ;; <backspace> to `c-hungry-delete-backwards' but also
318 ;; C-c C-<backspace>, so that the Ctrl key can be held down during
319 ;; the whole sequence regardless of the direction. This in turn
320 ;; implies that we bind C-c C-<delete> to `c-hungry-delete-forward',
321 ;; for the same reason.
323 ;; Bind the electric deletion functions to C-d and DEL. Emacs 21
324 ;; automatically maps the [delete] and [backspace] keys to these two
325 ;; depending on window system and user preferences. (In earlier
326 ;; versions it's possible to do the same by using `function-key-map'.)
327 (define-key c-mode-base-map
"\C-d" 'c-electric-delete-forward
)
328 (define-key c-mode-base-map
"\177" 'c-electric-backspace
)
329 (define-key c-mode-base-map
"\C-c\C-d" 'c-hungry-delete-forward
)
330 (define-key c-mode-base-map
[?\C-c ?\d
] 'c-hungry-delete-backwards
)
331 (define-key c-mode-base-map
[?\C-c ?\C-\d
] 'c-hungry-delete-backwards
)
332 (define-key c-mode-base-map
[?\C-c deletechar
] 'c-hungry-delete-forward
) ; C-c <delete> on a tty.
333 (define-key c-mode-base-map
[?\C-c
(control deletechar
)] ; C-c C-<delete> on a tty.
334 'c-hungry-delete-forward
)
335 (when (boundp 'normal-erase-is-backspace
)
336 ;; The automatic C-d and DEL mapping functionality doesn't extend
337 ;; to special combinations like C-c C-<delete>, so we have to hook
338 ;; into the `normal-erase-is-backspace' system to bind it directly
340 (add-hook 'normal-erase-is-backspace-hook
'c-bind-special-erase-keys
)
341 (c-bind-special-erase-keys))
343 (when (fboundp 'delete-forward-p
)
344 ;; In XEmacs we fix the forward and backward deletion behavior by
345 ;; binding the keysyms for the [delete] and [backspace] keys
346 ;; directly, and use `delete-forward-p' to decide what [delete]
347 ;; should do. That's done in the XEmacs specific
348 ;; `c-electric-delete' and `c-hungry-delete' functions.
349 (define-key c-mode-base-map
[delete] 'c-electric-delete)
350 (define-key c-mode-base-map [backspace] 'c-electric-backspace)
351 (define-key c-mode-base-map (kbd "C-c <delete>") 'c-hungry-delete)
352 (define-key c-mode-base-map (kbd "C-c C-<delete>") 'c-hungry-delete)
353 (define-key c-mode-base-map (kbd "C-c <backspace>")
354 'c-hungry-delete-backwards)
355 (define-key c-mode-base-map (kbd "C-c C-<backspace>")
356 'c-hungry-delete-backwards))
358 (define-key c-mode-base-map "#" 'c-electric-pound)
359 (define-key c-mode-base-map "{" 'c-electric-brace)
360 (define-key c-mode-base-map "}" 'c-electric-brace)
361 (define-key c-mode-base-map "/" 'c-electric-slash)
362 (define-key c-mode-base-map "*" 'c-electric-star)
363 (define-key c-mode-base-map ";" 'c-electric-semi&comma)
364 (define-key c-mode-base-map "," 'c-electric-semi&comma)
365 (define-key c-mode-base-map ":" 'c-electric-colon)
366 (define-key c-mode-base-map "(" 'c-electric-paren)
367 (define-key c-mode-base-map ")" 'c-electric-paren)
369 (define-key c-mode-base-map "\C-c\C-\\" 'c-backslash-region)
370 (define-key c-mode-base-map "\C-c\C-a" 'c-toggle-auto-newline)
371 (define-key c-mode-base-map "\C-c\C-b" 'c-submit-bug-report)
372 (define-key c-mode-base-map "\C-c\C-c" 'comment-region)
373 (define-key c-mode-base-map "\C-c\C-l" 'c-toggle-electric-state)
374 (define-key c-mode-base-map "\C-c\C-o" 'c-set-offset)
375 (define-key c-mode-base-map "\C-c\C-q" 'c-indent-defun)
376 (define-key c-mode-base-map "\C-c\C-s" 'c-show-syntactic-information)
377 ;; (define-key c-mode-base-map "\C-c\C-t" 'c-toggle-auto-hungry-state) Commented out by ACM, 2005-03-05.
378 (define-key c-mode-base-map "\C-c." 'c-set-style)
379 ;; conflicts with OOBR
380 ;;(define-key c-mode-base-map "\C-c\C-v" 'c-version)
381 ;; (define-key c-mode-base-map "\C-c\C-y" 'c-toggle-hungry-state) Commented out by ACM, 2005-11-22.
382 (define-key c-mode-base-map "\C-c\C-w" 'subword-mode)
385 ;; We don't require the outline package, but we configure it a bit anyway.
386 (cc-bytecomp-defvar outline-level)
388 (defun c-mode-menu (modestr)
389 "Return a menu spec suitable for `easy-menu-define' that is exactly
390 like the C mode menu except that the menu bar item name is MODESTR
393 This function is provided for compatibility only; derived modes should
394 preferably use the `c-mode-menu' language constant directly."
395 (cons modestr (c-lang-const c-mode-menu c)))
397 ;; Ugly hack to pull in the definition of `c-populate-syntax-table'
398 ;; from cc-langs to make it available at runtime. It's either this or
399 ;; moving the definition for it to cc-defs, but that would mean to
400 ;; break up the syntax table setup over two files.
401 (defalias 'c-populate-syntax-table
402 (cc-eval-when-compile
403 (let ((f (symbol-function 'c-populate-syntax-table)))
404 (if (byte-code-function-p f) f (byte-compile f)))))
406 ;; CAUTION: Try to avoid installing things on
407 ;; `before-change-functions'. The macro `combine-after-change-calls'
408 ;; is used and it doesn't work if there are things on that hook. That
409 ;; can cause font lock functions to run in inconvenient places during
410 ;; temporary changes in some font lock support modes, causing extra
411 ;; unnecessary work and font lock glitches due to interactions between
412 ;; various text properties.
414 ;; (2007-02-12): The macro `combine-after-change-calls' ISN'T used any
417 (defun c-unfind-enclosing-token (pos)
418 ;; If POS is wholly inside a token, remove that id from
419 ;; `c-found-types', should it be present. Return t if we were in an
422 (let ((tok-beg (progn (goto-char pos)
423 (and (c-beginning-of-current-token) (point))))
424 (tok-end (progn (goto-char pos)
425 (and (c-end-of-current-token) (point)))))
426 (when (and tok-beg tok-end)
427 (c-unfind-type (buffer-substring-no-properties tok-beg tok-end))
430 (defun c-unfind-coalesced-tokens (beg end)
431 ;; unless the non-empty region (beg end) is entirely WS and there's at
432 ;; least one character of WS just before or after this region, remove
433 ;; the tokens which touch the region from `c-found-types' should they
435 (or (c-partial-ws-p beg end)
439 (or (eq beg (point-min))
440 (c-skip-ws-backward (1- beg))
442 (= (c-backward-token-2) 1)
443 (c-unfind-type (buffer-substring-no-properties
446 (or (eq end (point-max))
447 (c-skip-ws-forward (1+ end))
449 (progn (forward-char) (c-end-of-current-token) nil)
450 (c-unfind-type (buffer-substring-no-properties
453 ;; c-maybe-stale-found-type records a place near the region being
454 ;; changed where an element of `found-types' might become stale. It
455 ;; is set in c-before-change and is either nil, or has the form:
457 ;; (c-decl-id-start "foo" 97 107 " (* ooka) " "o"), where
459 ;; o - `c-decl-id-start' is the c-type text property value at buffer
462 ;; o - 97 107 is the region potentially containing the stale type -
463 ;; this is delimited by a non-nil c-type text property at 96 and
464 ;; either another one or a ";", "{", or "}" at 107.
466 ;; o - " (* ooka) " is the (before change) buffer portion containing
467 ;; the suspect type (here "ooka").
469 ;; o - "o" is the buffer contents which is about to be deleted. This
470 ;; would be the empty string for an insertion.
471 (defvar c-maybe-stale-found-type nil)
472 (make-variable-buffer-local 'c-maybe-stale-found-type)
474 (defun c-basic-common-init (mode default-style)
475 "Do the necessary initialization for the syntax handling routines
476 and the line breaking/filling code. Intended to be used by other
477 packages that embed CC Mode.
479 MODE is the CC Mode flavor to set up, e.g. 'c-mode or 'java-mode.
480 DEFAULT-STYLE tells which indentation style to install. It has the
481 same format as `c-default-style'.
483 Note that `c-init-language-vars' must be called before this function.
484 This function cannot do that since `c-init-language-vars' is a macro
485 that requires a literal mode spec at compile time."
487 (setq c-buffer-is-cc-mode mode)
489 ;; these variables should always be buffer local; they do not affect
490 ;; indentation style.
491 (make-local-variable 'comment-start)
492 (make-local-variable 'comment-end)
493 (make-local-variable 'comment-start-skip)
495 (make-local-variable 'paragraph-start)
496 (make-local-variable 'paragraph-separate)
497 (make-local-variable 'paragraph-ignore-fill-prefix)
498 (make-local-variable 'adaptive-fill-mode)
499 (make-local-variable 'adaptive-fill-regexp)
500 (make-local-variable 'fill-paragraph-handle-comment)
502 ;; now set their values
503 (set (make-local-variable 'parse-sexp-ignore-comments) t)
504 (set (make-local-variable 'indent-line-function) 'c-indent-line)
505 (set (make-local-variable 'indent-region-function) 'c-indent-region)
506 (set (make-local-variable 'normal-auto-fill-function) 'c-do-auto-fill)
507 (set (make-local-variable 'comment-multi-line) t)
508 (set (make-local-variable 'comment-line-break-function)
509 'c-indent-new-comment-line)
511 ;; For the benefit of adaptive file, which otherwise mis-fills.
512 (setq fill-paragraph-handle-comment nil)
514 ;; Install `c-fill-paragraph' on `fill-paragraph-function' so that a
515 ;; direct call to `fill-paragraph' behaves better. This still
516 ;; doesn't work with filladapt but it's better than nothing.
517 (set (make-local-variable 'fill-paragraph-function) 'c-fill-paragraph)
519 ;; Initialize the cache of brace pairs, and opening braces/brackets/parens.
522 (when (or c-recognize-<>-arglists
523 (c-major-mode-is 'awk-mode)
524 (c-major-mode-is '(java-mode c-mode c++-mode objc-mode)))
525 ;; We'll use the syntax-table text property to change the syntax
526 ;; of some chars for this language, so do the necessary setup for
529 ;; Note to other package developers: It's ok to turn this on in CC
530 ;; Mode buffers when CC Mode doesn't, but it's not ok to turn it
531 ;; off if CC Mode has turned it on.
534 (when (boundp 'parse-sexp-lookup-properties)
535 (set (make-local-variable 'parse-sexp-lookup-properties) t))
537 ;; Same as above for XEmacs.
538 (when (boundp 'lookup-syntax-properties)
539 (set (make-local-variable 'lookup-syntax-properties) t)))
541 ;; Use this in Emacs 21+ to avoid meddling with the rear-nonsticky
542 ;; property on each character.
543 (when (boundp 'text-property-default-nonsticky)
544 (mapc (lambda (tprop)
545 (unless (assq tprop text-property-default-nonsticky)
546 (set (make-local-variable 'text-property-default-nonsticky)
547 (cons `(,tprop . t) text-property-default-nonsticky))))
548 '(syntax-table category c-type)))
550 ;; In Emacs 21 and later it's possible to turn off the ad-hoc
551 ;; heuristic that open parens in column 0 are defun starters. Since
552 ;; we have c-state-cache, that heuristic isn't useful and only causes
553 ;; trouble, so turn it off.
554 ;; 2006/12/17: This facility is somewhat confused, and doesn't really seem
555 ;; helpful. Comment it out for now.
556 ;; (when (memq 'col-0-paren c-emacs-features)
557 ;; (make-local-variable 'open-paren-in-column-0-is-defun-start)
558 ;; (setq open-paren-in-column-0-is-defun-start nil))
560 (c-clear-found-types)
562 ;; now set the mode style based on default-style
563 (let ((style (cc-choose-style-for-mode mode default-style)))
564 ;; Override style variables if `c-old-style-variable-behavior' is
565 ;; set. Also override if we are using global style variables,
566 ;; have already initialized a style once, and are switching to a
567 ;; different style. (It's doubtful whether this is desirable, but
568 ;; the whole situation with nonlocal style variables is a bit
569 ;; awkward. It's at least the most compatible way with the old
570 ;; style init procedure.)
571 (c-set-style style (not (or c-old-style-variable-behavior
572 (and (not c-style-variables-are-local-p)
574 (not (string-equal c-indentation-style
576 (c-setup-paragraph-variables)
578 ;; we have to do something special for c-offsets-alist so that the
579 ;; buffer local value has its own alist structure.
580 (setq c-offsets-alist (copy-alist c-offsets-alist))
582 ;; setup the comment indent variable in a Emacs version portable way
583 (set (make-local-variable 'comment-indent-function) 'c-comment-indent)
585 ;; In Emacs 24.4 onwards, prevent Emacs's built in electric indentation from
586 ;; messing up CC Mode's, and set `c-electric-flag' if `electric-indent-mode'
587 ;; has been called by the user.
588 (when (boundp 'electric-indent-inhibit) (setq electric-indent-inhibit t))
589 ;; CC-mode should obey Emacs's generic preferences, tho only do it if
590 ;; Emacs's generic preferences can be set per-buffer (Emacs>=24.4).
591 (when (fboundp 'electric-indent-local-mode)
592 (setq c-electric-flag electric-indent-mode))
594 ;; ;; Put submode indicators onto minor-mode-alist, but only once.
595 ;; (or (assq 'c-submode-indicators minor-mode-alist)
596 ;; (setq minor-mode-alist
597 ;; (cons '(c-submode-indicators c-submode-indicators)
598 ;; minor-mode-alist)))
601 ;; Install the functions that ensure that various internal caches
602 ;; don't become invalid due to buffer changes.
603 (when (featurep 'xemacs)
604 (make-local-hook 'before-change-functions)
605 (make-local-hook 'after-change-functions))
606 (add-hook 'before-change-functions 'c-before-change nil t)
607 (add-hook 'after-change-functions 'c-after-change nil t)
608 (set (make-local-variable 'font-lock-extend-after-change-region-function)
609 'c-extend-after-change-region)) ; Currently (2009-05) used by all
610 ; languages with #define (C, C++,; ObjC), and by AWK.
612 (defun c-setup-doc-comment-style ()
613 "Initialize the variables that depend on the value of `c-doc-comment-style'."
614 (when (and (featurep 'font-lock)
615 (symbol-value 'font-lock-mode))
616 ;; Force font lock mode to reinitialize itself.
620 ;; Buffer local variables defining the region to be fontified by a font lock
621 ;; after-change function. They are set in c-after-change to
622 ;; after-change-functions' BEG and END, and may be modified by functions in
623 ;; `c-before-font-lock-functions'.
625 (make-variable-buffer-local 'c-new-BEG)
627 (make-variable-buffer-local 'c-new-END)
629 (defun c-common-init (&optional mode)
630 "Common initialization for all CC Mode modes.
631 In addition to the work done by `c-basic-common-init' and
632 `c-font-lock-init', this function sets up various other things as
633 customary in CC Mode modes but which aren't strictly necessary for CC
634 Mode to operate correctly.
636 MODE is the symbol for the mode to initialize, like 'c-mode. See
637 `c-basic-common-init' for details. It's only optional to be
638 compatible with old code; callers should always specify it."
641 ;; Called from an old third party package. The fallback is to
643 (c-init-language-vars-for 'c-mode))
645 (c-basic-common-init mode c-default-style)
647 ;; Only initialize font locking if we aren't called from an old package.
650 ;; Starting a mode is a sort of "change". So call the change functions...
653 (setq c-new-BEG (point-min))
654 (setq c-new-END (point-max))
657 (funcall fn (point-min) (point-max)))
658 c-get-state-before-change-functions)
660 (funcall fn (point-min) (point-max)
661 (- (point-max) (point-min))))
662 c-before-font-lock-functions)))
664 (set (make-local-variable 'outline-regexp) "[^#\n\^M]")
665 (set (make-local-variable 'outline-level) 'c-outline-level)
666 (set (make-local-variable 'add-log-current-defun-function)
668 (or (c-cpp-define-name) (c-defun-name))))
669 (let ((rfn (assq mode c-require-final-newline)))
672 (set (make-local-variable 'require-final-newline)
673 mode-require-final-newline)))))
675 (defun c-count-cfss (lv-alist)
676 ;; LV-ALIST is an alist like `file-local-variables-alist'. Count how many
677 ;; elements with the key `c-file-style' there are in it.
678 (let ((elt-ptr lv-alist) elt (cownt 0))
680 (setq elt (car elt-ptr)
681 elt-ptr (cdr elt-ptr))
682 (when (eq (car elt) 'c-file-style)
683 (setq cownt (1+ cownt))))
686 (defun c-before-hack-hook ()
687 "Set the CC Mode style and \"offsets\" when in the buffer's local variables.
688 They are set only when, respectively, the pseudo variables
689 `c-file-style' and `c-file-offsets' are present in the list.
691 This function is called from the hook `before-hack-local-variables-hook'."
692 (when c-buffer-is-cc-mode
693 (let ((mode-cons (assq 'mode file-local-variables-alist))
694 (stile (cdr (assq 'c-file-style file-local-variables-alist)))
695 (offsets (cdr (assq 'c-file-offsets file-local-variables-alist))))
697 (hack-one-local-variable (car mode-cons) (cdr mode-cons))
698 (setq file-local-variables-alist
699 (delq mode-cons file-local-variables-alist)))
701 (or (stringp stile) (error "c-file-style is not a string"))
702 (if (boundp 'dir-local-variables-alist)
703 ;; Determine whether `c-file-style' was set in the file's local
704 ;; variables or in a .dir-locals.el (a directory setting).
705 (let ((cfs-in-file-and-dir-count
706 (c-count-cfss file-local-variables-alist))
707 (cfs-in-dir-count (c-count-cfss dir-local-variables-alist)))
709 (and (= cfs-in-file-and-dir-count cfs-in-dir-count)
711 (c-set-style stile)))
715 (let ((langelem (car langentry))
716 (offset (cdr langentry)))
717 (c-set-offset langelem offset)))
720 (defun c-remove-any-local-eval-or-mode-variables ()
721 ;; If the buffer specifies `mode' or `eval' in its File Local Variable list
722 ;; or on the first line, remove all occurrences. See
723 ;; `c-postprocess-file-styles' for justification. There is no need to save
724 ;; point here, or even bother too much about the buffer contents. However,
725 ;; DON'T mess up the kill-ring.
727 ;; Most of the code here is derived from Emacs 21.3's `hack-local-variables'
729 (goto-char (point-max))
730 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move)
731 (let (lv-point (prefix "") (suffix ""))
732 (when (let ((case-fold-search t))
733 (search-forward "Local Variables:" nil t))
734 (setq lv-point (point))
735 ;; The prefix is what comes before "local variables:" in its line.
736 ;; The suffix is what comes after "local variables:" in its line.
737 (skip-chars-forward " \t")
739 (setq suffix (buffer-substring (point)
740 (progn (end-of-line) (point)))))
741 (goto-char (match-beginning 0))
744 (buffer-substring (point)
745 (progn (beginning-of-line) (point)))))
747 (while (search-forward-regexp
749 (regexp-quote prefix)
750 "\\(mode\\|eval\\):.*"
751 (regexp-quote suffix)
755 (delete-region (point) (progn (forward-line) (point)))))
757 ;; Delete the first line, if we've got one, in case it contains a mode spec.
758 (unless (and lv-point
759 (progn (goto-char lv-point)
762 (goto-char (point-min))
764 (delete-region (point) (progn (forward-line) (point)))))))
766 (defun c-postprocess-file-styles ()
767 "Function that post processes relevant file local variables in CC Mode.
768 Currently, this function simply applies any style and offset settings
769 found in the file's Local Variable list. It first applies any style
770 setting found in `c-file-style', then it applies any offset settings
771 it finds in `c-file-offsets'.
773 Note that the style variables are always made local to the buffer."
775 ;; apply file styles and offsets
776 (when c-buffer-is-cc-mode
777 (if (or c-file-style c-file-offsets)
778 (c-make-styles-buffer-local t))
780 (or (stringp c-file-style)
781 (error "c-file-style is not a string"))
782 (c-set-style c-file-style))
787 (let ((langelem (car langentry))
788 (offset (cdr langentry)))
789 (c-set-offset langelem offset)))
791 ;; Problem: The file local variable block might have explicitly set a
792 ;; style variable. The `c-set-style' or `mapcar' call might have
793 ;; overwritten this. So we run `hack-local-variables' again to remedy
794 ;; this. There are no guarantees this will work properly, particularly as
795 ;; we have no control over what the other hook functions on
796 ;; `hack-local-variables-hook' would have done. We now (2006/2/1) remove
797 ;; any `eval' or `mode' expressions before we evaluate again (see below).
800 ;; Problem (bug reported by Gustav Broberg): if one of the variables is
801 ;; `mode', this will invoke c-mode (etc.) again, setting up the style etc.
802 ;; We prevent this by temporarily removing `mode' from the Local Variables
804 (if (or c-file-style c-file-offsets)
805 (let ((hack-local-variables-hook nil) (inhibit-read-only t))
806 (c-tentative-buffer-changes
807 (c-remove-any-local-eval-or-mode-variables)
808 (hack-local-variables))
811 (if (boundp 'before-hack-local-variables-hook)
812 (add-hook 'before-hack-local-variables-hook 'c-before-hack-hook)
813 (add-hook 'hack-local-variables-hook 'c-postprocess-file-styles))
815 (defmacro c-run-mode-hooks (&rest hooks)
816 ;; Emacs 21.1 has introduced a system with delayed mode hooks that
817 ;; requires the use of the new function `run-mode-hooks'.
818 (if (cc-bytecomp-fboundp 'run-mode-hooks)
819 `(run-mode-hooks ,@hooks)
820 `(progn ,@(mapcar (lambda (hook) `(run-hooks ,hook)) hooks))))
823 ;;; Change hooks, linking with Font Lock and electric-indent-mode.
825 ;; Buffer local variables recording Beginning/End-of-Macro position before a
826 ;; change, when a macro straddles, respectively, the BEG or END (or both) of
827 ;; the change region. Otherwise these have the values BEG/END.
829 (make-variable-buffer-local 'c-old-BOM)
831 (make-variable-buffer-local 'c-old-EOM)
833 (defun c-extend-region-for-CPP (beg end)
834 ;; Set c-old-BOM or c-old-EOM respectively to BEG, END, each extended to the
835 ;; beginning/end of any preprocessor construct they may be in.
837 ;; Point is undefined both before and after this function call; the buffer
838 ;; has already been widened, and match-data saved. The return value is
841 ;; This function is in the C/C++/ObjC values of
842 ;; `c-get-state-before-change-functions' and is called exclusively as a
843 ;; before change function.
845 (c-beginning-of-macro)
846 (setq c-old-BOM (point))
849 (when (c-beginning-of-macro)
851 (or (eobp) (forward-char))) ; Over the terminating NL which may be marked
852 ; with a c-cpp-delimiter category property
853 (setq c-old-EOM (point)))
855 (defun c-extend-font-lock-region-for-macros (begg endd &optional old-len)
856 ;; Extend the region (BEGG ENDD) to cover all (possibly changed)
857 ;; preprocessor macros; return the cons (new-BEG . new-END). OLD-LEN should
858 ;; be either the old length parameter when called from an
859 ;; after-change-function, or nil otherwise. This defun uses the variables
860 ;; c-old-BOM, c-new-BOM.
862 ;; Point is undefined on both entry and exit to this function. The buffer
863 ;; will have been widened on entry.
864 (let (limits new-beg new-end)
865 (goto-char c-old-BOM) ; already set to old start of macro or begg.
868 (if (setq limits (c-state-literal-at (point)))
869 (cdr limits) ; go forward out of any string or comment.
873 (if (setq limits (c-state-literal-at (point)))
874 (goto-char (car limits))) ; go backward out of any string or comment.
875 (if (c-beginning-of-macro)
877 (setq new-end (max endd
879 (+ (- c-old-EOM old-len) (- endd begg))
882 (cons new-beg new-end)))
884 (defun c-neutralize-CPP-line (beg end)
885 ;; BEG and END bound a region, typically a preprocessor line. Put a
886 ;; "punctuation" syntax-table property on syntactically obtrusive
887 ;; characters, ones which would interact syntactically with stuff outside
890 ;; These are unmatched string delimiters, or unmatched
891 ;; parens/brackets/braces. An unclosed comment is regarded as valid, NOT
897 (setq s (parse-partial-sexp beg end -1))
899 ((< (nth 0 s) 0) ; found an unmated ),},]
900 (c-put-char-property (1- (point)) 'syntax-table '(1))
902 ((nth 3 s) ; In a string
903 (c-put-char-property (nth 8 s) 'syntax-table '(1))
905 ((> (nth 0 s) 0) ; In a (,{,[
906 (c-put-char-property (nth 1 s) 'syntax-table '(1))
910 (defun c-neutralize-syntax-in-and-mark-CPP (begg endd old-len)
911 ;; (i) Extend the font lock region to cover all changed preprocessor
912 ;; regions; it does this by setting the variables `c-new-BEG' and
913 ;; `c-new-END' to the new boundaries.
915 ;; (ii) "Neutralize" every preprocessor line wholly or partially in the
916 ;; extended changed region. "Restore" lines which were CPP lines before the
917 ;; change and are no longer so; these can be located from the Buffer local
918 ;; variables `c-old-BOM' and `c-old-EOM'.
920 ;; (iii) Mark every CPP construct by placing a `category' property value
921 ;; `c-cpp-delimiter' at its start and end. The marked characters are the
922 ;; opening # and usually the terminating EOL, but sometimes the character
923 ;; before a comment/string delimiter.
925 ;; That is, set syntax-table properties on characters that would otherwise
926 ;; interact syntactically with those outside the CPP line(s).
928 ;; This function is called from an after-change function, BEGG ENDD and
929 ;; OLD-LEN being the standard parameters. It prepares the buffer for font
930 ;; locking, hence must get called before `font-lock-after-change-function'.
932 ;; Point is undefined both before and after this function call, the buffer
933 ;; has been widened, and match-data saved. The return value is ignored.
935 ;; This function is in the C/C++/ObjC value of `c-before-font-lock-functions'.
937 ;; Note: SPEED _MATTERS_ IN THIS FUNCTION!!!
939 ;; This function might make hidden buffer changes.
940 (c-save-buffer-state (new-bounds)
941 ;; First determine the region, (c-new-BEG c-new-END), which will get font
942 ;; locked. It might need "neutralizing". This region may not start
943 ;; inside a string, comment, or macro.
944 (setq new-bounds (c-extend-font-lock-region-for-macros
945 c-new-BEG c-new-END old-len))
946 (setq c-new-BEG (max (car new-bounds) (c-determine-limit 500 begg))
947 c-new-END (min (cdr new-bounds) (c-determine-+ve-limit 500 endd)))
948 ;; Clear all old relevant properties.
949 (c-clear-char-property-with-value c-new-BEG c-new-END 'syntax-table '(1))
950 (c-clear-char-property-with-value c-new-BEG c-new-END 'category 'c-cpp-delimiter)
951 ;; FIXME!!! What about the "<" and ">" category properties? 2009-11-16
953 ;; Add needed properties to each CPP construct in the region.
954 (goto-char c-new-BEG)
955 (skip-chars-backward " \t")
956 (let ((pps-position (point)) pps-state mbeg)
957 (while (and (< (point) c-new-END)
958 (search-forward-regexp c-anchored-cpp-prefix c-new-END t))
959 ;; If we've found a "#" inside a string/comment, ignore it.
961 (parse-partial-sexp pps-position (point) nil nil pps-state)
962 pps-position (point))
963 (unless (or (nth 3 pps-state) ; in a string?
964 (nth 4 pps-state)) ; in a comment?
965 (goto-char (match-beginning 1))
967 (if (> (c-syntactic-end-of-macro) mbeg)
969 (c-neutralize-CPP-line mbeg (point))
970 (c-set-cpp-delimiters mbeg (point)))
971 (forward-line)) ; no infinite loop with, e.g., "#//"
974 (defun c-before-change (beg end)
975 ;; Function to be put on `before-change-functions'. Primarily, this calls
976 ;; the language dependent `c-get-state-before-change-functions'. It is
977 ;; otherwise used only to remove stale entries from the `c-found-types'
978 ;; cache, and to record entries which a `c-after-change' function might
981 ;; Note that this function must be FAST rather than accurate. Note
982 ;; also that it only has any effect when font locking is enabled.
983 ;; We exploit this by checking for font-lock-*-face instead of doing
984 ;; rigorous syntactic analysis.
986 ;; If either change boundary is wholly inside an identifier, delete
987 ;; it/them from the cache. Don't worry about being inside a string
988 ;; or a comment - "wrongly" removing a symbol from `c-found-types'
990 (setq c-maybe-stale-found-type nil)
995 ;; Are we inserting/deleting stuff in the middle of an identifier?
996 (c-unfind-enclosing-token beg)
997 (c-unfind-enclosing-token end)
998 ;; Are we coalescing two tokens together, e.g. "fo o" -> "foo"?
1000 (c-unfind-coalesced-tokens beg end))
1001 ;; Are we (potentially) disrupting the syntactic context which
1002 ;; makes a type a type? E.g. by inserting stuff after "foo" in
1003 ;; "foo bar;", or before "foo" in "typedef foo *bar;"?
1005 ;; We search for appropriate c-type properties "near" the change.
1006 ;; First, find an appropriate boundary for this property search.
1011 (or (and (eq (get-text-property end 'face) 'font-lock-comment-face)
1012 (previous-single-property-change end 'face))
1014 (when (>= end1 beg) ; Don't hassle about changes entirely in comments.
1015 ;; Find a limit for the search for a `c-type' property
1017 (and (/= (skip-chars-backward "^;{}") 0)
1018 (> (point) (point-min))
1019 (memq (c-get-char-property (1- (point)) 'face)
1020 '(font-lock-comment-face font-lock-string-face))))
1021 (setq lim (max (point-min) (1- (point))))
1023 ;; Look for the latest `c-type' property before end1
1024 (when (and (> end1 (point-min))
1026 (if (get-text-property (1- end1) 'c-type)
1028 (previous-single-property-change end1 'c-type nil lim))))
1029 (setq type (get-text-property (max (1- type-pos) lim) 'c-type))
1031 (when (memq type '(c-decl-id-start c-decl-type-start))
1032 ;; Get the identifier, if any, that the property is on.
1033 (goto-char (1- type-pos))
1035 (when (looking-at "\\(\\sw\\|\\s_\\)")
1036 (c-beginning-of-current-token)
1037 (buffer-substring-no-properties (point) type-pos)))
1040 (skip-chars-forward "^;{}") ; FIXME!!! loop for comment, maybe
1043 (or (next-single-property-change end 'c-type nil lim) lim))
1044 (setq c-maybe-stale-found-type
1045 (list type marked-id
1047 (buffer-substring-no-properties type-pos term-pos)
1048 (buffer-substring-no-properties beg end)))))))
1050 (if c-get-state-before-change-functions
1051 (let (open-paren-in-column-0-is-defun-start)
1053 (funcall fn beg end))
1054 c-get-state-before-change-functions)))
1056 ;; The following must be done here rather than in `c-after-change' because
1057 ;; newly inserted parens would foul up the invalidation algorithm.
1058 (c-invalidate-state-cache beg))
1060 (defvar c-in-after-change-fontification nil)
1061 (make-variable-buffer-local 'c-in-after-change-fontification)
1062 ;; A flag to prevent region expanding stuff being done twice for after-change
1065 (defun c-after-change (beg end old-len)
1066 ;; Function put on `after-change-functions' to adjust various caches
1067 ;; etc. Prefer speed to finesse here, since there will be an order
1068 ;; of magnitude more calls to this function than any of the
1069 ;; functions that use the caches.
1071 ;; Note that care must be taken so that this is called before any
1072 ;; font-lock callbacks since we might get calls to functions using
1073 ;; these caches from inside them, and we must thus be sure that this
1074 ;; has already been executed.
1076 ;; This calls the language variable c-before-font-lock-functions, if non nil.
1077 ;; This typically sets `syntax-table' properties.
1079 (c-save-buffer-state (case-fold-search open-paren-in-column-0-is-defun-start)
1080 ;; When `combine-after-change-calls' is used we might get calls
1081 ;; with regions outside the current narrowing. This has been
1082 ;; observed in Emacs 20.7.
1084 (save-match-data ; c-recognize-<>-arglists changes match-data
1087 (when (> end (point-max))
1088 ;; Some emacsen might return positions past the end. This has been
1089 ;; observed in Emacs 20.7 when rereading a buffer changed on disk
1090 ;; (haven't been able to minimize it, but Emacs 21.3 appears to
1092 (setq end (point-max))
1096 ;; C-y is capable of spuriously converting category properties
1097 ;; c-</>-as-paren-syntax and c-cpp-delimiter into hard syntax-table
1098 ;; properties. Remove these when it happens.
1099 (c-clear-char-property-with-value beg end 'syntax-table
1100 c-<-as-paren-syntax)
1101 (c-clear-char-property-with-value beg end 'syntax-table
1102 c->-as-paren-syntax)
1103 (c-clear-char-property-with-value beg end 'syntax-table nil)
1105 (c-trim-found-types beg end old-len) ; maybe we don't need all of these.
1106 (c-invalidate-sws-region-after beg end)
1107 ;; (c-invalidate-state-cache beg) ; moved to `c-before-change'.
1108 (c-invalidate-find-decl-cache beg)
1110 (when c-recognize-<>-arglists
1111 (c-after-change-check-<>-operators beg end))
1113 ;; (c-new-BEG c-new-END) will be the region to fontify. It may become
1114 ;; larger than (beg end).
1117 (setq c-in-after-change-fontification t)
1120 (funcall fn beg end old-len))
1121 c-before-font-lock-functions))))))
1123 (defun c-set-fl-decl-start (pos)
1124 ;; If the beginning of the line containing POS is in the middle of a "local"
1125 ;; declaration (i.e. one which does not start outside of braces enclosing
1126 ;; POS, such as a struct), return the beginning of that declaration.
1127 ;; Otherwise return POS. Note that declarations, in this sense, can be
1130 ;; This function is called indirectly from font locking stuff - either from
1131 ;; c-after-change (to prepare for after-change font-locking) or from font
1132 ;; lock context (etc.) fontification.
1133 (let ((lit-limits (c-literal-limits))
1136 (goto-char (c-point 'bol new-pos))
1137 (when lit-limits ; Comment or string.
1138 (goto-char (car lit-limits)))
1139 (setq bod-lim (c-determine-limit 500))
1142 ;; Go to a less nested declaration each time round this loop.
1144 (eq (car (c-beginning-of-decl-1 bod-lim)) 'same)
1145 (progn (setq bo-decl (point))
1146 ;; Are we looking at a keyword such as "template" or
1147 ;; "typedef" which can decorate a type, or the type itself?
1148 (when (or (looking-at c-prefix-spec-kwds-re)
1150 ;; We've found another candidate position.
1151 (setq new-pos (min new-pos bo-decl))
1152 (goto-char bo-decl))
1154 ;; Try and go out a level to search again.
1156 (c-backward-syntactic-ws bod-lim)
1157 (and (> (point) bod-lim)
1158 (or (memq (char-before) '(?\( ?\[))
1159 (and (eq (char-before) ?\<)
1160 (eq (c-get-char-property
1161 (1- (point)) 'syntax-table)
1162 c-<-as-paren-syntax)))))
1165 new-pos)) ; back over (, [, <.
1167 (defun c-change-set-fl-decl-start (_beg _end _old-len)
1168 ;; Set c-new-BEG to the beginning of a "local" declaration if it('s BOL) is
1169 ;; inside one. This is called from an after-change-function, but the
1170 ;; parameters BEG END and OLD-LEN are ignored. See `c-set-fl-decl-start'
1171 ;; for the detailed functionality.
1173 (setq c-new-BEG (c-set-fl-decl-start c-new-BEG))))
1175 (defun c-context-set-fl-decl-start (beg end)
1176 ;; Return a cons (NEW-BEG . END), where NEW-BEG is the beginning of a
1177 ;; "local" declaration (BOL at) NEW is inside or BEG. See
1178 ;; `c-set-fl-decl-start' for the detailed functionality.
1179 (cons (c-set-fl-decl-start beg) end))
1181 (defun c-font-lock-fontify-region (beg end &optional verbose)
1182 ;; Effectively advice around `font-lock-fontify-region' which extends the
1183 ;; region (BEG END), for example, to avoid context fontification chopping
1184 ;; off the start of the context. Do not do anything if it's already been
1185 ;; done (i.e. from an after-change fontification. An example (C++) where
1186 ;; this used to happen is this:
1188 ;; template <typename T>
1191 ;; void myfunc(T* p) {}
1193 ;; Type a space in the first blank line, and the fontification of the next
1194 ;; line was fouled up by context fontification.
1195 (let ((new-beg beg) (new-end end) new-region case-fold-search
1196 open-paren-in-column-0-is-defun-start)
1197 (if c-in-after-change-fontification
1198 (setq c-in-after-change-fontification nil)
1203 (setq new-region (funcall fn new-beg new-end))
1204 (setq new-beg (car new-region) new-end (cdr new-region)))
1205 c-before-context-fontification-functions))))
1206 (funcall (default-value 'font-lock-fontify-region-function)
1207 new-beg new-end verbose)))
1209 (defun c-after-font-lock-init ()
1210 ;; Put on `font-lock-mode-hook'. This function ensures our after-change
1211 ;; function will get executed before the font-lock one.
1212 (remove-hook 'after-change-functions 'c-after-change t)
1213 (add-hook 'after-change-functions 'c-after-change nil t))
1215 (defun c-font-lock-init ()
1216 "Set up the font-lock variables for using the font-lock support in CC Mode.
1217 This does not load the font-lock package. Use after
1218 `c-basic-common-init' and after cc-fonts has been loaded.
1219 This function is called from `c-common-init', once per mode initialization."
1221 (set (make-local-variable 'font-lock-defaults)
1222 `(,(if (c-major-mode-is 'awk-mode)
1223 ;; awk-mode currently has only one font lock level.
1224 'awk-font-lock-keywords
1225 (mapcar 'c-mode-symbol
1226 '("font-lock-keywords" "font-lock-keywords-1"
1227 "font-lock-keywords-2" "font-lock-keywords-3")))
1229 ,c-identifier-syntax-modifications
1230 c-beginning-of-syntax
1231 (font-lock-mark-block-function
1232 . c-mark-function)))
1234 (make-local-variable 'font-lock-fontify-region-function)
1235 (setq font-lock-fontify-region-function 'c-font-lock-fontify-region)
1237 (if (featurep 'xemacs)
1238 (make-local-hook 'font-lock-mode-hook))
1239 (add-hook 'font-lock-mode-hook 'c-after-font-lock-init nil t))
1241 (defun c-extend-after-change-region (_beg _end _old-len)
1242 "Extend the region to be fontified, if necessary."
1243 ;; Note: the parameters are ignored here. This somewhat indirect
1244 ;; implementation exists because it is minimally different from the
1245 ;; stand-alone CC Mode which, lacking
1246 ;; font-lock-extend-after-change-region-function, is forced to use advice
1249 ;; Of the seven CC Mode languages, currently (2009-05) only C, C++, Objc
1250 ;; (the languages with #define) and AWK Mode make non-null use of this
1252 (cons c-new-BEG c-new-END))
1254 ;; Connect up to `electric-indent-mode' (Emacs 24.4 and later).
1255 (defun c-electric-indent-mode-hook ()
1256 ;; Emacs has en/disabled `electric-indent-mode'. Propagate this through to
1257 ;; each CC Mode buffer.
1259 (with-current-buffer buf
1260 (when c-buffer-is-cc-mode
1261 ;; Don't use `c-toggle-electric-state' here due to recursion.
1262 (setq c-electric-flag electric-indent-mode)
1263 (c-update-modeline))))
1266 (defun c-electric-indent-local-mode-hook ()
1267 ;; Emacs has en/disabled `electric-indent-local-mode' for this buffer.
1268 ;; Propagate this through to this buffer's value of `c-electric-flag'
1269 (when c-buffer-is-cc-mode
1270 (setq c-electric-flag electric-indent-mode)
1271 (c-update-modeline)))
1276 (defvar c-mode-syntax-table
1277 (funcall (c-lang-const c-make-mode-syntax-table c))
1278 "Syntax table used in c-mode buffers.")
1280 (c-define-abbrev-table 'c-mode-abbrev-table
1281 '(("else" "else" c-electric-continued-statement 0)
1282 ("while" "while" c-electric-continued-statement 0))
1283 "Abbreviation table used in c-mode buffers.")
1286 (let ((map (c-make-inherited-keymap)))
1287 ;; Add bindings which are only useful for C.
1288 (define-key map "\C-c\C-e" 'c-macro-expand)
1290 "Keymap used in c-mode buffers.")
1293 (easy-menu-define c-c-menu c-mode-map "C Mode Commands"
1294 (cons "C" (c-lang-const c-mode-menu c)))
1296 ;; In XEmacs >= 21.5 modes should add their own entries to
1297 ;; `auto-mode-alist'. The comment form of autoload is used to avoid
1298 ;; doing this on load. That since `add-to-list' prepends the value
1299 ;; which could cause it to clobber user settings. Later emacsen have
1300 ;; an append option, but it's not safe to use.
1302 ;; The extension ".C" is associated with C++ while the lowercase
1303 ;; variant goes with C. On case insensitive file systems, this means
1304 ;; that ".c" files also might open C++ mode if the C++ entry comes
1305 ;; first on `auto-mode-alist'. Thus we try to ensure that ".C" comes
1306 ;; after ".c", and since `add-to-list' adds the entry first we have to
1307 ;; add the ".C" entry first.
1308 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.\\(cc\\|hh\\)\\'" . c++-mode))
1309 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.[ch]\\(pp\\|xx\\|\\+\\+\\)\\'" . c++-mode))
1310 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.\\(CC?\\|HH?\\)\\'" . c++-mode))
1312 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.[ch]\\'" . c-mode))
1314 ;; NB: The following two associate yacc and lex files to C Mode, which
1315 ;; is not really suitable for those formats. Anyway, afaik there's
1316 ;; currently no better mode for them, and besides this is legacy.
1317 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.y\\(acc\\)?\\'" . c-mode))
1318 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.lex\\'" . c-mode))
1320 ;; Preprocessed files generated by C and C++ compilers.
1321 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.i\\'" . c-mode))
1322 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.ii\\'" . c++-mode))
1324 (unless (fboundp 'prog-mode) (defalias 'prog-mode 'fundamental-mode))
1327 (define-derived-mode c-mode prog-mode "C"
1328 "Major mode for editing K&R and ANSI C code.
1329 To submit a problem report, enter `\\[c-submit-bug-report]' from a
1330 c-mode buffer. This automatically sets up a mail buffer with version
1331 information already added. You just need to add a description of the
1332 problem, including a reproducible test case, and send the message.
1334 To see what version of CC Mode you are running, enter `\\[c-version]'.
1336 The hook `c-mode-common-hook' is run with no args at mode
1337 initialization, then `c-mode-hook'.
1341 (c-initialize-cc-mode t)
1342 (set-syntax-table c-mode-syntax-table)
1343 (setq local-abbrev-table c-mode-abbrev-table
1345 (use-local-map c-mode-map)
1346 (c-init-language-vars-for 'c-mode)
1347 (c-make-macro-with-semi-re) ; matches macro names whose expansion ends with ;
1348 (c-common-init 'c-mode)
1349 (easy-menu-add c-c-menu)
1350 (cc-imenu-init cc-imenu-c-generic-expression)
1351 (c-run-mode-hooks 'c-mode-common-hook 'c-mode-hook)
1352 (c-update-modeline))
1357 (defvar c++-mode-syntax-table
1358 (funcall (c-lang-const c-make-mode-syntax-table c++))
1359 "Syntax table used in c++-mode buffers.")
1361 (c-define-abbrev-table 'c++-mode-abbrev-table
1362 '(("else" "else" c-electric-continued-statement 0)
1363 ("while" "while" c-electric-continued-statement 0)
1364 ("catch" "catch" c-electric-continued-statement 0))
1365 "Abbreviation table used in c++-mode buffers.")
1367 (defvar c++-mode-map
1368 (let ((map (c-make-inherited-keymap)))
1369 ;; Add bindings which are only useful for C++.
1370 (define-key map "\C-c\C-e" 'c-macro-expand)
1371 (define-key map "\C-c:" 'c-scope-operator)
1372 (define-key map "<" 'c-electric-lt-gt)
1373 (define-key map ">" 'c-electric-lt-gt)
1375 "Keymap used in c++-mode buffers.")
1377 (easy-menu-define c-c++-menu c++-mode-map "C++ Mode Commands"
1378 (cons "C++" (c-lang-const c-mode-menu c++)))
1381 (define-derived-mode c++-mode prog-mode "C++"
1382 "Major mode for editing C++ code.
1383 To submit a problem report, enter `\\[c-submit-bug-report]' from a
1384 c++-mode buffer. This automatically sets up a mail buffer with
1385 version information already added. You just need to add a description
1386 of the problem, including a reproducible test case, and send the
1389 To see what version of CC Mode you are running, enter `\\[c-version]'.
1391 The hook `c-mode-common-hook' is run with no args at mode
1392 initialization, then `c++-mode-hook'.
1396 (c-initialize-cc-mode t)
1397 (set-syntax-table c++-mode-syntax-table)
1398 (setq local-abbrev-table c++-mode-abbrev-table
1400 (use-local-map c++-mode-map)
1401 (c-init-language-vars-for 'c++-mode)
1402 (c-make-macro-with-semi-re) ; matches macro names whose expansion ends with ;
1403 (c-common-init 'c++-mode)
1404 (easy-menu-add c-c++-menu)
1405 (cc-imenu-init cc-imenu-c++-generic-expression)
1406 (c-run-mode-hooks 'c-mode-common-hook 'c++-mode-hook)
1407 (c-update-modeline))
1410 ;; Support for Objective-C
1412 (defvar objc-mode-syntax-table
1413 (funcall (c-lang-const c-make-mode-syntax-table objc))
1414 "Syntax table used in objc-mode buffers.")
1416 (c-define-abbrev-table 'objc-mode-abbrev-table
1417 '(("else" "else" c-electric-continued-statement 0)
1418 ("while" "while" c-electric-continued-statement 0))
1419 "Abbreviation table used in objc-mode buffers.")
1421 (defvar objc-mode-map
1422 (let ((map (c-make-inherited-keymap)))
1423 ;; Add bindings which are only useful for Objective-C.
1424 (define-key map "\C-c\C-e" 'c-macro-expand)
1426 "Keymap used in objc-mode buffers.")
1428 (easy-menu-define c-objc-menu objc-mode-map "ObjC Mode Commands"
1429 (cons "ObjC" (c-lang-const c-mode-menu objc)))
1431 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.m\\'" . objc-mode))
1434 (define-derived-mode objc-mode prog-mode "ObjC"
1435 "Major mode for editing Objective C code.
1436 To submit a problem report, enter `\\[c-submit-bug-report]' from an
1437 objc-mode buffer. This automatically sets up a mail buffer with
1438 version information already added. You just need to add a description
1439 of the problem, including a reproducible test case, and send the
1442 To see what version of CC Mode you are running, enter `\\[c-version]'.
1444 The hook `c-mode-common-hook' is run with no args at mode
1445 initialization, then `objc-mode-hook'.
1449 (c-initialize-cc-mode t)
1450 (set-syntax-table objc-mode-syntax-table)
1451 (setq local-abbrev-table objc-mode-abbrev-table
1453 (use-local-map objc-mode-map)
1454 (c-init-language-vars-for 'objc-mode)
1455 (c-make-macro-with-semi-re) ; matches macro names whose expansion ends with ;
1456 (c-common-init 'objc-mode)
1457 (easy-menu-add c-objc-menu)
1458 (cc-imenu-init nil 'cc-imenu-objc-function)
1459 (c-run-mode-hooks 'c-mode-common-hook 'objc-mode-hook)
1460 (c-update-modeline))
1465 (defvar java-mode-syntax-table
1466 (funcall (c-lang-const c-make-mode-syntax-table java))
1467 "Syntax table used in java-mode buffers.")
1469 (c-define-abbrev-table 'java-mode-abbrev-table
1470 '(("else" "else" c-electric-continued-statement 0)
1471 ("while" "while" c-electric-continued-statement 0)
1472 ("catch" "catch" c-electric-continued-statement 0)
1473 ("finally" "finally" c-electric-continued-statement 0))
1474 "Abbreviation table used in java-mode buffers.")
1476 (defvar java-mode-map
1477 (let ((map (c-make-inherited-keymap)))
1478 ;; Add bindings which are only useful for Java.
1480 "Keymap used in java-mode buffers.")
1482 ;; Regexp trying to describe the beginning of a Java top-level
1483 ;; definition. This is not used by CC Mode, nor is it maintained
1484 ;; since it's practically impossible to write a regexp that reliably
1485 ;; matches such a construct. Other tools are necessary.
1486 (defconst c-Java-defun-prompt-regexp
1487 "^[ \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-*")
1489 (easy-menu-define c-java-menu java-mode-map "Java Mode Commands"
1490 (cons "Java" (c-lang-const c-mode-menu java)))
1492 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.java\\'" . java-mode))
1495 (define-derived-mode java-mode prog-mode "Java"
1496 "Major mode for editing Java code.
1497 To submit a problem report, enter `\\[c-submit-bug-report]' from a
1498 java-mode buffer. This automatically sets up a mail buffer with
1499 version information already added. You just need to add a description
1500 of the problem, including a reproducible test case, and send the
1503 To see what version of CC Mode you are running, enter `\\[c-version]'.
1505 The hook `c-mode-common-hook' is run with no args at mode
1506 initialization, then `java-mode-hook'.
1510 (c-initialize-cc-mode t)
1511 (set-syntax-table java-mode-syntax-table)
1512 (setq local-abbrev-table java-mode-abbrev-table
1514 (use-local-map java-mode-map)
1515 (c-init-language-vars-for 'java-mode)
1516 (c-common-init 'java-mode)
1517 (easy-menu-add c-java-menu)
1518 (cc-imenu-init cc-imenu-java-generic-expression)
1519 (c-run-mode-hooks 'c-mode-common-hook 'java-mode-hook)
1520 (c-update-modeline))
1523 ;; Support for CORBA's IDL language
1525 (defvar idl-mode-syntax-table
1526 (funcall (c-lang-const c-make-mode-syntax-table idl))
1527 "Syntax table used in idl-mode buffers.")
1529 (c-define-abbrev-table 'idl-mode-abbrev-table nil
1530 "Abbreviation table used in idl-mode buffers.")
1532 (defvar idl-mode-map
1533 (let ((map (c-make-inherited-keymap)))
1534 ;; Add bindings which are only useful for IDL.
1536 "Keymap used in idl-mode buffers.")
1538 (easy-menu-define c-idl-menu idl-mode-map "IDL Mode Commands"
1539 (cons "IDL" (c-lang-const c-mode-menu idl)))
1541 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.idl\\'" . idl-mode))
1544 (define-derived-mode idl-mode prog-mode "IDL"
1545 "Major mode for editing CORBA's IDL, PSDL and CIDL code.
1546 To submit a problem report, enter `\\[c-submit-bug-report]' from an
1547 idl-mode buffer. This automatically sets up a mail buffer with
1548 version information already added. You just need to add a description
1549 of the problem, including a reproducible test case, and send the
1552 To see what version of CC Mode you are running, enter `\\[c-version]'.
1554 The hook `c-mode-common-hook' is run with no args at mode
1555 initialization, then `idl-mode-hook'.
1559 (c-initialize-cc-mode t)
1560 (set-syntax-table idl-mode-syntax-table)
1561 (setq local-abbrev-table idl-mode-abbrev-table)
1562 (use-local-map idl-mode-map)
1563 (c-init-language-vars-for 'idl-mode)
1564 (c-common-init 'idl-mode)
1565 (easy-menu-add c-idl-menu)
1566 ;;(cc-imenu-init cc-imenu-idl-generic-expression) ;TODO
1567 (c-run-mode-hooks 'c-mode-common-hook 'idl-mode-hook)
1568 (c-update-modeline))
1573 (defvar pike-mode-syntax-table
1574 (funcall (c-lang-const c-make-mode-syntax-table pike))
1575 "Syntax table used in pike-mode buffers.")
1577 (c-define-abbrev-table 'pike-mode-abbrev-table
1578 '(("else" "else" c-electric-continued-statement 0)
1579 ("while" "while" c-electric-continued-statement 0))
1580 "Abbreviation table used in pike-mode buffers.")
1582 (defvar pike-mode-map
1583 (let ((map (c-make-inherited-keymap)))
1584 ;; Additional bindings.
1585 (define-key map "\C-c\C-e" 'c-macro-expand)
1587 "Keymap used in pike-mode buffers.")
1589 (easy-menu-define c-pike-menu pike-mode-map "Pike Mode Commands"
1590 (cons "Pike" (c-lang-const c-mode-menu pike)))
1592 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.\\(u?lpc\\|pike\\|pmod\\(\\.in\\)?\\)\\'" . pike-mode))
1593 ;;;###autoload (add-to-list 'interpreter-mode-alist '("pike" . pike-mode))
1596 (define-derived-mode pike-mode prog-mode "Pike"
1597 "Major mode for editing Pike code.
1598 To submit a problem report, enter `\\[c-submit-bug-report]' from a
1599 pike-mode buffer. This automatically sets up a mail buffer with
1600 version information already added. You just need to add a description
1601 of the problem, including a reproducible test case, and send the
1604 To see what version of CC Mode you are running, enter `\\[c-version]'.
1606 The hook `c-mode-common-hook' is run with no args at mode
1607 initialization, then `pike-mode-hook'.
1611 (c-initialize-cc-mode t)
1612 (set-syntax-table pike-mode-syntax-table)
1613 (setq local-abbrev-table pike-mode-abbrev-table
1615 (use-local-map pike-mode-map)
1616 (c-init-language-vars-for 'pike-mode)
1617 (c-common-init 'pike-mode)
1618 (easy-menu-add c-pike-menu)
1619 ;;(cc-imenu-init cc-imenu-pike-generic-expression) ;TODO
1620 (c-run-mode-hooks 'c-mode-common-hook 'pike-mode-hook)
1621 (c-update-modeline))
1626 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.awk\\'" . awk-mode))
1627 ;;;###autoload (add-to-list 'interpreter-mode-alist '("awk" . awk-mode))
1628 ;;;###autoload (add-to-list 'interpreter-mode-alist '("mawk" . awk-mode))
1629 ;;;###autoload (add-to-list 'interpreter-mode-alist '("nawk" . awk-mode))
1630 ;;;###autoload (add-to-list 'interpreter-mode-alist '("gawk" . awk-mode))
1632 (c-define-abbrev-table 'awk-mode-abbrev-table
1633 '(("else" "else" c-electric-continued-statement 0)
1634 ("while" "while" c-electric-continued-statement 0))
1635 "Abbreviation table used in awk-mode buffers.")
1637 (defvar awk-mode-map
1638 (let ((map (c-make-inherited-keymap)))
1639 ;; Add bindings which are only useful for awk.
1640 (define-key map "#" 'self-insert-command)
1641 (define-key map "/" 'self-insert-command)
1642 (define-key map "*" 'self-insert-command)
1643 (define-key map "\C-c\C-n" 'undefined) ; #if doesn't exist in awk.
1644 (define-key map "\C-c\C-p" 'undefined)
1645 (define-key map "\C-c\C-u" 'undefined)
1646 (define-key map "\M-a" 'c-beginning-of-statement) ; 2003/10/7
1647 (define-key map "\M-e" 'c-end-of-statement) ; 2003/10/7
1648 (define-key map "\C-\M-a" 'c-awk-beginning-of-defun)
1649 (define-key map "\C-\M-e" 'c-awk-end-of-defun)
1651 "Keymap used in awk-mode buffers.")
1653 (easy-menu-define c-awk-menu awk-mode-map "AWK Mode Commands"
1654 (cons "AWK" (c-lang-const c-mode-menu awk)))
1656 ;; (require 'cc-awk) brings these in.
1657 (defvar awk-mode-syntax-table)
1658 (declare-function c-awk-unstick-NL-prop "cc-awk" ())
1661 (define-derived-mode awk-mode prog-mode "AWK"
1662 "Major mode for editing AWK code.
1663 To submit a problem report, enter `\\[c-submit-bug-report]' from an
1664 awk-mode buffer. This automatically sets up a mail buffer with version
1665 information already added. You just need to add a description of the
1666 problem, including a reproducible test case, and send the message.
1668 To see what version of CC Mode you are running, enter `\\[c-version]'.
1670 The hook `c-mode-common-hook' is run with no args at mode
1671 initialization, then `awk-mode-hook'.
1675 ;; We need the next line to stop the macro defining
1676 ;; `awk-mode-syntax-table'. This would mask the real table which is
1677 ;; declared in cc-awk.el and hasn't yet been loaded.
1679 (require 'cc-awk) ; Added 2003/6/10.
1680 (c-initialize-cc-mode t)
1681 (set-syntax-table awk-mode-syntax-table)
1682 (setq local-abbrev-table awk-mode-abbrev-table
1684 (use-local-map awk-mode-map)
1685 (c-init-language-vars-for 'awk-mode)
1686 (c-common-init 'awk-mode)
1687 (c-awk-unstick-NL-prop)
1689 (c-run-mode-hooks 'c-mode-common-hook 'awk-mode-hook)
1690 (c-update-modeline))
1695 (defconst c-mode-help-address
1696 "bug-cc-mode@gnu.org"
1697 "Address(es) for CC Mode bug reports.")
1700 "Echo the current version of CC Mode in the minibuffer."
1702 (message "Using CC Mode version %s" c-version)
1703 (c-keep-region-active))
1705 (define-obsolete-variable-alias 'c-prepare-bug-report-hooks
1706 'c-prepare-bug-report-hook "24.3")
1707 (defvar c-prepare-bug-report-hook nil)
1709 ;; Dynamic variables used by reporter.
1710 (defvar reporter-prompt-for-summary-p)
1711 (defvar reporter-dont-compact-list)
1713 (defun c-submit-bug-report ()
1714 "Submit via mail a bug report on CC Mode."
1718 (let ((reporter-prompt-for-summary-p t)
1719 (reporter-dont-compact-list '(c-offsets-alist))
1720 (style c-indentation-style)
1721 (c-features c-emacs-features))
1723 (if (y-or-n-p "Do you want to submit a report on CC Mode? ")
1725 (reporter-submit-bug-report
1727 (concat "CC Mode " c-version " (" mode-name ")")
1730 '(c-buffer-is-cc-mode
1732 c-syntactic-indentation
1733 c-syntactic-indentation-in-macros
1735 c-auto-align-backslashes
1736 c-backspace-function
1738 c-electric-pound-behavior
1740 c-enable-xemacs-performance-kludge-p
1741 c-old-style-variable-behavior
1745 parse-sexp-ignore-comments
1746 parse-sexp-lookup-properties
1747 lookup-syntax-properties
1748 ;; A brain-damaged XEmacs only variable that, if
1749 ;; set to nil can cause all kinds of chaos.
1750 signal-error-on-buffer-boundary
1751 ;; Variables that affect line breaking and comments.
1761 adaptive-fill-regexp)
1763 (mapc (lambda (var) (unless (boundp var)
1764 (setq vars (delq var vars))))
1765 '(signal-error-on-buffer-boundary
1770 font-lock-maximum-decoration
1771 parse-sexp-lookup-properties
1772 lookup-syntax-properties))
1775 (run-hooks 'c-prepare-bug-report-hook)
1776 (insert (format "Buffer Style: %s\nc-emacs-features: %s\n"
1777 style c-features)))))))
1780 (cc-provide 'cc-mode)
1782 ;;; cc-mode.el ends here