Mercurial > emacs
comparison lisp/progmodes/cc-langs.el @ 24282:5b0864259a4b Release_5_25
Installed CC Mode 5.25.
author | Barry A. Warsaw <barry@zope.org> |
---|---|
date | Mon, 08 Feb 1999 16:53:18 +0000 |
parents | 76aa8f3934bf |
children | 03befb219d03 |
comparison
equal
deleted
inserted
replaced
24281:d03b1e915af1 | 24282:5b0864259a4b |
---|---|
1 ;;; cc-langs.el --- specific language support for CC Mode | 1 ;;; cc-langs.el --- specific language support for CC Mode |
2 | 2 |
3 ;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Authors: 1992-1997 Barry A. Warsaw | 5 ;; Authors: 1998 Barry A. Warsaw and Martin Stjernholm |
6 ;; 1992-1997 Barry A. Warsaw | |
6 ;; 1987 Dave Detlefs and Stewart Clamen | 7 ;; 1987 Dave Detlefs and Stewart Clamen |
7 ;; 1985 Richard M. Stallman | 8 ;; 1985 Richard M. Stallman |
8 ;; Maintainer: cc-mode-help@python.org | 9 ;; Maintainer: bug-cc-mode@gnu.org |
9 ;; Created: 22-Apr-1997 (split from cc-mode.el) | 10 ;; Created: 22-Apr-1997 (split from cc-mode.el) |
10 ;; Version: See cc-mode.el | 11 ;; Version: See cc-mode.el |
11 ;; Keywords: c languages oop | 12 ;; Keywords: c languages oop |
12 | 13 |
13 ;; This file is part of GNU Emacs. | 14 ;; This file is part of GNU Emacs. |
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 28 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
28 ;; Boston, MA 02111-1307, USA. | 29 ;; Boston, MA 02111-1307, USA. |
29 | 30 |
30 | 31 |
31 | 32 |
32 (require 'cc-defs) | 33 (eval-when-compile |
34 (require 'cc-defs)) | |
33 | 35 |
34 ;; Regular expressions and other values which must be parameterized on | 36 ;; Regular expressions and other values which must be parameterized on |
35 ;; a per-language basis. | 37 ;; a per-language basis. |
36 | 38 |
37 ;; Keywords defining protection levels | 39 ;; Keywords defining protection levels |
52 | 54 |
53 | 55 |
54 ;; keywords introducing class definitions. language specific | 56 ;; keywords introducing class definitions. language specific |
55 (defconst c-C-class-key "\\(struct\\|union\\)") | 57 (defconst c-C-class-key "\\(struct\\|union\\)") |
56 (defconst c-C++-class-key "\\(class\\|struct\\|union\\)") | 58 (defconst c-C++-class-key "\\(class\\|struct\\|union\\)") |
57 (defconst c-C-extra-toplevel-key "\\(extern\\)[^_]") | 59 (defconst c-IDL-class-key "\\(class\\|struct\\|union\\|interface\\)") |
58 (defconst c-C++-extra-toplevel-key "\\(extern\\|namespace\\)[^_]") | 60 (defconst c-C-extra-toplevel-key "\\(extern\\)") |
61 (defconst c-C++-extra-toplevel-key "\\(extern\\|namespace\\)") | |
62 (defconst c-IDL-extra-toplevel-key "\\(module\\)") | |
59 | 63 |
60 (defconst c-ObjC-class-key | 64 (defconst c-ObjC-class-key |
61 (concat | 65 (concat |
62 "@\\(interface\\|implementation\\)\\s +" | 66 "@\\(interface\\|implementation\\)\\s +" |
63 c-symbol-key ;name of the class | 67 c-symbol-key ;name of the class |
68 (defconst c-Java-class-key | 72 (defconst c-Java-class-key |
69 (concat | 73 (concat |
70 "\\(" c-protection-key "\\s +\\)?" | 74 "\\(" c-protection-key "\\s +\\)?" |
71 "\\(interface\\|class\\)\\s +" | 75 "\\(interface\\|class\\)\\s +" |
72 c-symbol-key ;name of the class | 76 c-symbol-key ;name of the class |
73 "\\(\\s *extends\\s *" c-symbol-key "\\)?" ;maybe followed by superclass | 77 "\\(\\s *extends\\s *" c-symbol-key "\\)?" ;maybe followed by superclass |
74 ;;"\\(\\s *implements *[^{]+{\\)?" ;maybe the adopted protocols list | 78 ;;"\\(\\s *implements *[^{]+{\\)?" ;maybe the adopted protocols list |
75 )) | 79 )) |
80 | |
81 (defconst c-Pike-class-key "class") | |
76 | 82 |
77 (defvar c-class-key c-C-class-key) | 83 (defvar c-class-key c-C-class-key) |
78 (make-variable-buffer-local 'c-class-key) | 84 (make-variable-buffer-local 'c-class-key) |
79 | 85 |
80 (defvar c-extra-toplevel-key c-C-extra-toplevel-key) | 86 (defvar c-extra-toplevel-key c-C-extra-toplevel-key) |
85 (defvar c-access-key nil) | 91 (defvar c-access-key nil) |
86 (make-variable-buffer-local 'c-access-key) | 92 (make-variable-buffer-local 'c-access-key) |
87 (defconst c-C++-access-key (concat c-protection-key "[ \t]*:")) | 93 (defconst c-C++-access-key (concat c-protection-key "[ \t]*:")) |
88 (defconst c-ObjC-access-key (concat "@" c-protection-key)) | 94 (defconst c-ObjC-access-key (concat "@" c-protection-key)) |
89 (defconst c-Java-access-key nil) | 95 (defconst c-Java-access-key nil) |
96 (defconst c-Pike-access-key nil) | |
90 | 97 |
91 | 98 |
92 ;; keywords introducing conditional blocks | 99 ;; keywords introducing conditional blocks |
93 (defconst c-C-conditional-key nil) | 100 (defconst c-C-conditional-key nil) |
94 (defconst c-C++-conditional-key nil) | 101 (defconst c-C++-conditional-key nil) |
95 (defconst c-Java-conditional-key nil) | 102 (defconst c-Java-conditional-key nil) |
103 (defconst c-Pike-conditional-key nil) | |
96 | 104 |
97 (let ((all-kws "for\\|if\\|do\\|else\\|while\\|switch") | 105 (let ((all-kws "for\\|if\\|do\\|else\\|while\\|switch") |
98 (exc-kws "\\|try\\|catch") | 106 (exc-kws "\\|try\\|catch") |
99 (thr-kws "\\|finally\\|synchronized") | 107 (thr-kws "\\|finally\\|synchronized") |
100 (front "\\b\\(") | 108 (front "\\b\\(") |
101 (back "\\)\\b[^_]")) | 109 (back "\\)\\b[^_]")) |
102 (setq c-C-conditional-key (concat front all-kws back) | 110 (setq c-C-conditional-key (concat front all-kws back) |
103 c-C++-conditional-key (concat front all-kws exc-kws back) | 111 c-C++-conditional-key (concat front all-kws exc-kws back) |
104 c-Java-conditional-key (concat front all-kws exc-kws thr-kws back))) | 112 c-Java-conditional-key (concat front all-kws exc-kws thr-kws back) |
113 c-Pike-conditional-key (concat front all-kws "\\|foreach" back))) | |
105 | 114 |
106 (defvar c-conditional-key c-C-conditional-key) | 115 (defvar c-conditional-key c-C-conditional-key) |
107 (make-variable-buffer-local 'c-conditional-key) | 116 (make-variable-buffer-local 'c-conditional-key) |
108 | 117 |
109 | 118 |
164 | 173 |
165 ;; Regexp describing Javadoc markup that always starts paragraphs. | 174 ;; Regexp describing Javadoc markup that always starts paragraphs. |
166 (defconst c-Java-javadoc-paragraph-start | 175 (defconst c-Java-javadoc-paragraph-start |
167 "@\\(author\\|exception\\|param\\|return\\|see\\|version\\)") | 176 "@\\(author\\|exception\\|param\\|return\\|see\\|version\\)") |
168 | 177 |
178 ;; Regexp that starts lambda constructs. | |
179 (defvar c-lambda-key nil) | |
180 (make-variable-buffer-local 'c-lambda-key) | |
181 (defconst c-Pike-lambda-key "\\<lambda\\>") | |
182 | |
183 ;; Regexp that are followed by a statement block in expressions. | |
184 (defvar c-inexpr-block-key nil) | |
185 (make-variable-buffer-local 'c-inexpr-block-key) | |
186 (defconst c-Pike-inexpr-block-key "\\<\\(catch\\|gauge\\)\\>") | |
187 | |
188 ;; Regexp that may be followed by an anonymous class in expressions. | |
189 (defvar c-inexpr-class-key nil) | |
190 (make-variable-buffer-local 'c-inexpr-class-key) | |
191 (defconst c-Java-inexpr-class-key "\\<new\\>") | |
192 | |
193 ;; List of open- and close-chars that makes up a pike-style brace | |
194 ;; list, ie for a `([ ])' list there should be a cons (?\[ . ?\]) in | |
195 ;; this list. | |
196 (defvar c-special-brace-lists nil) | |
197 (make-variable-buffer-local 'c-special-brace-lists) | |
198 (defconst c-Pike-special-brace-lists '((?{ . ?}) | |
199 (?\[ . ?\]) | |
200 (?< . ?>))) | |
201 | |
169 | 202 |
170 | 203 |
171 ;; internal state variables | 204 ;; internal state variables |
172 | 205 |
173 ;; Internal state of hungry delete key feature | 206 ;; Internal state of hungry delete key feature |
186 (defvar c-recognize-knr-p t) | 219 (defvar c-recognize-knr-p t) |
187 (make-variable-buffer-local 'c-recognize-knr-p) | 220 (make-variable-buffer-local 'c-recognize-knr-p) |
188 | 221 |
189 | 222 |
190 | 223 |
191 (defun c-use-java-style () | |
192 "Institutes `java' indentation style. | |
193 For use with the variable `java-mode-hook'." | |
194 (c-set-style "java")) | |
195 | |
196 (defun c-common-init () | 224 (defun c-common-init () |
197 ;; Common initializations for all modes. | 225 ;; Common initializations for all modes. |
198 ;; these variables should always be buffer local; they do not affect | 226 ;; these variables should always be buffer local; they do not affect |
199 ;; indentation style. | 227 ;; indentation style. |
200 (make-local-variable 'paragraph-start) | 228 (make-local-variable 'paragraph-start) |
210 (make-local-variable 'comment-start-skip) | 238 (make-local-variable 'comment-start-skip) |
211 (make-local-variable 'comment-multi-line) | 239 (make-local-variable 'comment-multi-line) |
212 (make-local-variable 'outline-regexp) | 240 (make-local-variable 'outline-regexp) |
213 (make-local-variable 'outline-level) | 241 (make-local-variable 'outline-level) |
214 (make-local-variable 'adaptive-fill-regexp) | 242 (make-local-variable 'adaptive-fill-regexp) |
243 (make-local-variable 'adaptive-fill-mode) | |
215 (make-local-variable 'imenu-generic-expression) ;set in the mode functions | 244 (make-local-variable 'imenu-generic-expression) ;set in the mode functions |
216 ;; X/Emacs 20 only | 245 ;; X/Emacs 20 only |
217 (and (boundp 'comment-line-break-function) | 246 (and (boundp 'comment-line-break-function) |
218 (make-local-variable 'comment-line-break-function)) | 247 (make-local-variable 'comment-line-break-function)) |
219 ;; Emacs 19.30 and beyond only, AFAIK | 248 ;; Emacs 19.30 and beyond only, AFAIK |
233 outline-level 'c-outline-level | 262 outline-level 'c-outline-level |
234 comment-column 32 | 263 comment-column 32 |
235 comment-start-skip "/\\*+ *\\|// *" | 264 comment-start-skip "/\\*+ *\\|// *" |
236 comment-multi-line nil | 265 comment-multi-line nil |
237 comment-line-break-function 'c-comment-line-break-function | 266 comment-line-break-function 'c-comment-line-break-function |
238 adaptive-fill-regexp nil) | 267 adaptive-fill-regexp nil |
268 adaptive-fill-mode nil) | |
239 ;; we have to do something special for c-offsets-alist so that the | 269 ;; we have to do something special for c-offsets-alist so that the |
240 ;; buffer local value has its own alist structure. | 270 ;; buffer local value has its own alist structure. |
241 (setq c-offsets-alist (copy-alist c-offsets-alist)) | 271 (setq c-offsets-alist (copy-alist c-offsets-alist)) |
242 ;; setup the comment indent variable in a Emacs version portable way | 272 ;; setup the comment indent variable in a Emacs version portable way |
243 ;; ignore any byte compiler warnings you might get here | 273 ;; ignore any byte compiler warnings you might get here |
247 (easy-menu-add (c-mode-menu mode-name)) | 277 (easy-menu-add (c-mode-menu mode-name)) |
248 ;; put auto-hungry designators onto minor-mode-alist, but only once | 278 ;; put auto-hungry designators onto minor-mode-alist, but only once |
249 (or (assq 'c-auto-hungry-string minor-mode-alist) | 279 (or (assq 'c-auto-hungry-string minor-mode-alist) |
250 (setq minor-mode-alist | 280 (setq minor-mode-alist |
251 (cons '(c-auto-hungry-string c-auto-hungry-string) | 281 (cons '(c-auto-hungry-string c-auto-hungry-string) |
252 minor-mode-alist)))) | 282 minor-mode-alist))) |
283 ;; now set the mode style based on c-default-style | |
284 (c-set-style (if (stringp c-default-style) | |
285 (if (c-major-mode-is 'java-mode) | |
286 "java" | |
287 c-default-style) | |
288 (or (cdr (assq major-mode c-default-style)) | |
289 (cdr (assq 'other c-default-style)) | |
290 "gnu"))) | |
291 ) | |
292 | |
253 | 293 |
254 (defun c-postprocess-file-styles () | 294 (defun c-postprocess-file-styles () |
255 "Function that post processes relevant file local variables. | 295 "Function that post processes relevant file local variables. |
256 Currently, this function simply applies any style and offset settings | 296 Currently, this function simply applies any style and offset settings |
257 found in the file's Local Variable list. It first applies any style | 297 found in the file's Local Variable list. It first applies any style |
275 c-file-offsets))) | 315 c-file-offsets))) |
276 | 316 |
277 (add-hook 'hack-local-variables-hook 'c-postprocess-file-styles) | 317 (add-hook 'hack-local-variables-hook 'c-postprocess-file-styles) |
278 | 318 |
279 | 319 |
320 (defvar c-mode-base-map () | |
321 "Keymap shared by all CC Mode related modes.") | |
322 | |
280 ;; Common routines | 323 ;; Common routines |
281 (defun c-make-inherited-keymap () | 324 (defun c-make-inherited-keymap () |
282 (let ((map (make-sparse-keymap))) | 325 (let ((map (make-sparse-keymap))) |
283 (cond | 326 (cond |
284 ;; XEmacs 19 & 20 | 327 ;; XEmacs 19 & 20 |
323 (modify-syntax-entry ?\n "> b" table) | 366 (modify-syntax-entry ?\n "> b" table) |
324 ;; Give CR the same syntax as newline, for selective-display | 367 ;; Give CR the same syntax as newline, for selective-display |
325 (modify-syntax-entry ?\^m "> b" table)) | 368 (modify-syntax-entry ?\^m "> b" table)) |
326 | 369 |
327 | 370 |
328 (defvar c-mode-base-map () | |
329 "Keymap shared by all CC Mode related modes.") | |
330 | |
331 (if c-mode-base-map | 371 (if c-mode-base-map |
332 nil | 372 nil |
333 ;; TBD: should we even worry about naming this keymap. My vote: no, | 373 ;; TBD: should we even worry about naming this keymap. My vote: no, |
334 ;; because Emacs and XEmacs do it differently. | 374 ;; because Emacs and XEmacs do it differently. |
335 (setq c-mode-base-map (make-sparse-keymap)) | 375 (setq c-mode-base-map (make-sparse-keymap)) |
338 (define-key c-mode-base-map "{" 'c-electric-brace) | 378 (define-key c-mode-base-map "{" 'c-electric-brace) |
339 (define-key c-mode-base-map "}" 'c-electric-brace) | 379 (define-key c-mode-base-map "}" 'c-electric-brace) |
340 (define-key c-mode-base-map ";" 'c-electric-semi&comma) | 380 (define-key c-mode-base-map ";" 'c-electric-semi&comma) |
341 (define-key c-mode-base-map "#" 'c-electric-pound) | 381 (define-key c-mode-base-map "#" 'c-electric-pound) |
342 (define-key c-mode-base-map ":" 'c-electric-colon) | 382 (define-key c-mode-base-map ":" 'c-electric-colon) |
383 (define-key c-mode-base-map "(" 'c-electric-paren) | |
384 (define-key c-mode-base-map ")" 'c-electric-paren) | |
343 ;; Separate M-BS from C-M-h. The former should remain | 385 ;; Separate M-BS from C-M-h. The former should remain |
344 ;; backward-kill-word. | 386 ;; backward-kill-word. |
345 (define-key c-mode-base-map [(control meta h)] 'c-mark-function) | 387 (define-key c-mode-base-map [(control meta h)] 'c-mark-function) |
346 (define-key c-mode-base-map "\e\C-q" 'c-indent-exp) | 388 (define-key c-mode-base-map "\e\C-q" 'c-indent-exp) |
347 (define-key c-mode-base-map "\ea" 'c-beginning-of-statement) | 389 (define-key c-mode-base-map "\ea" 'c-beginning-of-statement) |
394 | 436 |
395 (defvar c-c-menu nil) | 437 (defvar c-c-menu nil) |
396 (defvar c-c++-menu nil) | 438 (defvar c-c++-menu nil) |
397 (defvar c-objc-menu nil) | 439 (defvar c-objc-menu nil) |
398 (defvar c-java-menu nil) | 440 (defvar c-java-menu nil) |
441 (defvar c-pike-menu nil) | |
399 | 442 |
400 (defun c-mode-menu (modestr) | 443 (defun c-mode-menu (modestr) |
401 (let ((m | 444 (let ((m |
402 '(["Comment Out Region" comment-region (mark t)] | 445 '(["Comment Out Region" comment-region (c-region-is-active-p)] |
403 ["Uncomment Region" | 446 ["Uncomment Region" |
404 (comment-region (region-beginning) (region-end) '(4)) | 447 (comment-region (region-beginning) (region-end) '(4)) |
405 (mark t)] | 448 (c-region-is-active-p)] |
406 ["Fill Comment Paragraph" c-fill-paragraph t] | 449 ["Fill Comment Paragraph" c-fill-paragraph t] |
407 "---" | 450 "---" |
408 ["Indent Expression" c-indent-exp | 451 ["Indent Expression" c-indent-exp |
409 (memq (char-after) '(?\( ?\[ ?\{))] | 452 (memq (char-after) '(?\( ?\[ ?\{))] |
410 ["Indent Line" c-indent-command t] | 453 ["Indent Line or Region" c-indent-line-or-region t] |
411 ["Up Conditional" c-up-conditional t] | 454 ["Up Conditional" c-up-conditional t] |
412 ["Backward Conditional" c-backward-conditional t] | 455 ["Backward Conditional" c-backward-conditional t] |
413 ["Forward Conditional" c-forward-conditional t] | 456 ["Forward Conditional" c-forward-conditional t] |
414 ["Backward Statement" c-beginning-of-statement t] | 457 ["Backward Statement" c-beginning-of-statement t] |
415 ["Forward Statement" c-end-of-statement t] | 458 ["Forward Statement" c-end-of-statement t] |
416 "---" | 459 "---" |
417 ["Macro Expand Region" c-macro-expand (mark t)] | 460 ["Macro Expand Region" c-macro-expand (c-region-is-active-p)] |
418 ["Backslashify" c-backslash-region (mark t)] | 461 ["Backslashify" c-backslash-region (c-region-is-active-p)] |
419 ))) | 462 ))) |
420 (cons modestr m))) | 463 (cons modestr m))) |
421 | 464 |
422 | 465 |
423 | 466 |
562 (c-populate-syntax-table idl-mode-syntax-table)) | 605 (c-populate-syntax-table idl-mode-syntax-table)) |
563 | 606 |
564 (easy-menu-define c-idl-menu idl-mode-map "IDL Mode Commands" | 607 (easy-menu-define c-idl-menu idl-mode-map "IDL Mode Commands" |
565 (c-mode-menu "IDL")) | 608 (c-mode-menu "IDL")) |
566 | 609 |
610 | |
611 ;; Support for Pike | |
612 | |
613 (defvar pike-mode-abbrev-table nil | |
614 "Abbreviation table used in pike-mode buffers.") | |
615 (define-abbrev-table 'pike-mode-abbrev-table ()) | |
616 | |
617 (defvar pike-mode-map () | |
618 "Keymap used in pike-mode buffers.") | |
619 (if pike-mode-map | |
620 nil | |
621 (setq pike-mode-map (c-make-inherited-keymap)) | |
622 ;; additional bindings | |
623 (define-key pike-mode-map "\C-c\C-e" 'c-macro-expand)) | |
624 | |
625 ;;;###autoload | |
626 (defvar pike-mode-syntax-table nil | |
627 "Syntax table used in pike-mode buffers.") | |
628 (if pike-mode-syntax-table | |
629 () | |
630 (setq pike-mode-syntax-table (make-syntax-table)) | |
631 (c-populate-syntax-table pike-mode-syntax-table) | |
632 (modify-syntax-entry ?@ "." pike-mode-syntax-table)) | |
633 | |
634 (easy-menu-define c-pike-menu pike-mode-map "Pike Mode Commands" | |
635 (c-mode-menu "Pike")) | |
636 | |
567 | 637 |
568 | 638 |
569 (provide 'cc-langs) | 639 (provide 'cc-langs) |
570 ;;; cc-langs.el ends here | 640 ;;; cc-langs.el ends here |