Merge branch 'master' into comment-cache
[emacs.git] / lisp / progmodes / cc-mode.el
blobe2969c607a51b08843567a93fc8f0dad64900b1a
1 ;;; cc-mode.el --- major mode for editing C and similar languages
3 ;; Copyright (C) 1985, 1987, 1992-2017 Free Software Foundation, Inc.
5 ;; Authors: 2003- Alan Mackenzie
6 ;; 1998- Martin Stjernholm
7 ;; 1992-1999 Barry A. Warsaw
8 ;; 1987 Dave Detlefs
9 ;; 1987 Stewart Clamen
10 ;; 1985 Richard M. Stallman
11 ;; Maintainer: bug-cc-mode@gnu.org
12 ;; Created: a long, long, time ago. adapted from the original c-mode.el
13 ;; Keywords: c languages
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/>.
30 ;;; Commentary:
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
50 ;; cplus-md1.el..
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
70 ;; visiting
72 ;; http://lists.sourceforge.net/mailman/listinfo/cc-mode-announce
74 ;; Externally maintained major modes which use CC-mode's engine include:
75 ;; - cuda-mode
76 ;; - csharp-mode (https://github.com/josteink/csharp-mode)
77 ;; - haxe-mode
78 ;; - d-mode
79 ;; - dart-mode
80 ;; - cc-php-js-cs.el
81 ;; - php-mode
82 ;; - yang-mode
83 ;; - math-mode (mathematica)
84 ;; - unrealscript-mode
85 ;; - groovy-mode
87 ;;; Code:
89 ;; For Emacs < 22.2.
90 (eval-and-compile
91 (unless (fboundp 'declare-function) (defmacro declare-function (&rest _r))))
93 (eval-when-compile
94 (let ((load-path
95 (if (and (boundp 'byte-compile-dest-file)
96 (stringp byte-compile-dest-file))
97 (cons (file-name-directory byte-compile-dest-file) load-path)
98 load-path)))
99 (load "cc-bytecomp" nil t)))
101 (cc-require 'cc-defs)
102 (cc-require 'cc-vars)
103 (cc-require-when-compile 'cc-langs)
104 (cc-require 'cc-engine)
105 (cc-require 'cc-styles)
106 (cc-require 'cc-cmds)
107 (cc-require 'cc-align)
108 (cc-require 'cc-menus)
109 (cc-require 'cc-guess)
111 ;; Silence the compiler.
112 (cc-bytecomp-defvar adaptive-fill-first-line-regexp) ; Emacs
113 (cc-bytecomp-defun run-mode-hooks) ; Emacs 21.1
115 ;; We set this variable during mode init, yet we don't require
116 ;; font-lock.
117 (cc-bytecomp-defvar font-lock-defaults)
119 ;; Menu support for both XEmacs and Emacs. If you don't have easymenu
120 ;; with your version of Emacs, you are incompatible!
121 (cc-external-require 'easymenu)
123 ;; Load cc-fonts first after font-lock is loaded, since it isn't
124 ;; necessary until font locking is requested.
125 ; (eval-after-load "font-lock" ; 2006-07-09: font-lock is now preloaded.
127 (require 'cc-fonts) ;)
130 ;; Other modes and packages which depend on CC Mode should do the
131 ;; following to make sure everything is loaded and available for their
132 ;; use:
134 ;; (require 'cc-mode)
136 ;; And in the major mode function:
138 ;; (c-initialize-cc-mode t)
139 ;; (c-init-language-vars some-mode)
140 ;; (c-common-init 'some-mode) ; Or perhaps (c-basic-common-init 'some-mode)
142 ;; If you're not writing a derived mode using the language variable
143 ;; system, then some-mode is one of the language modes directly
144 ;; supported by CC Mode. You can then use (c-init-language-vars-for
145 ;; 'some-mode) instead of `c-init-language-vars'.
146 ;; `c-init-language-vars-for' is a function that avoids the rather
147 ;; large expansion of `c-init-language-vars'.
149 ;; If you use `c-basic-common-init' then you might want to call
150 ;; `c-font-lock-init' too to set up CC Mode's font lock support.
152 ;; See cc-langs.el for further info. A small example of a derived mode
153 ;; is also available at <http://cc-mode.sourceforge.net/
154 ;; derived-mode-ex.el>.
156 (defun c-leave-cc-mode-mode ()
157 (when c-buffer-is-cc-mode
158 (save-restriction
159 (widen)
160 (c-save-buffer-state ()
161 (c-clear-char-properties (point-min) (point-max) 'category)
162 (c-clear-char-properties (point-min) (point-max) 'syntax-table)
163 (c-clear-char-properties (point-min) (point-max) 'c-is-sws)
164 (c-clear-char-properties (point-min) (point-max) 'c-in-sws)
165 (c-clear-char-properties (point-min) (point-max) 'c-type)
166 (if (c-major-mode-is 'awk-mode)
167 (c-clear-char-properties (point-min) (point-max) 'c-awk-NL-prop))))
168 (setq c-buffer-is-cc-mode nil)))
170 (defun c-init-language-vars-for (mode)
171 "Initialize the language variables for one of the language modes
172 directly supported by CC Mode. This can be used instead of the
173 `c-init-language-vars' macro if the language you want to use is one of
174 those, rather than a derived language defined through the language
175 variable system (see \"cc-langs.el\")."
176 (cond ((eq mode 'c-mode) (c-init-language-vars c-mode))
177 ((eq mode 'c++-mode) (c-init-language-vars c++-mode))
178 ((eq mode 'objc-mode) (c-init-language-vars objc-mode))
179 ((eq mode 'java-mode) (c-init-language-vars java-mode))
180 ((eq mode 'idl-mode) (c-init-language-vars idl-mode))
181 ((eq mode 'pike-mode) (c-init-language-vars pike-mode))
182 ((eq mode 'awk-mode) (c-init-language-vars awk-mode))
183 (t (error "Unsupported mode %s" mode))))
185 ;;;###autoload
186 (defun c-initialize-cc-mode (&optional new-style-init)
187 "Initialize CC Mode for use in the current buffer.
188 If the optional NEW-STYLE-INIT is nil or left out then all necessary
189 initialization to run CC Mode for the C language is done. Otherwise
190 only some basic setup is done, and a call to `c-init-language-vars' or
191 `c-init-language-vars-for' is necessary too (which gives more
192 control). See \"cc-mode.el\" for more info."
194 (setq c-buffer-is-cc-mode t)
196 (let ((initprop 'cc-mode-is-initialized)
197 c-initialization-ok)
198 (unless (get 'c-initialize-cc-mode initprop)
199 (unwind-protect
200 (progn
201 (put 'c-initialize-cc-mode initprop t)
202 (c-initialize-builtin-style)
203 (run-hooks 'c-initialization-hook)
204 ;; Fix obsolete variables.
205 (if (boundp 'c-comment-continuation-stars)
206 (setq c-block-comment-prefix c-comment-continuation-stars))
207 (add-hook 'change-major-mode-hook 'c-leave-cc-mode-mode)
208 (setq c-initialization-ok t)
209 ;; Connect up with Emacs's electric-indent-mode, for >= Emacs 24.4
210 (when (fboundp 'electric-indent-local-mode)
211 (add-hook 'electric-indent-mode-hook 'c-electric-indent-mode-hook)
212 (add-hook 'electric-indent-local-mode-hook
213 'c-electric-indent-local-mode-hook)))
214 ;; Will try initialization hooks again if they failed.
215 (put 'c-initialize-cc-mode initprop c-initialization-ok))))
217 (unless new-style-init
218 (c-init-language-vars-for 'c-mode)))
221 ;;; Common routines.
223 (defvar c-mode-base-map ()
224 "Keymap shared by all CC Mode related modes.")
226 (defun c-make-inherited-keymap ()
227 (let ((map (make-sparse-keymap)))
228 ;; Necessary to use `cc-bytecomp-fboundp' below since this
229 ;; function is called from top-level forms that are evaluated
230 ;; while cc-bytecomp is active when one does M-x eval-buffer.
231 (cond
232 ;; Emacs
233 ((cc-bytecomp-fboundp 'set-keymap-parent)
234 (set-keymap-parent map c-mode-base-map))
235 ;; XEmacs
236 ((fboundp 'set-keymap-parents)
237 (set-keymap-parents map c-mode-base-map))
238 ;; incompatible
239 (t (error "CC Mode is incompatible with this version of Emacs")))
240 map))
242 (defun c-define-abbrev-table (name defs &optional doc)
243 ;; Compatibility wrapper for `define-abbrev' which passes a non-nil
244 ;; sixth argument for SYSTEM-FLAG in emacsen that support it
245 ;; (currently only Emacs >= 21.2).
246 (let ((table (or (and (boundp name) (symbol-value name))
247 (progn (condition-case nil
248 (define-abbrev-table name nil doc)
249 (wrong-number-of-arguments ;E.g. Emacs<23.
250 (eval `(defvar ,name nil ,doc))
251 (define-abbrev-table name nil)))
252 (symbol-value name)))))
253 (while defs
254 (condition-case nil
255 (apply 'define-abbrev table (append (car defs) '(t)))
256 (wrong-number-of-arguments
257 (apply 'define-abbrev table (car defs))))
258 (setq defs (cdr defs)))))
259 (put 'c-define-abbrev-table 'lisp-indent-function 1)
261 (defun c-bind-special-erase-keys ()
262 ;; Only used in Emacs to bind C-c C-<delete> and C-c C-<backspace>
263 ;; to the proper keys depending on `normal-erase-is-backspace'.
264 (if normal-erase-is-backspace
265 (progn
266 (define-key c-mode-base-map (kbd "C-c C-<delete>")
267 'c-hungry-delete-forward)
268 (define-key c-mode-base-map (kbd "C-c C-<backspace>")
269 'c-hungry-delete-backwards))
270 (define-key c-mode-base-map (kbd "C-c C-<delete>")
271 'c-hungry-delete-backwards)
272 (define-key c-mode-base-map (kbd "C-c C-<backspace>")
273 'c-hungry-delete-forward)))
275 (if c-mode-base-map
278 (setq c-mode-base-map (make-sparse-keymap))
280 ;; Separate M-BS from C-M-h. The former should remain
281 ;; backward-kill-word.
282 (define-key c-mode-base-map [(control meta h)] 'c-mark-function)
283 (define-key c-mode-base-map "\e\C-q" 'c-indent-exp)
284 (substitute-key-definition 'backward-sentence
285 'c-beginning-of-statement
286 c-mode-base-map global-map)
287 (substitute-key-definition 'forward-sentence
288 'c-end-of-statement
289 c-mode-base-map global-map)
290 (substitute-key-definition 'indent-new-comment-line
291 'c-indent-new-comment-line
292 c-mode-base-map global-map)
293 (substitute-key-definition 'indent-for-tab-command
294 ;; XXX Is this the right thing to do
295 ;; here?
296 'c-indent-line-or-region
297 c-mode-base-map global-map)
298 (when (fboundp 'comment-indent-new-line)
299 ;; indent-new-comment-line has changed name to
300 ;; comment-indent-new-line in Emacs 21.
301 (substitute-key-definition 'comment-indent-new-line
302 'c-indent-new-comment-line
303 c-mode-base-map global-map))
305 ;; RMS says don't make these the default.
306 ;; (April 2006): RMS has now approved these commands as defaults.
307 (unless (memq 'argumentative-bod-function c-emacs-features)
308 (define-key c-mode-base-map "\e\C-a" 'c-beginning-of-defun)
309 (define-key c-mode-base-map "\e\C-e" 'c-end-of-defun))
311 (define-key c-mode-base-map "\C-c\C-n" 'c-forward-conditional)
312 (define-key c-mode-base-map "\C-c\C-p" 'c-backward-conditional)
313 (define-key c-mode-base-map "\C-c\C-u" 'c-up-conditional)
315 ;; It doesn't suffice to put `c-fill-paragraph' on
316 ;; `fill-paragraph-function' since `c-fill-paragraph' must be called
317 ;; before any fill prefix adaption is done. E.g. `filladapt-mode'
318 ;; replaces `fill-paragraph' and does the adaption before calling
319 ;; `fill-paragraph-function', and we have to mask comments etc
320 ;; before that. Also, `c-fill-paragraph' chains on to
321 ;; `fill-paragraph' and the value on `fill-paragraph-function' to
322 ;; do the actual filling work.
323 (substitute-key-definition 'fill-paragraph 'c-fill-paragraph
324 c-mode-base-map global-map)
325 ;; In XEmacs the default fill function is called
326 ;; fill-paragraph-or-region.
327 (substitute-key-definition 'fill-paragraph-or-region 'c-fill-paragraph
328 c-mode-base-map global-map)
330 ;; We bind the forward deletion key and (implicitly) C-d to
331 ;; `c-electric-delete-forward', and the backward deletion key to
332 ;; `c-electric-backspace'. The hungry variants are bound to the
333 ;; same keys but prefixed with C-c. This implies that C-c C-d is
334 ;; `c-hungry-delete-forward'. For consistency, we bind not only C-c
335 ;; <backspace> to `c-hungry-delete-backwards' but also
336 ;; C-c C-<backspace>, so that the Ctrl key can be held down during
337 ;; the whole sequence regardless of the direction. This in turn
338 ;; implies that we bind C-c C-<delete> to `c-hungry-delete-forward',
339 ;; for the same reason.
341 ;; Bind the electric deletion functions to C-d and DEL. Emacs 21
342 ;; automatically maps the [delete] and [backspace] keys to these two
343 ;; depending on window system and user preferences. (In earlier
344 ;; versions it's possible to do the same by using `function-key-map'.)
345 (define-key c-mode-base-map "\C-d" 'c-electric-delete-forward)
346 (define-key c-mode-base-map "\177" 'c-electric-backspace)
347 (define-key c-mode-base-map "\C-c\C-d" 'c-hungry-delete-forward)
348 (define-key c-mode-base-map [?\C-c ?\d] 'c-hungry-delete-backwards)
349 (define-key c-mode-base-map [?\C-c ?\C-\d] 'c-hungry-delete-backwards)
350 (define-key c-mode-base-map [?\C-c deletechar] 'c-hungry-delete-forward) ; C-c <delete> on a tty.
351 (define-key c-mode-base-map [?\C-c (control deletechar)] ; C-c C-<delete> on a tty.
352 'c-hungry-delete-forward)
353 (when (boundp 'normal-erase-is-backspace)
354 ;; The automatic C-d and DEL mapping functionality doesn't extend
355 ;; to special combinations like C-c C-<delete>, so we have to hook
356 ;; into the `normal-erase-is-backspace' system to bind it directly
357 ;; as appropriate.
358 (add-hook 'normal-erase-is-backspace-hook 'c-bind-special-erase-keys)
359 (c-bind-special-erase-keys))
361 (when (fboundp 'delete-forward-p)
362 ;; In XEmacs we fix the forward and backward deletion behavior by
363 ;; binding the keysyms for the [delete] and [backspace] keys
364 ;; directly, and use `delete-forward-p' to decide what [delete]
365 ;; should do. That's done in the XEmacs specific
366 ;; `c-electric-delete' and `c-hungry-delete' functions.
367 (define-key c-mode-base-map [delete] 'c-electric-delete)
368 (define-key c-mode-base-map [backspace] 'c-electric-backspace)
369 (define-key c-mode-base-map (kbd "C-c <delete>") 'c-hungry-delete)
370 (define-key c-mode-base-map (kbd "C-c C-<delete>") 'c-hungry-delete)
371 (define-key c-mode-base-map (kbd "C-c <backspace>")
372 'c-hungry-delete-backwards)
373 (define-key c-mode-base-map (kbd "C-c C-<backspace>")
374 'c-hungry-delete-backwards))
376 (define-key c-mode-base-map "#" 'c-electric-pound)
377 (define-key c-mode-base-map "{" 'c-electric-brace)
378 (define-key c-mode-base-map "}" 'c-electric-brace)
379 (define-key c-mode-base-map "/" 'c-electric-slash)
380 (define-key c-mode-base-map "*" 'c-electric-star)
381 (define-key c-mode-base-map ";" 'c-electric-semi&comma)
382 (define-key c-mode-base-map "," 'c-electric-semi&comma)
383 (define-key c-mode-base-map ":" 'c-electric-colon)
384 (define-key c-mode-base-map "(" 'c-electric-paren)
385 (define-key c-mode-base-map ")" 'c-electric-paren)
387 (define-key c-mode-base-map "\C-c\C-\\" 'c-backslash-region)
388 (define-key c-mode-base-map "\C-c\C-a" 'c-toggle-auto-newline)
389 (define-key c-mode-base-map "\C-c\C-b" 'c-submit-bug-report)
390 (define-key c-mode-base-map "\C-c\C-c" 'comment-region)
391 (define-key c-mode-base-map "\C-c\C-l" 'c-toggle-electric-state)
392 (define-key c-mode-base-map "\C-c\C-o" 'c-set-offset)
393 (define-key c-mode-base-map "\C-c\C-q" 'c-indent-defun)
394 (define-key c-mode-base-map "\C-c\C-s" 'c-show-syntactic-information)
395 ;; (define-key c-mode-base-map "\C-c\C-t" 'c-toggle-auto-hungry-state) Commented out by ACM, 2005-03-05.
396 (define-key c-mode-base-map "\C-c." 'c-set-style)
397 ;; conflicts with OOBR
398 ;;(define-key c-mode-base-map "\C-c\C-v" 'c-version)
399 ;; (define-key c-mode-base-map "\C-c\C-y" 'c-toggle-hungry-state) Commented out by ACM, 2005-11-22.
400 (define-key c-mode-base-map "\C-c\C-w" 'c-subword-mode)
403 ;; We don't require the outline package, but we configure it a bit anyway.
404 (cc-bytecomp-defvar outline-level)
406 (defun c-mode-menu (modestr)
407 "Return a menu spec suitable for `easy-menu-define' that is exactly
408 like the C mode menu except that the menu bar item name is MODESTR
409 instead of \"C\".
411 This function is provided for compatibility only; derived modes should
412 preferably use the `c-mode-menu' language constant directly."
413 (cons modestr (c-lang-const c-mode-menu c)))
415 ;; Ugly hack to pull in the definition of `c-populate-syntax-table'
416 ;; from cc-langs to make it available at runtime. It's either this or
417 ;; moving the definition for it to cc-defs, but that would mean to
418 ;; break up the syntax table setup over two files.
419 (defalias 'c-populate-syntax-table
420 (cc-eval-when-compile
421 (let ((f (symbol-function 'c-populate-syntax-table)))
422 (if (byte-code-function-p f) f (byte-compile f)))))
424 ;; CAUTION: Try to avoid installing things on
425 ;; `before-change-functions'. The macro `combine-after-change-calls'
426 ;; is used and it doesn't work if there are things on that hook. That
427 ;; can cause font lock functions to run in inconvenient places during
428 ;; temporary changes in some font lock support modes, causing extra
429 ;; unnecessary work and font lock glitches due to interactions between
430 ;; various text properties.
432 ;; (2007-02-12): The macro `combine-after-change-calls' ISN'T used any
433 ;; more.
435 (defun c-unfind-enclosing-token (pos)
436 ;; If POS is wholly inside a token, remove that id from
437 ;; `c-found-types', should it be present. Return t if we were in an
438 ;; id, else nil.
439 (save-excursion
440 (let ((tok-beg (progn (goto-char pos)
441 (and (c-beginning-of-current-token) (point))))
442 (tok-end (progn (goto-char pos)
443 (and (c-end-of-current-token) (point)))))
444 (when (and tok-beg tok-end)
445 (c-unfind-type (buffer-substring-no-properties tok-beg tok-end))
446 t))))
448 (defun c-unfind-coalesced-tokens (beg end)
449 ;; unless the non-empty region (beg end) is entirely WS and there's at
450 ;; least one character of WS just before or after this region, remove
451 ;; the tokens which touch the region from `c-found-types' should they
452 ;; be present.
453 (or (c-partial-ws-p beg end)
454 (save-excursion
455 (progn
456 (goto-char beg)
457 (or (eq beg (point-min))
458 (c-skip-ws-backward (1- beg))
459 (/= (point) beg)
460 (= (c-backward-token-2) 1)
461 (c-unfind-type (buffer-substring-no-properties
462 (point) beg)))
463 (goto-char end)
464 (or (eq end (point-max))
465 (c-skip-ws-forward (1+ end))
466 (/= (point) end)
467 (progn (forward-char) (c-end-of-current-token) nil)
468 (c-unfind-type (buffer-substring-no-properties
469 end (point))))))))
471 ;; c-maybe-stale-found-type records a place near the region being
472 ;; changed where an element of `found-types' might become stale. It
473 ;; is set in c-before-change and is either nil, or has the form:
475 ;; (c-decl-id-start "foo" 97 107 " (* ooka) " "o"), where
477 ;; o - `c-decl-id-start' is the c-type text property value at buffer
478 ;; pos 96.
480 ;; o - 97 107 is the region potentially containing the stale type -
481 ;; this is delimited by a non-nil c-type text property at 96 and
482 ;; either another one or a ";", "{", or "}" at 107.
484 ;; o - " (* ooka) " is the (before change) buffer portion containing
485 ;; the suspect type (here "ooka").
487 ;; o - "o" is the buffer contents which is about to be deleted. This
488 ;; would be the empty string for an insertion.
489 (defvar c-maybe-stale-found-type nil)
490 (make-variable-buffer-local 'c-maybe-stale-found-type)
492 (defvar c-just-done-before-change nil)
493 (make-variable-buffer-local 'c-just-done-before-change)
494 ;; This variable is set to t by `c-before-change' and to nil by
495 ;; `c-after-change'. It is used for two purposes: (i) to detect a spurious
496 ;; invocation of `before-change-functions' directly following on from a
497 ;; correct one. This happens in some Emacsen, for example when
498 ;; `basic-save-buffer' does (insert ?\n) when `require-final-newline' is
499 ;; non-nil; (ii) to detect when Emacs fails to invoke
500 ;; `before-change-functions'. This can happen when reverting a buffer - see
501 ;; bug #24094. It seems these failures happen only in GNU Emacs; XEmacs
502 ;; seems to maintain the strict alternation of calls to
503 ;; `before-change-functions' and `after-change-functions'.
505 (defun c-basic-common-init (mode default-style)
506 "Do the necessary initialization for the syntax handling routines
507 and the line breaking/filling code. Intended to be used by other
508 packages that embed CC Mode.
510 MODE is the CC Mode flavor to set up, e.g. `c-mode' or `java-mode'.
511 DEFAULT-STYLE tells which indentation style to install. It has the
512 same format as `c-default-style'.
514 Note that `c-init-language-vars' must be called before this function.
515 This function cannot do that since `c-init-language-vars' is a macro
516 that requires a literal mode spec at compile time."
518 (setq c-buffer-is-cc-mode mode)
520 ;; these variables should always be buffer local; they do not affect
521 ;; indentation style.
522 (make-local-variable 'comment-start)
523 (make-local-variable 'comment-end)
524 (make-local-variable 'comment-start-skip)
526 (make-local-variable 'paragraph-start)
527 (make-local-variable 'paragraph-separate)
528 (make-local-variable 'paragraph-ignore-fill-prefix)
529 (make-local-variable 'adaptive-fill-mode)
530 (make-local-variable 'adaptive-fill-regexp)
531 (make-local-variable 'fill-paragraph-handle-comment)
533 ;; now set their values
534 (set (make-local-variable 'parse-sexp-ignore-comments) t)
535 (set (make-local-variable 'indent-line-function) 'c-indent-line)
536 (set (make-local-variable 'indent-region-function) 'c-indent-region)
537 (set (make-local-variable 'normal-auto-fill-function) 'c-do-auto-fill)
538 (set (make-local-variable 'comment-multi-line) t)
539 (set (make-local-variable 'comment-line-break-function)
540 'c-indent-new-comment-line)
542 ;; Prevent time-wasting activity on C-y.
543 (when (boundp 'yank-handled-properties)
544 (make-local-variable 'yank-handled-properties)
545 (let ((yank-cat-handler (assq 'category yank-handled-properties)))
546 (when yank-cat-handler
547 (setq yank-handled-properties (remq yank-cat-handler
548 yank-handled-properties)))))
550 ;; For the benefit of adaptive file, which otherwise mis-fills.
551 (setq fill-paragraph-handle-comment nil)
553 ;; Install `c-fill-paragraph' on `fill-paragraph-function' so that a
554 ;; direct call to `fill-paragraph' behaves better. This still
555 ;; doesn't work with filladapt but it's better than nothing.
556 (set (make-local-variable 'fill-paragraph-function) 'c-fill-paragraph)
558 ;; Initialize the cache of brace pairs, and opening braces/brackets/parens.
559 (c-state-cache-init)
560 ;; Initialize the "brace stack" cache.
561 (c-init-bs-cache)
563 (when (or c-recognize-<>-arglists
564 (c-major-mode-is 'awk-mode)
565 (c-major-mode-is '(java-mode c-mode c++-mode objc-mode)))
566 ;; We'll use the syntax-table text property to change the syntax
567 ;; of some chars for this language, so do the necessary setup for
568 ;; that.
570 ;; Note to other package developers: It's ok to turn this on in CC
571 ;; Mode buffers when CC Mode doesn't, but it's not ok to turn it
572 ;; off if CC Mode has turned it on.
574 ;; Emacs.
575 (when (boundp 'parse-sexp-lookup-properties)
576 (set (make-local-variable 'parse-sexp-lookup-properties) t))
578 ;; Same as above for XEmacs.
579 (when (boundp 'lookup-syntax-properties)
580 (set (make-local-variable 'lookup-syntax-properties) t)))
582 ;; Use this in Emacs 21+ to avoid meddling with the rear-nonsticky
583 ;; property on each character.
584 (when (boundp 'text-property-default-nonsticky)
585 (make-local-variable 'text-property-default-nonsticky)
586 (mapc (lambda (tprop)
587 (unless (assq tprop text-property-default-nonsticky)
588 (setq text-property-default-nonsticky
589 (cons `(,tprop . t) text-property-default-nonsticky))))
590 '(syntax-table category c-type)))
592 ;; In Emacs 21 and later it's possible to turn off the ad-hoc
593 ;; heuristic that open parens in column 0 are defun starters. Since
594 ;; we have c-state-cache, that heuristic isn't useful and only causes
595 ;; trouble, so turn it off.
596 ;; 2006/12/17: This facility is somewhat confused, and doesn't really seem
597 ;; helpful. Comment it out for now.
598 ;; (when (memq 'col-0-paren c-emacs-features)
599 ;; (make-local-variable 'open-paren-in-column-0-is-defun-start)
600 ;; (setq open-paren-in-column-0-is-defun-start nil))
602 (c-clear-found-types)
604 ;; now set the mode style based on default-style
605 (let ((style (cc-choose-style-for-mode mode default-style)))
606 ;; Override style variables if `c-old-style-variable-behavior' is
607 ;; set. Also override if we are using global style variables,
608 ;; have already initialized a style once, and are switching to a
609 ;; different style. (It's doubtful whether this is desirable, but
610 ;; the whole situation with nonlocal style variables is a bit
611 ;; awkward. It's at least the most compatible way with the old
612 ;; style init procedure.)
613 (c-set-style style (not (or c-old-style-variable-behavior
614 (and (not c-style-variables-are-local-p)
615 c-indentation-style
616 (not (string-equal c-indentation-style
617 style)))))))
618 (c-setup-paragraph-variables)
620 ;; we have to do something special for c-offsets-alist so that the
621 ;; buffer local value has its own alist structure.
622 (setq c-offsets-alist (copy-alist c-offsets-alist))
624 ;; setup the comment indent variable in a Emacs version portable way
625 (set (make-local-variable 'comment-indent-function) 'c-comment-indent)
627 ;; In Emacs 24.4 onwards, prevent Emacs's built in electric indentation from
628 ;; messing up CC Mode's, and set `c-electric-flag' if `electric-indent-mode'
629 ;; has been called by the user.
630 (when (boundp 'electric-indent-inhibit) (setq electric-indent-inhibit t))
631 ;; CC-mode should obey Emacs's generic preferences, tho only do it if
632 ;; Emacs's generic preferences can be set per-buffer (Emacs>=24.4).
633 (when (fboundp 'electric-indent-local-mode)
634 (setq c-electric-flag electric-indent-mode))
636 ;; ;; Put submode indicators onto minor-mode-alist, but only once.
637 ;; (or (assq 'c-submode-indicators minor-mode-alist)
638 ;; (setq minor-mode-alist
639 ;; (cons '(c-submode-indicators c-submode-indicators)
640 ;; minor-mode-alist)))
641 (c-update-modeline)
643 ;; Install the functions that ensure that various internal caches
644 ;; don't become invalid due to buffer changes.
645 (when (featurep 'xemacs)
646 (make-local-hook 'before-change-functions)
647 (make-local-hook 'after-change-functions))
648 (add-hook 'before-change-functions 'c-before-change nil t)
649 (setq c-just-done-before-change nil)
650 (add-hook 'after-change-functions 'c-after-change nil t)
651 (when (boundp 'font-lock-extend-after-change-region-function)
652 (set (make-local-variable 'font-lock-extend-after-change-region-function)
653 'c-extend-after-change-region))) ; Currently (2009-05) used by all
654 ; languages with #define (C, C++,; ObjC), and by AWK.
656 (defun c-setup-doc-comment-style ()
657 "Initialize the variables that depend on the value of `c-doc-comment-style'."
658 (when (and (featurep 'font-lock)
659 (symbol-value 'font-lock-mode))
660 ;; Force font lock mode to reinitialize itself.
661 (font-lock-mode 0)
662 (font-lock-mode 1)))
664 ;; Buffer local variables defining the region to be fontified by a font lock
665 ;; after-change function. They are initialized in c-before-change to
666 ;; before-change-functions' BEG and END. `c-new-END' is amended in
667 ;; c-after-change with after-change-functions' BEG, END, and OLD-LEN. These
668 ;; variables may be modified by any before/after-change function, in
669 ;; particular by functions in `c-get-state-before-change-functions' and
670 ;; `c-before-font-lock-functions'.
671 (defvar c-new-BEG 0)
672 (make-variable-buffer-local 'c-new-BEG)
673 (defvar c-new-END 0)
674 (make-variable-buffer-local 'c-new-END)
675 ;; The following two variables record the values of `c-new-BEG' and
676 ;; `c-new-END' just after `c-new-END' has been adjusted for the length of text
677 ;; inserted or removed. They may be read by any after-change function (but
678 ;; should not be altered by one).
679 (defvar c-old-BEG 0)
680 (make-variable-buffer-local 'c-old-BEG)
681 (defvar c-old-END 0)
682 (make-variable-buffer-local 'c-old-END)
684 (defun c-common-init (&optional mode)
685 "Common initialization for all CC Mode modes.
686 In addition to the work done by `c-basic-common-init' and
687 `c-font-lock-init', this function sets up various other things as
688 customary in CC Mode modes but which aren't strictly necessary for CC
689 Mode to operate correctly.
691 MODE is the symbol for the mode to initialize, like `c-mode'. See
692 `c-basic-common-init' for details. It's only optional to be
693 compatible with old code; callers should always specify it."
695 (unless mode
696 ;; Called from an old third party package. The fallback is to
697 ;; initialize for C.
698 (c-init-language-vars-for 'c-mode))
700 (c-basic-common-init mode c-default-style)
701 (when mode
702 ;; Only initialize font locking if we aren't called from an old package.
703 (c-font-lock-init))
705 ;; Starting a mode is a sort of "change". So call the change functions...
706 (save-restriction
707 (widen)
708 (setq c-new-BEG (point-min))
709 (setq c-new-END (point-max))
710 (save-excursion
711 (let (before-change-functions after-change-functions)
712 (mapc (lambda (fn)
713 (funcall fn (point-min) (point-max)))
714 c-get-state-before-change-functions)
715 (mapc (lambda (fn)
716 (funcall fn (point-min) (point-max)
717 (- (point-max) (point-min))))
718 c-before-font-lock-functions))))
720 (set (make-local-variable 'outline-regexp) "[^#\n\^M]")
721 (set (make-local-variable 'outline-level) 'c-outline-level)
722 (set (make-local-variable 'add-log-current-defun-function)
723 (lambda ()
724 (or (c-cpp-define-name) (c-defun-name))))
725 (let ((rfn (assq mode c-require-final-newline)))
726 (when rfn
727 (if (boundp 'mode-require-final-newline)
728 (and (cdr rfn)
729 (set (make-local-variable 'require-final-newline)
730 mode-require-final-newline))
731 (set (make-local-variable 'require-final-newline) (cdr rfn))))))
733 (defun c-count-cfss (lv-alist)
734 ;; LV-ALIST is an alist like `file-local-variables-alist'. Count how many
735 ;; elements with the key `c-file-style' there are in it.
736 (let ((elt-ptr lv-alist) elt (cownt 0))
737 (while elt-ptr
738 (setq elt (car elt-ptr)
739 elt-ptr (cdr elt-ptr))
740 (when (eq (car elt) 'c-file-style)
741 (setq cownt (1+ cownt))))
742 cownt))
744 (defun c-before-hack-hook ()
745 "Set the CC Mode style and \"offsets\" when in the buffer's local variables.
746 They are set only when, respectively, the pseudo variables
747 `c-file-style' and `c-file-offsets' are present in the list.
749 This function is called from the hook `before-hack-local-variables-hook'."
750 (when c-buffer-is-cc-mode
751 (let ((mode-cons (assq 'mode file-local-variables-alist))
752 (stile (cdr (assq 'c-file-style file-local-variables-alist)))
753 (offsets (cdr (assq 'c-file-offsets file-local-variables-alist))))
754 (when mode-cons
755 (hack-one-local-variable (car mode-cons) (cdr mode-cons))
756 (setq file-local-variables-alist
757 (delq mode-cons file-local-variables-alist)))
758 (when stile
759 (or (stringp stile) (error "c-file-style is not a string"))
760 (if (boundp 'dir-local-variables-alist)
761 ;; Determine whether `c-file-style' was set in the file's local
762 ;; variables or in a .dir-locals.el (a directory setting).
763 (let ((cfs-in-file-and-dir-count
764 (c-count-cfss file-local-variables-alist))
765 (cfs-in-dir-count (c-count-cfss dir-local-variables-alist)))
766 (c-set-style stile
767 (and (= cfs-in-file-and-dir-count cfs-in-dir-count)
768 'keep-defaults)))
769 (c-set-style stile)))
770 (when offsets
771 (mapc
772 (lambda (langentry)
773 (let ((langelem (car langentry))
774 (offset (cdr langentry)))
775 (c-set-offset langelem offset)))
776 offsets)))))
778 (defun c-remove-any-local-eval-or-mode-variables ()
779 ;; If the buffer specifies `mode' or `eval' in its File Local Variable list
780 ;; or on the first line, remove all occurrences. See
781 ;; `c-postprocess-file-styles' for justification. There is no need to save
782 ;; point here, or even bother too much about the buffer contents. However,
783 ;; DON'T mess up the kill-ring.
785 ;; Most of the code here is derived from Emacs 21.3's `hack-local-variables'
786 ;; in files.el.
787 (goto-char (point-max))
788 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move)
789 (let (lv-point (prefix "") (suffix ""))
790 (when (let ((case-fold-search t))
791 (search-forward "Local Variables:" nil t))
792 (setq lv-point (point))
793 ;; The prefix is what comes before "local variables:" in its line.
794 ;; The suffix is what comes after "local variables:" in its line.
795 (skip-chars-forward " \t")
796 (or (eolp)
797 (setq suffix (buffer-substring (point)
798 (progn (end-of-line) (point)))))
799 (goto-char (match-beginning 0))
800 (or (bolp)
801 (setq prefix
802 (buffer-substring (point)
803 (progn (beginning-of-line) (point)))))
805 (while (search-forward-regexp
806 (concat "^[ \t]*"
807 (regexp-quote prefix)
808 "\\(mode\\|eval\\):.*"
809 (regexp-quote suffix)
810 "$")
811 nil t)
812 (forward-line 0)
813 (delete-region (point) (progn (forward-line) (point)))))
815 ;; Delete the first line, if we've got one, in case it contains a mode spec.
816 (unless (and lv-point
817 (progn (goto-char lv-point)
818 (forward-line 0)
819 (bobp)))
820 (goto-char (point-min))
821 (unless (eobp)
822 (delete-region (point) (progn (forward-line) (point)))))))
824 (defun c-postprocess-file-styles ()
825 "Function that post processes relevant file local variables in CC Mode.
826 Currently, this function simply applies any style and offset settings
827 found in the file's Local Variable list. It first applies any style
828 setting found in `c-file-style', then it applies any offset settings
829 it finds in `c-file-offsets'.
831 Note that the style variables are always made local to the buffer."
833 ;; apply file styles and offsets
834 (when c-buffer-is-cc-mode
835 (if (or c-file-style c-file-offsets)
836 (c-make-styles-buffer-local t))
837 (when c-file-style
838 (or (stringp c-file-style)
839 (error "c-file-style is not a string"))
840 (c-set-style c-file-style))
842 (and c-file-offsets
843 (mapc
844 (lambda (langentry)
845 (let ((langelem (car langentry))
846 (offset (cdr langentry)))
847 (c-set-offset langelem offset)))
848 c-file-offsets))
849 ;; Problem: The file local variable block might have explicitly set a
850 ;; style variable. The `c-set-style' or `mapcar' call might have
851 ;; overwritten this. So we run `hack-local-variables' again to remedy
852 ;; this. There are no guarantees this will work properly, particularly as
853 ;; we have no control over what the other hook functions on
854 ;; `hack-local-variables-hook' would have done. We now (2006/2/1) remove
855 ;; any `eval' or `mode' expressions before we evaluate again (see below).
856 ;; ACM, 2005/11/2.
858 ;; Problem (bug reported by Gustav Broberg): if one of the variables is
859 ;; `mode', this will invoke c-mode (etc.) again, setting up the style etc.
860 ;; We prevent this by temporarily removing `mode' from the Local Variables
861 ;; section.
862 (if (or c-file-style c-file-offsets)
863 (let ((hack-local-variables-hook nil) (inhibit-read-only t))
864 (c-tentative-buffer-changes
865 (c-remove-any-local-eval-or-mode-variables)
866 (hack-local-variables))
867 nil))))
869 (if (boundp 'before-hack-local-variables-hook)
870 (add-hook 'before-hack-local-variables-hook 'c-before-hack-hook)
871 (add-hook 'hack-local-variables-hook 'c-postprocess-file-styles))
873 (defmacro c-run-mode-hooks (&rest hooks)
874 ;; Emacs 21.1 has introduced a system with delayed mode hooks that
875 ;; requires the use of the new function `run-mode-hooks'.
876 (if (cc-bytecomp-fboundp 'run-mode-hooks)
877 `(run-mode-hooks ,@hooks)
878 `(progn ,@(mapcar (lambda (hook) `(run-hooks ,hook)) hooks))))
881 ;;; Change hooks, linking with Font Lock and electric-indent-mode.
883 (defun c-called-from-text-property-change-p ()
884 ;; Is the primitive which invoked `before-change-functions' or
885 ;; `after-change-functions' one which merely changes text properties? This
886 ;; function must be called directly from a member of one of the above hooks.
888 ;; In the following call, frame 0 is `backtrace-frame', frame 1 is
889 ;; `c-called-from-text-property-change-p', frame 2 is
890 ;; `c-before/after-change', frame 3 is the primitive invoking the change
891 ;; hook.
892 (memq (cadr (backtrace-frame 3))
893 '(put-text-property remove-list-of-text-properties)))
895 (defun c-depropertize-CPP (beg end)
896 ;; Remove the punctuation syntax-table text property from the CPP parts of
897 ;; (c-new-BEG c-new-END).
899 ;; This function is in the C/C++/ObjC values of
900 ;; `c-get-state-before-change-functions' and is called exclusively as a
901 ;; before change function.
902 (c-save-buffer-state (m-beg ss-found)
903 (goto-char c-new-BEG)
904 (while (and (< (point) beg)
905 (search-forward-regexp c-anchored-cpp-prefix beg 'bound))
906 (goto-char (match-beginning 1))
907 (setq m-beg (point))
908 (c-end-of-macro)
909 (c-clear-char-property-with-value m-beg (point) 'syntax-table '(1)))
911 (while (and (< (point) end)
912 (setq ss-found
913 (search-forward-regexp c-anchored-cpp-prefix end 'bound)))
914 (goto-char (match-beginning 1))
915 (setq m-beg (point))
916 (c-end-of-macro))
917 (if (and ss-found (> (point) end))
918 (c-clear-char-property-with-value m-beg (point) 'syntax-table '(1)))
920 (while (and (< (point) c-new-END)
921 (search-forward-regexp c-anchored-cpp-prefix c-new-END 'bound))
922 (goto-char (match-beginning 1))
923 (setq m-beg (point))
924 (c-end-of-macro)
925 (c-clear-char-property-with-value
926 m-beg (point) 'syntax-table '(1)))))
928 (defun c-extend-region-for-CPP (beg end)
929 ;; Adjust `c-new-BEG', `c-new-END' respectively to the beginning and end of
930 ;; any preprocessor construct they may be in.
932 ;; Point is undefined both before and after this function call; the buffer
933 ;; has already been widened, and match-data saved. The return value is
934 ;; meaningless.
936 ;; This function is in the C/C++/ObjC values of
937 ;; `c-get-state-before-change-functions' and is called exclusively as a
938 ;; before change function.
939 (goto-char c-new-BEG)
940 (c-beginning-of-macro)
941 (when (< (point) c-new-BEG)
942 (setq c-new-BEG (max (point) (c-determine-limit 500 c-new-BEG))))
944 (goto-char c-new-END)
945 (when (c-beginning-of-macro)
946 (c-end-of-macro)
947 (or (eobp) (forward-char))) ; Over the terminating NL which may be marked
948 ; with a c-cpp-delimiter category property
949 (when (> (point) c-new-END)
950 (setq c-new-END (min (point) (c-determine-+ve-limit 500 c-new-END)))))
952 (defun c-depropertize-new-text (beg end old-len)
953 ;; Remove from the new text in (BEG END) any and all text properties which
954 ;; might interfere with CC Mode's proper working.
956 ;; This function is called exclusively as an after-change function. It
957 ;; appears in the value (for all languages) of
958 ;; `c-before-font-lock-functions'. The value of point is undefined both on
959 ;; entry and exit, and the return value has no significance. The parameters
960 ;; BEG, END, and OLD-LEN are the standard ones supplied to all after-change
961 ;; functions.
962 (c-save-buffer-state ()
963 (when (> end beg)
964 (c-clear-char-properties beg end 'syntax-table)
965 (c-clear-char-properties beg end 'category)
966 (c-clear-char-properties beg end 'c-is-sws)
967 (c-clear-char-properties beg end 'c-in-sws)
968 (c-clear-char-properties beg end 'c-type)
969 (c-clear-char-properties beg end 'c-awk-NL-prop))))
971 (defun c-extend-font-lock-region-for-macros (begg endd old-len)
972 ;; Extend the region (c-new-BEG c-new-END) to cover all (possibly changed)
973 ;; preprocessor macros; The return value has no significance.
975 ;; Point is undefined on both entry and exit to this function. The buffer
976 ;; will have been widened on entry.
978 ;; c-new-BEG has already been extended in `c-extend-region-for-CPP' so we
979 ;; don't need to repeat the exercise here.
981 ;; This function is in the C/C++/ObjC value of `c-before-font-lock-functions'.
982 (goto-char endd)
983 (when (c-beginning-of-macro)
984 (c-end-of-macro)
985 ;; Determine the region, (c-new-BEG c-new-END), which will get font
986 ;; locked. This restricts the region should there be long macros.
987 (setq c-new-END (min (max c-new-END (point))
988 (c-determine-+ve-limit 500 c-new-END)))))
990 (defun c-neutralize-CPP-line (beg end)
991 ;; BEG and END bound a region, typically a preprocessor line. Put a
992 ;; "punctuation" syntax-table property on syntactically obtrusive
993 ;; characters, ones which would interact syntactically with stuff outside
994 ;; this region.
996 ;; These are unmatched string delimiters, or unmatched
997 ;; parens/brackets/braces. An unclosed comment is regarded as valid, NOT
998 ;; obtrusive.
999 (save-excursion
1000 (let (s)
1001 (while
1002 (progn
1003 (setq s (parse-partial-sexp beg end -1))
1004 (cond
1005 ((< (nth 0 s) 0) ; found an unmated ),},]
1006 (c-put-char-property (1- (point)) 'syntax-table '(1))
1008 ((nth 3 s) ; In a string
1009 (c-put-char-property (nth 8 s) 'syntax-table '(1))
1011 ((> (nth 0 s) 0) ; In a (,{,[
1012 (c-put-char-property (nth 1 s) 'syntax-table '(1))
1014 (t nil)))))))
1016 (defun c-neutralize-syntax-in-and-mark-CPP (begg endd old-len)
1017 ;; (i) "Neutralize" every preprocessor line wholly or partially in the
1018 ;; changed region. "Restore" lines which were CPP lines before the change
1019 ;; and are no longer so.
1021 ;; (ii) Mark each CPP construct by placing a `category' property value
1022 ;; `c-cpp-delimiter' at its start and end. The marked characters are the
1023 ;; opening # and usually the terminating EOL, but sometimes the character
1024 ;; before a comment delimiter.
1026 ;; That is, set syntax-table properties on characters that would otherwise
1027 ;; interact syntactically with those outside the CPP line(s).
1029 ;; This function is called from an after-change function, BEGG ENDD and
1030 ;; OLD-LEN being the standard parameters. It prepares the buffer for font
1031 ;; locking, hence must get called before `font-lock-after-change-function'.
1033 ;; Point is undefined both before and after this function call, the buffer
1034 ;; has been widened, and match-data saved. The return value is ignored.
1036 ;; This function is in the C/C++/ObjC value of `c-before-font-lock-functions'.
1038 ;; Note: SPEED _MATTERS_ IN THIS FUNCTION!!!
1040 ;; This function might make hidden buffer changes.
1041 (c-save-buffer-state (limits)
1042 ;; Clear 'syntax-table properties "punctuation":
1043 ;; (c-clear-char-property-with-value c-new-BEG c-new-END 'syntax-table '(1))
1045 ;; CPP "comment" markers:
1046 (if (eval-when-compile (memq 'category-properties c-emacs-features));Emacs.
1047 (c-clear-char-property-with-value
1048 c-new-BEG c-new-END 'category 'c-cpp-delimiter))
1049 ;; FIXME!!! What about the "<" and ">" category properties? 2009-11-16
1051 ;; Add needed properties to each CPP construct in the region.
1052 (goto-char c-new-BEG)
1053 (if (setq limits (c-literal-limits)) ; Go past any literal.
1054 (goto-char (cdr limits)))
1055 (skip-chars-backward " \t")
1056 (let ((pps-position (point)) pps-state mbeg)
1057 (while (and (< (point) c-new-END)
1058 (search-forward-regexp c-anchored-cpp-prefix c-new-END t))
1059 ;; If we've found a "#" inside a macro/string/comment, ignore it.
1060 (unless
1061 (or (save-excursion
1062 (goto-char (match-beginning 0))
1063 (let ((here (point)))
1064 (and (save-match-data (c-beginning-of-macro))
1065 (< (point) here))))
1066 (progn
1067 (setq pps-state
1068 (parse-partial-sexp pps-position (point) nil nil pps-state)
1069 pps-position (point))
1070 (or (nth 3 pps-state) ; in a string?
1071 (and (nth 4 pps-state)
1072 (not (eq (nth 7 pps-state) 'syntax-table)))))) ; in a comment?
1073 (goto-char (match-beginning 1))
1074 (setq mbeg (point))
1075 (if (> (c-no-comment-end-of-macro) mbeg)
1076 (progn
1077 (c-neutralize-CPP-line mbeg (point)) ; "punctuation" properties
1078 (if (eval-when-compile
1079 (memq 'category-properties c-emacs-features)) ;Emacs.
1080 (c-set-cpp-delimiters mbeg (point)))) ; "comment" markers
1081 (forward-line)) ; no infinite loop with, e.g., "#//"
1082 )))))
1084 (defun c-before-after-change-digit-quote (beg end &optional old-len)
1085 ;; This function either removes or applies the punctuation value ('(1)) of
1086 ;; the `syntax-table' text property on single quote marks which are
1087 ;; separator characters in long integer literals, e.g. "4'294'967'295". It
1088 ;; applies to both decimal/octal and hex literals. (FIXME (2016-06-10): it
1089 ;; should also apply to binary literals.)
1091 ;; In both uses of the function, the `syntax-table' properties are
1092 ;; removed/applied only on quote marks which appear to be digit separators.
1094 ;; Point is undefined on both entry and exit to this function, and the
1095 ;; return value has no significance. The function is called solely as a
1096 ;; before-change function (see `c-get-state-before-change-functions') and as
1097 ;; an after change function (see `c-before-font-lock-functions', with the
1098 ;; parameters BEG, END, and (optionally) OLD-LEN being given the standard
1099 ;; values for before/after-change functions.
1100 (c-save-buffer-state ((num-begin c-new-BEG) digit-re try-end)
1101 (goto-char c-new-END)
1102 (when (looking-at "\\(x\\)?[0-9a-fA-F']+")
1103 (setq c-new-END (match-end 0)))
1104 (goto-char c-new-BEG)
1105 (when (looking-at "\\(x?\\)[0-9a-fA-F']")
1106 (if (re-search-backward "\\(0x\\)?[0-9a-fA-F]*\\=" nil t)
1107 (setq c-new-BEG (point))))
1109 (while
1110 (re-search-forward "[0-9a-fA-F]'[0-9a-fA-F]" c-new-END t)
1111 (setq try-end (1- (point)))
1112 (re-search-backward "[^0-9a-fA-F']" num-begin t)
1113 (setq digit-re
1114 (cond
1115 ((and (not (bobp)) (eq (char-before) ?0) (memq (char-after) '(?x ?X)))
1116 "[0-9a-fA-F]")
1117 ((and (eq (char-after (1+ (point))) ?0)
1118 (memq (char-after (+ 2 (point))) '(?b ?B)))
1119 "[01]")
1120 ((memq (char-after (1+ (point))) '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9))
1121 "[0-9]")
1122 (t nil)))
1123 (when digit-re
1124 (cond ((eq (char-after) ?x) (forward-char))
1125 ((looking-at ".?0[Bb]") (goto-char (match-end 0)))
1126 ((looking-at digit-re))
1127 (t (forward-char)))
1128 (when (not (c-in-literal))
1129 (let ((num-end ; End of valid sequence of digits/quotes.
1130 (save-excursion
1131 (re-search-forward
1132 (concat "\\=\\(" digit-re "+'\\)*" digit-re "+") nil t)
1133 (point))))
1134 (setq try-end ; End of sequence of digits/quotes
1135 (save-excursion
1136 (re-search-forward
1137 (concat "\\=\\(" digit-re "\\|'\\)+") nil t)
1138 (point)))
1139 (while (re-search-forward
1140 (concat digit-re "\\('\\)" digit-re) num-end t)
1141 (if old-len ; i.e. are we in an after-change function?
1142 (c-put-char-property (match-beginning 1) 'syntax-table '(1))
1143 (c-clear-char-property (match-beginning 1) 'syntax-table))
1144 (backward-char)))))
1145 (goto-char try-end)
1146 (setq num-begin (point)))))
1148 ;; The following doesn't seem needed at the moment (2016-08-15).
1149 ;; (defun c-before-after-change-extend-region-for-lambda-capture
1150 ;; (_beg _end &optional _old-len)
1151 ;; ;; In C++ Mode, extend the region (c-new-BEG c-new-END) to cover any lambda
1152 ;; ;; function capture lists we happen to be inside. This function is expected
1153 ;; ;; to be called both as a before-change and after change function.
1154 ;; ;;
1155 ;; ;; Note that these things _might_ be nested, with a capture list looking
1156 ;; ;; like:
1157 ;; ;;
1158 ;; ;; [ ...., &foo = [..](){...}(..), ... ]
1159 ;; ;;
1160 ;; ;; . What a wonderful language is C++. ;-)
1161 ;; (c-save-buffer-state (paren-state pos)
1162 ;; (goto-char c-new-BEG)
1163 ;; (setq paren-state (c-parse-state))
1164 ;; (while (setq pos (c-pull-open-brace paren-state))
1165 ;; (goto-char pos)
1166 ;; (when (c-looking-at-c++-lambda-capture-list)
1167 ;; (setq c-new-BEG (min c-new-BEG pos))
1168 ;; (if (c-go-list-forward)
1169 ;; (setq c-new-END (max c-new-END (point))))))
1171 ;; (goto-char c-new-END)
1172 ;; (setq paren-state (c-parse-state))
1173 ;; (while (setq pos (c-pull-open-brace paren-state))
1174 ;; (goto-char pos)
1175 ;; (when (c-looking-at-c++-lambda-capture-list)
1176 ;; (setq c-new-BEG (min c-new-BEG pos))
1177 ;; (if (c-go-list-forward)
1178 ;; (setq c-new-END (max c-new-END (point))))))))
1180 (defun c-before-change (beg end)
1181 ;; Function to be put on `before-change-functions'. Primarily, this calls
1182 ;; the language dependent `c-get-state-before-change-functions'. It is
1183 ;; otherwise used only to remove stale entries from the `c-found-types'
1184 ;; cache, and to record entries which a `c-after-change' function might
1185 ;; confirm as stale.
1187 ;; Note that this function must be FAST rather than accurate. Note
1188 ;; also that it only has any effect when font locking is enabled.
1189 ;; We exploit this by checking for font-lock-*-face instead of doing
1190 ;; rigorous syntactic analysis.
1192 ;; If either change boundary is wholly inside an identifier, delete
1193 ;; it/them from the cache. Don't worry about being inside a string
1194 ;; or a comment - "wrongly" removing a symbol from `c-found-types'
1195 ;; isn't critical.
1196 (unless (or (c-called-from-text-property-change-p)
1197 c-just-done-before-change) ; guard against a spurious second
1198 ; invocation of before-change-functions.
1199 (setq c-just-done-before-change t)
1200 ;; (c-new-BEG c-new-END) will be the region to fontify.
1201 (setq c-new-BEG beg c-new-END end)
1202 (setq c-maybe-stale-found-type nil)
1203 (save-restriction
1204 (save-match-data
1205 (widen)
1206 (save-excursion
1207 ;; Are we inserting/deleting stuff in the middle of an identifier?
1208 (c-unfind-enclosing-token beg)
1209 (c-unfind-enclosing-token end)
1210 ;; Are we coalescing two tokens together, e.g. "fo o" -> "foo"?
1211 (when (< beg end)
1212 (c-unfind-coalesced-tokens beg end))
1213 (c-invalidate-sws-region-before end)
1214 ;; Are we (potentially) disrupting the syntactic context which
1215 ;; makes a type a type? E.g. by inserting stuff after "foo" in
1216 ;; "foo bar;", or before "foo" in "typedef foo *bar;"?
1218 ;; We search for appropriate c-type properties "near" the change.
1219 ;; First, find an appropriate boundary for this property search.
1220 (let (lim
1221 type type-pos
1222 marked-id term-pos
1223 (end1
1224 (or (and (eq (get-text-property end 'face)
1225 'font-lock-comment-face)
1226 (previous-single-property-change end 'face))
1227 end)))
1228 (when (>= end1 beg) ; Don't hassle about changes entirely in comments.
1229 ;; Find a limit for the search for a `c-type' property
1230 (while
1231 (and (/= (skip-chars-backward "^;{}") 0)
1232 (> (point) (point-min))
1233 (memq (c-get-char-property (1- (point)) 'face)
1234 '(font-lock-comment-face font-lock-string-face))))
1235 (setq lim (max (point-min) (1- (point))))
1237 ;; Look for the latest `c-type' property before end1
1238 (when (and (> end1 (point-min))
1239 (setq type-pos
1240 (if (get-text-property (1- end1) 'c-type)
1241 end1
1242 (previous-single-property-change end1 'c-type
1243 nil lim))))
1244 (setq type (get-text-property (max (1- type-pos) lim) 'c-type))
1246 (when (memq type '(c-decl-id-start c-decl-type-start))
1247 ;; Get the identifier, if any, that the property is on.
1248 (goto-char (1- type-pos))
1249 (setq marked-id
1250 (when (looking-at "\\(\\sw\\|\\s_\\)")
1251 (c-beginning-of-current-token)
1252 (buffer-substring-no-properties (point) type-pos)))
1254 (goto-char end1)
1255 (skip-chars-forward "^;{}") ;FIXME!!! loop for comment, maybe
1256 (setq lim (point))
1257 (setq term-pos
1258 (or (c-next-single-property-change end 'c-type nil lim)
1259 lim))
1260 (setq c-maybe-stale-found-type
1261 (list type marked-id
1262 type-pos term-pos
1263 (buffer-substring-no-properties type-pos
1264 term-pos)
1265 (buffer-substring-no-properties beg end)))))))
1267 (if c-get-state-before-change-functions
1268 (mapc (lambda (fn)
1269 (funcall fn beg end))
1270 c-get-state-before-change-functions))
1272 ;; The following must be done here rather than in `c-after-change' because
1273 ;; newly inserted parens would foul up the invalidation algorithm.
1274 (c-invalidate-state-cache beg)))
1276 (defvar c-in-after-change-fontification nil)
1277 (make-variable-buffer-local 'c-in-after-change-fontification)
1278 ;; A flag to prevent region expanding stuff being done twice for after-change
1279 ;; fontification.
1281 (defun c-after-change (beg end old-len)
1282 ;; Function put on `after-change-functions' to adjust various caches
1283 ;; etc. Prefer speed to finesse here, since there will be an order
1284 ;; of magnitude more calls to this function than any of the
1285 ;; functions that use the caches.
1287 ;; Note that care must be taken so that this is called before any
1288 ;; font-lock callbacks since we might get calls to functions using
1289 ;; these caches from inside them, and we must thus be sure that this
1290 ;; has already been executed.
1292 ;; This calls the language variable c-before-font-lock-functions, if non nil.
1293 ;; This typically sets `syntax-table' properties.
1295 ;; We can sometimes get two consecutive calls to `after-change-functions'
1296 ;; without an intervening call to `before-change-functions' when reverting
1297 ;; the buffer (see bug #24094). Whatever the cause, assume that the entire
1298 ;; buffer has changed.
1299 (when (not c-just-done-before-change)
1300 (save-restriction
1301 (widen)
1302 (c-before-change (point-min) (point-max))
1303 (setq beg (point-min)
1304 end (point-max)
1305 old-len (- end beg))))
1307 ;; (c-new-BEG c-new-END) will be the region to fontify. It may become
1308 ;; larger than (beg end).
1309 (setq c-new-END (- (+ c-new-END (- end beg)) old-len))
1310 (setq c-old-BEG c-new-BEG c-old-END c-new-END)
1312 (unless (c-called-from-text-property-change-p)
1313 (setq c-just-done-before-change nil)
1314 (c-save-buffer-state (case-fold-search)
1315 ;; When `combine-after-change-calls' is used we might get calls
1316 ;; with regions outside the current narrowing. This has been
1317 ;; observed in Emacs 20.7.
1318 (save-restriction
1319 (save-match-data ; c-recognize-<>-arglists changes match-data
1320 (widen)
1322 (when (> end (point-max))
1323 ;; Some emacsen might return positions past the end. This has been
1324 ;; observed in Emacs 20.7 when rereading a buffer changed on disk
1325 ;; (haven't been able to minimize it, but Emacs 21.3 appears to
1326 ;; work).
1327 (setq end (point-max))
1328 (when (> beg end)
1329 (setq beg end)))
1331 ;; C-y is capable of spuriously converting category properties
1332 ;; c-</>-as-paren-syntax and c-cpp-delimiter into hard syntax-table
1333 ;; properties. Remove these when it happens.
1334 (when (eval-when-compile (memq 'category-properties c-emacs-features))
1335 (c-save-buffer-state ()
1336 (c-clear-char-property-with-value beg end 'syntax-table
1337 c-<-as-paren-syntax)
1338 (c-clear-char-property-with-value beg end 'syntax-table
1339 c->-as-paren-syntax)
1340 (c-clear-char-property-with-value beg end 'syntax-table nil)))
1342 (c-trim-found-types beg end old-len) ; maybe we don't need all of these.
1343 (c-invalidate-sws-region-after beg end old-len)
1344 ;; (c-invalidate-state-cache beg) ; moved to `c-before-change'.
1345 (c-invalidate-find-decl-cache beg)
1347 (when c-recognize-<>-arglists
1348 (c-after-change-check-<>-operators beg end))
1350 (setq c-in-after-change-fontification t)
1351 (save-excursion
1352 (mapc (lambda (fn)
1353 (funcall fn beg end old-len))
1354 c-before-font-lock-functions)))))))
1356 (defun c-fl-decl-start (pos)
1357 ;; If the beginning of the line containing POS is in the middle of a "local"
1358 ;; declaration, return the beginning of that declaration. Otherwise return
1359 ;; nil. Note that declarations, in this sense, can be nested. (A local
1360 ;; declaration is one which does not start outside of struct braces (and
1361 ;; similar) enclosing POS. Brace list braces here are not "similar".
1363 ;; This function is called indirectly from font locking stuff - either from
1364 ;; c-after-change (to prepare for after-change font-locking) or from font
1365 ;; lock context (etc.) fontification.
1366 (let ((lit-start (c-literal-start))
1367 (new-pos pos)
1368 capture-opener
1369 bod-lim bo-decl)
1370 (goto-char (c-point 'bol new-pos))
1371 (when lit-start ; Comment or string.
1372 (goto-char lit-start))
1373 (setq bod-lim (c-determine-limit 500))
1375 ;; In C++ Mode, first check if we are within a (possibly nested) lambda
1376 ;; form capture list.
1377 (when (c-major-mode-is 'c++-mode)
1378 (let ((paren-state (c-parse-state))
1379 opener)
1380 (save-excursion
1381 (while (setq opener (c-pull-open-brace paren-state))
1382 (goto-char opener)
1383 (if (c-looking-at-c++-lambda-capture-list)
1384 (setq capture-opener (point)))))))
1386 (while
1387 ;; Go to a less nested declaration each time round this loop.
1388 (and
1389 (c-syntactic-skip-backward "^;{}" bod-lim t)
1390 (> (point) bod-lim)
1391 (progn (c-forward-syntactic-ws)
1392 (setq bo-decl (point))
1393 ;; Are we looking at a keyword such as "template" or
1394 ;; "typedef" which can decorate a type, or the type itself?
1395 (when (or (looking-at c-prefix-spec-kwds-re)
1396 (c-forward-type t))
1397 ;; We've found another candidate position.
1398 (setq new-pos (min new-pos bo-decl))
1399 (goto-char bo-decl))
1401 ;; Try and go out a level to search again.
1402 (progn
1403 (c-backward-syntactic-ws bod-lim)
1404 (and (> (point) bod-lim)
1405 (or (memq (char-before) '(?\( ?\[))
1406 (and (eq (char-before) ?\<)
1407 (eq (c-get-char-property
1408 (1- (point)) 'syntax-table)
1409 c-<-as-paren-syntax))
1410 (and (eq (char-before) ?{)
1411 (save-excursion
1412 (backward-char)
1413 (consp (c-looking-at-or-maybe-in-bracelist))))
1415 (not (bobp)))
1416 (backward-char)) ; back over (, [, <.
1417 (when (and capture-opener (< capture-opener new-pos))
1418 (setq new-pos capture-opener))
1419 (and (/= new-pos pos) new-pos)))
1421 (defun c-change-expand-fl-region (_beg _end _old-len)
1422 ;; Expand the region (c-new-BEG c-new-END) to an after-change font-lock
1423 ;; region. This will usually be the smallest sequence of whole lines
1424 ;; containing `c-new-BEG' and `c-new-END', but if `c-new-BEG' is in a
1425 ;; "local" declaration (see `c-fl-decl-start') the beginning of this is used
1426 ;; as the lower bound.
1428 ;; This is called from an after-change-function, but the parameters BEG END
1429 ;; and OLD-LEN are not used.
1430 (if font-lock-mode
1431 (setq c-new-BEG
1432 (or (c-fl-decl-start c-new-BEG) (c-point 'bol c-new-BEG))
1433 c-new-END
1434 (save-excursion
1435 (goto-char c-new-END)
1436 (if (bolp)
1437 (point)
1438 (c-point 'bonl c-new-END))))))
1440 (defun c-context-expand-fl-region (beg end)
1441 ;; Return a cons (NEW-BEG . NEW-END), where NEW-BEG is the beginning of a
1442 ;; "local" declaration containing BEG (see `c-fl-decl-start') or BOL BEG is
1443 ;; in. NEW-END is beginning of the line after the one END is in.
1444 (cons (or (c-fl-decl-start beg) (c-point 'bol beg))
1445 (c-point 'bonl end)))
1447 (defun c-before-context-fl-expand-region (beg end)
1448 ;; Expand the region (BEG END) as specified by
1449 ;; `c-before-context-fontification-functions'. Return a cons of the bounds
1450 ;; of the new region.
1451 (save-restriction
1452 (widen)
1453 (save-excursion
1454 (let ((new-beg beg) (new-end end)
1455 (new-region (cons beg end)))
1456 (mapc (lambda (fn)
1457 (setq new-region (funcall fn new-beg new-end))
1458 (setq new-beg (car new-region) new-end (cdr new-region)))
1459 c-before-context-fontification-functions)
1460 new-region))))
1462 (defun c-font-lock-fontify-region (beg end &optional verbose)
1463 ;; Effectively advice around `font-lock-fontify-region' which extends the
1464 ;; region (BEG END), for example, to avoid context fontification chopping
1465 ;; off the start of the context. Do not extend the region if it's already
1466 ;; been done (i.e. from an after-change fontification. An example (C++)
1467 ;; where the chopping off used to happen is this:
1469 ;; template <typename T>
1472 ;; void myfunc(T* p) {}
1474 ;; Type a space in the first blank line, and the fontification of the next
1475 ;; line was fouled up by context fontification.
1476 (let (new-beg new-end new-region case-fold-search)
1477 (if (and c-in-after-change-fontification
1478 (< beg c-new-END) (> end c-new-BEG))
1479 ;; Region and the latest after-change fontification region overlap.
1480 ;; Determine the upper and lower bounds of our adjusted region
1481 ;; separately.
1482 (progn
1483 (if (<= beg c-new-BEG)
1484 (setq c-in-after-change-fontification nil))
1485 (setq new-beg
1486 (if (and (>= beg (c-point 'bol c-new-BEG))
1487 (<= beg c-new-BEG))
1488 ;; Either jit-lock has accepted `c-new-BEG', or has
1489 ;; (probably) extended the change region spuriously to
1490 ;; BOL, which position likely has a syntactically
1491 ;; different position. To ensure correct fontification,
1492 ;; we start at `c-new-BEG', assuming any characters to the
1493 ;; left of `c-new-BEG' on the line do not require
1494 ;; fontification.
1495 c-new-BEG
1496 (setq new-region (c-before-context-fl-expand-region beg end)
1497 new-end (cdr new-region))
1498 (car new-region)))
1499 (setq new-end
1500 (if (and (>= end (c-point 'bol c-new-END))
1501 (<= end c-new-END))
1502 c-new-END
1503 (or new-end
1504 (cdr (c-before-context-fl-expand-region beg end))))))
1505 ;; Context (etc.) fontification.
1506 (setq new-region (c-before-context-fl-expand-region beg end)
1507 new-beg (car new-region) new-end (cdr new-region)))
1508 (funcall (default-value 'font-lock-fontify-region-function)
1509 new-beg new-end verbose)))
1511 (defun c-after-font-lock-init ()
1512 ;; Put on `font-lock-mode-hook'. This function ensures our after-change
1513 ;; function will get executed before the font-lock one.
1514 (when (memq #'c-after-change after-change-functions)
1515 (remove-hook 'after-change-functions #'c-after-change t)
1516 (add-hook 'after-change-functions #'c-after-change nil t)))
1518 (defun c-font-lock-init ()
1519 "Set up the font-lock variables for using the font-lock support in CC Mode.
1520 This does not load the font-lock package. Use after
1521 `c-basic-common-init' and after cc-fonts has been loaded.
1522 This function is called from `c-common-init', once per mode initialization."
1524 (set (make-local-variable 'font-lock-defaults)
1525 `(,(if (c-major-mode-is 'awk-mode)
1526 ;; awk-mode currently has only one font lock level.
1527 'awk-font-lock-keywords
1528 (mapcar 'c-mode-symbol
1529 '("font-lock-keywords" "font-lock-keywords-1"
1530 "font-lock-keywords-2" "font-lock-keywords-3")))
1531 nil nil
1532 ,c-identifier-syntax-modifications
1533 c-beginning-of-syntax
1534 (font-lock-mark-block-function
1535 . c-mark-function)))
1537 ;; Prevent `font-lock-default-fontify-region' extending the region it will
1538 ;; fontify to whole lines by removing `font-lock-extend-region-wholelines'
1539 ;; from `font-lock-extend-region-functions'. (Emacs only). This fixes
1540 ;; Emacs bug #19669.
1541 (when (boundp 'font-lock-extend-region-functions)
1542 (setq font-lock-extend-region-functions
1543 (delq 'font-lock-extend-region-wholelines
1544 font-lock-extend-region-functions)))
1546 (make-local-variable 'font-lock-fontify-region-function)
1547 (setq font-lock-fontify-region-function 'c-font-lock-fontify-region)
1549 (if (featurep 'xemacs)
1550 (make-local-hook 'font-lock-mode-hook))
1551 (add-hook 'font-lock-mode-hook 'c-after-font-lock-init nil t))
1553 ;; Emacs 22 and later.
1554 (defun c-extend-after-change-region (beg end _old-len)
1555 "Extend the region to be fontified, if necessary."
1556 ;; Note: the parameter OLD-LEN is ignored here. This somewhat indirect
1557 ;; implementation exists because it is minimally different from the
1558 ;; stand-alone CC Mode which, lacking
1559 ;; font-lock-extend-after-change-region-function, is forced to use advice
1560 ;; instead.
1562 ;; Of the seven CC Mode languages, currently (2009-05) only C, C++, Objc
1563 ;; (the languages with #define) and AWK Mode make non-null use of this
1564 ;; function.
1565 (when (eq font-lock-support-mode 'jit-lock-mode)
1566 (save-restriction
1567 (widen)
1568 (c-save-buffer-state () ; Protect the undo-list from put-text-property.
1569 (if (< c-new-BEG beg)
1570 (put-text-property c-new-BEG beg 'fontified nil))
1571 (if (> c-new-END end)
1572 (put-text-property end c-new-END 'fontified nil)))))
1573 (cons c-new-BEG c-new-END))
1575 ;; Emacs < 22 and XEmacs
1576 (defmacro c-advise-fl-for-region (function)
1577 `(defadvice ,function (before get-awk-region activate)
1578 ;; Make sure that any string/regexp is completely font-locked.
1579 (when c-buffer-is-cc-mode
1580 (save-excursion
1581 (ad-set-arg 1 c-new-END) ; end
1582 (ad-set-arg 0 c-new-BEG))))) ; beg
1584 (unless (boundp 'font-lock-extend-after-change-region-function)
1585 (c-advise-fl-for-region font-lock-after-change-function)
1586 (c-advise-fl-for-region jit-lock-after-change)
1587 (c-advise-fl-for-region lazy-lock-defer-rest-after-change)
1588 (c-advise-fl-for-region lazy-lock-defer-line-after-change))
1590 ;; Connect up to `electric-indent-mode' (Emacs 24.4 and later).
1591 (defun c-electric-indent-mode-hook ()
1592 ;; Emacs has en/disabled `electric-indent-mode'. Propagate this through to
1593 ;; each CC Mode buffer.
1594 (mapc (lambda (buf)
1595 (with-current-buffer buf
1596 (when c-buffer-is-cc-mode
1597 ;; Don't use `c-toggle-electric-state' here due to recursion.
1598 (setq c-electric-flag electric-indent-mode)
1599 (c-update-modeline))))
1600 (buffer-list)))
1602 (defun c-electric-indent-local-mode-hook ()
1603 ;; Emacs has en/disabled `electric-indent-local-mode' for this buffer.
1604 ;; Propagate this through to this buffer's value of `c-electric-flag'
1605 (when c-buffer-is-cc-mode
1606 (setq c-electric-flag electric-indent-mode)
1607 (c-update-modeline)))
1610 ;; Support for C
1612 (defvar c-mode-syntax-table
1613 (funcall (c-lang-const c-make-mode-syntax-table c))
1614 "Syntax table used in c-mode buffers.")
1616 (c-define-abbrev-table 'c-mode-abbrev-table
1617 '(("else" "else" c-electric-continued-statement 0)
1618 ("while" "while" c-electric-continued-statement 0))
1619 "Abbreviation table used in c-mode buffers.")
1621 (defvar c-mode-map
1622 (let ((map (c-make-inherited-keymap)))
1623 ;; Add bindings which are only useful for C.
1624 (define-key map "\C-c\C-e" 'c-macro-expand)
1625 map)
1626 "Keymap used in c-mode buffers.")
1629 (easy-menu-define c-c-menu c-mode-map "C Mode Commands"
1630 (cons "C" (c-lang-const c-mode-menu c)))
1632 ;; In XEmacs >= 21.5 modes should add their own entries to
1633 ;; `auto-mode-alist'. The comment form of autoload is used to avoid
1634 ;; doing this on load. That since `add-to-list' prepends the value
1635 ;; which could cause it to clobber user settings. Later emacsen have
1636 ;; an append option, but it's not safe to use.
1638 ;; The extension ".C" is associated with C++ while the lowercase
1639 ;; variant goes with C. On case insensitive file systems, this means
1640 ;; that ".c" files also might open C++ mode if the C++ entry comes
1641 ;; first on `auto-mode-alist'. Thus we try to ensure that ".C" comes
1642 ;; after ".c", and since `add-to-list' adds the entry first we have to
1643 ;; add the ".C" entry first.
1644 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.\\(cc\\|hh\\)\\'" . c++-mode))
1645 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.[ch]\\(pp\\|xx\\|\\+\\+\\)\\'" . c++-mode))
1646 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.\\(CC?\\|HH?\\)\\'" . c++-mode))
1648 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.c\\'" . c-mode))
1649 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.h\\'" . c-or-c++-mode))
1651 ;; NB: The following two associate yacc and lex files to C Mode, which
1652 ;; is not really suitable for those formats. Anyway, afaik there's
1653 ;; currently no better mode for them, and besides this is legacy.
1654 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.y\\(acc\\)?\\'" . c-mode))
1655 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.lex\\'" . c-mode))
1657 ;; Preprocessed files generated by C and C++ compilers.
1658 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.i\\'" . c-mode))
1659 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.ii\\'" . c++-mode))
1661 (unless (fboundp 'prog-mode) (defalias 'prog-mode 'fundamental-mode))
1663 ;;;###autoload
1664 (define-derived-mode c-mode prog-mode "C"
1665 "Major mode for editing C code.
1667 To submit a problem report, enter `\\[c-submit-bug-report]' from a
1668 c-mode buffer. This automatically sets up a mail buffer with version
1669 information already added. You just need to add a description of the
1670 problem, including a reproducible test case, and send the message.
1672 To see what version of CC Mode you are running, enter `\\[c-version]'.
1674 The hook `c-mode-common-hook' is run with no args at mode
1675 initialization, then `c-mode-hook'.
1677 Key bindings:
1678 \\{c-mode-map}"
1679 :after-hook (progn (c-make-noise-macro-regexps)
1680 (c-make-macro-with-semi-re)
1681 (c-update-modeline))
1682 (c-initialize-cc-mode t)
1683 (setq abbrev-mode t)
1684 (c-init-language-vars-for 'c-mode)
1685 (c-common-init 'c-mode)
1686 (easy-menu-add c-c-menu)
1687 (cc-imenu-init cc-imenu-c-generic-expression)
1688 (c-run-mode-hooks 'c-mode-common-hook))
1690 (defconst c-or-c++-mode--regexp
1691 (eval-when-compile
1692 (let ((id "[a-zA-Z0-9_]+") (ws "[ \t\r]+") (ws-maybe "[ \t\r]*"))
1693 (concat "^" ws-maybe "\\(?:"
1694 "using" ws "\\(?:namespace" ws "std;\\|std::\\)"
1695 "\\|" "namespace" "\\(:?" ws id "\\)?" ws-maybe "{"
1696 "\\|" "class" ws id ws-maybe "[:{\n]"
1697 "\\|" "template" ws-maybe "<.*>"
1698 "\\|" "#include" ws-maybe "<\\(?:string\\|iostream\\|map\\)>"
1699 "\\)")))
1700 "A regexp applied to C header files to check if they are really C++.")
1702 ;;;###autoload
1703 (defun c-or-c++-mode ()
1704 "Analyse buffer and enable either C or C++ mode.
1706 Some people and projects use .h extension for C++ header files
1707 which is also the one used for C header files. This makes
1708 matching on file name insufficient for detecting major mode that
1709 should be used.
1711 This function attempts to use file contents to determine whether
1712 the code is C or C++ and based on that chooses whether to enable
1713 `c-mode' or `c++-mode'."
1714 (if (save-excursion
1715 (save-restriction
1716 (save-match-data
1717 (widen)
1718 (goto-char (point-min))
1719 (re-search-forward c-or-c++-mode--regexp
1720 (+ (point) c-guess-region-max) t))))
1721 (c++-mode)
1722 (c-mode)))
1725 ;; Support for C++
1727 (defvar c++-mode-syntax-table
1728 (funcall (c-lang-const c-make-mode-syntax-table c++))
1729 "Syntax table used in c++-mode buffers.")
1731 (c-define-abbrev-table 'c++-mode-abbrev-table
1732 '(("else" "else" c-electric-continued-statement 0)
1733 ("while" "while" c-electric-continued-statement 0)
1734 ("catch" "catch" c-electric-continued-statement 0))
1735 "Abbreviation table used in c++-mode buffers.")
1737 (defvar c++-mode-map
1738 (let ((map (c-make-inherited-keymap)))
1739 ;; Add bindings which are only useful for C++.
1740 (define-key map "\C-c\C-e" 'c-macro-expand)
1741 (define-key map "\C-c:" 'c-scope-operator)
1742 (define-key map "<" 'c-electric-lt-gt)
1743 (define-key map ">" 'c-electric-lt-gt)
1744 map)
1745 "Keymap used in c++-mode buffers.")
1747 (easy-menu-define c-c++-menu c++-mode-map "C++ Mode Commands"
1748 (cons "C++" (c-lang-const c-mode-menu c++)))
1750 ;;;###autoload
1751 (define-derived-mode c++-mode prog-mode "C++"
1752 "Major mode for editing C++ code.
1753 To submit a problem report, enter `\\[c-submit-bug-report]' from a
1754 c++-mode buffer. This automatically sets up a mail buffer with
1755 version information already added. You just need to add a description
1756 of the problem, including a reproducible test case, and send the
1757 message.
1759 To see what version of CC Mode you are running, enter `\\[c-version]'.
1761 The hook `c-mode-common-hook' is run with no args at mode
1762 initialization, then `c++-mode-hook'.
1764 Key bindings:
1765 \\{c++-mode-map}"
1766 :after-hook (progn (c-make-noise-macro-regexps)
1767 (c-make-macro-with-semi-re)
1768 (c-update-modeline))
1769 (c-initialize-cc-mode t)
1770 (setq abbrev-mode t)
1771 (c-init-language-vars-for 'c++-mode)
1772 (c-common-init 'c++-mode)
1773 (easy-menu-add c-c++-menu)
1774 (cc-imenu-init cc-imenu-c++-generic-expression)
1775 (c-run-mode-hooks 'c-mode-common-hook))
1778 ;; Support for Objective-C
1780 (defvar objc-mode-syntax-table
1781 (funcall (c-lang-const c-make-mode-syntax-table objc))
1782 "Syntax table used in objc-mode buffers.")
1784 (c-define-abbrev-table 'objc-mode-abbrev-table
1785 '(("else" "else" c-electric-continued-statement 0)
1786 ("while" "while" c-electric-continued-statement 0))
1787 "Abbreviation table used in objc-mode buffers.")
1789 (defvar objc-mode-map
1790 (let ((map (c-make-inherited-keymap)))
1791 ;; Add bindings which are only useful for Objective-C.
1792 (define-key map "\C-c\C-e" 'c-macro-expand)
1793 map)
1794 "Keymap used in objc-mode buffers.")
1796 (easy-menu-define c-objc-menu objc-mode-map "ObjC Mode Commands"
1797 (cons "ObjC" (c-lang-const c-mode-menu objc)))
1799 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.m\\'" . objc-mode))
1801 ;;;###autoload
1802 (define-derived-mode objc-mode prog-mode "ObjC"
1803 "Major mode for editing Objective C code.
1804 To submit a problem report, enter `\\[c-submit-bug-report]' from an
1805 objc-mode buffer. This automatically sets up a mail buffer with
1806 version information already added. You just need to add a description
1807 of the problem, including a reproducible test case, and send the
1808 message.
1810 To see what version of CC Mode you are running, enter `\\[c-version]'.
1812 The hook `c-mode-common-hook' is run with no args at mode
1813 initialization, then `objc-mode-hook'.
1815 Key bindings:
1816 \\{objc-mode-map}"
1817 :after-hook (progn (c-make-noise-macro-regexps)
1818 (c-make-macro-with-semi-re)
1819 (c-update-modeline))
1820 (c-initialize-cc-mode t)
1821 (setq abbrev-mode t)
1822 (c-init-language-vars-for 'objc-mode)
1823 (c-common-init 'objc-mode)
1824 (easy-menu-add c-objc-menu)
1825 (cc-imenu-init nil 'cc-imenu-objc-function)
1826 (c-run-mode-hooks 'c-mode-common-hook))
1829 ;; Support for Java
1831 (defvar java-mode-syntax-table
1832 (funcall (c-lang-const c-make-mode-syntax-table java))
1833 "Syntax table used in java-mode buffers.")
1835 (c-define-abbrev-table 'java-mode-abbrev-table
1836 '(("else" "else" c-electric-continued-statement 0)
1837 ("while" "while" c-electric-continued-statement 0)
1838 ("catch" "catch" c-electric-continued-statement 0)
1839 ("finally" "finally" c-electric-continued-statement 0))
1840 "Abbreviation table used in java-mode buffers.")
1842 (defvar java-mode-map
1843 (let ((map (c-make-inherited-keymap)))
1844 ;; Add bindings which are only useful for Java.
1845 map)
1846 "Keymap used in java-mode buffers.")
1848 ;; Regexp trying to describe the beginning of a Java top-level
1849 ;; definition. This is not used by CC Mode, nor is it maintained
1850 ;; since it's practically impossible to write a regexp that reliably
1851 ;; matches such a construct. Other tools are necessary.
1852 (defconst c-Java-defun-prompt-regexp
1853 "^[ \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-*")
1855 (easy-menu-define c-java-menu java-mode-map "Java Mode Commands"
1856 (cons "Java" (c-lang-const c-mode-menu java)))
1858 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.java\\'" . java-mode))
1860 ;;;###autoload
1861 (define-derived-mode java-mode prog-mode "Java"
1862 "Major mode for editing Java code.
1863 To submit a problem report, enter `\\[c-submit-bug-report]' from a
1864 java-mode buffer. This automatically sets up a mail buffer with
1865 version information already added. You just need to add a description
1866 of the problem, including a reproducible test case, and send the
1867 message.
1869 To see what version of CC Mode you are running, enter `\\[c-version]'.
1871 The hook `c-mode-common-hook' is run with no args at mode
1872 initialization, then `java-mode-hook'.
1874 Key bindings:
1875 \\{java-mode-map}"
1876 :after-hook (c-update-modeline)
1877 (c-initialize-cc-mode t)
1878 (setq abbrev-mode t)
1879 (c-init-language-vars-for 'java-mode)
1880 (c-common-init 'java-mode)
1881 (easy-menu-add c-java-menu)
1882 (cc-imenu-init cc-imenu-java-generic-expression)
1883 (c-run-mode-hooks 'c-mode-common-hook))
1886 ;; Support for CORBA's IDL language
1888 (defvar idl-mode-syntax-table
1889 (funcall (c-lang-const c-make-mode-syntax-table idl))
1890 "Syntax table used in idl-mode buffers.")
1892 (c-define-abbrev-table 'idl-mode-abbrev-table nil
1893 "Abbreviation table used in idl-mode buffers.")
1895 (defvar idl-mode-map
1896 (let ((map (c-make-inherited-keymap)))
1897 ;; Add bindings which are only useful for IDL.
1898 map)
1899 "Keymap used in idl-mode buffers.")
1901 (easy-menu-define c-idl-menu idl-mode-map "IDL Mode Commands"
1902 (cons "IDL" (c-lang-const c-mode-menu idl)))
1904 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.idl\\'" . idl-mode))
1906 ;;;###autoload
1907 (define-derived-mode idl-mode prog-mode "IDL"
1908 "Major mode for editing CORBA's IDL, PSDL and CIDL code.
1909 To submit a problem report, enter `\\[c-submit-bug-report]' from an
1910 idl-mode buffer. This automatically sets up a mail buffer with
1911 version information already added. You just need to add a description
1912 of the problem, including a reproducible test case, and send the
1913 message.
1915 To see what version of CC Mode you are running, enter `\\[c-version]'.
1917 The hook `c-mode-common-hook' is run with no args at mode
1918 initialization, then `idl-mode-hook'.
1920 Key bindings:
1921 \\{idl-mode-map}"
1922 :after-hook (c-update-modeline)
1923 (c-initialize-cc-mode t)
1924 (c-init-language-vars-for 'idl-mode)
1925 (c-common-init 'idl-mode)
1926 (easy-menu-add c-idl-menu)
1927 ;;(cc-imenu-init cc-imenu-idl-generic-expression) ;TODO
1928 (c-run-mode-hooks 'c-mode-common-hook))
1931 ;; Support for Pike
1933 (defvar pike-mode-syntax-table
1934 (funcall (c-lang-const c-make-mode-syntax-table pike))
1935 "Syntax table used in pike-mode buffers.")
1937 (c-define-abbrev-table 'pike-mode-abbrev-table
1938 '(("else" "else" c-electric-continued-statement 0)
1939 ("while" "while" c-electric-continued-statement 0))
1940 "Abbreviation table used in pike-mode buffers.")
1942 (defvar pike-mode-map
1943 (let ((map (c-make-inherited-keymap)))
1944 ;; Additional bindings.
1945 (define-key map "\C-c\C-e" 'c-macro-expand)
1946 map)
1947 "Keymap used in pike-mode buffers.")
1949 (easy-menu-define c-pike-menu pike-mode-map "Pike Mode Commands"
1950 (cons "Pike" (c-lang-const c-mode-menu pike)))
1952 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.\\(u?lpc\\|pike\\|pmod\\(\\.in\\)?\\)\\'" . pike-mode))
1953 ;;;###autoload (add-to-list 'interpreter-mode-alist '("pike" . pike-mode))
1955 ;;;###autoload
1956 (define-derived-mode pike-mode prog-mode "Pike"
1957 "Major mode for editing Pike code.
1958 To submit a problem report, enter `\\[c-submit-bug-report]' from a
1959 pike-mode buffer. This automatically sets up a mail buffer with
1960 version information already added. You just need to add a description
1961 of the problem, including a reproducible test case, and send the
1962 message.
1964 To see what version of CC Mode you are running, enter `\\[c-version]'.
1966 The hook `c-mode-common-hook' is run with no args at mode
1967 initialization, then `pike-mode-hook'.
1969 Key bindings:
1970 \\{pike-mode-map}"
1971 :after-hook (c-update-modeline)
1972 (c-initialize-cc-mode t)
1973 (setq abbrev-mode t)
1974 (c-init-language-vars-for 'pike-mode)
1975 (c-common-init 'pike-mode)
1976 (easy-menu-add c-pike-menu)
1977 ;;(cc-imenu-init cc-imenu-pike-generic-expression) ;TODO
1978 (c-run-mode-hooks 'c-mode-common-hook))
1981 ;; Support for AWK
1983 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.awk\\'" . awk-mode))
1984 ;;;###autoload (add-to-list 'interpreter-mode-alist '("awk" . awk-mode))
1985 ;;;###autoload (add-to-list 'interpreter-mode-alist '("mawk" . awk-mode))
1986 ;;;###autoload (add-to-list 'interpreter-mode-alist '("nawk" . awk-mode))
1987 ;;;###autoload (add-to-list 'interpreter-mode-alist '("gawk" . awk-mode))
1989 (c-define-abbrev-table 'awk-mode-abbrev-table
1990 '(("else" "else" c-electric-continued-statement 0)
1991 ("while" "while" c-electric-continued-statement 0))
1992 "Abbreviation table used in awk-mode buffers.")
1994 (defvar awk-mode-map
1995 (let ((map (c-make-inherited-keymap)))
1996 ;; Add bindings which are only useful for awk.
1997 (define-key map "#" 'self-insert-command);Overrides electric parent binding.
1998 (define-key map "/" 'self-insert-command);Overrides electric parent binding.
1999 (define-key map "*" 'self-insert-command);Overrides electric parent binding.
2000 (define-key map "\C-c\C-n" 'undefined) ; #if doesn't exist in awk.
2001 (define-key map "\C-c\C-p" 'undefined)
2002 (define-key map "\C-c\C-u" 'undefined)
2003 (define-key map "\M-a" 'c-beginning-of-statement) ; 2003/10/7
2004 (define-key map "\M-e" 'c-end-of-statement) ; 2003/10/7
2005 (define-key map "\C-\M-a" 'c-awk-beginning-of-defun)
2006 (define-key map "\C-\M-e" 'c-awk-end-of-defun)
2007 map)
2008 "Keymap used in awk-mode buffers.")
2010 (easy-menu-define c-awk-menu awk-mode-map "AWK Mode Commands"
2011 (cons "AWK" (c-lang-const c-mode-menu awk)))
2013 ;; (require 'cc-awk) brings these in.
2014 (defvar awk-mode-syntax-table)
2015 (declare-function c-awk-unstick-NL-prop "cc-awk" ())
2017 ;;;###autoload
2018 (define-derived-mode awk-mode prog-mode "AWK"
2019 "Major mode for editing AWK code.
2020 To submit a problem report, enter `\\[c-submit-bug-report]' from an
2021 awk-mode buffer. This automatically sets up a mail buffer with version
2022 information already added. You just need to add a description of the
2023 problem, including a reproducible test case, and send the message.
2025 To see what version of CC Mode you are running, enter `\\[c-version]'.
2027 The hook `c-mode-common-hook' is run with no args at mode
2028 initialization, then `awk-mode-hook'.
2030 Key bindings:
2031 \\{awk-mode-map}"
2032 :after-hook (c-update-modeline)
2033 ;; We need the next line to stop the macro defining
2034 ;; `awk-mode-syntax-table'. This would mask the real table which is
2035 ;; declared in cc-awk.el and hasn't yet been loaded.
2036 :syntax-table nil
2037 (require 'cc-awk) ; Added 2003/6/10.
2038 (c-initialize-cc-mode t)
2039 (setq abbrev-mode t)
2040 (c-init-language-vars-for 'awk-mode)
2041 (c-common-init 'awk-mode)
2042 (c-awk-unstick-NL-prop)
2043 (c-run-mode-hooks 'c-mode-common-hook))
2046 ;; bug reporting
2048 (defconst c-mode-help-address
2049 "submit@debbugs.gnu.org"
2050 "Address(es) for CC Mode bug reports.")
2052 (defun c-version ()
2053 "Echo the current version of CC Mode in the minibuffer."
2054 (interactive)
2055 (message "Using CC Mode version %s" c-version)
2056 (c-keep-region-active))
2058 (define-obsolete-variable-alias 'c-prepare-bug-report-hooks
2059 'c-prepare-bug-report-hook "24.3")
2060 (defvar c-prepare-bug-report-hook nil)
2062 ;; Dynamic variables used by reporter.
2063 (defvar reporter-prompt-for-summary-p)
2064 (defvar reporter-dont-compact-list)
2066 ;; This could be "emacs,cc-mode" in the version included in Emacs.
2067 (defconst c-mode-bug-package "cc-mode"
2068 "The package to use in the bug submission.")
2070 ;; reporter-submit-bug-report requires sendmail.
2071 (declare-function mail-position-on-field "sendmail" (field &optional soft))
2073 (defun c-submit-bug-report ()
2074 "Submit via mail a bug report on CC Mode."
2075 (interactive)
2076 (require 'reporter)
2077 ;; load in reporter
2078 (let ((reporter-prompt-for-summary-p t)
2079 (reporter-dont-compact-list '(c-offsets-alist))
2080 (style c-indentation-style)
2081 (c-features c-emacs-features))
2082 (and
2083 (if (y-or-n-p "Do you want to submit a report on CC Mode? ")
2084 t (message "") nil)
2085 (reporter-submit-bug-report
2086 c-mode-help-address
2087 (concat "CC Mode " c-version " (" mode-name ")")
2088 (let ((vars (append
2089 c-style-variables
2090 '(c-buffer-is-cc-mode
2091 c-tab-always-indent
2092 c-syntactic-indentation
2093 c-syntactic-indentation-in-macros
2094 c-ignore-auto-fill
2095 c-auto-align-backslashes
2096 c-backspace-function
2097 c-delete-function
2098 c-electric-pound-behavior
2099 c-default-style
2100 c-enable-xemacs-performance-kludge-p
2101 c-old-style-variable-behavior
2102 defun-prompt-regexp
2103 tab-width
2104 comment-column
2105 parse-sexp-ignore-comments
2106 parse-sexp-lookup-properties
2107 lookup-syntax-properties
2108 ;; A brain-damaged XEmacs only variable that, if
2109 ;; set to nil can cause all kinds of chaos.
2110 signal-error-on-buffer-boundary
2111 ;; Variables that affect line breaking and comments.
2112 auto-fill-mode
2113 auto-fill-function
2114 filladapt-mode
2115 comment-multi-line
2116 comment-start-skip
2117 fill-prefix
2118 fill-column
2119 paragraph-start
2120 adaptive-fill-mode
2121 adaptive-fill-regexp)
2122 nil)))
2123 (mapc (lambda (var) (unless (boundp var)
2124 (setq vars (delq var vars))))
2125 '(signal-error-on-buffer-boundary
2126 filladapt-mode
2127 defun-prompt-regexp
2128 font-lock-mode
2129 auto-fill-mode
2130 font-lock-maximum-decoration
2131 parse-sexp-lookup-properties
2132 lookup-syntax-properties))
2133 vars)
2134 (lambda ()
2135 (run-hooks 'c-prepare-bug-report-hook)
2136 (save-excursion
2137 (or (mail-position-on-field "X-Debbugs-Package")
2138 (insert c-mode-bug-package)))
2139 (insert (format "Buffer Style: %s\nc-emacs-features: %s\n"
2140 style c-features)))))))
2143 (cc-provide 'cc-mode)
2145 ;; Local Variables:
2146 ;; indent-tabs-mode: t
2147 ;; tab-width: 8
2148 ;; End:
2149 ;;; cc-mode.el ends here