Mercurial > emacs
comparison lisp/progmodes/cc-mode.el @ 88155:d7ddb3e565de
sync with trunk
author | Henrik Enberg <henrik.enberg@telia.com> |
---|---|
date | Mon, 16 Jan 2006 00:03:54 +0000 |
parents | b025ca405045 |
children |
comparison
equal
deleted
inserted
replaced
88154:8ce476d3ba36 | 88155:d7ddb3e565de |
---|---|
1 ;;; cc-mode.el --- major mode for editing C, C++, Objective-C, and Java code | 1 ;;; cc-mode.el --- major mode for editing C and similar languages |
2 | 2 |
3 ;; Copyright (C) 1985,1987,1992-2001 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1985,1987,1992-2003, 2004, 2005 Free Software Foundation, |
4 | 4 ;; Inc. |
5 ;; Authors: 2000- Martin Stjernholm | 5 |
6 ;; 1998-1999 Barry A. Warsaw and Martin Stjernholm | 6 ;; Authors: 2003- Alan Mackenzie |
7 ;; 1992-1997 Barry A. Warsaw | 7 ;; 1998- Martin Stjernholm |
8 ;; 1992-1999 Barry A. Warsaw | |
8 ;; 1987 Dave Detlefs and Stewart Clamen | 9 ;; 1987 Dave Detlefs and Stewart Clamen |
9 ;; 1985 Richard M. Stallman | 10 ;; 1985 Richard M. Stallman |
10 ;; Maintainer: bug-cc-mode@gnu.org | 11 ;; Maintainer: bug-cc-mode@gnu.org |
11 ;; Created: a long, long, time ago. adapted from the original c-mode.el | 12 ;; Created: a long, long, time ago. adapted from the original c-mode.el |
12 ;; Keywords: c languages oop | 13 ;; Keywords: c languages oop |
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | 23 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 24 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
24 ;; GNU General Public License for more details. | 25 ;; GNU General Public License for more details. |
25 | 26 |
26 ;; You should have received a copy of the GNU General Public License | 27 ;; You should have received a copy of the GNU General Public License |
27 ;; along with GNU Emacs; see the file COPYING. If not, write to | 28 ;; along with this program; see the file COPYING. If not, write to |
28 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 29 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
29 ;; Boston, MA 02111-1307, USA. | 30 ;; Boston, MA 02110-1301, USA. |
30 | 31 |
31 (defconst c-version "5.29" | 32 ;;; Commentary: |
32 "CC Mode version number.") | |
33 | 33 |
34 ;; NOTE: Read the commentary below for the right way to submit bug reports! | 34 ;; NOTE: Read the commentary below for the right way to submit bug reports! |
35 ;; NOTE: See the accompanying texinfo manual for details on using this mode! | 35 ;; NOTE: See the accompanying texinfo manual for details on using this mode! |
36 | 36 ;; Note: The version string is in cc-defs. |
37 ;;; Commentary: | |
38 | 37 |
39 ;; This package provides GNU Emacs major modes for editing C, C++, | 38 ;; This package provides GNU Emacs major modes for editing C, C++, |
40 ;; Objective-C, Java, IDL and Pike code. As of the latest Emacs and | 39 ;; Objective-C, Java, CORBA's IDL, Pike and AWK code. As of the |
41 ;; XEmacs releases, it is the default package for editing these | 40 ;; latest Emacs and XEmacs releases, it is the default package for |
42 ;; languages. This package is called "CC Mode", and should be spelled | 41 ;; editing these languages. This package is called "CC Mode", and |
43 ;; exactly this way. | 42 ;; should be spelled exactly this way. |
44 | 43 |
45 ;; CC Mode supports K&R and ANSI C, ANSI C++, Objective-C, Java, | 44 ;; CC Mode supports K&R and ANSI C, ANSI C++, Objective-C, Java, |
46 ;; CORBA's IDL, and Pike with a consistent indentation model across | 45 ;; CORBA's IDL, Pike and AWK with a consistent indentation model |
47 ;; all modes. This indentation model is intuitive and very flexible, | 46 ;; across all modes. This indentation model is intuitive and very |
48 ;; so that almost any desired style of indentation can be supported. | 47 ;; flexible, so that almost any desired style of indentation can be |
49 ;; Installation, usage, and programming details are contained in an | 48 ;; supported. Installation, usage, and programming details are |
50 ;; accompanying texinfo manual. | 49 ;; contained in an accompanying texinfo manual. |
51 | 50 |
52 ;; CC Mode's immediate ancestors were, c++-mode.el, cplus-md.el, and | 51 ;; CC Mode's immediate ancestors were, c++-mode.el, cplus-md.el, and |
53 ;; cplus-md1.el.. | 52 ;; cplus-md1.el.. |
54 | |
55 ;; NOTE: This mode does not perform font-locking (a.k.a syntactic | |
56 ;; coloring, keyword highlighting, etc.) for any of the supported | |
57 ;; modes. Typically this is done by a package called font-lock.el | |
58 ;; which we do *not* maintain. You should contact the Emacs or XEmacs | |
59 ;; maintainers for questions about coloring or highlighting in any | |
60 ;; language mode. | |
61 | 53 |
62 ;; To submit bug reports, type "C-c C-b". These will be sent to | 54 ;; To submit bug reports, type "C-c C-b". These will be sent to |
63 ;; bug-gnu-emacs@gnu.org (mirrored as the Usenet newsgroup | 55 ;; bug-gnu-emacs@gnu.org (mirrored as the Usenet newsgroup |
64 ;; gnu.emacs.bug) as well as bug-cc-mode@gnu.org, which directly | 56 ;; gnu.emacs.bug) as well as bug-cc-mode@gnu.org, which directly |
65 ;; contacts the CC Mode maintainers. Questions can sent to | 57 ;; contacts the CC Mode maintainers. Questions can sent to |
87 (let ((load-path | 79 (let ((load-path |
88 (if (and (boundp 'byte-compile-dest-file) | 80 (if (and (boundp 'byte-compile-dest-file) |
89 (stringp byte-compile-dest-file)) | 81 (stringp byte-compile-dest-file)) |
90 (cons (file-name-directory byte-compile-dest-file) load-path) | 82 (cons (file-name-directory byte-compile-dest-file) load-path) |
91 load-path))) | 83 load-path))) |
92 (require 'cc-bytecomp))) | 84 (load "cc-bytecomp" nil t))) |
93 | 85 |
94 (cc-require 'cc-defs) | 86 (cc-require 'cc-defs) |
95 (cc-require 'cc-menus) | 87 (cc-require-when-compile 'cc-langs) |
96 (cc-require 'cc-vars) | 88 (cc-require 'cc-vars) |
97 (cc-require 'cc-langs) | 89 (cc-require 'cc-engine) |
98 (cc-require 'cc-styles) | 90 (cc-require 'cc-styles) |
99 (cc-require 'cc-engine) | |
100 (cc-require 'cc-cmds) | 91 (cc-require 'cc-cmds) |
101 (cc-require 'cc-align) | 92 (cc-require 'cc-align) |
93 (cc-require 'cc-menus) | |
102 | 94 |
103 ;; Silence the compiler. | 95 ;; Silence the compiler. |
104 (cc-bytecomp-defvar comment-line-break-function) ; (X)Emacs 20+ | 96 (cc-bytecomp-defvar adaptive-fill-first-line-regexp) ; Emacs |
105 (cc-bytecomp-defvar adaptive-fill-first-line-regexp) ; Emacs 20+ | |
106 (cc-bytecomp-defun set-keymap-parents) ; XEmacs | 97 (cc-bytecomp-defun set-keymap-parents) ; XEmacs |
98 (cc-bytecomp-defun run-mode-hooks) ; Emacs 21.1 | |
99 (cc-bytecomp-obsolete-fun make-local-hook) ; Marked obsolete in Emacs 21.1. | |
100 | |
101 ;; We set these variables during mode init, yet we don't require | |
102 ;; font-lock. | |
103 (cc-bytecomp-defvar font-lock-defaults) | |
104 (cc-bytecomp-defvar font-lock-syntactic-keywords) | |
107 | 105 |
108 ;; Menu support for both XEmacs and Emacs. If you don't have easymenu | 106 ;; Menu support for both XEmacs and Emacs. If you don't have easymenu |
109 ;; with your version of Emacs, you are incompatible! | 107 ;; with your version of Emacs, you are incompatible! |
110 (require 'easymenu) | 108 (cc-external-require 'easymenu) |
109 | |
110 ;; Autoload directive for emacsen that doesn't have an older CC Mode | |
111 ;; version in the dist. | |
112 (autoload 'c-subword-mode "cc-subword" | |
113 "Mode enabling subword movement and editing keys." t) | |
114 | |
115 ;; Load cc-fonts first after font-lock is loaded, since it isn't | |
116 ;; necessary until font locking is requested. | |
117 (eval-after-load "font-lock" | |
118 '(require 'cc-fonts)) | |
119 | |
120 ;; cc-langs isn't loaded when we're byte compiled, so add autoload | |
121 ;; directives for the interface functions. | |
122 (autoload 'c-make-init-lang-vars-fun "cc-langs") | |
123 (autoload 'c-init-language-vars "cc-langs" nil nil 'macro) | |
111 | 124 |
112 | 125 |
113 ;; Other modes and packages which depend on CC Mode should do the | 126 ;; Other modes and packages which depend on CC Mode should do the |
114 ;; following to make sure everything is loaded and available for their | 127 ;; following to make sure everything is loaded and available for their |
115 ;; use: | 128 ;; use: |
116 ;; | 129 ;; |
117 ;; (require 'cc-mode) | 130 ;; (require 'cc-mode) |
118 ;; | 131 ;; |
119 ;; And in the major mode function: | 132 ;; And in the major mode function: |
120 ;; | 133 ;; |
121 ;; (c-initialize-cc-mode) | 134 ;; (c-initialize-cc-mode t) |
135 ;; (c-init-language-vars some-mode) | |
136 ;; (c-common-init 'some-mode) ; Or perhaps (c-basic-common-init 'some-mode) | |
137 ;; | |
138 ;; If you're not writing a derived mode using the language variable | |
139 ;; system, then some-mode is one of the language modes directly | |
140 ;; supported by CC Mode. You can then use (c-init-language-vars-for | |
141 ;; 'some-mode) instead of `c-init-language-vars'. | |
142 ;; `c-init-language-vars-for' is a function that avoids the rather | |
143 ;; large expansion of `c-init-language-vars'. | |
144 ;; | |
145 ;; If you use `c-basic-common-init' then you might want to call | |
146 ;; `c-font-lock-init' too to set up CC Mode's font lock support. | |
147 ;; | |
148 ;; See cc-langs.el for further info. A small example of a derived mode | |
149 ;; is also available at <http://cc-mode.sourceforge.net/ | |
150 ;; derived-mode-ex.el>. | |
122 | 151 |
123 (defun c-leave-cc-mode-mode () | 152 (defun c-leave-cc-mode-mode () |
124 (setq c-buffer-is-cc-mode nil)) | 153 (setq c-buffer-is-cc-mode nil)) |
125 | 154 |
155 (defun c-init-language-vars-for (mode) | |
156 "Initialize the language variables for one of the language modes | |
157 directly supported by CC Mode. This can be used instead of the | |
158 `c-init-language-vars' macro if the language you want to use is one of | |
159 those, rather than a derived language defined through the language | |
160 variable system (see \"cc-langs.el\")." | |
161 (cond ((eq mode 'c-mode) (c-init-language-vars c-mode)) | |
162 ((eq mode 'c++-mode) (c-init-language-vars c++-mode)) | |
163 ((eq mode 'objc-mode) (c-init-language-vars objc-mode)) | |
164 ((eq mode 'java-mode) (c-init-language-vars java-mode)) | |
165 ((eq mode 'idl-mode) (c-init-language-vars idl-mode)) | |
166 ((eq mode 'pike-mode) (c-init-language-vars pike-mode)) | |
167 ((eq mode 'awk-mode) (c-init-language-vars awk-mode)) | |
168 (t (error "Unsupported mode %s" mode)))) | |
169 | |
126 ;;;###autoload | 170 ;;;###autoload |
127 (defun c-initialize-cc-mode () | 171 (defun c-initialize-cc-mode (&optional new-style-init) |
172 "Initialize CC Mode for use in the current buffer. | |
173 If the optional NEW-STYLE-INIT is nil or left out then all necessary | |
174 initialization to run CC Mode for the C language is done. Otherwise | |
175 only some basic setup is done, and a call to `c-init-language-vars' or | |
176 `c-init-language-vars-for' is necessary too (which gives more | |
177 control). See \"cc-mode.el\" for more info." | |
178 | |
128 (setq c-buffer-is-cc-mode t) | 179 (setq c-buffer-is-cc-mode t) |
180 | |
129 (let ((initprop 'cc-mode-is-initialized) | 181 (let ((initprop 'cc-mode-is-initialized) |
130 c-initialization-ok) | 182 c-initialization-ok) |
131 (unless (get 'c-initialize-cc-mode initprop) | 183 (unless (get 'c-initialize-cc-mode initprop) |
132 (unwind-protect | 184 (unwind-protect |
133 (progn | 185 (progn |
138 (if (boundp 'c-comment-continuation-stars) | 190 (if (boundp 'c-comment-continuation-stars) |
139 (setq c-block-comment-prefix c-comment-continuation-stars)) | 191 (setq c-block-comment-prefix c-comment-continuation-stars)) |
140 (add-hook 'change-major-mode-hook 'c-leave-cc-mode-mode) | 192 (add-hook 'change-major-mode-hook 'c-leave-cc-mode-mode) |
141 (setq c-initialization-ok t)) | 193 (setq c-initialization-ok t)) |
142 ;; Will try initialization hooks again if they failed. | 194 ;; Will try initialization hooks again if they failed. |
143 (put 'c-initialize-cc-mode initprop c-initialization-ok))) | 195 (put 'c-initialize-cc-mode initprop c-initialization-ok)))) |
144 )) | 196 |
197 (unless new-style-init | |
198 (c-init-language-vars-for 'c-mode))) | |
145 | 199 |
146 | 200 |
147 ;; Common routines | 201 ;;; Common routines. |
202 | |
148 (defvar c-mode-base-map () | 203 (defvar c-mode-base-map () |
149 "Keymap shared by all CC Mode related modes.") | 204 "Keymap shared by all CC Mode related modes.") |
150 | 205 |
151 (defun c-make-inherited-keymap () | 206 (defun c-make-inherited-keymap () |
152 (let ((map (make-sparse-keymap))) | 207 (let ((map (make-sparse-keymap))) |
208 ;; Necessary to use `cc-bytecomp-fboundp' below since this | |
209 ;; function is called from top-level forms that are evaluated | |
210 ;; while cc-bytecomp is active when one does M-x eval-buffer. | |
153 (cond | 211 (cond |
154 ;; XEmacs 19 & 20 | 212 ;; XEmacs |
155 ((fboundp 'set-keymap-parents) | 213 ((cc-bytecomp-fboundp 'set-keymap-parents) |
156 (set-keymap-parents map c-mode-base-map)) | 214 (set-keymap-parents map c-mode-base-map)) |
157 ;; Emacs 19 | 215 ;; Emacs |
158 ((fboundp 'set-keymap-parent) | 216 ((cc-bytecomp-fboundp 'set-keymap-parent) |
159 (set-keymap-parent map c-mode-base-map)) | 217 (set-keymap-parent map c-mode-base-map)) |
160 ;; incompatible | 218 ;; incompatible |
161 (t (error "CC Mode is incompatible with this version of Emacs"))) | 219 (t (error "CC Mode is incompatible with this version of Emacs"))) |
162 map)) | 220 map)) |
163 | 221 |
164 (defun c-define-abbrev-table (name defs) | 222 (defun c-define-abbrev-table (name defs) |
165 ;; Compatibility wrapper for `define-abbrev' which passes a non-nil | 223 ;; Compatibility wrapper for `define-abbrev' which passes a non-nil |
166 ;; sixth argument for SYSTEM-FLAG in emacsen that support it | 224 ;; sixth argument for SYSTEM-FLAG in emacsen that support it |
167 ;; (currently only Emacs 21.2). | 225 ;; (currently only Emacs >= 21.2). |
168 (define-abbrev-table name nil) | 226 (let ((table (or (symbol-value name) |
169 (let ((table (symbol-value name))) | 227 (progn (define-abbrev-table name nil) |
228 (symbol-value name))))) | |
170 (while defs | 229 (while defs |
171 (condition-case nil | 230 (condition-case nil |
172 (apply 'define-abbrev table (append (car defs) '(t))) | 231 (apply 'define-abbrev table (append (car defs) '(t))) |
173 (wrong-number-of-arguments | 232 (wrong-number-of-arguments |
174 (apply 'define-abbrev table (car defs)))) | 233 (apply 'define-abbrev table (car defs)))) |
175 (setq defs (cdr defs))))) | 234 (setq defs (cdr defs))))) |
235 (put 'c-define-abbrev-table 'lisp-indent-function 1) | |
236 | |
237 (defun c-bind-special-erase-keys () | |
238 ;; Only used in Emacs to bind C-c C-<delete> and C-c C-<backspace> | |
239 ;; to the proper keys depending on `normal-erase-is-backspace'. | |
240 (if normal-erase-is-backspace | |
241 (progn | |
242 (define-key c-mode-base-map (kbd "C-c C-<delete>") | |
243 'c-hungry-delete-forward) | |
244 (define-key c-mode-base-map (kbd "C-c C-<backspace>") | |
245 'c-hungry-backspace)) | |
246 (define-key c-mode-base-map (kbd "C-c C-<delete>") | |
247 'c-hungry-backspace) | |
248 (define-key c-mode-base-map (kbd "C-c C-<backspace>") | |
249 'c-hungry-delete-forward))) | |
176 | 250 |
177 (if c-mode-base-map | 251 (if c-mode-base-map |
178 nil | 252 nil |
179 ;; TBD: should we even worry about naming this keymap. My vote: no, | 253 |
180 ;; because Emacs and XEmacs do it differently. | |
181 (setq c-mode-base-map (make-sparse-keymap)) | 254 (setq c-mode-base-map (make-sparse-keymap)) |
182 ;; put standard keybindings into MAP | 255 |
183 ;; the following mappings correspond more or less directly to BOCM | |
184 (define-key c-mode-base-map "{" 'c-electric-brace) | |
185 (define-key c-mode-base-map "}" 'c-electric-brace) | |
186 (define-key c-mode-base-map ";" 'c-electric-semi&comma) | |
187 (define-key c-mode-base-map "#" 'c-electric-pound) | |
188 (define-key c-mode-base-map ":" 'c-electric-colon) | |
189 (define-key c-mode-base-map "(" 'c-electric-paren) | |
190 (define-key c-mode-base-map ")" 'c-electric-paren) | |
191 ;; Separate M-BS from C-M-h. The former should remain | 256 ;; Separate M-BS from C-M-h. The former should remain |
192 ;; backward-kill-word. | 257 ;; backward-kill-word. |
193 (define-key c-mode-base-map [(control meta h)] 'c-mark-function) | 258 (define-key c-mode-base-map [(control meta h)] 'c-mark-function) |
194 (define-key c-mode-base-map "\e\C-q" 'c-indent-exp) | 259 (define-key c-mode-base-map "\e\C-q" 'c-indent-exp) |
195 (substitute-key-definition 'backward-sentence | 260 (substitute-key-definition 'backward-sentence |
199 'c-end-of-statement | 264 'c-end-of-statement |
200 c-mode-base-map global-map) | 265 c-mode-base-map global-map) |
201 (substitute-key-definition 'indent-new-comment-line | 266 (substitute-key-definition 'indent-new-comment-line |
202 'c-indent-new-comment-line | 267 'c-indent-new-comment-line |
203 c-mode-base-map global-map) | 268 c-mode-base-map global-map) |
269 (substitute-key-definition 'indent-for-tab-command | |
270 'c-indent-command | |
271 c-mode-base-map global-map) | |
204 (when (fboundp 'comment-indent-new-line) | 272 (when (fboundp 'comment-indent-new-line) |
205 ;; indent-new-comment-line has changed name to | 273 ;; indent-new-comment-line has changed name to |
206 ;; comment-indent-new-line in Emacs 21. | 274 ;; comment-indent-new-line in Emacs 21. |
207 (substitute-key-definition 'comment-indent-new-line | 275 (substitute-key-definition 'comment-indent-new-line |
208 'c-indent-new-comment-line | 276 'c-indent-new-comment-line |
209 c-mode-base-map global-map)) | 277 c-mode-base-map global-map)) |
278 | |
210 ;; RMS says don't make these the default. | 279 ;; RMS says don't make these the default. |
211 ;; (define-key c-mode-base-map "\e\C-a" 'c-beginning-of-defun) | 280 ;; (define-key c-mode-base-map "\e\C-a" 'c-beginning-of-defun) |
212 ;; (define-key c-mode-base-map "\e\C-e" 'c-end-of-defun) | 281 ;; (define-key c-mode-base-map "\e\C-e" 'c-end-of-defun) |
282 | |
213 (define-key c-mode-base-map "\C-c\C-n" 'c-forward-conditional) | 283 (define-key c-mode-base-map "\C-c\C-n" 'c-forward-conditional) |
214 (define-key c-mode-base-map "\C-c\C-p" 'c-backward-conditional) | 284 (define-key c-mode-base-map "\C-c\C-p" 'c-backward-conditional) |
215 (define-key c-mode-base-map "\C-c\C-u" 'c-up-conditional) | 285 (define-key c-mode-base-map "\C-c\C-u" 'c-up-conditional) |
216 (substitute-key-definition 'indent-for-tab-command | 286 |
217 'c-indent-command | 287 ;; It doesn't suffice to put `c-fill-paragraph' on |
218 c-mode-base-map global-map) | 288 ;; `fill-paragraph-function' since `c-fill-paragraph' must be called |
219 ;; It doesn't suffice to put c-fill-paragraph on | 289 ;; before any fill prefix adaption is done. E.g. `filladapt-mode' |
220 ;; fill-paragraph-function due to the way it works. | 290 ;; replaces `fill-paragraph' and does the adaption before calling |
291 ;; `fill-paragraph-function', and we have to mask comments etc | |
292 ;; before that. Also, `c-fill-paragraph' chains on to | |
293 ;; `fill-paragraph' and the value on `fill-parapgraph-function' to | |
294 ;; do the actual filling work. | |
221 (substitute-key-definition 'fill-paragraph 'c-fill-paragraph | 295 (substitute-key-definition 'fill-paragraph 'c-fill-paragraph |
222 c-mode-base-map global-map) | 296 c-mode-base-map global-map) |
223 ;; In XEmacs the default fill function is called | 297 ;; In XEmacs the default fill function is called |
224 ;; fill-paragraph-or-region. | 298 ;; fill-paragraph-or-region. |
225 (substitute-key-definition 'fill-paragraph-or-region 'c-fill-paragraph | 299 (substitute-key-definition 'fill-paragraph-or-region 'c-fill-paragraph |
226 c-mode-base-map global-map) | 300 c-mode-base-map global-map) |
301 | |
302 ;; We bind the forward deletion key and (implicitly) C-d to | |
303 ;; `c-electric-delete-forward', and the backward deletion key to | |
304 ;; `c-electric-backspace'. The hungry variants are bound to the | |
305 ;; same keys but prefixed with C-c. This implies that C-c C-d is | |
306 ;; `c-hungry-delete-forward'. For consistency, we bind not only C-c | |
307 ;; <backspace> to `c-hungry-backspace' but also C-c C-<backspace>, | |
308 ;; so that the Ctrl key can be held down during the whole sequence | |
309 ;; regardless of the direction. This in turn implies that we bind | |
310 ;; C-c C-<delete> to `c-hungry-delete-forward', for the same reason. | |
311 | |
227 ;; Bind the electric deletion functions to C-d and DEL. Emacs 21 | 312 ;; Bind the electric deletion functions to C-d and DEL. Emacs 21 |
228 ;; automatically maps the [delete] and [backspace] keys to these two | 313 ;; automatically maps the [delete] and [backspace] keys to these two |
229 ;; depending on window system and user preferences. (In earlier | 314 ;; depending on window system and user preferences. (In earlier |
230 ;; versions it's possible to do the same by using `function-key-map'.) | 315 ;; versions it's possible to do the same by using `function-key-map'.) |
231 (define-key c-mode-base-map "\C-d" 'c-electric-delete-forward) | 316 (define-key c-mode-base-map "\C-d" 'c-electric-delete-forward) |
232 (define-key c-mode-base-map "\177" 'c-electric-backspace) | 317 (define-key c-mode-base-map "\177" 'c-electric-backspace) |
233 (when (boundp 'delete-key-deletes-forward) | 318 (define-key c-mode-base-map "\C-c\C-d" 'c-hungry-delete-forward) |
234 ;; In XEmacs 20 and later we fix the forward and backward deletion | 319 (define-key c-mode-base-map [?\C-c ?\d] 'c-hungry-backspace) |
235 ;; behavior by binding the keysyms for the [delete] and | 320 (define-key c-mode-base-map [?\C-c ?\C-\d] 'c-hungry-backspace) |
236 ;; [backspace] keys directly, and use `delete-forward-p' or | 321 (define-key c-mode-base-map [?\C-c deletechar] 'c-hungry-delete-forward) ; C-c <delete> on a tty. |
237 ;; `delete-key-deletes-forward' to decide what [delete] should do. | 322 (define-key c-mode-base-map [?\C-c (control deletechar)] ; C-c C-<delete> on a tty. |
323 'c-hungry-delete-forward) | |
324 (when (boundp 'normal-erase-is-backspace) | |
325 ;; The automatic C-d and DEL mapping functionality doesn't extend | |
326 ;; to special combinations like C-c C-<delete>, so we have to hook | |
327 ;; into the `normal-erase-is-backspace' system to bind it directly | |
328 ;; as appropriate. | |
329 (add-hook 'normal-erase-is-backspace-hook 'c-bind-special-erase-keys) | |
330 (c-bind-special-erase-keys)) | |
331 | |
332 (when (fboundp 'delete-forward-p) | |
333 ;; In XEmacs we fix the forward and backward deletion behavior by | |
334 ;; binding the keysyms for the [delete] and [backspace] keys | |
335 ;; directly, and use `delete-forward-p' to decide what [delete] | |
336 ;; should do. That's done in the XEmacs specific | |
337 ;; `c-electric-delete' and `c-hungry-delete' functions. | |
238 (define-key c-mode-base-map [delete] 'c-electric-delete) | 338 (define-key c-mode-base-map [delete] 'c-electric-delete) |
239 (define-key c-mode-base-map [backspace] 'c-electric-backspace)) | 339 (define-key c-mode-base-map [backspace] 'c-electric-backspace) |
240 ;; these are new keybindings, with no counterpart to BOCM | 340 (define-key c-mode-base-map (kbd "C-c <delete>") 'c-hungry-delete) |
341 (define-key c-mode-base-map (kbd "C-c C-<delete>") 'c-hungry-delete) | |
342 (define-key c-mode-base-map (kbd "C-c <backspace>") 'c-hungry-backspace) | |
343 (define-key c-mode-base-map (kbd "C-c C-<backspace>") 'c-hungry-backspace)) | |
344 | |
345 (define-key c-mode-base-map "#" 'c-electric-pound) | |
346 (define-key c-mode-base-map "{" 'c-electric-brace) | |
347 (define-key c-mode-base-map "}" 'c-electric-brace) | |
348 (define-key c-mode-base-map "/" 'c-electric-slash) | |
349 (define-key c-mode-base-map "*" 'c-electric-star) | |
350 (define-key c-mode-base-map ";" 'c-electric-semi&comma) | |
241 (define-key c-mode-base-map "," 'c-electric-semi&comma) | 351 (define-key c-mode-base-map "," 'c-electric-semi&comma) |
242 (define-key c-mode-base-map "*" 'c-electric-star) | 352 (define-key c-mode-base-map ":" 'c-electric-colon) |
243 (define-key c-mode-base-map "/" 'c-electric-slash) | 353 (define-key c-mode-base-map "(" 'c-electric-paren) |
244 (define-key c-mode-base-map "\C-c\C-q" 'c-indent-defun) | 354 (define-key c-mode-base-map ")" 'c-electric-paren) |
355 | |
245 (define-key c-mode-base-map "\C-c\C-\\" 'c-backslash-region) | 356 (define-key c-mode-base-map "\C-c\C-\\" 'c-backslash-region) |
246 ;; TBD: where if anywhere, to put c-backward|forward-into-nomenclature | 357 (define-key c-mode-base-map "\C-c\C-a" 'c-toggle-auto-newline) |
247 (define-key c-mode-base-map "\C-c\C-a" 'c-toggle-auto-state) | |
248 (define-key c-mode-base-map "\C-c\C-b" 'c-submit-bug-report) | 358 (define-key c-mode-base-map "\C-c\C-b" 'c-submit-bug-report) |
249 (define-key c-mode-base-map "\C-c\C-c" 'comment-region) | 359 (define-key c-mode-base-map "\C-c\C-c" 'comment-region) |
250 (define-key c-mode-base-map "\C-c\C-d" 'c-toggle-hungry-state) | 360 (define-key c-mode-base-map "\C-c\C-l" 'c-toggle-electric-state) |
251 (define-key c-mode-base-map "\C-c\C-o" 'c-set-offset) | 361 (define-key c-mode-base-map "\C-c\C-o" 'c-set-offset) |
362 (define-key c-mode-base-map "\C-c\C-q" 'c-indent-defun) | |
252 (define-key c-mode-base-map "\C-c\C-s" 'c-show-syntactic-information) | 363 (define-key c-mode-base-map "\C-c\C-s" 'c-show-syntactic-information) |
253 (define-key c-mode-base-map "\C-c\C-t" 'c-toggle-auto-hungry-state) | 364 ;; (define-key c-mode-base-map "\C-c\C-t" 'c-toggle-auto-hungry-state) Commented out by ACM, 2005-03-05. |
254 (define-key c-mode-base-map "\C-c." 'c-set-style) | 365 (define-key c-mode-base-map "\C-c." 'c-set-style) |
255 ;; conflicts with OOBR | 366 ;; conflicts with OOBR |
256 ;;(define-key c-mode-base-map "\C-c\C-v" 'c-version) | 367 ;;(define-key c-mode-base-map "\C-c\C-v" 'c-version) |
368 ;; (define-key c-mode-base-map "\C-c\C-y" 'c-toggle-hungry-state) Commented out by ACM, 2005-11-22. | |
369 (define-key c-mode-base-map "\C-c\C-w" 'c-subword-mode) | |
257 ) | 370 ) |
258 | |
259 (defvar c-c-menu nil) | |
260 (defvar c-c++-menu nil) | |
261 (defvar c-objc-menu nil) | |
262 (defvar c-java-menu nil) | |
263 (defvar c-pike-menu nil) | |
264 | |
265 (defun c-mode-menu (modestr) | |
266 (let ((m | |
267 '(["Comment Out Region" comment-region (c-fn-region-is-active-p)] | |
268 ["Uncomment Region" | |
269 (comment-region (region-beginning) (region-end) '(4)) | |
270 (c-fn-region-is-active-p)] | |
271 ["Fill Comment Paragraph" c-fill-paragraph t] | |
272 "----" | |
273 ["Indent Expression" c-indent-exp | |
274 (memq (char-after) '(?\( ?\[ ?\{))] | |
275 ["Indent Line or Region" c-indent-line-or-region t] | |
276 ["Up Conditional" c-up-conditional t] | |
277 ["Backward Conditional" c-backward-conditional t] | |
278 ["Forward Conditional" c-forward-conditional t] | |
279 ["Backward Statement" c-beginning-of-statement t] | |
280 ["Forward Statement" c-end-of-statement t] | |
281 "----" | |
282 ["Macro Expand Region" c-macro-expand (c-fn-region-is-active-p)] | |
283 ["Backslashify" c-backslash-region | |
284 (c-fn-region-is-active-p)] | |
285 "----" | |
286 ("Toggle..." | |
287 ["Syntactic indentation" c-toggle-syntactic-indentation t] | |
288 ["Auto newline" c-toggle-auto-state t] | |
289 ["Hungry delete" c-toggle-hungry-state t]) | |
290 ))) | |
291 (cons modestr m))) | |
292 | 371 |
293 ;; We don't require the outline package, but we configure it a bit anyway. | 372 ;; We don't require the outline package, but we configure it a bit anyway. |
294 (cc-bytecomp-defvar outline-level) | 373 (cc-bytecomp-defvar outline-level) |
295 | 374 |
296 (defun c-common-init (mode) | 375 (defun c-mode-menu (modestr) |
297 ;; Common initializations for all modes. | 376 "Return a menu spec suitable for `easy-menu-define' that is exactly |
377 like the C mode menu except that the menu bar item name is MODESTR | |
378 instead of \"C\". | |
379 | |
380 This function is provided for compatibility only; derived modes should | |
381 preferably use the `c-mode-menu' language constant directly." | |
382 (cons modestr (c-lang-const c-mode-menu c))) | |
383 | |
384 ;; Ugly hack to pull in the definition of `c-populate-syntax-table' | |
385 ;; from cc-langs to make it available at runtime. It's either this or | |
386 ;; moving the definition for it to cc-defs, but that would mean to | |
387 ;; break up the syntax table setup over two files. | |
388 (defalias 'c-populate-syntax-table | |
389 (cc-eval-when-compile | |
390 (let ((f (symbol-function 'c-populate-syntax-table))) | |
391 (if (byte-code-function-p f) f (byte-compile f))))) | |
392 | |
393 ;; CAUTION: Try to avoid installing things on | |
394 ;; `before-change-functions'. The macro `combine-after-change-calls' | |
395 ;; is used and it doesn't work if there are things on that hook. That | |
396 ;; can cause font lock functions to run in inconvenient places during | |
397 ;; temporary changes in some font lock support modes, causing extra | |
398 ;; unnecessary work and font lock glitches due to interactions between | |
399 ;; various text properties. | |
400 | |
401 (defun c-after-change (beg end len) | |
402 ;; Function put on `after-change-functions' to adjust various caches | |
403 ;; etc. Prefer speed to finesse here, since there will be an order | |
404 ;; of magnitude more calls to this function than any of the | |
405 ;; functions that use the caches. | |
406 ;; | |
407 ;; Note that care must be taken so that this is called before any | |
408 ;; font-lock callbacks since we might get calls to functions using | |
409 ;; these caches from inside them, and we must thus be sure that this | |
410 ;; has already been executed. | |
411 | |
412 (c-save-buffer-state () | |
413 ;; When `combine-after-change-calls' is used we might get calls | |
414 ;; with regions outside the current narrowing. This has been | |
415 ;; observed in Emacs 20.7. | |
416 (save-restriction | |
417 (widen) | |
418 | |
419 (when (> end (point-max)) | |
420 ;; Some emacsen might return positions past the end. This has been | |
421 ;; observed in Emacs 20.7 when rereading a buffer changed on disk | |
422 ;; (haven't been able to minimize it, but Emacs 21.3 appears to | |
423 ;; work). | |
424 (setq end (point-max)) | |
425 (when (> beg end) | |
426 (setq beg end))) | |
427 | |
428 (c-invalidate-sws-region-after beg end) | |
429 (c-invalidate-state-cache beg) | |
430 (c-invalidate-find-decl-cache beg) | |
431 | |
432 (when c-recognize-<>-arglists | |
433 (c-after-change-check-<>-operators beg end))))) | |
434 | |
435 (defun c-basic-common-init (mode default-style) | |
436 "Do the necessary initialization for the syntax handling routines | |
437 and the line breaking/filling code. Intended to be used by other | |
438 packages that embed CC Mode. | |
439 | |
440 MODE is the CC Mode flavor to set up, e.g. 'c-mode or 'java-mode. | |
441 DEFAULT-STYLE tells which indentation style to install. It has the | |
442 same format as `c-default-style'. | |
443 | |
444 Note that `c-init-language-vars' must be called before this function. | |
445 This function cannot do that since `c-init-language-vars' is a macro | |
446 that requires a literal mode spec at compile time." | |
447 | |
298 (setq c-buffer-is-cc-mode mode) | 448 (setq c-buffer-is-cc-mode mode) |
299 | 449 |
300 ;; these variables should always be buffer local; they do not affect | 450 ;; these variables should always be buffer local; they do not affect |
301 ;; indentation style. | 451 ;; indentation style. |
302 (make-local-variable 'parse-sexp-ignore-comments) | 452 (make-local-variable 'parse-sexp-ignore-comments) |
303 (make-local-variable 'indent-line-function) | 453 (make-local-variable 'indent-line-function) |
304 (make-local-variable 'indent-region-function) | 454 (make-local-variable 'indent-region-function) |
305 (make-local-variable 'outline-regexp) | |
306 (make-local-variable 'outline-level) | |
307 (make-local-variable 'normal-auto-fill-function) | 455 (make-local-variable 'normal-auto-fill-function) |
308 (make-local-variable 'comment-start) | 456 (make-local-variable 'comment-start) |
309 (make-local-variable 'comment-end) | 457 (make-local-variable 'comment-end) |
310 (make-local-variable 'comment-column) | |
311 (make-local-variable 'comment-start-skip) | 458 (make-local-variable 'comment-start-skip) |
312 (make-local-variable 'comment-multi-line) | 459 (make-local-variable 'comment-multi-line) |
460 (make-local-variable 'comment-line-break-function) | |
313 (make-local-variable 'paragraph-start) | 461 (make-local-variable 'paragraph-start) |
314 (make-local-variable 'paragraph-separate) | 462 (make-local-variable 'paragraph-separate) |
315 (make-local-variable 'paragraph-ignore-fill-prefix) | 463 (make-local-variable 'paragraph-ignore-fill-prefix) |
316 (make-local-variable 'adaptive-fill-mode) | 464 (make-local-variable 'adaptive-fill-mode) |
317 (make-local-variable 'adaptive-fill-regexp) | 465 (make-local-variable 'adaptive-fill-regexp) |
318 (make-local-variable 'imenu-generic-expression) ;set in the mode functions | |
319 | |
320 ;; X/Emacs 20 only | |
321 (and (boundp 'comment-line-break-function) | |
322 (progn | |
323 (make-local-variable 'comment-line-break-function) | |
324 (setq comment-line-break-function | |
325 'c-indent-new-comment-line))) | |
326 | 466 |
327 ;; now set their values | 467 ;; now set their values |
328 (setq parse-sexp-ignore-comments t | 468 (setq parse-sexp-ignore-comments t |
329 indent-line-function 'c-indent-line | 469 indent-line-function 'c-indent-line |
330 indent-region-function 'c-indent-region | 470 indent-region-function 'c-indent-region |
331 outline-regexp "[^#\n\^M]" | |
332 outline-level 'c-outline-level | |
333 normal-auto-fill-function 'c-do-auto-fill | 471 normal-auto-fill-function 'c-do-auto-fill |
334 comment-column 32 | 472 comment-multi-line t |
335 comment-start-skip "/\\*+ *\\|//+ *" | 473 comment-line-break-function 'c-indent-new-comment-line) |
336 comment-multi-line t) | |
337 | 474 |
338 ;; Install `c-fill-paragraph' on `fill-paragraph-function' so that a | 475 ;; Install `c-fill-paragraph' on `fill-paragraph-function' so that a |
339 ;; direct call to `fill-paragraph' behaves better. This still | 476 ;; direct call to `fill-paragraph' behaves better. This still |
340 ;; doesn't work with filladapt but it's better than nothing. | 477 ;; doesn't work with filladapt but it's better than nothing. |
341 (make-local-variable 'fill-paragraph-function) | 478 (make-local-variable 'fill-paragraph-function) |
342 (setq fill-paragraph-function 'c-fill-paragraph) | 479 (setq fill-paragraph-function 'c-fill-paragraph) |
343 | 480 |
344 ;; Set `require-final-newline' only if we should. | 481 (when (or c-recognize-<>-arglists |
345 (let ((rfn (assq mode c-require-final-newline))) | 482 (c-major-mode-is 'awk-mode)) |
346 (when rfn | 483 ;; We'll use the syntax-table text property to change the syntax |
347 (make-local-variable 'require-final-newline) | 484 ;; of some chars for this language, so do the necessary setup for |
348 (setq require-final-newline (cdr rfn)))) | 485 ;; that. |
349 | 486 ;; |
350 ;; Fix keyword regexps. | 487 ;; Note to other package developers: It's ok to turn this on in CC |
351 (c-init-language-vars) | 488 ;; Mode buffers when CC Mode doesn't, but it's not ok to turn it |
352 | 489 ;; off if CC Mode has turned it on. |
353 ;; now set the mode style based on c-default-style | 490 |
354 (let ((style (if (stringp c-default-style) | 491 ;; Emacs. |
355 c-default-style | 492 (when (boundp 'parse-sexp-lookup-properties) |
356 (or (cdr (assq mode c-default-style)) | 493 (make-local-variable 'parse-sexp-lookup-properties) |
357 (cdr (assq 'other c-default-style)) | 494 (setq parse-sexp-lookup-properties t)) |
495 | |
496 ;; Same as above for XEmacs. | |
497 (when (boundp 'lookup-syntax-properties) | |
498 (make-local-variable 'lookup-syntax-properties) | |
499 (setq lookup-syntax-properties t))) | |
500 | |
501 ;; Use this in Emacs 21 to avoid meddling with the rear-nonsticky | |
502 ;; property on each character. | |
503 (when (boundp 'text-property-default-nonsticky) | |
504 (make-local-variable 'text-property-default-nonsticky) | |
505 (let ((elem (assq 'syntax-table text-property-default-nonsticky))) | |
506 (if elem | |
507 (setcdr elem t) | |
508 (setq text-property-default-nonsticky | |
509 (cons '(syntax-table . t) | |
510 text-property-default-nonsticky)))) | |
511 (setq text-property-default-nonsticky | |
512 (cons '(c-type . t) | |
513 text-property-default-nonsticky))) | |
514 | |
515 ;; In Emacs 21 and later it's possible to turn off the ad-hoc | |
516 ;; heuristic that open parens in column 0 are defun starters. Since | |
517 ;; we have c-state-cache, that heuristic isn't useful and only causes | |
518 ;; trouble, so turn it off. | |
519 (when (memq 'col-0-paren c-emacs-features) | |
520 (make-local-variable 'open-paren-in-column-0-is-defun-start) | |
521 (setq open-paren-in-column-0-is-defun-start nil)) | |
522 | |
523 (c-clear-found-types) | |
524 | |
525 ;; now set the mode style based on default-style | |
526 (let ((style (if (stringp default-style) | |
527 default-style | |
528 (or (cdr (assq mode default-style)) | |
529 (cdr (assq 'other default-style)) | |
358 "gnu")))) | 530 "gnu")))) |
359 ;; Override style variables if `c-old-style-variable-behavior' is | 531 ;; Override style variables if `c-old-style-variable-behavior' is |
360 ;; set. Also override if we are using global style variables, | 532 ;; set. Also override if we are using global style variables, |
361 ;; have already initialized a style once, and are switching to a | 533 ;; have already initialized a style once, and are switching to a |
362 ;; different style. (It's doubtful whether this is desirable, but | 534 ;; different style. (It's doubtful whether this is desirable, but |
376 | 548 |
377 ;; setup the comment indent variable in a Emacs version portable way | 549 ;; setup the comment indent variable in a Emacs version portable way |
378 (make-local-variable 'comment-indent-function) | 550 (make-local-variable 'comment-indent-function) |
379 (setq comment-indent-function 'c-comment-indent) | 551 (setq comment-indent-function 'c-comment-indent) |
380 | 552 |
381 ;; add menus to menubar | 553 ;; Put submode indicators onto minor-mode-alist, but only once. |
382 (easy-menu-add (c-mode-menu mode-name)) | 554 (or (assq 'c-submode-indicators minor-mode-alist) |
383 | |
384 ;; put auto-hungry designators onto minor-mode-alist, but only once | |
385 (or (assq 'c-auto-hungry-string minor-mode-alist) | |
386 (setq minor-mode-alist | 555 (setq minor-mode-alist |
387 (cons '(c-auto-hungry-string c-auto-hungry-string) | 556 (cons '(c-submode-indicators c-submode-indicators) |
388 minor-mode-alist))) | 557 minor-mode-alist))) |
389 | 558 |
390 ;; Install the function that ensures `c-state-cache' doesn't become | 559 ;; Install the functions that ensure that various internal caches |
391 ;; invalid. | 560 ;; don't become invalid due to buffer changes. |
392 (make-local-variable 'after-change-functions) | 561 (make-local-hook 'after-change-functions) |
393 (add-hook 'after-change-functions 'c-check-state-cache)) | 562 (add-hook 'after-change-functions 'c-after-change nil t)) |
563 | |
564 (defun c-after-font-lock-init () | |
565 ;; Put on `font-lock-mode-hook'. | |
566 (remove-hook 'after-change-functions 'c-after-change t) | |
567 (add-hook 'after-change-functions 'c-after-change nil t)) | |
568 | |
569 (defun c-font-lock-init () | |
570 "Set up the font-lock variables for using the font-lock support in CC Mode. | |
571 This does not load the font-lock package. Use after | |
572 `c-basic-common-init' and after cc-fonts has been loaded." | |
573 | |
574 (make-local-variable 'font-lock-defaults) | |
575 (setq font-lock-defaults | |
576 `(,(if (c-major-mode-is 'awk-mode) | |
577 ;; awk-mode currently has only one font lock level. | |
578 'awk-font-lock-keywords | |
579 (mapcar 'c-mode-symbol | |
580 '("font-lock-keywords" "font-lock-keywords-1" | |
581 "font-lock-keywords-2" "font-lock-keywords-3"))) | |
582 nil nil | |
583 ,c-identifier-syntax-modifications | |
584 c-beginning-of-syntax | |
585 (font-lock-lines-before . 1) | |
586 (font-lock-mark-block-function | |
587 . c-mark-function))) | |
588 | |
589 (make-local-hook 'font-lock-mode-hook) | |
590 (add-hook 'font-lock-mode-hook 'c-after-font-lock-init nil t)) | |
591 | |
592 (defun c-setup-doc-comment-style () | |
593 "Initialize the variables that depend on the value of `c-doc-comment-style'." | |
594 (when (and (featurep 'font-lock) | |
595 (symbol-value 'font-lock-mode)) | |
596 ;; Force font lock mode to reinitialize itself. | |
597 (font-lock-mode 0) | |
598 (font-lock-mode 1))) | |
599 | |
600 (defun c-common-init (&optional mode) | |
601 "Common initialization for all CC Mode modes. | |
602 In addition to the work done by `c-basic-common-init' and | |
603 `c-font-lock-init', this function sets up various other things as | |
604 customary in CC Mode modes but which aren't strictly necessary for CC | |
605 Mode to operate correctly. | |
606 | |
607 MODE is the symbol for the mode to initialize, like 'c-mode. See | |
608 `c-basic-common-init' for details. It's only optional to be | |
609 compatible with old code; callers should always specify it." | |
610 | |
611 (unless mode | |
612 ;; Called from an old third party package. The fallback is to | |
613 ;; initialize for C. | |
614 (c-init-language-vars-for 'c-mode)) | |
615 | |
616 (c-basic-common-init mode c-default-style) | |
617 (when mode | |
618 ;; Only initialize font locking if we aren't called from an old package. | |
619 (c-font-lock-init)) | |
620 | |
621 (make-local-variable 'outline-regexp) | |
622 (make-local-variable 'outline-level) | |
623 (setq outline-regexp "[^#\n\^M]" | |
624 outline-level 'c-outline-level) | |
625 | |
626 (let ((rfn (assq mode c-require-final-newline))) | |
627 (when rfn | |
628 (make-local-variable 'require-final-newline) | |
629 (and (cdr rfn) | |
630 (setq require-final-newline mode-require-final-newline))))) | |
394 | 631 |
395 (defun c-postprocess-file-styles () | 632 (defun c-postprocess-file-styles () |
396 "Function that post processes relevant file local variables. | 633 "Function that post processes relevant file local variables in CC Mode. |
397 Currently, this function simply applies any style and offset settings | 634 Currently, this function simply applies any style and offset settings |
398 found in the file's Local Variable list. It first applies any style | 635 found in the file's Local Variable list. It first applies any style |
399 setting found in `c-file-style', then it applies any offset settings | 636 setting found in `c-file-style', then it applies any offset settings |
400 it finds in `c-file-offsets'. | 637 it finds in `c-file-offsets'. |
401 | 638 |
402 Note that the style variables are always made local to the buffer." | 639 Note that the style variables are always made local to the buffer." |
640 | |
403 ;; apply file styles and offsets | 641 ;; apply file styles and offsets |
404 (when c-buffer-is-cc-mode | 642 (when c-buffer-is-cc-mode |
405 (if (or c-file-style c-file-offsets) | 643 (if (or c-file-style c-file-offsets) |
406 (c-make-styles-buffer-local t)) | 644 (c-make-styles-buffer-local t)) |
407 (and c-file-style | 645 (and c-file-style |
410 (mapcar | 648 (mapcar |
411 (lambda (langentry) | 649 (lambda (langentry) |
412 (let ((langelem (car langentry)) | 650 (let ((langelem (car langentry)) |
413 (offset (cdr langentry))) | 651 (offset (cdr langentry))) |
414 (c-set-offset langelem offset))) | 652 (c-set-offset langelem offset))) |
415 c-file-offsets)))) | 653 c-file-offsets)) |
654 ;; Problem: The file local variable block might have explicitly set a | |
655 ;; style variable. The `c-set-style' or `mapcar' call might have | |
656 ;; overwritten this. So we run `hack-local-variables' again to remedy | |
657 ;; this. There are no guarantees this will work properly, particularly as | |
658 ;; we have no control over what the other hook functions on | |
659 ;; `hack-local-variables-hook' would have done, or what any "eval" | |
660 ;; expression will do when evaluated again. C'est la vie! ACM, | |
661 ;; 2005/11/2. | |
662 (if (or c-file-style c-file-offsets) | |
663 (let ((hack-local-variables-hook nil)) | |
664 (hack-local-variables))))) | |
416 | 665 |
417 (add-hook 'hack-local-variables-hook 'c-postprocess-file-styles) | 666 (add-hook 'hack-local-variables-hook 'c-postprocess-file-styles) |
667 | |
668 (defmacro c-run-mode-hooks (&rest hooks) | |
669 ;; Emacs 21.1 has introduced a system with delayed mode hooks that | |
670 ;; require the use of the new function `run-mode-hooks'. | |
671 (if (cc-bytecomp-fboundp 'run-mode-hooks) | |
672 `(run-mode-hooks ,@hooks) | |
673 `(progn ,@(mapcar (lambda (hook) `(run-hooks ,hook)) hooks)))) | |
418 | 674 |
419 | 675 |
420 ;; Support for C | 676 ;; Support for C |
677 | |
678 ;;;###autoload | |
679 (defvar c-mode-syntax-table nil | |
680 "Syntax table used in c-mode buffers.") | |
681 (or c-mode-syntax-table | |
682 (setq c-mode-syntax-table | |
683 (funcall (c-lang-const c-make-mode-syntax-table c)))) | |
421 | 684 |
422 (defvar c-mode-abbrev-table nil | 685 (defvar c-mode-abbrev-table nil |
423 "Abbreviation table used in c-mode buffers.") | 686 "Abbreviation table used in c-mode buffers.") |
424 (c-define-abbrev-table 'c-mode-abbrev-table | 687 (c-define-abbrev-table 'c-mode-abbrev-table |
425 '(("else" "else" c-electric-continued-statement 0) | 688 '(("else" "else" c-electric-continued-statement 0) |
433 ;; add bindings which are only useful for C | 696 ;; add bindings which are only useful for C |
434 (define-key c-mode-map "\C-c\C-e" 'c-macro-expand) | 697 (define-key c-mode-map "\C-c\C-e" 'c-macro-expand) |
435 ) | 698 ) |
436 | 699 |
437 (easy-menu-define c-c-menu c-mode-map "C Mode Commands" | 700 (easy-menu-define c-c-menu c-mode-map "C Mode Commands" |
438 (c-mode-menu "C")) | 701 (cons "C" (c-lang-const c-mode-menu c))) |
702 | |
703 ;; In XEmacs >= 21.5 modes should add their own entries to | |
704 ;; `auto-mode-alist'. The comment form of autoload is used to avoid | |
705 ;; doing this on load. That since `add-to-list' prepends the value | |
706 ;; which could cause it to clobber user settings. Later emacsen have | |
707 ;; an append option, but it's not safe to use. | |
708 | |
709 ;; The the extension ".C" is associated to C++ while the lowercase | |
710 ;; variant goes to C. On case insensitive file systems, this means | |
711 ;; that ".c" files also might open C++ mode if the C++ entry comes | |
712 ;; first on `auto-mode-alist'. Thus we try to ensure that ".C" comes | |
713 ;; after ".c", and since `add-to-list' adds the entry first we have to | |
714 ;; add the ".C" entry first. | |
715 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.\\(cc\\|hh\\)\\'" . c++-mode)) | |
716 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.[ch]\\(pp\\|xx\\|\\+\\+\\)\\'" . c++-mode)) | |
717 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.\\(CC?\\|HH?\\)\\'" . c++-mode)) | |
718 | |
719 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.[ch]\\'" . c-mode)) | |
720 | |
721 ;; NB: The following two associate yacc and lex files to C Mode, which | |
722 ;; is not really suitable for those formats. Anyway, afaik there's | |
723 ;; currently no better mode for them, and besides this is legacy. | |
724 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.y\\(acc\\)?\\'" . c-mode)) | |
725 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.lex\\'" . c-mode)) | |
439 | 726 |
440 ;;;###autoload | 727 ;;;###autoload |
441 (defun c-mode () | 728 (defun c-mode () |
442 "Major mode for editing K&R and ANSI C code. | 729 "Major mode for editing K&R and ANSI C code. |
443 To submit a problem report, enter `\\[c-submit-bug-report]' from a | 730 To submit a problem report, enter `\\[c-submit-bug-report]' from a |
444 c-mode buffer. This automatically sets up a mail buffer with version | 731 c-mode buffer. This automatically sets up a mail buffer with version |
445 information already added. You just need to add a description of the | 732 information already added. You just need to add a description of the |
446 problem, including a reproducible test case and send the message. | 733 problem, including a reproducible test case, and send the message. |
447 | 734 |
448 To see what version of CC Mode you are running, enter `\\[c-version]'. | 735 To see what version of CC Mode you are running, enter `\\[c-version]'. |
449 | 736 |
450 The hook variable `c-mode-hook' is run with no args, if that value is | 737 The hook `c-mode-common-hook' is run with no args at mode |
451 bound and has a non-nil value. Also the hook `c-mode-common-hook' is | 738 initialization, then `c-mode-hook'. |
452 run first. | |
453 | 739 |
454 Key bindings: | 740 Key bindings: |
455 \\{c-mode-map}" | 741 \\{c-mode-map}" |
456 (interactive) | 742 (interactive) |
457 (kill-all-local-variables) | 743 (kill-all-local-variables) |
458 (c-initialize-cc-mode) | 744 (c-initialize-cc-mode t) |
459 (set-syntax-table c-mode-syntax-table) | 745 (set-syntax-table c-mode-syntax-table) |
460 (setq major-mode 'c-mode | 746 (setq major-mode 'c-mode |
461 mode-name "C" | 747 mode-name "C" |
462 local-abbrev-table c-mode-abbrev-table | 748 local-abbrev-table c-mode-abbrev-table |
463 abbrev-mode t) | 749 abbrev-mode t) |
464 (use-local-map c-mode-map) | 750 (use-local-map c-mode-map) |
751 (c-init-language-vars-for 'c-mode) | |
465 (c-common-init 'c-mode) | 752 (c-common-init 'c-mode) |
753 (easy-menu-add c-c-menu) | |
466 (cc-imenu-init cc-imenu-c-generic-expression) | 754 (cc-imenu-init cc-imenu-c-generic-expression) |
467 (run-hooks 'c-mode-common-hook) | 755 (c-run-mode-hooks 'c-mode-common-hook 'c-mode-hook) |
468 (run-hooks 'c-mode-hook) | |
469 (c-update-modeline)) | 756 (c-update-modeline)) |
470 | 757 |
471 | 758 |
472 ;; Support for C++ | 759 ;; Support for C++ |
760 | |
761 ;;;###autoload | |
762 (defvar c++-mode-syntax-table nil | |
763 "Syntax table used in c++-mode buffers.") | |
764 (or c++-mode-syntax-table | |
765 (setq c++-mode-syntax-table | |
766 (funcall (c-lang-const c-make-mode-syntax-table c++)))) | |
473 | 767 |
474 (defvar c++-mode-abbrev-table nil | 768 (defvar c++-mode-abbrev-table nil |
475 "Abbreviation table used in c++-mode buffers.") | 769 "Abbreviation table used in c++-mode buffers.") |
476 (c-define-abbrev-table 'c++-mode-abbrev-table | 770 (c-define-abbrev-table 'c++-mode-abbrev-table |
477 '(("else" "else" c-electric-continued-statement 0) | 771 '(("else" "else" c-electric-continued-statement 0) |
488 (define-key c++-mode-map "\C-c:" 'c-scope-operator) | 782 (define-key c++-mode-map "\C-c:" 'c-scope-operator) |
489 (define-key c++-mode-map "<" 'c-electric-lt-gt) | 783 (define-key c++-mode-map "<" 'c-electric-lt-gt) |
490 (define-key c++-mode-map ">" 'c-electric-lt-gt)) | 784 (define-key c++-mode-map ">" 'c-electric-lt-gt)) |
491 | 785 |
492 (easy-menu-define c-c++-menu c++-mode-map "C++ Mode Commands" | 786 (easy-menu-define c-c++-menu c++-mode-map "C++ Mode Commands" |
493 (c-mode-menu "C++")) | 787 (cons "C++" (c-lang-const c-mode-menu c++))) |
494 | 788 |
495 ;;;###autoload | 789 ;;;###autoload |
496 (defun c++-mode () | 790 (defun c++-mode () |
497 "Major mode for editing C++ code. | 791 "Major mode for editing C++ code. |
498 To submit a problem report, enter `\\[c-submit-bug-report]' from a | 792 To submit a problem report, enter `\\[c-submit-bug-report]' from a |
501 of the problem, including a reproducible test case, and send the | 795 of the problem, including a reproducible test case, and send the |
502 message. | 796 message. |
503 | 797 |
504 To see what version of CC Mode you are running, enter `\\[c-version]'. | 798 To see what version of CC Mode you are running, enter `\\[c-version]'. |
505 | 799 |
506 The hook variable `c++-mode-hook' is run with no args, if that | 800 The hook `c-mode-common-hook' is run with no args at mode |
507 variable is bound and has a non-nil value. Also the hook | 801 initialization, then `c++-mode-hook'. |
508 `c-mode-common-hook' is run first. | |
509 | 802 |
510 Key bindings: | 803 Key bindings: |
511 \\{c++-mode-map}" | 804 \\{c++-mode-map}" |
512 (interactive) | 805 (interactive) |
513 (kill-all-local-variables) | 806 (kill-all-local-variables) |
514 (c-initialize-cc-mode) | 807 (c-initialize-cc-mode t) |
515 (set-syntax-table c++-mode-syntax-table) | 808 (set-syntax-table c++-mode-syntax-table) |
516 (setq major-mode 'c++-mode | 809 (setq major-mode 'c++-mode |
517 mode-name "C++" | 810 mode-name "C++" |
518 local-abbrev-table c++-mode-abbrev-table | 811 local-abbrev-table c++-mode-abbrev-table |
519 abbrev-mode t) | 812 abbrev-mode t) |
520 (use-local-map c++-mode-map) | 813 (use-local-map c++-mode-map) |
814 (c-init-language-vars-for 'c++-mode) | |
521 (c-common-init 'c++-mode) | 815 (c-common-init 'c++-mode) |
816 (easy-menu-add c-c++-menu) | |
522 (cc-imenu-init cc-imenu-c++-generic-expression) | 817 (cc-imenu-init cc-imenu-c++-generic-expression) |
523 (run-hooks 'c-mode-common-hook) | 818 (c-run-mode-hooks 'c-mode-common-hook 'c++-mode-hook) |
524 (run-hooks 'c++-mode-hook) | |
525 (c-update-modeline)) | 819 (c-update-modeline)) |
526 | 820 |
527 | 821 |
528 ;; Support for Objective-C | 822 ;; Support for Objective-C |
823 | |
824 ;;;###autoload | |
825 (defvar objc-mode-syntax-table nil | |
826 "Syntax table used in objc-mode buffers.") | |
827 (or objc-mode-syntax-table | |
828 (setq objc-mode-syntax-table | |
829 (funcall (c-lang-const c-make-mode-syntax-table objc)))) | |
529 | 830 |
530 (defvar objc-mode-abbrev-table nil | 831 (defvar objc-mode-abbrev-table nil |
531 "Abbreviation table used in objc-mode buffers.") | 832 "Abbreviation table used in objc-mode buffers.") |
532 (c-define-abbrev-table 'objc-mode-abbrev-table | 833 (c-define-abbrev-table 'objc-mode-abbrev-table |
533 '(("else" "else" c-electric-continued-statement 0) | 834 '(("else" "else" c-electric-continued-statement 0) |
540 (setq objc-mode-map (c-make-inherited-keymap)) | 841 (setq objc-mode-map (c-make-inherited-keymap)) |
541 ;; add bindings which are only useful for Objective-C | 842 ;; add bindings which are only useful for Objective-C |
542 (define-key objc-mode-map "\C-c\C-e" 'c-macro-expand)) | 843 (define-key objc-mode-map "\C-c\C-e" 'c-macro-expand)) |
543 | 844 |
544 (easy-menu-define c-objc-menu objc-mode-map "ObjC Mode Commands" | 845 (easy-menu-define c-objc-menu objc-mode-map "ObjC Mode Commands" |
545 (c-mode-menu "ObjC")) | 846 (cons "ObjC" (c-lang-const c-mode-menu objc))) |
847 | |
848 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.m\\'" . objc-mode)) | |
546 | 849 |
547 ;;;###autoload | 850 ;;;###autoload |
548 (defun objc-mode () | 851 (defun objc-mode () |
549 "Major mode for editing Objective C code. | 852 "Major mode for editing Objective C code. |
550 To submit a problem report, enter `\\[c-submit-bug-report]' from an | 853 To submit a problem report, enter `\\[c-submit-bug-report]' from an |
553 of the problem, including a reproducible test case, and send the | 856 of the problem, including a reproducible test case, and send the |
554 message. | 857 message. |
555 | 858 |
556 To see what version of CC Mode you are running, enter `\\[c-version]'. | 859 To see what version of CC Mode you are running, enter `\\[c-version]'. |
557 | 860 |
558 The hook variable `objc-mode-hook' is run with no args, if that value | 861 The hook `c-mode-common-hook' is run with no args at mode |
559 is bound and has a non-nil value. Also the hook `c-mode-common-hook' | 862 initialization, then `objc-mode-hook'. |
560 is run first. | |
561 | 863 |
562 Key bindings: | 864 Key bindings: |
563 \\{objc-mode-map}" | 865 \\{objc-mode-map}" |
564 (interactive) | 866 (interactive) |
565 (kill-all-local-variables) | 867 (kill-all-local-variables) |
566 (c-initialize-cc-mode) | 868 (c-initialize-cc-mode t) |
567 (set-syntax-table objc-mode-syntax-table) | 869 (set-syntax-table objc-mode-syntax-table) |
568 (setq major-mode 'objc-mode | 870 (setq major-mode 'objc-mode |
569 mode-name "ObjC" | 871 mode-name "ObjC" |
570 local-abbrev-table objc-mode-abbrev-table | 872 local-abbrev-table objc-mode-abbrev-table |
571 abbrev-mode t) | 873 abbrev-mode t) |
572 (use-local-map objc-mode-map) | 874 (use-local-map objc-mode-map) |
875 (c-init-language-vars-for 'objc-mode) | |
573 (c-common-init 'objc-mode) | 876 (c-common-init 'objc-mode) |
574 (cc-imenu-init cc-imenu-objc-generic-expression) | 877 (easy-menu-add c-objc-menu) |
575 (run-hooks 'c-mode-common-hook) | 878 (cc-imenu-init nil 'cc-imenu-objc-function) |
576 (run-hooks 'objc-mode-hook) | 879 (c-run-mode-hooks 'c-mode-common-hook 'objc-mode-hook) |
577 (c-update-modeline)) | 880 (c-update-modeline)) |
578 | 881 |
579 | 882 |
580 ;; Support for Java | 883 ;; Support for Java |
884 | |
885 ;;;###autoload | |
886 (defvar java-mode-syntax-table nil | |
887 "Syntax table used in java-mode buffers.") | |
888 (or java-mode-syntax-table | |
889 (setq java-mode-syntax-table | |
890 (funcall (c-lang-const c-make-mode-syntax-table java)))) | |
581 | 891 |
582 (defvar java-mode-abbrev-table nil | 892 (defvar java-mode-abbrev-table nil |
583 "Abbreviation table used in java-mode buffers.") | 893 "Abbreviation table used in java-mode buffers.") |
584 (c-define-abbrev-table 'java-mode-abbrev-table | 894 (c-define-abbrev-table 'java-mode-abbrev-table |
585 '(("else" "else" c-electric-continued-statement 0) | 895 '(("else" "else" c-electric-continued-statement 0) |
593 nil | 903 nil |
594 (setq java-mode-map (c-make-inherited-keymap)) | 904 (setq java-mode-map (c-make-inherited-keymap)) |
595 ;; add bindings which are only useful for Java | 905 ;; add bindings which are only useful for Java |
596 ) | 906 ) |
597 | 907 |
908 ;; Regexp trying to describe the beginning of a Java top-level | |
909 ;; definition. This is not used by CC Mode, nor is it maintained | |
910 ;; since it's practically impossible to write a regexp that reliably | |
911 ;; matches such a construct. Other tools are necessary. | |
912 (defconst c-Java-defun-prompt-regexp | |
913 "^[ \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\v]*\\)+\\)?\\s-*") | |
914 | |
598 (easy-menu-define c-java-menu java-mode-map "Java Mode Commands" | 915 (easy-menu-define c-java-menu java-mode-map "Java Mode Commands" |
599 (c-mode-menu "Java")) | 916 (cons "Java" (c-lang-const c-mode-menu java))) |
917 | |
918 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.java\\'" . java-mode)) | |
600 | 919 |
601 ;;;###autoload | 920 ;;;###autoload |
602 (defun java-mode () | 921 (defun java-mode () |
603 "Major mode for editing Java code. | 922 "Major mode for editing Java code. |
604 To submit a problem report, enter `\\[c-submit-bug-report]' from a | 923 To submit a problem report, enter `\\[c-submit-bug-report]' from a |
605 java-mode buffer. This automatically sets up a mail buffer with | 924 java-mode buffer. This automatically sets up a mail buffer with |
606 version information already added. You just need to add a description | 925 version information already added. You just need to add a description |
607 of the problem, including a reproducible test case and send the | 926 of the problem, including a reproducible test case, and send the |
608 message. | 927 message. |
609 | 928 |
610 To see what version of CC Mode you are running, enter `\\[c-version]'. | 929 To see what version of CC Mode you are running, enter `\\[c-version]'. |
611 | 930 |
612 The hook variable `java-mode-hook' is run with no args, if that value | 931 The hook `c-mode-common-hook' is run with no args at mode |
613 is bound and has a non-nil value. Also the common hook | 932 initialization, then `java-mode-hook'. |
614 `c-mode-common-hook' is run first. Note that this mode automatically | |
615 sets the \"java\" style before calling any hooks so be careful if you | |
616 set styles in `c-mode-common-hook'. | |
617 | 933 |
618 Key bindings: | 934 Key bindings: |
619 \\{java-mode-map}" | 935 \\{java-mode-map}" |
620 (interactive) | 936 (interactive) |
621 (kill-all-local-variables) | 937 (kill-all-local-variables) |
622 (c-initialize-cc-mode) | 938 (c-initialize-cc-mode t) |
623 (set-syntax-table java-mode-syntax-table) | 939 (set-syntax-table java-mode-syntax-table) |
624 (setq major-mode 'java-mode | 940 (setq major-mode 'java-mode |
625 mode-name "Java" | 941 mode-name "Java" |
626 local-abbrev-table java-mode-abbrev-table | 942 local-abbrev-table java-mode-abbrev-table |
627 abbrev-mode t) | 943 abbrev-mode t) |
628 (use-local-map java-mode-map) | 944 (use-local-map java-mode-map) |
945 (c-init-language-vars-for 'java-mode) | |
629 (c-common-init 'java-mode) | 946 (c-common-init 'java-mode) |
947 (easy-menu-add c-java-menu) | |
630 (cc-imenu-init cc-imenu-java-generic-expression) | 948 (cc-imenu-init cc-imenu-java-generic-expression) |
631 (run-hooks 'c-mode-common-hook) | 949 (c-run-mode-hooks 'c-mode-common-hook 'java-mode-hook) |
632 (run-hooks 'java-mode-hook) | |
633 (c-update-modeline)) | 950 (c-update-modeline)) |
634 | 951 |
635 | 952 |
636 ;; Support for CORBA's IDL language | 953 ;; Support for CORBA's IDL language |
954 | |
955 ;;;###autoload | |
956 (defvar idl-mode-syntax-table nil | |
957 "Syntax table used in idl-mode buffers.") | |
958 (or idl-mode-syntax-table | |
959 (setq idl-mode-syntax-table | |
960 (funcall (c-lang-const c-make-mode-syntax-table idl)))) | |
637 | 961 |
638 (defvar idl-mode-abbrev-table nil | 962 (defvar idl-mode-abbrev-table nil |
639 "Abbreviation table used in idl-mode buffers.") | 963 "Abbreviation table used in idl-mode buffers.") |
640 (c-define-abbrev-table 'idl-mode-abbrev-table nil) | 964 (c-define-abbrev-table 'idl-mode-abbrev-table nil) |
641 | 965 |
646 (setq idl-mode-map (c-make-inherited-keymap)) | 970 (setq idl-mode-map (c-make-inherited-keymap)) |
647 ;; add bindings which are only useful for IDL | 971 ;; add bindings which are only useful for IDL |
648 ) | 972 ) |
649 | 973 |
650 (easy-menu-define c-idl-menu idl-mode-map "IDL Mode Commands" | 974 (easy-menu-define c-idl-menu idl-mode-map "IDL Mode Commands" |
651 (c-mode-menu "IDL")) | 975 (cons "IDL" (c-lang-const c-mode-menu idl))) |
976 | |
977 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.idl\\'" . idl-mode)) | |
652 | 978 |
653 ;;;###autoload | 979 ;;;###autoload |
654 (defun idl-mode () | 980 (defun idl-mode () |
655 "Major mode for editing CORBA's IDL code. | 981 "Major mode for editing CORBA's IDL, PSDL and CIDL code. |
656 To submit a problem report, enter `\\[c-submit-bug-report]' from an | 982 To submit a problem report, enter `\\[c-submit-bug-report]' from an |
657 idl-mode buffer. This automatically sets up a mail buffer with | 983 idl-mode buffer. This automatically sets up a mail buffer with |
658 version information already added. You just need to add a description | 984 version information already added. You just need to add a description |
659 of the problem, including a reproducible test case, and send the | 985 of the problem, including a reproducible test case, and send the |
660 message. | 986 message. |
661 | 987 |
662 To see what version of CC Mode you are running, enter `\\[c-version]'. | 988 To see what version of CC Mode you are running, enter `\\[c-version]'. |
663 | 989 |
664 The hook variable `idl-mode-hook' is run with no args, if that | 990 The hook `c-mode-common-hook' is run with no args at mode |
665 variable is bound and has a non-nil value. Also the hook | 991 initialization, then `idl-mode-hook'. |
666 `c-mode-common-hook' is run first. | |
667 | 992 |
668 Key bindings: | 993 Key bindings: |
669 \\{idl-mode-map}" | 994 \\{idl-mode-map}" |
670 (interactive) | 995 (interactive) |
671 (kill-all-local-variables) | 996 (kill-all-local-variables) |
672 (c-initialize-cc-mode) | 997 (c-initialize-cc-mode t) |
673 (set-syntax-table idl-mode-syntax-table) | 998 (set-syntax-table idl-mode-syntax-table) |
674 (setq major-mode 'idl-mode | 999 (setq major-mode 'idl-mode |
675 mode-name "IDL" | 1000 mode-name "IDL" |
676 local-abbrev-table idl-mode-abbrev-table) | 1001 local-abbrev-table idl-mode-abbrev-table) |
677 (use-local-map idl-mode-map) | 1002 (use-local-map idl-mode-map) |
1003 (c-init-language-vars-for 'idl-mode) | |
678 (c-common-init 'idl-mode) | 1004 (c-common-init 'idl-mode) |
679 ;;(cc-imenu-init cc-imenu-idl-generic-expression) ;FIXME | 1005 (easy-menu-add c-idl-menu) |
680 (run-hooks 'c-mode-common-hook) | 1006 ;;(cc-imenu-init cc-imenu-idl-generic-expression) ;TODO |
681 (run-hooks 'idl-mode-hook) | 1007 (c-run-mode-hooks 'c-mode-common-hook 'idl-mode-hook) |
682 (c-update-modeline)) | 1008 (c-update-modeline)) |
683 | 1009 |
684 | 1010 |
685 ;; Support for Pike | 1011 ;; Support for Pike |
1012 | |
1013 ;;;###autoload | |
1014 (defvar pike-mode-syntax-table nil | |
1015 "Syntax table used in pike-mode buffers.") | |
1016 (or pike-mode-syntax-table | |
1017 (setq pike-mode-syntax-table | |
1018 (funcall (c-lang-const c-make-mode-syntax-table pike)))) | |
686 | 1019 |
687 (defvar pike-mode-abbrev-table nil | 1020 (defvar pike-mode-abbrev-table nil |
688 "Abbreviation table used in pike-mode buffers.") | 1021 "Abbreviation table used in pike-mode buffers.") |
689 (c-define-abbrev-table 'pike-mode-abbrev-table | 1022 (c-define-abbrev-table 'pike-mode-abbrev-table |
690 '(("else" "else" c-electric-continued-statement 0) | 1023 '(("else" "else" c-electric-continued-statement 0) |
697 (setq pike-mode-map (c-make-inherited-keymap)) | 1030 (setq pike-mode-map (c-make-inherited-keymap)) |
698 ;; additional bindings | 1031 ;; additional bindings |
699 (define-key pike-mode-map "\C-c\C-e" 'c-macro-expand)) | 1032 (define-key pike-mode-map "\C-c\C-e" 'c-macro-expand)) |
700 | 1033 |
701 (easy-menu-define c-pike-menu pike-mode-map "Pike Mode Commands" | 1034 (easy-menu-define c-pike-menu pike-mode-map "Pike Mode Commands" |
702 (c-mode-menu "Pike")) | 1035 (cons "Pike" (c-lang-const c-mode-menu pike))) |
1036 | |
1037 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.\\(u?lpc\\|pike\\|pmod\\(.in\\)?\\)\\'" . pike-mode)) | |
1038 ;;;###autoload (add-to-list 'interpreter-mode-alist '("pike" . pike-mode)) | |
703 | 1039 |
704 ;;;###autoload | 1040 ;;;###autoload |
705 (defun pike-mode () | 1041 (defun pike-mode () |
706 "Major mode for editing Pike code. | 1042 "Major mode for editing Pike code. |
707 To submit a problem report, enter `\\[c-submit-bug-report]' from a | 1043 To submit a problem report, enter `\\[c-submit-bug-report]' from a |
710 of the problem, including a reproducible test case, and send the | 1046 of the problem, including a reproducible test case, and send the |
711 message. | 1047 message. |
712 | 1048 |
713 To see what version of CC Mode you are running, enter `\\[c-version]'. | 1049 To see what version of CC Mode you are running, enter `\\[c-version]'. |
714 | 1050 |
715 The hook variable `pike-mode-hook' is run with no args, if that value | 1051 The hook `c-mode-common-hook' is run with no args at mode |
716 is bound and has a non-nil value. Also the common hook | 1052 initialization, then `pike-mode-hook'. |
717 `c-mode-common-hook' is run first. | |
718 | 1053 |
719 Key bindings: | 1054 Key bindings: |
720 \\{pike-mode-map}" | 1055 \\{pike-mode-map}" |
721 (interactive) | 1056 (interactive) |
722 (kill-all-local-variables) | 1057 (kill-all-local-variables) |
723 (c-initialize-cc-mode) | 1058 (c-initialize-cc-mode t) |
724 (set-syntax-table pike-mode-syntax-table) | 1059 (set-syntax-table pike-mode-syntax-table) |
725 (setq major-mode 'pike-mode | 1060 (setq major-mode 'pike-mode |
726 mode-name "Pike" | 1061 mode-name "Pike" |
727 local-abbrev-table pike-mode-abbrev-table | 1062 local-abbrev-table pike-mode-abbrev-table |
728 abbrev-mode t) | 1063 abbrev-mode t) |
729 (use-local-map pike-mode-map) | 1064 (use-local-map pike-mode-map) |
1065 (c-init-language-vars-for 'pike-mode) | |
730 (c-common-init 'pike-mode) | 1066 (c-common-init 'pike-mode) |
731 ;;(cc-imenu-init cc-imenu-pike-generic-expression) ;FIXME | 1067 (easy-menu-add c-pike-menu) |
732 (run-hooks 'c-mode-common-hook) | 1068 ;;(cc-imenu-init cc-imenu-pike-generic-expression) ;TODO |
733 (run-hooks 'pike-mode-hook) | 1069 (c-run-mode-hooks 'c-mode-common-hook 'pike-mode-hook) |
1070 (c-update-modeline)) | |
1071 | |
1072 | |
1073 ;; Support for AWK | |
1074 | |
1075 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.awk\\'" . awk-mode)) | |
1076 ;;;###autoload (add-to-list 'interpreter-mode-alist '("awk" . awk-mode)) | |
1077 ;;;###autoload (add-to-list 'interpreter-mode-alist '("mawk" . awk-mode)) | |
1078 ;;;###autoload (add-to-list 'interpreter-mode-alist '("nawk" . awk-mode)) | |
1079 ;;;###autoload (add-to-list 'interpreter-mode-alist '("gawk" . awk-mode)) | |
1080 | |
1081 ;;; Autoload directives must be on the top level, so we construct an | |
1082 ;;; autoload form instead. | |
1083 ;;;###autoload (autoload 'awk-mode "cc-mode" "Major mode for editing AWK code." t) | |
1084 | |
1085 (defvar awk-mode-abbrev-table nil | |
1086 "Abbreviation table used in awk-mode buffers.") | |
1087 (c-define-abbrev-table 'awk-mode-abbrev-table | |
1088 '(("else" "else" c-electric-continued-statement 0) | |
1089 ("while" "while" c-electric-continued-statement 0))) | |
1090 | |
1091 (defvar awk-mode-map () | |
1092 "Keymap used in awk-mode buffers.") | |
1093 (if awk-mode-map | |
1094 nil | |
1095 (setq awk-mode-map (c-make-inherited-keymap)) | |
1096 ;; add bindings which are only useful for awk. | |
1097 (define-key awk-mode-map "#" 'self-insert-command) | |
1098 (define-key awk-mode-map "/" 'self-insert-command) | |
1099 (define-key awk-mode-map "*" 'self-insert-command) | |
1100 (define-key awk-mode-map "\C-c\C-n" 'undefined) ; #if doesn't exist in awk. | |
1101 (define-key awk-mode-map "\C-c\C-p" 'undefined) | |
1102 (define-key awk-mode-map "\C-c\C-u" 'undefined) | |
1103 (define-key awk-mode-map "\M-a" 'c-beginning-of-statement) ; 2003/10/7 | |
1104 (define-key awk-mode-map "\M-e" 'c-end-of-statement) ; 2003/10/7 | |
1105 (define-key awk-mode-map "\C-\M-a" 'c-awk-beginning-of-defun) | |
1106 (define-key awk-mode-map "\C-\M-e" 'c-awk-end-of-defun)) | |
1107 | |
1108 (easy-menu-define c-awk-menu awk-mode-map "AWK Mode Commands" | |
1109 (cons "AWK" (c-lang-const c-mode-menu awk))) | |
1110 | |
1111 (defun awk-mode () | |
1112 "Major mode for editing AWK code. | |
1113 To submit a problem report, enter `\\[c-submit-bug-report]' from an | |
1114 awk-mode buffer. This automatically sets up a mail buffer with version | |
1115 information already added. You just need to add a description of the | |
1116 problem, including a reproducible test case, and send the message. | |
1117 | |
1118 To see what version of CC Mode you are running, enter `\\[c-version]'. | |
1119 | |
1120 The hook `c-mode-common-hook' is run with no args at mode | |
1121 initialization, then `awk-mode-hook'. | |
1122 | |
1123 Key bindings: | |
1124 \\{awk-mode-map}" | |
1125 (interactive) | |
1126 (require 'cc-awk) ; Added 2003/6/10. | |
1127 (kill-all-local-variables) | |
1128 (c-initialize-cc-mode t) | |
1129 (set-syntax-table awk-mode-syntax-table) | |
1130 (setq major-mode 'awk-mode | |
1131 mode-name "AWK" | |
1132 local-abbrev-table awk-mode-abbrev-table | |
1133 abbrev-mode t) | |
1134 (use-local-map awk-mode-map) | |
1135 (c-init-language-vars-for 'awk-mode) | |
1136 (c-common-init 'awk-mode) | |
1137 ;; The rest of CC Mode does not (yet) use `font-lock-syntactic-keywords', | |
1138 ;; so it's not set by `c-font-lock-init'. | |
1139 (make-local-variable 'font-lock-syntactic-keywords) | |
1140 (setq font-lock-syntactic-keywords | |
1141 '((c-awk-set-syntax-table-properties | |
1142 0 (0) ; Everything on this line is a dummy. | |
1143 nil t))) | |
1144 (c-awk-unstick-NL-prop) | |
1145 (add-hook 'before-change-functions 'c-awk-before-change nil t) | |
1146 (add-hook 'after-change-functions 'c-awk-after-change nil t) | |
1147 (c-save-buffer-state nil | |
1148 (save-restriction | |
1149 (widen) | |
1150 (c-awk-clear-NL-props (point-min) (point-max)) | |
1151 (c-awk-after-change (point-min) (point-max) 0))) ; Set syntax-table props. | |
1152 | |
1153 ;; Prevent Xemacs's buffer-syntactic-context being used. See the comment | |
1154 ;; in cc-engine.el, just before (defun c-fast-in-literal ... | |
1155 (defalias 'c-in-literal 'c-slow-in-literal) | |
1156 | |
1157 (c-run-mode-hooks 'c-mode-common-hook 'awk-mode-hook) | |
734 (c-update-modeline)) | 1158 (c-update-modeline)) |
735 | 1159 |
736 | 1160 |
737 ;; bug reporting | 1161 ;; bug reporting |
738 | 1162 |
762 (style c-indentation-style) | 1186 (style c-indentation-style) |
763 (c-features c-emacs-features)) | 1187 (c-features c-emacs-features)) |
764 (and | 1188 (and |
765 (if (y-or-n-p "Do you want to submit a report on CC Mode? ") | 1189 (if (y-or-n-p "Do you want to submit a report on CC Mode? ") |
766 t (message "") nil) | 1190 t (message "") nil) |
767 (require 'reporter) | |
768 (reporter-submit-bug-report | 1191 (reporter-submit-bug-report |
769 c-mode-help-address | 1192 c-mode-help-address |
770 (concat "CC Mode " c-version " (" | 1193 (concat "CC Mode " c-version " (" mode-name ")") |
771 (cond ((eq major-mode 'c++-mode) "C++") | |
772 ((eq major-mode 'c-mode) "C") | |
773 ((eq major-mode 'objc-mode) "ObjC") | |
774 ((eq major-mode 'java-mode) "Java") | |
775 ((eq major-mode 'idl-mode) "IDL") | |
776 ((eq major-mode 'pike-mode) "Pike") | |
777 ) | |
778 ")") | |
779 (let ((vars (append | 1194 (let ((vars (append |
780 ;; report only the vars that affect indentation | |
781 c-style-variables | 1195 c-style-variables |
782 '(c-delete-function | 1196 '(c-buffer-is-cc-mode |
1197 c-tab-always-indent | |
1198 c-syntactic-indentation | |
1199 c-syntactic-indentation-in-macros | |
1200 c-ignore-auto-fill | |
1201 c-auto-align-backslashes | |
1202 c-backspace-function | |
1203 c-delete-function | |
783 c-electric-pound-behavior | 1204 c-electric-pound-behavior |
784 c-indent-comments-syntactically-p | 1205 c-default-style |
785 c-tab-always-indent | 1206 c-enable-xemacs-performance-kludge-p |
1207 c-old-style-variable-behavior | |
786 defun-prompt-regexp | 1208 defun-prompt-regexp |
787 tab-width | 1209 tab-width |
788 comment-column | 1210 comment-column |
789 parse-sexp-ignore-comments | 1211 parse-sexp-ignore-comments |
1212 parse-sexp-lookup-properties | |
1213 lookup-syntax-properties | |
790 ;; A brain-damaged XEmacs only variable that, if | 1214 ;; A brain-damaged XEmacs only variable that, if |
791 ;; set to nil can cause all kinds of chaos. | 1215 ;; set to nil can cause all kinds of chaos. |
792 signal-error-on-buffer-boundary | 1216 signal-error-on-buffer-boundary |
793 ;; Variables that affect line breaking and comments. | 1217 ;; Variables that affect line breaking and comments. |
1218 auto-fill-mode | |
794 auto-fill-function | 1219 auto-fill-function |
795 filladapt-mode | 1220 filladapt-mode |
796 comment-multi-line | 1221 comment-multi-line |
797 comment-start-skip | 1222 comment-start-skip |
798 fill-prefix | 1223 fill-prefix |
1224 fill-column | |
799 paragraph-start | 1225 paragraph-start |
800 adaptive-fill-mode | 1226 adaptive-fill-mode |
801 adaptive-fill-regexp) | 1227 adaptive-fill-regexp) |
802 nil))) | 1228 nil))) |
803 (delq 'c-special-indent-hook vars) | 1229 (mapcar (lambda (var) (unless (boundp var) |
804 (mapcar (lambda (var) (unless (boundp var) (delq var vars))) | 1230 (setq vars (delq var vars)))) |
805 '(signal-error-on-buffer-boundary | 1231 '(signal-error-on-buffer-boundary |
806 filladapt-mode | 1232 filladapt-mode |
807 defun-prompt-regexp)) | 1233 defun-prompt-regexp |
1234 font-lock-mode | |
1235 font-lock-maximum-decoration | |
1236 parse-sexp-lookup-properties | |
1237 lookup-syntax-properties)) | |
808 vars) | 1238 vars) |
809 (lambda () | 1239 (lambda () |
810 (run-hooks 'c-prepare-bug-report-hooks) | 1240 (run-hooks 'c-prepare-bug-report-hooks) |
811 (insert (format "Buffer Style: %s\n\nc-emacs-features: %s\n" | 1241 (insert (format "Buffer Style: %s\nc-emacs-features: %s\n" |
812 style c-features))))))) | 1242 style c-features))))))) |
813 | 1243 |
814 | 1244 |
815 (cc-provide 'cc-mode) | 1245 (cc-provide 'cc-mode) |
1246 | |
1247 ;;; arch-tag: 7825e5c4-fd09-439f-a04d-4c13208ba3d7 | |
816 ;;; cc-mode.el ends here | 1248 ;;; cc-mode.el ends here |