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