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