file-attribute-collect: New defun
[emacs.git] / lisp / progmodes / cc-mode.el
blobf630b053edc8d347638cc9c2578f770dbc2f5272
1 ;;; cc-mode.el --- major mode for editing C and similar languages
3 ;; Copyright (C) 1985, 1987, 1992-2016 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 happend 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)
561 (when (or c-recognize-<>-arglists
562 (c-major-mode-is 'awk-mode)
563 (c-major-mode-is '(java-mode c-mode c++-mode objc-mode)))
564 ;; We'll use the syntax-table text property to change the syntax
565 ;; of some chars for this language, so do the necessary setup for
566 ;; that.
568 ;; Note to other package developers: It's ok to turn this on in CC
569 ;; Mode buffers when CC Mode doesn't, but it's not ok to turn it
570 ;; off if CC Mode has turned it on.
572 ;; Emacs.
573 (when (boundp 'parse-sexp-lookup-properties)
574 (set (make-local-variable 'parse-sexp-lookup-properties) t))
576 ;; Same as above for XEmacs.
577 (when (boundp 'lookup-syntax-properties)
578 (set (make-local-variable 'lookup-syntax-properties) t)))
580 ;; Use this in Emacs 21+ to avoid meddling with the rear-nonsticky
581 ;; property on each character.
582 (when (boundp 'text-property-default-nonsticky)
583 (make-local-variable 'text-property-default-nonsticky)
584 (mapc (lambda (tprop)
585 (unless (assq tprop text-property-default-nonsticky)
586 (setq text-property-default-nonsticky
587 (cons `(,tprop . t) text-property-default-nonsticky))))
588 '(syntax-table category c-type)))
590 ;; In Emacs 21 and later it's possible to turn off the ad-hoc
591 ;; heuristic that open parens in column 0 are defun starters. Since
592 ;; we have c-state-cache, that heuristic isn't useful and only causes
593 ;; trouble, so turn it off.
594 ;; 2006/12/17: This facility is somewhat confused, and doesn't really seem
595 ;; helpful. Comment it out for now.
596 ;; (when (memq 'col-0-paren c-emacs-features)
597 ;; (make-local-variable 'open-paren-in-column-0-is-defun-start)
598 ;; (setq open-paren-in-column-0-is-defun-start nil))
600 (c-clear-found-types)
602 ;; now set the mode style based on default-style
603 (let ((style (cc-choose-style-for-mode mode default-style)))
604 ;; Override style variables if `c-old-style-variable-behavior' is
605 ;; set. Also override if we are using global style variables,
606 ;; have already initialized a style once, and are switching to a
607 ;; different style. (It's doubtful whether this is desirable, but
608 ;; the whole situation with nonlocal style variables is a bit
609 ;; awkward. It's at least the most compatible way with the old
610 ;; style init procedure.)
611 (c-set-style style (not (or c-old-style-variable-behavior
612 (and (not c-style-variables-are-local-p)
613 c-indentation-style
614 (not (string-equal c-indentation-style
615 style)))))))
616 (c-setup-paragraph-variables)
618 ;; we have to do something special for c-offsets-alist so that the
619 ;; buffer local value has its own alist structure.
620 (setq c-offsets-alist (copy-alist c-offsets-alist))
622 ;; setup the comment indent variable in a Emacs version portable way
623 (set (make-local-variable 'comment-indent-function) 'c-comment-indent)
625 ;; In Emacs 24.4 onwards, prevent Emacs's built in electric indentation from
626 ;; messing up CC Mode's, and set `c-electric-flag' if `electric-indent-mode'
627 ;; has been called by the user.
628 (when (boundp 'electric-indent-inhibit) (setq electric-indent-inhibit t))
629 ;; CC-mode should obey Emacs's generic preferences, tho only do it if
630 ;; Emacs's generic preferences can be set per-buffer (Emacs>=24.4).
631 (when (fboundp 'electric-indent-local-mode)
632 (setq c-electric-flag electric-indent-mode))
634 ;; ;; Put submode indicators onto minor-mode-alist, but only once.
635 ;; (or (assq 'c-submode-indicators minor-mode-alist)
636 ;; (setq minor-mode-alist
637 ;; (cons '(c-submode-indicators c-submode-indicators)
638 ;; minor-mode-alist)))
639 (c-update-modeline)
641 ;; Install the functions that ensure that various internal caches
642 ;; don't become invalid due to buffer changes.
643 (when (featurep 'xemacs)
644 (make-local-hook 'before-change-functions)
645 (make-local-hook 'after-change-functions))
646 (add-hook 'before-change-functions 'c-before-change nil t)
647 (setq c-just-done-before-change nil)
648 (add-hook 'after-change-functions 'c-after-change nil t)
649 (when (boundp 'font-lock-extend-after-change-region-function)
650 (set (make-local-variable 'font-lock-extend-after-change-region-function)
651 'c-extend-after-change-region))) ; Currently (2009-05) used by all
652 ; languages with #define (C, C++,; ObjC), and by AWK.
654 (defun c-setup-doc-comment-style ()
655 "Initialize the variables that depend on the value of `c-doc-comment-style'."
656 (when (and (featurep 'font-lock)
657 (symbol-value 'font-lock-mode))
658 ;; Force font lock mode to reinitialize itself.
659 (font-lock-mode 0)
660 (font-lock-mode 1)))
662 ;; Buffer local variables defining the region to be fontified by a font lock
663 ;; after-change function. They are initialized in c-before-change to
664 ;; before-change-functions' BEG and END. `c-new-END' is amended in
665 ;; c-after-change with after-change-functions' BEG, END, and OLD-LEN. These
666 ;; variables may be modified by any before/after-change function, in
667 ;; particular by functions in `c-get-state-before-change-functions' and
668 ;; `c-before-font-lock-functions'.
669 (defvar c-new-BEG 0)
670 (make-variable-buffer-local 'c-new-BEG)
671 (defvar c-new-END 0)
672 (make-variable-buffer-local 'c-new-END)
673 ;; The following two variables record the values of `c-new-BEG' and
674 ;; `c-new-END' just after `c-new-END' has been adjusted for the length of text
675 ;; inserted or removed. They may be read by any after-change function (but
676 ;; should not be altered by one).
677 (defvar c-old-BEG 0)
678 (make-variable-buffer-local 'c-old-BEG)
679 (defvar c-old-END 0)
680 (make-variable-buffer-local 'c-old-END)
682 (defun c-common-init (&optional mode)
683 "Common initialization for all CC Mode modes.
684 In addition to the work done by `c-basic-common-init' and
685 `c-font-lock-init', this function sets up various other things as
686 customary in CC Mode modes but which aren't strictly necessary for CC
687 Mode to operate correctly.
689 MODE is the symbol for the mode to initialize, like `c-mode'. See
690 `c-basic-common-init' for details. It's only optional to be
691 compatible with old code; callers should always specify it."
693 (unless mode
694 ;; Called from an old third party package. The fallback is to
695 ;; initialize for C.
696 (c-init-language-vars-for 'c-mode))
698 (c-basic-common-init mode c-default-style)
699 (when mode
700 ;; Only initialize font locking if we aren't called from an old package.
701 (c-font-lock-init))
703 ;; Starting a mode is a sort of "change". So call the change functions...
704 (save-restriction
705 (widen)
706 (setq c-new-BEG (point-min))
707 (setq c-new-END (point-max))
708 (save-excursion
709 (let (before-change-functions after-change-functions)
710 (mapc (lambda (fn)
711 (funcall fn (point-min) (point-max)))
712 c-get-state-before-change-functions)
713 (mapc (lambda (fn)
714 (funcall fn (point-min) (point-max)
715 (- (point-max) (point-min))))
716 c-before-font-lock-functions))))
718 (set (make-local-variable 'outline-regexp) "[^#\n\^M]")
719 (set (make-local-variable 'outline-level) 'c-outline-level)
720 (set (make-local-variable 'add-log-current-defun-function)
721 (lambda ()
722 (or (c-cpp-define-name) (c-defun-name))))
723 (let ((rfn (assq mode c-require-final-newline)))
724 (when rfn
725 (if (boundp 'mode-require-final-newline)
726 (and (cdr rfn)
727 (set (make-local-variable 'require-final-newline)
728 mode-require-final-newline))
729 (set (make-local-variable 'require-final-newline) (cdr rfn))))))
731 (defun c-count-cfss (lv-alist)
732 ;; LV-ALIST is an alist like `file-local-variables-alist'. Count how many
733 ;; elements with the key `c-file-style' there are in it.
734 (let ((elt-ptr lv-alist) elt (cownt 0))
735 (while elt-ptr
736 (setq elt (car elt-ptr)
737 elt-ptr (cdr elt-ptr))
738 (when (eq (car elt) 'c-file-style)
739 (setq cownt (1+ cownt))))
740 cownt))
742 (defun c-before-hack-hook ()
743 "Set the CC Mode style and \"offsets\" when in the buffer's local variables.
744 They are set only when, respectively, the pseudo variables
745 `c-file-style' and `c-file-offsets' are present in the list.
747 This function is called from the hook `before-hack-local-variables-hook'."
748 (when c-buffer-is-cc-mode
749 (let ((mode-cons (assq 'mode file-local-variables-alist))
750 (stile (cdr (assq 'c-file-style file-local-variables-alist)))
751 (offsets (cdr (assq 'c-file-offsets file-local-variables-alist))))
752 (when mode-cons
753 (hack-one-local-variable (car mode-cons) (cdr mode-cons))
754 (setq file-local-variables-alist
755 (delq mode-cons file-local-variables-alist)))
756 (when stile
757 (or (stringp stile) (error "c-file-style is not a string"))
758 (if (boundp 'dir-local-variables-alist)
759 ;; Determine whether `c-file-style' was set in the file's local
760 ;; variables or in a .dir-locals.el (a directory setting).
761 (let ((cfs-in-file-and-dir-count
762 (c-count-cfss file-local-variables-alist))
763 (cfs-in-dir-count (c-count-cfss dir-local-variables-alist)))
764 (c-set-style stile
765 (and (= cfs-in-file-and-dir-count cfs-in-dir-count)
766 'keep-defaults)))
767 (c-set-style stile)))
768 (when offsets
769 (mapc
770 (lambda (langentry)
771 (let ((langelem (car langentry))
772 (offset (cdr langentry)))
773 (c-set-offset langelem offset)))
774 offsets)))))
776 (defun c-remove-any-local-eval-or-mode-variables ()
777 ;; If the buffer specifies `mode' or `eval' in its File Local Variable list
778 ;; or on the first line, remove all occurrences. See
779 ;; `c-postprocess-file-styles' for justification. There is no need to save
780 ;; point here, or even bother too much about the buffer contents. However,
781 ;; DON'T mess up the kill-ring.
783 ;; Most of the code here is derived from Emacs 21.3's `hack-local-variables'
784 ;; in files.el.
785 (goto-char (point-max))
786 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move)
787 (let (lv-point (prefix "") (suffix ""))
788 (when (let ((case-fold-search t))
789 (search-forward "Local Variables:" nil t))
790 (setq lv-point (point))
791 ;; The prefix is what comes before "local variables:" in its line.
792 ;; The suffix is what comes after "local variables:" in its line.
793 (skip-chars-forward " \t")
794 (or (eolp)
795 (setq suffix (buffer-substring (point)
796 (progn (end-of-line) (point)))))
797 (goto-char (match-beginning 0))
798 (or (bolp)
799 (setq prefix
800 (buffer-substring (point)
801 (progn (beginning-of-line) (point)))))
803 (while (search-forward-regexp
804 (concat "^[ \t]*"
805 (regexp-quote prefix)
806 "\\(mode\\|eval\\):.*"
807 (regexp-quote suffix)
808 "$")
809 nil t)
810 (forward-line 0)
811 (delete-region (point) (progn (forward-line) (point)))))
813 ;; Delete the first line, if we've got one, in case it contains a mode spec.
814 (unless (and lv-point
815 (progn (goto-char lv-point)
816 (forward-line 0)
817 (bobp)))
818 (goto-char (point-min))
819 (unless (eobp)
820 (delete-region (point) (progn (forward-line) (point)))))))
822 (defun c-postprocess-file-styles ()
823 "Function that post processes relevant file local variables in CC Mode.
824 Currently, this function simply applies any style and offset settings
825 found in the file's Local Variable list. It first applies any style
826 setting found in `c-file-style', then it applies any offset settings
827 it finds in `c-file-offsets'.
829 Note that the style variables are always made local to the buffer."
831 ;; apply file styles and offsets
832 (when c-buffer-is-cc-mode
833 (if (or c-file-style c-file-offsets)
834 (c-make-styles-buffer-local t))
835 (when c-file-style
836 (or (stringp c-file-style)
837 (error "c-file-style is not a string"))
838 (c-set-style c-file-style))
840 (and c-file-offsets
841 (mapc
842 (lambda (langentry)
843 (let ((langelem (car langentry))
844 (offset (cdr langentry)))
845 (c-set-offset langelem offset)))
846 c-file-offsets))
847 ;; Problem: The file local variable block might have explicitly set a
848 ;; style variable. The `c-set-style' or `mapcar' call might have
849 ;; overwritten this. So we run `hack-local-variables' again to remedy
850 ;; this. There are no guarantees this will work properly, particularly as
851 ;; we have no control over what the other hook functions on
852 ;; `hack-local-variables-hook' would have done. We now (2006/2/1) remove
853 ;; any `eval' or `mode' expressions before we evaluate again (see below).
854 ;; ACM, 2005/11/2.
856 ;; Problem (bug reported by Gustav Broberg): if one of the variables is
857 ;; `mode', this will invoke c-mode (etc.) again, setting up the style etc.
858 ;; We prevent this by temporarily removing `mode' from the Local Variables
859 ;; section.
860 (if (or c-file-style c-file-offsets)
861 (let ((hack-local-variables-hook nil) (inhibit-read-only t))
862 (c-tentative-buffer-changes
863 (c-remove-any-local-eval-or-mode-variables)
864 (hack-local-variables))
865 nil))))
867 (if (boundp 'before-hack-local-variables-hook)
868 (add-hook 'before-hack-local-variables-hook 'c-before-hack-hook)
869 (add-hook 'hack-local-variables-hook 'c-postprocess-file-styles))
871 (defmacro c-run-mode-hooks (&rest hooks)
872 ;; Emacs 21.1 has introduced a system with delayed mode hooks that
873 ;; requires the use of the new function `run-mode-hooks'.
874 (if (cc-bytecomp-fboundp 'run-mode-hooks)
875 `(run-mode-hooks ,@hooks)
876 `(progn ,@(mapcar (lambda (hook) `(run-hooks ,hook)) hooks))))
879 ;;; Change hooks, linking with Font Lock and electric-indent-mode.
881 (defun c-called-from-text-property-change-p ()
882 ;; Is the primitive which invoked `before-change-functions' or
883 ;; `after-change-functions' one which merely changes text properties? This
884 ;; function must be called directly from a member of one of the above hooks.
886 ;; In the following call, frame 0 is `backtrace-frame', frame 1 is
887 ;; `c-called-from-text-property-change-p', frame 2 is
888 ;; `c-before/after-change', frame 3 is the primitive invoking the change
889 ;; hook.
890 (memq (cadr (backtrace-frame 3))
891 '(put-text-property remove-list-of-text-properties)))
893 (defun c-depropertize-CPP (beg end)
894 ;; Remove the punctuation syntax-table text property from the CPP parts of
895 ;; (c-new-BEG c-new-END).
897 ;; This function is in the C/C++/ObjC values of
898 ;; `c-get-state-before-change-functions' and is called exclusively as a
899 ;; before change function.
900 (c-save-buffer-state (m-beg ss-found)
901 (goto-char c-new-BEG)
902 (while (and (< (point) beg)
903 (search-forward-regexp c-anchored-cpp-prefix beg 'bound))
904 (goto-char (match-beginning 1))
905 (setq m-beg (point))
906 (c-end-of-macro)
907 (c-clear-char-property-with-value m-beg (point) 'syntax-table '(1)))
909 (while (and (< (point) end)
910 (setq ss-found
911 (search-forward-regexp c-anchored-cpp-prefix end 'bound)))
912 (goto-char (match-beginning 1))
913 (setq m-beg (point))
914 (c-end-of-macro))
915 (if (and ss-found (> (point) end))
916 (c-clear-char-property-with-value m-beg (point) 'syntax-table '(1)))
918 (while (and (< (point) c-new-END)
919 (search-forward-regexp c-anchored-cpp-prefix c-new-END 'bound))
920 (goto-char (match-beginning 1))
921 (setq m-beg (point))
922 (c-end-of-macro)
923 (c-clear-char-property-with-value
924 m-beg (point) 'syntax-table '(1)))))
926 (defun c-extend-region-for-CPP (beg end)
927 ;; Adjust `c-new-BEG', `c-new-END' respectively to the beginning and end of
928 ;; any preprocessor construct they may be in.
930 ;; Point is undefined both before and after this function call; the buffer
931 ;; has already been widened, and match-data saved. The return value is
932 ;; meaningless.
934 ;; This function is in the C/C++/ObjC values of
935 ;; `c-get-state-before-change-functions' and is called exclusively as a
936 ;; before change function.
937 (goto-char c-new-BEG)
938 (c-beginning-of-macro)
939 (when (< (point) c-new-BEG)
940 (setq c-new-BEG (max (point) (c-determine-limit 500 c-new-BEG))))
942 (goto-char c-new-END)
943 (when (c-beginning-of-macro)
944 (c-end-of-macro)
945 (or (eobp) (forward-char))) ; Over the terminating NL which may be marked
946 ; with a c-cpp-delimiter category property
947 (when (> (point) c-new-END)
948 (setq c-new-END (min (point) (c-determine-+ve-limit 500 c-new-END)))))
950 (defun c-depropertize-new-text (beg end old-len)
951 ;; Remove from the new text in (BEG END) any and all text properties which
952 ;; might interfere with CC Mode's proper working.
954 ;; This function is called exclusively as an after-change function. It
955 ;; appears in the value (for all languages) of
956 ;; `c-before-font-lock-functions'. The value of point is undefined both on
957 ;; entry and exit, and the return value has no significance. The parameters
958 ;; BEG, END, and OLD-LEN are the standard ones supplied to all after-change
959 ;; functions.
960 (c-save-buffer-state ()
961 (when (> end beg)
962 (c-clear-char-properties beg end 'syntax-table)
963 (c-clear-char-properties beg end 'category)
964 (c-clear-char-properties beg end 'c-is-sws)
965 (c-clear-char-properties beg end 'c-in-sws)
966 (c-clear-char-properties beg end 'c-type)
967 (c-clear-char-properties beg end 'c-awk-NL-prop))))
969 (defun c-extend-font-lock-region-for-macros (begg endd old-len)
970 ;; Extend the region (c-new-BEG c-new-END) to cover all (possibly changed)
971 ;; preprocessor macros; The return value has no significance.
973 ;; Point is undefined on both entry and exit to this function. The buffer
974 ;; will have been widened on entry.
976 ;; c-new-BEG has already been extended in `c-extend-region-for-CPP' so we
977 ;; don't need to repeat the exercise here.
979 ;; This function is in the C/C++/ObjC value of `c-before-font-lock-functions'.
980 (goto-char endd)
981 (when (c-beginning-of-macro)
982 (c-end-of-macro)
983 ;; Determine the region, (c-new-BEG c-new-END), which will get font
984 ;; locked. This restricts the region should there be long macros.
985 (setq c-new-END (min (max c-new-END (point))
986 (c-determine-+ve-limit 500 c-new-END)))))
988 (defun c-neutralize-CPP-line (beg end)
989 ;; BEG and END bound a region, typically a preprocessor line. Put a
990 ;; "punctuation" syntax-table property on syntactically obtrusive
991 ;; characters, ones which would interact syntactically with stuff outside
992 ;; this region.
994 ;; These are unmatched string delimiters, or unmatched
995 ;; parens/brackets/braces. An unclosed comment is regarded as valid, NOT
996 ;; obtrusive.
997 (save-excursion
998 (let (s)
999 (while
1000 (progn
1001 (setq s (parse-partial-sexp beg end -1))
1002 (cond
1003 ((< (nth 0 s) 0) ; found an unmated ),},]
1004 (c-put-char-property (1- (point)) 'syntax-table '(1))
1006 ((nth 3 s) ; In a string
1007 (c-put-char-property (nth 8 s) 'syntax-table '(1))
1009 ((> (nth 0 s) 0) ; In a (,{,[
1010 (c-put-char-property (nth 1 s) 'syntax-table '(1))
1012 (t nil)))))))
1014 (defun c-neutralize-syntax-in-and-mark-CPP (begg endd old-len)
1015 ;; (i) "Neutralize" every preprocessor line wholly or partially in the
1016 ;; changed region. "Restore" lines which were CPP lines before the change
1017 ;; and are no longer so.
1019 ;; (ii) Mark each CPP construct by placing a `category' property value
1020 ;; `c-cpp-delimiter' at its start and end. The marked characters are the
1021 ;; opening # and usually the terminating EOL, but sometimes the character
1022 ;; before a comment delimiter.
1024 ;; That is, set syntax-table properties on characters that would otherwise
1025 ;; interact syntactically with those outside the CPP line(s).
1027 ;; This function is called from an after-change function, BEGG ENDD and
1028 ;; OLD-LEN being the standard parameters. It prepares the buffer for font
1029 ;; locking, hence must get called before `font-lock-after-change-function'.
1031 ;; Point is undefined both before and after this function call, the buffer
1032 ;; has been widened, and match-data saved. The return value is ignored.
1034 ;; This function is in the C/C++/ObjC value of `c-before-font-lock-functions'.
1036 ;; Note: SPEED _MATTERS_ IN THIS FUNCTION!!!
1038 ;; This function might make hidden buffer changes.
1039 (c-save-buffer-state (limits)
1040 ;; Clear 'syntax-table properties "punctuation":
1041 ;; (c-clear-char-property-with-value c-new-BEG c-new-END 'syntax-table '(1))
1043 ;; CPP "comment" markers:
1044 (if (eval-when-compile (memq 'category-properties c-emacs-features));Emacs.
1045 (c-clear-char-property-with-value
1046 c-new-BEG c-new-END 'category 'c-cpp-delimiter))
1047 ;; FIXME!!! What about the "<" and ">" category properties? 2009-11-16
1049 ;; Add needed properties to each CPP construct in the region.
1050 (goto-char c-new-BEG)
1051 (if (setq limits (c-literal-limits)) ; Go past any literal.
1052 (goto-char (cdr limits)))
1053 (skip-chars-backward " \t")
1054 (let ((pps-position (point)) pps-state mbeg)
1055 (while (and (< (point) c-new-END)
1056 (search-forward-regexp c-anchored-cpp-prefix c-new-END t))
1057 ;; If we've found a "#" inside a macro/string/comment, ignore it.
1058 (unless
1059 (or (save-excursion
1060 (goto-char (match-beginning 0))
1061 (let ((here (point)))
1062 (and (save-match-data (c-beginning-of-macro))
1063 (< (point) here))))
1064 (progn
1065 (setq pps-state
1066 (parse-partial-sexp pps-position (point) nil nil pps-state)
1067 pps-position (point))
1068 (or (nth 3 pps-state) ; in a string?
1069 (nth 4 pps-state)))) ; in a comment?
1070 (goto-char (match-beginning 1))
1071 (setq mbeg (point))
1072 (if (> (c-no-comment-end-of-macro) mbeg)
1073 (progn
1074 (c-neutralize-CPP-line mbeg (point)) ; "punctuation" properties
1075 (if (eval-when-compile
1076 (memq 'category-properties c-emacs-features)) ;Emacs.
1077 (c-set-cpp-delimiters mbeg (point)))) ; "comment" markers
1078 (forward-line)) ; no infinite loop with, e.g., "#//"
1079 )))))
1081 (defun c-before-after-change-digit-quote (beg end &optional old-len)
1082 ;; This function either removes or applies the punctuation value ('(1)) of
1083 ;; the `syntax-table' text property on single quote marks which are
1084 ;; separator characters in long integer literals, e.g. "4'294'967'295". It
1085 ;; applies to both decimal/octal and hex literals. (FIXME (2016-06-10): it
1086 ;; should also apply to binary literals.)
1088 ;; In both uses of the function, the `syntax-table' properties are
1089 ;; removed/applied only on quote marks which appear to be digit separators.
1091 ;; Point is undefined on both entry and exit to this function, and the
1092 ;; return value has no significance. The function is called solely as a
1093 ;; before-change function (see `c-get-state-before-change-functions') and as
1094 ;; an after change function (see `c-before-font-lock-functions', with the
1095 ;; parameters BEG, END, and (optionally) OLD-LEN being given the standard
1096 ;; values for before/after-change functions.
1097 (c-save-buffer-state ((num-begin c-new-BEG) digit-re try-end)
1098 (goto-char c-new-END)
1099 (when (looking-at "\\(x\\)?[0-9a-fA-F']+")
1100 (setq c-new-END (match-end 0)))
1101 (goto-char c-new-BEG)
1102 (when (looking-at "\\(x?\\)[0-9a-fA-F']")
1103 (if (re-search-backward "\\(0x\\)?[0-9a-fA-F]*\\=" nil t)
1104 (setq c-new-BEG (point))))
1106 (while
1107 (re-search-forward "[0-9a-fA-F]'[0-9a-fA-F]" c-new-END t)
1108 (setq try-end (1- (point)))
1109 (re-search-backward "[^0-9a-fA-F']" num-begin t)
1110 (setq digit-re
1111 (cond
1112 ((and (not (bobp)) (eq (char-before) ?0) (memq (char-after) '(?x ?X)))
1113 "[0-9a-fA-F]")
1114 ((and (eq (char-after (1+ (point))) ?0)
1115 (memq (char-after (+ 2 (point))) '(?b ?B)))
1116 "[01]")
1117 ((memq (char-after (1+ (point))) '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9))
1118 "[0-9]")
1119 (t nil)))
1120 (when digit-re
1121 (cond ((eq (char-after) ?x) (forward-char))
1122 ((looking-at ".?0[Bb]") (goto-char (match-end 0)))
1123 ((looking-at digit-re))
1124 (t (forward-char)))
1125 (when (not (c-in-literal))
1126 (let ((num-end ; End of valid sequence of digits/quotes.
1127 (save-excursion
1128 (re-search-forward
1129 (concat "\\=\\(" digit-re "+'\\)*" digit-re "+") nil t)
1130 (point))))
1131 (setq try-end ; End of sequence of digits/quotes
1132 (save-excursion
1133 (re-search-forward
1134 (concat "\\=\\(" digit-re "\\|'\\)+") nil t)
1135 (point)))
1136 (while (re-search-forward
1137 (concat digit-re "\\('\\)" digit-re) num-end t)
1138 (if old-len ; i.e. are we in an after-change function?
1139 (c-put-char-property (match-beginning 1) 'syntax-table '(1))
1140 (c-clear-char-property (match-beginning 1) 'syntax-table))
1141 (backward-char)))))
1142 (goto-char try-end)
1143 (setq num-begin (point)))))
1145 ;; The following doesn't seem needed at the moment (2016-08-15).
1146 ;; (defun c-before-after-change-extend-region-for-lambda-capture
1147 ;; (_beg _end &optional _old-len)
1148 ;; ;; In C++ Mode, extend the region (c-new-BEG c-new-END) to cover any lambda
1149 ;; ;; function capture lists we happen to be inside. This function is expected
1150 ;; ;; to be called both as a before-change and after change function.
1151 ;; ;;
1152 ;; ;; Note that these things _might_ be nested, with a capture list looking
1153 ;; ;; like:
1154 ;; ;;
1155 ;; ;; [ ...., &foo = [..](){...}(..), ... ]
1156 ;; ;;
1157 ;; ;; . What a wonderful language is C++. ;-)
1158 ;; (c-save-buffer-state (paren-state pos)
1159 ;; (goto-char c-new-BEG)
1160 ;; (setq paren-state (c-parse-state))
1161 ;; (while (setq pos (c-pull-open-brace paren-state))
1162 ;; (goto-char pos)
1163 ;; (when (c-looking-at-c++-lambda-capture-list)
1164 ;; (setq c-new-BEG (min c-new-BEG pos))
1165 ;; (if (c-go-list-forward)
1166 ;; (setq c-new-END (max c-new-END (point))))))
1168 ;; (goto-char c-new-END)
1169 ;; (setq paren-state (c-parse-state))
1170 ;; (while (setq pos (c-pull-open-brace paren-state))
1171 ;; (goto-char pos)
1172 ;; (when (c-looking-at-c++-lambda-capture-list)
1173 ;; (setq c-new-BEG (min c-new-BEG pos))
1174 ;; (if (c-go-list-forward)
1175 ;; (setq c-new-END (max c-new-END (point))))))))
1177 (defun c-before-change (beg end)
1178 ;; Function to be put on `before-change-functions'. Primarily, this calls
1179 ;; the language dependent `c-get-state-before-change-functions'. It is
1180 ;; otherwise used only to remove stale entries from the `c-found-types'
1181 ;; cache, and to record entries which a `c-after-change' function might
1182 ;; confirm as stale.
1184 ;; Note that this function must be FAST rather than accurate. Note
1185 ;; also that it only has any effect when font locking is enabled.
1186 ;; We exploit this by checking for font-lock-*-face instead of doing
1187 ;; rigorous syntactic analysis.
1189 ;; If either change boundary is wholly inside an identifier, delete
1190 ;; it/them from the cache. Don't worry about being inside a string
1191 ;; or a comment - "wrongly" removing a symbol from `c-found-types'
1192 ;; isn't critical.
1193 (unless (or (c-called-from-text-property-change-p)
1194 c-just-done-before-change) ; guard against a spurious second
1195 ; invocation of before-change-functions.
1196 (setq c-just-done-before-change t)
1197 ;; (c-new-BEG c-new-END) will be the region to fontify.
1198 (setq c-new-BEG beg c-new-END end)
1199 (setq c-maybe-stale-found-type nil)
1200 (save-restriction
1201 (save-match-data
1202 (widen)
1203 (save-excursion
1204 ;; Are we inserting/deleting stuff in the middle of an identifier?
1205 (c-unfind-enclosing-token beg)
1206 (c-unfind-enclosing-token end)
1207 ;; Are we coalescing two tokens together, e.g. "fo o" -> "foo"?
1208 (when (< beg end)
1209 (c-unfind-coalesced-tokens beg end))
1210 ;; Are we (potentially) disrupting the syntactic context which
1211 ;; makes a type a type? E.g. by inserting stuff after "foo" in
1212 ;; "foo bar;", or before "foo" in "typedef foo *bar;"?
1214 ;; We search for appropriate c-type properties "near" the change.
1215 ;; First, find an appropriate boundary for this property search.
1216 (let (lim
1217 type type-pos
1218 marked-id term-pos
1219 (end1
1220 (or (and (eq (get-text-property end 'face)
1221 'font-lock-comment-face)
1222 (previous-single-property-change end 'face))
1223 end)))
1224 (when (>= end1 beg) ; Don't hassle about changes entirely in comments.
1225 ;; Find a limit for the search for a `c-type' property
1226 (while
1227 (and (/= (skip-chars-backward "^;{}") 0)
1228 (> (point) (point-min))
1229 (memq (c-get-char-property (1- (point)) 'face)
1230 '(font-lock-comment-face font-lock-string-face))))
1231 (setq lim (max (point-min) (1- (point))))
1233 ;; Look for the latest `c-type' property before end1
1234 (when (and (> end1 (point-min))
1235 (setq type-pos
1236 (if (get-text-property (1- end1) 'c-type)
1237 end1
1238 (previous-single-property-change end1 'c-type
1239 nil lim))))
1240 (setq type (get-text-property (max (1- type-pos) lim) 'c-type))
1242 (when (memq type '(c-decl-id-start c-decl-type-start))
1243 ;; Get the identifier, if any, that the property is on.
1244 (goto-char (1- type-pos))
1245 (setq marked-id
1246 (when (looking-at "\\(\\sw\\|\\s_\\)")
1247 (c-beginning-of-current-token)
1248 (buffer-substring-no-properties (point) type-pos)))
1250 (goto-char end1)
1251 (skip-chars-forward "^;{}") ;FIXME!!! loop for comment, maybe
1252 (setq lim (point))
1253 (setq term-pos
1254 (or (c-next-single-property-change end 'c-type nil lim)
1255 lim))
1256 (setq c-maybe-stale-found-type
1257 (list type marked-id
1258 type-pos term-pos
1259 (buffer-substring-no-properties type-pos
1260 term-pos)
1261 (buffer-substring-no-properties beg end)))))))
1263 (if c-get-state-before-change-functions
1264 (mapc (lambda (fn)
1265 (funcall fn beg end))
1266 c-get-state-before-change-functions))
1268 ;; The following must be done here rather than in `c-after-change' because
1269 ;; newly inserted parens would foul up the invalidation algorithm.
1270 (c-invalidate-state-cache beg)))
1272 (defvar c-in-after-change-fontification nil)
1273 (make-variable-buffer-local 'c-in-after-change-fontification)
1274 ;; A flag to prevent region expanding stuff being done twice for after-change
1275 ;; fontification.
1277 (defun c-after-change (beg end old-len)
1278 ;; Function put on `after-change-functions' to adjust various caches
1279 ;; etc. Prefer speed to finesse here, since there will be an order
1280 ;; of magnitude more calls to this function than any of the
1281 ;; functions that use the caches.
1283 ;; Note that care must be taken so that this is called before any
1284 ;; font-lock callbacks since we might get calls to functions using
1285 ;; these caches from inside them, and we must thus be sure that this
1286 ;; has already been executed.
1288 ;; This calls the language variable c-before-font-lock-functions, if non nil.
1289 ;; This typically sets `syntax-table' properties.
1291 ;; We can sometimes get two consecutive calls to `after-change-functions'
1292 ;; without an intervening call to `before-change-functions' when reverting
1293 ;; the buffer (see bug #24094). Whatever the cause, assume that the entire
1294 ;; buffer has changed.
1295 (when (not c-just-done-before-change)
1296 (save-restriction
1297 (widen)
1298 (c-before-change (point-min) (point-max))
1299 (setq beg (point-min)
1300 end (point-max)
1301 old-len (- end beg))))
1303 ;; (c-new-BEG c-new-END) will be the region to fontify. It may become
1304 ;; larger than (beg end).
1305 (setq c-new-END (- (+ c-new-END (- end beg)) old-len))
1306 (setq c-old-BEG c-new-BEG c-old-END c-new-END)
1308 (unless (c-called-from-text-property-change-p)
1309 (setq c-just-done-before-change nil)
1310 (c-save-buffer-state (case-fold-search)
1311 ;; When `combine-after-change-calls' is used we might get calls
1312 ;; with regions outside the current narrowing. This has been
1313 ;; observed in Emacs 20.7.
1314 (save-restriction
1315 (save-match-data ; c-recognize-<>-arglists changes match-data
1316 (widen)
1318 (when (> end (point-max))
1319 ;; Some emacsen might return positions past the end. This has been
1320 ;; observed in Emacs 20.7 when rereading a buffer changed on disk
1321 ;; (haven't been able to minimize it, but Emacs 21.3 appears to
1322 ;; work).
1323 (setq end (point-max))
1324 (when (> beg end)
1325 (setq beg end)))
1327 ;; C-y is capable of spuriously converting category properties
1328 ;; c-</>-as-paren-syntax and c-cpp-delimiter into hard syntax-table
1329 ;; properties. Remove these when it happens.
1330 (when (eval-when-compile (memq 'category-properties c-emacs-features))
1331 (c-save-buffer-state ()
1332 (c-clear-char-property-with-value beg end 'syntax-table
1333 c-<-as-paren-syntax)
1334 (c-clear-char-property-with-value beg end 'syntax-table
1335 c->-as-paren-syntax)
1336 (c-clear-char-property-with-value beg end 'syntax-table nil)))
1338 (c-trim-found-types beg end old-len) ; maybe we don't need all of these.
1339 (c-invalidate-sws-region-after beg end)
1340 ;; (c-invalidate-state-cache beg) ; moved to `c-before-change'.
1341 (c-invalidate-find-decl-cache beg)
1343 (when c-recognize-<>-arglists
1344 (c-after-change-check-<>-operators beg end))
1346 (setq c-in-after-change-fontification t)
1347 (save-excursion
1348 (mapc (lambda (fn)
1349 (funcall fn beg end old-len))
1350 c-before-font-lock-functions)))))))
1352 (defun c-fl-decl-start (pos)
1353 ;; If the beginning of the line containing POS is in the middle of a "local"
1354 ;; declaration (i.e. one which does not start outside of braces enclosing
1355 ;; POS, such as a struct), return the beginning of that declaration.
1356 ;; Otherwise return nil. Note that declarations, in this sense, can be
1357 ;; nested.
1359 ;; This function is called indirectly from font locking stuff - either from
1360 ;; c-after-change (to prepare for after-change font-locking) or from font
1361 ;; lock context (etc.) fontification.
1362 (let ((lit-start (c-literal-start))
1363 (new-pos pos)
1364 capture-opener
1365 bod-lim bo-decl)
1366 (goto-char (c-point 'bol new-pos))
1367 (when lit-start ; Comment or string.
1368 (goto-char lit-start))
1369 (setq bod-lim (c-determine-limit 500))
1371 ;; In C++ Mode, first check if we are within a (possibly nested) lambda
1372 ;; form capture list.
1373 (when (c-major-mode-is 'c++-mode)
1374 (let ((paren-state (c-parse-state))
1375 opener)
1376 (save-excursion
1377 (while (setq opener (c-pull-open-brace paren-state))
1378 (goto-char opener)
1379 (if (c-looking-at-c++-lambda-capture-list)
1380 (setq capture-opener (point)))))))
1382 (while
1383 ;; Go to a less nested declaration each time round this loop.
1384 (and
1385 (c-syntactic-skip-backward "^;{}" bod-lim t)
1386 (> (point) bod-lim)
1387 (progn (c-forward-syntactic-ws)
1388 (setq bo-decl (point))
1389 ;; Are we looking at a keyword such as "template" or
1390 ;; "typedef" which can decorate a type, or the type itself?
1391 (when (or (looking-at c-prefix-spec-kwds-re)
1392 (c-forward-type t))
1393 ;; We've found another candidate position.
1394 (setq new-pos (min new-pos bo-decl))
1395 (goto-char bo-decl))
1397 ;; Try and go out a level to search again.
1398 (progn
1399 (c-backward-syntactic-ws bod-lim)
1400 (and (> (point) bod-lim)
1401 (or (memq (char-before) '(?\( ?\[))
1402 (and (eq (char-before) ?\<)
1403 (eq (c-get-char-property
1404 (1- (point)) 'syntax-table)
1405 c-<-as-paren-syntax)))))
1406 (not (bobp)))
1407 (backward-char)) ; back over (, [, <.
1408 (when (and capture-opener (< capture-opener new-pos))
1409 (setq new-pos capture-opener))
1410 (and (/= new-pos pos) new-pos)))
1412 (defun c-change-expand-fl-region (_beg _end _old-len)
1413 ;; Expand the region (c-new-BEG c-new-END) to an after-change font-lock
1414 ;; region. This will usually be the smallest sequence of whole lines
1415 ;; containing `c-new-BEG' and `c-new-END', but if `c-new-BEG' is in a
1416 ;; "local" declaration (see `c-fl-decl-start') the beginning of this is used
1417 ;; as the lower bound.
1419 ;; This is called from an after-change-function, but the parameters BEG END
1420 ;; and OLD-LEN are not used.
1421 (if font-lock-mode
1422 (setq c-new-BEG
1423 (or (c-fl-decl-start c-new-BEG) (c-point 'bol c-new-BEG))
1424 c-new-END
1425 (save-excursion
1426 (goto-char c-new-END)
1427 (if (bolp)
1428 (point)
1429 (c-point 'bonl c-new-END))))))
1431 (defun c-context-expand-fl-region (beg end)
1432 ;; Return a cons (NEW-BEG . NEW-END), where NEW-BEG is the beginning of a
1433 ;; "local" declaration containing BEG (see `c-fl-decl-start') or BOL BEG is
1434 ;; in. NEW-END is beginning of the line after the one END is in.
1435 (cons (or (c-fl-decl-start beg) (c-point 'bol beg))
1436 (c-point 'bonl end)))
1438 (defun c-before-context-fl-expand-region (beg end)
1439 ;; Expand the region (BEG END) as specified by
1440 ;; `c-before-context-fontification-functions'. Return a cons of the bounds
1441 ;; of the new region.
1442 (save-restriction
1443 (widen)
1444 (save-excursion
1445 (let ((new-beg beg) (new-end end)
1446 (new-region (cons beg end)))
1447 (mapc (lambda (fn)
1448 (setq new-region (funcall fn new-beg new-end))
1449 (setq new-beg (car new-region) new-end (cdr new-region)))
1450 c-before-context-fontification-functions)
1451 new-region))))
1453 (defun c-font-lock-fontify-region (beg end &optional verbose)
1454 ;; Effectively advice around `font-lock-fontify-region' which extends the
1455 ;; region (BEG END), for example, to avoid context fontification chopping
1456 ;; off the start of the context. Do not extend the region if it's already
1457 ;; been done (i.e. from an after-change fontification. An example (C++)
1458 ;; where the chopping off used to happen is this:
1460 ;; template <typename T>
1463 ;; void myfunc(T* p) {}
1465 ;; Type a space in the first blank line, and the fontification of the next
1466 ;; line was fouled up by context fontification.
1467 (let (new-beg new-end new-region case-fold-search)
1468 (if (and c-in-after-change-fontification
1469 (< beg c-new-END) (> end c-new-BEG))
1470 ;; Region and the latest after-change fontification region overlap.
1471 ;; Determine the upper and lower bounds of our adjusted region
1472 ;; separately.
1473 (progn
1474 (if (<= beg c-new-BEG)
1475 (setq c-in-after-change-fontification nil))
1476 (setq new-beg
1477 (if (and (>= beg (c-point 'bol c-new-BEG))
1478 (<= beg c-new-BEG))
1479 ;; Either jit-lock has accepted `c-new-BEG', or has
1480 ;; (probably) extended the change region spuriously to
1481 ;; BOL, which position likely has a syntactically
1482 ;; different position. To ensure correct fontification,
1483 ;; we start at `c-new-BEG', assuming any characters to the
1484 ;; left of `c-new-BEG' on the line do not require
1485 ;; fontification.
1486 c-new-BEG
1487 (setq new-region (c-before-context-fl-expand-region beg end)
1488 new-end (cdr new-region))
1489 (car new-region)))
1490 (setq new-end
1491 (if (and (>= end (c-point 'bol c-new-END))
1492 (<= end c-new-END))
1493 c-new-END
1494 (or new-end
1495 (cdr (c-before-context-fl-expand-region beg end))))))
1496 ;; Context (etc.) fontification.
1497 (setq new-region (c-before-context-fl-expand-region beg end)
1498 new-beg (car new-region) new-end (cdr new-region)))
1499 (funcall (default-value 'font-lock-fontify-region-function)
1500 new-beg new-end verbose)))
1502 (defun c-after-font-lock-init ()
1503 ;; Put on `font-lock-mode-hook'. This function ensures our after-change
1504 ;; function will get executed before the font-lock one.
1505 (when (memq #'c-after-change after-change-functions)
1506 (remove-hook 'after-change-functions #'c-after-change t)
1507 (add-hook 'after-change-functions #'c-after-change nil t)))
1509 (defun c-font-lock-init ()
1510 "Set up the font-lock variables for using the font-lock support in CC Mode.
1511 This does not load the font-lock package. Use after
1512 `c-basic-common-init' and after cc-fonts has been loaded.
1513 This function is called from `c-common-init', once per mode initialization."
1515 (set (make-local-variable 'font-lock-defaults)
1516 `(,(if (c-major-mode-is 'awk-mode)
1517 ;; awk-mode currently has only one font lock level.
1518 'awk-font-lock-keywords
1519 (mapcar 'c-mode-symbol
1520 '("font-lock-keywords" "font-lock-keywords-1"
1521 "font-lock-keywords-2" "font-lock-keywords-3")))
1522 nil nil
1523 ,c-identifier-syntax-modifications
1524 c-beginning-of-syntax
1525 (font-lock-mark-block-function
1526 . c-mark-function)))
1528 ;; Prevent `font-lock-default-fontify-region' extending the region it will
1529 ;; fontify to whole lines by removing `font-lock-extend-region-wholelines'
1530 ;; from `font-lock-extend-region-functions'. (Emacs only). This fixes
1531 ;; Emacs bug #19669.
1532 (when (boundp 'font-lock-extend-region-functions)
1533 (setq font-lock-extend-region-functions
1534 (delq 'font-lock-extend-region-wholelines
1535 font-lock-extend-region-functions)))
1537 (make-local-variable 'font-lock-fontify-region-function)
1538 (setq font-lock-fontify-region-function 'c-font-lock-fontify-region)
1540 (if (featurep 'xemacs)
1541 (make-local-hook 'font-lock-mode-hook))
1542 (add-hook 'font-lock-mode-hook 'c-after-font-lock-init nil t))
1544 ;; Emacs 22 and later.
1545 (defun c-extend-after-change-region (beg end _old-len)
1546 "Extend the region to be fontified, if necessary."
1547 ;; Note: the parameter OLD-LEN is ignored here. This somewhat indirect
1548 ;; implementation exists because it is minimally different from the
1549 ;; stand-alone CC Mode which, lacking
1550 ;; font-lock-extend-after-change-region-function, is forced to use advice
1551 ;; instead.
1553 ;; Of the seven CC Mode languages, currently (2009-05) only C, C++, Objc
1554 ;; (the languages with #define) and AWK Mode make non-null use of this
1555 ;; function.
1556 (when (eq font-lock-support-mode 'jit-lock-mode)
1557 (save-restriction
1558 (widen)
1559 (c-save-buffer-state () ; Protect the undo-list from put-text-property.
1560 (if (< c-new-BEG beg)
1561 (put-text-property c-new-BEG beg 'fontified nil))
1562 (if (> c-new-END end)
1563 (put-text-property end c-new-END 'fontified nil)))))
1564 (cons c-new-BEG c-new-END))
1566 ;; Emacs < 22 and XEmacs
1567 (defmacro c-advise-fl-for-region (function)
1568 `(defadvice ,function (before get-awk-region activate)
1569 ;; Make sure that any string/regexp is completely font-locked.
1570 (when c-buffer-is-cc-mode
1571 (save-excursion
1572 (ad-set-arg 1 c-new-END) ; end
1573 (ad-set-arg 0 c-new-BEG))))) ; beg
1575 (unless (boundp 'font-lock-extend-after-change-region-function)
1576 (c-advise-fl-for-region font-lock-after-change-function)
1577 (c-advise-fl-for-region jit-lock-after-change)
1578 (c-advise-fl-for-region lazy-lock-defer-rest-after-change)
1579 (c-advise-fl-for-region lazy-lock-defer-line-after-change))
1581 ;; Connect up to `electric-indent-mode' (Emacs 24.4 and later).
1582 (defun c-electric-indent-mode-hook ()
1583 ;; Emacs has en/disabled `electric-indent-mode'. Propagate this through to
1584 ;; each CC Mode buffer.
1585 (mapc (lambda (buf)
1586 (with-current-buffer buf
1587 (when c-buffer-is-cc-mode
1588 ;; Don't use `c-toggle-electric-state' here due to recursion.
1589 (setq c-electric-flag electric-indent-mode)
1590 (c-update-modeline))))
1591 (buffer-list)))
1593 (defun c-electric-indent-local-mode-hook ()
1594 ;; Emacs has en/disabled `electric-indent-local-mode' for this buffer.
1595 ;; Propagate this through to this buffer's value of `c-electric-flag'
1596 (when c-buffer-is-cc-mode
1597 (setq c-electric-flag electric-indent-mode)
1598 (c-update-modeline)))
1601 ;; Support for C
1603 (defvar c-mode-syntax-table
1604 (funcall (c-lang-const c-make-mode-syntax-table c))
1605 "Syntax table used in c-mode buffers.")
1607 (c-define-abbrev-table 'c-mode-abbrev-table
1608 '(("else" "else" c-electric-continued-statement 0)
1609 ("while" "while" c-electric-continued-statement 0))
1610 "Abbreviation table used in c-mode buffers.")
1612 (defvar c-mode-map
1613 (let ((map (c-make-inherited-keymap)))
1614 ;; Add bindings which are only useful for C.
1615 (define-key map "\C-c\C-e" 'c-macro-expand)
1616 map)
1617 "Keymap used in c-mode buffers.")
1620 (easy-menu-define c-c-menu c-mode-map "C Mode Commands"
1621 (cons "C" (c-lang-const c-mode-menu c)))
1623 ;; In XEmacs >= 21.5 modes should add their own entries to
1624 ;; `auto-mode-alist'. The comment form of autoload is used to avoid
1625 ;; doing this on load. That since `add-to-list' prepends the value
1626 ;; which could cause it to clobber user settings. Later emacsen have
1627 ;; an append option, but it's not safe to use.
1629 ;; The extension ".C" is associated with C++ while the lowercase
1630 ;; variant goes with C. On case insensitive file systems, this means
1631 ;; that ".c" files also might open C++ mode if the C++ entry comes
1632 ;; first on `auto-mode-alist'. Thus we try to ensure that ".C" comes
1633 ;; after ".c", and since `add-to-list' adds the entry first we have to
1634 ;; add the ".C" entry first.
1635 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.\\(cc\\|hh\\)\\'" . c++-mode))
1636 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.[ch]\\(pp\\|xx\\|\\+\\+\\)\\'" . c++-mode))
1637 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.\\(CC?\\|HH?\\)\\'" . c++-mode))
1639 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.c\\'" . c-mode))
1640 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.h\\'" . c-or-c++-mode))
1642 ;; NB: The following two associate yacc and lex files to C Mode, which
1643 ;; is not really suitable for those formats. Anyway, afaik there's
1644 ;; currently no better mode for them, and besides this is legacy.
1645 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.y\\(acc\\)?\\'" . c-mode))
1646 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.lex\\'" . c-mode))
1648 ;; Preprocessed files generated by C and C++ compilers.
1649 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.i\\'" . c-mode))
1650 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.ii\\'" . c++-mode))
1652 (unless (fboundp 'prog-mode) (defalias 'prog-mode 'fundamental-mode))
1654 ;;;###autoload
1655 (define-derived-mode c-mode prog-mode "C"
1656 "Major mode for editing C code.
1658 To submit a problem report, enter `\\[c-submit-bug-report]' from a
1659 c-mode buffer. This automatically sets up a mail buffer with version
1660 information already added. You just need to add a description of the
1661 problem, including a reproducible test case, and send the message.
1663 To see what version of CC Mode you are running, enter `\\[c-version]'.
1665 The hook `c-mode-common-hook' is run with no args at mode
1666 initialization, then `c-mode-hook'.
1668 Key bindings:
1669 \\{c-mode-map}"
1670 :after-hook (progn (c-make-noise-macro-regexps)
1671 (c-make-macro-with-semi-re)
1672 (c-update-modeline))
1673 (c-initialize-cc-mode t)
1674 (setq abbrev-mode t)
1675 (c-init-language-vars-for 'c-mode)
1676 (c-common-init 'c-mode)
1677 (easy-menu-add c-c-menu)
1678 (cc-imenu-init cc-imenu-c-generic-expression)
1679 (c-run-mode-hooks 'c-mode-common-hook))
1681 (defconst c-or-c++-mode--regexp
1682 (eval-when-compile
1683 (let ((id "[a-zA-Z0-9_]+") (ws "[ \t\r]+") (ws-maybe "[ \t\r]*"))
1684 (concat "^" ws-maybe "\\(?:"
1685 "using" ws "\\(?:namespace" ws "std;\\|std::\\)"
1686 "\\|" "namespace" "\\(:?" ws id "\\)?" ws-maybe "{"
1687 "\\|" "class" ws id ws-maybe "[:{\n]"
1688 "\\|" "template" ws-maybe "<.*>"
1689 "\\|" "#include" ws-maybe "<\\(?:string\\|iostream\\|map\\)>"
1690 "\\)")))
1691 "A regexp applied to C header files to check if they are really C++.")
1693 ;;;###autoload
1694 (defun c-or-c++-mode ()
1695 "Analyse buffer and enable either C or C++ mode.
1697 Some people and projects use .h extension for C++ header files
1698 which is also the one used for C header files. This makes
1699 matching on file name insufficient for detecting major mode that
1700 should be used.
1702 This function attempts to use file contents to determine whether
1703 the code is C or C++ and based on that chooses whether to enable
1704 `c-mode' or `c++-mode'."
1705 (if (save-excursion
1706 (save-restriction
1707 (save-match-data
1708 (widen)
1709 (goto-char (point-min))
1710 (re-search-forward c-or-c++-mode--regexp
1711 (+ (point) c-guess-region-max) t))))
1712 (c++-mode)
1713 (c-mode)))
1716 ;; Support for C++
1718 (defvar c++-mode-syntax-table
1719 (funcall (c-lang-const c-make-mode-syntax-table c++))
1720 "Syntax table used in c++-mode buffers.")
1722 (c-define-abbrev-table 'c++-mode-abbrev-table
1723 '(("else" "else" c-electric-continued-statement 0)
1724 ("while" "while" c-electric-continued-statement 0)
1725 ("catch" "catch" c-electric-continued-statement 0))
1726 "Abbreviation table used in c++-mode buffers.")
1728 (defvar c++-mode-map
1729 (let ((map (c-make-inherited-keymap)))
1730 ;; Add bindings which are only useful for C++.
1731 (define-key map "\C-c\C-e" 'c-macro-expand)
1732 (define-key map "\C-c:" 'c-scope-operator)
1733 (define-key map "<" 'c-electric-lt-gt)
1734 (define-key map ">" 'c-electric-lt-gt)
1735 map)
1736 "Keymap used in c++-mode buffers.")
1738 (easy-menu-define c-c++-menu c++-mode-map "C++ Mode Commands"
1739 (cons "C++" (c-lang-const c-mode-menu c++)))
1741 ;;;###autoload
1742 (define-derived-mode c++-mode prog-mode "C++"
1743 "Major mode for editing C++ code.
1744 To submit a problem report, enter `\\[c-submit-bug-report]' from a
1745 c++-mode buffer. This automatically sets up a mail buffer with
1746 version information already added. You just need to add a description
1747 of the problem, including a reproducible test case, and send the
1748 message.
1750 To see what version of CC Mode you are running, enter `\\[c-version]'.
1752 The hook `c-mode-common-hook' is run with no args at mode
1753 initialization, then `c++-mode-hook'.
1755 Key bindings:
1756 \\{c++-mode-map}"
1757 :after-hook (progn (c-make-noise-macro-regexps)
1758 (c-make-macro-with-semi-re)
1759 (c-update-modeline))
1760 (c-initialize-cc-mode t)
1761 (setq abbrev-mode t)
1762 (c-init-language-vars-for 'c++-mode)
1763 (c-common-init 'c++-mode)
1764 (easy-menu-add c-c++-menu)
1765 (cc-imenu-init cc-imenu-c++-generic-expression)
1766 (c-run-mode-hooks 'c-mode-common-hook))
1769 ;; Support for Objective-C
1771 (defvar objc-mode-syntax-table
1772 (funcall (c-lang-const c-make-mode-syntax-table objc))
1773 "Syntax table used in objc-mode buffers.")
1775 (c-define-abbrev-table 'objc-mode-abbrev-table
1776 '(("else" "else" c-electric-continued-statement 0)
1777 ("while" "while" c-electric-continued-statement 0))
1778 "Abbreviation table used in objc-mode buffers.")
1780 (defvar objc-mode-map
1781 (let ((map (c-make-inherited-keymap)))
1782 ;; Add bindings which are only useful for Objective-C.
1783 (define-key map "\C-c\C-e" 'c-macro-expand)
1784 map)
1785 "Keymap used in objc-mode buffers.")
1787 (easy-menu-define c-objc-menu objc-mode-map "ObjC Mode Commands"
1788 (cons "ObjC" (c-lang-const c-mode-menu objc)))
1790 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.m\\'" . objc-mode))
1792 ;;;###autoload
1793 (define-derived-mode objc-mode prog-mode "ObjC"
1794 "Major mode for editing Objective C code.
1795 To submit a problem report, enter `\\[c-submit-bug-report]' from an
1796 objc-mode buffer. This automatically sets up a mail buffer with
1797 version information already added. You just need to add a description
1798 of the problem, including a reproducible test case, and send the
1799 message.
1801 To see what version of CC Mode you are running, enter `\\[c-version]'.
1803 The hook `c-mode-common-hook' is run with no args at mode
1804 initialization, then `objc-mode-hook'.
1806 Key bindings:
1807 \\{objc-mode-map}"
1808 :after-hook (progn (c-make-noise-macro-regexps)
1809 (c-make-macro-with-semi-re)
1810 (c-update-modeline))
1811 (c-initialize-cc-mode t)
1812 (setq abbrev-mode t)
1813 (c-init-language-vars-for 'objc-mode)
1814 (c-common-init 'objc-mode)
1815 (easy-menu-add c-objc-menu)
1816 (cc-imenu-init nil 'cc-imenu-objc-function)
1817 (c-run-mode-hooks 'c-mode-common-hook))
1820 ;; Support for Java
1822 (defvar java-mode-syntax-table
1823 (funcall (c-lang-const c-make-mode-syntax-table java))
1824 "Syntax table used in java-mode buffers.")
1826 (c-define-abbrev-table 'java-mode-abbrev-table
1827 '(("else" "else" c-electric-continued-statement 0)
1828 ("while" "while" c-electric-continued-statement 0)
1829 ("catch" "catch" c-electric-continued-statement 0)
1830 ("finally" "finally" c-electric-continued-statement 0))
1831 "Abbreviation table used in java-mode buffers.")
1833 (defvar java-mode-map
1834 (let ((map (c-make-inherited-keymap)))
1835 ;; Add bindings which are only useful for Java.
1836 map)
1837 "Keymap used in java-mode buffers.")
1839 ;; Regexp trying to describe the beginning of a Java top-level
1840 ;; definition. This is not used by CC Mode, nor is it maintained
1841 ;; since it's practically impossible to write a regexp that reliably
1842 ;; matches such a construct. Other tools are necessary.
1843 (defconst c-Java-defun-prompt-regexp
1844 "^[ \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-*")
1846 (easy-menu-define c-java-menu java-mode-map "Java Mode Commands"
1847 (cons "Java" (c-lang-const c-mode-menu java)))
1849 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.java\\'" . java-mode))
1851 ;;;###autoload
1852 (define-derived-mode java-mode prog-mode "Java"
1853 "Major mode for editing Java code.
1854 To submit a problem report, enter `\\[c-submit-bug-report]' from a
1855 java-mode buffer. This automatically sets up a mail buffer with
1856 version information already added. You just need to add a description
1857 of the problem, including a reproducible test case, and send the
1858 message.
1860 To see what version of CC Mode you are running, enter `\\[c-version]'.
1862 The hook `c-mode-common-hook' is run with no args at mode
1863 initialization, then `java-mode-hook'.
1865 Key bindings:
1866 \\{java-mode-map}"
1867 :after-hook (c-update-modeline)
1868 (c-initialize-cc-mode t)
1869 (setq abbrev-mode t)
1870 (c-init-language-vars-for 'java-mode)
1871 (c-common-init 'java-mode)
1872 (easy-menu-add c-java-menu)
1873 (cc-imenu-init cc-imenu-java-generic-expression)
1874 (c-run-mode-hooks 'c-mode-common-hook))
1877 ;; Support for CORBA's IDL language
1879 (defvar idl-mode-syntax-table
1880 (funcall (c-lang-const c-make-mode-syntax-table idl))
1881 "Syntax table used in idl-mode buffers.")
1883 (c-define-abbrev-table 'idl-mode-abbrev-table nil
1884 "Abbreviation table used in idl-mode buffers.")
1886 (defvar idl-mode-map
1887 (let ((map (c-make-inherited-keymap)))
1888 ;; Add bindings which are only useful for IDL.
1889 map)
1890 "Keymap used in idl-mode buffers.")
1892 (easy-menu-define c-idl-menu idl-mode-map "IDL Mode Commands"
1893 (cons "IDL" (c-lang-const c-mode-menu idl)))
1895 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.idl\\'" . idl-mode))
1897 ;;;###autoload
1898 (define-derived-mode idl-mode prog-mode "IDL"
1899 "Major mode for editing CORBA's IDL, PSDL and CIDL code.
1900 To submit a problem report, enter `\\[c-submit-bug-report]' from an
1901 idl-mode buffer. This automatically sets up a mail buffer with
1902 version information already added. You just need to add a description
1903 of the problem, including a reproducible test case, and send the
1904 message.
1906 To see what version of CC Mode you are running, enter `\\[c-version]'.
1908 The hook `c-mode-common-hook' is run with no args at mode
1909 initialization, then `idl-mode-hook'.
1911 Key bindings:
1912 \\{idl-mode-map}"
1913 :after-hook (c-update-modeline)
1914 (c-initialize-cc-mode t)
1915 (c-init-language-vars-for 'idl-mode)
1916 (c-common-init 'idl-mode)
1917 (easy-menu-add c-idl-menu)
1918 ;;(cc-imenu-init cc-imenu-idl-generic-expression) ;TODO
1919 (c-run-mode-hooks 'c-mode-common-hook))
1922 ;; Support for Pike
1924 (defvar pike-mode-syntax-table
1925 (funcall (c-lang-const c-make-mode-syntax-table pike))
1926 "Syntax table used in pike-mode buffers.")
1928 (c-define-abbrev-table 'pike-mode-abbrev-table
1929 '(("else" "else" c-electric-continued-statement 0)
1930 ("while" "while" c-electric-continued-statement 0))
1931 "Abbreviation table used in pike-mode buffers.")
1933 (defvar pike-mode-map
1934 (let ((map (c-make-inherited-keymap)))
1935 ;; Additional bindings.
1936 (define-key map "\C-c\C-e" 'c-macro-expand)
1937 map)
1938 "Keymap used in pike-mode buffers.")
1940 (easy-menu-define c-pike-menu pike-mode-map "Pike Mode Commands"
1941 (cons "Pike" (c-lang-const c-mode-menu pike)))
1943 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.\\(u?lpc\\|pike\\|pmod\\(\\.in\\)?\\)\\'" . pike-mode))
1944 ;;;###autoload (add-to-list 'interpreter-mode-alist '("pike" . pike-mode))
1946 ;;;###autoload
1947 (define-derived-mode pike-mode prog-mode "Pike"
1948 "Major mode for editing Pike code.
1949 To submit a problem report, enter `\\[c-submit-bug-report]' from a
1950 pike-mode buffer. This automatically sets up a mail buffer with
1951 version information already added. You just need to add a description
1952 of the problem, including a reproducible test case, and send the
1953 message.
1955 To see what version of CC Mode you are running, enter `\\[c-version]'.
1957 The hook `c-mode-common-hook' is run with no args at mode
1958 initialization, then `pike-mode-hook'.
1960 Key bindings:
1961 \\{pike-mode-map}"
1962 :after-hook (c-update-modeline)
1963 (c-initialize-cc-mode t)
1964 (setq abbrev-mode t)
1965 (c-init-language-vars-for 'pike-mode)
1966 (c-common-init 'pike-mode)
1967 (easy-menu-add c-pike-menu)
1968 ;;(cc-imenu-init cc-imenu-pike-generic-expression) ;TODO
1969 (c-run-mode-hooks 'c-mode-common-hook))
1972 ;; Support for AWK
1974 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.awk\\'" . awk-mode))
1975 ;;;###autoload (add-to-list 'interpreter-mode-alist '("awk" . awk-mode))
1976 ;;;###autoload (add-to-list 'interpreter-mode-alist '("mawk" . awk-mode))
1977 ;;;###autoload (add-to-list 'interpreter-mode-alist '("nawk" . awk-mode))
1978 ;;;###autoload (add-to-list 'interpreter-mode-alist '("gawk" . awk-mode))
1980 (c-define-abbrev-table 'awk-mode-abbrev-table
1981 '(("else" "else" c-electric-continued-statement 0)
1982 ("while" "while" c-electric-continued-statement 0))
1983 "Abbreviation table used in awk-mode buffers.")
1985 (defvar awk-mode-map
1986 (let ((map (c-make-inherited-keymap)))
1987 ;; Add bindings which are only useful for awk.
1988 (define-key map "#" 'self-insert-command);Overrides electric parent binding.
1989 (define-key map "/" 'self-insert-command);Overrides electric parent binding.
1990 (define-key map "*" 'self-insert-command);Overrides electric parent binding.
1991 (define-key map "\C-c\C-n" 'undefined) ; #if doesn't exist in awk.
1992 (define-key map "\C-c\C-p" 'undefined)
1993 (define-key map "\C-c\C-u" 'undefined)
1994 (define-key map "\M-a" 'c-beginning-of-statement) ; 2003/10/7
1995 (define-key map "\M-e" 'c-end-of-statement) ; 2003/10/7
1996 (define-key map "\C-\M-a" 'c-awk-beginning-of-defun)
1997 (define-key map "\C-\M-e" 'c-awk-end-of-defun)
1998 map)
1999 "Keymap used in awk-mode buffers.")
2001 (easy-menu-define c-awk-menu awk-mode-map "AWK Mode Commands"
2002 (cons "AWK" (c-lang-const c-mode-menu awk)))
2004 ;; (require 'cc-awk) brings these in.
2005 (defvar awk-mode-syntax-table)
2006 (declare-function c-awk-unstick-NL-prop "cc-awk" ())
2008 ;;;###autoload
2009 (define-derived-mode awk-mode prog-mode "AWK"
2010 "Major mode for editing AWK code.
2011 To submit a problem report, enter `\\[c-submit-bug-report]' from an
2012 awk-mode buffer. This automatically sets up a mail buffer with version
2013 information already added. You just need to add a description of the
2014 problem, including a reproducible test case, and send the message.
2016 To see what version of CC Mode you are running, enter `\\[c-version]'.
2018 The hook `c-mode-common-hook' is run with no args at mode
2019 initialization, then `awk-mode-hook'.
2021 Key bindings:
2022 \\{awk-mode-map}"
2023 :after-hook (c-update-modeline)
2024 ;; We need the next line to stop the macro defining
2025 ;; `awk-mode-syntax-table'. This would mask the real table which is
2026 ;; declared in cc-awk.el and hasn't yet been loaded.
2027 :syntax-table nil
2028 (require 'cc-awk) ; Added 2003/6/10.
2029 (c-initialize-cc-mode t)
2030 (setq abbrev-mode t)
2031 (c-init-language-vars-for 'awk-mode)
2032 (c-common-init 'awk-mode)
2033 (c-awk-unstick-NL-prop)
2034 (c-run-mode-hooks 'c-mode-common-hook))
2037 ;; bug reporting
2039 (defconst c-mode-help-address
2040 "submit@debbugs.gnu.org"
2041 "Address(es) for CC Mode bug reports.")
2043 (defun c-version ()
2044 "Echo the current version of CC Mode in the minibuffer."
2045 (interactive)
2046 (message "Using CC Mode version %s" c-version)
2047 (c-keep-region-active))
2049 (define-obsolete-variable-alias 'c-prepare-bug-report-hooks
2050 'c-prepare-bug-report-hook "24.3")
2051 (defvar c-prepare-bug-report-hook nil)
2053 ;; Dynamic variables used by reporter.
2054 (defvar reporter-prompt-for-summary-p)
2055 (defvar reporter-dont-compact-list)
2057 ;; This could be "emacs,cc-mode" in the version included in Emacs.
2058 (defconst c-mode-bug-package "cc-mode"
2059 "The package to use in the bug submission.")
2061 ;; reporter-submit-bug-report requires sendmail.
2062 (declare-function mail-position-on-field "sendmail" (field &optional soft))
2064 (defun c-submit-bug-report ()
2065 "Submit via mail a bug report on CC Mode."
2066 (interactive)
2067 (require 'reporter)
2068 ;; load in reporter
2069 (let ((reporter-prompt-for-summary-p t)
2070 (reporter-dont-compact-list '(c-offsets-alist))
2071 (style c-indentation-style)
2072 (c-features c-emacs-features))
2073 (and
2074 (if (y-or-n-p "Do you want to submit a report on CC Mode? ")
2075 t (message "") nil)
2076 (reporter-submit-bug-report
2077 c-mode-help-address
2078 (concat "CC Mode " c-version " (" mode-name ")")
2079 (let ((vars (append
2080 c-style-variables
2081 '(c-buffer-is-cc-mode
2082 c-tab-always-indent
2083 c-syntactic-indentation
2084 c-syntactic-indentation-in-macros
2085 c-ignore-auto-fill
2086 c-auto-align-backslashes
2087 c-backspace-function
2088 c-delete-function
2089 c-electric-pound-behavior
2090 c-default-style
2091 c-enable-xemacs-performance-kludge-p
2092 c-old-style-variable-behavior
2093 defun-prompt-regexp
2094 tab-width
2095 comment-column
2096 parse-sexp-ignore-comments
2097 parse-sexp-lookup-properties
2098 lookup-syntax-properties
2099 ;; A brain-damaged XEmacs only variable that, if
2100 ;; set to nil can cause all kinds of chaos.
2101 signal-error-on-buffer-boundary
2102 ;; Variables that affect line breaking and comments.
2103 auto-fill-mode
2104 auto-fill-function
2105 filladapt-mode
2106 comment-multi-line
2107 comment-start-skip
2108 fill-prefix
2109 fill-column
2110 paragraph-start
2111 adaptive-fill-mode
2112 adaptive-fill-regexp)
2113 nil)))
2114 (mapc (lambda (var) (unless (boundp var)
2115 (setq vars (delq var vars))))
2116 '(signal-error-on-buffer-boundary
2117 filladapt-mode
2118 defun-prompt-regexp
2119 font-lock-mode
2120 auto-fill-mode
2121 font-lock-maximum-decoration
2122 parse-sexp-lookup-properties
2123 lookup-syntax-properties))
2124 vars)
2125 (lambda ()
2126 (run-hooks 'c-prepare-bug-report-hook)
2127 (save-excursion
2128 (or (mail-position-on-field "X-Debbugs-Package")
2129 (insert c-mode-bug-package)))
2130 (insert (format "Buffer Style: %s\nc-emacs-features: %s\n"
2131 style c-features)))))))
2134 (cc-provide 'cc-mode)
2136 ;; Local Variables:
2137 ;; indent-tabs-mode: t
2138 ;; tab-width: 8
2139 ;; End:
2140 ;;; cc-mode.el ends here