]> code.delx.au - gnu-emacs/blob - lisp/progmodes/cc-langs.el
(ada-stmt-add-to-ada-menu): Hide the menu if not in
[gnu-emacs] / lisp / progmodes / cc-langs.el
1 ;;; cc-langs.el --- specific language support for CC Mode
2
3 ;; Copyright (C) 1985,1987,1992-2000 Free Software Foundation, Inc.
4
5 ;; Authors: 2000- Martin Stjernholm
6 ;; 1998-1999 Barry A. Warsaw and Martin Stjernholm
7 ;; 1992-1997 Barry A. Warsaw
8 ;; 1987 Dave Detlefs and Stewart Clamen
9 ;; 1985 Richard M. Stallman
10 ;; Maintainer: bug-cc-mode@gnu.org
11 ;; Created: 22-Apr-1997 (split from cc-mode.el)
12 ;; Version: See cc-mode.el
13 ;; Keywords: c languages oop
14
15 ;; This file is part of GNU Emacs.
16
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 2, or (at your option)
20 ;; any later version.
21
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.
26
27 ;; You should have received a copy of the GNU General Public License
28 ;; along with GNU Emacs; see the file COPYING. If not, write to the
29 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
30 ;; Boston, MA 02111-1307, USA.
31
32 (eval-when-compile
33 (let ((load-path
34 (if (and (boundp 'byte-compile-current-file)
35 (stringp byte-compile-current-file))
36 (cons (file-name-directory byte-compile-current-file)
37 load-path)
38 load-path)))
39 (load "cc-defs" nil t)))
40 (require 'cc-styles)
41
42 ;; Pull in some other packages.
43 (eval-when-compile
44 (condition-case nil
45 ;; Not required and only needed during compilation to shut up
46 ;; the compiler.
47 (require 'outline)
48 (error nil)))
49 ;; menu support for both XEmacs and Emacs. If you don't have easymenu
50 ;; with your version of Emacs, you are incompatible!
51 (require 'easymenu)
52
53 \f
54 (defvar c-buffer-is-cc-mode nil
55 "Non-nil for all buffers with a `major-mode' derived from CC Mode.
56 Otherwise, this variable is nil. I.e. this variable is non-nil for
57 `c-mode', `c++-mode', `objc-mode', `java-mode', `idl-mode',
58 `pike-mode', and any other non-CC Mode mode that calls
59 `c-initialize-cc-mode' (e.g. `awk-mode').")
60 (make-variable-buffer-local 'c-buffer-is-cc-mode)
61 (put 'c-buffer-is-cc-mode 'permanent-local t)
62
63 \f
64 ;; Regular expressions and other values which must be parameterized on
65 ;; a per-language basis.
66
67 ;; Keywords defining protection levels
68 (defconst c-protection-key "\\<\\(public\\|protected\\|private\\)\\>")
69
70 ;; Regex describing a `symbol' in all languages. We cannot use just
71 ;; `word' syntax class since `_' cannot be in word class. Putting
72 ;; underscore in word class breaks forward word movement behavior that
73 ;; users are familiar with. Besides, this runs counter to Emacs
74 ;; convention.
75 ;;
76 ;; I suspect this definition isn't correct in light of Java's
77 ;; definition of a symbol as being Unicode. I know so little about
78 ;; I18N (except how to sound cool and say I18N :-) that I'm willing to
79 ;; punt on this for now.
80
81 (defconst c-symbol-key "[_a-zA-Z]\\(\\w\\|\\s_\\)*")
82
83 \f
84 ;; keywords introducing class definitions. language specific
85 (defconst c-C-class-key "\\(struct\\|union\\)")
86 (defconst c-C++-class-key "\\(class\\|struct\\|union\\)")
87 (defconst c-IDL-class-key "\\(interface\\|struct\\|union\\|valuetype\\)")
88 (defconst c-C-extra-toplevel-key "\\(extern\\)")
89 (defconst c-C++-extra-toplevel-key "\\(extern\\|namespace\\)")
90 (defconst c-IDL-extra-toplevel-key "\\(module\\)")
91
92 (defconst c-ObjC-class-key
93 (concat
94 "@\\(interface\\|implementation\\)\\s +"
95 c-symbol-key ;name of the class
96 "\\(\\s *:\\s *" c-symbol-key "\\)?" ;maybe followed by the superclass
97 "\\(\\s *<[^>]+>\\)?" ;and maybe the adopted protocols list
98 ))
99
100 (defconst c-Java-class-key
101 (concat
102 "\\(" c-protection-key "\\s +\\)?"
103 "\\(interface\\|class\\)\\s +"
104 c-symbol-key ;name of the class
105 "\\(\\s *extends\\s *" c-symbol-key "\\)?" ;maybe followed by superclass
106 ;;"\\(\\s *implements *[^{]+{\\)?" ;maybe the adopted protocols list
107 ))
108
109 (defconst c-Pike-class-key "class")
110
111 (defvar c-class-key c-C-class-key)
112 (make-variable-buffer-local 'c-class-key)
113
114 (defvar c-extra-toplevel-key c-C-extra-toplevel-key)
115 (make-variable-buffer-local 'c-extra-toplevel-key)
116
117 ;; Keywords that can introduce bitfields in the languages that supports that.
118 (defconst c-C-bitfield-key "\\(char\\|int\\|long\\|signed\\|unsigned\\)")
119
120 (defvar c-bitfield-key nil)
121 (make-variable-buffer-local 'c-bitfield-key)
122
123 \f
124 ;; regexp describing access protection clauses. language specific
125 (defvar c-access-key nil)
126 (make-variable-buffer-local 'c-access-key)
127 (defconst c-C++-access-key (concat c-protection-key "[ \t]*:"))
128 (defconst c-IDL-access-key nil)
129 (defconst c-ObjC-access-key (concat "@" c-protection-key))
130 (defconst c-Java-access-key nil)
131 (defconst c-Pike-access-key nil)
132
133 \f
134 ;; keywords introducing conditional blocks
135 (defconst c-C-conditional-key nil)
136 (defconst c-C++-conditional-key nil)
137 (defconst c-IDL-conditional-key nil)
138 (defconst c-ObjC-conditional-key nil)
139 (defconst c-Java-conditional-key nil)
140 (defconst c-Pike-conditional-key nil)
141
142 (let ((all-kws "for\\|if\\|do\\|else\\|while\\|switch")
143 (exc-kws "\\|try\\|catch")
144 (thr-kws "\\|finally\\|synchronized")
145 (front "\\b\\(")
146 (back "\\)\\b[^_]"))
147 (setq c-C-conditional-key (concat front all-kws back)
148 c-C++-conditional-key (concat front all-kws exc-kws back)
149 ;; c-IDL-conditional-key is nil.
150 c-ObjC-conditional-key c-C-conditional-key
151 c-Java-conditional-key (concat front all-kws exc-kws thr-kws back)
152 c-Pike-conditional-key (concat front all-kws "\\|foreach" back)))
153
154 (defvar c-conditional-key c-C-conditional-key)
155 (make-variable-buffer-local 'c-conditional-key)
156
157 \f
158 ;; keywords describing method definition introductions
159 (defvar c-method-key nil)
160 (make-variable-buffer-local 'c-method-key)
161
162 (defconst c-ObjC-method-key
163 (concat
164 "^\\s *[+-]\\s *"
165 "\\(([^)]*)\\)?" ; return type
166 ;; \\s- in objc syntax table does not include \n
167 ;; since it is considered the end of //-comments.
168 "[ \t\n]*" c-symbol-key))
169
170
171 \f
172 ;; comment starter definitions for various languages. language specific
173 (defconst c-C++-comment-start-regexp "/[/*]")
174 (defconst c-C-comment-start-regexp c-C++-comment-start-regexp)
175 (defconst c-IDL-comment-start-regexp c-C++-comment-start-regexp)
176 (defconst c-ObjC-comment-start-regexp c-C++-comment-start-regexp)
177 (defconst c-Pike-comment-start-regexp c-C++-comment-start-regexp)
178 ;; We need to match all 3 Java style comments
179 ;; 1) Traditional C block; 2) javadoc /** ...; 3) C++ style
180 (defconst c-Java-comment-start-regexp "/\\(/\\|[*][*]?\\)")
181 (defvar c-comment-start-regexp c-C++-comment-start-regexp)
182 (make-variable-buffer-local 'c-comment-start-regexp)
183
184
185 \f
186 ;; Regexp describing a switch's case or default label for all languages
187 (defconst c-switch-label-key "\\(\\(case[( \t]+\\S .*\\)\\|default[ \t]*\\):")
188 ;; Regexp describing any label.
189 (defconst c-label-key (concat c-symbol-key ":\\([^:]\\|$\\)"))
190
191 ;; Regexp describing class inheritance declarations. TBD: this should
192 ;; be language specific, and only makes sense for C++
193 (defconst c-inher-key
194 (concat "\\(\\<static\\>\\s +\\)?"
195 c-C++-class-key "[ \t]+" c-symbol-key
196 "\\([ \t]*:[ \t]*\\)\\s *[^;]"))
197
198 ;; Regexp describing C++ base classes in a derived class definition.
199 ;; TBD: this should be language specific, and only makes sense for C++
200 (defvar c-baseclass-key
201 (concat
202 ":?[ \t]*\\(virtual[ \t]+\\)?\\("
203 c-protection-key "[ \t]+\\)" c-symbol-key))
204 (make-variable-buffer-local 'c-baseclass-key)
205
206 ;; Regexp describing friend declarations in C++ classes.
207 (defconst c-C++-friend-key
208 "friend[ \t]+\\|template[ \t]*<.+>[ \t]*friend[ \t]+")
209
210 ;; Regexp describing Java inheritance and throws clauses.
211 (defconst c-Java-special-key "\\(implements\\|extends\\|throws\\)[^_]")
212
213 ;; Regexp describing the beginning of a Java top-level definition.
214 (defconst c-Java-defun-prompt-regexp
215 "^[ \t]*\\(\\(\\(public\\|protected\\|private\\|const\\|abstract\\|synchronized\\|final\\|static\\|threadsafe\\|transient\\|native\\|volatile\\)\\s-+\\)*\\(\\(\\([[a-zA-Z][][_$.a-zA-Z0-9]*[][_$.a-zA-Z0-9]+\\|[[a-zA-Z]\\)\\s-*\\)\\s-+\\)\\)?\\(\\([[a-zA-Z][][_$.a-zA-Z0-9]*\\s-+\\)\\s-*\\)?\\([_a-zA-Z][^][ \t:;.,{}()\7f=]*\\|\\([_$a-zA-Z][_$.a-zA-Z0-9]*\\)\\)\\s-*\\(([^);{}]*)\\)?\\([] \t]*\\)\\(\\s-*\\<throws\\>\\s-*\\(\\([_$a-zA-Z][_$.a-zA-Z0-9]*\\)[, \t\n\r\f]*\\)+\\)?\\s-*")
216
217 ;; Regexp describing regexp to append to paragraph-start
218 (defvar c-append-paragraph-start "$")
219 (make-variable-buffer-local 'c-append-paragraph-start)
220 (defconst c-Java-javadoc-paragraph-start
221 (concat "\\("
222 "@\\(author\\|deprecated\\|exception\\|param\\|return\\|"
223 "s\\(e\\(e\\|rial\\(\\|Data\\|Field\\)\\)\\|ince\\)\\|"
224 "throws\\|version\\)"
225 "\\|$\\)"))
226
227 ;; Regexp that starts lambda constructs.
228 (defvar c-lambda-key nil)
229 (make-variable-buffer-local 'c-lambda-key)
230 (defconst c-Pike-lambda-key "\\<lambda\\>")
231
232 ;; Regexp that are followed by a statement block in expressions.
233 (defvar c-inexpr-block-key nil)
234 (make-variable-buffer-local 'c-inexpr-block-key)
235 (defconst c-Pike-inexpr-block-key "\\<\\(catch\\|gauge\\)\\>")
236
237 ;; Regexp that may be followed by an anonymous class in expressions.
238 (defvar c-inexpr-class-key nil)
239 (make-variable-buffer-local 'c-inexpr-class-key)
240 (defconst c-Java-inexpr-class-key "\\<new\\>")
241 (defconst c-Pike-inexpr-class-key "\\<class\\>")
242
243 ;; List of open- and close-chars that makes up a pike-style brace
244 ;; list, ie for a `([ ])' list there should be a cons (?\[ . ?\]) in
245 ;; this list.
246 (defvar c-special-brace-lists nil)
247 (make-variable-buffer-local 'c-special-brace-lists)
248 (defconst c-Pike-special-brace-lists '((?{ . ?})
249 (?\[ . ?\])
250 (?< . ?>)))
251
252
253 \f
254 ;; internal state variables
255
256 ;; Internal state of hungry delete key feature
257 (defvar c-hungry-delete-key nil)
258 (make-variable-buffer-local 'c-hungry-delete-key)
259
260 ;; Internal state of auto newline feature.
261 (defvar c-auto-newline nil)
262 (make-variable-buffer-local 'c-auto-newline)
263
264 ;; Internal auto-newline/hungry-delete designation string for mode line.
265 (defvar c-auto-hungry-string nil)
266 (make-variable-buffer-local 'c-auto-hungry-string)
267
268 ;; Non-nil means K&R style argument declarations are valid.
269 (defvar c-recognize-knr-p t)
270 (make-variable-buffer-local 'c-recognize-knr-p)
271
272
273 \f
274 (defun c-common-init ()
275 ;; Common initializations for all modes.
276 ;; these variables should always be buffer local; they do not affect
277 ;; indentation style.
278 (make-local-variable 'require-final-newline)
279 (make-local-variable 'parse-sexp-ignore-comments)
280 (make-local-variable 'indent-line-function)
281 (make-local-variable 'indent-region-function)
282 (make-local-variable 'outline-regexp)
283 (make-local-variable 'outline-level)
284 (make-local-variable 'normal-auto-fill-function)
285 (make-local-variable 'comment-start)
286 (make-local-variable 'comment-end)
287 (make-local-variable 'comment-column)
288 (make-local-variable 'comment-start-skip)
289 (make-local-variable 'comment-multi-line)
290 (make-local-variable 'paragraph-start)
291 (make-local-variable 'paragraph-separate)
292 (make-local-variable 'paragraph-ignore-fill-prefix)
293 (make-local-variable 'adaptive-fill-mode)
294 (make-local-variable 'adaptive-fill-regexp)
295 (make-local-variable 'imenu-generic-expression) ;set in the mode functions
296 ;; X/Emacs 20 only
297 (and (boundp 'comment-line-break-function)
298 (progn
299 (make-local-variable 'comment-line-break-function)
300 (setq comment-line-break-function
301 'c-indent-new-comment-line)))
302 ;; now set their values
303 (setq require-final-newline t
304 parse-sexp-ignore-comments t
305 indent-line-function 'c-indent-line
306 indent-region-function 'c-indent-region
307 outline-regexp "[^#\n\^M]"
308 outline-level 'c-outline-level
309 normal-auto-fill-function 'c-do-auto-fill
310 comment-column 32
311 comment-start-skip "/\\*+ *\\|//+ *"
312 comment-multi-line t)
313 ;; now set the mode style based on c-default-style
314 (let ((style (if (stringp c-default-style)
315 (if (c-major-mode-is 'java-mode)
316 "java"
317 c-default-style)
318 (or (cdr (assq major-mode c-default-style))
319 (cdr (assq 'other c-default-style))
320 "gnu"))))
321 ;; Override style variables if `c-old-style-variable-behavior' is
322 ;; set. Also override if we are using global style variables,
323 ;; have already initialized a style once, and are switching to a
324 ;; different style. (It's doubtful whether this is desirable, but
325 ;; the whole situation with nonlocal style variables is a bit
326 ;; awkward. It's at least the most compatible way with the old
327 ;; style init procedure.)
328 (c-set-style style (not (or c-old-style-variable-behavior
329 (and (not c-style-variables-are-local-p)
330 c-indentation-style
331 (not (string-equal c-indentation-style
332 style)))))))
333 ;; Fix things up for paragraph recognition and filling inside
334 ;; comments by using c-comment-prefix-regexp in the relevant places.
335 ;; We use adaptive filling for this to make it possible to use
336 ;; filladapt or some other fancy package.
337 (let ((comment-line-prefix
338 (concat "[ \t]*\\(" c-comment-prefix-regexp "\\)?[ \t]*")))
339 (setq paragraph-start (concat comment-line-prefix
340 c-append-paragraph-start
341 "\\|"
342 page-delimiter)
343 paragraph-separate (concat comment-line-prefix "$"
344 "\\|"
345 page-delimiter)
346 paragraph-ignore-fill-prefix t
347 adaptive-fill-mode t
348 adaptive-fill-regexp
349 (concat comment-line-prefix
350 (if adaptive-fill-regexp
351 (concat "\\(" adaptive-fill-regexp "\\)")
352 "")))
353 (when (boundp 'adaptive-fill-first-line-regexp)
354 ;; XEmacs (20.x) adaptive fill mode doesn't have this.
355 (make-local-variable 'adaptive-fill-first-line-regexp)
356 (setq adaptive-fill-first-line-regexp
357 (concat "\\`" comment-line-prefix
358 ;; Maybe we should incorporate the old value here,
359 ;; but then we have to do all sorts of kludges to
360 ;; deal with the \` and \' it probably contains.
361 "\\'"))))
362 ;; we have to do something special for c-offsets-alist so that the
363 ;; buffer local value has its own alist structure.
364 (setq c-offsets-alist (copy-alist c-offsets-alist))
365 ;; setup the comment indent variable in a Emacs version portable way
366 ;; ignore any byte compiler warnings you might get here
367 (make-local-variable 'comment-indent-function)
368 (setq comment-indent-function 'c-comment-indent)
369 ;; add menus to menubar
370 (easy-menu-add (c-mode-menu mode-name))
371 ;; put auto-hungry designators onto minor-mode-alist, but only once
372 (or (assq 'c-auto-hungry-string minor-mode-alist)
373 (setq minor-mode-alist
374 (cons '(c-auto-hungry-string c-auto-hungry-string)
375 minor-mode-alist)))
376 )
377
378
379 (defun c-postprocess-file-styles ()
380 "Function that post processes relevant file local variables.
381 Currently, this function simply applies any style and offset settings
382 found in the file's Local Variable list. It first applies any style
383 setting found in `c-file-style', then it applies any offset settings
384 it finds in `c-file-offsets'.
385
386 Note that the style variables are always made local to the buffer."
387 ;; apply file styles and offsets
388 (if (or c-file-style c-file-offsets)
389 (c-make-styles-buffer-local t))
390 (and c-file-style
391 (c-set-style c-file-style))
392 (and c-file-offsets
393 (mapcar
394 (function
395 (lambda (langentry)
396 (let ((langelem (car langentry))
397 (offset (cdr langentry)))
398 (c-set-offset langelem offset)
399 )))
400 c-file-offsets)))
401
402 (add-hook 'hack-local-variables-hook 'c-postprocess-file-styles)
403
404 \f
405 (defvar c-mode-base-map ()
406 "Keymap shared by all CC Mode related modes.")
407
408 ;; Common routines
409 (defun c-make-inherited-keymap ()
410 (let ((map (make-sparse-keymap)))
411 (cond
412 ;; XEmacs 19 & 20
413 ((fboundp 'set-keymap-parents)
414 (set-keymap-parents map c-mode-base-map))
415 ;; Emacs 19
416 ((fboundp 'set-keymap-parent)
417 (set-keymap-parent map c-mode-base-map))
418 ;; incompatible
419 (t (error "CC Mode is incompatible with this version of Emacs")))
420 map))
421
422 (defun c-populate-syntax-table (table)
423 ;; Populate the syntax TABLE
424 ;; DO NOT TRY TO SET _ (UNDERSCORE) TO WORD CLASS!
425 (modify-syntax-entry ?_ "_" table)
426 (modify-syntax-entry ?\\ "\\" table)
427 (modify-syntax-entry ?+ "." table)
428 (modify-syntax-entry ?- "." table)
429 (modify-syntax-entry ?= "." table)
430 (modify-syntax-entry ?% "." table)
431 (modify-syntax-entry ?< "." table)
432 (modify-syntax-entry ?> "." table)
433 (modify-syntax-entry ?& "." table)
434 (modify-syntax-entry ?| "." table)
435 (modify-syntax-entry ?\' "\"" table)
436 ;; Set up block and line oriented comments. The new C standard
437 ;; mandates both comment styles even in C, so since all languages
438 ;; now require dual comments, we make this the default.
439 (cond
440 ;; XEmacs 19 & 20
441 ((memq '8-bit c-emacs-features)
442 (modify-syntax-entry ?/ ". 1456" table)
443 (modify-syntax-entry ?* ". 23" table))
444 ;; Emacs 19 & 20
445 ((memq '1-bit c-emacs-features)
446 (modify-syntax-entry ?/ ". 124b" table)
447 (modify-syntax-entry ?* ". 23" table))
448 ;; incompatible
449 (t (error "CC Mode is incompatible with this version of Emacs"))
450 )
451 (modify-syntax-entry ?\n "> b" table)
452 ;; Give CR the same syntax as newline, for selective-display
453 (modify-syntax-entry ?\^m "> b" table))
454
455
456 (if c-mode-base-map
457 nil
458 ;; TBD: should we even worry about naming this keymap. My vote: no,
459 ;; because Emacs and XEmacs do it differently.
460 (setq c-mode-base-map (make-sparse-keymap))
461 ;; put standard keybindings into MAP
462 ;; the following mappings correspond more or less directly to BOCM
463 (define-key c-mode-base-map "{" 'c-electric-brace)
464 (define-key c-mode-base-map "}" 'c-electric-brace)
465 (define-key c-mode-base-map ";" 'c-electric-semi&comma)
466 (define-key c-mode-base-map "#" 'c-electric-pound)
467 (define-key c-mode-base-map ":" 'c-electric-colon)
468 (define-key c-mode-base-map "(" 'c-electric-paren)
469 (define-key c-mode-base-map ")" 'c-electric-paren)
470 ;; Separate M-BS from C-M-h. The former should remain
471 ;; backward-kill-word.
472 (define-key c-mode-base-map [(control meta h)] 'c-mark-function)
473 (define-key c-mode-base-map "\e\C-q" 'c-indent-exp)
474 (substitute-key-definition 'backward-sentence
475 'c-beginning-of-statement
476 c-mode-base-map global-map)
477 (substitute-key-definition 'forward-sentence
478 'c-end-of-statement
479 c-mode-base-map global-map)
480 (substitute-key-definition 'indent-new-comment-line
481 'c-indent-new-comment-line
482 c-mode-base-map global-map)
483 ;; RMS says don't make these the default.
484 ;; (define-key c-mode-base-map "\e\C-a" 'c-beginning-of-defun)
485 ;; (define-key c-mode-base-map "\e\C-e" 'c-end-of-defun)
486 (define-key c-mode-base-map "\C-c\C-n" 'c-forward-conditional)
487 (define-key c-mode-base-map "\C-c\C-p" 'c-backward-conditional)
488 (define-key c-mode-base-map "\C-c\C-u" 'c-up-conditional)
489 (substitute-key-definition 'indent-for-tab-command
490 'c-indent-command
491 c-mode-base-map global-map)
492 ;; It doesn't suffice to put c-fill-paragraph on
493 ;; fill-paragraph-function due to the way it works.
494 (substitute-key-definition 'fill-paragraph 'c-fill-paragraph
495 c-mode-base-map global-map)
496 ;; In XEmacs the default fill function is called
497 ;; fill-paragraph-or-region.
498 (substitute-key-definition 'fill-paragraph-or-region 'c-fill-paragraph
499 c-mode-base-map global-map)
500 ;; Caution! Enter here at your own risk. We are trying to support
501 ;; several behaviors and it gets disgusting. :-(
502 ;;
503 (if (boundp 'delete-key-deletes-forward)
504 (progn
505 ;; In XEmacs 20 it is possible to sanely define both backward
506 ;; and forward deletion behavior under X separately (TTYs are
507 ;; forever beyond hope, but who cares? XEmacs 20 does the
508 ;; right thing with these too).
509 (define-key c-mode-base-map [delete] 'c-electric-delete)
510 (define-key c-mode-base-map [backspace] 'c-electric-backspace))
511 ;; In XEmacs 19, Emacs 19, and Emacs 20, we use this to bind
512 ;; backwards deletion behavior to DEL, which both Delete and
513 ;; Backspace get translated to. There's no way to separate this
514 ;; behavior in a clean way, so deal with it! Besides, it's been
515 ;; this way since the dawn of BOCM.
516 (define-key c-mode-base-map "\177" 'c-electric-backspace))
517 ;; these are new keybindings, with no counterpart to BOCM
518 (define-key c-mode-base-map "," 'c-electric-semi&comma)
519 (define-key c-mode-base-map "*" 'c-electric-star)
520 (define-key c-mode-base-map "/" 'c-electric-slash)
521 (define-key c-mode-base-map "\C-c\C-q" 'c-indent-defun)
522 (define-key c-mode-base-map "\C-c\C-\\" 'c-backslash-region)
523 ;; TBD: where if anywhere, to put c-backward|forward-into-nomenclature
524 (define-key c-mode-base-map "\C-c\C-a" 'c-toggle-auto-state)
525 (define-key c-mode-base-map "\C-c\C-b" 'c-submit-bug-report)
526 (define-key c-mode-base-map "\C-c\C-c" 'comment-region)
527 (define-key c-mode-base-map "\C-c\C-d" 'c-toggle-hungry-state)
528 (define-key c-mode-base-map "\C-c\C-o" 'c-set-offset)
529 (define-key c-mode-base-map "\C-c\C-s" 'c-show-syntactic-information)
530 (define-key c-mode-base-map "\C-c\C-t" 'c-toggle-auto-hungry-state)
531 (define-key c-mode-base-map "\C-c." 'c-set-style)
532 ;; conflicts with OOBR
533 ;;(define-key c-mode-base-map "\C-c\C-v" 'c-version)
534 )
535
536 (defvar c-c-menu nil)
537 (defvar c-c++-menu nil)
538 (defvar c-objc-menu nil)
539 (defvar c-java-menu nil)
540 (defvar c-pike-menu nil)
541
542 (defun c-mode-menu (modestr)
543 (let ((m
544 '(["Comment Out Region" comment-region (c-region-is-active-p)]
545 ["Uncomment Region"
546 (comment-region (region-beginning) (region-end) '(4))
547 (c-region-is-active-p)]
548 ["Fill Comment Paragraph" c-fill-paragraph t]
549 "---"
550 ["Indent Expression" c-indent-exp
551 (memq (char-after) '(?\( ?\[ ?\{))]
552 ["Indent Line or Region" c-indent-line-or-region t]
553 ["Up Conditional" c-up-conditional t]
554 ["Backward Conditional" c-backward-conditional t]
555 ["Forward Conditional" c-forward-conditional t]
556 ["Backward Statement" c-beginning-of-statement t]
557 ["Forward Statement" c-end-of-statement t]
558 "---"
559 ["Macro Expand Region" c-macro-expand (c-region-is-active-p)]
560 ["Backslashify" c-backslash-region (c-region-is-active-p)]
561 )))
562 (cons modestr m)))
563
564
565 \f
566 ;; Support for C
567
568 (defvar c-mode-abbrev-table nil
569 "Abbreviation table used in c-mode buffers.")
570 (define-abbrev-table 'c-mode-abbrev-table ())
571
572 (defvar c-mode-map ()
573 "Keymap used in c-mode buffers.")
574 (if c-mode-map
575 nil
576 (setq c-mode-map (c-make-inherited-keymap))
577 ;; add bindings which are only useful for C
578 (define-key c-mode-map "\C-c\C-e" 'c-macro-expand)
579 )
580
581 ;;;###autoload
582 (defvar c-mode-syntax-table nil
583 "Syntax table used in c-mode buffers.")
584 (if c-mode-syntax-table
585 ()
586 (setq c-mode-syntax-table (make-syntax-table))
587 (c-populate-syntax-table c-mode-syntax-table))
588
589 (easy-menu-define c-c-menu c-mode-map "C Mode Commands"
590 (c-mode-menu "C"))
591
592 \f
593 ;; Support for C++
594
595 (defvar c++-mode-abbrev-table nil
596 "Abbreviation table used in c++-mode buffers.")
597 (define-abbrev-table 'c++-mode-abbrev-table ())
598
599 (defvar c++-mode-map ()
600 "Keymap used in c++-mode buffers.")
601 (if c++-mode-map
602 nil
603 (setq c++-mode-map (c-make-inherited-keymap))
604 ;; add bindings which are only useful for C++
605 (define-key c++-mode-map "\C-c\C-e" 'c-macro-expand)
606 (define-key c++-mode-map "\C-c:" 'c-scope-operator)
607 (define-key c++-mode-map "<" 'c-electric-lt-gt)
608 (define-key c++-mode-map ">" 'c-electric-lt-gt))
609
610 ;;;###autoload
611 (defvar c++-mode-syntax-table nil
612 "Syntax table used in c++-mode buffers.")
613 (if c++-mode-syntax-table
614 ()
615 (setq c++-mode-syntax-table (make-syntax-table))
616 (c-populate-syntax-table c++-mode-syntax-table)
617 ;; TBD: does it make sense for colon to be symbol class in C++?
618 ;; I'm not so sure, since c-label-key is busted on lines like:
619 ;; Foo::bar( i );
620 ;; maybe c-label-key should be fixed instead of commenting this out,
621 ;; but it also bothers me that this only seems appropriate for C++
622 ;; and not C.
623 ;;(modify-syntax-entry ?: "_" c++-mode-syntax-table)
624 )
625
626 (defvar c++-template-syntax-table nil
627 "A variant of `c++-mode-syntax-table' that defines `<' and `>' as
628 parenthesis characters. Used temporarily when template argument lists
629 are parsed.")
630 (if c++-template-syntax-table
631 ()
632 (setq c++-template-syntax-table
633 (copy-syntax-table c++-mode-syntax-table))
634 (modify-syntax-entry ?< "(>" c++-template-syntax-table)
635 (modify-syntax-entry ?> ")<" c++-template-syntax-table))
636
637 (easy-menu-define c-c++-menu c++-mode-map "C++ Mode Commands"
638 (c-mode-menu "C++"))
639
640 \f
641 ;; Support for Objective-C
642
643 (defvar objc-mode-abbrev-table nil
644 "Abbreviation table used in objc-mode buffers.")
645 (define-abbrev-table 'objc-mode-abbrev-table ())
646
647 (defvar objc-mode-map ()
648 "Keymap used in objc-mode buffers.")
649 (if objc-mode-map
650 nil
651 (setq objc-mode-map (c-make-inherited-keymap))
652 ;; add bindings which are only useful for Objective-C
653 (define-key objc-mode-map "\C-c\C-e" 'c-macro-expand))
654
655 ;;;###autoload
656 (defvar objc-mode-syntax-table nil
657 "Syntax table used in objc-mode buffers.")
658 (if objc-mode-syntax-table
659 ()
660 (setq objc-mode-syntax-table (make-syntax-table))
661 (c-populate-syntax-table objc-mode-syntax-table)
662 ;; add extra Objective-C only syntax
663 (modify-syntax-entry ?@ "_" objc-mode-syntax-table))
664
665 (easy-menu-define c-objc-menu objc-mode-map "ObjC Mode Commands"
666 (c-mode-menu "ObjC"))
667
668 \f
669 ;; Support for Java
670
671 (defvar java-mode-abbrev-table nil
672 "Abbreviation table used in java-mode buffers.")
673 (define-abbrev-table 'java-mode-abbrev-table ())
674
675 (defvar java-mode-map ()
676 "Keymap used in java-mode buffers.")
677 (if java-mode-map
678 nil
679 (setq java-mode-map (c-make-inherited-keymap))
680 ;; add bindings which are only useful for Java
681 )
682
683 ;;;###autoload
684 (defvar java-mode-syntax-table nil
685 "Syntax table used in java-mode buffers.")
686 (if java-mode-syntax-table
687 ()
688 (setq java-mode-syntax-table (make-syntax-table))
689 (c-populate-syntax-table java-mode-syntax-table))
690
691 (easy-menu-define c-java-menu java-mode-map "Java Mode Commands"
692 (c-mode-menu "Java"))
693
694 \f
695 ;; Support for CORBA's IDL language
696
697 (defvar idl-mode-abbrev-table nil
698 "Abbreviation table used in idl-mode buffers.")
699 (define-abbrev-table 'idl-mode-abbrev-table ())
700
701 (defvar idl-mode-map ()
702 "Keymap used in idl-mode buffers.")
703 (if idl-mode-map
704 nil
705 (setq idl-mode-map (c-make-inherited-keymap))
706 ;; add bindings which are only useful for IDL
707 )
708
709 ;;;###autoload
710 (defvar idl-mode-syntax-table nil
711 "Syntax table used in idl-mode buffers.")
712 (if idl-mode-syntax-table
713 nil
714 (setq idl-mode-syntax-table (make-syntax-table))
715 (c-populate-syntax-table idl-mode-syntax-table))
716
717 (easy-menu-define c-idl-menu idl-mode-map "IDL Mode Commands"
718 (c-mode-menu "IDL"))
719
720 \f
721 ;; Support for Pike
722
723 (defvar pike-mode-abbrev-table nil
724 "Abbreviation table used in pike-mode buffers.")
725 (define-abbrev-table 'pike-mode-abbrev-table ())
726
727 (defvar pike-mode-map ()
728 "Keymap used in pike-mode buffers.")
729 (if pike-mode-map
730 nil
731 (setq pike-mode-map (c-make-inherited-keymap))
732 ;; additional bindings
733 (define-key pike-mode-map "\C-c\C-e" 'c-macro-expand))
734
735 ;;;###autoload
736 (defvar pike-mode-syntax-table nil
737 "Syntax table used in pike-mode buffers.")
738 (if pike-mode-syntax-table
739 ()
740 (setq pike-mode-syntax-table (make-syntax-table))
741 (c-populate-syntax-table pike-mode-syntax-table)
742 (modify-syntax-entry ?@ "." pike-mode-syntax-table))
743
744 (easy-menu-define c-pike-menu pike-mode-map "Pike Mode Commands"
745 (c-mode-menu "Pike"))
746
747
748 \f
749 (provide 'cc-langs)
750 ;;; cc-langs.el ends here