comparison lisp/progmodes/cc-mode.el @ 51714:bc91cbf50c24

Updated CC Mode to version 5.30.
author Martin Stjernholm <mast@lysator.liu.se>
date Thu, 03 Jul 2003 12:30:59 +0000
parents a668aa6d6cdc
children b4fb79bf98ba
comparison
equal deleted inserted replaced
51713:205602055b5f 51714:bc91cbf50c24
1 ;;; cc-mode.el --- major mode for editing C, C++, Objective-C, and Java code 1 ;;; cc-mode.el --- major mode for editing C and similar languages
2 2
3 ;; Copyright (C) 1985,1987,1992-2001,2003 Free Software Foundation, Inc. 3 ;; Copyright (C) 1985,1987,1992-2003 Free Software Foundation, Inc.
4 4
5 ;; Authors: 2000- Martin Stjernholm 5 ;; Authors: 2003- Alan Mackenzie
6 ;; 1998-1999 Barry A. Warsaw and Martin Stjernholm 6 ;; 1998- Martin Stjernholm
7 ;; 1992-1997 Barry A. Warsaw 7 ;; 1992-1999 Barry A. Warsaw
8 ;; 1987 Dave Detlefs and Stewart Clamen 8 ;; 1987 Dave Detlefs and Stewart Clamen
9 ;; 1985 Richard M. Stallman 9 ;; 1985 Richard M. Stallman
10 ;; Maintainer: bug-cc-mode@gnu.org 10 ;; Maintainer: bug-cc-mode@gnu.org
11 ;; Created: a long, long, time ago. adapted from the original c-mode.el 11 ;; Created: a long, long, time ago. adapted from the original c-mode.el
12 ;; Keywords: c languages oop 12 ;; Keywords: c languages oop
26 ;; You should have received a copy of the GNU General Public License 26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs; see the file COPYING. If not, write to 27 ;; along with GNU Emacs; see the file COPYING. If not, write to
28 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 28 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
29 ;; Boston, MA 02111-1307, USA. 29 ;; Boston, MA 02111-1307, USA.
30 30
31 (defconst c-version "5.29" 31 ;;; Commentary:
32 "CC Mode version number.")
33 32
34 ;; NOTE: Read the commentary below for the right way to submit bug reports! 33 ;; NOTE: Read the commentary below for the right way to submit bug reports!
35 ;; NOTE: See the accompanying texinfo manual for details on using this mode! 34 ;; NOTE: See the accompanying texinfo manual for details on using this mode!
36 35 ;; Note: The version string is in cc-defs.
37 ;;; Commentary:
38 36
39 ;; This package provides GNU Emacs major modes for editing C, C++, 37 ;; This package provides GNU Emacs major modes for editing C, C++,
40 ;; Objective-C, Java, IDL and Pike code. As of the latest Emacs and 38 ;; Objective-C, Java, CORBA's IDL, Pike and AWK code. As of the
41 ;; XEmacs releases, it is the default package for editing these 39 ;; latest Emacs and XEmacs releases, it is the default package for
42 ;; languages. This package is called "CC Mode", and should be spelled 40 ;; editing these languages. This package is called "CC Mode", and
43 ;; exactly this way. 41 ;; should be spelled exactly this way.
44 42
45 ;; CC Mode supports K&R and ANSI C, ANSI C++, Objective-C, Java, 43 ;; CC Mode supports K&R and ANSI C, ANSI C++, Objective-C, Java,
46 ;; CORBA's IDL, and Pike with a consistent indentation model across 44 ;; CORBA's IDL, Pike and AWK with a consistent indentation model
47 ;; all modes. This indentation model is intuitive and very flexible, 45 ;; across all modes. This indentation model is intuitive and very
48 ;; so that almost any desired style of indentation can be supported. 46 ;; flexible, so that almost any desired style of indentation can be
49 ;; Installation, usage, and programming details are contained in an 47 ;; supported. Installation, usage, and programming details are
50 ;; accompanying texinfo manual. 48 ;; contained in an accompanying texinfo manual.
51 49
52 ;; CC Mode's immediate ancestors were, c++-mode.el, cplus-md.el, and 50 ;; CC Mode's immediate ancestors were, c++-mode.el, cplus-md.el, and
53 ;; cplus-md1.el.. 51 ;; cplus-md1.el..
54
55 ;; NOTE: This mode does not perform font-locking (a.k.a syntactic
56 ;; coloring, keyword highlighting, etc.) for any of the supported
57 ;; modes. Typically this is done by a package called font-lock.el
58 ;; which we do *not* maintain. You should contact the Emacs or XEmacs
59 ;; maintainers for questions about coloring or highlighting in any
60 ;; language mode.
61 52
62 ;; To submit bug reports, type "C-c C-b". These will be sent to 53 ;; To submit bug reports, type "C-c C-b". These will be sent to
63 ;; bug-gnu-emacs@gnu.org (mirrored as the Usenet newsgroup 54 ;; bug-gnu-emacs@gnu.org (mirrored as the Usenet newsgroup
64 ;; gnu.emacs.bug) as well as bug-cc-mode@gnu.org, which directly 55 ;; gnu.emacs.bug) as well as bug-cc-mode@gnu.org, which directly
65 ;; contacts the CC Mode maintainers. Questions can sent to 56 ;; contacts the CC Mode maintainers. Questions can sent to
87 (let ((load-path 78 (let ((load-path
88 (if (and (boundp 'byte-compile-dest-file) 79 (if (and (boundp 'byte-compile-dest-file)
89 (stringp byte-compile-dest-file)) 80 (stringp byte-compile-dest-file))
90 (cons (file-name-directory byte-compile-dest-file) load-path) 81 (cons (file-name-directory byte-compile-dest-file) load-path)
91 load-path))) 82 load-path)))
92 (require 'cc-bytecomp))) 83 (load "cc-bytecomp" nil t)))
93 84
94 (cc-require 'cc-defs) 85 (cc-require 'cc-defs)
95 (cc-require 'cc-menus) 86 (cc-require-when-compile 'cc-langs)
96 (cc-require 'cc-vars) 87 (cc-require 'cc-vars)
97 (cc-require 'cc-langs) 88 (cc-require 'cc-engine)
98 (cc-require 'cc-styles) 89 (cc-require 'cc-styles)
99 (cc-require 'cc-engine)
100 (cc-require 'cc-cmds) 90 (cc-require 'cc-cmds)
101 (cc-require 'cc-align) 91 (cc-require 'cc-align)
102 92 (cc-require 'cc-menus)
103 ;; Silence the compiler. 93
94 ;; SILENCE the compiler.
104 (cc-bytecomp-defvar comment-line-break-function) ; (X)Emacs 20+ 95 (cc-bytecomp-defvar comment-line-break-function) ; (X)Emacs 20+
105 (cc-bytecomp-defvar adaptive-fill-first-line-regexp) ; Emacs 20+ 96 (cc-bytecomp-defvar adaptive-fill-first-line-regexp) ; Emacs 20+
106 (cc-bytecomp-defun set-keymap-parents) ; XEmacs 97 (cc-bytecomp-defun set-keymap-parents) ; XEmacs
107 98
99 ;; We set these variables during mode init, yet we don't require
100 ;; font-lock.
101 (cc-bytecomp-defvar font-lock-defaults)
102 (cc-bytecomp-defvar font-lock-syntactic-keywords)
103
108 ;; Menu support for both XEmacs and Emacs. If you don't have easymenu 104 ;; Menu support for both XEmacs and Emacs. If you don't have easymenu
109 ;; with your version of Emacs, you are incompatible! 105 ;; with your version of Emacs, you are incompatible!
110 (require 'easymenu) 106 (cc-external-require 'easymenu)
107
108 ;; Load cc-fonts first after font-lock is loaded, since it isn't
109 ;; necessary until font locking is requested.
110 (eval-after-load "font-lock"
111 '(require 'cc-fonts))
112
113 ;; cc-langs isn't loaded when we're byte compiled, so add autoload
114 ;; directives for the interface functions.
115 (autoload 'c-make-init-lang-vars-fun "cc-langs")
116 (autoload 'c-init-language-vars "cc-langs" nil nil 'macro)
111 117
112 118
113 ;; Other modes and packages which depend on CC Mode should do the 119 ;; Other modes and packages which depend on CC Mode should do the
114 ;; following to make sure everything is loaded and available for their 120 ;; following to make sure everything is loaded and available for their
115 ;; use: 121 ;; use:
116 ;; 122 ;;
117 ;; (require 'cc-mode) 123 ;; (require 'cc-mode)
118 ;; 124 ;;
119 ;; And in the major mode function: 125 ;; And in the major mode function:
120 ;; 126 ;;
121 ;; (c-initialize-cc-mode) 127 ;; (c-initialize-cc-mode t)
128 ;; (c-init-language-vars some-mode)
129 ;; (c-common-init 'some-mode) ; Or perhaps (c-basic-common-init 'some-mode)
130 ;;
131 ;; See cc-langs.el for further info. A small example of a derived mode
132 ;; is also available at <http://cc-mode.sourceforge.net/
133 ;; derived-mode-ex.el>.
122 134
123 (defun c-leave-cc-mode-mode () 135 (defun c-leave-cc-mode-mode ()
124 (setq c-buffer-is-cc-mode nil)) 136 (setq c-buffer-is-cc-mode nil))
125 137
126 ;;;###autoload 138 ;;;###autoload
127 (defun c-initialize-cc-mode () 139 (defun c-initialize-cc-mode (&optional new-style-init)
140 "Initialize CC Mode for use in the current buffer.
141 If the optional NEW-STYLE-INIT is nil or left out then all necessary
142 initialization to run CC Mode for the C language is done. Otherwise
143 only some basic setup is done, and a call to `c-init-language-vars',
144 is necessary too (which gives more control). See \"cc-mode.el\" for
145 more info."
146 ;;
147 ;; This function does not do any hidden buffer changes.
148
128 (setq c-buffer-is-cc-mode t) 149 (setq c-buffer-is-cc-mode t)
150
129 (let ((initprop 'cc-mode-is-initialized) 151 (let ((initprop 'cc-mode-is-initialized)
130 c-initialization-ok) 152 c-initialization-ok)
131 (unless (get 'c-initialize-cc-mode initprop) 153 (unless (get 'c-initialize-cc-mode initprop)
132 (unwind-protect 154 (unwind-protect
133 (progn 155 (progn
138 (if (boundp 'c-comment-continuation-stars) 160 (if (boundp 'c-comment-continuation-stars)
139 (setq c-block-comment-prefix c-comment-continuation-stars)) 161 (setq c-block-comment-prefix c-comment-continuation-stars))
140 (add-hook 'change-major-mode-hook 'c-leave-cc-mode-mode) 162 (add-hook 'change-major-mode-hook 'c-leave-cc-mode-mode)
141 (setq c-initialization-ok t)) 163 (setq c-initialization-ok t))
142 ;; Will try initialization hooks again if they failed. 164 ;; Will try initialization hooks again if they failed.
143 (put 'c-initialize-cc-mode initprop c-initialization-ok))) 165 (put 'c-initialize-cc-mode initprop c-initialization-ok))))
144 )) 166
167 (unless new-style-init
168 (c-init-c-language-vars)))
145 169
146 170
147 ;; Common routines 171 ;;; Common routines.
172
148 (defvar c-mode-base-map () 173 (defvar c-mode-base-map ()
149 "Keymap shared by all CC Mode related modes.") 174 "Keymap shared by all CC Mode related modes.")
150 175
151 (defun c-make-inherited-keymap () 176 (defun c-make-inherited-keymap ()
152 (let ((map (make-sparse-keymap))) 177 (let ((map (make-sparse-keymap)))
153 (cond 178 (cond
154 ;; XEmacs 19 & 20 179 ;; XEmacs
155 ((fboundp 'set-keymap-parents) 180 ((fboundp 'set-keymap-parents)
156 (set-keymap-parents map c-mode-base-map)) 181 (set-keymap-parents map c-mode-base-map))
157 ;; Emacs 19 182 ;; Emacs
158 ((fboundp 'set-keymap-parent) 183 ((fboundp 'set-keymap-parent)
159 (set-keymap-parent map c-mode-base-map)) 184 (set-keymap-parent map c-mode-base-map))
160 ;; incompatible 185 ;; incompatible
161 (t (error "CC Mode is incompatible with this version of Emacs"))) 186 (t (error "CC Mode is incompatible with this version of Emacs")))
162 map)) 187 map))
163 188
164 (defun c-define-abbrev-table (name defs) 189 (defun c-define-abbrev-table (name defs)
165 ;; Compatibility wrapper for `define-abbrev' which passes a non-nil 190 ;; Compatibility wrapper for `define-abbrev' which passes a non-nil
166 ;; sixth argument for SYSTEM-FLAG in emacsen that support it 191 ;; sixth argument for SYSTEM-FLAG in emacsen that support it
167 ;; (currently only Emacs 21.2). 192 ;; (currently only Emacs 21.2).
168 (define-abbrev-table name nil) 193 (let ((table (or (symbol-value name)
169 (let ((table (symbol-value name))) 194 (progn (define-abbrev-table name nil)
195 (symbol-value name)))))
170 (while defs 196 (while defs
171 (condition-case nil 197 (condition-case nil
172 (apply 'define-abbrev table (append (car defs) '(t))) 198 (apply 'define-abbrev table (append (car defs) '(t)))
173 (wrong-number-of-arguments 199 (wrong-number-of-arguments
174 (apply 'define-abbrev table (car defs)))) 200 (apply 'define-abbrev table (car defs))))
175 (setq defs (cdr defs))))) 201 (setq defs (cdr defs)))))
202 (put 'c-define-abbrev-table 'lisp-indent-function 1)
176 203
177 (if c-mode-base-map 204 (if c-mode-base-map
178 nil 205 nil
179 ;; TBD: should we even worry about naming this keymap. My vote: no, 206 ;; TBD: should we even worry about naming this keymap. My vote: no,
180 ;; because Emacs and XEmacs do it differently. 207 ;; because Emacs and XEmacs do it differently.
214 (define-key c-mode-base-map "\C-c\C-p" 'c-backward-conditional) 241 (define-key c-mode-base-map "\C-c\C-p" 'c-backward-conditional)
215 (define-key c-mode-base-map "\C-c\C-u" 'c-up-conditional) 242 (define-key c-mode-base-map "\C-c\C-u" 'c-up-conditional)
216 (substitute-key-definition 'indent-for-tab-command 243 (substitute-key-definition 'indent-for-tab-command
217 'c-indent-command 244 'c-indent-command
218 c-mode-base-map global-map) 245 c-mode-base-map global-map)
219 ;; It doesn't suffice to put c-fill-paragraph on 246
220 ;; fill-paragraph-function due to the way it works. 247 ;; It doesn't suffice to put `c-fill-paragraph' on
248 ;; `fill-paragraph-function' since `c-fill-paragraph' must be called
249 ;; before any fill prefix adaption is done. E.g. `filladapt-mode'
250 ;; replaces `fill-paragraph' and does the adaption before calling
251 ;; `fill-paragraph-function', and we have to mask comments etc
252 ;; before that. Also, `c-fill-paragraph' chains on to
253 ;; `fill-paragraph' and the value on `fill-parapgraph-function' to
254 ;; do the actual filling work.
221 (substitute-key-definition 'fill-paragraph 'c-fill-paragraph 255 (substitute-key-definition 'fill-paragraph 'c-fill-paragraph
222 c-mode-base-map global-map) 256 c-mode-base-map global-map)
223 ;; In XEmacs the default fill function is called 257 ;; In XEmacs the default fill function is called
224 ;; fill-paragraph-or-region. 258 ;; fill-paragraph-or-region.
225 (substitute-key-definition 'fill-paragraph-or-region 'c-fill-paragraph 259 (substitute-key-definition 'fill-paragraph-or-region 'c-fill-paragraph
226 c-mode-base-map global-map) 260 c-mode-base-map global-map)
261
227 ;; Bind the electric deletion functions to C-d and DEL. Emacs 21 262 ;; Bind the electric deletion functions to C-d and DEL. Emacs 21
228 ;; automatically maps the [delete] and [backspace] keys to these two 263 ;; automatically maps the [delete] and [backspace] keys to these two
229 ;; depending on window system and user preferences. (In earlier 264 ;; depending on window system and user preferences. (In earlier
230 ;; versions it's possible to do the same by using `function-key-map'.) 265 ;; versions it's possible to do the same by using `function-key-map'.)
231 (define-key c-mode-base-map "\C-d" 'c-electric-delete-forward) 266 (define-key c-mode-base-map "\C-d" 'c-electric-delete-forward)
235 ;; behavior by binding the keysyms for the [delete] and 270 ;; behavior by binding the keysyms for the [delete] and
236 ;; [backspace] keys directly, and use `delete-forward-p' or 271 ;; [backspace] keys directly, and use `delete-forward-p' or
237 ;; `delete-key-deletes-forward' to decide what [delete] should do. 272 ;; `delete-key-deletes-forward' to decide what [delete] should do.
238 (define-key c-mode-base-map [delete] 'c-electric-delete) 273 (define-key c-mode-base-map [delete] 'c-electric-delete)
239 (define-key c-mode-base-map [backspace] 'c-electric-backspace)) 274 (define-key c-mode-base-map [backspace] 'c-electric-backspace))
240 ;; these are new keybindings, with no counterpart to BOCM
241 (define-key c-mode-base-map "," 'c-electric-semi&comma) 275 (define-key c-mode-base-map "," 'c-electric-semi&comma)
242 (define-key c-mode-base-map "*" 'c-electric-star) 276 (define-key c-mode-base-map "*" 'c-electric-star)
243 (define-key c-mode-base-map "/" 'c-electric-slash) 277 (define-key c-mode-base-map "/" 'c-electric-slash)
244 (define-key c-mode-base-map "\C-c\C-q" 'c-indent-defun) 278 (define-key c-mode-base-map "\C-c\C-q" 'c-indent-defun)
245 (define-key c-mode-base-map "\C-c\C-\\" 'c-backslash-region) 279 (define-key c-mode-base-map "\C-c\C-\\" 'c-backslash-region)
246 ;; TBD: where if anywhere, to put c-backward|forward-into-nomenclature
247 (define-key c-mode-base-map "\C-c\C-a" 'c-toggle-auto-state) 280 (define-key c-mode-base-map "\C-c\C-a" 'c-toggle-auto-state)
248 (define-key c-mode-base-map "\C-c\C-b" 'c-submit-bug-report) 281 (define-key c-mode-base-map "\C-c\C-b" 'c-submit-bug-report)
249 (define-key c-mode-base-map "\C-c\C-c" 'comment-region) 282 (define-key c-mode-base-map "\C-c\C-c" 'comment-region)
250 (define-key c-mode-base-map "\C-c\C-d" 'c-toggle-hungry-state) 283 (define-key c-mode-base-map "\C-c\C-d" 'c-toggle-hungry-state)
251 (define-key c-mode-base-map "\C-c\C-o" 'c-set-offset) 284 (define-key c-mode-base-map "\C-c\C-o" 'c-set-offset)
254 (define-key c-mode-base-map "\C-c." 'c-set-style) 287 (define-key c-mode-base-map "\C-c." 'c-set-style)
255 ;; conflicts with OOBR 288 ;; conflicts with OOBR
256 ;;(define-key c-mode-base-map "\C-c\C-v" 'c-version) 289 ;;(define-key c-mode-base-map "\C-c\C-v" 'c-version)
257 ) 290 )
258 291
259 (defvar c-c-menu nil)
260 (defvar c-c++-menu nil)
261 (defvar c-objc-menu nil)
262 (defvar c-java-menu nil)
263 (defvar c-pike-menu nil)
264
265 (defun c-mode-menu (modestr)
266 (let ((m
267 '(["Comment Out Region" comment-region (c-fn-region-is-active-p)]
268 ["Uncomment Region"
269 (comment-region (region-beginning) (region-end) '(4))
270 (c-fn-region-is-active-p)]
271 ["Fill Comment Paragraph" c-fill-paragraph t]
272 "----"
273 ["Indent Expression" c-indent-exp
274 (memq (char-after) '(?\( ?\[ ?\{))]
275 ["Indent Line or Region" c-indent-line-or-region t]
276 ["Up Conditional" c-up-conditional t]
277 ["Backward Conditional" c-backward-conditional t]
278 ["Forward Conditional" c-forward-conditional t]
279 ["Backward Statement" c-beginning-of-statement t]
280 ["Forward Statement" c-end-of-statement t]
281 "----"
282 ["Macro Expand Region" c-macro-expand (c-fn-region-is-active-p)]
283 ["Backslashify" c-backslash-region
284 (c-fn-region-is-active-p)]
285 "----"
286 ("Toggle..."
287 ["Syntactic indentation" c-toggle-syntactic-indentation t]
288 ["Auto newline" c-toggle-auto-state t]
289 ["Hungry delete" c-toggle-hungry-state t])
290 )))
291 (cons modestr m)))
292
293 ;; We don't require the outline package, but we configure it a bit anyway. 292 ;; We don't require the outline package, but we configure it a bit anyway.
294 (cc-bytecomp-defvar outline-level) 293 (cc-bytecomp-defvar outline-level)
295 294
296 (defun c-common-init (mode) 295 (defun c-mode-menu (modestr)
297 ;; Common initializations for all modes. 296 "Return a menu spec suitable for `easy-menu-define' that is exactly
297 like the C mode menu except that the menu bar item name is MODESTR
298 instead of \"C\".
299
300 This function is provided for compatibility only; derived modes should
301 preferably use the `c-mode-menu' language constant directly."
302 (cons modestr (c-lang-const c-mode-menu c)))
303
304 ;; Ugly hack to pull in the definition of `c-populate-syntax-table'
305 ;; from cc-langs to make it available at runtime. It's either this or
306 ;; moving the definition for it to cc-defs, but that would mean to
307 ;; break up the syntax table setup over two files.
308 (defalias 'c-populate-syntax-table
309 (cc-eval-when-compile
310 (let ((f (symbol-function 'c-populate-syntax-table)))
311 (if (byte-code-function-p f) f (byte-compile f)))))
312
313 (defun c-after-change (beg end len)
314 ;; Function put on `after-change-functions' to adjust various
315 ;; caches. Prefer speed to finesse here, since there will be an
316 ;; order of magnitude more calls to this function than any of the
317 ;; functions that use the caches.
318 ;;
319 ;; Note that care must be taken so that this is called before any
320 ;; font-lock callbacks since we might get calls to functions using
321 ;; these caches from inside them, and we must thus be sure that this
322 ;; has already been executed.
323 ;;
324 ;; This function does not do any hidden buffer changes.
325
326 (c-save-buffer-state ()
327 (when (> end (point-max))
328 ;; Some emacsen might return positions past the end. This has been
329 ;; observed in Emacs 20.7 when rereading a buffer changed on disk
330 ;; (haven't been able to minimize it, but Emacs 21.3 appears to
331 ;; work).
332 (setq end (point-max))
333 (when (> beg end)
334 (setq beg end)))
335
336 (c-invalidate-sws-region-after beg end)
337 (c-invalidate-state-cache beg)
338 (c-invalidate-find-decl-cache beg)))
339
340 (defun c-basic-common-init (mode default-style)
341 "Do the necessary initialization for the syntax handling routines
342 and the line breaking/filling code. Intended to be used by other
343 packages that embed CC Mode.
344
345 MODE is the CC Mode flavor to set up, e.g. 'c-mode or 'java-mode.
346 DEFAULT-STYLE tells which indentation style to install. It has the
347 same format as `c-default-style'.
348
349 Note that `c-init-language-vars' must be called before this function.
350 This function cannot do that since `c-init-language-vars' is a macro
351 that requires a literal mode spec at compile time."
352 ;;
353 ;; This function does not do any hidden buffer changes.
354
298 (setq c-buffer-is-cc-mode mode) 355 (setq c-buffer-is-cc-mode mode)
299 356
300 ;; these variables should always be buffer local; they do not affect 357 ;; these variables should always be buffer local; they do not affect
301 ;; indentation style. 358 ;; indentation style.
302 (make-local-variable 'parse-sexp-ignore-comments) 359 (make-local-variable 'parse-sexp-ignore-comments)
303 (make-local-variable 'indent-line-function) 360 (make-local-variable 'indent-line-function)
304 (make-local-variable 'indent-region-function) 361 (make-local-variable 'indent-region-function)
305 (make-local-variable 'outline-regexp)
306 (make-local-variable 'outline-level)
307 (make-local-variable 'normal-auto-fill-function) 362 (make-local-variable 'normal-auto-fill-function)
308 (make-local-variable 'comment-start) 363 (make-local-variable 'comment-start)
309 (make-local-variable 'comment-end) 364 (make-local-variable 'comment-end)
310 (make-local-variable 'comment-column)
311 (make-local-variable 'comment-start-skip) 365 (make-local-variable 'comment-start-skip)
312 (make-local-variable 'comment-multi-line) 366 (make-local-variable 'comment-multi-line)
313 (make-local-variable 'paragraph-start) 367 (make-local-variable 'paragraph-start)
314 (make-local-variable 'paragraph-separate) 368 (make-local-variable 'paragraph-separate)
315 (make-local-variable 'paragraph-ignore-fill-prefix) 369 (make-local-variable 'paragraph-ignore-fill-prefix)
316 (make-local-variable 'adaptive-fill-mode) 370 (make-local-variable 'adaptive-fill-mode)
317 (make-local-variable 'adaptive-fill-regexp) 371 (make-local-variable 'adaptive-fill-regexp)
318 (make-local-variable 'imenu-generic-expression) ;set in the mode functions
319
320 ;; X/Emacs 20 only
321 (and (boundp 'comment-line-break-function)
322 (progn
323 (make-local-variable 'comment-line-break-function)
324 (setq comment-line-break-function
325 'c-indent-new-comment-line)))
326 372
327 ;; now set their values 373 ;; now set their values
328 (setq parse-sexp-ignore-comments t 374 (setq parse-sexp-ignore-comments t
329 indent-line-function 'c-indent-line 375 indent-line-function 'c-indent-line
330 indent-region-function 'c-indent-region 376 indent-region-function 'c-indent-region
331 outline-regexp "[^#\n\^M]"
332 outline-level 'c-outline-level
333 normal-auto-fill-function 'c-do-auto-fill 377 normal-auto-fill-function 'c-do-auto-fill
334 comment-column 32
335 comment-start-skip "/\\*+ *\\|//+ *"
336 comment-multi-line t) 378 comment-multi-line t)
337 379
338 ;; Install `c-fill-paragraph' on `fill-paragraph-function' so that a 380 ;; Install `c-fill-paragraph' on `fill-paragraph-function' so that a
339 ;; direct call to `fill-paragraph' behaves better. This still 381 ;; direct call to `fill-paragraph' behaves better. This still
340 ;; doesn't work with filladapt but it's better than nothing. 382 ;; doesn't work with filladapt but it's better than nothing.
341 (make-local-variable 'fill-paragraph-function) 383 (make-local-variable 'fill-paragraph-function)
342 (setq fill-paragraph-function 'c-fill-paragraph) 384 (setq fill-paragraph-function 'c-fill-paragraph)
343 385
344 ;; Set `require-final-newline' only if we should. 386 ;; (X)Emacs 20 and later.
345 (let ((rfn (assq mode c-require-final-newline))) 387 (when (boundp 'comment-line-break-function)
346 (when rfn 388 (make-local-variable 'comment-line-break-function)
347 (make-local-variable 'require-final-newline) 389 (setq comment-line-break-function
348 (setq require-final-newline (cdr rfn)))) 390 'c-indent-new-comment-line))
349 391
350 ;; Fix keyword regexps. 392 ;; Emacs 20 and later.
351 (c-init-language-vars) 393 (when (boundp 'parse-sexp-lookup-properties)
352 394 (make-local-variable 'parse-sexp-lookup-properties)
353 ;; now set the mode style based on c-default-style 395 (setq parse-sexp-lookup-properties t))
354 (let ((style (if (stringp c-default-style) 396
355 c-default-style 397 ;; Same as above for XEmacs 21 (although currently undocumented).
356 (or (cdr (assq mode c-default-style)) 398 (when (boundp 'lookup-syntax-properties)
357 (cdr (assq 'other c-default-style)) 399 (make-local-variable 'lookup-syntax-properties)
400 (setq lookup-syntax-properties t))
401
402 ;; Use this in Emacs 21 to avoid meddling with the rear-nonsticky
403 ;; property on each character.
404 (when (boundp 'text-property-default-nonsticky)
405 (make-local-variable 'text-property-default-nonsticky)
406 (let ((elem (assq 'syntax-table text-property-default-nonsticky)))
407 (if elem
408 (setcdr elem t)
409 (setq text-property-default-nonsticky
410 (cons '(syntax-table . t)
411 text-property-default-nonsticky))))
412 (setq text-property-default-nonsticky
413 (cons '(c-type . t)
414 text-property-default-nonsticky)))
415
416 ;; In Emacs 21 and later it's possible to turn off the ad-hoc
417 ;; heuristic that open parens in column 0 are defun starters. Since
418 ;; we have c-state-cache that isn't useful and only causes trouble
419 ;; so turn it off.
420 (when (memq 'col-0-paren c-emacs-features)
421 (make-local-variable 'open-paren-in-column-0-is-defun-start)
422 (setq open-paren-in-column-0-is-defun-start nil))
423
424 ;; The `c-type' text property with `c-decl-end' is used to mark the
425 ;; ends of access keys to make interactive refontification work
426 ;; better.
427 (when c-opt-access-key
428 (setq c-type-decl-end-used t))
429
430 (c-clear-found-types)
431
432 ;; now set the mode style based on default-style
433 (let ((style (if (stringp default-style)
434 default-style
435 (or (cdr (assq mode default-style))
436 (cdr (assq 'other default-style))
358 "gnu")))) 437 "gnu"))))
359 ;; Override style variables if `c-old-style-variable-behavior' is 438 ;; Override style variables if `c-old-style-variable-behavior' is
360 ;; set. Also override if we are using global style variables, 439 ;; set. Also override if we are using global style variables,
361 ;; have already initialized a style once, and are switching to a 440 ;; have already initialized a style once, and are switching to a
362 ;; different style. (It's doubtful whether this is desirable, but 441 ;; different style. (It's doubtful whether this is desirable, but
376 455
377 ;; setup the comment indent variable in a Emacs version portable way 456 ;; setup the comment indent variable in a Emacs version portable way
378 (make-local-variable 'comment-indent-function) 457 (make-local-variable 'comment-indent-function)
379 (setq comment-indent-function 'c-comment-indent) 458 (setq comment-indent-function 'c-comment-indent)
380 459
381 ;; add menus to menubar
382 (easy-menu-add (c-mode-menu mode-name))
383
384 ;; put auto-hungry designators onto minor-mode-alist, but only once 460 ;; put auto-hungry designators onto minor-mode-alist, but only once
385 (or (assq 'c-auto-hungry-string minor-mode-alist) 461 (or (assq 'c-auto-hungry-string minor-mode-alist)
386 (setq minor-mode-alist 462 (setq minor-mode-alist
387 (cons '(c-auto-hungry-string c-auto-hungry-string) 463 (cons '(c-auto-hungry-string c-auto-hungry-string)
388 minor-mode-alist))) 464 minor-mode-alist)))
389 465
390 ;; Install the function that ensures `c-state-cache' doesn't become 466 ;; Install the functions that ensure that various internal caches
391 ;; invalid. 467 ;; don't become invalid due to buffer changes.
392 (make-local-variable 'after-change-functions) 468 (make-local-hook 'after-change-functions)
393 (add-hook 'after-change-functions 'c-check-state-cache)) 469 (add-hook 'after-change-functions 'c-after-change nil t))
470
471 (defun c-after-font-lock-init ()
472 ;; Put on `font-lock-mode-hook'.
473 (remove-hook 'after-change-functions 'c-after-change t)
474 (add-hook 'after-change-functions 'c-after-change nil t))
475
476 (defun c-font-lock-init ()
477 "Set up the font-lock variables for using the font-lock support in CC Mode.
478 This does not load the font-lock package. Use after
479 `c-basic-common-init' and after cc-fonts has been loaded."
480
481 (make-local-variable 'font-lock-defaults)
482 (setq font-lock-defaults
483 `(,(if (c-mode-is-new-awk-p)
484 ;; awk-mode currently has only one font lock level.
485 'awk-font-lock-keywords
486 (mapcar 'c-mode-symbol
487 '("font-lock-keywords" "font-lock-keywords-1"
488 "font-lock-keywords-2" "font-lock-keywords-3")))
489 nil nil
490 ,c-identifier-syntax-modifications
491 c-beginning-of-syntax
492 (font-lock-mark-block-function
493 . c-mark-function)))
494
495 (make-local-hook 'font-lock-mode-hook)
496 (add-hook 'font-lock-mode-hook 'c-after-font-lock-init nil t))
497
498 (defun c-setup-doc-comment-style ()
499 "Initialize the variables that depend on the value of `c-doc-comment-style'."
500 (when (and (featurep 'font-lock)
501 (symbol-value 'font-lock-mode))
502 ;; Force font lock mode to reinitialize itself.
503 (font-lock-mode 0)
504 (font-lock-mode 1)))
505
506 (defun c-common-init (&optional mode)
507 "Common initialization for all CC Mode modes.
508 In addition to the work done by `c-basic-common-init' and
509 `c-font-lock-init', this function sets up various other things as
510 customary in CC Mode modes but which aren't strictly necessary for CC
511 Mode to operate correctly.
512
513 MODE is the symbol for the mode to initialize, like 'c-mode. See
514 `c-basic-common-init' for details. It's only optional to be
515 compatible with old code; callers should always specify it.
516
517 This function does not do any hidden buffer changes."
518
519 (unless mode
520 ;; Called from an old third party package. The fallback is to
521 ;; initialize for C.
522 (c-init-c-language-vars))
523
524 (c-basic-common-init mode c-default-style)
525 (when mode
526 ;; Only initialize font locking if we aren't called from an old package.
527 (c-font-lock-init))
528
529 (make-local-variable 'outline-regexp)
530 (make-local-variable 'outline-level)
531 (setq outline-regexp "[^#\n\^M]"
532 outline-level 'c-outline-level)
533
534 (let ((rfn (assq mode c-require-final-newline)))
535 (when rfn
536 (make-local-variable 'require-final-newline)
537 (setq require-final-newline (cdr rfn)))))
394 538
395 (defun c-postprocess-file-styles () 539 (defun c-postprocess-file-styles ()
396 "Function that post processes relevant file local variables. 540 "Function that post processes relevant file local variables in CC Mode.
397 Currently, this function simply applies any style and offset settings 541 Currently, this function simply applies any style and offset settings
398 found in the file's Local Variable list. It first applies any style 542 found in the file's Local Variable list. It first applies any style
399 setting found in `c-file-style', then it applies any offset settings 543 setting found in `c-file-style', then it applies any offset settings
400 it finds in `c-file-offsets'. 544 it finds in `c-file-offsets'.
401 545
402 Note that the style variables are always made local to the buffer." 546 Note that the style variables are always made local to the buffer."
547 ;;
548 ;; This function does not do any hidden buffer changes.
549
403 ;; apply file styles and offsets 550 ;; apply file styles and offsets
404 (when c-buffer-is-cc-mode 551 (when c-buffer-is-cc-mode
405 (if (or c-file-style c-file-offsets) 552 (if (or c-file-style c-file-offsets)
406 (c-make-styles-buffer-local t)) 553 (c-make-styles-buffer-local t))
407 (and c-file-style 554 (and c-file-style
417 (add-hook 'hack-local-variables-hook 'c-postprocess-file-styles) 564 (add-hook 'hack-local-variables-hook 'c-postprocess-file-styles)
418 565
419 566
420 ;; Support for C 567 ;; Support for C
421 568
569 ;;;###autoload
570 (defvar c-mode-syntax-table nil
571 "Syntax table used in c-mode buffers.")
572 (or c-mode-syntax-table
573 (setq c-mode-syntax-table
574 (funcall (c-lang-const c-make-mode-syntax-table c))))
575
422 (defvar c-mode-abbrev-table nil 576 (defvar c-mode-abbrev-table nil
423 "Abbreviation table used in c-mode buffers.") 577 "Abbreviation table used in c-mode buffers.")
424 (c-define-abbrev-table 'c-mode-abbrev-table 578 (c-define-abbrev-table 'c-mode-abbrev-table
425 '(("else" "else" c-electric-continued-statement 0) 579 '(("else" "else" c-electric-continued-statement 0)
426 ("while" "while" c-electric-continued-statement 0))) 580 ("while" "while" c-electric-continued-statement 0)))
433 ;; add bindings which are only useful for C 587 ;; add bindings which are only useful for C
434 (define-key c-mode-map "\C-c\C-e" 'c-macro-expand) 588 (define-key c-mode-map "\C-c\C-e" 'c-macro-expand)
435 ) 589 )
436 590
437 (easy-menu-define c-c-menu c-mode-map "C Mode Commands" 591 (easy-menu-define c-c-menu c-mode-map "C Mode Commands"
438 (c-mode-menu "C")) 592 (cons "C" (c-lang-const c-mode-menu c)))
593
594 ;; In XEmacs >= 21.5 modes should add their own entries to
595 ;; `auto-mode-alist'. The comment form of autoload is used to avoid
596 ;; doing this on load. That since `add-to-list' prepends the value
597 ;; which could cause it to clobber user settings. Later emacsen have
598 ;; an append option, but it's not safe to use.
599 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.[ch]\\'" . c-mode))
600
601 ;; NB: The following two associate yacc and lex files to C Mode, which
602 ;; is not really suitable for those formats. Anyway, afaik there's
603 ;; currently no better mode for them, and besides this is legacy.
604 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.y\\(acc\\)?\\'" . c-mode))
605 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.lex\\'" . c-mode))
606
607 (defun c-init-c-language-vars ()
608 (c-init-language-vars c-mode))
439 609
440 ;;;###autoload 610 ;;;###autoload
441 (defun c-mode () 611 (defun c-mode ()
442 "Major mode for editing K&R and ANSI C code. 612 "Major mode for editing K&R and ANSI C code.
443 To submit a problem report, enter `\\[c-submit-bug-report]' from a 613 To submit a problem report, enter `\\[c-submit-bug-report]' from a
445 information already added. You just need to add a description of the 615 information already added. You just need to add a description of the
446 problem, including a reproducible test case and send the message. 616 problem, including a reproducible test case and send the message.
447 617
448 To see what version of CC Mode you are running, enter `\\[c-version]'. 618 To see what version of CC Mode you are running, enter `\\[c-version]'.
449 619
450 The hook variable `c-mode-hook' is run with no args, if that value is 620 The hook `c-mode-common-hook' is run with no args at mode
451 bound and has a non-nil value. Also the hook `c-mode-common-hook' is 621 initialization, then `c-mode-hook'.
452 run first.
453 622
454 Key bindings: 623 Key bindings:
455 \\{c-mode-map}" 624 \\{c-mode-map}"
456 (interactive) 625 (interactive)
457 (kill-all-local-variables) 626 (kill-all-local-variables)
458 (c-initialize-cc-mode) 627 (c-initialize-cc-mode t)
459 (set-syntax-table c-mode-syntax-table) 628 (set-syntax-table c-mode-syntax-table)
460 (setq major-mode 'c-mode 629 (setq major-mode 'c-mode
461 mode-name "C" 630 mode-name "C"
462 local-abbrev-table c-mode-abbrev-table 631 local-abbrev-table c-mode-abbrev-table
463 abbrev-mode t) 632 abbrev-mode t)
464 (use-local-map c-mode-map) 633 (use-local-map c-mode-map)
634 (c-init-c-language-vars)
465 (c-common-init 'c-mode) 635 (c-common-init 'c-mode)
636 (easy-menu-add c-c-menu)
466 (cc-imenu-init cc-imenu-c-generic-expression) 637 (cc-imenu-init cc-imenu-c-generic-expression)
467 (run-hooks 'c-mode-common-hook) 638 (run-hooks 'c-mode-common-hook)
468 (run-hooks 'c-mode-hook) 639 (run-hooks 'c-mode-hook)
469 (c-update-modeline)) 640 (c-update-modeline))
470 641
471 642
472 ;; Support for C++ 643 ;; Support for C++
644
645 ;;;###autoload
646 (defvar c++-mode-syntax-table nil
647 "Syntax table used in c++-mode buffers.")
648 (or c++-mode-syntax-table
649 (setq c++-mode-syntax-table
650 (funcall (c-lang-const c-make-mode-syntax-table c++))))
473 651
474 (defvar c++-mode-abbrev-table nil 652 (defvar c++-mode-abbrev-table nil
475 "Abbreviation table used in c++-mode buffers.") 653 "Abbreviation table used in c++-mode buffers.")
476 (c-define-abbrev-table 'c++-mode-abbrev-table 654 (c-define-abbrev-table 'c++-mode-abbrev-table
477 '(("else" "else" c-electric-continued-statement 0) 655 '(("else" "else" c-electric-continued-statement 0)
488 (define-key c++-mode-map "\C-c:" 'c-scope-operator) 666 (define-key c++-mode-map "\C-c:" 'c-scope-operator)
489 (define-key c++-mode-map "<" 'c-electric-lt-gt) 667 (define-key c++-mode-map "<" 'c-electric-lt-gt)
490 (define-key c++-mode-map ">" 'c-electric-lt-gt)) 668 (define-key c++-mode-map ">" 'c-electric-lt-gt))
491 669
492 (easy-menu-define c-c++-menu c++-mode-map "C++ Mode Commands" 670 (easy-menu-define c-c++-menu c++-mode-map "C++ Mode Commands"
493 (c-mode-menu "C++")) 671 (cons "C++" (c-lang-const c-mode-menu c++)))
672
673 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.\\(cc\\|hh\\)\\'" . c++-mode))
674 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.[ch]\\(pp\\|xx\\|\\+\\+\\)\\'" . c++-mode))
675 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.\\(CC?\\|HH?\\)\\'" . c++-mode))
494 676
495 ;;;###autoload 677 ;;;###autoload
496 (defun c++-mode () 678 (defun c++-mode ()
497 "Major mode for editing C++ code. 679 "Major mode for editing C++ code.
498 To submit a problem report, enter `\\[c-submit-bug-report]' from a 680 To submit a problem report, enter `\\[c-submit-bug-report]' from a
501 of the problem, including a reproducible test case, and send the 683 of the problem, including a reproducible test case, and send the
502 message. 684 message.
503 685
504 To see what version of CC Mode you are running, enter `\\[c-version]'. 686 To see what version of CC Mode you are running, enter `\\[c-version]'.
505 687
506 The hook variable `c++-mode-hook' is run with no args, if that 688 The hook `c-mode-common-hook' is run with no args at mode
507 variable is bound and has a non-nil value. Also the hook 689 initialization, then `c++-mode-hook'.
508 `c-mode-common-hook' is run first.
509 690
510 Key bindings: 691 Key bindings:
511 \\{c++-mode-map}" 692 \\{c++-mode-map}"
512 (interactive) 693 (interactive)
513 (kill-all-local-variables) 694 (kill-all-local-variables)
514 (c-initialize-cc-mode) 695 (c-initialize-cc-mode t)
515 (set-syntax-table c++-mode-syntax-table) 696 (set-syntax-table c++-mode-syntax-table)
516 (setq major-mode 'c++-mode 697 (setq major-mode 'c++-mode
517 mode-name "C++" 698 mode-name "C++"
518 local-abbrev-table c++-mode-abbrev-table 699 local-abbrev-table c++-mode-abbrev-table
519 abbrev-mode t) 700 abbrev-mode t)
520 (use-local-map c++-mode-map) 701 (use-local-map c++-mode-map)
702 (c-init-language-vars c++-mode)
521 (c-common-init 'c++-mode) 703 (c-common-init 'c++-mode)
704 (easy-menu-add c-c++-menu)
522 (cc-imenu-init cc-imenu-c++-generic-expression) 705 (cc-imenu-init cc-imenu-c++-generic-expression)
523 (run-hooks 'c-mode-common-hook) 706 (run-hooks 'c-mode-common-hook)
524 (run-hooks 'c++-mode-hook) 707 (run-hooks 'c++-mode-hook)
525 (c-update-modeline)) 708 (c-update-modeline))
526 709
527 710
528 ;; Support for Objective-C 711 ;; Support for Objective-C
712
713 ;;;###autoload
714 (defvar objc-mode-syntax-table nil
715 "Syntax table used in objc-mode buffers.")
716 (or objc-mode-syntax-table
717 (setq objc-mode-syntax-table
718 (funcall (c-lang-const c-make-mode-syntax-table objc))))
529 719
530 (defvar objc-mode-abbrev-table nil 720 (defvar objc-mode-abbrev-table nil
531 "Abbreviation table used in objc-mode buffers.") 721 "Abbreviation table used in objc-mode buffers.")
532 (c-define-abbrev-table 'objc-mode-abbrev-table 722 (c-define-abbrev-table 'objc-mode-abbrev-table
533 '(("else" "else" c-electric-continued-statement 0) 723 '(("else" "else" c-electric-continued-statement 0)
540 (setq objc-mode-map (c-make-inherited-keymap)) 730 (setq objc-mode-map (c-make-inherited-keymap))
541 ;; add bindings which are only useful for Objective-C 731 ;; add bindings which are only useful for Objective-C
542 (define-key objc-mode-map "\C-c\C-e" 'c-macro-expand)) 732 (define-key objc-mode-map "\C-c\C-e" 'c-macro-expand))
543 733
544 (easy-menu-define c-objc-menu objc-mode-map "ObjC Mode Commands" 734 (easy-menu-define c-objc-menu objc-mode-map "ObjC Mode Commands"
545 (c-mode-menu "ObjC")) 735 (cons "ObjC" (c-lang-const c-mode-menu objc)))
736
737 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.m\\'" . objc-mode))
546 738
547 ;;;###autoload 739 ;;;###autoload
548 (defun objc-mode () 740 (defun objc-mode ()
549 "Major mode for editing Objective C code. 741 "Major mode for editing Objective C code.
550 To submit a problem report, enter `\\[c-submit-bug-report]' from an 742 To submit a problem report, enter `\\[c-submit-bug-report]' from an
553 of the problem, including a reproducible test case, and send the 745 of the problem, including a reproducible test case, and send the
554 message. 746 message.
555 747
556 To see what version of CC Mode you are running, enter `\\[c-version]'. 748 To see what version of CC Mode you are running, enter `\\[c-version]'.
557 749
558 The hook variable `objc-mode-hook' is run with no args, if that value 750 The hook `c-mode-common-hook' is run with no args at mode
559 is bound and has a non-nil value. Also the hook `c-mode-common-hook' 751 initialization, then `objc-mode-hook'.
560 is run first.
561 752
562 Key bindings: 753 Key bindings:
563 \\{objc-mode-map}" 754 \\{objc-mode-map}"
564 (interactive) 755 (interactive)
565 (kill-all-local-variables) 756 (kill-all-local-variables)
566 (c-initialize-cc-mode) 757 (c-initialize-cc-mode t)
567 (set-syntax-table objc-mode-syntax-table) 758 (set-syntax-table objc-mode-syntax-table)
568 (setq major-mode 'objc-mode 759 (setq major-mode 'objc-mode
569 mode-name "ObjC" 760 mode-name "ObjC"
570 local-abbrev-table objc-mode-abbrev-table 761 local-abbrev-table objc-mode-abbrev-table
571 abbrev-mode t) 762 abbrev-mode t)
763 ;; The `c-type' text property with `c-decl-end' is used to mark the
764 ;; end of the @-style directives.
765 (setq c-type-decl-end-used t)
572 (use-local-map objc-mode-map) 766 (use-local-map objc-mode-map)
767 (c-init-language-vars objc-mode)
573 (c-common-init 'objc-mode) 768 (c-common-init 'objc-mode)
574 (cc-imenu-init cc-imenu-objc-generic-expression) 769 (easy-menu-add c-objc-menu)
770 (cc-imenu-init nil 'cc-imenu-objc-function)
575 (run-hooks 'c-mode-common-hook) 771 (run-hooks 'c-mode-common-hook)
576 (run-hooks 'objc-mode-hook) 772 (run-hooks 'objc-mode-hook)
577 (c-update-modeline)) 773 (c-update-modeline))
578 774
579 775
580 ;; Support for Java 776 ;; Support for Java
777
778 ;;;###autoload
779 (defvar java-mode-syntax-table nil
780 "Syntax table used in java-mode buffers.")
781 (or java-mode-syntax-table
782 (setq java-mode-syntax-table
783 (funcall (c-lang-const c-make-mode-syntax-table java))))
581 784
582 (defvar java-mode-abbrev-table nil 785 (defvar java-mode-abbrev-table nil
583 "Abbreviation table used in java-mode buffers.") 786 "Abbreviation table used in java-mode buffers.")
584 (c-define-abbrev-table 'java-mode-abbrev-table 787 (c-define-abbrev-table 'java-mode-abbrev-table
585 '(("else" "else" c-electric-continued-statement 0) 788 '(("else" "else" c-electric-continued-statement 0)
593 nil 796 nil
594 (setq java-mode-map (c-make-inherited-keymap)) 797 (setq java-mode-map (c-make-inherited-keymap))
595 ;; add bindings which are only useful for Java 798 ;; add bindings which are only useful for Java
596 ) 799 )
597 800
801 ;; Regexp trying to describe the beginning of a Java top-level
802 ;; definition. This is not used by CC Mode, nor is it maintained
803 ;; since it's practically impossible to write a regexp that reliably
804 ;; matches such a construct. Other tools are necessary.
805 (defconst c-Java-defun-prompt-regexp
806 "^[ \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:;.,{}()=]*\\|\\([_$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-*")
807
598 (easy-menu-define c-java-menu java-mode-map "Java Mode Commands" 808 (easy-menu-define c-java-menu java-mode-map "Java Mode Commands"
599 (c-mode-menu "Java")) 809 (cons "Java" (c-lang-const c-mode-menu java)))
810
811 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.java\\'" . java-mode))
600 812
601 ;;;###autoload 813 ;;;###autoload
602 (defun java-mode () 814 (defun java-mode ()
603 "Major mode for editing Java code. 815 "Major mode for editing Java code.
604 To submit a problem report, enter `\\[c-submit-bug-report]' from a 816 To submit a problem report, enter `\\[c-submit-bug-report]' from a
607 of the problem, including a reproducible test case and send the 819 of the problem, including a reproducible test case and send the
608 message. 820 message.
609 821
610 To see what version of CC Mode you are running, enter `\\[c-version]'. 822 To see what version of CC Mode you are running, enter `\\[c-version]'.
611 823
612 The hook variable `java-mode-hook' is run with no args, if that value 824 The hook `c-mode-common-hook' is run with no args at mode
613 is bound and has a non-nil value. Also the common hook 825 initialization, then `java-mode-hook'.
614 `c-mode-common-hook' is run first. Note that this mode automatically
615 sets the \"java\" style before calling any hooks so be careful if you
616 set styles in `c-mode-common-hook'.
617 826
618 Key bindings: 827 Key bindings:
619 \\{java-mode-map}" 828 \\{java-mode-map}"
620 (interactive) 829 (interactive)
621 (kill-all-local-variables) 830 (kill-all-local-variables)
622 (c-initialize-cc-mode) 831 (c-initialize-cc-mode t)
623 (set-syntax-table java-mode-syntax-table) 832 (set-syntax-table java-mode-syntax-table)
624 (setq major-mode 'java-mode 833 (setq major-mode 'java-mode
625 mode-name "Java" 834 mode-name "Java"
626 local-abbrev-table java-mode-abbrev-table 835 local-abbrev-table java-mode-abbrev-table
627 abbrev-mode t) 836 abbrev-mode t)
628 (use-local-map java-mode-map) 837 (use-local-map java-mode-map)
838 (c-init-language-vars java-mode)
629 (c-common-init 'java-mode) 839 (c-common-init 'java-mode)
840 (easy-menu-add c-java-menu)
630 (cc-imenu-init cc-imenu-java-generic-expression) 841 (cc-imenu-init cc-imenu-java-generic-expression)
631 (run-hooks 'c-mode-common-hook) 842 (run-hooks 'c-mode-common-hook)
632 (run-hooks 'java-mode-hook) 843 (run-hooks 'java-mode-hook)
633 (c-update-modeline)) 844 (c-update-modeline))
634 845
635 846
636 ;; Support for CORBA's IDL language 847 ;; Support for CORBA's IDL language
848
849 ;;;###autoload
850 (defvar idl-mode-syntax-table nil
851 "Syntax table used in idl-mode buffers.")
852 (or idl-mode-syntax-table
853 (setq idl-mode-syntax-table
854 (funcall (c-lang-const c-make-mode-syntax-table idl))))
637 855
638 (defvar idl-mode-abbrev-table nil 856 (defvar idl-mode-abbrev-table nil
639 "Abbreviation table used in idl-mode buffers.") 857 "Abbreviation table used in idl-mode buffers.")
640 (c-define-abbrev-table 'idl-mode-abbrev-table nil) 858 (c-define-abbrev-table 'idl-mode-abbrev-table nil)
641 859
646 (setq idl-mode-map (c-make-inherited-keymap)) 864 (setq idl-mode-map (c-make-inherited-keymap))
647 ;; add bindings which are only useful for IDL 865 ;; add bindings which are only useful for IDL
648 ) 866 )
649 867
650 (easy-menu-define c-idl-menu idl-mode-map "IDL Mode Commands" 868 (easy-menu-define c-idl-menu idl-mode-map "IDL Mode Commands"
651 (c-mode-menu "IDL")) 869 (cons "IDL" (c-lang-const c-mode-menu idl)))
870
871 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.idl\\'" . idl-mode))
652 872
653 ;;;###autoload 873 ;;;###autoload
654 (defun idl-mode () 874 (defun idl-mode ()
655 "Major mode for editing CORBA's IDL code. 875 "Major mode for editing CORBA's IDL, PSDL and CIDL code.
656 To submit a problem report, enter `\\[c-submit-bug-report]' from an 876 To submit a problem report, enter `\\[c-submit-bug-report]' from an
657 idl-mode buffer. This automatically sets up a mail buffer with 877 idl-mode buffer. This automatically sets up a mail buffer with
658 version information already added. You just need to add a description 878 version information already added. You just need to add a description
659 of the problem, including a reproducible test case, and send the 879 of the problem, including a reproducible test case, and send the
660 message. 880 message.
661 881
662 To see what version of CC Mode you are running, enter `\\[c-version]'. 882 To see what version of CC Mode you are running, enter `\\[c-version]'.
663 883
664 The hook variable `idl-mode-hook' is run with no args, if that 884 The hook `c-mode-common-hook' is run with no args at mode
665 variable is bound and has a non-nil value. Also the hook 885 initialization, then `idl-mode-hook'.
666 `c-mode-common-hook' is run first.
667 886
668 Key bindings: 887 Key bindings:
669 \\{idl-mode-map}" 888 \\{idl-mode-map}"
670 (interactive) 889 (interactive)
671 (kill-all-local-variables) 890 (kill-all-local-variables)
672 (c-initialize-cc-mode) 891 (c-initialize-cc-mode t)
673 (set-syntax-table idl-mode-syntax-table) 892 (set-syntax-table idl-mode-syntax-table)
674 (setq major-mode 'idl-mode 893 (setq major-mode 'idl-mode
675 mode-name "IDL" 894 mode-name "IDL"
676 local-abbrev-table idl-mode-abbrev-table) 895 local-abbrev-table idl-mode-abbrev-table)
677 (use-local-map idl-mode-map) 896 (use-local-map idl-mode-map)
897 (c-init-language-vars idl-mode)
678 (c-common-init 'idl-mode) 898 (c-common-init 'idl-mode)
679 ;;(cc-imenu-init cc-imenu-idl-generic-expression) ;FIXME 899 (easy-menu-add c-idl-menu)
900 ;;(cc-imenu-init cc-imenu-idl-generic-expression) ;TODO
680 (run-hooks 'c-mode-common-hook) 901 (run-hooks 'c-mode-common-hook)
681 (run-hooks 'idl-mode-hook) 902 (run-hooks 'idl-mode-hook)
682 (c-update-modeline)) 903 (c-update-modeline))
683 904
684 905
685 ;; Support for Pike 906 ;; Support for Pike
907
908 ;;;###autoload
909 (defvar pike-mode-syntax-table nil
910 "Syntax table used in pike-mode buffers.")
911 (or pike-mode-syntax-table
912 (setq pike-mode-syntax-table
913 (funcall (c-lang-const c-make-mode-syntax-table pike))))
686 914
687 (defvar pike-mode-abbrev-table nil 915 (defvar pike-mode-abbrev-table nil
688 "Abbreviation table used in pike-mode buffers.") 916 "Abbreviation table used in pike-mode buffers.")
689 (c-define-abbrev-table 'pike-mode-abbrev-table 917 (c-define-abbrev-table 'pike-mode-abbrev-table
690 '(("else" "else" c-electric-continued-statement 0) 918 '(("else" "else" c-electric-continued-statement 0)
697 (setq pike-mode-map (c-make-inherited-keymap)) 925 (setq pike-mode-map (c-make-inherited-keymap))
698 ;; additional bindings 926 ;; additional bindings
699 (define-key pike-mode-map "\C-c\C-e" 'c-macro-expand)) 927 (define-key pike-mode-map "\C-c\C-e" 'c-macro-expand))
700 928
701 (easy-menu-define c-pike-menu pike-mode-map "Pike Mode Commands" 929 (easy-menu-define c-pike-menu pike-mode-map "Pike Mode Commands"
702 (c-mode-menu "Pike")) 930 (cons "Pike" (c-lang-const c-mode-menu pike)))
931
932 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.\\(pike\\|pmod\\(.in\\)?\\)\\'" . pike-mode))
933 ;;;###autoload (add-to-list 'interpreter-mode-alist '(("pike" . pike-mode)))
703 934
704 ;;;###autoload 935 ;;;###autoload
705 (defun pike-mode () 936 (defun pike-mode ()
706 "Major mode for editing Pike code. 937 "Major mode for editing Pike code.
707 To submit a problem report, enter `\\[c-submit-bug-report]' from a 938 To submit a problem report, enter `\\[c-submit-bug-report]' from a
710 of the problem, including a reproducible test case, and send the 941 of the problem, including a reproducible test case, and send the
711 message. 942 message.
712 943
713 To see what version of CC Mode you are running, enter `\\[c-version]'. 944 To see what version of CC Mode you are running, enter `\\[c-version]'.
714 945
715 The hook variable `pike-mode-hook' is run with no args, if that value 946 The hook `c-mode-common-hook' is run with no args at mode
716 is bound and has a non-nil value. Also the common hook 947 initialization, then `pike-mode-hook'.
717 `c-mode-common-hook' is run first.
718 948
719 Key bindings: 949 Key bindings:
720 \\{pike-mode-map}" 950 \\{pike-mode-map}"
721 (interactive) 951 (interactive)
722 (kill-all-local-variables) 952 (kill-all-local-variables)
723 (c-initialize-cc-mode) 953 (c-initialize-cc-mode t)
724 (set-syntax-table pike-mode-syntax-table) 954 (set-syntax-table pike-mode-syntax-table)
725 (setq major-mode 'pike-mode 955 (setq major-mode 'pike-mode
726 mode-name "Pike" 956 mode-name "Pike"
727 local-abbrev-table pike-mode-abbrev-table 957 local-abbrev-table pike-mode-abbrev-table
728 abbrev-mode t) 958 abbrev-mode t)
729 (use-local-map pike-mode-map) 959 (use-local-map pike-mode-map)
960 (c-init-language-vars pike-mode)
730 (c-common-init 'pike-mode) 961 (c-common-init 'pike-mode)
731 ;;(cc-imenu-init cc-imenu-pike-generic-expression) ;FIXME 962 (easy-menu-add c-pike-menu)
963 ;;(cc-imenu-init cc-imenu-pike-generic-expression) ;TODO
732 (run-hooks 'c-mode-common-hook) 964 (run-hooks 'c-mode-common-hook)
733 (run-hooks 'pike-mode-hook) 965 (run-hooks 'pike-mode-hook)
734 (c-update-modeline)) 966 (c-update-modeline))
967
968
969 ;; Support for awk. This is purposely disabled for older (X)Emacsen which
970 ;; don't support syntax-table properties.
971
972 (if (not (memq 'syntax-properties c-emacs-features))
973 (autoload 'awk-mode "awk-mode.el" "Major mode for editing AWK code.
974 To submit a problem report, enter `\\[c-submit-bug-report]' from an
975 awk-mode buffer. This automatically sets up a mail buffer with version
976 information already added. You just need to add a description of the
977 problem, including a reproducible test case and send the message.
978
979 To see what version of CC Mode you are running, enter `\\[c-version]'.
980
981 The hook `c-mode-common-hook' is run with no args at mode
982 initialization, then `awk-mode-hook'.
983 " t)
984 (defvar awk-mode-abbrev-table nil
985 "Abbreviation table used in awk-mode buffers.")
986 (c-define-abbrev-table 'awk-mode-abbrev-table
987 '(("else" "else" c-electric-continued-statement 0)
988 ("while" "while" c-electric-continued-statement 0)))
989
990 (defvar awk-mode-map ()
991 "Keymap used in awk-mode buffers.")
992 (if awk-mode-map
993 nil
994 (setq awk-mode-map (c-make-inherited-keymap))
995 ;; add bindings which are only useful for awk.
996 (define-key awk-mode-map "#" 'self-insert-command)
997 (define-key awk-mode-map "/" 'self-insert-command)
998 (define-key awk-mode-map "*" 'self-insert-command)
999 (define-key awk-mode-map "\C-c\C-n" 'undefined) ; #if doesn't exist in awk.
1000 (define-key awk-mode-map "\C-c\C-p" 'undefined)
1001 (define-key awk-mode-map "\C-c\C-u" 'undefined)
1002 (define-key awk-mode-map "\M-a" 'undefined) ; c-awk-beginning-of-statement isn't yet implemented.
1003 (define-key awk-mode-map "\M-e" 'undefined) ; c-awk-end-of-statement isn't yet implemented.
1004 (define-key awk-mode-map "\C-\M-a" 'c-awk-beginning-of-defun)
1005 (define-key awk-mode-map "\C-\M-e" 'c-awk-end-of-defun))
1006
1007 (easy-menu-define c-awk-menu awk-mode-map "AWK Mode Commands"
1008 (cons "AWK" (c-lang-const c-mode-menu awk)))
1009
1010 ;; In XEmacs >= 21.5 modes should add their own entries to
1011 ;; `auto-mode-alist' and `interpreter-mode-alist'.
1012 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.awk\\'" . awk-mode))
1013 ;;;###autoload (add-to-list 'interpreter-mode-alist '(("awk" . awk-mode) ("mawk" . awk-mode) ("nawk" . awk-mode) ("gawk" . awk-mode)))
1014
1015 ;;;###autoload
1016 (defun awk-mode ()
1017 "Major mode for editing AWK code.
1018 To submit a problem report, enter `\\[c-submit-bug-report]' from an
1019 awk-mode buffer. This automatically sets up a mail buffer with version
1020 information already added. You just need to add a description of the
1021 problem, including a reproducible test case and send the message.
1022
1023 To see what version of CC Mode you are running, enter `\\[c-version]'.
1024
1025 The hook `c-mode-common-hook' is run with no args at mode
1026 initialization, then `awk-mode-hook'.
1027
1028 Key bindings:
1029 \\{awk-mode-map}"
1030 (interactive)
1031 (require 'cc-awk) ; Added 2003/6/10.
1032 (kill-all-local-variables)
1033 (c-initialize-cc-mode t)
1034 (set-syntax-table awk-mode-syntax-table)
1035 (setq major-mode 'awk-mode
1036 mode-name "AWK"
1037 local-abbrev-table awk-mode-abbrev-table
1038 abbrev-mode t)
1039 (use-local-map awk-mode-map)
1040 (c-init-language-vars awk-mode)
1041 (c-common-init 'awk-mode)
1042 ;; The rest of CC Mode does not (yet) use `font-lock-syntactic-keywords',
1043 ;; so it's not set by `c-font-lock-init'.
1044 (make-local-variable 'font-lock-syntactic-keywords)
1045 (setq font-lock-syntactic-keywords
1046 '((c-awk-set-syntax-table-properties
1047 0 (0) ; Everything on this line is a dummy.
1048 nil t)))
1049 (c-awk-unstick-NL-prop)
1050 (add-hook 'before-change-functions 'c-awk-before-change nil t)
1051 (add-hook 'after-change-functions 'c-awk-after-change nil t)
1052 (c-save-buffer-state nil
1053 (save-restriction
1054 (widen)
1055 (c-awk-clear-NL-props (point-min) (point-max))
1056 (c-awk-after-change (point-min) (point-max) 0))) ; Set syntax-table props.
1057
1058 ;; Prevent Xemacs's buffer-syntactic-context being used. See the comment
1059 ;; in cc-engine.el, just before (defun c-fast-in-literal ...
1060 (defalias 'c-in-literal 'c-slow-in-literal)
1061
1062 (run-hooks 'c-mode-common-hook)
1063 (run-hooks 'awk-mode-hook)
1064 (c-update-modeline))
1065 ) ;; closes the (if (not (memq 'syntax-properties c-emacs-features))
735 1066
736 1067
737 ;; bug reporting 1068 ;; bug reporting
738 1069
739 (defconst c-mode-help-address 1070 (defconst c-mode-help-address
762 (style c-indentation-style) 1093 (style c-indentation-style)
763 (c-features c-emacs-features)) 1094 (c-features c-emacs-features))
764 (and 1095 (and
765 (if (y-or-n-p "Do you want to submit a report on CC Mode? ") 1096 (if (y-or-n-p "Do you want to submit a report on CC Mode? ")
766 t (message "") nil) 1097 t (message "") nil)
767 (require 'reporter)
768 (reporter-submit-bug-report 1098 (reporter-submit-bug-report
769 c-mode-help-address 1099 c-mode-help-address
770 (concat "CC Mode " c-version " (" 1100 (concat "CC Mode " c-version " (" mode-name ")")
771 (cond ((eq major-mode 'c++-mode) "C++")
772 ((eq major-mode 'c-mode) "C")
773 ((eq major-mode 'objc-mode) "ObjC")
774 ((eq major-mode 'java-mode) "Java")
775 ((eq major-mode 'idl-mode) "IDL")
776 ((eq major-mode 'pike-mode) "Pike")
777 )
778 ")")
779 (let ((vars (append 1101 (let ((vars (append
780 ;; report only the vars that affect indentation
781 c-style-variables 1102 c-style-variables
782 '(c-delete-function 1103 '(c-buffer-is-cc-mode
1104 c-tab-always-indent
1105 c-syntactic-indentation
1106 c-syntactic-indentation-in-macros
1107 c-ignore-auto-fill
1108 c-auto-align-backslashes
1109 c-backspace-function
1110 c-delete-function
783 c-electric-pound-behavior 1111 c-electric-pound-behavior
784 c-indent-comments-syntactically-p 1112 c-default-style
785 c-tab-always-indent 1113 c-enable-xemacs-performance-kludge-p
1114 c-old-style-variable-behavior
786 defun-prompt-regexp 1115 defun-prompt-regexp
787 tab-width 1116 tab-width
788 comment-column 1117 comment-column
789 parse-sexp-ignore-comments 1118 parse-sexp-ignore-comments
1119 parse-sexp-lookup-properties
1120 lookup-syntax-properties
790 ;; A brain-damaged XEmacs only variable that, if 1121 ;; A brain-damaged XEmacs only variable that, if
791 ;; set to nil can cause all kinds of chaos. 1122 ;; set to nil can cause all kinds of chaos.
792 signal-error-on-buffer-boundary 1123 signal-error-on-buffer-boundary
793 ;; Variables that affect line breaking and comments. 1124 ;; Variables that affect line breaking and comments.
1125 auto-fill-mode
794 auto-fill-function 1126 auto-fill-function
795 filladapt-mode 1127 filladapt-mode
796 comment-multi-line 1128 comment-multi-line
797 comment-start-skip 1129 comment-start-skip
798 fill-prefix 1130 fill-prefix
1131 fill-column
799 paragraph-start 1132 paragraph-start
800 adaptive-fill-mode 1133 adaptive-fill-mode
801 adaptive-fill-regexp) 1134 adaptive-fill-regexp)
802 nil))) 1135 nil)))
803 (delq 'c-special-indent-hook vars) 1136 (mapcar (lambda (var) (unless (boundp var)
804 (mapcar (lambda (var) (unless (boundp var) (delq var vars))) 1137 (setq vars (delq var vars))))
805 '(signal-error-on-buffer-boundary 1138 '(signal-error-on-buffer-boundary
806 filladapt-mode 1139 filladapt-mode
807 defun-prompt-regexp)) 1140 defun-prompt-regexp
1141 font-lock-mode
1142 font-lock-maximum-decoration
1143 parse-sexp-lookup-properties
1144 lookup-syntax-properties))
808 vars) 1145 vars)
809 (lambda () 1146 (lambda ()
810 (run-hooks 'c-prepare-bug-report-hooks) 1147 (run-hooks 'c-prepare-bug-report-hooks)
811 (insert (format "Buffer Style: %s\n\nc-emacs-features: %s\n" 1148 (insert (format "Buffer Style: %s\nc-emacs-features: %s\n"
812 style c-features))))))) 1149 style c-features)))))))
813 1150
814 1151
815 (cc-provide 'cc-mode) 1152 (cc-provide 'cc-mode)
816 ;;; cc-mode.el ends here 1153 ;;; cc-mode.el ends here