18720
|
1 ;;; cc-langs.el --- specific language support for CC Mode
|
|
2
|
|
3 ;; Copyright (C) 1985,87,92,93,94,95,96,97 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Authors: 1992-1997 Barry A. Warsaw
|
|
6 ;; 1987 Dave Detlefs and Stewart Clamen
|
|
7 ;; 1985 Richard M. Stallman
|
|
8 ;; Maintainer: cc-mode-help@python.org
|
|
9 ;; Created: 22-Apr-1997 (split from cc-mode.el)
|
|
10 ;; Version: 5.12
|
|
11 ;; Keywords: c languages oop
|
|
12
|
|
13 ;; This file is part of GNU Emacs.
|
|
14
|
|
15 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
16 ;; it under the terms of the GNU General Public License as published by
|
|
17 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
18 ;; any later version.
|
|
19
|
|
20 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
23 ;; GNU General Public License for more details.
|
|
24
|
|
25 ;; You should have received a copy of the GNU General Public License
|
|
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
28 ;; Boston, MA 02111-1307, USA.
|
|
29
|
|
30
|
|
31 ;; Regular expressions and other values which must be parameterized on
|
|
32 ;; a per-language basis.
|
|
33
|
|
34 ;; Keywords defining protection levels
|
|
35 (defconst c-protection-key "\\<\\(public\\|protected\\|private\\)\\>")
|
|
36
|
|
37 ;; Regex describing a `symbol' in all languages We cannot use just
|
|
38 ;; `word' syntax class since `_' cannot be in word class. Putting
|
|
39 ;; underscore in word class breaks forward word movement behavior that
|
|
40 ;; users are familiar with.
|
|
41 (defconst c-symbol-key "\\(\\w\\|\\s_\\)+")
|
|
42
|
|
43
|
|
44 ;; keywords introducing class definitions. language specific
|
|
45 (defconst c-C-class-key "\\(struct\\|union\\)")
|
|
46 (defconst c-C++-class-key "\\(class\\|struct\\|union\\)")
|
|
47
|
|
48 (defconst c-ObjC-class-key
|
|
49 (concat
|
|
50 "@\\(interface\\|implementation\\)\\s +"
|
|
51 c-symbol-key ;name of the class
|
|
52 "\\(\\s *:\\s *" c-symbol-key "\\)?" ;maybe followed by the superclass
|
|
53 "\\(\\s *<[^>]+>\\)?" ;and maybe the adopted protocols list
|
|
54 ))
|
|
55
|
|
56 (defconst c-Java-class-key
|
|
57 (concat
|
|
58 "\\(" c-protection-key "\\s +\\)?"
|
|
59 "\\(interface\\|class\\)\\s +"
|
|
60 c-symbol-key ;name of the class
|
|
61 "\\(\\s *extends\\s *" c-symbol-key "\\)?" ;maybe followed by superclass
|
|
62 ;;"\\(\\s *implements *[^{]+{\\)?" ;maybe the adopted protocols list
|
|
63 ))
|
|
64
|
|
65 (defvar c-class-key c-C-class-key)
|
|
66 (make-variable-buffer-local 'c-class-key)
|
|
67
|
|
68
|
|
69 ;; regexp describing access protection clauses. language specific
|
|
70 (defvar c-access-key nil)
|
|
71 (make-variable-buffer-local 'c-access-key)
|
|
72 (defconst c-C++-access-key (concat c-protection-key "[ \t]*:"))
|
|
73 (defconst c-ObjC-access-key (concat "@" c-protection-key))
|
|
74 (defconst c-Java-access-key nil)
|
|
75
|
|
76
|
|
77 ;; keywords introducing conditional blocks
|
|
78 (defconst c-C-conditional-key nil)
|
|
79 (defconst c-C++-conditional-key nil)
|
|
80 (defconst c-Java-conditional-key nil)
|
|
81
|
|
82 (let ((all-kws "for\\|if\\|do\\|else\\|while\\|switch")
|
|
83 (exc-kws "\\|try\\|catch")
|
|
84 (thr-kws "\\|finally\\|synchronized")
|
|
85 (front "\\b\\(")
|
|
86 (back "\\)\\b[^_]"))
|
|
87 (setq c-C-conditional-key (concat front all-kws back)
|
|
88 c-C++-conditional-key (concat front all-kws exc-kws back)
|
|
89 c-Java-conditional-key (concat front all-kws exc-kws thr-kws back)))
|
|
90
|
|
91 (defvar c-conditional-key c-C-conditional-key)
|
|
92 (make-variable-buffer-local 'c-conditional-key)
|
|
93
|
|
94
|
|
95 ;; keywords describing method definition introductions
|
|
96 (defvar c-method-key nil)
|
|
97 (make-variable-buffer-local 'c-method-key)
|
|
98
|
|
99 (defconst c-ObjC-method-key
|
|
100 (concat
|
|
101 "^\\s *[+-]\\s *"
|
|
102 "\\(([^)]*)\\)?" ; return type
|
|
103 ;; \\s- in objc syntax table does not include \n
|
|
104 ;; since it is considered the end of //-comments.
|
|
105 "[ \t\n]*" c-symbol-key))
|
|
106
|
|
107 (defconst c-Java-method-key
|
|
108 (concat
|
|
109 "^\\s *[+-]\\s *"
|
|
110 "\\(([^)]*)\\)?" ; return type
|
|
111 ;; \\s- in java syntax table does not include \n
|
|
112 ;; since it is considered the end of //-comments.
|
|
113 "[ \t\n]*" c-symbol-key))
|
|
114
|
|
115
|
|
116 ;; comment starter definitions for various languages. language specific
|
|
117 (defconst c-C-comment-start-regexp "/[*]")
|
|
118 (defconst c-C++-comment-start-regexp "/[/*]")
|
|
119 ;; We need to match all 3 Java style comments
|
|
120 ;; 1) Traditional C block; 2) javadoc /** ...; 3) C++ style
|
|
121 (defconst c-Java-comment-start-regexp "/\\(/\\|[*][*]?\\)")
|
|
122 (defvar c-comment-start-regexp c-C-comment-start-regexp)
|
|
123 (make-variable-buffer-local 'c-comment-start-regexp)
|
|
124
|
|
125
|
|
126
|
|
127 ;; Regexp describing a switch's case or default label for all languages
|
|
128 (defconst c-switch-label-key "\\(\\(case[( \t]+\\S .*\\)\\|default[ \t]*\\):")
|
|
129 ;; Regexp describing any label.
|
|
130 (defconst c-label-key (concat c-symbol-key ":\\([^:]\\|$\\)"))
|
|
131
|
|
132 ;; Regexp describing class inheritance declarations. TBD: this should
|
|
133 ;; be language specific, and only makes sense for C++
|
|
134 (defconst c-inher-key
|
|
135 (concat "\\(\\<static\\>\\s +\\)?"
|
|
136 c-C++-class-key "[ \t]+" c-symbol-key
|
|
137 "\\([ \t]*:[ \t]*\\)\\s *[^;]"))
|
|
138
|
|
139 ;; Regexp describing C++ base classes in a derived class definition.
|
|
140 ;; TBD: this should be language specific, and only makes sense for C++
|
|
141 (defvar c-baseclass-key
|
|
142 (concat
|
|
143 ":?[ \t]*\\(virtual[ \t]+\\)?\\("
|
|
144 c-protection-key "[ \t]+\\)" c-symbol-key))
|
|
145 (make-variable-buffer-local 'c-baseclass-key)
|
|
146
|
|
147 ;; Regexp describing friend declarations in C++ classes.
|
|
148 (defconst c-C++-friend-key
|
|
149 "friend[ \t]+\\|template[ \t]*<.+>[ \t]*friend[ \t]+")
|
|
150
|
|
151 ;; Regexp describing Java inheritance and throws clauses.
|
|
152 (defconst c-Java-special-key "\\(implements\\|extends\\|throws\\)[^_]")
|
|
153
|
|
154 ;; Regexp describing the beginning of a Java top-level definition.
|
|
155 (defconst c-Java-defun-prompt-regexp
|
|
156 "^[ \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]*\\)+\\)?\\s-*")
|
|
157
|
|
158
|
|
159
|
|
160 ;; internal state variables
|
|
161
|
|
162 ;; Internal state of hungry delete key feature
|
|
163 (defvar c-hungry-delete-key nil)
|
|
164 (make-variable-buffer-local 'c-hungry-delete-key)
|
|
165
|
|
166 ;; Internal state of auto newline feature.
|
|
167 (defvar c-auto-newline nil)
|
|
168 (make-variable-buffer-local 'c-auto-newline)
|
|
169
|
|
170 ;; Internal auto-newline/hungry-delete designation string for mode line.
|
|
171 (defvar c-auto-hungry-string nil)
|
|
172 (make-variable-buffer-local 'c-auto-hungry-string)
|
|
173
|
|
174 ;; Buffer local language-specific comment style flag.
|
|
175 (defvar c-double-slash-is-comments-p nil)
|
|
176 (make-variable-buffer-local 'c-double-slash-is-comments-p)
|
|
177
|
|
178 ;; Non-nil means K&R style argument declarations are valid.
|
|
179 (defvar c-recognize-knr-p t)
|
|
180 (make-variable-buffer-local 'c-recognize-knr-p)
|
|
181
|
|
182
|
|
183
|
|
184 (defun c-use-java-style ()
|
|
185 "Institutes `java' indentation style.
|
|
186 For use with the variable `java-mode-hook'."
|
|
187 (c-set-style "java"))
|
|
188
|
|
189 (defvar c-styles-are-initialized nil)
|
|
190
|
|
191 (defun c-common-init ()
|
|
192 ;; Common initializations for all modes.
|
|
193 (if c-styles-are-initialized
|
|
194 nil
|
|
195 (require 'cc-styles)
|
|
196 (c-initialize-builtin-style)
|
|
197 (if c-style-variables-are-local-p
|
|
198 (c-make-styles-buffer-local))
|
|
199 (setq c-styles-are-initialized t))
|
|
200 ;; these variables should always be buffer local; they do not affect
|
|
201 ;; indentation style.
|
|
202 (make-local-variable 'paragraph-start)
|
|
203 (make-local-variable 'paragraph-separate)
|
|
204 (make-local-variable 'paragraph-ignore-fill-prefix)
|
|
205 (make-local-variable 'require-final-newline)
|
|
206 (make-local-variable 'parse-sexp-ignore-comments)
|
|
207 (make-local-variable 'indent-line-function)
|
|
208 (make-local-variable 'indent-region-function)
|
|
209 (make-local-variable 'comment-start)
|
|
210 (make-local-variable 'comment-end)
|
|
211 (make-local-variable 'comment-column)
|
|
212 (make-local-variable 'comment-start-skip)
|
|
213 (make-local-variable 'comment-multi-line)
|
|
214 (make-local-variable 'outline-regexp)
|
|
215 (make-local-variable 'outline-level)
|
|
216 (make-local-variable 'adaptive-fill-regexp)
|
|
217 (make-local-variable 'imenu-generic-expression) ;set in the mode functions
|
|
218 ;; Emacs 19.30 and beyond only, AFAIK
|
|
219 (if (boundp 'fill-paragraph-function)
|
|
220 (progn
|
|
221 (make-local-variable 'fill-paragraph-function)
|
|
222 (setq fill-paragraph-function 'c-fill-paragraph)))
|
|
223 ;; now set their values
|
|
224 (setq paragraph-start (concat page-delimiter "\\|$")
|
|
225 paragraph-separate paragraph-start
|
|
226 paragraph-ignore-fill-prefix t
|
|
227 require-final-newline t
|
|
228 parse-sexp-ignore-comments t
|
|
229 indent-line-function 'c-indent-line
|
|
230 indent-region-function 'c-indent-region
|
|
231 outline-regexp "[^#\n\^M]"
|
|
232 outline-level 'c-outline-level
|
|
233 comment-column 32
|
|
234 comment-start-skip "/\\*+ *\\|// *"
|
|
235 adaptive-fill-regexp nil)
|
|
236 ;; we have to do something special for c-offsets-alist so that the
|
|
237 ;; buffer local value has its own alist structure.
|
|
238 (setq c-offsets-alist (copy-alist c-offsets-alist))
|
|
239 ;; setup the comment indent variable in a Emacs version portable way
|
|
240 ;; ignore any byte compiler warnings you might get here
|
|
241 (make-local-variable 'comment-indent-function)
|
|
242 (setq comment-indent-function 'c-comment-indent)
|
|
243 ;; add menus to menubar
|
|
244 (easy-menu-add (c-mode-menu mode-name))
|
|
245 ;; put auto-hungry designators onto minor-mode-alist, but only once
|
|
246 (or (assq 'c-auto-hungry-string minor-mode-alist)
|
|
247 (setq minor-mode-alist
|
|
248 (cons '(c-auto-hungry-string c-auto-hungry-string)
|
|
249 minor-mode-alist))))
|
|
250
|
|
251 (defun c-postprocess-file-styles ()
|
|
252 "Function that post processes relevant file local variables.
|
|
253 Currently, this function simply applies any style and offset settings
|
|
254 found in the file's Local Variable list. It first applies any style
|
|
255 setting found in `c-file-style', then it applies any offset settings
|
|
256 it finds in `c-file-offsets'."
|
|
257 ;; apply file styles and offsets
|
|
258 (and c-file-style
|
|
259 (c-set-style c-file-style))
|
|
260 (and c-file-offsets
|
|
261 (mapcar
|
|
262 (function
|
|
263 (lambda (langentry)
|
|
264 (let ((langelem (car langentry))
|
|
265 (offset (cdr langentry)))
|
|
266 (c-set-offset langelem offset)
|
|
267 )))
|
|
268 c-file-offsets)))
|
|
269
|
|
270 (add-hook 'hack-local-variables-hook 'c-postprocess-file-styles)
|
|
271
|
|
272
|
|
273 ;; Common routines
|
|
274 (defsubst c-make-inherited-keymap ()
|
|
275 (let ((map (make-sparse-keymap)))
|
|
276 (cond
|
|
277 ;; XEmacs 19 & 20
|
|
278 ((fboundp 'set-keymap-parents)
|
|
279 (set-keymap-parents map c-mode-base-map))
|
|
280 ;; Emacs 19
|
|
281 ((fboundp 'set-keymap-parent)
|
|
282 (set-keymap-parent map c-mode-base-map))
|
|
283 ;; incompatible
|
|
284 (t (error "CC Mode is incompatible with this version of Emacs")))
|
|
285 map))
|
|
286
|
|
287 (defun c-populate-syntax-table (table)
|
|
288 ;; Populate the syntax TABLE
|
|
289 ;; DO NOT TRY TO SET _ (UNDERSCORE) TO WORD CLASS!
|
|
290 (modify-syntax-entry ?_ "_" table)
|
|
291 (modify-syntax-entry ?\\ "\\" table)
|
|
292 (modify-syntax-entry ?+ "." table)
|
|
293 (modify-syntax-entry ?- "." table)
|
|
294 (modify-syntax-entry ?= "." table)
|
|
295 (modify-syntax-entry ?% "." table)
|
|
296 (modify-syntax-entry ?< "." table)
|
|
297 (modify-syntax-entry ?> "." table)
|
|
298 (modify-syntax-entry ?& "." table)
|
|
299 (modify-syntax-entry ?| "." table)
|
|
300 (modify-syntax-entry ?\' "\"" table))
|
|
301
|
|
302 (defun c-setup-dual-comments (table)
|
|
303 ;; Set up TABLE to handle block and line style comments
|
|
304 (cond
|
|
305 ;; XEmacs 19 & 20
|
|
306 ((memq '8-bit c-emacs-features)
|
|
307 (modify-syntax-entry ?/ ". 1456" table)
|
|
308 (modify-syntax-entry ?* ". 23" table)
|
|
309 (modify-syntax-entry ?\n "> b" table)
|
|
310 ;; Give CR the same syntax as newline, for selective-display
|
|
311 (modify-syntax-entry ?\^m "> b" table))
|
|
312 ;; Emacs 19
|
|
313 ((memq '1-bit c-emacs-features)
|
|
314 (modify-syntax-entry ?/ ". 124b" table)
|
|
315 (modify-syntax-entry ?* ". 23" table)
|
|
316 (modify-syntax-entry ?\n "> b" table)
|
|
317 ;; Give CR the same syntax as newline, for selective-display
|
|
318 (modify-syntax-entry ?\^m "> b" table))
|
|
319 ;; incompatible
|
|
320 (t (error "CC Mode is incompatible with this version of Emacs"))
|
|
321 ))
|
|
322
|
|
323 (defvar c-mode-base-map ()
|
|
324 "Keymap shared by all CC Mode related modes.")
|
|
325
|
|
326 (if c-mode-base-map
|
|
327 nil
|
|
328 ;; TBD: should we even worry about naming this keymap. My vote: no,
|
|
329 ;; because Emacs and XEmacs do it differently.
|
|
330 (setq c-mode-base-map (make-sparse-keymap))
|
|
331 ;; put standard keybindings into MAP
|
|
332 ;; the following mappings correspond more or less directly to BOCM
|
|
333 (define-key c-mode-base-map "{" 'c-electric-brace)
|
|
334 (define-key c-mode-base-map "}" 'c-electric-brace)
|
|
335 (define-key c-mode-base-map ";" 'c-electric-semi&comma)
|
|
336 (define-key c-mode-base-map "#" 'c-electric-pound)
|
|
337 (define-key c-mode-base-map ":" 'c-electric-colon)
|
|
338 ;; Lucid Emacs 19.9 defined these two, the second of which was
|
|
339 ;; commented out...
|
|
340 ;; (define-key c-mode-base-map "\e{" 'c-insert-braces)
|
|
341 ;; Commented out electric square brackets because nobody likes them.
|
|
342 ;; (define-key c-mode-base-map "[" 'c-insert-brackets)
|
|
343 (define-key c-mode-base-map "\C-c\C-m" 'c-mark-function)
|
|
344 (define-key c-mode-base-map "\e\C-q" 'c-indent-exp)
|
|
345 (define-key c-mode-base-map "\ea" 'c-beginning-of-statement)
|
|
346 (define-key c-mode-base-map "\ee" 'c-end-of-statement)
|
|
347 (define-key c-mode-base-map "\C-c\C-n" 'c-forward-conditional)
|
|
348 (define-key c-mode-base-map "\C-c\C-p" 'c-backward-conditional)
|
|
349 (define-key c-mode-base-map "\C-c\C-u" 'c-up-conditional)
|
|
350 (define-key c-mode-base-map "\t" 'c-indent-command)
|
|
351 ;; Caution! Enter here at your own risk. We are trying to support
|
|
352 ;; several behaviors and it gets disgusting. :-(
|
|
353 ;;
|
|
354 ;; In XEmacs 19, Emacs 19, and Emacs 20, we use this to bind
|
|
355 ;; backwards deletion behavior to DEL, which both Delete and
|
|
356 ;; Backspace get translated to. There's no way to separate this
|
|
357 ;; behavior in a clean way, so deal with it! Besides, it's been
|
|
358 ;; this way since the dawn of BOCM.
|
|
359 (if (not (boundp 'delete-key-deletes-forward))
|
|
360 (define-key c-mode-base-map "\177" 'c-electric-backspace)
|
|
361 ;; However, XEmacs 20 actually achieved enlightenment. It is
|
|
362 ;; possible to sanely define both backward and forward deletion
|
|
363 ;; behavior under X separately (TTYs are forever beyond hope, but
|
|
364 ;; who cares? XEmacs 20 does the right thing with these too).
|
|
365 (define-key c-mode-base-map [delete] 'c-electric-delete)
|
|
366 (define-key c-mode-base-map [backspace] 'c-electric-backspace))
|
|
367 ;; these are new keybindings, with no counterpart to BOCM
|
|
368 (define-key c-mode-base-map "," 'c-electric-semi&comma)
|
|
369 (define-key c-mode-base-map "*" 'c-electric-star)
|
|
370 (define-key c-mode-base-map "\C-c\C-q" 'c-indent-defun)
|
|
371 (define-key c-mode-base-map "\C-c\C-\\" 'c-backslash-region)
|
|
372 ;; TBD: where if anywhere, to put c-backward|forward-into-nomenclature
|
|
373 (define-key c-mode-base-map "\C-c\C-a" 'c-toggle-auto-state)
|
|
374 (define-key c-mode-base-map "\C-c\C-b" 'c-submit-bug-report)
|
|
375 (define-key c-mode-base-map "\C-c\C-c" 'comment-region)
|
|
376 (define-key c-mode-base-map "\C-c\C-d" 'c-toggle-hungry-state)
|
|
377 (define-key c-mode-base-map "\C-c\C-e" 'c-macro-expand)
|
|
378 (define-key c-mode-base-map "\C-c\C-o" 'c-set-offset)
|
|
379 (define-key c-mode-base-map "\C-c\C-s" 'c-show-syntactic-information)
|
|
380 (define-key c-mode-base-map "\C-c\C-t" 'c-toggle-auto-hungry-state)
|
|
381 (define-key c-mode-base-map "\C-c." 'c-set-style)
|
|
382 ;; conflicts with OOBR
|
|
383 ;;(define-key c-mode-base-map "\C-c\C-v" 'c-version)
|
|
384 )
|
|
385
|
|
386 ;; menu support for both XEmacs and Emacs. If you don't have easymenu
|
|
387 ;; with your version of Emacs, you are incompatible!
|
|
388 (require 'easymenu)
|
|
389
|
|
390 (defvar c-c-menu nil)
|
|
391 (defvar c-c++-menu nil)
|
|
392 (defvar c-objc-menu nil)
|
|
393 (defvar c-java-menu nil)
|
|
394
|
|
395 (defun c-mode-menu (modestr)
|
|
396 (let ((m
|
|
397 '(["Comment Out Region" comment-region (mark)]
|
|
398 ["Macro Expand Region" c-macro-expand (mark)]
|
|
399 ["Backslashify" c-backslash-region (mark)]
|
|
400 ["Indent Expression" c-indent-exp
|
|
401 (memq (char-after) '(?\( ?\[ ?\{))]
|
|
402 ["Indent Line" c-indent-command t]
|
|
403 ["Fill Comment Paragraph" c-fill-paragraph t]
|
|
404 ["Up Conditional" c-up-conditional t]
|
|
405 ["Backward Conditional" c-backward-conditional t]
|
|
406 ["Forward Conditional" c-forward-conditional t]
|
|
407 ["Backward Statement" c-beginning-of-statement t]
|
|
408 ["Forward Statement" c-end-of-statement t]
|
|
409 )))
|
|
410 (cons modestr m)))
|
|
411
|
|
412
|
|
413
|
|
414 ;; Support for C
|
|
415
|
|
416 (defvar c-mode-abbrev-table nil
|
|
417 "Abbrev table in use in c-mode buffers.")
|
|
418 (define-abbrev-table 'c-mode-abbrev-table ())
|
|
419
|
|
420 (defvar c-mode-map ()
|
|
421 "Keymap used in c-mode buffers.")
|
|
422 (if c-mode-map
|
|
423 nil
|
|
424 (setq c-mode-map (c-make-inherited-keymap))
|
|
425 ;; add bindings which are only useful for C
|
|
426 )
|
|
427
|
|
428 ;;;###autoload
|
|
429 (defvar c-mode-syntax-table nil
|
|
430 "Syntax table used in c-mode buffers.")
|
|
431 (if c-mode-syntax-table
|
|
432 ()
|
|
433 (setq c-mode-syntax-table (make-syntax-table))
|
|
434 (c-populate-syntax-table c-mode-syntax-table)
|
|
435 ;; add extra comment syntax
|
|
436 (modify-syntax-entry ?/ ". 14" c-mode-syntax-table)
|
|
437 (modify-syntax-entry ?* ". 23" c-mode-syntax-table))
|
|
438
|
|
439 (defun c-enable-//-in-c-mode ()
|
|
440 "Enables // as a comment delimiter in `c-mode'.
|
|
441 ANSI C currently does *not* allow this, although many C compilers
|
|
442 support optional C++ style comments. To use, call this function from
|
|
443 your `.emacs' file before you visit any C files. The changes are
|
|
444 global and affect all future `c-mode' buffers."
|
|
445 (c-setup-dual-comments c-mode-syntax-table)
|
|
446 (setq-default c-C-comment-start-regexp c-C++-comment-start-regexp))
|
|
447
|
|
448 (easy-menu-define c-c-menu c-mode-map "C Mode Commands"
|
|
449 (c-mode-menu "C"))
|
|
450
|
|
451
|
|
452 ;; Support for C++
|
|
453
|
|
454 (defvar c++-mode-abbrev-table nil
|
|
455 "Abbrev table in use in c++-mode buffers.")
|
|
456 (define-abbrev-table 'c++-mode-abbrev-table ())
|
|
457
|
|
458 (defvar c++-mode-map ()
|
|
459 "Keymap used in c++-mode buffers.")
|
|
460 (if c++-mode-map
|
|
461 nil
|
|
462 (setq c++-mode-map (c-make-inherited-keymap))
|
|
463 ;; add bindings which are only useful for C++
|
|
464 (define-key c++-mode-map "\C-c:" 'c-scope-operator)
|
|
465 (define-key c++-mode-map "/" 'c-electric-slash)
|
|
466 (define-key c++-mode-map "<" 'c-electric-lt-gt)
|
|
467 (define-key c++-mode-map ">" 'c-electric-lt-gt))
|
|
468
|
|
469 (defvar c++-mode-syntax-table nil
|
|
470 "Syntax table used in c++-mode buffers.")
|
|
471 (if c++-mode-syntax-table
|
|
472 ()
|
|
473 (setq c++-mode-syntax-table (make-syntax-table))
|
|
474 (c-populate-syntax-table c++-mode-syntax-table)
|
|
475 ;; add extra comment syntax
|
|
476 (c-setup-dual-comments c++-mode-syntax-table)
|
|
477 ;; TBD: does it make sense for colon to be symbol class in C++?
|
|
478 ;; I'm not so sure, since c-label-key is busted on lines like:
|
|
479 ;; Foo::bar( i );
|
|
480 ;; maybe c-label-key should be fixed instead of commenting this out,
|
|
481 ;; but it also bothers me that this only seems appropriate for C++
|
|
482 ;; and not C.
|
|
483 ;;(modify-syntax-entry ?: "_" c++-mode-syntax-table)
|
|
484 )
|
|
485
|
|
486 (easy-menu-define c-c++-menu c++-mode-map "C++ Mode Commands"
|
|
487 (c-mode-menu "C++"))
|
|
488
|
|
489
|
|
490 ;; Support for Objective-C
|
|
491
|
|
492 (defvar objc-mode-abbrev-table nil
|
|
493 "Abbrev table in use in objc-mode buffers.")
|
|
494 (define-abbrev-table 'objc-mode-abbrev-table ())
|
|
495
|
|
496 (defvar objc-mode-map ()
|
|
497 "Keymap used in objc-mode buffers.")
|
|
498 (if objc-mode-map
|
|
499 nil
|
|
500 (setq objc-mode-map (c-make-inherited-keymap))
|
|
501 ;; add bindings which are only useful for Objective-C
|
|
502 (define-key objc-mode-map "/" 'c-electric-slash))
|
|
503
|
|
504 (defvar objc-mode-syntax-table nil
|
|
505 "Syntax table used in objc-mode buffers.")
|
|
506 (if objc-mode-syntax-table
|
|
507 ()
|
|
508 (setq objc-mode-syntax-table (make-syntax-table))
|
|
509 (c-populate-syntax-table objc-mode-syntax-table)
|
|
510 ;; add extra comment syntax
|
|
511 (c-setup-dual-comments objc-mode-syntax-table)
|
|
512 ;; everyone gets these
|
|
513 (modify-syntax-entry ?@ "_" objc-mode-syntax-table)
|
|
514 )
|
|
515
|
|
516 (easy-menu-define c-objc-menu objc-mode-map "ObjC Mode Commands"
|
|
517 (c-mode-menu "ObjC"))
|
|
518
|
|
519
|
|
520 ;; Support for Java
|
|
521
|
|
522 (defvar java-mode-abbrev-table nil
|
|
523 "Abbrev table in use in java-mode buffers.")
|
|
524 (define-abbrev-table 'java-mode-abbrev-table ())
|
|
525
|
|
526 (defvar java-mode-map ()
|
|
527 "Keymap used in java-mode buffers.")
|
|
528 (if java-mode-map
|
|
529 nil
|
|
530 (setq java-mode-map (c-make-inherited-keymap))
|
|
531 ;; add bindings which are only useful for Java
|
|
532 (define-key java-mode-map "/" 'c-electric-slash))
|
|
533
|
|
534 (defvar java-mode-syntax-table nil
|
|
535 "Syntax table used in java-mode buffers.")
|
|
536 (if java-mode-syntax-table
|
|
537 ()
|
|
538 (setq java-mode-syntax-table (make-syntax-table))
|
|
539 (c-populate-syntax-table java-mode-syntax-table)
|
|
540 ;; add extra comment syntax
|
|
541 (c-setup-dual-comments java-mode-syntax-table)
|
|
542 ;; everyone gets these
|
|
543 (modify-syntax-entry ?@ "_" java-mode-syntax-table)
|
|
544 )
|
|
545
|
|
546 (easy-menu-define c-java-menu java-mode-map "Java Mode Commands"
|
|
547 (c-mode-menu "Java"))
|
|
548
|
|
549
|
|
550 (provide 'cc-langs)
|
|
551 ;;; cc-langs.el ends here
|