aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerd Moellmann2001-03-21 12:59:36 +0000
committerGerd Moellmann2001-03-21 12:59:36 +0000
commit130c507e58dc58cd41a01288565902922d87409a (patch)
treeaf93e276c60e5e64b4de204348f95d2a5fbc2cb3
parent170a9e70c18727df0544a01d6bac040d65513409 (diff)
downloademacs-130c507e58dc58cd41a01288565902922d87409a.tar.gz
emacs-130c507e58dc58cd41a01288565902922d87409a.zip
Update to version 5.28.
-rw-r--r--lisp/ChangeLog366
-rw-r--r--lisp/progmodes/cc-align.el60
-rw-r--r--lisp/progmodes/cc-bytecomp.el290
-rw-r--r--lisp/progmodes/cc-cmds.el1104
-rw-r--r--lisp/progmodes/cc-compat.el28
-rw-r--r--lisp/progmodes/cc-defs.el237
-rw-r--r--lisp/progmodes/cc-engine.el428
-rw-r--r--lisp/progmodes/cc-langs.el685
-rw-r--r--lisp/progmodes/cc-menus.el42
-rw-r--r--lisp/progmodes/cc-mode.el499
-rw-r--r--lisp/progmodes/cc-styles.el91
-rw-r--r--lisp/progmodes/cc-vars.el286
12 files changed, 2662 insertions, 1454 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index e094f5cc0b2..5473ab98fd7 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -6,6 +6,372 @@
6 * mail/sendmail.el (sendmail-send-it): Don't parse Resent-* 6 * mail/sendmail.el (sendmail-send-it): Don't parse Resent-*
7 headers. Always invoke sendmail with option -t. 7 headers. Always invoke sendmail with option -t.
8 8
92000-03-21 Martin Stjernholm <bug-cc-mode@gnu.org>
10
11 * Release of cc-mode 5.28.
12
132000-03-21 Martin Stjernholm <bug-cc-mode@gnu.org>
14
15 * cc-mode.el, cc-vars.el (c-common-init, c-default-style):
16 Removed the hardcoded switch to "java" style in Java mode.
17 It's instead taken care of by the default value for
18 c-default-style.
19
20 * cc-mode.texi: Updated the mentions of the "java" style
21 special case for Java mode.
22
232000-03-21 Martin Stjernholm <bug-cc-mode@gnu.org>
24
25 * cc-align.el (c-lineup-math): Fix bug where lineup was
26 triggered by equal signs in string literals.
27
282000-03-21 Martin Stjernholm <bug-cc-mode@gnu.org>
29
30 * cc-cmds.el (c-fill-paragraph): Fixed bug in the paragraph
31 limit detection when at the ends of the buffer.
32
33 * cc-engine.el (c-guess-basic-syntax): Removed bogus check for
34 "for" statement clause in case 7F; a better one is done
35 earlier in case 7D anyway.
36
372000-03-21 Martin Stjernholm <bug-cc-mode@gnu.org>
38
39 * cc-cmds.el (c-guess-fill-prefix): Improved the heuristics
40 somewhat more and did a small optimization.
41
422000-03-21 Martin Stjernholm <bug-cc-mode@gnu.org>
43
44 * cc-cmds.el (c-beginning-of-statement, c-end-of-statement):
45 Use the limit argument only to limit the syntactic context
46 search, not to limit the actual movement.
47
48 * cc-cmds.el (c-beginning-of-statement): Move by sentence
49 inside multiline strings, just like in comments. Also various
50 fixes to the paragraph and comment prefix recognition, block
51 comment ender handling etc.
52
532000-03-21 Martin Stjernholm <bug-cc-mode@gnu.org>
54
55 * cc-cmds.el (c-fill-paragraph): Take more care to preserve
56 the relative position of the point.
57
58 * cc-cmds.el (c-electric-continued-statement): New function to
59 use as abbrev hook to reindent for keywords such as "else"
60 that continues an earlier statement.
61
62 * cc-menus.el (cc-imenu-c++-generic-expression): Treat structs
63 like classes.
64
65 * cc-mode.el (c-mode, c++-mode, java-mode, objc-mode)
66 (pike-mode): Populate the default abbrev tables to reindent for
67 keywords such as "else" that can continue earlier statements.
68 Abbrev mode is therefore turned on by default now. (Note that
69 this doesn't apply to idl-mode, since IDL afaik doesn't have
70 statements at all.)
71
722000-03-21 Martin Stjernholm <bug-cc-mode@gnu.org>
73
74 * cc-engine.el (c-inside-bracelist-p): Fix for handling
75 bracelists where the declaration contains template arguments.
76
772000-03-21 Martin Stjernholm <bug-cc-mode@gnu.org>
78
79 * cc-cmds.el (c-comment-indent): Use
80 `c-get-syntactic-indentation' to correctly calculate the
81 syntactic indentation. Fixes bug with lineup functions that
82 return vectors.
83
84 * cc-engine.el (c-get-syntactic-indentation): Split the
85 indentation sum calculation from `c-indent-line' to a separate
86 function.
87
882000-03-21 Martin Stjernholm <bug-cc-mode@gnu.org>
89
90 * cc-cmds.el (c-beginning-of-statement, c-comment-indent):
91 Fixed places where it was assumed that preprocessor directives
92 have to start in column zero.
93
94 * cc-engine.el (c-beginning-of-member-init-list): Handle C++
95 template arguments after a class identifier properly.
96
97 * cc-engine.el (c-guess-basic-syntax): Treat initializer brace
98 lists for `new Foo[]' constructs in Java as expressions and
99 not top level definition brace lists on the top level, so that
100 they'll get indented consistently with the same type of
101 expression in a normal block.
102
1032000-03-21 Martin Stjernholm <bug-cc-mode@gnu.org>
104
105 * cc-cmds.el (c-fill-paragraph): The kludge that checks
106 whether the adaptive filling package fails to keep the comment
107 prefix is now kludged further to check for filladapt-mode
108 which doesn't have that problem. This is really icky, but it's
109 the only way that works with the current misfeatures/bugs in
110 both adaptive-fill-mode and filladapt-mode.
111
112 * cc-cmds.el (c-fill-paragraph): Made the way the paragraph
113 around point is recognized more robust.
114
1152000-03-21 Martin Stjernholm <bug-cc-mode@gnu.org>
116
117 * cc-cmds.el, cc-engine.el, cc-lobotomy.el (c-state-cache)
118 (c-in-literal-cache, c-auto-fill-prefix, c-lit-limits)
119 (c-lit-type): Fixed all internal variables used dynamically so
120 that they are always bound.
121
122 * cc-cmds.el, cc-engine.el: Improved recovery of syntactic
123 errors:
124
125 (c-indent-region): Fixed reporting of syntactic errors so that
126 the region is fully reindented even when an error occurs. The
127 last syntactic error is printed afterwards. Also cleanup up a
128 whole lot of code that tried to optimize indentation of whole
129 sexps but in reality accomplishes nothing.
130
131 (c-indent-sexp): Use c-indent-region.
132
133 (c-parsing-error): Changed this variable to hold the message
134 for any syntactic error that is discovered.
135
136 (c-parse-state): Search backward from point instead of the bod
137 position when the latter is invalid. This makes CC Mode
138 recover faster when there are unbalanced close braces.
139
140 (c-backward-to-start-of-if): Use c-parsing-error to report
141 dangling "else" clauses instead of throwing an error, and fall
142 back to a reasonable position.
143
144 (c-indent-line): Added argument to avoid reporting syntactic
145 errors.
146
147 (c-show-syntactic-information): Don't report any syntactic
148 errors.
149
1502000-03-21 Martin Stjernholm <bug-cc-mode@gnu.org>
151
152 * cc-cmds.el (c-beginning-of-statement): Fixed bugs with
153 paragraph recognition when moving by sentence in literals.
154
155 * cc-langs.el (c-Java-javadoc-paragraph-start): Modified
156 paragraph start regexp for javadoc to recognize javadoc markup
157 in general instead of a specific set of keywords, to be more
158 future-safe.
159
160 (c-Pike-pikedoc-paragraph-start)
161 (c-Pike-pikedoc-paragraph-separate): New regexps to recognize
162 pikedoc markup.
163
164 * cc-mode.el: Fixed initialization and use of
165 c-current-comment-prefix.
166
167 (pike-mode): Initialize paragraph settings pikedoc
168 recognition.
169
170 * cc-vars.el (c-default-style): Made a nicer Customize widget.
171
172 (c-comment-prefix-regexp): Made it possible to use an
173 association list on this to specify mode specific regexps.
174 The default value now use a special regexp in Pike mode to
175 recognize pikedoc markup.
176
177 (c-current-comment-prefix): New variable containing the actual
178 regexp from c-comment-prefix-regexp for the current buffer.
179
1802000-03-21 Martin Stjernholm <bug-cc-mode@gnu.org>
181
182 * cc-cmds.el (c-electric-brace): Fixed check for special brace
183 lists: We can't look at the syntax, since a brace list can get
184 recognized as a plain statement-cont.
185
186 * cc-engine.el (c-guess-basic-syntax): Fixed bug where a
187 special brace list opener broken over two lines got recognized
188 as a statement on the second line. Case 9A changed.
189
1902000-03-21 Martin Stjernholm <bug-cc-mode@gnu.org>
191
192 * cc-cmds.el (c-electric-brace): Fixed bug in c-state-cache
193 adjustment after line is reindented.
194
1952000-03-21 Martin Stjernholm <bug-cc-mode@gnu.org>
196
197 * cc-defs.el (c-point): Added optional argument for position
198 to use instead of the current point.
199
200 * cc-defs.el, cc-engine.el (c-add-class-syntax): Do not add
201 the in-expression block symbols when the construct starts at
202 boi, to avoid the extra level of indentation in that case.
203 Cases 4, 16A and 17E affected.
204
2052000-03-21 Martin Stjernholm <bug-cc-mode@gnu.org>
206
207 * cc-cmds.el: Use `indent-according-to-mode' instead of direct
208 calls to `c-indent-line', to adhere better to Emacs
209 conventions.
210
211 * cc-engine.el (c-indent-line): Use the syntax already bound
212 to `c-syntactic-context', if there is any.
213
2142000-03-21 Martin Stjernholm <bug-cc-mode@gnu.org>
215
216 * cc-engine.el (c-get-offset): Fixed bug where the indentation
217 wasn't added up correctly when a lineup function returned nil.
218
2192000-03-21 Martin Stjernholm <bug-cc-mode@gnu.org>
220
221 * cc-engine.el (c-collect-line-comments): Fixed bug where
222 empty lines were ignored when collecting line comments
223 backwards.
224
2252000-03-21 Martin Stjernholm <bug-cc-mode@gnu.org>
226
227 * cc-align.el (c-lineup-dont-change): Return an absolute
228 indentation column to work correctly in the case when several
229 syntactic elements are processed for the same line.
230
231 * cc-engine.el, cc-styles.el, cc-vars.el (c-evaluate-offset)
232 (c-get-offset, c-indent-line, c-valid-offset, c-read-offset)
233 (c-set-offset): Added absolute indentation column settings by
234 using the vector type.
235
236 * cc-mode.texi: Documented the new vector setting for offsets.
237
2382000-03-21 Martin Stjernholm <bug-cc-mode@gnu.org>
239
240 * cc-cmds.el, cc-vars.el (c-electric-paren, c-cleanup-list):
241 Implemented two new cleanups `space-before-funcall' and
242 `compact-empty-funcall'.
243
244 * cc-mode.texi: Documented the two new cleanups
245 space-before-funcall and compact-empty-funcall on
246 c-cleanup-list.
247
2482000-03-21 Martin Stjernholm <bug-cc-mode@gnu.org>
249
250 * cc-defs.el (c-paren-re, c-identifier-re): Two new macros for
251 helping building regexps.
252
253 * cc-engine.el (c-on-identifier): New function for detecting
254 identifiers. It takes keywords into account.
255
256 * cc-langs.el, cc-mode.el: Added regexps for complete keyword
257 lists. `c-keywords' is set to a regexp matching all keywords
258 in the current language.
259
2602000-03-21 Martin Stjernholm <bug-cc-mode@gnu.org>
261
262 * cc-engine.el (c-beginning-of-statement-1): Added '#' to the
263 list of characters to skip backwards over at the beginning of
264 a statement, since it can precede string literals in Pike.
265
2662000-03-21 Martin Stjernholm <bug-cc-mode@gnu.org>
267
268 * cc-cmds.el (c-guess-fill-prefix): Fixed bug with prefix
269 recognition when standing on the last line in a C++ comment
270 with nothing but whitespace after the prefix.
271
272 * cc-engine.el (c-backward-to-start-of-if): Fixed bug when
273 given no limit argument.
274
2752000-03-21 Martin Stjernholm <bug-cc-mode@gnu.org>
276
277 * cc-engine.el (c-inside-bracelist-p): Fixed brace list
278 recognition for the `[]= operator symbol in Pike.
279
2802000-03-21 Martin Stjernholm <bug-cc-mode@gnu.org>
281
282 * cc-bytecomp.el (cc-eval-when-compile): New macro that works
283 around a bug in `eval-when-compile' in the byte compiler.
284
285 * cc-engine.el (c-forward-token-1): Fixed bug with return
286 value when count is zero and there's no token start within the
287 limit.
288
289 (c-guess-basic-syntax): Don't add 'comment-intro to lines with
290 "prefix comments", i.e. comments which are followed by code on
291 the same line.
292
293 * cc-mode-19.el: Fixes so that checks that must be done at
294 compile time also are done then.
295
2962000-03-21 Martin Stjernholm <bug-cc-mode@gnu.org>
297
298 * cc-defs.el: Make sure cc-mode-19 is loaded both at compile
299 time and at runtime, and only when it's needed.
300
3012000-03-21 Martin Stjernholm <bug-cc-mode@gnu.org>
302
303 Major cleanup for less error prone and more warning free
304 compilation, including some fixes for bugs due to different
305 compilation orders. Thanks to Martin Buchholz for providing
306 the basis for all this.
307
308 * cc-bytecomp.el: New file that provides some byte compilation
309 features: It ensures that files always are loaded from the
310 current source directory during compilation, and it provides a
311 set of macros to turn off specific compiler warnings for
312 specific symbols. (It's not CC Mode specific in any way.)
313
314 Fixed a nearly acyclic dependency tree (both runtime and
315 compile-time) between all files.
316
317 * cc-defs.el: Separated all macros before the inline functions,
318 to ensure correct compilation.
319
320 * cc-defs.el, cc-engine.el: Moved c-beginning-of-macro to from
321 cc-defs.el to cc-engine.el and made it a function instead.
322
323 * cc-mode-19.el: Patch the byte compiler in Emacs 19 not to warn
324 about char-after.
325
326 * cc-vars.el: Cope even when there isn't a custom package
327 containing defcustom available.
328
329 * cc-make.el: Removed since it's no longer necessary.
330
331 README: Updated installation instructions.
332
3332000-03-21 Martin Stjernholm <bug-cc-mode@gnu.org>
334
335 * cc-cmds.el, cc-langs.el, cc-mode.el: Moved around things to
336 improve the modularity: Moved all mode init stuff from
337 cc-langs.el to cc-mode.el, including the keymap
338 initialization; cc-langs now only contains the various
339 variables for configuring the language syntax.
340
341 * cc-engine.el, cc-styles.el (c-evaluate-offset,
342 c-get-offset): Moved from cc-styles to cc-engine since file
343 dependency analysis suggests they belong there (which also
344 makes more sense). Thanks to Martin Buchholz for doing the
345 analysis.
346
3472000-03-21 Martin Stjernholm <bug-cc-mode@gnu.org>
348
349 * cc-cmds.el (c-fn-region-is-active-p): New function that
350 wraps the corresponding macro, for use in places that aren't
351 compiled. Thanks to Martin Buchholz for pointing out this.
352
353 * cc-langs.el (c-mode-menu): Use c-fn-region-is-active-p.
354
355 * cc-mode.el (c-prepare-bug-report-hooks): Hook variable to
356 add things to the bug report.
357
3582000-03-21 Martin Stjernholm <bug-cc-mode@gnu.org>
359
360 * cc-cmds.el (c-guess-fill-prefix): Fixed bug where the
361 returned prefix could contain a newline when the search for a
362 good prefix line failed.
363
3642000-03-21 Martin Stjernholm <bug-cc-mode@gnu.org>
365
366 * cc-cmds.el (c-toggle-auto-state, c-toggle-hungry-state)
367 (c-toggle-auto-hungry-state): Made the argument optional, as
368 the documentation says it is.
369
3702000-03-21 Martin Stjernholm <bug-cc-mode@gnu.org>
371
372 * cc-engine.el (c-guess-basic-syntax): Don't treat the Pike
373 multiline string syntax, #"...", as a cpp macro.
374
92001-03-21 Paul Eggert <eggert@twinsun.com> 3752001-03-21 Paul Eggert <eggert@twinsun.com>
10 376
11 * international/mule-cmds.el (set-locale-environment): Set 377 * international/mule-cmds.el (set-locale-environment): Set
diff --git a/lisp/progmodes/cc-align.el b/lisp/progmodes/cc-align.el
index 8bb69e387c8..c5c8786085c 100644
--- a/lisp/progmodes/cc-align.el
+++ b/lisp/progmodes/cc-align.el
@@ -1,6 +1,6 @@
1;;; cc-align.el --- custom indentation functions for CC Mode 1;;; cc-align.el --- custom indentation functions for CC Mode
2 2
3;; Copyright (C) 1985,87,92,93,94,95,96,97,98,99,2000 Free Software Foundation, Inc. 3;; Copyright (C) 1985,1987,1992-2001 Free Software Foundation, Inc.
4 4
5;; Authors: 2000- Martin Stjernholm 5;; Authors: 2000- Martin Stjernholm
6;; 1998-1999 Barry A. Warsaw and Martin Stjernholm 6;; 1998-1999 Barry A. Warsaw and Martin Stjernholm
@@ -25,19 +25,22 @@
25;; GNU General Public License for more details. 25;; GNU General Public License for more details.
26 26
27;; 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
28;; along with GNU Emacs; see the file COPYING. If not, write to the 28;; along with this program; see the file COPYING. If not, write to
29;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 29;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
30;; Boston, MA 02111-1307, USA. 30;; Boston, MA 02111-1307, USA.
31 31
32(eval-when-compile 32(eval-when-compile
33 (let ((load-path 33 (let ((load-path
34 (if (and (boundp 'byte-compile-current-file) 34 (if (and (boundp 'byte-compile-dest-file)
35 (stringp byte-compile-current-file)) 35 (stringp byte-compile-dest-file))
36 (cons (file-name-directory byte-compile-current-file) 36 (cons (file-name-directory byte-compile-dest-file) load-path)
37 load-path)
38 load-path))) 37 load-path)))
39 (load "cc-defs" nil t))) 38 (require 'cc-bytecomp)))
40(require 'cc-engine) 39
40(cc-require 'cc-defs)
41(cc-require 'cc-vars)
42(cc-require 'cc-langs)
43(cc-require 'cc-engine)
41 44
42 45
43;; Standard indentation line-ups 46;; Standard indentation line-ups
@@ -254,9 +257,9 @@ if (n > 0) if (n > 0)
254<--> c-basic-offset m+=n; n=0; 257<--> c-basic-offset m+=n; n=0;
255 } 258 }
256 259
257The block may be surrounded by any kind of parenthesis characters. 260The block may use any kind of parenthesis character. nil is returned
258nil is returned if the line doesn't start with a one line block, which 261if the line doesn't start with a one line block, which makes the
259makes the function usable in list expressions. 262function usable in list expressions.
260 263
261Work with: Almost all syntactic symbols, but most useful on *-open." 264Work with: Almost all syntactic symbols, but most useful on *-open."
262 (save-excursion 265 (save-excursion
@@ -279,9 +282,9 @@ int *foo[] = { int *foo[] = {
279 } 282 }
280 <--> c-basic-offset 283 <--> c-basic-offset
281 284
282The block may be surrounded by any kind of parenthesis characters. 285The block may use any kind of parenthesis character. nil is returned
283nil is returned if the line doesn't start with a multi line block, 286if the line doesn't start with a multi line block, which makes the
284which makes the function usable in list expressions. 287function usable in list expressions.
285 288
286Work with: Almost all syntactic symbols, but most useful on *-open." 289Work with: Almost all syntactic symbols, but most useful on *-open."
287 (save-excursion 290 (save-excursion
@@ -295,7 +298,7 @@ Work with: Almost all syntactic symbols, but most useful on *-open."
295 298
296(defun c-lineup-C-comments (langelem) 299(defun c-lineup-C-comments (langelem)
297 "Line up C block comment continuation lines. 300 "Line up C block comment continuation lines.
298Various heuristics are used to handle most of the common comment 301Various heuristics are used to handle many of the common comment
299styles. Some examples: 302styles. Some examples:
300 303
301/* /** /* /* text /* /** 304/* /** /* /* text /* /**
@@ -322,7 +325,7 @@ Works with: The `c' syntactic symbol."
322 (save-excursion 325 (save-excursion
323 (let* ((here (point)) 326 (let* ((here (point))
324 (prefixlen (progn (back-to-indentation) 327 (prefixlen (progn (back-to-indentation)
325 (if (looking-at c-comment-prefix-regexp) 328 (if (looking-at c-current-comment-prefix)
326 (- (match-end 0) (point)) 329 (- (match-end 0) (point))
327 0))) 330 0)))
328 (starterlen (save-excursion 331 (starterlen (save-excursion
@@ -369,11 +372,11 @@ Works with: The `c' syntactic symbol."
369 ;; line has a nonempty comment prefix, align with it. 372 ;; line has a nonempty comment prefix, align with it.
370 ;; Otherwise, align with the previous nonempty line, but 373 ;; Otherwise, align with the previous nonempty line, but
371 ;; align the comment ender with the starter. 374 ;; align the comment ender with the starter.
372 (when (or (not (looking-at c-comment-prefix-regexp)) 375 (when (or (not (looking-at c-current-comment-prefix))
373 (eq (match-beginning 0) (match-end 0))) 376 (eq (match-beginning 0) (match-end 0)))
374 (goto-char here) 377 (goto-char here)
375 (back-to-indentation) 378 (back-to-indentation)
376 (if (looking-at (concat "\\(" c-comment-prefix-regexp "\\)\\*/")) 379 (if (looking-at (concat "\\(" c-current-comment-prefix "\\)\\*/"))
377 (goto-char (cdr langelem)) 380 (goto-char (cdr langelem))
378 (while (and (zerop (forward-line -1)) 381 (while (and (zerop (forward-line -1))
379 (looking-at "^[ \t]*$"))) 382 (looking-at "^[ \t]*$")))
@@ -392,19 +395,13 @@ line, that alignment is preserved.
392Works with: comment-intro." 395Works with: comment-intro."
393 (save-excursion 396 (save-excursion
394 (back-to-indentation) 397 (back-to-indentation)
395 ;; this highly kludgiforous flag prevents the mapcar over 398 (let ((col (current-column)))
396 ;; c-syntactic-context from entering an infinite loop
397 (let ((recurse-prevention-flag (boundp 'recurse-prevention-flag))
398 (col (current-column)))
399 (cond 399 (cond
400 (recurse-prevention-flag 0)
401 ;; CASE 1: preserve aligned comments 400 ;; CASE 1: preserve aligned comments
402 ((save-excursion 401 ((save-excursion
403 (and (c-forward-comment -1) 402 (and (c-forward-comment -1)
404 (= col (current-column)))) 403 (= col (current-column))))
405 ;; we have to subtract out all other indentation 404 (vector col)) ; Return an absolute column.
406 (- col (apply '+ (mapcar 'c-get-offset
407 c-syntactic-context))))
408 ;; indent as specified by c-comment-only-line-offset 405 ;; indent as specified by c-comment-only-line-offset
409 ((not (bolp)) 406 ((not (bolp))
410 (or (car-safe c-comment-only-line-offset) 407 (or (car-safe c-comment-only-line-offset)
@@ -446,7 +443,10 @@ Works with: statement-cont."
446 (save-excursion 443 (save-excursion
447 (let ((equalp (save-excursion 444 (let ((equalp (save-excursion
448 (goto-char (c-point 'boi)) 445 (goto-char (c-point 'boi))
449 (skip-chars-forward "^=" (c-point 'eol)) 446 (let ((eol (c-point 'eol)))
447 (c-forward-token-1 0 t eol)
448 (while (and (not (eq (char-after) ?=))
449 (= (c-forward-token-1 1 t eol) 0))))
450 (and (eq (char-after) ?=) 450 (and (eq (char-after) ?=)
451 (- (point) (c-point 'boi))))) 451 (- (point) (c-point 'boi)))))
452 (langelem-col (c-langelem-col langelem)) 452 (langelem-col (c-langelem-col langelem))
@@ -616,7 +616,7 @@ inextern-lang, innamespace."
616Works with: Any syntactic symbol." 616Works with: Any syntactic symbol."
617 (save-excursion 617 (save-excursion
618 (back-to-indentation) 618 (back-to-indentation)
619 (- (current-column) (c-langelem-col langelem)))) 619 (vector (current-column))))
620 620
621 621
622(defun c-snug-do-while (syntax pos) 622(defun c-snug-do-while (syntax pos)
@@ -718,5 +718,5 @@ For other semicolon contexts, no determination is made."
718 nil))) 718 nil)))
719 719
720 720
721(provide 'cc-align) 721(cc-provide 'cc-align)
722;;; cc-align.el ends here 722;;; cc-align.el ends here
diff --git a/lisp/progmodes/cc-bytecomp.el b/lisp/progmodes/cc-bytecomp.el
new file mode 100644
index 00000000000..1d2e44edad1
--- /dev/null
+++ b/lisp/progmodes/cc-bytecomp.el
@@ -0,0 +1,290 @@
1;;; cc-bytecomp.el --- Compile time setup for proper compilation
2
3;; Copyright (C) 2000, 01 Free Software Foundation, Inc.
4
5;; Author: Martin Stjernholm
6;; Maintainer: bug-cc-mode@gnu.org
7;; Created: 15-Jul-2000
8;; Version: See cc-mode.el
9;; Keywords: c languages oop
10
11;; This program is free software; you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
13;; the Free Software Foundation; either version 2 of the License, or
14;; (at your option) any later version.
15
16;; This program is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
22;; along with this program; see the file COPYING. If not, write to
23;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24;; Boston, MA 02111-1307, USA.
25
26;;; Commentary:
27
28;; This file is used to ensure that the CC Mode files are correctly
29;; compiled regardless the environment (e.g. if an older CC Mode with
30;; outdated macros are loaded during compilation). It also provides
31;; features to defeat the compiler warnings for selected symbols.
32
33
34(defvar cc-bytecomp-unbound-variables nil)
35(defvar cc-bytecomp-original-functions nil)
36(defvar cc-bytecomp-original-properties nil)
37(defvar cc-bytecomp-load-depth 0)
38(defvar cc-bytecomp-loaded-files nil)
39(defvar cc-bytecomp-environment-set nil)
40
41(put 'cc-eval-when-compile 'lisp-indent-hook 0)
42(defmacro cc-eval-when-compile (&rest body)
43 "Like `progn', but evaluates the body at compile time.
44The result of the body appears to the compiler as a quoted constant.
45
46This variant works around what looks like a bug in
47`eval-when-compile': During byte compilation it byte compiles its
48contents before evaluating it. That can cause forms to be compiled in
49situations they aren't intended to be compiled. See cc-bytecomp.el
50for further discussion."
51 ;;
52 ;; Example: It's not possible to defsubst a primitive, e.g. the
53 ;; following will produce an error (in any emacs flavor), since
54 ;; `nthcdr' is a primitive function that's handled specially by the
55 ;; byte compiler and thus can't be redefined:
56 ;;
57 ;; (defsubst nthcdr (val) val)
58 ;;
59 ;; `defsubst', like `defmacro', needs to be evaluated at compile
60 ;; time, so this will produce an error during byte compilation.
61 ;;
62 ;; CC Mode occasionally needs to do things like this for cross-emacs
63 ;; compatibility (although we try to avoid it since it results in
64 ;; byte code that isn't compatible between emacsen). It therefore
65 ;; uses the following to conditionally do a `defsubst':
66 ;;
67 ;; (eval-when-compile
68 ;; (if (not (fboundp 'foo))
69 ;; (defsubst foo ...)))
70 ;;
71 ;; But `eval-when-compile' byte compiles its contents and _then_
72 ;; evaluates it (in all current emacs versions, up to and including
73 ;; Emacs 20.6 and XEmacs 21.1 as of this writing). So this will
74 ;; still produce an error, since the byte compiler will get to the
75 ;; defsubst anyway. That's arguably a bug because the point with
76 ;; `eval-when-compile' is that it should evaluate rather than
77 ;; compile its contents.
78 `(eval-when-compile (eval '(progn ,@body))))
79
80(defun cc-bytecomp-setup-environment ()
81 ;; Eval'ed during compilation to setup variables, functions etc
82 ;; declared with `cc-bytecomp-defvar' et al.
83 (if (= cc-bytecomp-load-depth 0)
84 (let (p)
85 (if cc-bytecomp-environment-set
86 (error "Byte compilation environment already set - \
87perhaps a `cc-bytecomp-restore-environment' is forgotten somewhere"))
88 (setq p cc-bytecomp-unbound-variables)
89 (while p
90 (if (not (boundp (car p)))
91 (progn
92 (eval `(defvar ,(car p)))
93 (set (car p) 'cc-bytecomp-ignore)))
94 (setq p (cdr p)))
95 (setq p cc-bytecomp-original-functions)
96 (while p
97 (let ((fun (car (car p)))
98 (temp-macro (car (cdr (car p)))))
99 (if temp-macro
100 (eval `(defmacro ,fun ,@temp-macro))
101 (fset fun 'cc-bytecomp-ignore)))
102 (setq p (cdr p)))
103 (setq p cc-bytecomp-original-properties)
104 (while p
105 (let ((sym (car (car (car p))))
106 (prop (cdr (car (car p))))
107 (tempdef (car (cdr (car p)))))
108 (put sym prop tempdef))
109 (setq p (cdr p)))
110 (setq cc-bytecomp-environment-set t))))
111
112(defun cc-bytecomp-restore-environment ()
113 ;; Eval'ed during compilation to restore variables, functions etc
114 ;; declared with `cc-bytecomp-defvar' et al.
115 (if (= cc-bytecomp-load-depth 0)
116 (let (p)
117 (setq p cc-bytecomp-unbound-variables)
118 (while p
119 (let ((var (car p)))
120 (if (and (boundp var)
121 (eq var 'cc-bytecomp-ignore))
122 (makunbound var)))
123 (setq p (cdr p)))
124 (setq p cc-bytecomp-original-functions)
125 (while p
126 (let ((fun (car (car p)))
127 (def (car (cdr (cdr (car p))))))
128 (if (and (fboundp fun)
129 (eq (symbol-function fun) 'cc-bytecomp-ignore))
130 (if (eq def 'unbound)
131 (fmakunbound fun)
132 (fset fun def))))
133 (setq p (cdr p)))
134 (setq p cc-bytecomp-original-properties)
135 (while p
136 (let ((sym (car (car (car p))))
137 (prop (cdr (car (car p))))
138 (tempdef (car (cdr (car p))))
139 (origdef (cdr (cdr (car p)))))
140 (if (eq (get sym prop) tempdef)
141 (put sym prop origdef)))
142 (setq p (cdr p)))
143 (setq cc-bytecomp-environment-set nil))))
144
145(defun cc-bytecomp-load (cc-part)
146 ;; Eval'ed during compilation to load a CC Mode file from the source
147 ;; directory (assuming it's the same as the compiled file
148 ;; destination dir).
149 (if (and (boundp 'byte-compile-dest-file)
150 (stringp byte-compile-dest-file))
151 (progn
152 (cc-bytecomp-restore-environment)
153 (let ((cc-bytecomp-load-depth (1+ cc-bytecomp-load-depth))
154 (load-path
155 (cons (file-name-directory byte-compile-dest-file)
156 load-path))
157 (cc-file (concat cc-part ".el")))
158 (if (member cc-file cc-bytecomp-loaded-files)
159 ()
160 (setq cc-bytecomp-loaded-files
161 (cons cc-file cc-bytecomp-loaded-files))
162 (load cc-file nil t t)))
163 (cc-bytecomp-setup-environment)
164 t)))
165
166(defmacro cc-require (cc-part)
167 "Force loading of the corresponding .el file in the current
168directory during compilation, but compile in a `require'. Don't use
169within `eval-when-compile'.
170
171Having cyclic cc-require's will result in infinite recursion. That's
172somewhat intentional."
173 `(progn
174 (cc-eval-when-compile (cc-bytecomp-load (symbol-name ,cc-part)))
175 (require ,cc-part)))
176
177(defmacro cc-provide (feature)
178 "A replacement for the `provide' form that restores the environment
179after the compilation. Don't use within `eval-when-compile'."
180 `(progn
181 (eval-when-compile (cc-bytecomp-restore-environment))
182 (provide ,feature)))
183
184(defmacro cc-load (cc-part)
185 "Force loading of the corresponding .el file in the current
186directory during compilation. Don't use outside `eval-when-compile'
187or `eval-and-compile'.
188
189Having cyclic cc-load's will result in infinite recursion. That's
190somewhat intentional."
191 `(or (and (featurep 'cc-bytecomp)
192 (cc-bytecomp-load ,cc-part))
193 (load ,cc-part nil t nil)))
194
195(defun cc-bytecomp-is-compiling ()
196 "Return non-nil if eval'ed during compilation. Don't use outside
197`eval-when-compile'."
198 (and (boundp 'byte-compile-dest-file)
199 (stringp byte-compile-dest-file)))
200
201(defmacro cc-bytecomp-defvar (var)
202 "Binds the symbol as a variable during compilation of the file,
203to silence the byte compiler. Don't use within `eval-when-compile'."
204 `(eval-when-compile
205 (if (boundp ',var)
206 nil
207 (if (not (memq ',var cc-bytecomp-unbound-variables))
208 (setq cc-bytecomp-unbound-variables
209 (cons ',var cc-bytecomp-unbound-variables)))
210 (if (and (cc-bytecomp-is-compiling)
211 (= cc-bytecomp-load-depth 0))
212 (progn
213 (defvar ,var)
214 (set ',var 'cc-bytecomp-ignore))))))
215
216(defmacro cc-bytecomp-defun (fun)
217 "Bind the symbol as a function during compilation of the file,
218to silence the byte compiler. Don't use within `eval-when-compile'."
219 `(eval-when-compile
220 (if (not (assq ',fun cc-bytecomp-original-functions))
221 (setq cc-bytecomp-original-functions
222 (cons (list ',fun
223 nil
224 (if (fboundp ',fun)
225 (symbol-function ',fun)
226 'unbound))
227 cc-bytecomp-original-functions)))
228 (if (and (cc-bytecomp-is-compiling)
229 (= cc-bytecomp-load-depth 0)
230 (not (fboundp ',fun)))
231 (fset ',fun 'cc-bytecomp-ignore))))
232
233(put 'cc-bytecomp-defmacro 'lisp-indent-function 'defun)
234(defmacro cc-bytecomp-defmacro (fun &rest temp-macro)
235 "Bind the symbol as a macro during compilation (and evaluation) of the
236file. Don't use outside `eval-when-compile'."
237 `(progn
238 (if (not (assq ',fun cc-bytecomp-original-functions))
239 (setq cc-bytecomp-original-functions
240 (cons (list ',fun
241 ',temp-macro
242 (if (fboundp ',fun)
243 (symbol-function ',fun)
244 'unbound))
245 cc-bytecomp-original-functions)))
246 (defmacro ,fun ,@temp-macro)))
247
248(defmacro cc-bytecomp-put (symbol propname value)
249 "Set a property on a symbol during compilation (and evaluation) of
250the file. Don't use outside `eval-when-compile'."
251 `(cc-eval-when-compile
252 (if (not (assoc (cons ,symbol ,propname) cc-bytecomp-original-properties))
253 (setq cc-bytecomp-original-properties
254 (cons (cons (cons ,symbol ,propname)
255 (cons ,value (get ,symbol ,propname)))
256 cc-bytecomp-original-properties)))
257 (put ,symbol ,propname ,value)))
258
259(defmacro cc-bytecomp-obsolete-var (symbol)
260 "Suppress warnings about that the given symbol is an obsolete variable.
261Don't use within `eval-when-compile'."
262 `(eval-when-compile
263 (if (get ',symbol 'byte-obsolete-variable)
264 (cc-bytecomp-put ',symbol 'byte-obsolete-variable nil))))
265
266(defun cc-bytecomp-ignore-obsolete (form)
267 ;; Wraps a call to `byte-compile-obsolete' that suppresses the warning.
268 (let ((byte-compile-warnings
269 (delq 'obsolete (append byte-compile-warnings nil))))
270 (byte-compile-obsolete form)))
271
272(defmacro cc-bytecomp-obsolete-fun (symbol)
273 "Suppress warnings about that the given symbol is an obsolete function.
274Don't use within `eval-when-compile'."
275 `(eval-when-compile
276 (if (eq (get ',symbol 'byte-compile) 'byte-compile-obsolete)
277 (cc-bytecomp-put ',symbol 'byte-compile
278 'cc-bytecomp-ignore-obsolete))))
279
280;; Override ourselves with a version loaded from source if we're
281;; compiling, like cc-require does for all the other files.
282(if (and (cc-bytecomp-is-compiling)
283 (= cc-bytecomp-load-depth 0))
284 (let ((load-path
285 (cons (file-name-directory byte-compile-dest-file) load-path))
286 (cc-bytecomp-load-depth 1))
287 (load "cc-bytecomp.el" nil t t)))
288
289
290(provide 'cc-bytecomp)
diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el
index cc5c3b9f9ce..ae905c08d86 100644
--- a/lisp/progmodes/cc-cmds.el
+++ b/lisp/progmodes/cc-cmds.el
@@ -1,6 +1,6 @@
1;;; cc-cmds.el --- user level commands for CC Mode 1;;; cc-cmds.el --- user level commands for CC Mode
2 2
3;; Copyright (C) 1985,87,92,93,94,95,96,97,98,99,2000 Free Software Foundation, Inc. 3;; Copyright (C) 1985,1987,1992-2001 Free Software Foundation, Inc.
4 4
5;; Authors: 2000- Martin Stjernholm 5;; Authors: 2000- Martin Stjernholm
6;; 1998-1999 Barry A. Warsaw and Martin Stjernholm 6;; 1998-1999 Barry A. Warsaw and Martin Stjernholm
@@ -25,19 +25,29 @@
25;; GNU General Public License for more details. 25;; GNU General Public License for more details.
26 26
27;; 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
28;; along with GNU Emacs; see the file COPYING. If not, write to the 28;; along with this program; see the file COPYING. If not, write to
29;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 29;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
30;; Boston, MA 02111-1307, USA. 30;; Boston, MA 02111-1307, USA.
31 31
32(eval-when-compile 32(eval-when-compile
33 (let ((load-path 33 (let ((load-path
34 (if (and (boundp 'byte-compile-current-file) 34 (if (and (boundp 'byte-compile-dest-file)
35 (stringp byte-compile-current-file)) 35 (stringp byte-compile-dest-file))
36 (cons (file-name-directory byte-compile-current-file) 36 (cons (file-name-directory byte-compile-dest-file) load-path)
37 load-path)
38 load-path))) 37 load-path)))
39 (load "cc-defs" nil t))) 38 (require 'cc-bytecomp)))
40(require 'cc-engine) 39
40(cc-require 'cc-defs)
41(cc-require 'cc-vars)
42(cc-require 'cc-langs)
43(cc-require 'cc-engine)
44
45;; Silence the compiler.
46(cc-bytecomp-defvar delete-key-deletes-forward) ; XEmacs 20+
47(cc-bytecomp-defun delete-forward-p) ; XEmacs 21+
48(cc-bytecomp-obsolete-fun insert-and-inherit) ; Marked obsolete in XEmacs 19
49(cc-bytecomp-defvar filladapt-mode) ; c-fill-paragraph contains a kludge
50 ; which looks at this.
41 51
42 52
43(defun c-calculate-state (arg prevstate) 53(defun c-calculate-state (arg prevstate)
@@ -50,10 +60,11 @@
50 (> arg 0))) 60 (> arg 0)))
51 61
52;; Auto-newline and hungry-delete 62;; Auto-newline and hungry-delete
53(defun c-toggle-auto-state (arg) 63(defun c-toggle-auto-state (&optional arg)
54 "Toggle auto-newline feature. 64 "Toggle auto-newline feature.
55Optional numeric ARG, if supplied turns on auto-newline when positive, 65Optional numeric ARG, if supplied, turns on auto-newline when
56turns it off when negative, and just toggles it when zero. 66positive, turns it off when negative, and just toggles it when zero or
67left out.
57 68
58When the auto-newline feature is enabled (as evidenced by the `/a' or 69When the auto-newline feature is enabled (as evidenced by the `/a' or
59`/ah' on the modeline after the mode name) newlines are automatically 70`/ah' on the modeline after the mode name) newlines are automatically
@@ -64,10 +75,11 @@ and colon."
64 (c-update-modeline) 75 (c-update-modeline)
65 (c-keep-region-active)) 76 (c-keep-region-active))
66 77
67(defun c-toggle-hungry-state (arg) 78(defun c-toggle-hungry-state (&optional arg)
68 "Toggle hungry-delete-key feature. 79 "Toggle hungry-delete-key feature.
69Optional numeric ARG, if supplied turns on hungry-delete when positive, 80Optional numeric ARG, if supplied, turns on hungry-delete when
70turns it off when negative, and just toggles it when zero. 81positive, turns it off when negative, and just toggles it when zero or
82left out.
71 83
72When the hungry-delete-key feature is enabled (as evidenced by the 84When the hungry-delete-key feature is enabled (as evidenced by the
73`/h' or `/ah' on the modeline after the mode name) the delete key 85`/h' or `/ah' on the modeline after the mode name) the delete key
@@ -77,11 +89,11 @@ gobbles all preceding whitespace in one fell swoop."
77 (c-update-modeline) 89 (c-update-modeline)
78 (c-keep-region-active)) 90 (c-keep-region-active))
79 91
80(defun c-toggle-auto-hungry-state (arg) 92(defun c-toggle-auto-hungry-state (&optional arg)
81 "Toggle auto-newline and hungry-delete-key features. 93 "Toggle auto-newline and hungry-delete-key features.
82Optional numeric ARG, if supplied turns on auto-newline and 94Optional numeric ARG, if supplied, turns on auto-newline and
83hungry-delete when positive, turns them off when negative, and just 95hungry-delete when positive, turns them off when negative, and just
84toggles them when zero. 96toggles them when zero or left out.
85 97
86See `c-toggle-auto-state' and `c-toggle-hungry-state' for details." 98See `c-toggle-auto-state' and `c-toggle-hungry-state' for details."
87 (interactive "P") 99 (interactive "P")
@@ -258,9 +270,6 @@ This function does various newline cleanups based on the value of
258 ;; Do not try to insert newlines around a special (Pike-style) 270 ;; Do not try to insert newlines around a special (Pike-style)
259 ;; brace list. 271 ;; brace list.
260 (if (and c-special-brace-lists 272 (if (and c-special-brace-lists
261 (c-intersect-lists '(brace-list-open brace-list-close
262 brace-list-intro brace-entry-open)
263 syntax)
264 (save-excursion 273 (save-excursion
265 (c-safe (if (= (char-before) ?{) 274 (c-safe (if (= (char-before) ?{)
266 (forward-char -1) 275 (forward-char -1)
@@ -278,9 +287,12 @@ This function does various newline cleanups based on the value of
278 (if (memq 'before newlines) 287 (if (memq 'before newlines)
279 ;; we leave the newline we've put in there before, 288 ;; we leave the newline we've put in there before,
280 ;; but we need to re-indent the line above 289 ;; but we need to re-indent the line above
281 (let ((pos (- (point-max) (point))) 290 (let (old-ind
291 (old-point-max (point-max))
292 (pos (- (point-max) (point)))
282 (here (point))) 293 (here (point)))
283 (forward-line -1) 294 (forward-line -1)
295 (setq old-ind (c-point 'boi))
284 (let ((c-state-cache (c-whack-state (point) c-state-cache))) 296 (let ((c-state-cache (c-whack-state (point) c-state-cache)))
285 ;; we may need to update the cache. this should 297 ;; we may need to update the cache. this should
286 ;; still be faster than recalculating the state 298 ;; still be faster than recalculating the state
@@ -296,9 +308,9 @@ This function does various newline cleanups based on the value of
296 (setq c-state-cache 308 (setq c-state-cache
297 (c-hack-state (point) 'open c-state-cache))))) 309 (c-hack-state (point) 'open c-state-cache)))))
298 (if c-syntactic-indentation 310 (if c-syntactic-indentation
299 (c-indent-line))) 311 (indent-according-to-mode)))
300 (setq c-state-cache (c-adjust-state (c-point 'bol) here 312 (setq c-state-cache (c-adjust-state (c-point 'bol) old-point-max
301 (- (point) (c-point 'bol)) 313 (- (c-point 'boi) old-ind)
302 c-state-cache)) 314 c-state-cache))
303 (goto-char (- (point-max) pos)) 315 (goto-char (- (point-max) pos))
304 ;; if the buffer has changed due to the indentation, we 316 ;; if the buffer has changed due to the indentation, we
@@ -327,17 +339,19 @@ This function does various newline cleanups based on the value of
327 (setq syntax (c-guess-basic-syntax)) 339 (setq syntax (c-guess-basic-syntax))
328 ;; gotta punt. this requires some horrible kludgery 340 ;; gotta punt. this requires some horrible kludgery
329 (beginning-of-line) 341 (beginning-of-line)
330 (makunbound 'c-state-cache) 342 (setq c-state-cache nil
331 (setq c-state-cache (c-parse-state) 343 c-state-cache (c-parse-state)
332 syntax nil)))) 344 syntax nil))))
333 ) 345 )
334 ;; now adjust the line's indentation. don't update the state 346 ;; Now adjust the line's indentation. Don't update the state
335 ;; cache since c-guess-basic-syntax isn't called when the 347 ;; cache since c-guess-basic-syntax isn't called when
336 ;; syntax is passed to c-indent-line 348 ;; c-syntactic-context is set.
337 (let* ((here (point))) 349 (let* ((old-ind (c-point 'boi))
338 (c-indent-line syntax) 350 (old-point-max (point-max))
339 (setq c-state-cache (c-adjust-state (c-point 'bol) here 351 (c-syntactic-context syntax))
340 (- (c-point 'boi) (c-point 'bol)) 352 (indent-according-to-mode)
353 (setq c-state-cache (c-adjust-state (c-point 'bol) old-point-max
354 (- (c-point 'boi) old-ind)
341 c-state-cache))) 355 c-state-cache)))
342 ;; Do all appropriate clean ups 356 ;; Do all appropriate clean ups
343 (let ((here (point)) 357 (let ((here (point))
@@ -396,7 +410,7 @@ This function does various newline cleanups based on the value of
396 (let* ((bufpos (- (point) 2)) 410 (let* ((bufpos (- (point) 2))
397 (which (if (eq (char-after bufpos) ?{) 'open 'close)) 411 (which (if (eq (char-after bufpos) ?{) 'open 'close))
398 (c-state-cache (c-hack-state bufpos which c-state-cache))) 412 (c-state-cache (c-hack-state bufpos which c-state-cache)))
399 (c-indent-line)))) 413 (indent-according-to-mode))))
400 ;; blink the paren 414 ;; blink the paren
401 (and (eq last-command-char ?\}) 415 (and (eq last-command-char ?\})
402 old-blink-paren 416 old-blink-paren
@@ -432,7 +446,7 @@ If a numeric ARG is supplied, point is inside a literal, or
432 (c-echo-syntactic-information-p nil)) 446 (c-echo-syntactic-information-p nil))
433 (self-insert-command (prefix-numeric-value arg)) 447 (self-insert-command (prefix-numeric-value arg))
434 (if indentp 448 (if indentp
435 (c-indent-line)))) 449 (indent-according-to-mode))))
436 450
437(defun c-electric-star (arg) 451(defun c-electric-star (arg)
438 "Insert a star character. 452 "Insert a star character.
@@ -455,9 +469,8 @@ If a numeric ARG is supplied, point is inside a literal, or
455 (forward-char -1)) 469 (forward-char -1))
456 (skip-chars-backward " \t") 470 (skip-chars-backward " \t")
457 (bolp))) 471 (bolp)))
458 ;; shut this up 472 (let (c-echo-syntactic-information-p) ; shut this up
459 (let (c-echo-syntactic-information-p) 473 (indent-according-to-mode))
460 (c-indent-line))
461 )) 474 ))
462 475
463(defun c-electric-semi&comma (arg) 476(defun c-electric-semi&comma (arg)
@@ -490,7 +503,7 @@ following brace lists and semicolons following defuns."
490 ;; turned on 503 ;; turned on
491 (if (not c-auto-newline) 504 (if (not c-auto-newline)
492 (if c-syntactic-indentation 505 (if c-syntactic-indentation
493 (c-indent-line)) 506 (indent-according-to-mode))
494 ;; clean ups 507 ;; clean ups
495 (let ((pos (- (point-max) (point)))) 508 (let ((pos (- (point-max) (point))))
496 (if (and (or (and 509 (if (and (or (and
@@ -509,7 +522,7 @@ following brace lists and semicolons following defuns."
509 (goto-char (- (point-max) pos))) 522 (goto-char (- (point-max) pos)))
510 ;; re-indent line 523 ;; re-indent line
511 (if c-syntactic-indentation 524 (if c-syntactic-indentation
512 (c-indent-line)) 525 (indent-according-to-mode))
513 ;; check to see if a newline should be added 526 ;; check to see if a newline should be added
514 (let ((criteria c-hanging-semi&comma-criteria) 527 (let ((criteria c-hanging-semi&comma-criteria)
515 answer add-newline-p) 528 answer add-newline-p)
@@ -524,7 +537,7 @@ following brace lists and semicolons following defuns."
524 )) 537 ))
525 (if add-newline-p 538 (if add-newline-p
526 (progn (newline) 539 (progn (newline)
527 (c-indent-line))) 540 (indent-according-to-mode)))
528 ))))) 541 )))))
529 542
530(defun c-electric-colon (arg) 543(defun c-electric-colon (arg)
@@ -587,7 +600,8 @@ value of `c-cleanup-list'."
587 c-hanging-colons-alist)))) 600 c-hanging-colons-alist))))
588 ;; indent the current line if it's done syntactically. 601 ;; indent the current line if it's done syntactically.
589 (if c-syntactic-indentation 602 (if c-syntactic-indentation
590 (c-indent-line syntax)) 603 (let ((c-syntactic-context syntax))
604 (indent-according-to-mode)))
591 ;; does a newline go before the colon? Watch out for already 605 ;; does a newline go before the colon? Watch out for already
592 ;; non-hung colons. However, we don't unhang them because that 606 ;; non-hung colons. However, we don't unhang them because that
593 ;; would be a cleanup (and anti-social). 607 ;; would be a cleanup (and anti-social).
@@ -599,14 +613,14 @@ value of `c-cleanup-list'."
599 (let ((pos (- (point-max) (point)))) 613 (let ((pos (- (point-max) (point))))
600 (forward-char -1) 614 (forward-char -1)
601 (newline) 615 (newline)
602 (c-indent-line) 616 (indent-according-to-mode)
603 (goto-char (- (point-max) pos)))) 617 (goto-char (- (point-max) pos))))
604 ;; does a newline go after the colon? 618 ;; does a newline go after the colon?
605 (if (and (memq 'after (cdr-safe newlines)) 619 (if (and (memq 'after (cdr-safe newlines))
606 (not is-scope-op)) 620 (not is-scope-op))
607 (progn 621 (progn
608 (newline) 622 (newline)
609 (c-indent-line))) 623 (indent-according-to-mode)))
610 ))) 624 )))
611 625
612(defun c-electric-lt-gt (arg) 626(defun c-electric-lt-gt (arg)
@@ -625,14 +639,13 @@ will not be re-indented."
625 (c-echo-syntactic-information-p nil)) 639 (c-echo-syntactic-information-p nil))
626 (self-insert-command (prefix-numeric-value arg)) 640 (self-insert-command (prefix-numeric-value arg))
627 (if indentp 641 (if indentp
628 (c-indent-line)))) 642 (indent-according-to-mode))))
629 643
630(defun c-electric-paren (arg) 644(defun c-electric-paren (arg)
631 "Insert a parenthesis. 645 "Insert a parenthesis.
632 646
633If the auto-newline feature is turned on, as evidenced by the \"/a\" 647Some newline cleanups are done if appropriate; see the variable
634or \"/ah\" string on the mode line, some newline cleanups are done if 648`c-cleanup-list'.
635appropriate; see the variable `c-cleanup-list'.
636 649
637Also, the line is re-indented unless a numeric ARG is supplied, there 650Also, the line is re-indented unless a numeric ARG is supplied, there
638are non-whitespace characters present on the line after the 651are non-whitespace characters present on the line after the
@@ -642,7 +655,6 @@ parenthesis, the parenthesis is inserted inside a literal, or
642 (let (;; shut this up 655 (let (;; shut this up
643 (c-echo-syntactic-information-p nil)) 656 (c-echo-syntactic-information-p nil))
644 (if (or arg 657 (if (or arg
645 (not (looking-at "[ \t]*$"))
646 (c-in-literal (c-point 'bod))) 658 (c-in-literal (c-point 'bod)))
647 (self-insert-command (prefix-numeric-value arg)) 659 (self-insert-command (prefix-numeric-value arg))
648 ;; do some special stuff with the character 660 ;; do some special stuff with the character
@@ -652,43 +664,86 @@ parenthesis, the parenthesis is inserted inside a literal, or
652 (old-blink-paren blink-paren-function) 664 (old-blink-paren blink-paren-function)
653 blink-paren-function) 665 blink-paren-function)
654 (self-insert-command (prefix-numeric-value arg)) 666 (self-insert-command (prefix-numeric-value arg))
655 (if c-syntactic-indentation 667 (when (looking-at "[ \t]*$")
656 (c-indent-line)) 668 (if c-syntactic-indentation
657 (when c-auto-newline 669 (indent-according-to-mode))
658 ;; Do all appropriate clean ups 670 (when c-auto-newline
659 (let ((here (point)) 671 ;; Do all appropriate clean ups
660 (pos (- (point-max) (point))) 672 (let ((here (point))
661 mbeg mend) 673 (pos (- (point-max) (point)))
662 ;; clean up brace-elseif-brace 674 mbeg mend)
663 (if (and (memq 'brace-elseif-brace c-cleanup-list) 675 ;; clean up brace-elseif-brace
664 (eq last-command-char ?\() 676 (if (and (memq 'brace-elseif-brace c-cleanup-list)
665 (re-search-backward "}[ \t\n]*else[ \t\n]+if[ \t\n]*(" 677 (eq last-command-char ?\()
666 nil t) 678 (re-search-backward "}[ \t\n]*else[ \t\n]+if[ \t\n]*("
667 (save-excursion 679 nil t)
668 (setq mbeg (match-beginning 0) 680 (save-excursion
669 mend (match-end 0)) 681 (setq mbeg (match-beginning 0)
670 (= mend here)) 682 mend (match-end 0))
671 (not (c-in-literal))) 683 (= mend here))
672 (progn 684 (not (c-in-literal)))
673 (delete-region mbeg mend) 685 (progn
674 (insert "} else if ("))) 686 (delete-region mbeg mend)
675 ;; clean up brace-catch-brace 687 (insert "} else if (")))
676 (if (and (memq 'brace-catch-brace c-cleanup-list) 688 ;; clean up brace-catch-brace
677 (eq last-command-char ?\() 689 (if (and (memq 'brace-catch-brace c-cleanup-list)
678 (re-search-backward "}[ \t\n]*catch[ \t\n]*(" nil t) 690 (eq last-command-char ?\()
679 (save-excursion 691 (re-search-backward "}[ \t\n]*catch[ \t\n]*(" nil t)
680 (setq mbeg (match-beginning 0) 692 (save-excursion
681 mend (match-end 0)) 693 (setq mbeg (match-beginning 0)
682 (= mend here)) 694 mend (match-end 0))
683 (not (c-in-literal))) 695 (= mend here))
684 (progn 696 (not (c-in-literal)))
685 (delete-region mbeg mend) 697 (progn
686 (insert "} catch ("))) 698 (delete-region mbeg mend)
687 (goto-char (- (point-max) pos)) 699 (insert "} catch (")))
688 )) 700 (goto-char (- (point-max) pos))
701 )))
702 (let (beg (end (1- (point))))
703 (cond ((and (memq 'space-before-funcall c-cleanup-list)
704 (eq last-command-char ?\()
705 (save-excursion
706 (backward-char)
707 (skip-chars-backward " \t")
708 (setq beg (point))
709 (c-on-identifier)))
710 (save-excursion
711 (delete-region beg end)
712 (goto-char beg)
713 (insert " ")))
714 ((and (memq 'compact-empty-funcall c-cleanup-list)
715 (eq last-command-char ?\))
716 (save-excursion
717 (c-safe (backward-char 2))
718 (when (looking-at "()")
719 (setq end (point))
720 (skip-chars-backward " \t")
721 (setq beg (point))
722 (c-on-identifier))))
723 (delete-region beg end))))
689 (if old-blink-paren 724 (if old-blink-paren
690 (funcall old-blink-paren)))))) 725 (funcall old-blink-paren))))))
691 726
727(defun c-electric-continued-statement ()
728 "Reindent the current line if appropriate.
729
730This function is used to reindent the line after a keyword which
731continues an earlier statement is typed, e.g. an \"else\" or the
732\"while\" in a do-while block.
733
734The line is reindented if there is nothing but whitespace before the
735keyword on the line, the keyword is not inserted inside a literal, and
736`c-syntactic-indentation' is non-nil."
737 (let (;; shut this up
738 (c-echo-syntactic-information-p nil))
739 (when (and c-syntactic-indentation
740 (not (eq last-command-char ?_))
741 (= (save-excursion
742 (skip-syntax-backward "w")
743 (point))
744 (c-point 'boi))
745 (not (c-in-literal (c-point 'bod))))
746 (indent-according-to-mode))))
692 747
693 748
694;; better movement routines for ThisStyleOfVariablesCommonInCPlusPlus 749;; better movement routines for ThisStyleOfVariablesCommonInCPlusPlus
@@ -792,14 +847,13 @@ the open-parenthesis that starts a defun; see `beginning-of-defun'."
792With prefix arg, go back N - 1 statements. If already at the 847With prefix arg, go back N - 1 statements. If already at the
793beginning of a statement then go to the beginning of the closest 848beginning of a statement then go to the beginning of the closest
794preceding one, moving into nested blocks if necessary (use 849preceding one, moving into nested blocks if necessary (use
795\\[backward-sexp] to skip over a block). If within a comment, or next 850\\[backward-sexp] to skip over a block). If within or next to a
796to a comment (only whitespace between), move by sentences instead of 851comment or multiline string, move by sentences instead of statements.
797statements.
798 852
799When called from a program, this function takes 3 optional args: the 853When called from a program, this function takes 3 optional args: the
800repetition count, a buffer position limit which is the farthest back 854repetition count, a buffer position limit which is the farthest back
801to search, and a flag saying whether to do sentence motion when in a 855to search for the syntactic context, and a flag saying whether to do
802comment." 856sentence motion in or near comments and multiline strings."
803 (interactive (list (prefix-numeric-value current-prefix-arg) 857 (interactive (list (prefix-numeric-value current-prefix-arg)
804 nil t)) 858 nil t))
805 (let* ((count (or count 1)) 859 (let* ((count (or count 1))
@@ -812,48 +866,85 @@ comment."
812 (save-excursion 866 (save-excursion
813 ;; Find the comment next to point if we're not in one. 867 ;; Find the comment next to point if we're not in one.
814 (if (> count 0) 868 (if (> count 0)
815 (setq range (if (c-forward-comment -1) 869 (if (c-forward-comment -1)
816 (cons (point) 870 (setq range (cons (point)
817 (progn (c-forward-comment 1) (point))))) 871 (progn (c-forward-comment 1) (point))))
818 (skip-chars-forward " \t\n") 872 (skip-chars-backward " \t\n\r\f")
819 (setq range (point)) 873 (setq range (point))
820 (setq range (if (c-forward-comment 1) 874 (setq range
821 (cons range (point)) 875 (if (eq (char-before) ?\")
822 nil))) 876 (c-safe (c-backward-sexp 1)
877 (cons (point) range)))))
878 ;; skip-syntax-* doesn't count \n as whitespace..
879 (skip-chars-forward " \t\n\r\f")
880 (if (eq (char-after) ?\")
881 (setq range (cons (point)
882 (progn
883 (c-forward-sexp 1)
884 (point))))
885 (setq range (point))
886 (setq range (if (c-forward-comment 1)
887 (cons range (point))
888 nil))))
823 (setq range (c-collect-line-comments range)))) 889 (setq range (c-collect-line-comments range))))
824 (if (and (< count 0) (= here (point-max))) 890 (if (and (< count 0) (= here (point-max)))
825 ;; Special case because eob might be in a literal. 891 ;; Special case because eob might be in a literal.
826 (setq range nil)) 892 (setq range nil))
827 (if range 893 (if range
828 (if (and sentence-flag 894 (if (and sentence-flag
829 (/= (char-syntax (char-after (car range))) ?\")) 895 (or (/= (char-syntax (char-after (car range))) ?\")
896 ;; Only visit a string if it spans more than one line.
897 (save-excursion
898 (goto-char (car range))
899 (skip-chars-forward "^\n" (cdr range))
900 (< (point) (cdr range)))))
830 (let* ((lit-type (c-literal-type range)) 901 (let* ((lit-type (c-literal-type range))
831 (beg (save-excursion 902 (line-prefix (concat "[ \t]*\\("
832 (goto-char (car range)) 903 c-current-comment-prefix
833 (looking-at (if (eq lit-type 'c) 904 "\\)[ \t]*"))
834 comment-start-skip 905 (beg (if (eq lit-type 'string)
835 (concat "\\(" 906 (1+ (car range))
836 c-comment-prefix-regexp 907 (save-excursion
837 "\\)[ \t]*"))) 908 (goto-char (car range))
838 (goto-char (match-end 0)) 909 (max (progn
839 (point))) 910 (looking-at comment-start-skip)
840 (end (save-excursion 911 (match-end 0))
841 (goto-char (- (cdr range) 912 (progn
842 (if (eq lit-type 'c) 2 1))) 913 (looking-at line-prefix)
843 (point)))) 914 (match-end 0))))))
844 ;; move by sentence, but not past the limit of the literal 915 (end (- (cdr range) (if (eq lit-type 'c) 2 1)))
916 (beg-of-para (if (eq lit-type 'string)
917 (lambda ())
918 (lambda ()
919 (beginning-of-line)
920 (if (looking-at line-prefix)
921 (goto-char (match-end 0)))))))
845 (save-restriction 922 (save-restriction
846 (narrow-to-region beg end) 923 ;; Move by sentence, but not past the limit of the
924 ;; literal, narrowed to the appropriate
925 ;; paragraph(s).
926 (narrow-to-region (save-excursion
927 (let ((pos (min here end)))
928 (goto-char pos)
929 (forward-paragraph -1)
930 (if (looking-at paragraph-separate)
931 (forward-line))
932 (when (> (point) beg)
933 (funcall beg-of-para)
934 (when (>= (point) pos)
935 (forward-paragraph -2)
936 (funcall beg-of-para)))
937 (max (point) beg)))
938 end)
847 (c-safe (forward-sentence (if (< count 0) 1 -1))) 939 (c-safe (forward-sentence (if (< count 0) 1 -1)))
848 (if (and (memq lit-type '(c c++)) 940 (if (and (memq lit-type '(c c++))
849 ;; Check if we stopped due to a comment 941 ;; Check if we stopped due to a comment
850 ;; prefix and not a sentence end. 942 ;; prefix and not a sentence end.
851 (/= (point) beg) 943 (/= (point) (point-min))
944 (/= (point) (point-max))
852 (save-excursion 945 (save-excursion
853 (beginning-of-line) 946 (beginning-of-line)
854 (looking-at (concat "[ \t]*\\(" 947 (looking-at line-prefix))
855 c-comment-prefix-regexp
856 "\\)[ \t]*")))
857 (>= (point) (match-beginning 0)) 948 (>= (point) (match-beginning 0))
858 (/= (match-beginning 1) (match-end 1)) 949 (/= (match-beginning 1) (match-end 1))
859 (or (< (point) (match-end 0)) 950 (or (< (point) (match-end 0))
@@ -883,16 +974,22 @@ comment."
883 ;; comment ender, stop before it. Stop after 974 ;; comment ender, stop before it. Stop after
884 ;; the ender if there's either nothing or 975 ;; the ender if there's either nothing or
885 ;; newlines between. 976 ;; newlines between.
886 (when (and (eq lit-type 'c) (eq (point) end)) 977 (when (and (eq lit-type 'c)
978 (eq (point) (point-max)))
887 (widen) 979 (widen)
888 (skip-chars-backward " \t") 980 (when (or (= (skip-chars-backward " \t") 0)
889 (when (or (eq (point) end) (bolp)) 981 (eq (point) (point-max))
982 (bolp))
890 (goto-char (cdr range))))) 983 (goto-char (cdr range)))))
891 (when (and (eq (point) beg) (looking-at "[ \t]*$")) 984 (when (and (eq (point) (point-min))
985 (looking-at "[ \t]*$"))
892 ;; Stop before instead of after the comment 986 ;; Stop before instead of after the comment
893 ;; starter if nothing follows it. 987 ;; starter if nothing follows it.
894 (widen) 988 (widen)
895 (goto-char (car range)))))) 989 (goto-char (car range))
990 (if (and (eq lit-type 'string) (/= (point) here))
991 (setq count (1+ count)
992 range nil))))))
896 ;; See if we should escape the literal. 993 ;; See if we should escape the literal.
897 (if (> count 0) 994 (if (> count 0)
898 (if (< (point) here) 995 (if (< (point) here)
@@ -915,15 +1012,19 @@ comment."
915 ;; Stop before `{' and after `;', `{', `}' and `};' 1012 ;; Stop before `{' and after `;', `{', `}' and `};'
916 ;; when not followed by `}' or `)', but on the other 1013 ;; when not followed by `}' or `)', but on the other
917 ;; side of the syntactic ws. Move by sexps and move 1014 ;; side of the syntactic ws. Move by sexps and move
918 ;; into parens. Also stop before `#' when it's first 1015 ;; into parens. Also stop before `#' when it's at boi
919 ;; on a line. 1016 ;; on a line.
920 (let ((comment-pos (not sentence-flag)) 1017 (let ((literal-pos (not sentence-flag))
921 (large-enough (- (point-max))) 1018 (large-enough (- (point-max)))
922 last last-below-line) 1019 last last-below-line)
923 (catch 'done 1020 (catch 'done
924 (while t 1021 (while t
925 (setq last (point)) 1022 (setq last (point))
926 (when (and (looking-at "{\\|^#") (/= here last)) 1023 (when (and (or (eq (char-after) ?\{)
1024 (and (eq (char-after) ?#)
1025 (eq (point) (c-point 'boi)))
1026 )
1027 (/= here last))
927 (unless (and c-special-brace-lists 1028 (unless (and c-special-brace-lists
928 (eq (char-after) ?{) 1029 (eq (char-after) ?{)
929 (c-looking-at-special-brace-list)) 1030 (c-looking-at-special-brace-list))
@@ -932,13 +1033,13 @@ comment."
932 (not (eq last-below-line here))) 1033 (not (eq last-below-line here)))
933 (goto-char last-below-line)) 1034 (goto-char last-below-line))
934 (throw 'done t))) 1035 (throw 'done t)))
935 (if comment-pos 1036 (if literal-pos
936 (c-forward-comment large-enough) 1037 (c-forward-comment large-enough)
937 (when (c-forward-comment -1) 1038 (when (c-forward-comment -1)
938 ;; Record position of first comment. 1039 ;; Record position of first comment.
939 (save-excursion 1040 (save-excursion
940 (c-forward-comment 1) 1041 (c-forward-comment 1)
941 (setq comment-pos (point))) 1042 (setq literal-pos (point)))
942 (c-forward-comment large-enough))) 1043 (c-forward-comment large-enough)))
943 (unless last-below-line 1044 (unless last-below-line
944 (if (save-excursion 1045 (if (save-excursion
@@ -963,40 +1064,48 @@ comment."
963 (goto-char last) 1064 (goto-char last)
964 (throw 'done t)))) 1065 (throw 'done t))))
965 ((= (char-syntax (char-after)) ?\") 1066 ((= (char-syntax (char-after)) ?\")
966 (forward-char) 1067 (let ((end (point)))
967 (c-backward-sexp)) 1068 (forward-char)
1069 (c-backward-sexp)
1070 (save-excursion
1071 (skip-chars-forward "^\n" end)
1072 (when (< (point) end)
1073 ;; Break at multiline string.
1074 (setq literal-pos (1+ end))
1075 (throw 'done t)))))
968 (t (skip-syntax-backward "w_")) ; Speedup only. 1076 (t (skip-syntax-backward "w_")) ; Speedup only.
969 ))) 1077 )))
970 (if (and (numberp comment-pos) 1078 (if (and (numberp literal-pos)
971 (< (point) comment-pos)) 1079 (< (point) literal-pos))
972 ;; We jumped over a comment that should be investigated. 1080 ;; We jumped over a comment or string that
973 (goto-char comment-pos) 1081 ;; should be investigated.
1082 (goto-char literal-pos)
974 (setq count (1- count)))) 1083 (setq count (1- count))))
975 (error 1084 (error
976 (goto-char (point-min)) 1085 (goto-char (point-min))
977 (setq count 0))) 1086 (setq count 0)))
978 (condition-case nil 1087 (condition-case nil
979 ;; Stop before `{', `}', and `#' when it's first on a 1088 ;; Stop before `{', `}', and `#' when it's at boi on a
980 ;; line, but on the other side of the syntactic ws, and 1089 ;; line, but on the other side of the syntactic ws, and
981 ;; after `;', `}' and `};'. Only stop before `{' if at 1090 ;; after `;', `}' and `};'. Only stop before `{' if at
982 ;; top level or inside braces, though. Move by sexps 1091 ;; top level or inside braces, though. Move by sexps
983 ;; and move into parens. Also stop at eol of lines 1092 ;; and move into parens. Also stop at eol of lines
984 ;; starting with `#'. 1093 ;; with `#' at the boi.
985 (let ((comment-pos (not sentence-flag)) 1094 (let ((literal-pos (not sentence-flag))
986 (large-enough (point-max)) 1095 (large-enough (point-max))
987 last) 1096 last)
988 (catch 'done 1097 (catch 'done
989 (while t 1098 (while t
990 (setq last (point)) 1099 (setq last (point))
991 (if comment-pos 1100 (if literal-pos
992 (c-forward-comment large-enough) 1101 (c-forward-comment large-enough)
993 (if (progn 1102 (if (progn
994 (skip-chars-forward " \t\n\r\f") 1103 (skip-chars-forward " \t\n\r\f")
995 ;; Record position of first comment. 1104 ;; Record position of first comment.
996 (setq comment-pos (point)) 1105 (setq literal-pos (point))
997 (c-forward-comment 1)) 1106 (c-forward-comment 1))
998 (c-forward-comment large-enough) 1107 (c-forward-comment large-enough)
999 (setq comment-pos nil))) 1108 (setq literal-pos nil)))
1000 (cond ((and (eq (char-after) ?{) 1109 (cond ((and (eq (char-after) ?{)
1001 (not (and c-special-brace-lists 1110 (not (and c-special-brace-lists
1002 (c-looking-at-special-brace-list))) 1111 (c-looking-at-special-brace-list)))
@@ -1017,7 +1126,8 @@ comment."
1017 (/= here last)) 1126 (/= here last))
1018 (goto-char last) 1127 (goto-char last)
1019 (throw 'done t)) 1128 (throw 'done t))
1020 ((looking-at "^#") 1129 ((and (eq (char-after) ?#)
1130 (= (point) (c-point 'boi)))
1021 (if (= here last) 1131 (if (= here last)
1022 (or (re-search-forward "\\(^\\|[^\\]\\)$" nil t) 1132 (or (re-search-forward "\\(^\\|[^\\]\\)$" nil t)
1023 (goto-char (point-max))) 1133 (goto-char (point-max)))
@@ -1027,15 +1137,22 @@ comment."
1027 (goto-char (match-end 0)) 1137 (goto-char (match-end 0))
1028 (throw 'done t)) 1138 (throw 'done t))
1029 ((= (char-syntax (char-after)) ?\") 1139 ((= (char-syntax (char-after)) ?\")
1030 (c-forward-sexp)) 1140 (let ((beg (point)))
1141 (c-forward-sexp)
1142 (save-excursion
1143 (skip-chars-backward "^\n" beg)
1144 (when (> (point) beg)
1145 ;; Break at multiline string.
1146 (setq literal-pos beg)
1147 (throw 'done t)))))
1031 (t 1148 (t
1032 (forward-char 1) 1149 (forward-char 1)
1033 (skip-syntax-forward "w_")) ; Speedup only. 1150 (skip-syntax-forward "w_")) ; Speedup only.
1034 ))) 1151 )))
1035 (if (and (numberp comment-pos) 1152 (if (and (numberp literal-pos)
1036 (> (point) comment-pos)) 1153 (> (point) literal-pos))
1037 ;; We jumped over a comment that should be investigated. 1154 ;; We jumped over a comment that should be investigated.
1038 (goto-char comment-pos) 1155 (goto-char literal-pos)
1039 (setq count (1+ count)))) 1156 (setq count (1+ count))))
1040 (error 1157 (error
1041 (goto-char (point-max)) 1158 (goto-char (point-max))
@@ -1044,23 +1161,20 @@ comment."
1044 ;; If we haven't moved we're near a buffer limit. 1161 ;; If we haven't moved we're near a buffer limit.
1045 (when (and (not (zerop count)) (= (point) here)) 1162 (when (and (not (zerop count)) (= (point) here))
1046 (goto-char (if (> count 0) (point-min) (point-max))) 1163 (goto-char (if (> count 0) (point-min) (point-max)))
1047 (setq count 0))) 1164 (setq count 0))))
1048 ;; its possible we've been left up-buf of lim
1049 (if lim (goto-char (max (point) lim))))
1050 (c-keep-region-active)) 1165 (c-keep-region-active))
1051 1166
1052(defun c-end-of-statement (&optional count lim sentence-flag) 1167(defun c-end-of-statement (&optional count lim sentence-flag)
1053 "Go to the end of the innermost C statement. 1168 "Go to the end of the innermost C statement.
1054With prefix arg, go forward N - 1 statements. Move forward to the end 1169With prefix arg, go forward N - 1 statements. Move forward to the end
1055of the next statement if already at end, and move into nested blocks 1170of the next statement if already at end, and move into nested blocks
1056\(use \\[forward-sexp] to skip over a block). If within a comment, or 1171\(use \\[forward-sexp] to skip over a block). If within or next to a
1057next to a comment (only whitespace between), move by sentences instead 1172comment or multiline string, move by sentences instead of statements.
1058of statements.
1059 1173
1060When called from a program, this function takes 3 optional args: the 1174When called from a program, this function takes 3 optional args: the
1061repetition count, a buffer position limit which is the farthest back 1175repetition count, a buffer position limit which is the farthest back
1062to search, and a flag saying whether to do sentence motion when in a 1176to search for the syntactic context, and a flag saying whether to do
1063comment." 1177sentence motion in or near comments and multiline strings."
1064 (interactive (list (prefix-numeric-value current-prefix-arg) 1178 (interactive (list (prefix-numeric-value current-prefix-arg)
1065 nil t)) 1179 nil t))
1066 (c-beginning-of-statement (- (or count 1)) lim sentence-flag) 1180 (c-beginning-of-statement (- (or count 1)) lim sentence-flag)
@@ -1107,8 +1221,8 @@ comment."
1107 (search-forward "}") 1221 (search-forward "}")
1108 (1+ (current-column))) 1222 (1+ (current-column)))
1109 ;; CASE 2: 2 spaces after #endif 1223 ;; CASE 2: 2 spaces after #endif
1110 ((or (looking-at "^#[ \t]*endif[ \t]*") 1224 ((or (looking-at "[ \t]*#[ \t]*endif[ \t]*")
1111 (looking-at "^#[ \t]*else[ \t]*")) 1225 (looking-at "[ \t]*#[ \t]*else[ \t]*"))
1112 7) 1226 7)
1113 ;; CASE 3: when c-indent-comments-syntactically-p is t, 1227 ;; CASE 3: when c-indent-comments-syntactically-p is t,
1114 ;; calculate the offset according to c-offsets-alist. 1228 ;; calculate the offset according to c-offsets-alist.
@@ -1127,8 +1241,7 @@ comment."
1127 ;; to ignore any anchoring as specified by 1241 ;; to ignore any anchoring as specified by
1128 ;; c-comment-only-line-offset since it doesn't apply here. 1242 ;; c-comment-only-line-offset since it doesn't apply here.
1129 (if (save-excursion 1243 (if (save-excursion
1130 (beginning-of-line) 1244 (back-to-indentation)
1131 (skip-chars-forward " \t")
1132 (eolp)) 1245 (eolp))
1133 (c-add-syntax 'comment-intro)) 1246 (c-add-syntax 'comment-intro))
1134 (let ((c-comment-only-line-offset 1247 (let ((c-comment-only-line-offset
@@ -1136,7 +1249,7 @@ comment."
1136 c-comment-only-line-offset 1249 c-comment-only-line-offset
1137 (cons c-comment-only-line-offset 1250 (cons c-comment-only-line-offset
1138 c-comment-only-line-offset)))) 1251 c-comment-only-line-offset))))
1139 (apply '+ (mapcar 'c-get-offset syntax))))) 1252 (c-get-syntactic-indentation syntax))))
1140 ;; CASE 4: If previous line is a comment-only line, use its 1253 ;; CASE 4: If previous line is a comment-only line, use its
1141 ;; indentation if it's greater than comment-column. Leave at 1254 ;; indentation if it's greater than comment-column. Leave at
1142 ;; least one space between the comment and the last nonblank 1255 ;; least one space between the comment and the last nonblank
@@ -1346,7 +1459,7 @@ relative indentation among the lines of the expression is preserved.
1346 (let ((bod (c-point 'bod)) 1459 (let ((bod (c-point 'bod))
1347 (indent-function 1460 (indent-function
1348 (if c-syntactic-indentation 1461 (if c-syntactic-indentation
1349 (symbol-function 'c-indent-line) 1462 (symbol-function 'indent-according-to-mode)
1350 (lambda () 1463 (lambda ()
1351 (let ((steps (cond ((not current-prefix-arg) 1) 1464 (let ((steps (cond ((not current-prefix-arg) 1)
1352 ((equal current-prefix-arg '(4)) -1) 1465 ((equal current-prefix-arg '(4)) -1)
@@ -1357,8 +1470,15 @@ relative indentation among the lines of the expression is preserved.
1357 ;; If c-syntactic-indentation and got arg, always indent this 1470 ;; If c-syntactic-indentation and got arg, always indent this
1358 ;; line as C and shift remaining lines of expression the same 1471 ;; line as C and shift remaining lines of expression the same
1359 ;; amount. 1472 ;; amount.
1360 (let ((shift-amt (c-indent-line)) 1473 (let ((shift-amt (save-excursion
1474 (back-to-indentation)
1475 (current-column)))
1361 beg end) 1476 beg end)
1477 (c-indent-line)
1478 (setq shift-amt (- (save-excursion
1479 (back-to-indentation)
1480 (current-column))
1481 shift-amt))
1362 (save-excursion 1482 (save-excursion
1363 (if (eq c-tab-always-indent t) 1483 (if (eq c-tab-always-indent t)
1364 (beginning-of-line)) 1484 (beginning-of-line))
@@ -1369,7 +1489,7 @@ relative indentation among the lines of the expression is preserved.
1369 (forward-line 1) 1489 (forward-line 1)
1370 (setq beg (point))) 1490 (setq beg (point)))
1371 (if (> end beg) 1491 (if (> end beg)
1372 (indent-code-rigidly beg end (- shift-amt) "#"))) 1492 (indent-code-rigidly beg end shift-amt "#")))
1373 ;; Else use c-tab-always-indent to determine behavior. 1493 ;; Else use c-tab-always-indent to determine behavior.
1374 (cond 1494 (cond
1375 ;; CASE 1: indent when at column zero or in lines indentation, 1495 ;; CASE 1: indent when at column zero or in lines indentation,
@@ -1392,57 +1512,39 @@ relative indentation among the lines of the expression is preserved.
1392 ))))) 1512 )))))
1393 1513
1394(defun c-indent-exp (&optional shutup-p) 1514(defun c-indent-exp (&optional shutup-p)
1395 "Indent each line in balanced expression following point syntactically. 1515 "Indent each line in the balanced expression following point syntactically.
1396Optional SHUTUP-P if non-nil, inhibits message printing and error checking." 1516If optional SHUTUP-P is non-nil, no errors are signalled if no
1517balanced expression is found."
1397 (interactive "*P") 1518 (interactive "*P")
1398 (let ((here (point-marker)) 1519 (let ((here (point-marker))
1399 end progress-p) 1520 end)
1400 (set-marker-insertion-type here t) 1521 (set-marker-insertion-type here t)
1401 (unwind-protect 1522 (unwind-protect
1402 (let ((c-echo-syntactic-information-p nil) ;keep quiet for speed 1523 (let ((start (progn
1403 (start (progn
1404 ;; try to be smarter about finding the range of 1524 ;; try to be smarter about finding the range of
1405 ;; lines to indent. skip all following 1525 ;; lines to indent. skip all following
1406 ;; whitespace. failing that, try to find any 1526 ;; whitespace, then try to find any
1407 ;; opening brace on the current line 1527 ;; opening paren on the current line
1408 (skip-chars-forward " \t\n") 1528 (skip-chars-forward " \t\n")
1409 (if (memq (char-after) '(?\( ?\[ ?\{)) 1529 (save-restriction
1410 (point) 1530 (narrow-to-region (point-min) (c-point 'eol))
1411 (let ((state (parse-partial-sexp (point) 1531 (c-safe (1- (scan-lists (point) 1 -1)))))))
1412 (c-point 'eol))))
1413 (and (nth 1 state)
1414 (goto-char (nth 1 state))
1415 (memq (char-after) '(?\( ?\[ ?\{))
1416 (point)))))))
1417 ;; find balanced expression end 1532 ;; find balanced expression end
1418 (setq end (and (c-safe (progn (c-forward-sexp 1) t)) 1533 (setq end (and (c-safe (progn (c-forward-sexp 1) t))
1419 (point-marker))) 1534 (point)))
1420 ;; sanity check 1535 ;; sanity check
1421 (and (not start) 1536 (if (not start)
1422 (not shutup-p) 1537 (unless shutup-p
1423 (error "Cannot find start of balanced expression to indent.")) 1538 (error "Cannot find start of balanced expression to indent"))
1424 (and (not end) 1539 (if (not end)
1425 (not shutup-p) 1540 (unless shutup-p
1426 (error "Cannot find end of balanced expression to indent.")) 1541 (error "Cannot find end of balanced expression to indent"))
1427 (c-progress-init start end 'c-indent-exp) 1542 (c-indent-region start end))))
1428 (setq progress-p t)
1429 (goto-char start)
1430 (beginning-of-line)
1431 (while (< (point) end)
1432 (if (not (looking-at "[ \t]*$"))
1433 (c-indent-line))
1434 (c-progress-update)
1435 (forward-line 1)))
1436 ;; make sure marker is deleted
1437 (and end
1438 (set-marker end nil))
1439 (and progress-p
1440 (c-progress-fini 'c-indent-exp))
1441 (goto-char here) 1543 (goto-char here)
1442 (set-marker here nil)))) 1544 (set-marker here nil))))
1443 1545
1444(defun c-indent-defun () 1546(defun c-indent-defun ()
1445 "Re-indents the current top-level function def, struct or class declaration 1547 "Indent the current top-level function def, struct or class declaration
1446syntactically." 1548syntactically."
1447 (interactive "*") 1549 (interactive "*")
1448 (let ((here (point-marker)) 1550 (let ((here (point-marker))
@@ -1467,96 +1569,37 @@ syntactically."
1467 (goto-char here) 1569 (goto-char here)
1468 (set-marker here nil)))) 1570 (set-marker here nil))))
1469 1571
1470(defun c-indent-region (start end) 1572(defun c-indent-region (start end &optional quiet)
1471 ;; Indent every line whose first char is between START and END inclusive. 1573 "Indent every line whose first char is between START and END inclusive.
1574Be silent about syntactic errors if the optional argument QUIET is non-nil."
1472 (save-excursion 1575 (save-excursion
1473 (goto-char start) 1576 (goto-char start)
1474 ;; Advance to first nonblank line. 1577 ;; Advance to first nonblank line.
1475 (skip-chars-forward " \t\n") 1578 (skip-chars-forward " \t\n")
1476 (beginning-of-line) 1579 (beginning-of-line)
1477 (let (endmark) 1580 (setq c-parsing-error
1478 (unwind-protect 1581 (or (let ((endmark (copy-marker end))
1479 (let ((c-tab-always-indent t) 1582 (c-parsing-error nil)
1480 ;; shut up any echo msgs on indiv lines 1583 ;; shut up any echo msgs on indiv lines
1481 (c-echo-syntactic-information-p nil) 1584 (c-echo-syntactic-information-p nil))
1482 fence) 1585 (unwind-protect
1483 (c-progress-init start end 'c-indent-region) 1586 (progn
1484 (setq endmark (copy-marker end)) 1587 (c-progress-init start end 'c-indent-region)
1485 (while (and (bolp) 1588 (while (and (bolp)
1486 (not (eobp)) 1589 (not (eobp))
1487 (< (point) endmark)) 1590 (< (point) endmark))
1488 ;; update progress 1591 ;; update progress
1489 (c-progress-update) 1592 (c-progress-update)
1490 ;; Indent one line as with TAB. 1593 ;; skip blank lines
1491 (let (nextline sexpend sexpbeg) 1594 (skip-chars-forward " \t\n")
1492 ;; skip blank lines 1595 (beginning-of-line)
1493 (skip-chars-forward " \t\n") 1596 ;; indent the current line
1494 (beginning-of-line) 1597 (c-indent-line nil t)
1495 ;; indent the current line 1598 (forward-line)))
1496 (c-indent-line) 1599 (set-marker endmark nil)
1497 (setq fence (point)) 1600 (c-progress-fini 'c-indent-region))
1498 (if (save-excursion 1601 (c-echo-parsing-error quiet))
1499 (beginning-of-line) 1602 c-parsing-error))))
1500 (looking-at "[ \t]*#"))
1501 (forward-line 1)
1502 (save-excursion
1503 ;; Find beginning of following line.
1504 (setq nextline (c-point 'bonl))
1505 ;; Find first beginning-of-sexp for sexp extending past
1506 ;; this line.
1507 (beginning-of-line)
1508 (while (< (point) nextline)
1509 (condition-case nil
1510 (progn
1511 (c-forward-sexp 1)
1512 (setq sexpend (point)))
1513 (error (setq sexpend nil)
1514 (goto-char nextline)))
1515 (c-forward-syntactic-ws))
1516 (if sexpend
1517 (progn
1518 ;; make sure the sexp we found really starts on the
1519 ;; current line and extends past it
1520 (goto-char sexpend)
1521 (setq sexpend (point-marker))
1522 (c-safe (c-backward-sexp 1))
1523 (setq sexpbeg (point))))
1524 (if (and sexpbeg (< sexpbeg fence))
1525 (setq sexpbeg fence)))
1526 ;; Since we move by sexps we might have missed
1527 ;; comment-only lines.
1528 (if sexpbeg
1529 (save-excursion
1530 (while (progn
1531 (forward-line 1)
1532 (skip-chars-forward " \t")
1533 (< (point) sexpbeg))
1534 (if (looking-at c-comment-start-regexp)
1535 (setq sexpbeg (c-point 'bol))))))
1536 ;; If that sexp ends within the region, indent it all at
1537 ;; once, fast.
1538 (condition-case nil
1539 (if (and sexpend
1540 (> sexpend nextline)
1541 (<= sexpend endmark))
1542 (progn
1543 (goto-char sexpbeg)
1544 (c-indent-exp 'shutup)
1545 (c-progress-update)
1546 (goto-char sexpend)))
1547 (error
1548 (goto-char sexpbeg)
1549 (c-indent-line)))
1550 ;; Move to following line and try again.
1551 (and sexpend
1552 (markerp sexpend)
1553 (set-marker sexpend nil))
1554 (forward-line 1)
1555 (setq fence (point))))))
1556 (set-marker endmark nil)
1557 (c-progress-fini 'c-indent-region)
1558 (c-echo-parsing-error)
1559 ))))
1560 1603
1561(defun c-mark-function () 1604(defun c-mark-function ()
1562 "Put mark at end of current top-level defun, point at beginning." 1605 "Put mark at end of current top-level defun, point at beginning."
@@ -1582,10 +1625,10 @@ syntactically."
1582 (c-backward-syntactic-ws) 1625 (c-backward-syntactic-ws)
1583 (skip-chars-backward ";") 1626 (skip-chars-backward ";")
1584 (point)) 1627 (point))
1585 (cdar state))) 1628 (cdr (car state))))
1586 (progn 1629 (progn
1587 (setq eod (point)) 1630 (setq eod (point))
1588 (goto-char (caar state)) 1631 (goto-char (car (car state)))
1589 (c-beginning-of-statement-1)) 1632 (c-beginning-of-statement-1))
1590 (if (= ?{ (save-excursion 1633 (if (= ?{ (save-excursion
1591 (c-end-of-statement-1) 1634 (c-end-of-statement-1)
@@ -1613,13 +1656,18 @@ syntactically."
1613 (push-mark here) 1656 (push-mark here)
1614 (push-mark eod nil t))) 1657 (push-mark eod nil t)))
1615 1658
1659(defun c-fn-region-is-active-p ()
1660 ;; Function version of the macro for use in places that aren't
1661 ;; compiled, e.g. in the menus.
1662 (c-region-is-active-p))
1663
1616(defun c-indent-line-or-region () 1664(defun c-indent-line-or-region ()
1617 "When the region is active, indent it. Otherwise indent the current line." 1665 "When the region is active, indent it. Otherwise indent the current line."
1618 ;; Emacs has a variable called mark-active, XEmacs uses region-active-p 1666 ;; Emacs has a variable called mark-active, XEmacs uses region-active-p
1619 (interactive) 1667 (interactive)
1620 (if (c-region-is-active-p) 1668 (if (c-region-is-active-p)
1621 (c-indent-region (region-beginning) (region-end)) 1669 (c-indent-region (region-beginning) (region-end))
1622 (c-indent-command))) 1670 (indent-according-to-mode)))
1623 1671
1624 1672
1625;; for progress reporting 1673;; for progress reporting
@@ -1632,7 +1680,7 @@ syntactically."
1632 ;; Start the progress update messages. If this Emacs doesn't have 1680 ;; Start the progress update messages. If this Emacs doesn't have
1633 ;; a built-in timer, just be dumb about it. 1681 ;; a built-in timer, just be dumb about it.
1634 ((not (fboundp 'current-time)) 1682 ((not (fboundp 'current-time))
1635 (message "indenting region... (this may take a while)")) 1683 (message "Indenting region... (this may take a while)"))
1636 ;; If progress has already been initialized, do nothing. otherwise 1684 ;; If progress has already been initialized, do nothing. otherwise
1637 ;; initialize the counter with a vector of: 1685 ;; initialize the counter with a vector of:
1638 ;; [start end lastsec context] 1686 ;; [start end lastsec context]
@@ -1643,7 +1691,7 @@ syntactically."
1643 (point-marker)) 1691 (point-marker))
1644 (nth 1 (current-time)) 1692 (nth 1 (current-time))
1645 context)) 1693 context))
1646 (message "indenting region...")) 1694 (message "Indenting region..."))
1647 )) 1695 ))
1648 1696
1649(defun c-progress-update () 1697(defun c-progress-update ()
@@ -1658,7 +1706,7 @@ syntactically."
1658 ;; what's the right value? 1706 ;; what's the right value?
1659 (if (< c-progress-interval (- now lastsecs)) 1707 (if (< c-progress-interval (- now lastsecs))
1660 (progn 1708 (progn
1661 (message "indenting region... (%d%% complete)" 1709 (message "Indenting region... (%d%% complete)"
1662 (/ (* 100 (- (point) start)) (- end start))) 1710 (/ (* 100 (- (point) start)) (- end start)))
1663 (aset c-progress-info 2 now))) 1711 (aset c-progress-info 2 now)))
1664 ))) 1712 )))
@@ -1672,7 +1720,7 @@ syntactically."
1672 (progn 1720 (progn
1673 (set-marker (aref c-progress-info 1) nil) 1721 (set-marker (aref c-progress-info 1) nil)
1674 (setq c-progress-info nil) 1722 (setq c-progress-info nil)
1675 (message "indenting region...done"))))) 1723 (message "Indenting region... done")))))
1676 1724
1677 1725
1678 1726
@@ -1748,6 +1796,10 @@ command to conveniently insert and align the necessary backslashes."
1748 1796
1749;;; Line breaking and paragraph filling. 1797;;; Line breaking and paragraph filling.
1750 1798
1799(defvar c-auto-fill-prefix t)
1800(defvar c-lit-limits nil)
1801(defvar c-lit-type nil)
1802
1751;; The filling code is based on a simple theory; leave the intricacies 1803;; The filling code is based on a simple theory; leave the intricacies
1752;; of the text handling to the currently active mode for that 1804;; of the text handling to the currently active mode for that
1753;; (e.g. adaptive-fill-mode or filladapt-mode) and do as little as 1805;; (e.g. adaptive-fill-mode or filladapt-mode) and do as little as
@@ -1772,12 +1824,12 @@ command to conveniently insert and align the necessary backslashes."
1772 ;; function also uses the value of point in some heuristics. 1824 ;; function also uses the value of point in some heuristics.
1773 (let* ((here (point)) 1825 (let* ((here (point))
1774 (prefix-regexp (concat "[ \t]*\\(" 1826 (prefix-regexp (concat "[ \t]*\\("
1775 c-comment-prefix-regexp 1827 c-current-comment-prefix
1776 "\\)[ \t]*")) 1828 "\\)[ \t]*"))
1777 (comment-start-regexp (if (eq lit-type 'c++) 1829 (comment-start-regexp (if (eq lit-type 'c++)
1778 prefix-regexp 1830 prefix-regexp
1779 comment-start-skip)) 1831 comment-start-skip))
1780 prefix-line comment-prefix res) 1832 prefix-line comment-prefix res comment-text-end)
1781 (cond 1833 (cond
1782 (fill-prefix 1834 (fill-prefix
1783 (setq res (cons fill-prefix 1835 (setq res (cons fill-prefix
@@ -1796,7 +1848,8 @@ command to conveniently insert and align the necessary backslashes."
1796 ((eq lit-type 'c++) 1848 ((eq lit-type 'c++)
1797 (save-excursion 1849 (save-excursion
1798 ;; Set fallback for comment-prefix if none is found. 1850 ;; Set fallback for comment-prefix if none is found.
1799 (setq comment-prefix "// ") 1851 (setq comment-prefix "// "
1852 comment-text-end (cdr lit-limits))
1800 (beginning-of-line) 1853 (beginning-of-line)
1801 (if (> (point) (car lit-limits)) 1854 (if (> (point) (car lit-limits))
1802 ;; The current line is not the comment starter, so the 1855 ;; The current line is not the comment starter, so the
@@ -1847,6 +1900,7 @@ command to conveniently insert and align the necessary backslashes."
1847 ))))) 1900 )))))
1848 (t 1901 (t
1849 (save-excursion 1902 (save-excursion
1903 (setq comment-text-end (- (cdr lit-limits) 2))
1850 (beginning-of-line) 1904 (beginning-of-line)
1851 (if (and (> (point) (car lit-limits)) 1905 (if (and (> (point) (car lit-limits))
1852 (not (and (looking-at "[ \t]*\\*/") 1906 (not (and (looking-at "[ \t]*\\*/")
@@ -1868,7 +1922,7 @@ command to conveniently insert and align the necessary backslashes."
1868 ;; The comment is either one line or the next line 1922 ;; The comment is either one line or the next line
1869 ;; contains just the comment ender. Also, if point is 1923 ;; contains just the comment ender. Also, if point is
1870 ;; on the comment opener line and the following line is 1924 ;; on the comment opener line and the following line is
1871 ;; empty or doesn't match c-comment-prefix-regexp we 1925 ;; empty or doesn't match c-current-comment-prefix we
1872 ;; assume that this is in fact a not yet closed one line 1926 ;; assume that this is in fact a not yet closed one line
1873 ;; comment, so we shouldn't look for the comment prefix 1927 ;; comment, so we shouldn't look for the comment prefix
1874 ;; on the next line. In these cases we have no 1928 ;; on the next line. In these cases we have no
@@ -1910,7 +1964,7 @@ command to conveniently insert and align the necessary backslashes."
1910 ;; "" or ends with whitespace. 1964 ;; "" or ends with whitespace.
1911 (insert "x\n" comment-prefix ?x) 1965 (insert "x\n" comment-prefix ?x)
1912 (setq tmp-post (point-marker)) 1966 (setq tmp-post (point-marker))
1913 (c-indent-line) 1967 (indent-according-to-mode)
1914 (goto-char (1- tmp-post)) 1968 (goto-char (1- tmp-post))
1915 (cons (buffer-substring-no-properties 1969 (cons (buffer-substring-no-properties
1916 (c-point 'bol) (point)) 1970 (c-point 'bol) (point))
@@ -1931,37 +1985,56 @@ command to conveniently insert and align the necessary backslashes."
1931 (test-line 1985 (test-line
1932 (lambda () 1986 (lambda ()
1933 (when (and (looking-at prefix-regexp) 1987 (when (and (looking-at prefix-regexp)
1934 (< (match-end 0) (1- (cdr lit-limits)))) 1988 (<= (match-end 0) comment-text-end))
1989 (unless (eq (match-end 0) (c-point 'eol))
1990 ;; The match is fine if there's text after it.
1991 (throw 'found (cons (buffer-substring-no-properties
1992 (match-beginning 0) (match-end 0))
1993 (progn (goto-char (match-end 0))
1994 (current-column)))))
1935 (unless fb-string 1995 (unless fb-string
1996 ;; This match is better than nothing, so let's
1997 ;; remember it in case nothing better is found
1998 ;; on another line.
1936 (setq fb-string (buffer-substring-no-properties 1999 (setq fb-string (buffer-substring-no-properties
1937 (match-beginning 0) (match-end 0)) 2000 (match-beginning 0) (match-end 0))
1938 fb-endpos (match-end 0))) 2001 fb-endpos (match-end 0)))
1939 (unless (eq (match-end 0) (c-point 'eol))
1940 (throw 'found t))
1941 t)))) 2002 t))))
1942 (if (catch 'found 2003 (or (catch 'found
1943 ;; Search for a line which has text after the prefix 2004 ;; Search for a line which has text after the prefix
1944 ;; so that we get the proper amount of whitespace 2005 ;; so that we get the proper amount of whitespace
1945 ;; after it. We start with the current line, then 2006 ;; after it. We start with the current line, then
1946 ;; search backwards, then forwards. 2007 ;; search backwards, then forwards.
1947 (goto-char prefix-line) 2008 (goto-char prefix-line)
1948 (when (and (funcall test-line) 2009 (when (and (funcall test-line)
1949 (/= (match-end 1) (match-end 0))) 2010 (or (/= (match-end 1) (match-end 0))
2011 ;; The whitespace is sucked up by the
2012 ;; first [ \t]* glob if the prefix is empty.
2013 (and (= (match-beginning 1) (match-end 1))
2014 (/= (match-beginning 0) (match-end 0)))))
1950 ;; If the current line doesn't have text but do 2015 ;; If the current line doesn't have text but do
1951 ;; have whitespace after the prefix, we'll use it. 2016 ;; have whitespace after the prefix, we'll use it.
1952 (throw 'found t)) 2017 (throw 'found (cons fb-string
1953 (while (and (zerop (forward-line -1)) 2018 (progn (goto-char fb-endpos)
1954 (> (point) (car lit-limits))) 2019 (current-column)))))
1955 (funcall test-line)) 2020 (if (eq lit-type 'c++)
2021 ;; For line comments we can search up to and
2022 ;; including the first line.
2023 (while (and (zerop (forward-line -1))
2024 (>= (point) (car lit-limits)))
2025 (funcall test-line))
2026 ;; For block comments we must stop before the
2027 ;; block starter.
2028 (while (and (zerop (forward-line -1))
2029 (> (point) (car lit-limits)))
2030 (funcall test-line)))
1956 (goto-char prefix-line) 2031 (goto-char prefix-line)
1957 (while (and (zerop (forward-line 1)) 2032 (while (and (zerop (forward-line 1))
1958 (< (point) (cdr lit-limits))) 2033 (< (point) (cdr lit-limits)))
1959 (funcall test-line)) 2034 (funcall test-line))
2035 (goto-char prefix-line)
1960 nil) 2036 nil)
1961 ;; A good line with text after the prefix was found. 2037 (when fb-string
1962 (cons (buffer-substring-no-properties (point) (match-end 0))
1963 (progn (goto-char (match-end 0)) (current-column)))
1964 (if fb-string
1965 ;; A good line wasn't found, but at least we have a 2038 ;; A good line wasn't found, but at least we have a
1966 ;; fallback that matches the comment prefix regexp. 2039 ;; fallback that matches the comment prefix regexp.
1967 (cond ((string-match "\\s \\'" fb-string) 2040 (cond ((string-match "\\s \\'" fb-string)
@@ -1997,13 +2070,14 @@ command to conveniently insert and align the necessary backslashes."
1997 (c-point 'bol) 2070 (c-point 'bol)
1998 (point)) 2071 (point))
1999 (current-column))) 2072 (current-column)))
2000 (delete-region tmp (point))))) 2073 (delete-region tmp (point))
2074 (set-buffer-modified-p buffer-modified))))
2001 (t 2075 (t
2002 ;; Last resort: Just add a single space after 2076 ;; Last resort: Just add a single space after
2003 ;; the prefix. 2077 ;; the prefix.
2004 (cons (concat fb-string " ") 2078 (cons (concat fb-string " ")
2005 (progn (goto-char fb-endpos) 2079 (progn (goto-char fb-endpos)
2006 (1+ (current-column)))))) 2080 (1+ (current-column)))))))
2007 ;; The line doesn't match the comment prefix regexp. 2081 ;; The line doesn't match the comment prefix regexp.
2008 (if comment-prefix 2082 (if comment-prefix
2009 ;; We have a fallback for line comments that we must use. 2083 ;; We have a fallback for line comments that we must use.
@@ -2016,7 +2090,7 @@ command to conveniently insert and align the necessary backslashes."
2016 ;; comment where the lines doesn't have any comment 2090 ;; comment where the lines doesn't have any comment
2017 ;; prefix at all and we should just fill it as 2091 ;; prefix at all and we should just fill it as
2018 ;; normal text. 2092 ;; normal text.
2019 '("" . 0))))))) 2093 '("" . 0))))))
2020 )) 2094 ))
2021 2095
2022(defun c-fill-paragraph (&optional arg) 2096(defun c-fill-paragraph (&optional arg)
@@ -2043,193 +2117,240 @@ Optional prefix ARG means justify paragraph as well."
2043 (let (lit-limits lit-type fill 2117 (let (lit-limits lit-type fill
2044 ;; beg and end limits the region to be filled. end is a marker. 2118 ;; beg and end limits the region to be filled. end is a marker.
2045 beg end 2119 beg end
2046 ;; tmp-pre and tmp-post marks strings that are temporarily 2120 ;; tmp-pre and tmp-post mark strings that are temporarily
2047 ;; inserted at the start and end of the region. tmp-pre is a 2121 ;; inserted at the start and end of the region. tmp-pre is a
2048 ;; cons of the positions of the prepended string. tmp-post is 2122 ;; cons of the positions of the prepended string. tmp-post is
2049 ;; a marker pointing to the single character of the appended 2123 ;; a marker pointing to the single character of the appended
2050 ;; string. 2124 ;; string.
2051 tmp-pre tmp-post 2125 tmp-pre tmp-post
2052 hang-ender-stuck) 2126 ;; If hang-ender-stuck isn't nil, the comment ender is
2127 ;; hanging. In that case it's set to the number of spaces
2128 ;; that should be between the text and the ender.
2129 hang-ender-stuck
2130 (here (point)))
2053 ;; Restore point on undo. It's necessary since we do a lot of 2131 ;; Restore point on undo. It's necessary since we do a lot of
2054 ;; hidden inserts and deletes below that should be as transparent 2132 ;; hidden inserts and deletes below that should be as transparent
2055 ;; as possible. 2133 ;; as possible.
2056 (if (and buffer-undo-list (not (eq buffer-undo-list t))) 2134 (if (and buffer-undo-list (not (eq buffer-undo-list t)))
2057 (setq buffer-undo-list (cons (point) buffer-undo-list))) 2135 (setq buffer-undo-list (cons (point) buffer-undo-list)))
2136 (save-restriction
2137 ;; Widen to catch comment limits correctly.
2138 (widen)
2139 (setq lit-limits (c-collect-line-comments (c-literal-limits nil t))
2140 lit-type (c-literal-type lit-limits)))
2058 (save-excursion 2141 (save-excursion
2059 (save-restriction 2142 (unless (c-safe (backward-char)
2060 ;; Widen to catch comment limits correctly. 2143 (forward-paragraph)
2061 (widen) 2144 (>= (point) here))
2062 (setq lit-limits (c-collect-line-comments (c-literal-limits nil t)) 2145 (goto-char here)
2063 lit-type (c-literal-type lit-limits))) 2146 (forward-paragraph))
2064 (forward-paragraph) 2147 (setq end (point-marker)))
2065 (setq end (point-marker)) 2148 (save-excursion
2066 (backward-paragraph) 2149 (unless (c-safe (forward-char)
2150 (backward-paragraph)
2151 (<= (point) here))
2152 (goto-char here)
2153 (backward-paragraph))
2067 (setq beg (point))) 2154 (setq beg (point)))
2068 (when (and (>= (point) beg) (<= (point) end)) 2155 (unwind-protect
2069 (unwind-protect 2156 (progn
2070 (progn 2157 (cond
2071 (cond 2158 ((eq lit-type 'c++) ; Line comment.
2072 ((eq lit-type 'c++) ; Line comment. 2159 (save-excursion
2073 (save-excursion 2160 ;; Fill to the comment or paragraph end, whichever
2074 ;; Fill to the comment or paragraph end, whichever 2161 ;; comes first.
2075 ;; comes first. 2162 (set-marker end (min end (cdr lit-limits)))
2076 (set-marker end (min end (cdr lit-limits))) 2163 (when (<= beg (car lit-limits))
2077 (when (<= beg (car lit-limits)) 2164 ;; The region to be filled includes the comment
2078 ;; The region to be filled includes the comment 2165 ;; starter, so we must check it.
2079 ;; starter, so we must check it. 2166 (goto-char (car lit-limits))
2080 (goto-char (car lit-limits)) 2167 (back-to-indentation)
2081 (back-to-indentation) 2168 (if (eq (point) (car lit-limits))
2082 (if (eq (point) (car lit-limits)) 2169 ;; Include the first line in the fill.
2083 ;; Include the first line in the fill. 2170 (setq beg (c-point 'bol))
2084 (setq beg (c-point 'bol)) 2171 ;; The first line contains code before the
2085 ;; The first line contains code before the 2172 ;; comment. We must fake a line that doesn't.
2086 ;; comment. We must fake a line that doesn't. 2173 (setq tmp-pre t)))
2087 (setq tmp-pre t))) 2174 ))
2088 )) 2175 ((eq lit-type 'c) ; Block comment.
2089 ((eq lit-type 'c) ; Block comment. 2176 (when (>= end (cdr lit-limits))
2090 (save-excursion 2177 ;; The region to be filled includes the comment ender.
2091 (when (>= end (cdr lit-limits)) 2178 (unless (save-excursion
2092 ;; The region to be filled includes the comment ender. 2179 (goto-char (cdr lit-limits))
2093 (goto-char (cdr lit-limits)) 2180 (beginning-of-line)
2094 (beginning-of-line) 2181 (and (looking-at (concat "[ \t]*\\("
2095 (if (and (looking-at (concat "[ \t]*\\(" 2182 c-current-comment-prefix
2096 c-comment-prefix-regexp 2183 "\\)\\*/"))
2097 "\\)\\*/")) 2184 (eq (cdr lit-limits) (match-end 0))
2098 (eq (cdr lit-limits) (match-end 0))) 2185 ;; Leave the comment ender on its own line.
2099 ;; Leave the comment ender on its own line. 2186 (set-marker end (point))))
2100 (set-marker end (point)) 2187 ;; The comment ender should hang. Replace all cruft
2101 ;; The comment ender should hang. Replace all 2188 ;; between it and the last word with one or two 'x'
2102 ;; cruft between it and the last word with a 'x' 2189 ;; and include it in the fill. We'll change them back
2103 ;; and include it in the fill. We'll change it 2190 ;; spaces afterwards.
2104 ;; back to a space afterwards. 2191 (let* ((ender-start (save-excursion
2105 (let ((ender-start (progn 2192 (goto-char (cdr lit-limits))
2106 (goto-char (cdr lit-limits)) 2193 (skip-syntax-backward "^w ")
2107 (skip-syntax-backward "^w ") 2194 (point)))
2108 (point))) 2195 (point-rel (- ender-start here))
2109 spaces) 2196 spaces)
2110 (goto-char (cdr lit-limits)) 2197 (save-excursion
2111 (setq tmp-post (point-marker)) 2198 (goto-char (cdr lit-limits))
2112 (insert ?\n) 2199 (setq tmp-post (point-marker))
2113 (set-marker end (point)) 2200 (insert ?\n)
2114 (forward-line -1) 2201 (set-marker end (point))
2115 (if (and (looking-at (concat "[ \t]*\\(\\(" 2202 (forward-line -1)
2116 c-comment-prefix-regexp 2203 (if (and (looking-at (concat "[ \t]*\\(\\("
2117 "\\)[ \t]*\\)")) 2204 c-current-comment-prefix
2118 (eq ender-start (match-end 0))) 2205 "\\)[ \t]*\\)"))
2119 ;; The comment ender is prefixed by nothing 2206 (eq ender-start (match-end 0)))
2120 ;; but a comment line prefix. Remove it 2207 ;; The comment ender is prefixed by nothing
2121 ;; along with surrounding ws. 2208 ;; but a comment line prefix. Remove it
2122 (setq spaces (- (match-end 1) (match-end 2))) 2209 ;; along with surrounding ws.
2123 (goto-char ender-start)) 2210 (setq spaces (- (match-end 1) (match-end 2)))
2124 (skip-chars-backward " \t\r\n") 2211 (goto-char ender-start))
2125 (when (/= (point) ender-start) 2212 (skip-chars-backward " \t\r\n")
2126 ;; Keep one or two spaces between the text and 2213 (if (/= (point) ender-start)
2127 ;; the ender, depending on how many there are now. 2214 (progn
2128 (unless spaces (setq spaces (- ender-start (point)))) 2215 (if (<= here (point))
2129 (setq spaces (max (min spaces 2) 1)) 2216 ;; Don't adjust point below if it's
2130 ; Insert the filler first to keep marks right. 2217 ;; before the string we replace.
2131 (insert (make-string spaces ?x)) 2218 (setq point-rel -1))
2132 (delete-region (point) (+ ender-start spaces)) 2219 ;; Keep one or two spaces between the text and
2133 (setq hang-ender-stuck spaces))))) 2220 ;; the ender, depending on how many there are now.
2134 (when (<= beg (car lit-limits)) 2221 (unless spaces (setq spaces (- ender-start (point))))
2135 ;; The region to be filled includes the comment starter. 2222 (setq spaces (max (min spaces 2) 1))
2136 (goto-char (car lit-limits)) 2223 ;; Insert the filler first to keep marks right.
2137 (if (looking-at (concat "\\(" comment-start-skip "\\)$")) 2224 (insert (make-string spaces ?x))
2138 ;; Begin filling with the next line. 2225 (delete-region (point) (+ ender-start spaces))
2139 (setq beg (c-point 'bonl)) 2226 (setq hang-ender-stuck spaces)
2140 ;; Fake the fill prefix in the first line. 2227 (setq point-rel
2141 (setq tmp-pre t))) 2228 (and (>= point-rel 0)
2142 )) 2229 (- (point) (min point-rel spaces)))))
2143 ((eq lit-type 'string) ; String. 2230 (setq point-rel nil)))
2144 (save-excursion 2231 (if point-rel
2145 (when (>= end (cdr lit-limits)) 2232 ;; Point was in the middle of the string we
2146 (goto-char (1- (cdr lit-limits))) 2233 ;; replaced above, so put it back in the same
2147 (setq tmp-post (point-marker)) 2234 ;; relative position, counting from the end.
2148 (insert ?\n) 2235 (goto-char point-rel))
2149 (set-marker end (point))) 2236 )))
2150 (when (<= beg (car lit-limits)) 2237 (when (<= beg (car lit-limits))
2151 (goto-char (1+ (car lit-limits))) 2238 ;; The region to be filled includes the comment starter.
2152 (setq beg (if (looking-at "\\\\$")
2153 ;; Leave the start line if it's
2154 ;; nothing but an escaped newline.
2155 (1+ (match-end 0))
2156 (point))))))
2157 (t (setq beg nil)))
2158 (when tmp-pre
2159 ;; Temporarily insert the fill prefix after the comment
2160 ;; starter so that the first line looks like any other
2161 ;; comment line in the narrowed region.
2162 (setq fill (c-guess-fill-prefix lit-limits lit-type))
2163 (unless (string-match (concat "\\`[ \t]*\\("
2164 c-comment-prefix-regexp
2165 "\\)[ \t]*\\'")
2166 (car fill))
2167 ;; Oops, the prefix doesn't match the comment prefix
2168 ;; regexp. This could produce very confusing
2169 ;; results with adaptive fill packages together with
2170 ;; the insert prefix magic below, since the prefix
2171 ;; often doesn't appear at all. So let's warn about
2172 ;; it.
2173 (message "\
2174Warning: `c-comment-prefix-regexp' doesn't match the comment prefix %S"
2175 (car fill)))
2176 ;; Find the right spot on the line, break it, insert
2177 ;; the fill prefix and make sure we're back in the
2178 ;; same column by temporarily prefixing the first word
2179 ;; with a number of 'x'.
2180 (save-excursion 2239 (save-excursion
2181 (goto-char (car lit-limits)) 2240 (goto-char (car lit-limits))
2182 (if (looking-at (if (eq lit-type 'c++) 2241 (if (looking-at (concat "\\(" comment-start-skip "\\)$"))
2183 c-comment-prefix-regexp 2242 ;; Begin filling with the next line.
2184 comment-start-skip)) 2243 (setq beg (c-point 'bonl))
2185 (goto-char (match-end 0)) 2244 ;; Fake the fill prefix in the first line.
2186 (forward-char 2) 2245 (setq tmp-pre t)))))
2187 (skip-chars-forward " \t")) 2246 ((eq lit-type 'string) ; String.
2188 (while (< (current-column) (cdr fill)) (forward-char 1)) 2247 (save-excursion
2189 (let ((col (current-column))) 2248 (when (>= end (cdr lit-limits))
2190 (setq beg (1+ (point)) 2249 (goto-char (1- (cdr lit-limits)))
2191 tmp-pre (list (point))) 2250 (setq tmp-post (point-marker))
2192 (unwind-protect 2251 (insert ?\n)
2193 (progn 2252 (set-marker end (point)))
2194 (insert ?\n (car fill)) 2253 (when (<= beg (car lit-limits))
2195 (insert (make-string (- col (current-column)) ?x))) 2254 (goto-char (1+ (car lit-limits)))
2196 (setcdr tmp-pre (point)))))) 2255 (setq beg (if (looking-at "\\\\$")
2197 (when beg 2256 ;; Leave the start line if it's
2198 (let ((fill-paragraph-function 2257 ;; nothing but an escaped newline.
2199 ;; Avoid infinite recursion. 2258 (1+ (match-end 0))
2200 (if (not (eq fill-paragraph-function 'c-fill-paragraph)) 2259 (point))))))
2201 fill-paragraph-function)) 2260 (t (setq beg nil)))
2202 (fill-prefix 2261 (when tmp-pre
2203 (or fill-prefix 2262 ;; Temporarily insert the fill prefix after the comment
2204 (when (and (eq lit-type 'c++) 2263 ;; starter so that the first line looks like any other
2205 (not (string-match 2264 ;; comment line in the narrowed region.
2206 "\\`[ \t]*//" 2265 (setq fill (c-guess-fill-prefix lit-limits lit-type))
2207 (or (fill-context-prefix beg end) 2266 (unless (string-match (concat "\\`[ \t]*\\("
2208 "")))) 2267 c-current-comment-prefix
2209 ;; Kludge: If the function that adapts the 2268 "\\)[ \t]*\\'")
2210 ;; fill prefix doesn't produce the required 2269 (car fill))
2211 ;; comment starter for line comments, then 2270 ;; Oops, the prefix doesn't match the comment prefix
2212 ;; force it by setting fill-prefix. 2271 ;; regexp. This could produce very confusing
2213 (car (or fill (c-guess-fill-prefix 2272 ;; results with adaptive fill packages together with
2214 lit-limits lit-type))))))) 2273 ;; the insert prefix magic below, since the prefix
2215 ;; Preparations finally done! Now we can call the 2274 ;; often doesn't appear at all. So let's warn about
2216 ;; real fill function. 2275 ;; it.
2217 (save-restriction 2276 (message "\
2218 (narrow-to-region beg end) 2277Warning: Regexp from `c-comment-prefix-regexp' doesn't match the comment prefix %S"
2219 (fill-paragraph arg))))) 2278 (car fill)))
2220 (when (consp tmp-pre) 2279 ;; Find the right spot on the line, break it, insert
2221 (delete-region (car tmp-pre) (cdr tmp-pre))) 2280 ;; the fill prefix and make sure we're back in the
2222 (when tmp-post 2281 ;; same column by temporarily prefixing the first word
2223 (save-excursion 2282 ;; with a number of 'x'.
2224 (goto-char tmp-post) 2283 (save-excursion
2225 (delete-char 1) 2284 (goto-char (car lit-limits))
2226 (when hang-ender-stuck 2285 (if (looking-at (if (eq lit-type 'c++)
2227 (skip-syntax-backward "^w ") 2286 c-comment-prefix-regexp
2228 (forward-char (- hang-ender-stuck)) 2287 comment-start-skip))
2229 (insert (make-string hang-ender-stuck ?\ )) 2288 (goto-char (match-end 0))
2230 (delete-char hang-ender-stuck)) 2289 (forward-char 2)
2231 (set-marker tmp-post nil))))) 2290 (skip-chars-forward " \t"))
2232 (set-marker end nil)) 2291 (while (< (current-column) (cdr fill)) (forward-char 1))
2292 (let ((col (current-column)))
2293 (setq beg (1+ (point))
2294 tmp-pre (list (point)))
2295 (unwind-protect
2296 (progn
2297 (insert ?\n (car fill))
2298 (insert (make-string (- col (current-column)) ?x)))
2299 (setcdr tmp-pre (point))))))
2300 (when beg
2301 (let ((fill-paragraph-function
2302 ;; Avoid infinite recursion.
2303 (if (not (eq fill-paragraph-function 'c-fill-paragraph))
2304 fill-paragraph-function))
2305 (fill-prefix
2306 (or fill-prefix
2307 ;; Kludge: If the function that adapts the fill prefix
2308 ;; doesn't produce the required comment starter for line
2309 ;; comments, then force it by setting fill-prefix.
2310 (when (and (eq lit-type 'c++)
2311 ;; Kludge the kludge: filladapt-mode doesn't
2312 ;; have this problem, but it doesn't override
2313 ;; fill-context-prefix currently (version
2314 ;; 2.12).
2315 (not (and (boundp 'filladapt-mode)
2316 filladapt-mode))
2317 (not (string-match
2318 "\\`[ \t]*//"
2319 (or (fill-context-prefix beg end)
2320 ""))))
2321 (car (or fill (c-guess-fill-prefix
2322 lit-limits lit-type))))))
2323 (point-rel (cond ((< here beg) (- here beg))
2324 ((> here end) (- here end)))))
2325 ;; Preparations finally done! Now we can call the
2326 ;; real fill function.
2327 (save-restriction
2328 (narrow-to-region beg end)
2329 (fill-paragraph arg))
2330 (if point-rel
2331 ;; Restore point if it was outside the region.
2332 (if (< point-rel 0)
2333 (goto-char (+ beg point-rel))
2334 (goto-char (+ end point-rel))))
2335 )))
2336 (when (consp tmp-pre)
2337 (delete-region (car tmp-pre) (cdr tmp-pre)))
2338 (when tmp-post
2339 (save-excursion
2340 (goto-char tmp-post)
2341 (delete-char 1))
2342 (when hang-ender-stuck
2343 ;; Preserve point even if it's in the middle of the string
2344 ;; we replace; save-excursion doesn't work in that case.
2345 (setq here (point))
2346 (goto-char tmp-post)
2347 (skip-syntax-backward "^w ")
2348 (forward-char (- hang-ender-stuck))
2349 (insert (make-string hang-ender-stuck ?\ ))
2350 (delete-char hang-ender-stuck)
2351 (goto-char here))
2352 (set-marker tmp-post nil))
2353 (set-marker end nil)))
2233 ;; Always return t. This has the effect that if filling isn't done 2354 ;; Always return t. This has the effect that if filling isn't done
2234 ;; above, it isn't done at all, and it's therefore effectively 2355 ;; above, it isn't done at all, and it's therefore effectively
2235 ;; disabled in normal code. 2356 ;; disabled in normal code.
@@ -2267,9 +2388,9 @@ If a fill prefix is specified, it overrides all the above."
2267 (if soft (insert-and-inherit ?\n) (newline 1)))) 2388 (if soft (insert-and-inherit ?\n) (newline 1))))
2268 ;; Already know the literal type and limits when called from 2389 ;; Already know the literal type and limits when called from
2269 ;; c-context-line-break. 2390 ;; c-context-line-break.
2270 (c-lit-limits (if (boundp 'c-lit-limits) c-lit-limits)) 2391 (c-lit-limits c-lit-limits)
2271 (c-lit-type (if (boundp 'c-lit-type) c-lit-type))) 2392 (c-lit-type c-lit-type))
2272 (when (boundp 'c-auto-fill-prefix) 2393 (when (not (eq c-auto-fill-prefix t))
2273 ;; Called from do-auto-fill. 2394 ;; Called from do-auto-fill.
2274 (unless c-lit-limits 2395 (unless c-lit-limits
2275 (setq c-lit-limits (c-literal-limits nil nil t))) 2396 (setq c-lit-limits (c-literal-limits nil nil t)))
@@ -2325,7 +2446,7 @@ If a fill prefix is specified, it overrides all the above."
2325 (if (save-excursion 2446 (if (save-excursion
2326 (back-to-indentation) 2447 (back-to-indentation)
2327 (> (point) (car c-lit-limits)) 2448 (> (point) (car c-lit-limits))
2328 (looking-at c-comment-prefix-regexp)) 2449 (looking-at c-current-comment-prefix))
2329 (progn 2450 (progn
2330 ;; Skip forward past the fill prefix in case 2451 ;; Skip forward past the fill prefix in case
2331 ;; we're standing in it. 2452 ;; we're standing in it.
@@ -2390,13 +2511,14 @@ If a fill prefix is specified, it overrides all the above."
2390 2511
2391;; advice for indent-new-comment-line for older Emacsen 2512;; advice for indent-new-comment-line for older Emacsen
2392(unless (boundp 'comment-line-break-function) 2513(unless (boundp 'comment-line-break-function)
2514 (defvar c-inside-line-break-advice nil)
2393 (defadvice indent-new-comment-line (around c-line-break-advice 2515 (defadvice indent-new-comment-line (around c-line-break-advice
2394 activate preactivate) 2516 activate preactivate)
2395 "Call `c-indent-new-comment-line' if in CC Mode." 2517 "Call `c-indent-new-comment-line' if in CC Mode."
2396 (if (or (boundp 'c-inside-line-break-advice) 2518 (if (or c-inside-line-break-advice
2397 (not c-buffer-is-cc-mode)) 2519 (not c-buffer-is-cc-mode))
2398 ad-do-it 2520 ad-do-it
2399 (let (c-inside-line-break-advice) 2521 (let ((c-inside-line-break-advice t))
2400 (c-indent-new-comment-line (ad-get-arg 0)))))) 2522 (c-indent-new-comment-line (ad-get-arg 0))))))
2401 2523
2402(defun c-context-line-break () 2524(defun c-context-line-break ()
@@ -2431,8 +2553,8 @@ C++-style line comment doesn't count as inside the comment, though."
2431 (= (forward-line -1) 0)))) 2553 (= (forward-line -1) 0))))
2432 (current-column)))) 2554 (current-column))))
2433 (indent-to col)) 2555 (indent-to col))
2434 (c-indent-line)))) 2556 (indent-according-to-mode))))
2435 2557
2436 2558
2437(provide 'cc-cmds) 2559(cc-provide 'cc-cmds)
2438;;; cc-cmds.el ends here 2560;;; cc-cmds.el ends here
diff --git a/lisp/progmodes/cc-compat.el b/lisp/progmodes/cc-compat.el
index 98ba4bea3f6..887cf4bfc11 100644
--- a/lisp/progmodes/cc-compat.el
+++ b/lisp/progmodes/cc-compat.el
@@ -1,6 +1,6 @@
1;;; cc-compat.el --- cc-mode compatibility with c-mode.el confusion 1;;; cc-compat.el --- cc-mode compatibility with c-mode.el confusion
2 2
3;; Copyright (C) 1985,87,92,93,94,95,96,97,98,99,2000 Free Software Foundation, Inc. 3;; Copyright (C) 1985,1987,1992-2001 Free Software Foundation, Inc.
4 4
5;; Authors: 2000- Martin Stjernholm 5;; Authors: 2000- Martin Stjernholm
6;; 1998-1999 Barry A. Warsaw and Martin Stjernholm 6;; 1998-1999 Barry A. Warsaw and Martin Stjernholm
@@ -23,8 +23,8 @@
23;; GNU General Public License for more details. 23;; GNU General Public License for more details.
24 24
25;; You should have received a copy of the GNU General Public License 25;; You should have received a copy of the GNU General Public License
26;; along with GNU Emacs; see the file COPYING. If not, write to the 26;; along with this program; see the file COPYING. If not, write to
27;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 27;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28;; Boston, MA 02111-1307, USA. 28;; Boston, MA 02111-1307, USA.
29 29
30;;; Commentary: 30;;; Commentary:
@@ -38,19 +38,25 @@
38;; 38;;
39;; (require 'cc-compat) 39;; (require 'cc-compat)
40;; (c-set-style "BOCM") 40;; (c-set-style "BOCM")
41;;
42;; This file is completely unsupported! Although it has been patched
43;; superficially to keep pace with the rest of CC Mode, it hasn't been
44;; tested for a long time.
41 45
42;;; Code: 46;;; Code:
43 47
44(eval-when-compile 48(eval-when-compile
45 (let ((load-path 49 (let ((load-path
46 (if (and (boundp 'byte-compile-current-file) 50 (if (and (boundp 'byte-compile-dest-file)
47 (stringp byte-compile-current-file)) 51 (stringp byte-compile-dest-file))
48 (cons (file-name-directory byte-compile-current-file) 52 (cons (file-name-directory byte-compile-dest-file) load-path)
49 load-path)
50 load-path))) 53 load-path)))
51 (load "cc-defs" nil t))) 54 (require 'cc-bytecomp)))
52(require 'cc-styles) 55
53(require 'cc-engine) 56(cc-require 'cc-defs)
57(cc-require 'cc-vars)
58(cc-require 'cc-styles)
59(cc-require 'cc-engine)
54 60
55 61
56;; In case c-mode.el isn't loaded 62;; In case c-mode.el isn't loaded
@@ -154,5 +160,5 @@ This is in addition to c-continued-statement-offset.")
154 (+ c-continued-statement-offset c-continued-brace-offset)) 160 (+ c-continued-statement-offset c-continued-brace-offset))
155 161
156 162
157(provide 'cc-compat) 163(cc-provide 'cc-compat)
158;;; cc-compat.el ends here 164;;; cc-compat.el ends here
diff --git a/lisp/progmodes/cc-defs.el b/lisp/progmodes/cc-defs.el
index d7213d03469..b17cbdd5900 100644
--- a/lisp/progmodes/cc-defs.el
+++ b/lisp/progmodes/cc-defs.el
@@ -1,6 +1,6 @@
1;;; cc-defs.el --- compile time definitions for CC Mode 1;;; cc-defs.el --- compile time definitions for CC Mode
2 2
3;; Copyright (C) 1985,87,92,93,94,95,96,97,98,99,2000 Free Software Foundation, Inc. 3;; Copyright (C) 1985,1987,1992-2001 Free Software Foundation, Inc.
4 4
5;; Authors: 2000- Martin Stjernholm 5;; Authors: 2000- Martin Stjernholm
6;; 1998-1999 Barry A. Warsaw and Martin Stjernholm 6;; 1998-1999 Barry A. Warsaw and Martin Stjernholm
@@ -25,31 +25,55 @@
25;; GNU General Public License for more details. 25;; GNU General Public License for more details.
26 26
27;; 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
28;; along with GNU Emacs; see the file COPYING. If not, write to the 28;; along with this program; see the file COPYING. If not, write to
29;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 29;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
30;; Boston, MA 02111-1307, USA. 30;; Boston, MA 02111-1307, USA.
31 31
32;; Get all the necessary compile time definitions. 32(eval-when-compile
33(require 'custom) 33 (let ((load-path
34(require 'derived) ;only necessary in Emacs 20 34 (if (and (boundp 'byte-compile-dest-file)
35 (stringp byte-compile-dest-file))
36 (cons (file-name-directory byte-compile-dest-file) load-path)
37 load-path)))
38 (require 'cc-bytecomp)))
35 39
36;; cc-mode-19.el contains compatibility macros that should be compiled 40;; cc-mode-19.el contains compatibility macros that should be used if
37;; in if needed. 41;; needed.
38(if (or (not (fboundp 'functionp)) 42(eval-and-compile
39 (not (condition-case nil 43 (if (or (not (fboundp 'functionp))
40 (progn (char-before) t) 44 (not (condition-case nil
41 (error nil))) 45 (progn (eval '(char-before)) t)
42 (not (condition-case nil 46 (error nil)))
43 (progn (char-after) t) 47 (not (condition-case nil
44 (error nil))) 48 (progn (eval '(char-after)) t)
45 (not (fboundp 'when)) 49 (error nil)))
46 (not (fboundp 'unless))) 50 (not (fboundp 'when))
47 (require 'cc-mode-19)) 51 (not (fboundp 'unless)))
52 (cc-load "cc-mode-19")))
53
54;; Silence the compiler.
55(cc-bytecomp-defvar c-enable-xemacs-performance-kludge-p) ; In cc-vars.el
56(cc-bytecomp-defun buffer-syntactic-context-depth) ; XEmacs
57(cc-bytecomp-defun region-active-p) ; XEmacs
58(cc-bytecomp-defvar zmacs-region-stays) ; XEmacs
59(cc-bytecomp-defvar zmacs-regions) ; XEmacs
60(cc-bytecomp-defvar mark-active) ; Emacs
61(cc-bytecomp-defun scan-lists) ; 5 args in XEmacs, 3 in Emacs
62(require 'derived) ; Only necessary in Emacs
48 63
49 64
50(defmacro c-point (position) 65;;; Macros.
51 ;; Returns the value of point at certain commonly referenced POSITIONs. 66
52 ;; POSITION can be one of the following symbols: 67;;; Helpers for building regexps.
68(defmacro c-paren-re (re)
69 `(concat "\\(" ,re "\\)"))
70(defmacro c-identifier-re (re)
71 `(concat "\\<\\(" ,re "\\)\\>[^_]"))
72
73(defmacro c-point (position &optional point)
74 ;; Returns the value of certain commonly referenced POSITIONs
75 ;; relative to POINT. The current point is used if POINT isn't
76 ;; specified. POSITION can be one of the following symbols:
53 ;; 77 ;;
54 ;; bol -- beginning of line 78 ;; bol -- beginning of line
55 ;; eol -- end of line 79 ;; eol -- end of line
@@ -63,6 +87,7 @@
63 ;; 87 ;;
64 ;; This function does not modify point or mark. 88 ;; This function does not modify point or mark.
65 `(save-excursion 89 `(save-excursion
90 ,(if point `(goto-char ,point))
66 ,(if (and (eq (car-safe position) 'quote) 91 ,(if (and (eq (car-safe position) 'quote)
67 (symbolp (eval position))) 92 (symbolp (eval position)))
68 (let ((position (eval position))) 93 (let ((position (eval position)))
@@ -100,13 +125,81 @@
100 (t (error "unknown buffer position requested: %s" position))))) 125 (t (error "unknown buffer position requested: %s" position)))))
101 (point))) 126 (point)))
102 127
103
104(defmacro c-safe (&rest body) 128(defmacro c-safe (&rest body)
105 ;; safely execute BODY, return nil if an error occurred 129 ;; safely execute BODY, return nil if an error occurred
106 `(condition-case nil 130 `(condition-case nil
107 (progn ,@body) 131 (progn ,@body)
108 (error nil))) 132 (error nil)))
109 133
134(defmacro c-forward-sexp (&optional arg)
135 ;; like forward-sexp except
136 ;; 1. this is much stripped down from the XEmacs version
137 ;; 2. this cannot be used as a command, so we're insulated from
138 ;; XEmacs' losing efforts to make forward-sexp more user
139 ;; friendly
140 ;; 3. Preserves the semantics most of CC Mode is based on
141 (or arg (setq arg 1))
142 `(goto-char (or (scan-sexps (point) ,arg)
143 ,(if (numberp arg)
144 (if (> arg 0) `(point-max) `(point-min))
145 `(if (> ,arg 0) (point-max) (point-min))))))
146
147(defmacro c-backward-sexp (&optional arg)
148 ;; See c-forward-sexp and reverse directions
149 (or arg (setq arg 1))
150 `(c-forward-sexp ,(if (numberp arg) (- arg) `(- ,arg))))
151
152(defmacro c-add-syntax (symbol &optional relpos)
153 ;; a simple macro to append the syntax in symbol to the syntax list.
154 ;; try to increase performance by using this macro
155 `(setq syntax (cons (cons ,symbol ,relpos) syntax)))
156
157(defmacro c-add-class-syntax (symbol classkey)
158 ;; The inclass and class-close syntactic symbols are added in
159 ;; several places and some work is needed to fix everything.
160 ;; Therefore it's collected here. This is a macro mostly because
161 ;; c-add-syntax doesn't work otherwise.
162 `(save-restriction
163 (widen)
164 (let ((symbol ,symbol)
165 (classkey ,classkey)
166 inexpr)
167 (goto-char (aref classkey 1))
168 (if (and (eq symbol 'inclass) (= (point) (c-point 'boi)))
169 (c-add-syntax symbol (point))
170 (c-add-syntax symbol (aref classkey 0))
171 (if (and c-inexpr-class-key
172 (setq inexpr (c-looking-at-inexpr-block))
173 (/= (cdr inexpr) (c-point 'boi (cdr inexpr))))
174 (c-add-syntax 'inexpr-class))))))
175
176(defmacro c-update-modeline ()
177 ;; set the c-auto-hungry-string for the correct designation on the modeline
178 `(progn
179 (setq c-auto-hungry-string
180 (if c-auto-newline
181 (if c-hungry-delete-key "/ah" "/a")
182 (if c-hungry-delete-key "/h" nil)))
183 (force-mode-line-update)))
184
185(defmacro c-with-syntax-table (table &rest code)
186 ;; Temporarily switches to the specified syntax table in a failsafe
187 ;; way to execute code.
188 `(let ((c-with-syntax-table-orig-table (syntax-table)))
189 (unwind-protect
190 (progn
191 (set-syntax-table ,table)
192 ,@code)
193 (set-syntax-table c-with-syntax-table-orig-table))))
194(put 'c-with-syntax-table 'lisp-indent-function 1)
195
196;;; Inline functions.
197
198;; Note: All these after the macros, to be on safe side in avoiding
199;; bugs where macros are defined too late. These bugs often only show
200;; when the files are compiled in a certain order within the same
201;; session.
202
110(defsubst c-beginning-of-defun-1 () 203(defsubst c-beginning-of-defun-1 ()
111 ;; Wrapper around beginning-of-defun. 204 ;; Wrapper around beginning-of-defun.
112 ;; 205 ;;
@@ -165,52 +258,25 @@
165 (if (< (point) start) 258 (if (< (point) start)
166 (goto-char (point-max))))) 259 (goto-char (point-max)))))
167 260
168(defmacro c-forward-sexp (&optional arg)
169 ;; like forward-sexp except
170 ;; 1. this is much stripped down from the XEmacs version
171 ;; 2. this cannot be used as a command, so we're insulated from
172 ;; XEmacs' losing efforts to make forward-sexp more user
173 ;; friendly
174 ;; 3. Preserves the semantics most of CC Mode is based on
175 (or arg (setq arg 1))
176 `(goto-char (or (scan-sexps (point) ,arg)
177 ,(if (numberp arg)
178 (if (> arg 0) `(point-max) `(point-min))
179 `(if (> ,arg 0) (point-max) (point-min))))))
180
181(defmacro c-backward-sexp (&optional arg)
182 ;; See c-forward-sexp and reverse directions
183 (or arg (setq arg 1))
184 `(c-forward-sexp ,(if (numberp arg) (- arg) `(- ,arg))))
185
186(defsubst c-beginning-of-macro (&optional lim)
187 ;; Go to the beginning of a cpp macro definition. Leaves point at
188 ;; the beginning of the macro and returns t if in a cpp macro
189 ;; definition, otherwise returns nil and leaves point unchanged.
190 ;; `lim' is currently ignored, but the interface requires it.
191 (let ((here (point)))
192 (beginning-of-line)
193 (while (eq (char-before (1- (point))) ?\\)
194 (forward-line -1))
195 (back-to-indentation)
196 (if (and (<= (point) here)
197 (eq (char-after) ?#))
198 t
199 (goto-char here)
200 nil)))
201
202(defsubst c-forward-comment (count) 261(defsubst c-forward-comment (count)
203 ;; Insulation from various idiosyncrasies in implementations of 262 ;; Insulation from various idiosyncrasies in implementations of
204 ;; `forward-comment'. Note: Some emacsen considers incorrectly that 263 ;; `forward-comment'.
205 ;; any line comment ending with a backslash continues to the next 264 ;;
206 ;; line. I can't think of any way to work around that in a reliable 265 ;; Note: Some emacsen considers incorrectly that any line comment
207 ;; way without changing the buffer though. Suggestions welcome. ;) 266 ;; ending with a backslash continues to the next line. I can't
267 ;; think of any way to work around that in a reliable way without
268 ;; changing the buffer though. Suggestions welcome. ;)
269 ;;
270 ;; Another note: When moving backwards over a block comment, there's
271 ;; a bug in forward-comment that can make it stop at "/*" inside a
272 ;; line comment. Haven't yet found a reasonably cheap way to kludge
273 ;; around that one either. :\
208 (let ((here (point))) 274 (let ((here (point)))
209 (if (>= count 0) 275 (if (>= count 0)
210 (when (forward-comment count) 276 (when (forward-comment count)
211 ;; Emacs includes the ending newline in a b-style 277 ;; Emacs includes the ending newline in a b-style (c++)
212 ;; (c++) comment, but XEmacs don't. We depend on the 278 ;; comment, but XEmacs doesn't. We depend on the Emacs
213 ;; Emacs behavior (which also is symmetric). 279 ;; behavior (which also is symmetric).
214 (if (and (eolp) (nth 7 (parse-partial-sexp here (point)))) 280 (if (and (eolp) (nth 7 (parse-partial-sexp here (point))))
215 (condition-case nil (forward-char 1))) 281 (condition-case nil (forward-char 1)))
216 t) 282 t)
@@ -229,26 +295,6 @@
229 (if (forward-comment count) 295 (if (forward-comment count)
230 (if (eolp) (forward-comment -1) t)))))) 296 (if (eolp) (forward-comment -1) t))))))
231 297
232(defmacro c-add-syntax (symbol &optional relpos)
233 ;; a simple macro to append the syntax in symbol to the syntax list.
234 ;; try to increase performance by using this macro
235 `(setq syntax (cons (cons ,symbol ,relpos) syntax)))
236
237(defmacro c-add-class-syntax (symbol classkey)
238 ;; The inclass and class-close syntactic symbols are added in
239 ;; several places and some work is needed to fix everything.
240 ;; Therefore it's collected here.
241 `(save-restriction
242 (widen)
243 (let ((symbol ,symbol)
244 (classkey ,classkey))
245 (goto-char (aref classkey 1))
246 (if (and (eq symbol 'inclass) (= (point) (c-point 'boi)))
247 (c-add-syntax symbol (point))
248 (c-add-syntax symbol (aref classkey 0))
249 (if (and c-inexpr-class-key (c-looking-at-inexpr-block))
250 (c-add-syntax 'inexpr-class))))))
251
252(defsubst c-intersect-lists (list alist) 298(defsubst c-intersect-lists (list alist)
253 ;; return the element of ALIST that matches the first element found 299 ;; return the element of ALIST that matches the first element found
254 ;; in LIST. Uses assq. 300 ;; in LIST. Uses assq.
@@ -275,19 +321,9 @@
275 )) 321 ))
276 0)) 322 0))
277 323
278(defmacro c-update-modeline ()
279 ;; set the c-auto-hungry-string for the correct designation on the modeline
280 `(progn
281 (setq c-auto-hungry-string
282 (if c-auto-newline
283 (if c-hungry-delete-key "/ah" "/a")
284 (if c-hungry-delete-key "/h" nil)))
285 (force-mode-line-update)))
286
287(defsubst c-keep-region-active () 324(defsubst c-keep-region-active ()
288 ;; Do whatever is necessary to keep the region active in XEmacs. 325 ;; Do whatever is necessary to keep the region active in XEmacs.
289 ;; Ignore byte-compiler warnings you might see. This is not needed 326 ;; This is not needed for Emacs.
290 ;; for Emacs.
291 (and (boundp 'zmacs-region-stays) 327 (and (boundp 'zmacs-region-stays)
292 (setq zmacs-region-stays t))) 328 (setq zmacs-region-stays t)))
293 329
@@ -308,17 +344,6 @@
308(defsubst c-major-mode-is (mode) 344(defsubst c-major-mode-is (mode)
309 (eq (derived-mode-class major-mode) mode)) 345 (eq (derived-mode-class major-mode) mode))
310 346
311(defmacro c-with-syntax-table (table &rest code)
312 ;; Temporarily switches to the specified syntax table in a failsafe
313 ;; way to execute code.
314 `(let ((c-with-syntax-table-orig-table (syntax-table)))
315 (unwind-protect
316 (progn
317 (set-syntax-table ,table)
318 ,@code)
319 (set-syntax-table c-with-syntax-table-orig-table))))
320(put 'c-with-syntax-table 'lisp-indent-function 1)
321
322 347
323(provide 'cc-defs) 348(cc-provide 'cc-defs)
324;;; cc-defs.el ends here 349;;; cc-defs.el ends here
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index a2ed75e1520..50613a21ad4 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -1,6 +1,6 @@
1;;; cc-engine.el --- core syntax guessing engine for CC mode 1;;; cc-engine.el --- core syntax guessing engine for CC mode
2 2
3;; Copyright (C) 1985,87,92,93,94,95,96,97,98,99,2000 Free Software Foundation, Inc. 3;; Copyright (C) 1985,1987,1992-2001 Free Software Foundation, Inc.
4 4
5;; Authors: 2000- Martin Stjernholm 5;; Authors: 2000- Martin Stjernholm
6;; 1998-1999 Barry A. Warsaw and Martin Stjernholm 6;; 1998-1999 Barry A. Warsaw and Martin Stjernholm
@@ -25,21 +25,29 @@
25;; GNU General Public License for more details. 25;; GNU General Public License for more details.
26 26
27;; 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
28;; along with GNU Emacs; see the file COPYING. If not, write to the 28;; along with this program; see the file COPYING. If not, write to
29;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 29;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
30;; Boston, MA 02111-1307, USA. 30;; Boston, MA 02111-1307, USA.
31 31
32(eval-when-compile 32(eval-when-compile
33 (let ((load-path 33 (let ((load-path
34 (if (and (boundp 'byte-compile-current-file) 34 (if (and (boundp 'byte-compile-dest-file)
35 (stringp byte-compile-current-file)) 35 (stringp byte-compile-dest-file))
36 (cons (file-name-directory byte-compile-current-file) 36 (cons (file-name-directory byte-compile-dest-file) load-path)
37 load-path)
38 load-path))) 37 load-path)))
39 (load "cc-defs" nil t))) 38 (require 'cc-bytecomp)))
40(require 'cc-langs) 39
40(cc-require 'cc-defs)
41(cc-require 'cc-vars)
42(cc-require 'cc-langs)
43
44;; Silence the compiler.
45(cc-bytecomp-defun buffer-syntactic-context) ; XEmacs
41 46
42 47
48(defvar c-state-cache nil)
49(defvar c-in-literal-cache t)
50
43;; KLUDGE ALERT: c-maybe-labelp is used to pass information between 51;; KLUDGE ALERT: c-maybe-labelp is used to pass information between
44;; c-crosses-statement-barrier-p and c-beginning-of-statement-1. A 52;; c-crosses-statement-barrier-p and c-beginning-of-statement-1. A
45;; better way should be implemented, but this will at least shut up 53;; better way should be implemented, but this will at least shut up
@@ -203,7 +211,7 @@
203 ;; We always want to skip over the non-whitespace modifier 211 ;; We always want to skip over the non-whitespace modifier
204 ;; characters that can start a statement. 212 ;; characters that can start a statement.
205 (let ((lim (point))) 213 (let ((lim (point)))
206 (skip-chars-backward "-+!*&~@` \t\n" (c-point 'boi)) 214 (skip-chars-backward "-+!*&~@`# \t\n" (c-point 'boi))
207 (skip-chars-forward " \t\n" lim)))) 215 (skip-chars-forward " \t\n" lim))))
208 216
209(defun c-end-of-statement-1 () 217(defun c-end-of-statement-1 ()
@@ -258,6 +266,22 @@
258 crossedp)) 266 crossedp))
259 267
260 268
269(defun c-beginning-of-macro (&optional lim)
270 ;; Go to the beginning of a cpp macro definition. Leaves point at
271 ;; the beginning of the macro and returns t if in a cpp macro
272 ;; definition, otherwise returns nil and leaves point unchanged.
273 ;; `lim' is currently ignored, but the interface requires it.
274 (let ((here (point)))
275 (beginning-of-line)
276 (while (eq (char-before (1- (point))) ?\\)
277 (forward-line -1))
278 (back-to-indentation)
279 (if (and (<= (point) here)
280 (eq (char-after) ?#))
281 t
282 (goto-char here)
283 nil)))
284
261;; Skipping of "syntactic whitespace", defined as lexical whitespace, 285;; Skipping of "syntactic whitespace", defined as lexical whitespace,
262;; C and C++ style comments, and preprocessor directives. Search no 286;; C and C++ style comments, and preprocessor directives. Search no
263;; farther back or forward than optional LIM. If LIM is omitted, 287;; farther back or forward than optional LIM. If LIM is omitted,
@@ -317,26 +341,25 @@
317 '(?w ?_ ?\" ?\\ ?/ ?'))) 341 '(?w ?_ ?\" ?\\ ?/ ?')))
318 (last (point)) 342 (last (point))
319 (prev (point))) 343 (prev (point)))
320 (if (/= (point)
321 (progn (c-forward-syntactic-ws) (point)))
322 ;; Skip whitespace. Count this as a move if we did in fact
323 ;; move and aren't out of bounds.
324 (or (eobp)
325 (and lim (> (point) lim))
326 (setq count (max (1- count) 0))))
327 (if (and (= count 0)
328 (or (and (memq (char-syntax (or (char-after) ? )) '(?w ?_))
329 (memq (char-syntax (or (char-before) ? )) '(?w ?_)))
330 (eobp)))
331 ;; If count is zero we should jump if in the middle of a
332 ;; token or if there is whitespace between point and the
333 ;; following token beginning.
334 (setq count 1))
335 ;; Avoid having the limit tests inside the loop.
336 (save-restriction 344 (save-restriction
337 (if lim (narrow-to-region (point-min) lim)) 345 (if lim (narrow-to-region (point-min) lim))
346 (if (/= (point)
347 (progn (c-forward-syntactic-ws) (point)))
348 ;; Skip whitespace. Count this as a move if we did in fact
349 ;; move and aren't out of bounds.
350 (or (eobp)
351 (setq count (max (1- count) 0))))
352 (if (and (= count 0)
353 (or (and (memq (char-syntax (or (char-after) ? )) '(?w ?_))
354 (memq (char-syntax (or (char-before) ? )) '(?w ?_)))
355 (eobp)))
356 ;; If count is zero we should jump if in the middle of a
357 ;; token or if there is whitespace between point and the
358 ;; following token beginning.
359 (setq count 1))
338 (if (eobp) 360 (if (eobp)
339 (goto-char last) 361 (goto-char last)
362 ;; Avoid having the limit tests inside the loop.
340 (condition-case nil 363 (condition-case nil
341 (while (> count 0) 364 (while (> count 0)
342 (setq prev last 365 (setq prev last
@@ -370,11 +393,11 @@
370 ;; token or if there is whitespace between point and the 393 ;; token or if there is whitespace between point and the
371 ;; following token beginning. 394 ;; following token beginning.
372 (setq count 1)) 395 (setq count 1))
373 ;; Avoid having the limit tests inside the loop.
374 (save-restriction 396 (save-restriction
375 (if lim (narrow-to-region lim (point-max))) 397 (if lim (narrow-to-region lim (point-max)))
376 (or (bobp) 398 (or (bobp)
377 (progn 399 (progn
400 ;; Avoid having the limit tests inside the loop.
378 (condition-case nil 401 (condition-case nil
379 (while (progn 402 (while (progn
380 (setq last (point)) 403 (setq last (point))
@@ -398,8 +421,7 @@
398(defun c-in-literal (&optional lim) 421(defun c-in-literal (&optional lim)
399 ;; Determine if point is in a C++ literal. we cache the last point 422 ;; Determine if point is in a C++ literal. we cache the last point
400 ;; calculated if the cache is enabled 423 ;; calculated if the cache is enabled
401 (if (and (boundp 'c-in-literal-cache) 424 (if (and (vectorp c-in-literal-cache)
402 c-in-literal-cache
403 (= (point) (aref c-in-literal-cache 0))) 425 (= (point) (aref c-in-literal-cache 0)))
404 (aref c-in-literal-cache 1) 426 (aref c-in-literal-cache 1)
405 (let ((rtn (save-excursion 427 (let ((rtn (save-excursion
@@ -411,8 +433,8 @@
411 ((c-beginning-of-macro lim) 'pound) 433 ((c-beginning-of-macro lim) 'pound)
412 (t nil)))))) 434 (t nil))))))
413 ;; cache this result if the cache is enabled 435 ;; cache this result if the cache is enabled
414 (and (boundp 'c-in-literal-cache) 436 (if (not c-in-literal-cache)
415 (setq c-in-literal-cache (vector (point) rtn))) 437 (setq c-in-literal-cache (vector (point) rtn)))
416 rtn))) 438 rtn)))
417 439
418;; XEmacs has a built-in function that should make this much quicker. 440;; XEmacs has a built-in function that should make this much quicker.
@@ -573,11 +595,16 @@
573 (looking-at "//"))) 595 (looking-at "//")))
574 (let ((col (current-column)) 596 (let ((col (current-column))
575 (beg (point)) 597 (beg (point))
598 (bopl (c-point 'bopl))
576 (end (cdr range))) 599 (end (cdr range)))
600 ;; Got to take care in the backward direction to handle
601 ;; comments which are preceded by code.
577 (while (and (c-forward-comment -1) 602 (while (and (c-forward-comment -1)
603 (>= (point) bopl)
578 (looking-at "//") 604 (looking-at "//")
579 (= col (current-column))) 605 (= col (current-column)))
580 (setq beg (point))) 606 (setq beg (point)
607 bopl (c-point 'bopl)))
581 (goto-char end) 608 (goto-char end)
582 (while (and (progn (skip-chars-forward " \t") 609 (while (and (progn (skip-chars-forward " \t")
583 (looking-at "//")) 610 (looking-at "//"))
@@ -611,8 +638,7 @@
611 ;; earlier in the file and point. 638 ;; earlier in the file and point.
612 ;; 639 ;;
613 ;; if there's a state cache, return it 640 ;; if there's a state cache, return it
614 (setq c-parsing-error nil) 641 (if c-state-cache c-state-cache
615 (if (boundp 'c-state-cache) c-state-cache
616 (let* (at-bob 642 (let* (at-bob
617 (pos (save-excursion 643 (pos (save-excursion
618 ;; go back 2 bods, but ignore any bogus positions 644 ;; go back 2 bods, but ignore any bogus positions
@@ -641,7 +667,7 @@
641 (here (save-excursion 667 (here (save-excursion
642 ;;(skip-chars-forward " \t}") 668 ;;(skip-chars-forward " \t}")
643 (point))) 669 (point)))
644 (last-bod pos) (last-pos pos) 670 (last-bod here) (last-pos pos)
645 placeholder state sexp-end) 671 placeholder state sexp-end)
646 ;; cache last bod position 672 ;; cache last bod position
647 (while (catch 'backup-bod 673 (while (catch 'backup-bod
@@ -680,9 +706,13 @@
680 (while t 706 (while t
681 (setq last-bod (c-safe (scan-lists last-bod -1 1))) 707 (setq last-bod (c-safe (scan-lists last-bod -1 1)))
682 (if (not last-bod) 708 (if (not last-bod)
683 (progn 709 (save-excursion
684 ;; bogus, but what can we do here? 710 ;; bogus, but what can we do here?
685 (setq c-parsing-error (1- placeholder)) 711 (goto-char placeholder)
712 (beginning-of-line)
713 (setq c-parsing-error
714 (format "\
715Unbalanced close brace at line %d" (1+ (count-lines 1 (point)))))
686 (throw 'backup-bod nil)) 716 (throw 'backup-bod nil))
687 (setq at-bob (= last-bod (point-min)) 717 (setq at-bob (= last-bod (point-min))
688 pos last-bod) 718 pos last-bod)
@@ -910,13 +940,11 @@ brace."
910(defun c-backward-to-start-of-if (&optional lim) 940(defun c-backward-to-start-of-if (&optional lim)
911 ;; Move to the start of the last "unbalanced" if and return t. If 941 ;; Move to the start of the last "unbalanced" if and return t. If
912 ;; none is found, and we are looking at an if clause, nil is 942 ;; none is found, and we are looking at an if clause, nil is
913 ;; returned. If none is found and we are looking at an else clause, 943 ;; returned.
914 ;; an error is thrown.
915 (let ((if-level 1) 944 (let ((if-level 1)
916 (here (c-point 'bol)) 945 (here (c-point 'bol))
917 (case-fold-search nil) 946 (case-fold-search nil)
918 (lim (or (and (>= (point) lim) 947 (lim (or (and lim (>= (point) lim) lim)
919 lim)
920 (c-point 'bod))) 948 (c-point 'bod)))
921 (at-if (looking-at "if\\b[^_]"))) 949 (at-if (looking-at "if\\b[^_]")))
922 (catch 'orphan-if 950 (catch 'orphan-if
@@ -926,10 +954,13 @@ brace."
926 (condition-case nil 954 (condition-case nil
927 (c-backward-sexp 1) 955 (c-backward-sexp 1)
928 (error 956 (error
929 (if at-if 957 (unless at-if
930 (throw 'orphan-if nil) 958 (goto-char here)
931 (error "No matching `if' found for `else' on line %d." 959 (c-beginning-of-statement-1)
932 (1+ (count-lines 1 here)))))) 960 (setq c-parsing-error
961 (format "No matching `if' found for `else' on line %d"
962 (1+ (count-lines 1 here))))
963 (throw 'orphan-if nil))))
933 (cond 964 (cond
934 ((looking-at "else\\b[^_]") 965 ((looking-at "else\\b[^_]")
935 (setq if-level (1+ if-level))) 966 (setq if-level (1+ if-level)))
@@ -937,7 +968,7 @@ brace."
937 ;; check for else if... skip over 968 ;; check for else if... skip over
938 (let ((here (point))) 969 (let ((here (point)))
939 (c-safe (c-forward-sexp -1)) 970 (c-safe (c-forward-sexp -1))
940 (if (looking-at "\\<else\\>[ \t]+\\<if\\>") 971 (if (looking-at "\\<else\\>[ \t]+\\<if\\>[^_]")
941 nil 972 nil
942 (setq if-level (1- if-level)) 973 (setq if-level (1- if-level))
943 (goto-char here)))) 974 (goto-char here))))
@@ -952,9 +983,11 @@ brace."
952 ;; statements in parentheses. No error checking is performed. 983 ;; statements in parentheses. No error checking is performed.
953 (c-forward-sexp (cond 984 (c-forward-sexp (cond
954 ;; else if() 985 ;; else if()
955 ((looking-at "\\<else\\>[ \t]+\\<if\\>") 3) 986 ((looking-at "\\<else\\>[ \t]+\\<if\\>\\([^_]\\|$\\)") 3)
956 ;; do, else, try, finally 987 ;; do, else, try, finally
957 ((looking-at "\\<\\(do\\|else\\|try\\|finally\\)\\>") 1) 988 ((looking-at
989 "\\<\\(do\\|else\\|try\\|finally\\)\\>\\([^_]\\|$\\)")
990 1)
958 ;; for, if, while, switch, catch, synchronized, foreach 991 ;; for, if, while, switch, catch, synchronized, foreach
959 (t 2)))) 992 (t 2))))
960 993
@@ -991,25 +1024,31 @@ brace."
991 (if (eq (char-after) ?,) 1024 (if (eq (char-after) ?,)
992 (forward-char 1) 1025 (forward-char 1)
993 (c-backward-syntactic-ws limit)) 1026 (c-backward-syntactic-ws limit))
994 (while (and (< limit (point)) 1027 (c-with-syntax-table (if (c-major-mode-is 'c++-mode)
995 (eq (char-before) ?,)) 1028 c++-template-syntax-table
996 ;; this will catch member inits with multiple 1029 (syntax-table))
997 ;; line arglists 1030 (while (and (< limit (point))
998 (forward-char -1) 1031 (eq (char-before) ?,))
999 (c-backward-syntactic-ws) 1032 ;; this will catch member inits with multiple
1000 (if (eq (char-before) ?\)) 1033 ;; line arglists
1001 (c-backward-sexp 2) 1034 (forward-char -1)
1002 (c-backward-sexp 1)) 1035 (c-backward-syntactic-ws)
1003 ;; Skip backwards over a fully::qualified::name. 1036 (if (eq (char-before) ?\))
1004 (c-backward-syntactic-ws limit) 1037 (c-backward-sexp 2)
1005 (while (and (eq (char-before) ?:) 1038 (c-backward-sexp 1))
1006 (save-excursion 1039 ;; Skip over any template arg to the class.
1007 (forward-char -1) 1040 (if (eq (char-after) ?<)
1008 (eq (char-before) ?:))) 1041 (c-backward-sexp 1))
1009 (backward-char 2) 1042 ;; Skip backwards over a fully::qualified::name.
1010 (c-backward-sexp 1)) 1043 (c-backward-syntactic-ws limit)
1011 ;; now continue checking 1044 (while (and (eq (char-before) ?:)
1012 (c-backward-syntactic-ws limit)) 1045 (save-excursion
1046 (forward-char -1)
1047 (eq (char-before) ?:)))
1048 (backward-char 2)
1049 (c-backward-sexp 1))
1050 ;; now continue checking
1051 (c-backward-syntactic-ws limit)))
1013 (and (< limit (point)) 1052 (and (< limit (point))
1014 (eq (char-before) ?:))) 1053 (eq (char-before) ?:)))
1015 1054
@@ -1160,7 +1199,8 @@ brace."
1160 ;; return the buffer position of the beginning of the brace list 1199 ;; return the buffer position of the beginning of the brace list
1161 ;; statement if we're inside a brace list, otherwise return nil. 1200 ;; statement if we're inside a brace list, otherwise return nil.
1162 ;; CONTAINING-SEXP is the buffer pos of the innermost containing 1201 ;; CONTAINING-SEXP is the buffer pos of the innermost containing
1163 ;; paren. BRACE-STATE is the remainder of the state of enclosing braces 1202 ;; paren. BRACE-STATE is the remainder of the state of enclosing
1203 ;; braces
1164 ;; 1204 ;;
1165 ;; N.B.: This algorithm can potentially get confused by cpp macros 1205 ;; N.B.: This algorithm can potentially get confused by cpp macros
1166 ;; places in inconvenient locations. Its a trade-off we make for 1206 ;; places in inconvenient locations. Its a trade-off we make for
@@ -1213,7 +1253,7 @@ brace."
1213 (while (eq braceassignp 'dontknow) 1253 (while (eq braceassignp 'dontknow)
1214 (setq braceassignp 1254 (setq braceassignp
1215 (cond ((/= (c-backward-token-1 1 t lim) 0) nil) 1255 (cond ((/= (c-backward-token-1 1 t lim) 0) nil)
1216 ((looking-at "new\\>") t) 1256 ((looking-at "new\\>[^_]") t)
1217 ((looking-at "\\sw\\|\\s_\\|[.[]") 1257 ((looking-at "\\sw\\|\\s_\\|[.[]")
1218 ;; Carry on looking if this is an 1258 ;; Carry on looking if this is an
1219 ;; identifier (may contain "." in Java) 1259 ;; identifier (may contain "." in Java)
@@ -1238,22 +1278,29 @@ brace."
1238 (cond 1278 (cond
1239 ;; Check for operator = 1279 ;; Check for operator =
1240 ((looking-at "operator\\>") nil) 1280 ((looking-at "operator\\>") nil)
1241 ;; Check for `<opchar>= (Pike) 1281 ;; Check for `<opchar>= in Pike.
1242 ((eq (char-after) ?`) nil) 1282 ((and (c-major-mode-is 'pike-mode)
1283 (or (eq (char-after) ?`)
1284 ;; Special case for Pikes
1285 ;; `[]=, since '[' is not in
1286 ;; the punctuation class.
1287 (and (eq (char-after) ?\[)
1288 (eq (char-before) ?`))))
1289 nil)
1243 ((looking-at "\\s.") 'maybe) 1290 ((looking-at "\\s.") 'maybe)
1244 ;; make sure we're not in a C++ template 1291 ;; make sure we're not in a C++ template
1245 ;; argument assignment 1292 ;; argument assignment
1246 ((save-excursion 1293 ((and (c-major-mode-is 'c++-mode)
1247 (let ((here (point)) 1294 (save-excursion
1248 (pos< (progn 1295 (let ((here (point))
1249 (skip-chars-backward "^<") 1296 (pos< (progn
1250 (point)))) 1297 (skip-chars-backward "^<>")
1251 (and (c-major-mode-is 'c++-mode) 1298 (point))))
1252 (eq (char-before) ?<) 1299 (and (eq (char-before) ?<)
1253 (not (c-crosses-statement-barrier-p 1300 (not (c-crosses-statement-barrier-p
1254 pos< here)) 1301 pos< here))
1255 (not (c-in-literal)) 1302 (not (c-in-literal))
1256 ))) 1303 ))))
1257 nil) 1304 nil)
1258 (t t)))))) 1305 (t t))))))
1259 (if (and (eq braceassignp 'dontknow) 1306 (if (and (eq braceassignp 'dontknow)
@@ -1394,6 +1441,28 @@ brace."
1394 (if (>= (point) lim) 1441 (if (>= (point) lim)
1395 (c-looking-at-inexpr-block lim)))))))) 1442 (c-looking-at-inexpr-block lim))))))))
1396 1443
1444(defun c-on-identifier ()
1445 ;; Returns non-nil if we're on or directly after an identifier.
1446 (if (or (memq (char-syntax (or (char-after) ? )) '(?w ?_))
1447 (memq (char-syntax (or (char-before) ? )) '(?w ?_)))
1448 (save-excursion
1449 (skip-syntax-backward "w_")
1450 (not (looking-at c-keywords)))
1451 (if (c-major-mode-is 'pike-mode)
1452 ;; Handle the `<operator> syntax in Pike.
1453 (save-excursion
1454 (if (eq (char-after) ?\`) (forward-char))
1455 (skip-chars-backward "!%&*+\\-/<=>^|~")
1456 (let ((pos (point)))
1457 (cond ((memq (char-before) '(?\) ?\]))
1458 (c-safe (backward-char 2)))
1459 ((memq (char-before) '(?\( ?\[))
1460 (c-safe (backward-char 1))))
1461 (if (not (looking-at "()\\|\\[]"))
1462 (goto-char pos)))
1463 (and (eq (char-before) ?\`)
1464 (looking-at "[-!%&*+/<=>^|~]\\|()\\|\\[]"))))))
1465
1397 1466
1398(defun c-most-enclosing-brace (state) 1467(defun c-most-enclosing-brace (state)
1399 ;; return the bufpos of the most enclosing brace that hasn't been 1468 ;; return the bufpos of the most enclosing brace that hasn't been
@@ -1562,8 +1631,10 @@ brace."
1562 'inline-open 1631 'inline-open
1563 'lambda-intro-cont))) 1632 'lambda-intro-cont)))
1564 (goto-char (cdr placeholder)) 1633 (goto-char (cdr placeholder))
1565 (c-add-syntax tmpsymbol (c-point 'boi)) 1634 (back-to-indentation)
1566 (c-add-syntax (car placeholder))) 1635 (c-add-syntax tmpsymbol (point))
1636 (unless (eq (point) (cdr placeholder))
1637 (c-add-syntax (car placeholder))))
1567 ;; CASE 5: Line is at top level. 1638 ;; CASE 5: Line is at top level.
1568 ((null containing-sexp) 1639 ((null containing-sexp)
1569 (cond 1640 (cond
@@ -1602,12 +1673,7 @@ brace."
1602 ;; to go through much chicanery to ignore the cache. 1673 ;; to go through much chicanery to ignore the cache.
1603 ;; But of course, there may not be! BLECH! BOGUS! 1674 ;; But of course, there may not be! BLECH! BOGUS!
1604 (let ((decl 1675 (let ((decl
1605 (if (boundp 'c-state-cache) 1676 (let ((c-state-cache nil))
1606 (let ((old-cache c-state-cache))
1607 (prog2
1608 (makunbound 'c-state-cache)
1609 (c-search-uplist-for-classkey (c-parse-state))
1610 (setq c-state-cache old-cache)))
1611 (c-search-uplist-for-classkey (c-parse-state)) 1677 (c-search-uplist-for-classkey (c-parse-state))
1612 ))) 1678 )))
1613 (and decl 1679 (and decl
@@ -1625,20 +1691,38 @@ brace."
1625 (c-forward-syntactic-ws indent-point))) 1691 (c-forward-syntactic-ws indent-point)))
1626 (setq placeholder (c-point 'boi)) 1692 (setq placeholder (c-point 'boi))
1627 (or (consp special-brace-list) 1693 (or (consp special-brace-list)
1628 (and (or (looking-at "enum[ \t\n]+") 1694 (and (or (save-excursion
1629 (save-excursion
1630 (goto-char indent-point) 1695 (goto-char indent-point)
1696 (setq tmpsymbol nil)
1631 (while (and (> (point) placeholder) 1697 (while (and (> (point) placeholder)
1632 (= (c-backward-token-1 1 t) 0) 1698 (= (c-backward-token-1 1 t) 0)
1633 (/= (char-after) ?=))) 1699 (/= (char-after) ?=))
1634 (eq (char-after) ?=))) 1700 (if (and (not tmpsymbol)
1701 (looking-at "new\\>[^_]"))
1702 (setq tmpsymbol 'topmost-intro-cont)))
1703 (eq (char-after) ?=))
1704 (looking-at "enum[ \t\n]+"))
1635 (save-excursion 1705 (save-excursion
1636 (while (and (< (point) indent-point) 1706 (while (and (< (point) indent-point)
1637 (= (c-forward-token-1 1 t) 0) 1707 (= (c-forward-token-1 1 t) 0)
1638 (not (memq (char-after) '(?\; ?\())))) 1708 (not (memq (char-after) '(?\; ?\()))))
1639 (not (memq (char-after) '(?\; ?\())) 1709 (not (memq (char-after) '(?\; ?\()))
1640 )))) 1710 ))))
1641 (c-add-syntax 'brace-list-open placeholder)) 1711 (if (and (c-major-mode-is 'java-mode)
1712 (eq tmpsymbol 'topmost-intro-cont))
1713 ;; We're in Java and have found that the open brace
1714 ;; belongs to a "new Foo[]" initialization list,
1715 ;; which means the brace list is part of an
1716 ;; expression and not a top level definition. We
1717 ;; therefore treat it as any topmost continuation
1718 ;; even though the semantically correct symbol still
1719 ;; is brace-list-open, on the same grounds as in
1720 ;; case 10B.2.
1721 (progn
1722 (c-beginning-of-statement-1 lim)
1723 (c-forward-syntactic-ws)
1724 (c-add-syntax 'topmost-intro-cont (c-point 'boi)))
1725 (c-add-syntax 'brace-list-open placeholder)))
1642 ;; CASE 5A.4: inline defun open 1726 ;; CASE 5A.4: inline defun open
1643 ((and inclass-p (not inenclosing-p)) 1727 ((and inclass-p (not inenclosing-p))
1644 (c-add-syntax 'inline-open) 1728 (c-add-syntax 'inline-open)
@@ -2042,14 +2126,10 @@ brace."
2042 ;; opening paren. This case includes multi-line 2126 ;; opening paren. This case includes multi-line
2043 ;; mathematical paren groupings, but we could be on a 2127 ;; mathematical paren groupings, but we could be on a
2044 ;; for-list continuation line 2128 ;; for-list continuation line
2045 ((and (save-excursion 2129 ((save-excursion
2046 (goto-char (1+ containing-sexp)) 2130 (goto-char (1+ containing-sexp))
2047 (skip-chars-forward " \t") 2131 (skip-chars-forward " \t")
2048 (not (eolp))) 2132 (not (eolp)))
2049 (save-excursion
2050 (c-beginning-of-statement-1 lim)
2051 (skip-chars-backward " \t([")
2052 (<= (point) containing-sexp)))
2053 (goto-char containing-sexp) 2133 (goto-char containing-sexp)
2054 (setq placeholder (c-point 'boi)) 2134 (setq placeholder (c-point 'boi))
2055 (when (and (c-safe (backward-up-list 1) t) 2135 (when (and (c-safe (backward-up-list 1) t)
@@ -2102,8 +2182,10 @@ brace."
2102 (eq char-after-ip (car (cdr special-brace-list)))) 2182 (eq char-after-ip (car (cdr special-brace-list))))
2103 (goto-char (car (car special-brace-list))) 2183 (goto-char (car (car special-brace-list)))
2104 (skip-chars-backward " \t") 2184 (skip-chars-backward " \t")
2105 (if (bolp) 2185 (if (and (bolp)
2106 (setq syntax (c-guess-basic-syntax)) 2186 (assoc 'statement-cont
2187 (setq placeholder (c-guess-basic-syntax))))
2188 (setq syntax placeholder)
2107 (c-beginning-of-statement-1 lim) 2189 (c-beginning-of-statement-1 lim)
2108 (c-forward-token-1 0) 2190 (c-forward-token-1 0)
2109 (if (looking-at "typedef\\>") (c-forward-token-1 1)) 2191 (if (looking-at "typedef\\>") (c-forward-token-1 1))
@@ -2151,7 +2233,7 @@ brace."
2151 (c-add-syntax 'brace-list-intro (c-point 'boi)) 2233 (c-add-syntax 'brace-list-intro (c-point 'boi))
2152 ) ; end CASE 9C 2234 ) ; end CASE 9C
2153 ;; CASE 9D: this is just a later brace-list-entry or 2235 ;; CASE 9D: this is just a later brace-list-entry or
2154 ;; brace-entry-open 2236 ;; brace-entry-open
2155 (t (if (or (eq char-after-ip ?{) 2237 (t (if (or (eq char-after-ip ?{)
2156 (and c-special-brace-lists 2238 (and c-special-brace-lists
2157 (save-excursion 2239 (save-excursion
@@ -2346,8 +2428,10 @@ brace."
2346 (if (= containing-sexp (point)) 2428 (if (= containing-sexp (point))
2347 (c-add-syntax tmpsymbol (point)) 2429 (c-add-syntax tmpsymbol (point))
2348 (goto-char (cdr placeholder)) 2430 (goto-char (cdr placeholder))
2349 (c-add-syntax tmpsymbol (c-point 'boi)) 2431 (back-to-indentation)
2350 (c-add-syntax (car placeholder)))) 2432 (c-add-syntax tmpsymbol (point))
2433 (if (/= (point) (cdr placeholder))
2434 (c-add-syntax (car placeholder)))))
2351 ;; CASE 16B: does this close an inline or a function in 2435 ;; CASE 16B: does this close an inline or a function in
2352 ;; an extern block or namespace? 2436 ;; an extern block or namespace?
2353 ((progn 2437 ((progn
@@ -2480,8 +2564,10 @@ brace."
2480 (if (= containing-sexp (point)) 2564 (if (= containing-sexp (point))
2481 (c-add-syntax block-intro (point)) 2565 (c-add-syntax block-intro (point))
2482 (goto-char (cdr placeholder)) 2566 (goto-char (cdr placeholder))
2483 (c-add-syntax block-intro (c-point 'boi)) 2567 (back-to-indentation)
2484 (c-add-syntax (car placeholder)))) 2568 (c-add-syntax block-intro (point))
2569 (if (/= (point) (cdr placeholder))
2570 (c-add-syntax (car placeholder)))))
2485 (if (eq char-after-ip ?{) 2571 (if (eq char-after-ip ?{)
2486 (c-add-syntax 'block-open))) 2572 (c-add-syntax 'block-open)))
2487 ;; CASE 17F: first statement in an inline, or first 2573 ;; CASE 17F: first statement in an inline, or first
@@ -2533,7 +2619,8 @@ brace."
2533 (skip-chars-forward " \t") 2619 (skip-chars-forward " \t")
2534 (cond 2620 (cond
2535 ;; are we looking at a comment only line? 2621 ;; are we looking at a comment only line?
2536 ((looking-at c-comment-start-regexp) 2622 ((and (looking-at c-comment-start-regexp)
2623 (/= (c-forward-token-1 0 nil (c-point 'eol)) 0))
2537 (c-add-syntax 'comment-intro)) 2624 (c-add-syntax 'comment-intro))
2538 ;; we might want to give additional offset to friends (in C++). 2625 ;; we might want to give additional offset to friends (in C++).
2539 ((and (c-major-mode-is 'c++-mode) 2626 ((and (c-major-mode-is 'c++-mode)
@@ -2544,17 +2631,17 @@ brace."
2544 (= (save-excursion 2631 (= (save-excursion
2545 (c-beginning-of-macro lim) 2632 (c-beginning-of-macro lim)
2546 (setq placeholder (point))) 2633 (setq placeholder (point)))
2547 (c-point 'boi))) 2634 (c-point 'boi))
2635 (not (and (c-major-mode-is 'pike-mode)
2636 (eq (char-after (1+ placeholder)) ?\"))))
2548 (c-add-syntax 'cpp-macro))) 2637 (c-add-syntax 'cpp-macro)))
2549 ;; return the syntax 2638 ;; return the syntax
2550 syntax)))) 2639 syntax))))
2551 2640
2552 2641
2553(defun c-echo-parsing-error () 2642(defun c-echo-parsing-error (&optional quiet)
2554 (if (not c-parsing-error) 2643 (when (and c-parsing-error (not quiet))
2555 nil 2644 (message "%s" c-parsing-error)
2556 (message "unbalanced close brace at bufpos %d -- INDENTATION IS SUSPECT!"
2557 c-parsing-error)
2558 (ding)) 2645 (ding))
2559 c-parsing-error) 2646 c-parsing-error)
2560 2647
@@ -2573,21 +2660,99 @@ brace."
2573 (if (> (- (point-max) pos) (point)) 2660 (if (> (- (point-max) pos) (point))
2574 (goto-char (- (point-max) pos)))))) 2661 (goto-char (- (point-max) pos))))))
2575 2662
2576(defun c-indent-line (&optional syntax) 2663(defun c-evaluate-offset (offset langelem symbol)
2577 ;; Indent the current line as C/C++/ObjC code, if 2664 ;; offset can be a number, a function, a variable, a list, or one of
2665 ;; the symbols + or -
2666 (cond
2667 ((eq offset '+) c-basic-offset)
2668 ((eq offset '-) (- c-basic-offset))
2669 ((eq offset '++) (* 2 c-basic-offset))
2670 ((eq offset '--) (* 2 (- c-basic-offset)))
2671 ((eq offset '*) (/ c-basic-offset 2))
2672 ((eq offset '/) (/ (- c-basic-offset) 2))
2673 ((numberp offset) offset)
2674 ((functionp offset) (c-evaluate-offset
2675 (funcall offset langelem) langelem symbol))
2676 ((vectorp offset) offset)
2677 ((null offset) nil)
2678 ((listp offset)
2679 (let (done)
2680 (while (and (not done) offset)
2681 (setq done (c-evaluate-offset (car offset) langelem symbol)
2682 offset (cdr offset)))
2683 (if (not done)
2684 (if c-strict-syntax-p
2685 (error "No offset found for syntactic symbol %s" symbol))
2686 done)))
2687 (t (symbol-value offset))
2688 ))
2689
2690(defun c-get-offset (langelem)
2691 ;; Get offset from LANGELEM which is a cons cell of the form:
2692 ;; (SYMBOL . RELPOS). The symbol is matched against
2693 ;; c-offsets-alist and the offset found there is either returned,
2694 ;; or added to the indentation at RELPOS. If RELPOS is nil, then
2695 ;; the offset is simply returned.
2696 (let* ((symbol (car langelem))
2697 (relpos (cdr langelem))
2698 (match (assq symbol c-offsets-alist))
2699 (offset (cdr-safe match)))
2700 (if (not match)
2701 (if c-strict-syntax-p
2702 (error "No offset found for syntactic symbol %s" symbol)
2703 (setq offset 0
2704 relpos 0))
2705 (setq offset (c-evaluate-offset offset langelem symbol)))
2706 (if (vectorp offset)
2707 offset
2708 (+ (if (and relpos
2709 (< relpos (c-point 'bol)))
2710 (save-excursion
2711 (goto-char relpos)
2712 (current-column))
2713 0)
2714 (or (and (numberp offset) offset)
2715 (and (symbolp offset) (symbol-value offset))
2716 0)))
2717 ))
2718
2719(defun c-get-syntactic-indentation (langelems)
2720 ;; Apply c-get-offset to a list of langelem cells to get the total
2721 ;; syntactic indentation. Special treatment is needed for vectors
2722 ;; containing absolute columns.
2723 (let ((indent 0))
2724 (catch 'done
2725 (while langelems
2726 (let ((res (c-get-offset (car langelems))))
2727 (if (vectorp res)
2728 (throw 'done (elt res 0))
2729 (setq indent (+ indent res)
2730 langelems (cdr langelems)))))
2731 indent)))
2732
2733(defun c-indent-line (&optional syntax quiet)
2734 ;; Indent the current line according to the syntactic context, if
2578 ;; c-syntactic-indentation is non-nil. Optional SYNTAX is the 2735 ;; c-syntactic-indentation is non-nil. Optional SYNTAX is the
2579 ;; syntactic information for the current line. Returns the amount 2736 ;; syntactic information for the current line. Be silent about
2580 ;; of indentation change (in columns). 2737 ;; syntactic errors if the optional argument QUIET is non-nil.
2738 ;; Returns the amount of indentation change (in columns).
2581 (let (shift-amt) 2739 (let (shift-amt)
2582 (if c-syntactic-indentation 2740 (if c-syntactic-indentation
2583 (let* ((c-syntactic-context (or syntax (c-guess-basic-syntax))) 2741 (setq c-parsing-error
2584 (indent (apply '+ (mapcar 'c-get-offset c-syntactic-context)))) 2742 (or (let* ((c-parsing-error nil)
2585 (and c-echo-syntactic-information-p 2743 (c-syntactic-context (or syntax
2586 (not (c-echo-parsing-error)) 2744 c-syntactic-context
2587 (message "syntax: %s, indent= %d" c-syntactic-context indent)) 2745 (c-guess-basic-syntax)))
2588 (setq shift-amt (- indent (current-indentation))) 2746 (indent (c-get-syntactic-indentation c-syntactic-context)))
2589 (c-shift-line-indentation shift-amt) 2747 (and (not (c-echo-parsing-error quiet))
2590 (run-hooks 'c-special-indent-hook)) 2748 c-echo-syntactic-information-p
2749 (message "syntax: %s, indent: %d"
2750 c-syntactic-context indent))
2751 (setq shift-amt (- indent (current-indentation)))
2752 (c-shift-line-indentation shift-amt)
2753 (run-hooks 'c-special-indent-hook)
2754 c-parsing-error)
2755 c-parsing-error))
2591 (let ((indent 0)) 2756 (let ((indent 0))
2592 (save-excursion 2757 (save-excursion
2593 (while (and (= (forward-line -1) 0) 2758 (while (and (= (forward-line -1) 0)
@@ -2606,8 +2771,7 @@ With universal argument, inserts the analysis as a comment on that line."
2606 (interactive "P") 2771 (interactive "P")
2607 (let ((syntax (c-guess-basic-syntax))) 2772 (let ((syntax (c-guess-basic-syntax)))
2608 (if (not (consp arg)) 2773 (if (not (consp arg))
2609 (if (not (c-echo-parsing-error)) 2774 (message "syntactic analysis: %s" syntax)
2610 (message "syntactic analysis: %s" syntax))
2611 (indent-for-comment) 2775 (indent-for-comment)
2612 (insert (format "%s" syntax)) 2776 (insert (format "%s" syntax))
2613 )) 2777 ))
@@ -2625,5 +2789,5 @@ With universal argument, inserts the analysis as a comment on that line."
2625 (forward-line))))) 2789 (forward-line)))))
2626 2790
2627 2791
2628(provide 'cc-engine) 2792(cc-provide 'cc-engine)
2629;;; cc-engine.el ends here 2793;;; cc-engine.el ends here
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el
index 98620b73317..8bd60ff8d4a 100644
--- a/lisp/progmodes/cc-langs.el
+++ b/lisp/progmodes/cc-langs.el
@@ -1,7 +1,6 @@
1;;; cc-langs.el --- specific language support for CC Mode 1;;; cc-langs.el --- language specific settings for CC Mode
2 2
3;; Copyright (C) 1985,1987,1992,1993,1994,1995,1996,1997,1998,2000 3;; Copyright (C) 1985,1987,1992-2001 Free Software Foundation, Inc.
4;; Free Software Foundation, Inc.
5 4
6;; Authors: 2000- Martin Stjernholm 5;; Authors: 2000- Martin Stjernholm
7;; 1998-1999 Barry A. Warsaw and Martin Stjernholm 6;; 1998-1999 Barry A. Warsaw and Martin Stjernholm
@@ -26,30 +25,20 @@
26;; GNU General Public License for more details. 25;; GNU General Public License for more details.
27 26
28;; 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
29;; along with GNU Emacs; see the file COPYING. If not, write to the 28;; along with this program; see the file COPYING. If not, write to
30;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 29;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
31;; Boston, MA 02111-1307, USA. 30;; Boston, MA 02111-1307, USA.
32 31
33(eval-when-compile 32(eval-when-compile
34 (let ((load-path 33 (let ((load-path
35 (if (and (boundp 'byte-compile-current-file) 34 (if (and (boundp 'byte-compile-dest-file)
36 (stringp byte-compile-current-file)) 35 (stringp byte-compile-dest-file))
37 (cons (file-name-directory byte-compile-current-file) 36 (cons (file-name-directory byte-compile-dest-file) load-path)
38 load-path)
39 load-path))) 37 load-path)))
40 (load "cc-defs" nil t))) 38 (require 'cc-bytecomp)))
41(require 'cc-styles)
42 39
43;; Pull in some other packages. 40(cc-require 'cc-defs)
44(eval-when-compile 41(cc-require 'cc-vars)
45 (condition-case nil
46 ;; Not required and only needed during compilation to shut up
47 ;; the compiler.
48 (require 'outline)
49 (error nil)))
50;; menu support for both XEmacs and Emacs. If you don't have easymenu
51;; with your version of Emacs, you are incompatible!
52(require 'easymenu)
53 42
54 43
55(defvar c-buffer-is-cc-mode nil 44(defvar c-buffer-is-cc-mode nil
@@ -65,9 +54,6 @@ Otherwise, this variable is nil. I.e. this variable is non-nil for
65;; Regular expressions and other values which must be parameterized on 54;; Regular expressions and other values which must be parameterized on
66;; a per-language basis. 55;; a per-language basis.
67 56
68;; Keywords defining protection levels
69(defconst c-protection-key "\\<\\(public\\|protected\\|private\\)\\>")
70
71;; Regex describing a `symbol' in all languages. We cannot use just 57;; Regex describing a `symbol' in all languages. We cannot use just
72;; `word' syntax class since `_' cannot be in word class. Putting 58;; `word' syntax class since `_' cannot be in word class. Putting
73;; underscore in word class breaks forward word movement behavior that 59;; underscore in word class breaks forward word movement behavior that
@@ -78,40 +64,219 @@ Otherwise, this variable is nil. I.e. this variable is non-nil for
78;; definition of a symbol as being Unicode. I know so little about 64;; definition of a symbol as being Unicode. I know so little about
79;; I18N (except how to sound cool and say I18N :-) that I'm willing to 65;; I18N (except how to sound cool and say I18N :-) that I'm willing to
80;; punt on this for now. 66;; punt on this for now.
81
82(defconst c-symbol-key "[_a-zA-Z]\\(\\w\\|\\s_\\)*") 67(defconst c-symbol-key "[_a-zA-Z]\\(\\w\\|\\s_\\)*")
83 68
84 69;; HELPME: Many of the following keyword lists are more or less bogus
85;; keywords introducing class definitions. language specific 70;; for some languages (notably ObjC and IDL). The effects of the
86(defconst c-C-class-key "\\(struct\\|union\\)") 71;; erroneous values in the language handling is miniscule since these
87(defconst c-C++-class-key "\\(class\\|struct\\|union\\)") 72;; constants are not used very much (yet, anyway) in the actual syntax
88(defconst c-IDL-class-key "\\(interface\\|struct\\|union\\|valuetype\\)") 73;; detection code, but I'd still appreciate help to get them correct.
89(defconst c-C-extra-toplevel-key "\\(extern\\)") 74
90(defconst c-C++-extra-toplevel-key "\\(extern\\|namespace\\)") 75;; Primitive type keywords.
91(defconst c-IDL-extra-toplevel-key "\\(module\\)") 76(defconst c-C-primitive-type-kwds
77 "char\\|double\\|float\\|int\\|long\\|short\\|signed\\|unsigned\\|void")
78(defconst c-C++-primitive-type-kwds c-C-primitive-type-kwds)
79(defconst c-ObjC-primitive-type-kwds c-C-primitive-type-kwds)
80(defconst c-Java-primitive-type-kwds
81 "boolean\\|byte\\|char\\|double\\|float\\|int\\|long\\|short\\|void")
82(defconst c-IDL-primitive-type-kwds c-C-primitive-type-kwds)
83(defconst c-Pike-primitive-type-kwds
84 (concat "constant\\|float\\|int\\|mapping\\|multiset\\|object\\|"
85 "program\\|string\\|void"))
86
87;; Declaration specifier keywords.
88(defconst c-C-specifier-kwds
89 "auto\\|const\\|extern\\|register\\|static\\|volatile")
90(defconst c-C++-specifier-kwds
91 (concat c-C-specifier-kwds "\\|friend\\|inline\\|virtual"))
92(defconst c-ObjC-specifier-kwds c-C++-specifier-kwds)
93(defconst c-Java-specifier-kwds
94 ;; Note: `const' is not used, but it's still a reserved keyword.
95 (concat "abstract\\|const\\|final\\|native\\|private\\|protected\\|"
96 "public\\|static\\|synchronized\\|transient\\|volatile"))
97(defconst c-IDL-specifier-kwds c-C++-specifier-kwds)
98(defconst c-Pike-specifier-kwds
99 (concat "final\\|inline\\|local\\|nomask\\|optional\\|private\\|"
100 "protected\\|static\\|variant"))
101
102;; Class/struct declaration keywords.
103(defconst c-C-class-kwds "struct\\|union")
104(defconst c-C++-class-kwds (concat c-C-class-kwds "\\|class"))
105(defconst c-ObjC-class-kwds "interface\\|implementation")
106(defconst c-Java-class-kwds "class\\|interface")
107(defconst c-IDL-class-kwds
108 (concat c-C++-class-kwds "\\|interface\\|valuetype"))
109(defconst c-Pike-class-kwds "class")
110
111;; Keywords introducing other declaration-level blocks.
112(defconst c-C-extra-toplevel-kwds "extern")
113(defconst c-C++-extra-toplevel-kwds
114 (concat c-C-extra-toplevel-kwds "\\|namespace"))
115;;(defconst c-ObjC-extra-toplevel-kwds nil)
116;;(defconst c-Java-extra-toplevel-kwds nil)
117(defconst c-IDL-extra-toplevel-kwds "module")
118;;(defconst c-Pike-extra-toplevel-kwds nil)
119
120;; Keywords introducing other declaration-level constructs.
121(defconst c-C-other-decl-kwds "enum\\|typedef")
122(defconst c-C++-other-decl-kwds (concat c-C-other-decl-kwds "\\|template"))
123;;(defconst c-ObjC-other-decl-kwds nil)
124(defconst c-Java-other-decl-kwds "import\\|package")
125;;(defconst c-IDL-other-decl-kwds nil)
126(defconst c-Pike-other-decl-kwds "import\\|inherit")
127
128;; Keywords that occur in declaration-level constructs.
129;;(defconst c-C-decl-level-kwds nil)
130;;(defconst c-C++-decl-level-kwds nil)
131;;(defconst c-ObjC-decl-level-kwds nil)
132(defconst c-Java-decl-level-kwds "extends\\|implements\\|throws")
133;;(defconst c-IDL-decl-level-kwds nil)
134;;(defconst c-Pike-decl-level-kwds nil)
135
136;; Protection label keywords in classes.
137;;(defconst c-C-protection-kwds nil)
138(defconst c-C++-protection-kwds "private\\|protected\\|public")
139(defconst c-ObjC-protection-kwds c-C++-protection-kwds)
140;;(defconst c-Java-protection-kwds nil)
141;;(defconst c-IDL-protection-kwds nil)
142;;(defconst c-Pike-protection-kwds nil)
143
144;; Statement keywords followed directly by a block.
145(defconst c-C-block-stmt-1-kwds "do\\|else")
146(defconst c-C++-block-stmt-1-kwds
147 (concat c-C-block-stmt-1-kwds "\\|asm\\|try"))
148(defconst c-ObjC-block-stmt-1-kwds c-C++-block-stmt-1-kwds)
149(defconst c-Java-block-stmt-1-kwds
150 (concat c-C-block-stmt-1-kwds "\\|finally\\|try"))
151;;(defconst c-IDL-block-stmt-1-kwds nil)
152(defconst c-Pike-block-stmt-1-kwds c-C-block-stmt-1-kwds)
153
154;; Statement keywords followed by a paren sexp and then by a block.
155(defconst c-C-block-stmt-2-kwds "for\\|if\\|switch\\|while")
156(defconst c-C++-block-stmt-2-kwds (concat c-C-block-stmt-2-kwds "\\|catch"))
157(defconst c-ObjC-block-stmt-2-kwds c-C++-block-stmt-2-kwds)
158(defconst c-Java-block-stmt-2-kwds
159 (concat c-C++-block-stmt-2-kwds "\\|synchronized"))
160;;(defconst c-IDL-block-stmt-2-kwds nil)
161(defconst c-Pike-block-stmt-2-kwds c-C-block-stmt-2-kwds)
162
163;; Statement keywords followed by an expression or nothing.
164(defconst c-C-simple-stmt-kwds "break\\|continue\\|goto\\|return")
165(defconst c-C++-simple-stmt-kwds c-C-simple-stmt-kwds)
166(defconst c-ObjC-simple-stmt-kwds c-C-simple-stmt-kwds)
167(defconst c-Java-simple-stmt-kwds
168 ;; Note: `goto' is not a valid statement, but the keyword is still reserved.
169 (concat c-C-simple-stmt-kwds "\\|throw"))
170;;(defconst c-IDL-simple-stmt-kwds nil)
171(defconst c-Pike-simple-stmt-kwds "break\\|continue\\|return")
172
173;; Keywords introducing labels in blocks.
174(defconst c-C-label-kwds "case\\|default")
175(defconst c-C++-label-kwds c-C-label-kwds)
176(defconst c-ObjC-label-kwds c-C-label-kwds)
177(defconst c-Java-label-kwds c-C-label-kwds)
178;;(defconst c-IDL-label-kwds nil)
179(defconst c-Pike-label-kwds c-C-label-kwds)
180
181;; Keywords that can occur anywhere in expressions.
182(defconst c-C-expr-kwds "sizeof")
183(defconst c-C++-expr-kwds
184 (concat c-C-expr-kwds "\\|delete\\|new\\|operator\\|this\\|throw"))
185(defconst c-ObjC-expr-kwds c-C-expr-kwds)
186(defconst c-Java-expr-kwds "instanceof\\|new\\|super\\|this")
187;;(defconst c-IDL-expr-kwds nil)
188(defconst c-Pike-expr-kwds
189 (concat c-C-expr-kwds "\\|catch\\|class\\|gauge\\|lambda\\|predef"))
190
191;; All keywords.
192(defconst c-C-keywords
193 (concat c-C-primitive-type-kwds "\\|" c-C-specifier-kwds
194 "\\|" c-C-class-kwds "\\|" c-C-extra-toplevel-kwds
195 "\\|" c-C-other-decl-kwds
196 ;; "\\|" c-C-decl-level-kwds "\\|" c-C-protection-kwds
197 "\\|" c-C-block-stmt-1-kwds "\\|" c-C-block-stmt-2-kwds
198 "\\|" c-C-simple-stmt-kwds "\\|" c-C-label-kwds
199 "\\|" c-C-expr-kwds))
200(defconst c-C++-keywords
201 (concat c-C++-primitive-type-kwds "\\|" c-C++-specifier-kwds
202 "\\|" c-C++-class-kwds "\\|" c-C++-extra-toplevel-kwds
203 "\\|" c-C++-other-decl-kwds
204 ;; "\\|" c-C++-decl-level-kwds
205 "\\|" c-C++-protection-kwds
206 "\\|" c-C++-block-stmt-1-kwds "\\|" c-C++-block-stmt-2-kwds
207 "\\|" c-C++-simple-stmt-kwds "\\|" c-C++-label-kwds
208 "\\|" c-C++-expr-kwds))
209(defconst c-ObjC-keywords
210 (concat c-ObjC-primitive-type-kwds "\\|" c-ObjC-specifier-kwds
211 "\\|" c-ObjC-class-kwds
212 ;; "\\|" c-ObjC-extra-toplevel-kwds
213 ;; "\\|" c-ObjC-other-decl-kwds "\\|" c-ObjC-decl-level-kwds
214 "\\|" c-ObjC-protection-kwds
215 "\\|" c-ObjC-block-stmt-1-kwds "\\|" c-ObjC-block-stmt-2-kwds
216 "\\|" c-ObjC-simple-stmt-kwds "\\|" c-ObjC-label-kwds
217 "\\|" c-ObjC-expr-kwds))
218(defconst c-Java-keywords
219 (concat c-Java-primitive-type-kwds "\\|" c-Java-specifier-kwds
220 "\\|" c-Java-class-kwds
221 ;; "\\|" c-Java-extra-toplevel-kwds
222 "\\|" c-Java-other-decl-kwds "\\|" c-Java-decl-level-kwds
223 ;; "\\|" c-Java-protection-kwds
224 "\\|" c-Java-block-stmt-1-kwds "\\|" c-Java-block-stmt-2-kwds
225 "\\|" c-Java-simple-stmt-kwds "\\|" c-Java-label-kwds
226 "\\|" c-Java-expr-kwds))
227(defconst c-IDL-keywords
228 (concat c-IDL-primitive-type-kwds "\\|" c-IDL-specifier-kwds
229 "\\|" c-IDL-class-kwds "\\|" c-IDL-extra-toplevel-kwds
230 ;; "\\|" c-IDL-other-decl-kwds "\\|" c-IDL-decl-level-kwds
231 ;; "\\|" c-IDL-protection-kwds
232 ;; "\\|" c-IDL-block-stmt-1-kwds "\\|" c-IDL-block-stmt-2-kwds
233 ;; "\\|" c-IDL-simple-stmt-kwds "\\|" c-IDL-label-kwds
234 ;; "\\|" c-IDL-expr-kwds)
235 ))
236(defconst c-Pike-keywords
237 (concat c-Pike-primitive-type-kwds "\\|" c-Pike-specifier-kwds
238 "\\|" c-Pike-class-kwds
239 ;; "\\|" c-Pike-extra-toplevel-kwds
240 "\\|" c-Pike-other-decl-kwds
241 ;; "\\|" c-Pike-decl-level-kwds "\\|" c-Pike-protection-kwds
242 "\\|" c-Pike-block-stmt-1-kwds "\\|" c-Pike-block-stmt-2-kwds
243 "\\|" c-Pike-simple-stmt-kwds "\\|" c-Pike-label-kwds
244 "\\|" c-Pike-expr-kwds))
245
246(defvar c-keywords nil)
247(make-variable-buffer-local 'c-keywords)
248
249;; Keywords defining protection levels
250(defconst c-protection-key "\\<\\(public\\|protected\\|private\\)\\>")
92 251
252;; Regexps introducing class definitions.
253(defconst c-C-class-key (c-paren-re c-C-class-kwds))
254(defconst c-C++-class-key (c-paren-re c-C++-class-kwds))
255(defconst c-IDL-class-key (c-paren-re c-IDL-class-kwds))
93(defconst c-ObjC-class-key 256(defconst c-ObjC-class-key
94 (concat 257 (concat
95 "@\\(interface\\|implementation\\)\\s +" 258 "@\\(" c-ObjC-class-kwds "\\)\\s +"
96 c-symbol-key ;name of the class 259 c-symbol-key ;name of the class
97 "\\(\\s *:\\s *" c-symbol-key "\\)?" ;maybe followed by the superclass 260 "\\(\\s *:\\s *" c-symbol-key "\\)?" ;maybe followed by the superclass
98 "\\(\\s *<[^>]+>\\)?" ;and maybe the adopted protocols list 261 "\\(\\s *<[^>]+>\\)?" ;and maybe the adopted protocols list
99 )) 262 ))
100
101(defconst c-Java-class-key 263(defconst c-Java-class-key
102 (concat 264 (concat
103 "\\(" c-protection-key "\\s +\\)?" 265 "\\(" c-protection-key "\\s +\\)?"
104 "\\(interface\\|class\\)\\s +" 266 "\\(" c-Java-class-kwds "\\)\\s +"
105 c-symbol-key ;name of the class 267 c-symbol-key ;name of the class
106 "\\(\\s *extends\\s *" c-symbol-key "\\)?" ;maybe followed by superclass 268 "\\(\\s *extends\\s *" c-symbol-key "\\)?" ;maybe followed by superclass
107 ;;"\\(\\s *implements *[^{]+{\\)?" ;maybe the adopted protocols list 269 ;;"\\(\\s *implements *[^{]+{\\)?" ;maybe the adopted protocols list
108 )) 270 ))
109 271(defconst c-Pike-class-key (c-paren-re c-Pike-class-kwds))
110(defconst c-Pike-class-key "class")
111 272
112(defvar c-class-key c-C-class-key) 273(defvar c-class-key c-C-class-key)
113(make-variable-buffer-local 'c-class-key) 274(make-variable-buffer-local 'c-class-key)
114 275
276(defconst c-C-extra-toplevel-key (c-paren-re c-C-extra-toplevel-kwds))
277(defconst c-C++-extra-toplevel-key (c-paren-re c-C++-extra-toplevel-kwds))
278(defconst c-IDL-extra-toplevel-key (c-paren-re c-IDL-extra-toplevel-kwds))
279
115(defvar c-extra-toplevel-key c-C-extra-toplevel-key) 280(defvar c-extra-toplevel-key c-C-extra-toplevel-key)
116(make-variable-buffer-local 'c-extra-toplevel-key) 281(make-variable-buffer-local 'c-extra-toplevel-key)
117 282
@@ -121,17 +286,16 @@ Otherwise, this variable is nil. I.e. this variable is non-nil for
121(defvar c-bitfield-key nil) 286(defvar c-bitfield-key nil)
122(make-variable-buffer-local 'c-bitfield-key) 287(make-variable-buffer-local 'c-bitfield-key)
123 288
124
125;; regexp describing access protection clauses. language specific 289;; regexp describing access protection clauses. language specific
126(defvar c-access-key nil) 290(defvar c-access-key nil)
127(make-variable-buffer-local 'c-access-key) 291(make-variable-buffer-local 'c-access-key)
128(defconst c-C++-access-key (concat c-protection-key "[ \t]*:")) 292(defconst c-C++-access-key
129(defconst c-IDL-access-key nil) 293 (concat "\\<\\(" c-C++-protection-kwds "\\)\\>[ \t]*:"))
294;;(defconst c-IDL-access-key nil)
130(defconst c-ObjC-access-key (concat "@" c-protection-key)) 295(defconst c-ObjC-access-key (concat "@" c-protection-key))
131(defconst c-Java-access-key nil) 296;;(defconst c-Java-access-key nil)
132(defconst c-Pike-access-key nil) 297;;(defconst c-Pike-access-key nil)
133 298
134
135;; keywords introducing conditional blocks 299;; keywords introducing conditional blocks
136(defconst c-C-conditional-key nil) 300(defconst c-C-conditional-key nil)
137(defconst c-C++-conditional-key nil) 301(defconst c-C++-conditional-key nil)
@@ -143,8 +307,8 @@ Otherwise, this variable is nil. I.e. this variable is non-nil for
143(let ((all-kws "for\\|if\\|do\\|else\\|while\\|switch") 307(let ((all-kws "for\\|if\\|do\\|else\\|while\\|switch")
144 (exc-kws "\\|try\\|catch") 308 (exc-kws "\\|try\\|catch")
145 (thr-kws "\\|finally\\|synchronized") 309 (thr-kws "\\|finally\\|synchronized")
146 (front "\\b\\(") 310 (front "\\<\\(")
147 (back "\\)\\b[^_]")) 311 (back "\\)\\>[^_]"))
148 (setq c-C-conditional-key (concat front all-kws back) 312 (setq c-C-conditional-key (concat front all-kws back)
149 c-C++-conditional-key (concat front all-kws exc-kws back) 313 c-C++-conditional-key (concat front all-kws exc-kws back)
150 ;; c-IDL-conditional-key is nil. 314 ;; c-IDL-conditional-key is nil.
@@ -155,7 +319,6 @@ Otherwise, this variable is nil. I.e. this variable is non-nil for
155(defvar c-conditional-key c-C-conditional-key) 319(defvar c-conditional-key c-C-conditional-key)
156(make-variable-buffer-local 'c-conditional-key) 320(make-variable-buffer-local 'c-conditional-key)
157 321
158
159;; keywords describing method definition introductions 322;; keywords describing method definition introductions
160(defvar c-method-key nil) 323(defvar c-method-key nil)
161(make-variable-buffer-local 'c-method-key) 324(make-variable-buffer-local 'c-method-key)
@@ -168,8 +331,6 @@ Otherwise, this variable is nil. I.e. this variable is non-nil for
168 ;; since it is considered the end of //-comments. 331 ;; since it is considered the end of //-comments.
169 "[ \t\n]*" c-symbol-key)) 332 "[ \t\n]*" c-symbol-key))
170 333
171
172
173;; comment starter definitions for various languages. language specific 334;; comment starter definitions for various languages. language specific
174(defconst c-C++-comment-start-regexp "/[/*]") 335(defconst c-C++-comment-start-regexp "/[/*]")
175(defconst c-C-comment-start-regexp c-C++-comment-start-regexp) 336(defconst c-C-comment-start-regexp c-C++-comment-start-regexp)
@@ -182,8 +343,6 @@ Otherwise, this variable is nil. I.e. this variable is non-nil for
182(defvar c-comment-start-regexp c-C++-comment-start-regexp) 343(defvar c-comment-start-regexp c-C++-comment-start-regexp)
183(make-variable-buffer-local 'c-comment-start-regexp) 344(make-variable-buffer-local 'c-comment-start-regexp)
184 345
185
186
187;; Regexp describing a switch's case or default label for all languages 346;; Regexp describing a switch's case or default label for all languages
188(defconst c-switch-label-key "\\(\\(case[( \t]+\\S .*\\)\\|default[ \t]*\\):") 347(defconst c-switch-label-key "\\(\\(case[( \t]+\\S .*\\)\\|default[ \t]*\\):")
189;; Regexp describing any label. 348;; Regexp describing any label.
@@ -215,15 +374,18 @@ Otherwise, this variable is nil. I.e. this variable is non-nil for
215(defconst c-Java-defun-prompt-regexp 374(defconst c-Java-defun-prompt-regexp
216 "^[ \t]*\\(\\(\\(public\\|protected\\|private\\|const\\|abstract\\|synchronized\\|final\\|static\\|threadsafe\\|transient\\|native\\|volatile\\)\\s-+\\)*\\(\\(\\([[a-zA-Z][][_$.a-zA-Z0-9]*[][_$.a-zA-Z0-9]+\\|[[a-zA-Z]\\)\\s-*\\)\\s-+\\)\\)?\\(\\([[a-zA-Z][][_$.a-zA-Z0-9]*\\s-+\\)\\s-*\\)?\\([_a-zA-Z][^][ \t:;.,{}()=]*\\|\\([_$a-zA-Z][_$.a-zA-Z0-9]*\\)\\)\\s-*\\(([^);{}]*)\\)?\\([] \t]*\\)\\(\\s-*\\<throws\\>\\s-*\\(\\([_$a-zA-Z][_$.a-zA-Z0-9]*\\)[, \t\n\r\f]*\\)+\\)?\\s-*") 375 "^[ \t]*\\(\\(\\(public\\|protected\\|private\\|const\\|abstract\\|synchronized\\|final\\|static\\|threadsafe\\|transient\\|native\\|volatile\\)\\s-+\\)*\\(\\(\\([[a-zA-Z][][_$.a-zA-Z0-9]*[][_$.a-zA-Z0-9]+\\|[[a-zA-Z]\\)\\s-*\\)\\s-+\\)\\)?\\(\\([[a-zA-Z][][_$.a-zA-Z0-9]*\\s-+\\)\\s-*\\)?\\([_a-zA-Z][^][ \t:;.,{}()=]*\\|\\([_$a-zA-Z][_$.a-zA-Z0-9]*\\)\\)\\s-*\\(([^);{}]*)\\)?\\([] \t]*\\)\\(\\s-*\\<throws\\>\\s-*\\(\\([_$a-zA-Z][_$.a-zA-Z0-9]*\\)[, \t\n\r\f]*\\)+\\)?\\s-*")
217 376
218;; Regexp describing regexp to append to paragraph-start 377;; Regexp to append to paragraph-start.
219(defvar c-append-paragraph-start "$") 378(defvar c-append-paragraph-start "$")
220(make-variable-buffer-local 'c-append-paragraph-start) 379(make-variable-buffer-local 'c-append-paragraph-start)
221(defconst c-Java-javadoc-paragraph-start 380(defconst c-Java-javadoc-paragraph-start
222 (concat "\\(" 381 "\\(@[a-zA-Z]+\\>\\|$\\)")
223 "@\\(author\\|deprecated\\|exception\\|param\\|return\\|" 382(defconst c-Pike-pikedoc-paragraph-start
224 "s\\(e\\(e\\|rial\\(\\|Data\\|Field\\)\\)\\|ince\\)\\|" 383 "\\(@[a-zA-Z]+\\>\\([^{]\\|$\\)\\|$\\)")
225 "throws\\|version\\)" 384
226 "\\|$\\)")) 385;; Regexp to append to paragraph-separate.
386(defvar c-append-paragraph-separate "$")
387(make-variable-buffer-local 'c-append-paragraph-separate)
388(defconst c-Pike-pikedoc-paragraph-separate c-Pike-pikedoc-paragraph-start)
227 389
228;; Regexp that starts lambda constructs. 390;; Regexp that starts lambda constructs.
229(defvar c-lambda-key nil) 391(defvar c-lambda-key nil)
@@ -250,175 +412,8 @@ Otherwise, this variable is nil. I.e. this variable is non-nil for
250 (?\[ . ?\]) 412 (?\[ . ?\])
251 (?< . ?>))) 413 (?< . ?>)))
252 414
253
254
255;; internal state variables
256
257;; Internal state of hungry delete key feature
258(defvar c-hungry-delete-key nil)
259(make-variable-buffer-local 'c-hungry-delete-key)
260
261;; Internal state of auto newline feature.
262(defvar c-auto-newline nil)
263(make-variable-buffer-local 'c-auto-newline)
264
265;; Internal auto-newline/hungry-delete designation string for mode line.
266(defvar c-auto-hungry-string nil)
267(make-variable-buffer-local 'c-auto-hungry-string)
268
269;; Non-nil means K&R style argument declarations are valid.
270(defvar c-recognize-knr-p t)
271(make-variable-buffer-local 'c-recognize-knr-p)
272
273
274 415
275(defun c-common-init () 416;; Syntax tables.
276 ;; Common initializations for all modes.
277 ;; these variables should always be buffer local; they do not affect
278 ;; indentation style.
279 (make-local-variable 'require-final-newline)
280 (make-local-variable 'parse-sexp-ignore-comments)
281 (make-local-variable 'indent-line-function)
282 (make-local-variable 'indent-region-function)
283 (make-local-variable 'outline-regexp)
284 (make-local-variable 'outline-level)
285 (make-local-variable 'normal-auto-fill-function)
286 (make-local-variable 'comment-start)
287 (make-local-variable 'comment-end)
288 (make-local-variable 'comment-column)
289 (make-local-variable 'comment-start-skip)
290 (make-local-variable 'comment-multi-line)
291 (make-local-variable 'paragraph-start)
292 (make-local-variable 'paragraph-separate)
293 (make-local-variable 'paragraph-ignore-fill-prefix)
294 (make-local-variable 'adaptive-fill-mode)
295 (make-local-variable 'adaptive-fill-regexp)
296 (make-local-variable 'imenu-generic-expression) ;set in the mode functions
297 ;; X/Emacs 20 only
298 (and (boundp 'comment-line-break-function)
299 (progn
300 (make-local-variable 'comment-line-break-function)
301 (setq comment-line-break-function
302 'c-indent-new-comment-line)))
303 ;; now set their values
304 (setq require-final-newline t
305 parse-sexp-ignore-comments t
306 indent-line-function 'c-indent-line
307 indent-region-function 'c-indent-region
308 outline-regexp "[^#\n\^M]"
309 outline-level 'c-outline-level
310 normal-auto-fill-function 'c-do-auto-fill
311 comment-column 32
312 comment-start-skip "/\\*+ *\\|//+ *"
313 comment-multi-line t)
314 ;; now set the mode style based on c-default-style
315 (let ((style (if (stringp c-default-style)
316 (if (c-major-mode-is 'java-mode)
317 "java"
318 c-default-style)
319 (or (cdr (assq major-mode c-default-style))
320 (cdr (assq 'other c-default-style))
321 "gnu"))))
322 ;; Override style variables if `c-old-style-variable-behavior' is
323 ;; set. Also override if we are using global style variables,
324 ;; have already initialized a style once, and are switching to a
325 ;; different style. (It's doubtful whether this is desirable, but
326 ;; the whole situation with nonlocal style variables is a bit
327 ;; awkward. It's at least the most compatible way with the old
328 ;; style init procedure.)
329 (c-set-style style (not (or c-old-style-variable-behavior
330 (and (not c-style-variables-are-local-p)
331 c-indentation-style
332 (not (string-equal c-indentation-style
333 style)))))))
334 ;; Fix things up for paragraph recognition and filling inside
335 ;; comments by using c-comment-prefix-regexp in the relevant places.
336 ;; We use adaptive filling for this to make it possible to use
337 ;; filladapt or some other fancy package.
338 (let ((comment-line-prefix
339 (concat "[ \t]*\\(" c-comment-prefix-regexp "\\)?[ \t]*")))
340 (setq paragraph-start (concat comment-line-prefix
341 c-append-paragraph-start
342 "\\|"
343 page-delimiter)
344 paragraph-separate (concat comment-line-prefix "$"
345 "\\|"
346 page-delimiter)
347 paragraph-ignore-fill-prefix t
348 adaptive-fill-mode t
349 adaptive-fill-regexp
350 (concat comment-line-prefix
351 (if adaptive-fill-regexp
352 (concat "\\(" adaptive-fill-regexp "\\)")
353 "")))
354 (when (boundp 'adaptive-fill-first-line-regexp)
355 ;; XEmacs (20.x) adaptive fill mode doesn't have this.
356 (make-local-variable 'adaptive-fill-first-line-regexp)
357 (setq adaptive-fill-first-line-regexp
358 (concat "\\`" comment-line-prefix
359 ;; Maybe we should incorporate the old value here,
360 ;; but then we have to do all sorts of kludges to
361 ;; deal with the \` and \' it probably contains.
362 "\\'"))))
363 ;; we have to do something special for c-offsets-alist so that the
364 ;; buffer local value has its own alist structure.
365 (setq c-offsets-alist (copy-alist c-offsets-alist))
366 ;; setup the comment indent variable in a Emacs version portable way
367 ;; ignore any byte compiler warnings you might get here
368 (make-local-variable 'comment-indent-function)
369 (setq comment-indent-function 'c-comment-indent)
370 ;; add menus to menubar
371 (easy-menu-add (c-mode-menu mode-name))
372 ;; put auto-hungry designators onto minor-mode-alist, but only once
373 (or (assq 'c-auto-hungry-string minor-mode-alist)
374 (setq minor-mode-alist
375 (cons '(c-auto-hungry-string c-auto-hungry-string)
376 minor-mode-alist)))
377 )
378
379
380(defun c-postprocess-file-styles ()
381 "Function that post processes relevant file local variables.
382Currently, this function simply applies any style and offset settings
383found in the file's Local Variable list. It first applies any style
384setting found in `c-file-style', then it applies any offset settings
385it finds in `c-file-offsets'.
386
387Note that the style variables are always made local to the buffer."
388 ;; apply file styles and offsets
389 (if (or c-file-style c-file-offsets)
390 (c-make-styles-buffer-local t))
391 (and c-file-style
392 (c-set-style c-file-style))
393 (and c-file-offsets
394 (mapcar
395 (function
396 (lambda (langentry)
397 (let ((langelem (car langentry))
398 (offset (cdr langentry)))
399 (c-set-offset langelem offset)
400 )))
401 c-file-offsets)))
402
403(add-hook 'hack-local-variables-hook 'c-postprocess-file-styles)
404
405
406(defvar c-mode-base-map ()
407 "Keymap shared by all CC Mode related modes.")
408
409;; Common routines
410(defun c-make-inherited-keymap ()
411 (let ((map (make-sparse-keymap)))
412 (cond
413 ;; XEmacs 19 & 20
414 ((fboundp 'set-keymap-parents)
415 (set-keymap-parents map c-mode-base-map))
416 ;; Emacs 19
417 ((fboundp 'set-keymap-parent)
418 (set-keymap-parent map c-mode-base-map))
419 ;; incompatible
420 (t (error "CC Mode is incompatible with this version of Emacs")))
421 map))
422 417
423(defun c-populate-syntax-table (table) 418(defun c-populate-syntax-table (table)
424 ;; Populate the syntax TABLE 419 ;; Populate the syntax TABLE
@@ -453,132 +448,6 @@ Note that the style variables are always made local to the buffer."
453 ;; Give CR the same syntax as newline, for selective-display 448 ;; Give CR the same syntax as newline, for selective-display
454 (modify-syntax-entry ?\^m "> b" table)) 449 (modify-syntax-entry ?\^m "> b" table))
455 450
456
457(if c-mode-base-map
458 nil
459 ;; TBD: should we even worry about naming this keymap. My vote: no,
460 ;; because Emacs and XEmacs do it differently.
461 (setq c-mode-base-map (make-sparse-keymap))
462 ;; put standard keybindings into MAP
463 ;; the following mappings correspond more or less directly to BOCM
464 (define-key c-mode-base-map "{" 'c-electric-brace)
465 (define-key c-mode-base-map "}" 'c-electric-brace)
466 (define-key c-mode-base-map ";" 'c-electric-semi&comma)
467 (define-key c-mode-base-map "#" 'c-electric-pound)
468 (define-key c-mode-base-map ":" 'c-electric-colon)
469 (define-key c-mode-base-map "(" 'c-electric-paren)
470 (define-key c-mode-base-map ")" 'c-electric-paren)
471 ;; Separate M-BS from C-M-h. The former should remain
472 ;; backward-kill-word.
473 (define-key c-mode-base-map [(control meta h)] 'c-mark-function)
474 (define-key c-mode-base-map "\e\C-q" 'c-indent-exp)
475 (substitute-key-definition 'backward-sentence
476 'c-beginning-of-statement
477 c-mode-base-map global-map)
478 (substitute-key-definition 'forward-sentence
479 'c-end-of-statement
480 c-mode-base-map global-map)
481 (substitute-key-definition 'indent-new-comment-line
482 'c-indent-new-comment-line
483 c-mode-base-map global-map)
484 ;; RMS says don't make these the default.
485;; (define-key c-mode-base-map "\e\C-a" 'c-beginning-of-defun)
486;; (define-key c-mode-base-map "\e\C-e" 'c-end-of-defun)
487 (define-key c-mode-base-map "\C-c\C-n" 'c-forward-conditional)
488 (define-key c-mode-base-map "\C-c\C-p" 'c-backward-conditional)
489 (define-key c-mode-base-map "\C-c\C-u" 'c-up-conditional)
490 (substitute-key-definition 'indent-for-tab-command
491 'c-indent-command
492 c-mode-base-map global-map)
493 ;; It doesn't suffice to put c-fill-paragraph on
494 ;; fill-paragraph-function due to the way it works.
495 (substitute-key-definition 'fill-paragraph 'c-fill-paragraph
496 c-mode-base-map global-map)
497 ;; In XEmacs the default fill function is called
498 ;; fill-paragraph-or-region.
499 (substitute-key-definition 'fill-paragraph-or-region 'c-fill-paragraph
500 c-mode-base-map global-map)
501 ;; Caution! Enter here at your own risk. We are trying to support
502 ;; several behaviors and it gets disgusting. :-(
503 ;;
504 (if (boundp 'delete-key-deletes-forward)
505 (progn
506 ;; In XEmacs 20 it is possible to sanely define both backward
507 ;; and forward deletion behavior under X separately (TTYs are
508 ;; forever beyond hope, but who cares? XEmacs 20 does the
509 ;; right thing with these too).
510 (define-key c-mode-base-map [delete] 'c-electric-delete)
511 (define-key c-mode-base-map [backspace] 'c-electric-backspace))
512 ;; In XEmacs 19, Emacs 19, and Emacs 20, we use this to bind
513 ;; backwards deletion behavior to DEL, which both Delete and
514 ;; Backspace get translated to. There's no way to separate this
515 ;; behavior in a clean way, so deal with it! Besides, it's been
516 ;; this way since the dawn of BOCM.
517 (define-key c-mode-base-map "\177" 'c-electric-backspace))
518 ;; these are new keybindings, with no counterpart to BOCM
519 (define-key c-mode-base-map "," 'c-electric-semi&comma)
520 (define-key c-mode-base-map "*" 'c-electric-star)
521 (define-key c-mode-base-map "/" 'c-electric-slash)
522 (define-key c-mode-base-map "\C-c\C-q" 'c-indent-defun)
523 (define-key c-mode-base-map "\C-c\C-\\" 'c-backslash-region)
524 ;; TBD: where if anywhere, to put c-backward|forward-into-nomenclature
525 (define-key c-mode-base-map "\C-c\C-a" 'c-toggle-auto-state)
526 (define-key c-mode-base-map "\C-c\C-b" 'c-submit-bug-report)
527 (define-key c-mode-base-map "\C-c\C-c" 'comment-region)
528 (define-key c-mode-base-map "\C-c\C-d" 'c-toggle-hungry-state)
529 (define-key c-mode-base-map "\C-c\C-o" 'c-set-offset)
530 (define-key c-mode-base-map "\C-c\C-s" 'c-show-syntactic-information)
531 (define-key c-mode-base-map "\C-c\C-t" 'c-toggle-auto-hungry-state)
532 (define-key c-mode-base-map "\C-c." 'c-set-style)
533 ;; conflicts with OOBR
534 ;;(define-key c-mode-base-map "\C-c\C-v" 'c-version)
535 )
536
537(defvar c-c-menu nil)
538(defvar c-c++-menu nil)
539(defvar c-objc-menu nil)
540(defvar c-java-menu nil)
541(defvar c-pike-menu nil)
542
543(defun c-mode-menu (modestr)
544 (let ((m
545 '(["Comment Out Region" comment-region (c-region-is-active-p)]
546 ["Uncomment Region"
547 (comment-region (region-beginning) (region-end) '(4))
548 (c-region-is-active-p)]
549 ["Fill Comment Paragraph" c-fill-paragraph t]
550 "---"
551 ["Indent Expression" c-indent-exp
552 (memq (char-after) '(?\( ?\[ ?\{))]
553 ["Indent Line or Region" c-indent-line-or-region t]
554 ["Up Conditional" c-up-conditional t]
555 ["Backward Conditional" c-backward-conditional t]
556 ["Forward Conditional" c-forward-conditional t]
557 ["Backward Statement" c-beginning-of-statement t]
558 ["Forward Statement" c-end-of-statement t]
559 "---"
560 ["Macro Expand Region" c-macro-expand (c-region-is-active-p)]
561 ["Backslashify" c-backslash-region (c-region-is-active-p)]
562 )))
563 (cons modestr m)))
564
565
566
567;; Support for C
568
569(defvar c-mode-abbrev-table nil
570 "Abbreviation table used in c-mode buffers.")
571(define-abbrev-table 'c-mode-abbrev-table ())
572
573(defvar c-mode-map ()
574 "Keymap used in c-mode buffers.")
575(if c-mode-map
576 nil
577 (setq c-mode-map (c-make-inherited-keymap))
578 ;; add bindings which are only useful for C
579 (define-key c-mode-map "\C-c\C-e" 'c-macro-expand)
580 )
581
582;;;###autoload 451;;;###autoload
583(defvar c-mode-syntax-table nil 452(defvar c-mode-syntax-table nil
584 "Syntax table used in c-mode buffers.") 453 "Syntax table used in c-mode buffers.")
@@ -587,27 +456,6 @@ Note that the style variables are always made local to the buffer."
587 (setq c-mode-syntax-table (make-syntax-table)) 456 (setq c-mode-syntax-table (make-syntax-table))
588 (c-populate-syntax-table c-mode-syntax-table)) 457 (c-populate-syntax-table c-mode-syntax-table))
589 458
590(easy-menu-define c-c-menu c-mode-map "C Mode Commands"
591 (c-mode-menu "C"))
592
593
594;; Support for C++
595
596(defvar c++-mode-abbrev-table nil
597 "Abbreviation table used in c++-mode buffers.")
598(define-abbrev-table 'c++-mode-abbrev-table ())
599
600(defvar c++-mode-map ()
601 "Keymap used in c++-mode buffers.")
602(if c++-mode-map
603 nil
604 (setq c++-mode-map (c-make-inherited-keymap))
605 ;; add bindings which are only useful for C++
606 (define-key c++-mode-map "\C-c\C-e" 'c-macro-expand)
607 (define-key c++-mode-map "\C-c:" 'c-scope-operator)
608 (define-key c++-mode-map "<" 'c-electric-lt-gt)
609 (define-key c++-mode-map ">" 'c-electric-lt-gt))
610
611;;;###autoload 459;;;###autoload
612(defvar c++-mode-syntax-table nil 460(defvar c++-mode-syntax-table nil
613 "Syntax table used in c++-mode buffers.") 461 "Syntax table used in c++-mode buffers.")
@@ -635,24 +483,6 @@ are parsed.")
635 (modify-syntax-entry ?< "(>" c++-template-syntax-table) 483 (modify-syntax-entry ?< "(>" c++-template-syntax-table)
636 (modify-syntax-entry ?> ")<" c++-template-syntax-table)) 484 (modify-syntax-entry ?> ")<" c++-template-syntax-table))
637 485
638(easy-menu-define c-c++-menu c++-mode-map "C++ Mode Commands"
639 (c-mode-menu "C++"))
640
641
642;; Support for Objective-C
643
644(defvar objc-mode-abbrev-table nil
645 "Abbreviation table used in objc-mode buffers.")
646(define-abbrev-table 'objc-mode-abbrev-table ())
647
648(defvar objc-mode-map ()
649 "Keymap used in objc-mode buffers.")
650(if objc-mode-map
651 nil
652 (setq objc-mode-map (c-make-inherited-keymap))
653 ;; add bindings which are only useful for Objective-C
654 (define-key objc-mode-map "\C-c\C-e" 'c-macro-expand))
655
656;;;###autoload 486;;;###autoload
657(defvar objc-mode-syntax-table nil 487(defvar objc-mode-syntax-table nil
658 "Syntax table used in objc-mode buffers.") 488 "Syntax table used in objc-mode buffers.")
@@ -663,24 +493,6 @@ are parsed.")
663 ;; add extra Objective-C only syntax 493 ;; add extra Objective-C only syntax
664 (modify-syntax-entry ?@ "_" objc-mode-syntax-table)) 494 (modify-syntax-entry ?@ "_" objc-mode-syntax-table))
665 495
666(easy-menu-define c-objc-menu objc-mode-map "ObjC Mode Commands"
667 (c-mode-menu "ObjC"))
668
669
670;; Support for Java
671
672(defvar java-mode-abbrev-table nil
673 "Abbreviation table used in java-mode buffers.")
674(define-abbrev-table 'java-mode-abbrev-table ())
675
676(defvar java-mode-map ()
677 "Keymap used in java-mode buffers.")
678(if java-mode-map
679 nil
680 (setq java-mode-map (c-make-inherited-keymap))
681 ;; add bindings which are only useful for Java
682 )
683
684;;;###autoload 496;;;###autoload
685(defvar java-mode-syntax-table nil 497(defvar java-mode-syntax-table nil
686 "Syntax table used in java-mode buffers.") 498 "Syntax table used in java-mode buffers.")
@@ -689,24 +501,6 @@ are parsed.")
689 (setq java-mode-syntax-table (make-syntax-table)) 501 (setq java-mode-syntax-table (make-syntax-table))
690 (c-populate-syntax-table java-mode-syntax-table)) 502 (c-populate-syntax-table java-mode-syntax-table))
691 503
692(easy-menu-define c-java-menu java-mode-map "Java Mode Commands"
693 (c-mode-menu "Java"))
694
695
696;; Support for CORBA's IDL language
697
698(defvar idl-mode-abbrev-table nil
699 "Abbreviation table used in idl-mode buffers.")
700(define-abbrev-table 'idl-mode-abbrev-table ())
701
702(defvar idl-mode-map ()
703 "Keymap used in idl-mode buffers.")
704(if idl-mode-map
705 nil
706 (setq idl-mode-map (c-make-inherited-keymap))
707 ;; add bindings which are only useful for IDL
708 )
709
710;;;###autoload 504;;;###autoload
711(defvar idl-mode-syntax-table nil 505(defvar idl-mode-syntax-table nil
712 "Syntax table used in idl-mode buffers.") 506 "Syntax table used in idl-mode buffers.")
@@ -715,24 +509,6 @@ are parsed.")
715 (setq idl-mode-syntax-table (make-syntax-table)) 509 (setq idl-mode-syntax-table (make-syntax-table))
716 (c-populate-syntax-table idl-mode-syntax-table)) 510 (c-populate-syntax-table idl-mode-syntax-table))
717 511
718(easy-menu-define c-idl-menu idl-mode-map "IDL Mode Commands"
719 (c-mode-menu "IDL"))
720
721
722;; Support for Pike
723
724(defvar pike-mode-abbrev-table nil
725 "Abbreviation table used in pike-mode buffers.")
726(define-abbrev-table 'pike-mode-abbrev-table ())
727
728(defvar pike-mode-map ()
729 "Keymap used in pike-mode buffers.")
730(if pike-mode-map
731 nil
732 (setq pike-mode-map (c-make-inherited-keymap))
733 ;; additional bindings
734 (define-key pike-mode-map "\C-c\C-e" 'c-macro-expand))
735
736;;;###autoload 512;;;###autoload
737(defvar pike-mode-syntax-table nil 513(defvar pike-mode-syntax-table nil
738 "Syntax table used in pike-mode buffers.") 514 "Syntax table used in pike-mode buffers.")
@@ -742,10 +518,25 @@ are parsed.")
742 (c-populate-syntax-table pike-mode-syntax-table) 518 (c-populate-syntax-table pike-mode-syntax-table)
743 (modify-syntax-entry ?@ "." pike-mode-syntax-table)) 519 (modify-syntax-entry ?@ "." pike-mode-syntax-table))
744 520
745(easy-menu-define c-pike-menu pike-mode-map "Pike Mode Commands" 521
746 (c-mode-menu "Pike")) 522;; internal state variables
523
524;; Internal state of hungry delete key feature
525(defvar c-hungry-delete-key nil)
526(make-variable-buffer-local 'c-hungry-delete-key)
527
528;; Internal state of auto newline feature.
529(defvar c-auto-newline nil)
530(make-variable-buffer-local 'c-auto-newline)
747 531
532;; Internal auto-newline/hungry-delete designation string for mode line.
533(defvar c-auto-hungry-string nil)
534(make-variable-buffer-local 'c-auto-hungry-string)
535
536;; Non-nil means K&R style argument declarations are valid.
537(defvar c-recognize-knr-p t)
538(make-variable-buffer-local 'c-recognize-knr-p)
748 539
749 540
750(provide 'cc-langs) 541(cc-provide 'cc-langs)
751;;; cc-langs.el ends here 542;;; cc-langs.el ends here
diff --git a/lisp/progmodes/cc-menus.el b/lisp/progmodes/cc-menus.el
index 3cd67c67bdb..5179f952530 100644
--- a/lisp/progmodes/cc-menus.el
+++ b/lisp/progmodes/cc-menus.el
@@ -1,6 +1,6 @@
1;;; cc-menus.el --- imenu support for CC Mode 1;;; cc-menus.el --- imenu support for CC Mode
2 2
3;; Copyright (C) 1985,87,92,93,94,95,96,97,98,99,2000 Free Software Foundation, Inc. 3;; Copyright (C) 1985,1987,1992-2001 Free Software Foundation, Inc.
4 4
5;; Authors: 2000- Martin Stjernholm 5;; Authors: 2000- Martin Stjernholm
6;; 1998-1999 Barry A. Warsaw and Martin Stjernholm 6;; 1998-1999 Barry A. Warsaw and Martin Stjernholm
@@ -25,31 +25,27 @@
25;; GNU General Public License for more details. 25;; GNU General Public License for more details.
26 26
27;; 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
28;; along with GNU Emacs; see the file COPYING. If not, write to the 28;; along with this program; see the file COPYING. If not, write to
29;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 29;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
30;; Boston, MA 02111-1307, USA. 30;; Boston, MA 02111-1307, USA.
31 31
32(eval-when-compile 32(eval-when-compile
33 (let ((load-path 33 (let ((load-path
34 (if (and (boundp 'byte-compile-current-file) 34 (if (and (boundp 'byte-compile-dest-file)
35 (stringp byte-compile-current-file)) 35 (stringp byte-compile-dest-file))
36 (cons (file-name-directory byte-compile-current-file) 36 (cons (file-name-directory byte-compile-dest-file) load-path)
37 load-path)
38 load-path))) 37 load-path)))
39 (load "cc-defs" nil t))) 38 (require 'cc-bytecomp)))
40 39
41;; Dummy definitions to shut up the compiler in case imenu doesn't exist. 40;; Try to pull in imenu if it exists.
42(eval-when-compile 41(condition-case nil
43 (defvar imenu-generic-expression) 42 (require 'imenu)
44 (defvar imenu-case-fold-search)) 43 (error nil))
45(or (fboundp 'imenu-progress-message)
46 (defun imenu-progress-message (&rest args) nil))
47 44
48;; Try to pull in imenu. 45;; The things referenced in imenu, which we don't require.
49(eval-and-compile 46(cc-bytecomp-defvar imenu-case-fold-search)
50 (condition-case nil 47(cc-bytecomp-defvar imenu-generic-expression)
51 (require 'imenu) 48(cc-bytecomp-defun imenu-progress-message)
52 (error nil)))
53 49
54 50
55;; imenu integration 51;; imenu integration
@@ -134,13 +130,13 @@ A sample value might look like: `\\(_P\\|_PROTO\\)'.")
134 ,(concat 130 ,(concat
135 "^" ; beginning of line is required 131 "^" ; beginning of line is required
136 "\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a `template <...>' 132 "\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a `template <...>'
137 "class[ \t]+" 133 "\\(class\\|struct\\)[ \t]+"
138 "\\(" ; the string we want to get 134 "\\(" ; the string we want to get
139 "[a-zA-Z0-9_]+" ; class name 135 "[a-zA-Z0-9_]+" ; class name
140 "\\(<[^>]+>\\)?" ; possibly explicitely specialized 136 "\\(<[^>]+>\\)?" ; possibly explicitly specialized
141 "\\)" 137 "\\)"
142 "[ \t\n]*[:{]" 138 "[ \t\n]*[:{]"
143 ) 2)) 139 ) 3))
144 "Imenu generic expression for C++ mode. See `imenu-generic-expression'.") 140 "Imenu generic expression for C++ mode. See `imenu-generic-expression'.")
145 141
146(defvar cc-imenu-c-generic-expression 142(defvar cc-imenu-c-generic-expression
@@ -414,5 +410,5 @@ Example:
414 imenu-case-fold-search nil)) 410 imenu-case-fold-search nil))
415 411
416 412
417(provide 'cc-menus) 413(cc-provide 'cc-menus)
418;;; cc-menus.el ends here 414;;; cc-menus.el ends here
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index a3750bf082b..a7e35a9c185 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -1,6 +1,6 @@
1;;; cc-mode.el --- major mode for editing C, C++, Objective-C, and Java code 1;;; cc-mode.el --- major mode for editing C, C++, Objective-C, and Java code
2 2
3;; Copyright (C) 1985,87,92,93,94,95,96,97,98,99,2000 Free Software Foundation, Inc. 3;; Copyright (C) 1985,1987,1992-2001 Free Software Foundation, Inc.
4 4
5;; Authors: 2000- Martin Stjernholm 5;; Authors: 2000- Martin Stjernholm
6;; 1998-1999 Barry A. Warsaw and Martin Stjernholm 6;; 1998-1999 Barry A. Warsaw and Martin Stjernholm
@@ -11,12 +11,6 @@
11;; Created: a long, long, time ago. adapted from the original c-mode.el 11;; Created: a long, long, time ago. adapted from the original c-mode.el
12;; Keywords: c languages oop 12;; Keywords: c languages oop
13 13
14(defconst c-version "5.27"
15 "CC Mode version number.")
16
17;; NOTE: Read the commentary below for the right way to submit bug reports!
18;; NOTE: See the accompanying texinfo manual for details on using this mode!
19
20;; This file is part of GNU Emacs. 14;; This file is part of GNU Emacs.
21 15
22;; GNU Emacs is free software; you can redistribute it and/or modify 16;; GNU Emacs is free software; you can redistribute it and/or modify
@@ -30,10 +24,16 @@
30;; GNU General Public License for more details. 24;; GNU General Public License for more details.
31 25
32;; You should have received a copy of the GNU General Public License 26;; You should have received a copy of the GNU General Public License
33;; along with GNU Emacs; see the file COPYING. If not, write to the 27;; along with this program; see the file COPYING. If not, write to
34;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 28;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
35;; Boston, MA 02111-1307, USA. 29;; Boston, MA 02111-1307, USA.
36 30
31(defconst c-version "5.28"
32 "CC Mode version number.")
33
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!
36
37;;; Commentary: 37;;; Commentary:
38 38
39;; This package provides GNU Emacs major modes for editing C, C++, 39;; This package provides GNU Emacs major modes for editing C, C++,
@@ -64,9 +64,8 @@
64;; gnu.emacs.bug) as well as bug-cc-mode@gnu.org, which directly 64;; gnu.emacs.bug) as well as bug-cc-mode@gnu.org, which directly
65;; contacts the CC Mode maintainers. Questions can sent to 65;; contacts the CC Mode maintainers. Questions can sent to
66;; help-gnu-emacs@gnu.org (mirrored as gnu.emacs.help) and/or 66;; help-gnu-emacs@gnu.org (mirrored as gnu.emacs.help) and/or
67;; bug-cc-mode@gnu.org. Please use bug-cc-mode@gnu.org instead. 67;; bug-cc-mode@gnu.org. Please do not send bugs or questions to our
68;; Please do not send bugs or questions to our personal accounts; we 68;; personal accounts; we reserve the right to ignore such email!
69;; reserve the right to ignore such email!
70 69
71;; Many, many thanks go out to all the folks on the beta test list. 70;; Many, many thanks go out to all the folks on the beta test list.
72;; Without their patience, testing, insight, code contributions, and 71;; Without their patience, testing, insight, code contributions, and
@@ -86,31 +85,29 @@
86 85
87(eval-when-compile 86(eval-when-compile
88 (let ((load-path 87 (let ((load-path
89 ;; Try to make sure the source directory is at the front of 88 (if (and (boundp 'byte-compile-dest-file)
90 ;; load-path when we load cc-defs. 89 (stringp byte-compile-dest-file))
91 (if (and (boundp 'byte-compile-current-file) 90 (cons (file-name-directory byte-compile-dest-file) load-path)
92 (stringp byte-compile-current-file))
93 ;; byte-compile-current-file is set by the byte compiler
94 ;; to the full path to this file.
95 (cons (file-name-directory byte-compile-current-file)
96 load-path)
97 load-path))) 91 load-path)))
98 ;; Load our version of cc-defs unconditionally, since an older 92 (require 'cc-bytecomp)))
99 ;; version might very well be dumped in or already loaded. This 93
100 ;; way we ensure that the code is compiled with the correct macros 94(cc-require 'cc-defs)
101 ;; and defsubsts. The same problem affects the subpackages that's 95(cc-require 'cc-menus)
102 ;; require'd below, but that doesn't harm the compiler; it can 96(cc-require 'cc-vars)
103 ;; only cause some bogus warnings. 97(cc-require 'cc-langs)
104 (load "cc-defs" nil t))) 98(cc-require 'cc-styles)
105 99(cc-require 'cc-engine)
106(require 'cc-defs) ; Not meaningless; this passes on require's from cc-defs. 100(cc-require 'cc-cmds)
107(require 'cc-menus) 101(cc-require 'cc-align)
108(require 'cc-vars) 102
109(require 'cc-styles) 103;; Silence the compiler.
110(require 'cc-langs) 104(cc-bytecomp-defvar comment-line-break-function) ; (X)Emacs 20+
111(require 'cc-engine) 105(cc-bytecomp-defvar adaptive-fill-first-line-regexp) ; Emacs 20+
112(require 'cc-align) 106(cc-bytecomp-defun set-keymap-parents) ; XEmacs
113(require 'cc-cmds) 107
108;; Menu support for both XEmacs and Emacs. If you don't have easymenu
109;; with your version of Emacs, you are incompatible!
110(require 'easymenu)
114 111
115 112
116;; Other modes and packages which depend on CC Mode should do the 113;; Other modes and packages which depend on CC Mode should do the
@@ -140,6 +137,289 @@
140 )) 137 ))
141 138
142 139
140;; Common routines
141(defvar c-mode-base-map ()
142 "Keymap shared by all CC Mode related modes.")
143
144(defun c-make-inherited-keymap ()
145 (let ((map (make-sparse-keymap)))
146 (cond
147 ;; XEmacs 19 & 20
148 ((fboundp 'set-keymap-parents)
149 (set-keymap-parents map c-mode-base-map))
150 ;; Emacs 19
151 ((fboundp 'set-keymap-parent)
152 (set-keymap-parent map c-mode-base-map))
153 ;; incompatible
154 (t (error "CC Mode is incompatible with this version of Emacs")))
155 map))
156
157(if c-mode-base-map
158 nil
159 ;; TBD: should we even worry about naming this keymap. My vote: no,
160 ;; because Emacs and XEmacs do it differently.
161 (setq c-mode-base-map (make-sparse-keymap))
162 ;; put standard keybindings into MAP
163 ;; the following mappings correspond more or less directly to BOCM
164 (define-key c-mode-base-map "{" 'c-electric-brace)
165 (define-key c-mode-base-map "}" 'c-electric-brace)
166 (define-key c-mode-base-map ";" 'c-electric-semi&comma)
167 (define-key c-mode-base-map "#" 'c-electric-pound)
168 (define-key c-mode-base-map ":" 'c-electric-colon)
169 (define-key c-mode-base-map "(" 'c-electric-paren)
170 (define-key c-mode-base-map ")" 'c-electric-paren)
171 ;; Separate M-BS from C-M-h. The former should remain
172 ;; backward-kill-word.
173 (define-key c-mode-base-map [(control meta h)] 'c-mark-function)
174 (define-key c-mode-base-map "\e\C-q" 'c-indent-exp)
175 (substitute-key-definition 'backward-sentence
176 'c-beginning-of-statement
177 c-mode-base-map global-map)
178 (substitute-key-definition 'forward-sentence
179 'c-end-of-statement
180 c-mode-base-map global-map)
181 (substitute-key-definition 'indent-new-comment-line
182 'c-indent-new-comment-line
183 c-mode-base-map global-map)
184 ;; RMS says don't make these the default.
185;; (define-key c-mode-base-map "\e\C-a" 'c-beginning-of-defun)
186;; (define-key c-mode-base-map "\e\C-e" 'c-end-of-defun)
187 (define-key c-mode-base-map "\C-c\C-n" 'c-forward-conditional)
188 (define-key c-mode-base-map "\C-c\C-p" 'c-backward-conditional)
189 (define-key c-mode-base-map "\C-c\C-u" 'c-up-conditional)
190 (substitute-key-definition 'indent-for-tab-command
191 'c-indent-command
192 c-mode-base-map global-map)
193 ;; It doesn't suffice to put c-fill-paragraph on
194 ;; fill-paragraph-function due to the way it works.
195 (substitute-key-definition 'fill-paragraph 'c-fill-paragraph
196 c-mode-base-map global-map)
197 ;; In XEmacs the default fill function is called
198 ;; fill-paragraph-or-region.
199 (substitute-key-definition 'fill-paragraph-or-region 'c-fill-paragraph
200 c-mode-base-map global-map)
201 ;; Caution! Enter here at your own risk. We are trying to support
202 ;; several behaviors and it gets disgusting. :-(
203 ;;
204 (if (boundp 'delete-key-deletes-forward)
205 (progn
206 ;; In XEmacs 20 it is possible to sanely define both backward
207 ;; and forward deletion behavior under X separately (TTYs are
208 ;; forever beyond hope, but who cares? XEmacs 20 does the
209 ;; right thing with these too).
210 (define-key c-mode-base-map [delete] 'c-electric-delete)
211 (define-key c-mode-base-map [backspace] 'c-electric-backspace))
212 ;; In XEmacs 19, Emacs 19, and Emacs 20, we use this to bind
213 ;; backwards deletion behavior to DEL, which both Delete and
214 ;; Backspace get translated to. There's no way to separate this
215 ;; behavior in a clean way, so deal with it! Besides, it's been
216 ;; this way since the dawn of BOCM.
217 (define-key c-mode-base-map "\177" 'c-electric-backspace))
218 ;; these are new keybindings, with no counterpart to BOCM
219 (define-key c-mode-base-map "," 'c-electric-semi&comma)
220 (define-key c-mode-base-map "*" 'c-electric-star)
221 (define-key c-mode-base-map "/" 'c-electric-slash)
222 (define-key c-mode-base-map "\C-c\C-q" 'c-indent-defun)
223 (define-key c-mode-base-map "\C-c\C-\\" 'c-backslash-region)
224 ;; TBD: where if anywhere, to put c-backward|forward-into-nomenclature
225 (define-key c-mode-base-map "\C-c\C-a" 'c-toggle-auto-state)
226 (define-key c-mode-base-map "\C-c\C-b" 'c-submit-bug-report)
227 (define-key c-mode-base-map "\C-c\C-c" 'comment-region)
228 (define-key c-mode-base-map "\C-c\C-d" 'c-toggle-hungry-state)
229 (define-key c-mode-base-map "\C-c\C-o" 'c-set-offset)
230 (define-key c-mode-base-map "\C-c\C-s" 'c-show-syntactic-information)
231 (define-key c-mode-base-map "\C-c\C-t" 'c-toggle-auto-hungry-state)
232 (define-key c-mode-base-map "\C-c." 'c-set-style)
233 ;; conflicts with OOBR
234 ;;(define-key c-mode-base-map "\C-c\C-v" 'c-version)
235 )
236
237(defvar c-c-menu nil)
238(defvar c-c++-menu nil)
239(defvar c-objc-menu nil)
240(defvar c-java-menu nil)
241(defvar c-pike-menu nil)
242
243(defun c-mode-menu (modestr)
244 (let ((m
245 '(["Comment Out Region" comment-region (c-fn-region-is-active-p)]
246 ["Uncomment Region"
247 (comment-region (region-beginning) (region-end) '(4))
248 (c-fn-region-is-active-p)]
249 ["Fill Comment Paragraph" c-fill-paragraph t]
250 "---"
251 ["Indent Expression" c-indent-exp
252 (memq (char-after) '(?\( ?\[ ?\{))]
253 ["Indent Line or Region" c-indent-line-or-region t]
254 ["Up Conditional" c-up-conditional t]
255 ["Backward Conditional" c-backward-conditional t]
256 ["Forward Conditional" c-forward-conditional t]
257 ["Backward Statement" c-beginning-of-statement t]
258 ["Forward Statement" c-end-of-statement t]
259 "---"
260 ["Macro Expand Region" c-macro-expand (c-fn-region-is-active-p)]
261 ["Backslashify" c-backslash-region
262 (c-fn-region-is-active-p)]
263 )))
264 (cons modestr m)))
265
266;; We don't require the outline package, but we configure it a bit anyway.
267(cc-bytecomp-defvar outline-level)
268
269(defun c-common-init ()
270 ;; Common initializations for all modes.
271 ;; these variables should always be buffer local; they do not affect
272 ;; indentation style.
273 (make-local-variable 'require-final-newline)
274 (make-local-variable 'parse-sexp-ignore-comments)
275 (make-local-variable 'indent-line-function)
276 (make-local-variable 'indent-region-function)
277 (make-local-variable 'outline-regexp)
278 (make-local-variable 'outline-level)
279 (make-local-variable 'normal-auto-fill-function)
280 (make-local-variable 'comment-start)
281 (make-local-variable 'comment-end)
282 (make-local-variable 'comment-column)
283 (make-local-variable 'comment-start-skip)
284 (make-local-variable 'comment-multi-line)
285 (make-local-variable 'paragraph-start)
286 (make-local-variable 'paragraph-separate)
287 (make-local-variable 'paragraph-ignore-fill-prefix)
288 (make-local-variable 'adaptive-fill-mode)
289 (make-local-variable 'adaptive-fill-regexp)
290 (make-local-variable 'imenu-generic-expression) ;set in the mode functions
291 ;; X/Emacs 20 only
292 (and (boundp 'comment-line-break-function)
293 (progn
294 (make-local-variable 'comment-line-break-function)
295 (setq comment-line-break-function
296 'c-indent-new-comment-line)))
297 ;; now set their values
298 (setq require-final-newline t
299 parse-sexp-ignore-comments t
300 indent-line-function 'c-indent-line
301 indent-region-function 'c-indent-region
302 outline-regexp "[^#\n\^M]"
303 outline-level 'c-outline-level
304 normal-auto-fill-function 'c-do-auto-fill
305 comment-column 32
306 comment-start-skip "/\\*+ *\\|//+ *"
307 comment-multi-line t)
308 ;; now set the mode style based on c-default-style
309 (let ((style (if (stringp c-default-style)
310 c-default-style
311 (or (cdr (assq major-mode c-default-style))
312 (cdr (assq 'other c-default-style))
313 "gnu"))))
314 ;; Override style variables if `c-old-style-variable-behavior' is
315 ;; set. Also override if we are using global style variables,
316 ;; have already initialized a style once, and are switching to a
317 ;; different style. (It's doubtful whether this is desirable, but
318 ;; the whole situation with nonlocal style variables is a bit
319 ;; awkward. It's at least the most compatible way with the old
320 ;; style init procedure.)
321 (c-set-style style (not (or c-old-style-variable-behavior
322 (and (not c-style-variables-are-local-p)
323 c-indentation-style
324 (not (string-equal c-indentation-style
325 style)))))))
326 ;; Fix things up for paragraph recognition and filling inside
327 ;; comments by using c-current-comment-prefix in the relevant
328 ;; places. We use adaptive filling for this to make it possible to
329 ;; use filladapt or some other fancy package.
330 (setq c-current-comment-prefix
331 (if (listp c-comment-prefix-regexp)
332 (cdr-safe (or (assoc major-mode c-comment-prefix-regexp)
333 (assoc 'other c-comment-prefix-regexp)))
334 c-comment-prefix-regexp))
335 (let ((comment-line-prefix
336 (concat "[ \t]*\\(" c-current-comment-prefix "\\)[ \t]*")))
337 (setq paragraph-start (concat comment-line-prefix
338 c-append-paragraph-start
339 "\\|"
340 page-delimiter)
341 paragraph-separate (concat comment-line-prefix
342 c-append-paragraph-separate
343 "\\|"
344 page-delimiter)
345 paragraph-ignore-fill-prefix t
346 adaptive-fill-mode t
347 adaptive-fill-regexp
348 (concat comment-line-prefix
349 (if adaptive-fill-regexp
350 (concat "\\(" adaptive-fill-regexp "\\)")
351 "")))
352 (when (boundp 'adaptive-fill-first-line-regexp)
353 ;; XEmacs (20.x) adaptive fill mode doesn't have this.
354 (make-local-variable 'adaptive-fill-first-line-regexp)
355 (setq adaptive-fill-first-line-regexp
356 (concat "\\`" comment-line-prefix
357 ;; Maybe we should incorporate the old value here,
358 ;; but then we have to do all sorts of kludges to
359 ;; deal with the \` and \' it probably contains.
360 "\\'"))))
361 ;; we have to do something special for c-offsets-alist so that the
362 ;; buffer local value has its own alist structure.
363 (setq c-offsets-alist (copy-alist c-offsets-alist))
364 ;; setup the comment indent variable in a Emacs version portable way
365 ;; ignore any byte compiler warnings you might get here
366 (make-local-variable 'comment-indent-function)
367 (setq comment-indent-function 'c-comment-indent)
368 ;; add menus to menubar
369 (easy-menu-add (c-mode-menu mode-name))
370 ;; put auto-hungry designators onto minor-mode-alist, but only once
371 (or (assq 'c-auto-hungry-string minor-mode-alist)
372 (setq minor-mode-alist
373 (cons '(c-auto-hungry-string c-auto-hungry-string)
374 minor-mode-alist)))
375 )
376
377(defun c-postprocess-file-styles ()
378 "Function that post processes relevant file local variables.
379Currently, this function simply applies any style and offset settings
380found in the file's Local Variable list. It first applies any style
381setting found in `c-file-style', then it applies any offset settings
382it finds in `c-file-offsets'.
383
384Note that the style variables are always made local to the buffer."
385 ;; apply file styles and offsets
386 (if (or c-file-style c-file-offsets)
387 (c-make-styles-buffer-local t))
388 (and c-file-style
389 (c-set-style c-file-style))
390 (and c-file-offsets
391 (mapcar
392 (function
393 (lambda (langentry)
394 (let ((langelem (car langentry))
395 (offset (cdr langentry)))
396 (c-set-offset langelem offset)
397 )))
398 c-file-offsets)))
399
400(add-hook 'hack-local-variables-hook 'c-postprocess-file-styles)
401
402
403;; Support for C
404
405(defvar c-mode-abbrev-table nil
406 "Abbreviation table used in c-mode buffers.")
407(define-abbrev-table 'c-mode-abbrev-table
408 '(("else" "else" c-electric-continued-statement 0)
409 ("while" "while" c-electric-continued-statement 0)))
410
411(defvar c-mode-map ()
412 "Keymap used in c-mode buffers.")
413(if c-mode-map
414 nil
415 (setq c-mode-map (c-make-inherited-keymap))
416 ;; add bindings which are only useful for C
417 (define-key c-mode-map "\C-c\C-e" 'c-macro-expand)
418 )
419
420(easy-menu-define c-c-menu c-mode-map "C Mode Commands"
421 (c-mode-menu "C"))
422
143;;;###autoload 423;;;###autoload
144(defun c-mode () 424(defun c-mode ()
145 "Major mode for editing K&R and ANSI C code. 425 "Major mode for editing K&R and ANSI C code.
@@ -162,11 +442,13 @@ Key bindings:
162 (set-syntax-table c-mode-syntax-table) 442 (set-syntax-table c-mode-syntax-table)
163 (setq major-mode 'c-mode 443 (setq major-mode 'c-mode
164 mode-name "C" 444 mode-name "C"
165 local-abbrev-table c-mode-abbrev-table) 445 local-abbrev-table c-mode-abbrev-table
446 abbrev-mode t)
166 (use-local-map c-mode-map) 447 (use-local-map c-mode-map)
167 (c-common-init) 448 (c-common-init)
168 (setq comment-start "/* " 449 (setq comment-start "/* "
169 comment-end " */" 450 comment-end " */"
451 c-keywords (c-identifier-re c-C-keywords)
170 c-conditional-key c-C-conditional-key 452 c-conditional-key c-C-conditional-key
171 c-class-key c-C-class-key 453 c-class-key c-C-class-key
172 c-baseclass-key nil 454 c-baseclass-key nil
@@ -179,6 +461,29 @@ Key bindings:
179 (c-update-modeline)) 461 (c-update-modeline))
180 462
181 463
464;; Support for C++
465
466(defvar c++-mode-abbrev-table nil
467 "Abbreviation table used in c++-mode buffers.")
468(define-abbrev-table 'c++-mode-abbrev-table
469 '(("else" "else" c-electric-continued-statement 0)
470 ("while" "while" c-electric-continued-statement 0)
471 ("catch" "catch" c-electric-continued-statement 0)))
472
473(defvar c++-mode-map ()
474 "Keymap used in c++-mode buffers.")
475(if c++-mode-map
476 nil
477 (setq c++-mode-map (c-make-inherited-keymap))
478 ;; add bindings which are only useful for C++
479 (define-key c++-mode-map "\C-c\C-e" 'c-macro-expand)
480 (define-key c++-mode-map "\C-c:" 'c-scope-operator)
481 (define-key c++-mode-map "<" 'c-electric-lt-gt)
482 (define-key c++-mode-map ">" 'c-electric-lt-gt))
483
484(easy-menu-define c-c++-menu c++-mode-map "C++ Mode Commands"
485 (c-mode-menu "C++"))
486
182;;;###autoload 487;;;###autoload
183(defun c++-mode () 488(defun c++-mode ()
184 "Major mode for editing C++ code. 489 "Major mode for editing C++ code.
@@ -202,11 +507,13 @@ Key bindings:
202 (set-syntax-table c++-mode-syntax-table) 507 (set-syntax-table c++-mode-syntax-table)
203 (setq major-mode 'c++-mode 508 (setq major-mode 'c++-mode
204 mode-name "C++" 509 mode-name "C++"
205 local-abbrev-table c++-mode-abbrev-table) 510 local-abbrev-table c++-mode-abbrev-table
511 abbrev-mode t)
206 (use-local-map c++-mode-map) 512 (use-local-map c++-mode-map)
207 (c-common-init) 513 (c-common-init)
208 (setq comment-start "// " 514 (setq comment-start "// "
209 comment-end "" 515 comment-end ""
516 c-keywords (c-identifier-re c-C++-keywords)
210 c-conditional-key c-C++-conditional-key 517 c-conditional-key c-C++-conditional-key
211 c-comment-start-regexp c-C++-comment-start-regexp 518 c-comment-start-regexp c-C++-comment-start-regexp
212 c-class-key c-C++-class-key 519 c-class-key c-C++-class-key
@@ -221,6 +528,25 @@ Key bindings:
221 (c-update-modeline)) 528 (c-update-modeline))
222 529
223 530
531;; Support for Objective-C
532
533(defvar objc-mode-abbrev-table nil
534 "Abbreviation table used in objc-mode buffers.")
535(define-abbrev-table 'objc-mode-abbrev-table
536 '(("else" "else" c-electric-continued-statement 0)
537 ("while" "while" c-electric-continued-statement 0)))
538
539(defvar objc-mode-map ()
540 "Keymap used in objc-mode buffers.")
541(if objc-mode-map
542 nil
543 (setq objc-mode-map (c-make-inherited-keymap))
544 ;; add bindings which are only useful for Objective-C
545 (define-key objc-mode-map "\C-c\C-e" 'c-macro-expand))
546
547(easy-menu-define c-objc-menu objc-mode-map "ObjC Mode Commands"
548 (c-mode-menu "ObjC"))
549
224;;;###autoload 550;;;###autoload
225(defun objc-mode () 551(defun objc-mode ()
226 "Major mode for editing Objective C code. 552 "Major mode for editing Objective C code.
@@ -244,11 +570,13 @@ Key bindings:
244 (set-syntax-table objc-mode-syntax-table) 570 (set-syntax-table objc-mode-syntax-table)
245 (setq major-mode 'objc-mode 571 (setq major-mode 'objc-mode
246 mode-name "ObjC" 572 mode-name "ObjC"
247 local-abbrev-table objc-mode-abbrev-table) 573 local-abbrev-table objc-mode-abbrev-table
574 abbrev-mode t)
248 (use-local-map objc-mode-map) 575 (use-local-map objc-mode-map)
249 (c-common-init) 576 (c-common-init)
250 (setq comment-start "// " 577 (setq comment-start "// "
251 comment-end "" 578 comment-end ""
579 c-keywords (c-identifier-re c-ObjC-keywords)
252 c-conditional-key c-ObjC-conditional-key 580 c-conditional-key c-ObjC-conditional-key
253 c-comment-start-regexp c-ObjC-comment-start-regexp 581 c-comment-start-regexp c-ObjC-comment-start-regexp
254 c-class-key c-ObjC-class-key 582 c-class-key c-ObjC-class-key
@@ -262,6 +590,27 @@ Key bindings:
262 (c-update-modeline)) 590 (c-update-modeline))
263 591
264 592
593;; Support for Java
594
595(defvar java-mode-abbrev-table nil
596 "Abbreviation table used in java-mode buffers.")
597(define-abbrev-table 'java-mode-abbrev-table
598 '(("else" "else" c-electric-continued-statement 0)
599 ("while" "while" c-electric-continued-statement 0)
600 ("catch" "catch" c-electric-continued-statement 0)
601 ("finally" "finally" c-electric-continued-statement 0)))
602
603(defvar java-mode-map ()
604 "Keymap used in java-mode buffers.")
605(if java-mode-map
606 nil
607 (setq java-mode-map (c-make-inherited-keymap))
608 ;; add bindings which are only useful for Java
609 )
610
611(easy-menu-define c-java-menu java-mode-map "Java Mode Commands"
612 (c-mode-menu "Java"))
613
265;;;###autoload 614;;;###autoload
266(defun java-mode () 615(defun java-mode ()
267 "Major mode for editing Java code. 616 "Major mode for editing Java code.
@@ -288,18 +637,19 @@ Key bindings:
288 (setq major-mode 'java-mode 637 (setq major-mode 'java-mode
289 mode-name "Java" 638 mode-name "Java"
290 local-abbrev-table java-mode-abbrev-table 639 local-abbrev-table java-mode-abbrev-table
640 abbrev-mode t
291 c-append-paragraph-start c-Java-javadoc-paragraph-start) 641 c-append-paragraph-start c-Java-javadoc-paragraph-start)
292 (use-local-map java-mode-map) 642 (use-local-map java-mode-map)
293 (c-common-init) 643 (c-common-init)
294 (setq comment-start "// " 644 (setq comment-start "// "
295 comment-end "" 645 comment-end ""
646 c-keywords (c-identifier-re c-Java-keywords)
296 c-conditional-key c-Java-conditional-key 647 c-conditional-key c-Java-conditional-key
297 c-comment-start-regexp c-Java-comment-start-regexp 648 c-comment-start-regexp c-Java-comment-start-regexp
298 c-class-key c-Java-class-key 649 c-class-key c-Java-class-key
299 c-method-key nil 650 c-method-key nil
300 c-baseclass-key nil 651 c-baseclass-key nil
301 c-recognize-knr-p nil 652 c-recognize-knr-p nil
302 c-access-key c-Java-access-key
303 c-inexpr-class-key c-Java-inexpr-class-key 653 c-inexpr-class-key c-Java-inexpr-class-key
304 ;defun-prompt-regexp c-Java-defun-prompt-regexp 654 ;defun-prompt-regexp c-Java-defun-prompt-regexp
305 ) 655 )
@@ -309,6 +659,23 @@ Key bindings:
309 (c-update-modeline)) 659 (c-update-modeline))
310 660
311 661
662;; Support for CORBA's IDL language
663
664(defvar idl-mode-abbrev-table nil
665 "Abbreviation table used in idl-mode buffers.")
666(define-abbrev-table 'idl-mode-abbrev-table ())
667
668(defvar idl-mode-map ()
669 "Keymap used in idl-mode buffers.")
670(if idl-mode-map
671 nil
672 (setq idl-mode-map (c-make-inherited-keymap))
673 ;; add bindings which are only useful for IDL
674 )
675
676(easy-menu-define c-idl-menu idl-mode-map "IDL Mode Commands"
677 (c-mode-menu "IDL"))
678
312;;;###autoload 679;;;###autoload
313(defun idl-mode () 680(defun idl-mode ()
314 "Major mode for editing CORBA's IDL code. 681 "Major mode for editing CORBA's IDL code.
@@ -337,13 +704,13 @@ Key bindings:
337 (c-common-init) 704 (c-common-init)
338 (setq comment-start "// " 705 (setq comment-start "// "
339 comment-end "" 706 comment-end ""
707 c-keywords (c-identifier-re c-IDL-keywords)
340 c-conditional-key c-IDL-conditional-key 708 c-conditional-key c-IDL-conditional-key
341 c-comment-start-regexp c-IDL-comment-start-regexp 709 c-comment-start-regexp c-IDL-comment-start-regexp
342 c-class-key c-IDL-class-key 710 c-class-key c-IDL-class-key
343 c-method-key nil 711 c-method-key nil
344 c-baseclass-key nil 712 c-baseclass-key nil
345 c-extra-toplevel-key c-IDL-extra-toplevel-key 713 c-extra-toplevel-key c-IDL-extra-toplevel-key
346 c-access-key c-IDL-access-key
347 c-recognize-knr-p nil 714 c-recognize-knr-p nil
348 ) 715 )
349 ;;(cc-imenu-init cc-imenu-idl-generic-expression) ;FIXME 716 ;;(cc-imenu-init cc-imenu-idl-generic-expression) ;FIXME
@@ -352,6 +719,25 @@ Key bindings:
352 (c-update-modeline)) 719 (c-update-modeline))
353 720
354 721
722;; Support for Pike
723
724(defvar pike-mode-abbrev-table nil
725 "Abbreviation table used in pike-mode buffers.")
726(define-abbrev-table 'pike-mode-abbrev-table
727 '(("else" "else" c-electric-continued-statement 0)
728 ("while" "while" c-electric-continued-statement 0)))
729
730(defvar pike-mode-map ()
731 "Keymap used in pike-mode buffers.")
732(if pike-mode-map
733 nil
734 (setq pike-mode-map (c-make-inherited-keymap))
735 ;; additional bindings
736 (define-key pike-mode-map "\C-c\C-e" 'c-macro-expand))
737
738(easy-menu-define c-pike-menu pike-mode-map "Pike Mode Commands"
739 (c-mode-menu "Pike"))
740
355;;;###autoload 741;;;###autoload
356(defun pike-mode () 742(defun pike-mode ()
357 "Major mode for editing Pike code. 743 "Major mode for editing Pike code.
@@ -375,18 +761,21 @@ Key bindings:
375 (set-syntax-table pike-mode-syntax-table) 761 (set-syntax-table pike-mode-syntax-table)
376 (setq major-mode 'pike-mode 762 (setq major-mode 'pike-mode
377 mode-name "Pike" 763 mode-name "Pike"
378 local-abbrev-table pike-mode-abbrev-table) 764 local-abbrev-table pike-mode-abbrev-table
765 abbrev-mode t
766 c-append-paragraph-start c-Pike-pikedoc-paragraph-start
767 c-append-paragraph-separate c-Pike-pikedoc-paragraph-separate)
379 (use-local-map pike-mode-map) 768 (use-local-map pike-mode-map)
380 (c-common-init) 769 (c-common-init)
381 (setq comment-start "// " 770 (setq comment-start "// "
382 comment-end "" 771 comment-end ""
772 c-keywords (c-identifier-re c-Pike-keywords)
383 c-conditional-key c-Pike-conditional-key 773 c-conditional-key c-Pike-conditional-key
384 c-comment-start-regexp c-Pike-comment-start-regexp 774 c-comment-start-regexp c-Pike-comment-start-regexp
385 c-class-key c-Pike-class-key 775 c-class-key c-Pike-class-key
386 c-method-key nil 776 c-method-key nil
387 c-baseclass-key nil 777 c-baseclass-key nil
388 c-recognize-knr-p nil 778 c-recognize-knr-p nil
389 c-access-key c-Pike-access-key
390 c-lambda-key c-Pike-lambda-key 779 c-lambda-key c-Pike-lambda-key
391 c-inexpr-block-key c-Pike-inexpr-block-key 780 c-inexpr-block-key c-Pike-inexpr-block-key
392 c-inexpr-class-key c-Pike-inexpr-class-key 781 c-inexpr-class-key c-Pike-inexpr-class-key
@@ -398,6 +787,12 @@ Key bindings:
398 (c-update-modeline)) 787 (c-update-modeline))
399 788
400 789
790;; Helper for setting up Filladapt mode. It's not used by CC Mode itself.
791
792(cc-bytecomp-defvar filladapt-token-table)
793(cc-bytecomp-defvar filladapt-token-match-table)
794(cc-bytecomp-defvar filladapt-token-conversion-table)
795
401(defun c-setup-filladapt () 796(defun c-setup-filladapt ()
402 "Convenience function to configure Kyle E. Jones' Filladapt mode for 797 "Convenience function to configure Kyle E. Jones' Filladapt mode for
403CC Mode by making sure the proper entries are present on 798CC Mode by making sure the proper entries are present on
@@ -415,10 +810,10 @@ CC Mode by making sure the proper entries are present on
415 (while (and p (not (eq (car-safe (cdr-safe (car-safe p))) 'c-comment))) 810 (while (and p (not (eq (car-safe (cdr-safe (car-safe p))) 'c-comment)))
416 (setq p (cdr-safe p))) 811 (setq p (cdr-safe p)))
417 (if p 812 (if p
418 (setcar (car p) c-comment-prefix-regexp) 813 (setcar (car p) c-current-comment-prefix)
419 (setq filladapt-token-table 814 (setq filladapt-token-table
420 (append (list (car filladapt-token-table) 815 (append (list (car filladapt-token-table)
421 (list c-comment-prefix-regexp 'c-comment)) 816 (list c-current-comment-prefix 'c-comment))
422 (cdr filladapt-token-table))))) 817 (cdr filladapt-token-table)))))
423 (unless (assq 'c-comment filladapt-token-match-table) 818 (unless (assq 'c-comment filladapt-token-match-table)
424 (setq filladapt-token-match-table 819 (setq filladapt-token-match-table
@@ -442,16 +837,20 @@ CC Mode by making sure the proper entries are present on
442 (message "Using CC Mode version %s" c-version) 837 (message "Using CC Mode version %s" c-version)
443 (c-keep-region-active)) 838 (c-keep-region-active))
444 839
840(defvar c-prepare-bug-report-hooks nil)
841
842;; Dynamic variables used by reporter.
843(defvar reporter-prompt-for-summary-p)
844(defvar reporter-dont-compact-list)
845
445(defun c-submit-bug-report () 846(defun c-submit-bug-report ()
446 "Submit via mail a bug report on CC Mode." 847 "Submit via mail a bug report on CC Mode."
447 (interactive) 848 (interactive)
448 (require 'reporter) 849 (require 'reporter)
449 (require 'cc-vars)
450 ;; load in reporter 850 ;; load in reporter
451 (let ((reporter-prompt-for-summary-p t) 851 (let ((reporter-prompt-for-summary-p t)
452 (reporter-dont-compact-list '(c-offsets-alist)) 852 (reporter-dont-compact-list '(c-offsets-alist))
453 (style c-indentation-style) 853 (style c-indentation-style)
454 (hook c-special-indent-hook)
455 (c-features c-emacs-features)) 854 (c-features c-emacs-features))
456 (and 855 (and
457 (if (y-or-n-p "Do you want to submit a report on CC Mode? ") 856 (if (y-or-n-p "Do you want to submit a report on CC Mode? ")
@@ -500,12 +899,12 @@ CC Mode by making sure the proper entries are present on
500 vars) 899 vars)
501 (function 900 (function
502 (lambda () 901 (lambda ()
902 (run-hooks 'c-prepare-bug-report-hooks)
503 (insert 903 (insert
504 "Buffer Style: " style "\n\n" 904 "Buffer Style: " style "\n\n"
505 (format "c-emacs-features: %s\n" c-features) 905 (format "c-emacs-features: %s\n" c-features)
506 ))) 906 )))))))
507 nil))))
508 907
509 908
510(provide 'cc-mode) 909(cc-provide 'cc-mode)
511;;; cc-mode.el ends here 910;;; cc-mode.el ends here
diff --git a/lisp/progmodes/cc-styles.el b/lisp/progmodes/cc-styles.el
index 3ce24cfa3bd..68591f125c0 100644
--- a/lisp/progmodes/cc-styles.el
+++ b/lisp/progmodes/cc-styles.el
@@ -1,6 +1,6 @@
1;;; cc-styles.el --- support for styles in CC Mode 1;;; cc-styles.el --- support for styles in CC Mode
2 2
3;; Copyright (C) 1985,87,92,93,94,95,96,97,98,99,2000 Free Software Foundation, Inc. 3;; Copyright (C) 1985,1987,1992-2001 Free Software Foundation, Inc.
4 4
5;; Authors: 2000- Martin Stjernholm 5;; Authors: 2000- Martin Stjernholm
6;; 1998-1999 Barry A. Warsaw and Martin Stjernholm 6;; 1998-1999 Barry A. Warsaw and Martin Stjernholm
@@ -25,20 +25,20 @@
25;; GNU General Public License for more details. 25;; GNU General Public License for more details.
26 26
27;; 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
28;; along with GNU Emacs; see the file COPYING. If not, write to the 28;; along with this program; see the file COPYING. If not, write to
29;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 29;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
30;; Boston, MA 02111-1307, USA. 30;; Boston, MA 02111-1307, USA.
31 31
32(eval-when-compile 32(eval-when-compile
33 (let ((load-path 33 (let ((load-path
34 (if (and (boundp 'byte-compile-current-file) 34 (if (and (boundp 'byte-compile-dest-file)
35 (stringp byte-compile-current-file)) 35 (stringp byte-compile-dest-file))
36 (cons (file-name-directory byte-compile-current-file) 36 (cons (file-name-directory byte-compile-dest-file) load-path)
37 load-path)
38 load-path))) 37 load-path)))
39 (load "cc-defs" nil t))) 38 (require 'cc-bytecomp)))
40(require 'cc-vars)
41 39
40(cc-require 'cc-defs)
41(cc-require 'cc-vars)
42 42
43 43
44;; Warning: don't eval-defun this constant or you'll break style inheritance. 44;; Warning: don't eval-defun this constant or you'll break style inheritance.
@@ -340,61 +340,6 @@ STYLE using `c-set-style' if the optional SET-P flag is non-nil."
340 340
341 341
342 342
343(defun c-evaluate-offset (offset langelem symbol)
344 ;; offset can be a number, a function, a variable, a list, or one of
345 ;; the symbols + or -
346 (cond
347 ((eq offset '+) (setq offset c-basic-offset))
348 ((eq offset '-) (setq offset (- c-basic-offset)))
349 ((eq offset '++) (setq offset (* 2 c-basic-offset)))
350 ((eq offset '--) (setq offset (* 2 (- c-basic-offset))))
351 ((eq offset '*) (setq offset (/ c-basic-offset 2)))
352 ((eq offset '/) (setq offset (/ (- c-basic-offset) 2)))
353 ((functionp offset) (setq offset (funcall offset langelem)))
354 ((listp offset)
355 (setq offset
356 (let (done)
357 (while (and (not done) offset)
358 (setq done (c-evaluate-offset (car offset) langelem symbol)
359 offset (cdr offset)))
360 (if (not done)
361 (if c-strict-syntax-p
362 (error "No offset found for syntactic symbol %s" symbol)
363 0)
364 done))))
365 ((not (numberp offset)) (setq offset (symbol-value offset)))
366 )
367 offset)
368
369(defun c-get-offset (langelem)
370 ;; Get offset from LANGELEM which is a cons cell of the form:
371 ;; (SYMBOL . RELPOS). The symbol is matched against
372 ;; c-offsets-alist and the offset found there is either returned,
373 ;; or added to the indentation at RELPOS. If RELPOS is nil, then
374 ;; the offset is simply returned.
375 (let* ((symbol (car langelem))
376 (relpos (cdr langelem))
377 (match (assq symbol c-offsets-alist))
378 (offset (cdr-safe match)))
379 (if (not match)
380 (if c-strict-syntax-p
381 (error "No offset found for syntactic symbol %s" symbol)
382 (setq offset 0
383 relpos 0))
384 (setq offset (c-evaluate-offset offset langelem symbol)))
385 (+ (if (and relpos
386 (< relpos (c-point 'bol)))
387 (save-excursion
388 (goto-char relpos)
389 (current-column))
390 0)
391 (or (and (numberp offset) offset)
392 (and (symbolp offset) (symbol-value offset))
393 0))
394 ))
395
396
397
398(defvar c-read-offset-history nil) 343(defvar c-read-offset-history nil)
399 344
400(defun c-read-offset (langelem) 345(defun c-read-offset (langelem)
@@ -405,7 +350,7 @@ STYLE using `c-set-style' if the optional SET-P flag is non-nil."
405 'c-stylevar-fallback))))) 350 'c-stylevar-fallback)))))
406 (symname (symbol-name langelem)) 351 (symname (symbol-name langelem))
407 (defstr (format "(default %s): " oldoff)) 352 (defstr (format "(default %s): " oldoff))
408 (errmsg (concat "Offset must be int, func, var, list, " 353 (errmsg (concat "Offset must be int, func, var, vector, list, "
409 "or [+,-,++,--,*,/] " 354 "or [+,-,++,--,*,/] "
410 defstr)) 355 defstr))
411 (prompt (concat symname " offset " defstr)) 356 (prompt (concat symname " offset " defstr))
@@ -425,11 +370,14 @@ STYLE using `c-set-style' if the optional SET-P flag is non-nil."
425 ;; a symbol with a function binding 370 ;; a symbol with a function binding
426 ((fboundp (setq interned (intern input))) 371 ((fboundp (setq interned (intern input)))
427 interned) 372 interned)
428 ;; a lambda function
429 ((c-safe (functionp (setq raw (read input))))
430 raw)
431 ;; a symbol with variable binding 373 ;; a symbol with variable binding
432 ((boundp interned) interned) 374 ((boundp interned) interned)
375 ;; a lambda function or a vector
376 ((progn
377 (c-safe (setq raw (read input)))
378 (or (functionp raw)
379 (vectorp raw)))
380 raw)
433 ;; error, but don't signal one, keep trying 381 ;; error, but don't signal one, keep trying
434 ;; to read an input value 382 ;; to read an input value
435 (t (ding) 383 (t (ding)
@@ -466,7 +414,8 @@ and exists only for compatibility reasons."
466 (list langelem offset current-prefix-arg))) 414 (list langelem offset current-prefix-arg)))
467 ;; sanity check offset 415 ;; sanity check offset
468 (unless (c-valid-offset offset) 416 (unless (c-valid-offset offset)
469 (error "Offset must be int, func, var, list, or in [+,-,++,--,*,/]: %s" 417 (error (concat "Offset must be int, func, var, vector, list, "
418 "or in [+,-,++,--,*,/]: %s")
470 offset)) 419 offset))
471 (let ((entry (assq symbol c-offsets-alist))) 420 (let ((entry (assq symbol c-offsets-alist)))
472 (if entry 421 (if entry
@@ -485,7 +434,7 @@ and exists only for compatibility reasons."
485 ;; style. Only do this once! 434 ;; style. Only do this once!
486 (unless (get 'c-initialize-builtin-style 'is-run) 435 (unless (get 'c-initialize-builtin-style 'is-run)
487 (put 'c-initialize-builtin-style 'is-run t) 436 (put 'c-initialize-builtin-style 'is-run t)
488 (c-initialize-cc-mode) 437 ;;(c-initialize-cc-mode)
489 (or (assoc "cc-mode" c-style-alist) 438 (or (assoc "cc-mode" c-style-alist)
490 (assoc "user" c-style-alist) 439 (assoc "user" c-style-alist)
491 (progn 440 (progn
@@ -550,5 +499,5 @@ instead of `make-variable-buffer-local'."
550 499
551 500
552 501
553(provide 'cc-styles) 502(cc-provide 'cc-styles)
554;;; cc-styles.el ends here 503;;; cc-styles.el ends here
diff --git a/lisp/progmodes/cc-vars.el b/lisp/progmodes/cc-vars.el
index e7f84f49110..ec4a729b7b3 100644
--- a/lisp/progmodes/cc-vars.el
+++ b/lisp/progmodes/cc-vars.el
@@ -1,6 +1,6 @@
1;;; cc-vars.el --- user customization variables for CC Mode 1;;; cc-vars.el --- user customization variables for CC Mode
2 2
3;; Copyright (C) 1985,87,92,93,94,95,96,97,98,99,2000 Free Software Foundation, Inc. 3;; Copyright (C) 1985,1987,1992-2001 Free Software Foundation, Inc.
4 4
5;; Authors: 2000- Martin Stjernholm 5;; Authors: 2000- Martin Stjernholm
6;; 1998-1999 Barry A. Warsaw and Martin Stjernholm 6;; 1998-1999 Barry A. Warsaw and Martin Stjernholm
@@ -25,20 +25,44 @@
25;; GNU General Public License for more details. 25;; GNU General Public License for more details.
26 26
27;; 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
28;; along with GNU Emacs; see the file COPYING. If not, write to the 28;; along with this program; see the file COPYING. If not, write to
29;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 29;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
30;; Boston, MA 02111-1307, USA. 30;; Boston, MA 02111-1307, USA.
31 31
32(eval-when-compile 32(eval-when-compile
33 (let ((load-path 33 (let ((load-path
34 (if (and (boundp 'byte-compile-current-file) 34 (if (and (boundp 'byte-compile-dest-file)
35 (stringp byte-compile-current-file)) 35 (stringp byte-compile-dest-file))
36 (cons (file-name-directory byte-compile-current-file) 36 (cons (file-name-directory byte-compile-dest-file) load-path)
37 load-path)
38 load-path))) 37 load-path)))
39 (load "cc-defs" nil t))) 38 (require 'cc-bytecomp)))
40(require 'custom) 39
41 40(cc-require 'cc-defs)
41
42;; Silence the compiler.
43(cc-bytecomp-defun get-char-table) ; XEmacs 20+
44(cc-bytecomp-defun char-table-range) ; Emacs 19+
45(cc-bytecomp-defun char-table-p) ; Emacs 19+, XEmacs 20+
46
47;; Pull in custom if it exists and is recent enough (the one in Emacs
48;; 19.34 isn't).
49(eval
50 (cc-eval-when-compile
51 (condition-case nil
52 (progn
53 (require 'custom)
54 (or (fboundp 'defcustom) (error ""))
55 (require 'wid-edit)
56 '(progn ; Compile in the require's.
57 (require 'custom)
58 (require 'wid-edit)))
59 (error
60 (message "Warning: Compiling without Customize support \
61since a (good enough) custom library wasn't found")
62 (cc-bytecomp-defmacro define-widget (name class doc &rest args))
63 (cc-bytecomp-defmacro defcustom (symbol value doc &rest args)
64 `(defvar ,symbol ,value ,doc))
65 nil))))
42 66
43 67
44;;; Helpers 68;;; Helpers
@@ -84,11 +108,8 @@ Useful as last item in a `choice' widget."
84 108
85(defmacro defcustom-c-stylevar (name val doc &rest args) 109(defmacro defcustom-c-stylevar (name val doc &rest args)
86 "Defines a style variable." 110 "Defines a style variable."
87 (setq val (if (eq (car-safe val) 'quote)
88 (nth 1 val)
89 (eval val)))
90 `(progn 111 `(progn
91 (put ',name 'c-stylevar-fallback ',val) 112 (put ',name 'c-stylevar-fallback ,val)
92 (defcustom ,name 'set-from-style 113 (defcustom ,name 'set-from-style
93 ,(concat doc " 114 ,(concat doc "
94 115
@@ -124,6 +145,7 @@ See `c-offsets-alist'."
124 (eq offset '*) 145 (eq offset '*)
125 (eq offset '/) 146 (eq offset '/)
126 (integerp offset) 147 (integerp offset)
148 (vectorp offset)
127 (functionp offset) 149 (functionp offset)
128 (and (symbolp offset) 150 (and (symbolp offset)
129 (or (boundp offset) 151 (or (boundp offset)
@@ -195,7 +217,7 @@ should be inserted. Value must be a function taking no arguments."
195 :group 'c) 217 :group 'c)
196 218
197(defcustom c-syntactic-indentation t 219(defcustom c-syntactic-indentation t
198 "*Whether the identation should be controlled by the syntactic context. 220 "*Whether the indentation should be controlled by the syntactic context.
199 221
200If t, the indentation functions indents according to the syntactic 222If t, the indentation functions indents according to the syntactic
201context, using the style settings specified by `c-offsets-alist'. 223context, using the style settings specified by `c-offsets-alist'.
@@ -240,6 +262,15 @@ comment-only lines."
240 :type 'boolean 262 :type 'boolean
241 :group 'c) 263 :group 'c)
242 264
265(make-obsolete-variable 'c-comment-continuation-stars
266 'c-block-comment-prefix)
267
268;; Although c-comment-continuation-stars is obsolete, we look at it in
269;; some places in CC Mode anyway, so make the compiler ignore it
270;; during our compilation.
271(cc-bytecomp-obsolete-var c-comment-continuation-stars)
272(cc-bytecomp-defvar c-comment-continuation-stars)
273
243(defcustom-c-stylevar c-block-comment-prefix 274(defcustom-c-stylevar c-block-comment-prefix
244 (if (boundp 'c-comment-continuation-stars) 275 (if (boundp 'c-comment-continuation-stars)
245 c-comment-continuation-stars 276 c-comment-continuation-stars
@@ -259,25 +290,50 @@ style comments."
259 :type 'string 290 :type 'string
260 :group 'c) 291 :group 'c)
261 292
262(make-obsolete-variable 'c-comment-continuation-stars 293(defcustom-c-stylevar c-comment-prefix-regexp
263 'c-block-comment-prefix) 294 '((pike-mode . "//+!?\\|\\**")
264 295 (other . "//+\\|\\**"))
265(defcustom-c-stylevar c-comment-prefix-regexp "//+\\|\\**"
266 "*Regexp to match the line prefix inside comments. 296 "*Regexp to match the line prefix inside comments.
267This regexp is used to recognize the fill prefix inside comments for 297This regexp is used to recognize the fill prefix inside comments for
268correct paragraph filling and other things. 298correct paragraph filling and other things.
269 299
270It should match the prefix used in both C++ style line comments and C 300If this variable is a string, it will be used in all CC Mode major
271style block comments, but it does not need to match a block comment 301modes. It can also be an association list, to associate specific
272starter. In other words, it should at least match \"//\" for line 302regexps to specific major modes. The symbol for the major mode is
273comments and the string in `c-block-comment-prefix', which is 303looked up in the association list, and its value is used as the line
274sometimes inserted by CC Mode inside block comments. It should not 304prefix regexp. If it's not found, then the symbol `other' is looked
275match any surrounding whitespace. 305up and its value is used instead.
306
307The regexp should match the prefix used in both C++ style line
308comments and C style block comments, but it does not need to match a
309block comment starter. In other words, it should at least match
310\"//\" for line comments and the string in `c-block-comment-prefix',
311which is sometimes inserted by CC Mode inside block comments. It
312should not match any surrounding whitespace.
276 313
277Note that CC Mode modifies other variables from this one at mode 314Note that CC Mode modifies other variables from this one at mode
278initialization, so you might need to do \\[c-mode] (or whatever mode 315initialization, so you will need to do \\[c-mode] (or whatever mode
279you're currently using) if you change it in a CC Mode buffer." 316you're currently using) if you change it in a CC Mode buffer."
280 :type 'regexp 317 :type '(radio
318 (regexp :tag "Regexp for all modes")
319 (list
320 :tag "Mode-specific regexps"
321 (set
322 :inline t :format "%v"
323 (cons :format "%v"
324 (const :format "C " c-mode) (regexp :format "%v"))
325 (cons :format "%v"
326 (const :format "C++ " c++-mode) (regexp :format "%v"))
327 (cons :format "%v"
328 (const :format "ObjC " objc-mode) (regexp :format "%v"))
329 (cons :format "%v"
330 (const :format "Java " java-mode) (regexp :format "%v"))
331 (cons :format "%v"
332 (const :format "IDL " idl-mode) (regexp :format "%v"))
333 (cons :format "%v"
334 (const :format "Pike " pike-mode) (regexp :format "%v")))
335 (cons :format " %v"
336 (const :format "Other " other) (regexp :format "%v"))))
281 :group 'c) 337 :group 'c)
282 338
283(defcustom c-ignore-auto-fill '(string cpp code) 339(defcustom c-ignore-auto-fill '(string cpp code)
@@ -303,47 +359,74 @@ contexts are:
303 359
304(defcustom-c-stylevar c-cleanup-list '(scope-operator) 360(defcustom-c-stylevar c-cleanup-list '(scope-operator)
305 "*List of various C/C++/ObjC constructs to \"clean up\". 361 "*List of various C/C++/ObjC constructs to \"clean up\".
306These clean ups only take place when the auto-newline feature is 362The following clean ups only take place when the auto-newline feature
307turned on, as evidenced by the `/a' or `/ah' appearing next to the 363is turned on, as evidenced by the `/a' or `/ah' appearing next to the
308mode name. Valid symbols are: 364mode name:
309 365
310 brace-else-brace -- cleans up `} else {' constructs by placing entire 366 brace-else-brace -- Clean up \"} else {\" constructs by placing
311 construct on a single line. This clean up 367 entire construct on a single line. This clean
312 only takes place when there is nothing but 368 up only takes place when there is nothing but
313 white space between the braces and the `else'. 369 white space between the braces and the `else'.
314 Clean up occurs when the open brace after the 370 Clean up occurs when the open brace after the
315 `else' is typed. 371 `else' is typed.
316 brace-elseif-brace -- similar to brace-else-brace, but cleans up 372 brace-elseif-brace -- Similar to brace-else-brace, but clean up
317 `} else if (...) {' constructs. Clean up occurs 373 \"} else if (...) {\" constructs. Clean up
318 after the open parenthesis and the open brace. 374 occurs after the open parenthesis and the open
319 brace-catch-brace -- similar to brace-elseif-brace, but cleans up 375 brace.
320 `} catch (...) {' constructs. 376 brace-catch-brace -- Similar to brace-elseif-brace, but clean up
321 empty-defun-braces -- cleans up empty defun braces by placing the 377 \"} catch (...) {\" constructs.
378 empty-defun-braces -- Clean up empty defun braces by placing the
322 braces on the same line. Clean up occurs when 379 braces on the same line. Clean up occurs when
323 the defun closing brace is typed. 380 the defun closing brace is typed.
324 defun-close-semi -- cleans up the terminating semi-colon on defuns 381 defun-close-semi -- Clean up the terminating semi-colon on defuns
325 by placing the semi-colon on the same line as 382 by placing the semi-colon on the same line as
326 the closing brace. Clean up occurs when the 383 the closing brace. Clean up occurs when the
327 semi-colon is typed. 384 semi-colon is typed.
328 list-close-comma -- cleans up commas following braces in array 385 list-close-comma -- Clean up commas following braces in array
329 and aggregate initializers. Clean up occurs 386 and aggregate initializers. Clean up occurs
330 when the comma is typed. 387 when the comma is typed.
331 scope-operator -- cleans up double colons which may designate 388 scope-operator -- Clean up double colons which may designate
332 a C++ scope operator split across multiple 389 a C++ scope operator split across multiple
333 lines. Note that certain C++ constructs can 390 lines. Note that certain C++ constructs can
334 generate ambiguous situations. This clean up 391 generate ambiguous situations. This clean up
335 only takes place when there is nothing but 392 only takes place when there is nothing but
336 whitespace between colons. Clean up occurs 393 whitespace between colons. Clean up occurs
337 when the second colon is typed." 394 when the second colon is typed.
395
396The following clean ups always take place when they are on this list,
397regardless of the auto-newline feature, since they typically don't
398involve auto-newline inserted newlines:
399
400 space-before-funcall -- Insert exactly one space before the opening
401 parenthesis of a function call. Clean up
402 occurs when the opening parenthesis is typed.
403 compact-empty-funcall -- Clean up any space before the function call
404 opening parenthesis if and only if the
405 argument list is empty. This is typically
406 useful together with `space-before-funcall' to
407 get the style \"foo (bar)\" and \"foo()\".
408 Clean up occurs when the closing parenthesis
409 is typed."
338 :type '(set 410 :type '(set
339 :extra-offset 8 411 :extra-offset 8
340 (const :tag "Put `} else {' on one line" brace-else-brace) 412 (const :tag "Put \"} else {\" on one line"
341 (const :tag "Put `} else if (...) {' on one line" brace-elseif-brace) 413 brace-else-brace)
342 (const :tag "Put `} catch (...) {' on one line" brace-catch-brace) 414 (const :tag "Put \"} else if (...) {\" on one line"
343 (const :tag "Put empty defun braces on one line" empty-defun-braces) 415 brace-elseif-brace)
344 (const :tag "Put `};' ending defuns on one line" defun-close-semi) 416 (const :tag "Put \"} catch (...) {\" on one line"
345 (const :tag "Put `},' in aggregates on one line" list-close-comma) 417 brace-catch-brace)
346 (const :tag "Put C++ style `::' on one line" scope-operator)) 418 (const :tag "Put empty defun braces on one line"
419 empty-defun-braces)
420 (const :tag "Put \"};\" ending defuns on one line"
421 defun-close-semi)
422 (const :tag "Put \"},\" in aggregates on one line"
423 list-close-comma)
424 (const :tag "Put C++ style \"::\" on one line"
425 scope-operator)
426 (const :tag "Put a space before funcall parens, e.g. \"foo (bar)\""
427 space-before-funcall)
428 (const :tag "Remove space before empty funcalls, e.g. \"foo()\""
429 compact-empty-funcall))
347 :group 'c) 430 :group 'c)
348 431
349(defcustom-c-stylevar c-hanging-braces-alist '((brace-list-open) 432(defcustom-c-stylevar c-hanging-braces-alist '((brace-list-open)
@@ -500,7 +583,7 @@ this variable to nil."
500 :type 'integer 583 :type 'integer
501 :group 'c) 584 :group 'c)
502 585
503(defcustom c-default-style "gnu" 586(defcustom c-default-style '((java-mode . "java") (other . "gnu"))
504 "*Style which gets installed by default when a file is visited. 587 "*Style which gets installed by default when a file is visited.
505 588
506The value of this variable can be any style defined in 589The value of this variable can be any style defined in
@@ -508,8 +591,7 @@ The value of this variable can be any style defined in
508association list of major mode symbols to style names. 591association list of major mode symbols to style names.
509 592
510When the value is a string, all CC Mode major modes will install this 593When the value is a string, all CC Mode major modes will install this
511style by default, except `java-mode', which always installs the 594style by default.
512\"java\" style (this is for backwards compatibility).
513 595
514When the value is an alist, the major mode symbol is looked up in it 596When the value is an alist, the major mode symbol is looked up in it
515and the associated style is installed. If the major mode is not 597and the associated style is installed. If the major mode is not
@@ -519,22 +601,24 @@ the alist, then \"gnu\" style is used.
519 601
520The default style gets installed before your mode hooks run, so you 602The default style gets installed before your mode hooks run, so you
521can always override the use of `c-default-style' by making calls to 603can always override the use of `c-default-style' by making calls to
522`c-set-style' in the appropriate mode hook. 604`c-set-style' in the appropriate mode hook."
523
524Tip: If you use different styles in different languages, you probably
525want to set `c-style-variables-are-local-p'."
526 :type '(radio 605 :type '(radio
527 (string :tag "Style in all modes (except Java)") 606 (string :tag "Style in all modes")
528 (repeat :tag "Mode-specific styles" 607 (set :tag "Mode-specific styles"
529 :value ((other . "gnu")) 608 (cons :format "%v"
530 (cons :format "%v" 609 (const :format "C " c-mode) (string :format "%v"))
531 (choice :tag "Mode" 610 (cons :format "%v"
532 (const c-mode) (const c++-mode) 611 (const :format "C++ " c++-mode) (string :format "%v"))
533 (const objc-mode) (const java-mode) 612 (cons :format "%v"
534 (const idl-mode) (const pike-mode) 613 (const :format "ObjC " objc-mode) (string :format "%v"))
535 (const other)) 614 (cons :format "%v"
536 (string :tag "Style") 615 (const :format "Java " java-mode) (string :format "%v"))
537 ))) 616 (cons :format "%v"
617 (const :format "IDL " idl-mode) (string :format "%v"))
618 (cons :format "%v"
619 (const :format "Pike " pike-mode) (string :format "%v"))
620 (cons :format "%v"
621 (const :format "Other " other) (string :format "%v"))))
538 :group 'c) 622 :group 'c)
539 623
540(put 'c-offsets-alist 'c-stylevar-fallback 624(put 'c-offsets-alist 'c-stylevar-fallback
@@ -660,13 +744,13 @@ want to set `c-style-variables-are-local-p'."
660 (inclass . +) 744 (inclass . +)
661 ;; Relpos: At the class open brace if it's at boi, otherwise 745 ;; Relpos: At the class open brace if it's at boi, otherwise
662 ;; boi at the class decl start. 746 ;; boi at the class decl start.
663 (cpp-macro . -1000) 747 (cpp-macro . [0])
664 ;; Relpos: None. 748 ;; Relpos: None.
665 (cpp-macro-cont . c-lineup-dont-change) 749 (cpp-macro-cont . c-lineup-dont-change)
666 ;; Relpos: At the macro start (always at boi). 750 ;; Relpos: At the macro start (always at boi).
667 (friend . 0) 751 (friend . 0)
668 ;; Relpos: None. 752 ;; Relpos: None.
669 (objc-method-intro . -1000) 753 (objc-method-intro . [0])
670 ;; Relpos: Boi. 754 ;; Relpos: Boi.
671 (objc-method-args-cont . c-lineup-ObjC-method-args) 755 (objc-method-args-cont . c-lineup-ObjC-method-args)
672 ;; Relpos: At the method start (always at boi). 756 ;; Relpos: At the method start (always at boi).
@@ -722,23 +806,33 @@ The sum of this calculation for each element in the syntactic list is
722the absolute offset for line being indented. 806the absolute offset for line being indented.
723 807
724If the syntactic element does not match any in the `c-offsets-alist', 808If the syntactic element does not match any in the `c-offsets-alist',
725an error is generated if `c-strict-syntax-p' is non-nil, otherwise the 809the element is ignored.
726element is ignored. 810
727 811If OFFSET is nil, the syntactic element is ignored in the offset
728Actually, OFFSET can be an integer, a function, a variable, or one of 812calculation.
729the following symbols: `+', `-', `++', `--', `*', or `/'. These 813
730latter designate positive or negative multiples of `c-basic-offset', 814If OFFSET is an integer, it's added to the relative indent.
731respectively: 1, -1, 2, -2, 0.5, and -0.5. If OFFSET is a function, 815
732it is called with a single argument containing the cons of the 816If OFFSET is one of the symbols `+', `-', `++', `--', `*', or `/', a
733syntactic element symbol and the relative indent point. The function 817positive or negative multiple of `c-basic-offset' is added; 1, -1, 2,
734should return an integer offset or nil if it can't decide. 818-2, 0.5, and -0.5, respectively.
735 819
736OFFSET can also be a list, in which case it is recursively evaluated 820If OFFSET is a vector, it's first element, which must be an integer,
737using the semantics described above. The first element of the list to 821is used as an absolute indentation column. This overrides all
738return a non-nil value succeeds. If none of the elements returns a 822relative offsets. If there are several syntactic elements which
739non-nil value, then what happends depends on the value of 823evaluates to absolute indentation columns, the first one takes
740`c-strict-syntax-p'. When `c-strict-syntax-p' is nil, then an offset 824precedence. You can see in which order CC Mode combines the syntactic
741of zero is used, otherwise an error is generated. 825elements in a certain context by using \\[c-show-syntactic-information] on the line.
826
827If OFFSET is a function, it's called with a single argument
828containing the cons of the syntactic element symbol and the relative
829indent point. The return value from the function is then
830reinterpreted as an OFFSET value.
831
832If OFFSET is a list, it's recursively evaluated using the semantics
833described above. The first element of the list to return a non-nil
834value succeeds. If none of the elements returns a non-nil value, the
835syntactic element is ignored.
742 836
743`c-offsets-alist' is a style variable. This means that the offsets on 837`c-offsets-alist' is a style variable. This means that the offsets on
744this variable are normally taken from the style system in CC Mode 838this variable are normally taken from the style system in CC Mode
@@ -962,11 +1056,18 @@ as designated in the variable `c-file-style'.")
962(make-variable-buffer-local 'c-file-offsets) 1056(make-variable-buffer-local 'c-file-offsets)
963 1057
964(defvar c-syntactic-context nil 1058(defvar c-syntactic-context nil
965 "Variable containing syntactic analysis list during indentation.") 1059 "Variable containing syntactic analysis list during indentation.
1060This is always bound dynamically. It should never be set statically
1061(e.g. with `setq').")
966 1062
967(defvar c-indentation-style nil 1063(defvar c-indentation-style nil
968 "Name of the currently installed style.") 1064 "Name of the currently installed style.
1065Don't change this directly; call `c-set-style' instead.")
969 1066
1067(defvar c-current-comment-prefix nil
1068 "The current comment prefix regexp.
1069Set from `c-comment-prefix-regexp' at mode initialization.")
1070(make-variable-buffer-local 'c-current-comment-prefix)
970 1071
971 1072
972;; Figure out what features this Emacs has 1073;; Figure out what features this Emacs has
@@ -1011,7 +1112,6 @@ supported list, along with the values for this variable:
1011Infodock (based on XEmacs) has an additional symbol on this list: 1112Infodock (based on XEmacs) has an additional symbol on this list:
1012`infodock'.") 1113`infodock'.")
1013 1114
1014
1015 1115
1016(provide 'cc-vars) 1116(cc-provide 'cc-vars)
1017;;; cc-vars.el ends here 1117;;; cc-vars.el ends here