Skip to content
This repository
Browse code

Installed CC Mode 5.25.

  • Loading branch information...
commit ddca225854b222f6a1bba28acc2c8c387729eb1e 1 parent 587f2e9
authored
47  lisp/progmodes/cc-align.el
@@ -2,10 +2,11 @@
2 2
 
3 3
 ;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc.
4 4
 
5  
-;; Authors:    1992-1997 Barry A. Warsaw
  5
+;; Authors:    1998 Barry A. Warsaw and Martin Stjernholm
  6
+;;             1992-1997 Barry A. Warsaw
6 7
 ;;             1987 Dave Detlefs and Stewart Clamen
7 8
 ;;             1985 Richard M. Stallman
8  
-;; Maintainer: cc-mode-help@python.org
  9
+;; Maintainer: bug-cc-mode@gnu.org
9 10
 ;; Created:    22-Apr-1997 (split from cc-mode.el)
10 11
 ;; Version:    See cc-mode.el
11 12
 ;; Keywords:   c languages oop
@@ -28,6 +29,7 @@
28 29
 ;; Boston, MA 02111-1307, USA.
29 30
 
30 31
 (eval-when-compile
  32
+  (require 'cc-defs)
31 33
   (require 'cc-vars)
32 34
   (require 'cc-engine)
33 35
   (require 'cc-langs))
@@ -57,7 +59,7 @@
57 59
 	    (beginning-of-line)
58 60
 	    (looking-at "[ \t]*)"))
59 61
 	  (progn (goto-char (match-end 0))
60  
-		 (forward-sexp -1)
  62
+		 (c-forward-sexp -1)
61 63
 		 (forward-char 1)
62 64
 		 (c-forward-syntactic-ws)
63 65
 		 (- (current-column) langelem-col))
@@ -111,9 +113,8 @@
111 113
 	(let (opencol spec)
112 114
 	  (beginning-of-line)
113 115
 	  (backward-up-list 1)
114  
-	  (setq spec (if (fboundp 'c-looking-at-special-brace-list)
115  
-			 (c-looking-at-special-brace-list)))
116  
-	  (if spec (goto-char (car spec)))
  116
+	  (setq spec (c-looking-at-special-brace-list))
  117
+	  (if spec (goto-char (car (car spec))))
117 118
 	  (setq opencol (current-column))
118 119
 	  (forward-char 1)
119 120
 	  (if spec (progn
@@ -194,9 +195,7 @@
194 195
       (beginning-of-line)
195 196
       (skip-chars-forward " \t")
196 197
       (if (and (eq (following-char) ?{)
197  
-	       (condition-case nil
198  
-		   (progn (forward-sexp) t)
199  
-		 (error nil))
  198
+	       (c-safe (progn (c-forward-sexp) t))
200 199
 	       (<= (point) eol)
201 200
 	       (eq (preceding-char) ?}))
202 201
 	  c-basic-offset
@@ -291,7 +290,11 @@
291 290
 	(if (c-in-literal (cdr langelem))
292 291
 	    (forward-char 1)
293 292
 	  (setq donep t)))
294  
-      (if (not (eq (char-after) ?=))
  293
+      (if (or (not (eq (char-after) ?=))
  294
+	      (save-excursion
  295
+		(forward-char 1)
  296
+		(c-forward-syntactic-ws (c-point 'eol))
  297
+		(eolp)))
295 298
 	  ;; there's no equal sign on the line
296 299
 	  c-basic-offset
297 300
 	;; calculate indentation column after equals and ws, unless
@@ -324,7 +327,7 @@
324 327
 			       (current-column)))
325 328
            (target-col (progn
326 329
 			 (forward-char)
327  
-			 (forward-sexp)
  330
+			 (c-forward-sexp)
328 331
 			 (skip-chars-forward " \t")
329 332
 			 (if (eolp)
330 333
 			     (+ open-bracket-col c-basic-offset)
@@ -373,6 +376,26 @@
373 376
 	    (+ curcol (- prev-col-column (current-column)))
374 377
 	  c-basic-offset)))))
375 378
 
  379
+(defun c-lineup-inexpr-block (langelem)
  380
+  ;; This function lines up the block for the various constructs that
  381
+  ;; uses a block inside an expression.  For constructs matching
  382
+  ;; c-lambda-key and c-inexpr-block-key, indentation to the column of
  383
+  ;; the beginning of the match is added.  For standalone statement
  384
+  ;; blocks, indentation to the column of the opening brace is added.
  385
+  (save-excursion
  386
+    (back-to-indentation)
  387
+    (let ((res (or (c-looking-at-inexpr-block)
  388
+		   (if (c-safe (backward-up-list 1)
  389
+			       (eq (char-after) ?{))
  390
+		       (c-looking-at-inexpr-block)))))
  391
+      (if (not res)
  392
+	  0
  393
+	(goto-char (cdr res))
  394
+	(- (current-column)
  395
+	   (progn
  396
+	     (back-to-indentation)
  397
+	     (current-column)))))))
  398
+
376 399
 (defun c-lineup-dont-change (langelem)
377 400
   ;; Do not change the indentation of the current line
378 401
   (save-excursion
@@ -394,7 +417,7 @@ ACTION associated with `block-close' syntax."
394 417
 	       (setq langelem (assq 'block-close c-syntactic-context))
395 418
 	       (progn (goto-char (cdr langelem))
396 419
 		      (if (eq (char-after) ?{)
397  
-			  (c-safe (forward-sexp -1)))
  420
+			  (c-safe (c-forward-sexp -1)))
398 421
 		      (looking-at "\\<do\\>[^_]")))
399 422
 	  '(before)
400 423
 	'(before after)))))
507  lisp/progmodes/cc-cmds.el
... ...
@@ -1,11 +1,12 @@
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 Free Software Foundation, Inc.
  3
+;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Softare Foundation, Inc.
4 4
 
5  
-;; Authors:    1992-1997 Barry A. Warsaw
  5
+;; Authors:    1998 Barry A. Warsaw and Martin Stjernholm
  6
+;;             1992-1997 Barry A. Warsaw
6 7
 ;;             1987 Dave Detlefs and Stewart Clamen
7 8
 ;;             1985 Richard M. Stallman
8  
-;; Maintainer: cc-mode-help@python.org
  9
+;; Maintainer: bug-cc-mode@gnu.org
9 10
 ;; Created:    22-Apr-1997 (split from cc-mode.el)
10 11
 ;; Version:    See cc-mode.el
11 12
 ;; Keywords:   c languages oop
@@ -29,6 +30,9 @@
29 30
 
30 31
 
31 32
 
  33
+(eval-when-compile
  34
+  (require 'cc-defs))
  35
+
32 36
 (defun c-calculate-state (arg prevstate)
33 37
   ;; Calculate the new state of PREVSTATE, t or nil, based on arg. If
34 38
   ;; arg is nil or zero, toggle the state. If arg is negative, turn
@@ -128,8 +132,10 @@ consumed.  If however an ARG is supplied, or `c-hungry-delete-key' is
128 132
 nil, or point is inside a literal then the function in the variable
129 133
 `c-delete-function' is called."
130 134
   (interactive "*P")
131  
-  (if (and (boundp 'delete-key-deletes-forward)
132  
-	   delete-key-deletes-forward)
  135
+  (if (or (and (fboundp 'delete-forward-p) ;XEmacs 21
  136
+	       (delete-forward-p))
  137
+	  (and (boundp 'delete-key-deletes-forward) ;XEmacs 20
  138
+	       delete-key-deletes-forward))
133 139
       (if (or (not c-hungry-delete-key)
134 140
 	      arg
135 141
 	      (c-in-literal))
@@ -148,9 +154,10 @@ Inserts a `#' character specially depending on the variable
148 154
 `c-electric-pound-behavior'.  If a numeric ARG is supplied, or if
149 155
 point is inside a literal, nothing special happens."
150 156
   (interactive "*P")
151  
-  (if (or (c-in-literal)
152  
-	  arg
153  
-	  (not (memq 'alignleft c-electric-pound-behavior)))
  157
+  (if (or arg
  158
+	  (not (memq 'alignleft c-electric-pound-behavior))
  159
+	  (save-excursion (skip-chars-backward " \t") (not (bolp)))
  160
+	  (c-in-literal))
154 161
       ;; do nothing special
155 162
       (self-insert-command (prefix-numeric-value arg))
156 163
     ;; place the pound character at the left edge
@@ -172,7 +179,10 @@ after braces based on the value of `c-hanging-braces-alist'.
172 179
 
173 180
 Also, the line is re-indented unless a numeric ARG is supplied, there
174 181
 are non-whitespace characters present on the line after the brace, or
175  
-the brace is inserted inside a literal."
  182
+the brace is inserted inside a literal.
  183
+
  184
+This function does various newline cleanups based on the value of
  185
+`c-cleanup-list'."
176 186
   (interactive "*P")
177 187
   (let* ((c-state-cache (c-parse-state))
178 188
 	 (safepos (c-safe-position (point) c-state-cache))
@@ -180,8 +190,8 @@ the brace is inserted inside a literal."
180 190
     ;; if we're in a literal, or we're not at the end of the line, or
181 191
     ;; a numeric arg is provided, or auto-newlining is turned off,
182 192
     ;; then just insert the character.
183  
-    (if (or literal arg
184  
-;	    (not c-auto-newline)
  193
+    (if (or literal
  194
+	    arg
185 195
 	    (not (looking-at "[ \t]*$")))
186 196
 	(self-insert-command (prefix-numeric-value arg))
187 197
       (let* ((syms
@@ -191,11 +201,12 @@ the brace is inserted inside a literal."
191 201
 	      '(class-open class-close defun-open defun-close
192 202
 		inline-open inline-close
193 203
 		brace-list-open brace-list-close
194  
-		brace-list-intro brace-list-entry
  204
+		brace-list-intro brace-entry-open
195 205
 		block-open block-close
196 206
 		substatement-open statement-case-open
197 207
 		extern-lang-open extern-lang-close
198 208
 		namespace-open namespace-close
  209
+		inexpr-class-open inexpr-class-close
199 210
 		))
200 211
 	    ;; we want to inhibit blinking the paren since this will
201 212
 	    ;; be most disruptive. we'll blink it ourselves later on
@@ -220,8 +231,32 @@ the brace is inserted inside a literal."
220 231
 		      (c-guess-basic-syntax)))
221 232
 	    (newlines (and
222 233
 		       c-auto-newline
223  
-		       (or (c-lookup-lists syms syntax c-hanging-braces-alist)
  234
+		       (or (c-lookup-lists
  235
+			    syms
  236
+			    ;; Substitute inexpr-class and class-open
  237
+			    ;; or class-close with inexpr-class-open
  238
+			    ;; or inexpr-class-close.
  239
+			    (if (assq 'inexpr-class syntax)
  240
+				(cond ((assq 'class-open syntax)
  241
+				       '((inexpr-class-open)))
  242
+				      ((assq 'class-close syntax)
  243
+				       '((inexpr-class-close)))
  244
+				      (t syntax))
  245
+			      syntax)
  246
+			    c-hanging-braces-alist)
224 247
 			   '(ignore before after)))))
  248
+	;; Do not try to insert newlines around a special (Pike-style)
  249
+	;; brace list.
  250
+	(if (and c-special-brace-lists
  251
+		 (c-intersect-lists '(brace-list-open brace-list-close
  252
+				      brace-list-intro brace-entry-open)
  253
+				    syntax)
  254
+		 (save-excursion
  255
+		   (c-safe (if (= (char-before) ?{)
  256
+			       (forward-char -1)
  257
+			     (c-forward-sexp -1))
  258
+			   (c-looking-at-special-brace-list))))
  259
+	    (setq newlines nil))
225 260
 	;; If syntax is a function symbol, then call it using the
226 261
 	;; defined semantics.
227 262
 	(if (and (not (consp (cdr newlines)))
@@ -234,29 +269,26 @@ the brace is inserted inside a literal."
234 269
 	    ;; we leave the newline we've put in there before,
235 270
 	    ;; but we need to re-indent the line above
236 271
 	    (let ((pos (- (point-max) (point)))
237  
-		  (here (point))
238  
-		  (c-state-cache c-state-cache))
  272
+		  (here (point)))
239 273
 	      (forward-line -1)
240  
-	      ;; we may need to update the cache. this should still be
241  
-	      ;; faster than recalculating the state in many cases
242  
-	      (save-excursion
243  
-		(save-restriction
244  
-		  (narrow-to-region here (point))
245  
-		  (if (and (c-safe (progn (backward-up-list -1) t))
246  
-			   (memq (char-before) '(?\) ?}))
247  
-			   (progn (widen)
248  
-				  (c-safe (progn (forward-sexp -1) t))))
249  
-		      (setq c-state-cache
250  
-			    (c-hack-state (point) 'open c-state-cache))
251  
-		    (if (and (car c-state-cache)
252  
-			     (not (consp (car c-state-cache)))
253  
-			     (<= (point) (car c-state-cache)))
254  
-			(setq c-state-cache (cdr c-state-cache))
255  
-		      ))))
256  
-	      (let ((here (point))
257  
-		    (shift (c-indent-line)))
258  
-		(setq c-state-cache (c-adjust-state (c-point 'bol) here
259  
-						    (- shift) c-state-cache)))
  274
+	      (let ((c-state-cache (c-whack-state (point) c-state-cache)))
  275
+		;; we may need to update the cache. this should
  276
+		;; still be faster than recalculating the state
  277
+		;; in many cases
  278
+		(save-excursion
  279
+		  (save-restriction
  280
+		    (narrow-to-region here (point))
  281
+		    (if (and (c-safe (progn (backward-up-list -1) t))
  282
+			     (memq (char-before) '(?\) ?}))
  283
+			     (progn (widen)
  284
+				    (c-safe (progn (c-forward-sexp -1)
  285
+						   t))))
  286
+			(setq c-state-cache
  287
+			      (c-hack-state (point) 'open c-state-cache)))))
  288
+		(c-indent-line))
  289
+	      (setq c-state-cache (c-adjust-state (c-point 'bol) here
  290
+						  (- (point) (c-point 'bol))
  291
+						  c-state-cache))
260 292
 	      (goto-char (- (point-max) pos))
261 293
 	      ;; if the buffer has changed due to the indentation, we
262 294
 	      ;; need to recalculate syntax for the current line, but
@@ -291,10 +323,11 @@ the brace is inserted inside a literal."
291 323
 	;; now adjust the line's indentation. don't update the state
292 324
 	;; cache since c-guess-basic-syntax isn't called when the
293 325
 	;; syntax is passed to c-indent-line
294  
-	(let ((here (point))
295  
-	      (shift (c-indent-line syntax)))
  326
+	(let* ((here (point)))
  327
+	  (c-indent-line syntax)
296 328
 	  (setq c-state-cache (c-adjust-state (c-point 'bol) here
297  
-					      (- shift) c-state-cache)))
  329
+					      (- (c-point 'boi) (c-point 'bol))
  330
+					      c-state-cache)))
298 331
 	;; Do all appropriate clean ups
299 332
 	(let ((here (point))
300 333
 	      (pos (- (point-max) (point)))
@@ -325,22 +358,6 @@ the brace is inserted inside a literal."
325 358
 	      (progn
326 359
 		(delete-region mbeg mend)
327 360
 		(insert "} else {")))
328  
-	  ;; clean up brace-elseif-brace
329  
-	  (if (and c-auto-newline
330  
-		   (memq 'brace-elseif-brace c-cleanup-list)
331  
-		   (eq last-command-char ?\{)
332  
-		   (re-search-backward "}[ \t\n]*else[ \t\n]+if[ \t\n]*" nil t)
333  
-		   (save-excursion
334  
-		     (goto-char (match-end 0))
335  
-		     (c-safe (forward-sexp 1))
336  
-		     (skip-chars-forward " \t\n")
337  
-		     (setq mbeg (match-beginning 0)
338  
-			   mend (match-end 0))
339  
-		     (= here (1+ (point))))
340  
-		   (not (c-in-literal)))
341  
-	      (progn
342  
-		(delete-region mbeg mend)
343  
-		(insert "} else if ")))
344 361
 	  (goto-char (- (point-max) pos))
345 362
 	  )
346 363
 	;; does a newline go after the brace?
@@ -359,7 +376,7 @@ the brace is inserted inside a literal."
359 376
 	       (c-backward-syntactic-ws safepos)
360 377
 	       (funcall old-blink-paren)))
361 378
 	))))
362  
-      
  379
+
363 380
 (defun c-electric-slash (arg)
364 381
   "Insert a slash character.
365 382
 
@@ -422,7 +439,10 @@ is determined.
422 439
 
423 440
 When semicolon is inserted, the line is re-indented unless a numeric
424 441
 arg is supplied, point is inside a literal, or there are
425  
-non-whitespace characters on the line following the semicolon."
  442
+non-whitespace characters on the line following the semicolon.
  443
+
  444
+Based on the value of `c-cleanup-list', this function cleans up commas
  445
+following brace lists and semicolons following defuns."
426 446
   (interactive "*P")
427 447
   (let* ((lim (c-most-enclosing-brace (c-parse-state)))
428 448
 	 (literal (c-in-literal lim))
@@ -435,9 +455,10 @@ non-whitespace characters on the line following the semicolon."
435 455
 	(self-insert-command (prefix-numeric-value arg))
436 456
       ;; do some special stuff with the character
437 457
       (self-insert-command (prefix-numeric-value arg))
438  
-      ;; do all cleanups, reindentations, and newline insertions, but
439  
-      ;; only if c-auto-newline is turned on
440  
-      (if (not c-auto-newline) nil
  458
+      ;; do all cleanups and newline insertions if c-auto-newline is
  459
+      ;; turned on
  460
+      (if (not c-auto-newline)
  461
+	  (c-indent-line)
441 462
 	;; clean ups
442 463
 	(let ((pos (- (point-max) (point))))
443 464
 	  (if (and (or (and
@@ -524,10 +545,11 @@ value of `c-cleanup-list'."
524 545
 		 (or (c-lookup-lists '(case-label label access-label)
525 546
 				     syntax c-hanging-colons-alist)
526 547
 		     (c-lookup-lists '(member-init-intro inher-intro)
527  
-				     (prog2
528  
-					 (insert "\n")
529  
-					 (c-guess-basic-syntax)
530  
-				       (delete-char -1))
  548
+				     (let ((buffer-undo-list t))
  549
+				       (insert "\n")
  550
+				       (unwind-protect
  551
+					   (c-guess-basic-syntax)
  552
+					 (delete-char -1)))
531 553
 				     c-hanging-colons-alist))))
532 554
       ;; indent the current line
533 555
       (c-indent-line syntax)
@@ -554,13 +576,10 @@ value of `c-cleanup-list'."
554 576
 
555 577
 (defun c-electric-lt-gt (arg)
556 578
   "Insert a less-than, or greater-than character.
557  
-When the auto-newline feature is turned on, as evidenced by the \"/a\"
558  
-or \"/ah\" string on the mode line, the line will be re-indented if
559  
-the character inserted is the second of a C++ style stream operator
560  
-and the buffer is in C++ mode.
561  
-
562  
-The line will also not be re-indented if a numeric argument is
563  
-supplied, or point is inside a literal."
  579
+The line will be re-indented if the character inserted is the second
  580
+of a C++ style stream operator and the buffer is in C++ mode.
  581
+Exceptions are when a numeric argument is supplied, or point is inside
  582
+a literal, in which case the line will not be re-indented."
564 583
   (interactive "*P")
565 584
   (let ((indentp (and (not arg)
566 585
 		      (eq (char-before) last-command-char)
@@ -571,6 +590,65 @@ supplied, or point is inside a literal."
571 590
     (if indentp
572 591
 	(c-indent-line))))
573 592
 
  593
+(defun c-electric-paren (arg)
  594
+  "Insert a parenthesis.
  595
+
  596
+If the auto-newline feature is turned on, as evidenced by the \"/a\"
  597
+or \"/ah\" string on the mode line, some newline cleanups are done if
  598
+appropriate; see the variable `c-cleanup-list'.
  599
+
  600
+Also, the line is re-indented unless a numeric ARG is supplied, there
  601
+are non-whitespace characters present on the line after the colon, or
  602
+the colon is inserted inside a literal."
  603
+  (interactive "*P")
  604
+  (let (;; shut this up
  605
+	(c-echo-syntactic-information-p nil))
  606
+    (if (or arg
  607
+	    (not (looking-at "[ \t]*$"))
  608
+	    (c-in-literal (c-point 'bod)))
  609
+	(self-insert-command (prefix-numeric-value arg))
  610
+      ;; do some special stuff with the character
  611
+      (let* (;; We want to inhibit blinking the paren since this will
  612
+	     ;; be most disruptive.  We'll blink it ourselves
  613
+	     ;; afterwards.
  614
+	     (old-blink-paren blink-paren-function)
  615
+	     blink-paren-function)
  616
+	(self-insert-command (prefix-numeric-value arg))
  617
+	(c-indent-line)
  618
+	(when c-auto-newline
  619
+	  ;; Do all appropriate clean ups
  620
+	  (let ((here (point))
  621
+		(pos (- (point-max) (point)))
  622
+		mbeg mend)
  623
+	    ;; clean up brace-elseif-brace
  624
+	    (if (and (memq 'brace-elseif-brace c-cleanup-list)
  625
+		     (eq last-command-char ?\()
  626
+		     (re-search-backward "}[ \t\n]*else[ \t\n]+if[ \t\n]*("
  627
+					 nil t)
  628
+		     (save-excursion
  629
+		       (setq mbeg (match-beginning 0)
  630
+			     mend (match-end 0))
  631
+		       (= mend here))
  632
+		     (not (c-in-literal)))
  633
+		(progn
  634
+		  (delete-region mbeg mend)
  635
+		  (insert "} else if (")))
  636
+	    ;; clean up brace-catch-brace
  637
+	    (if (and (memq 'brace-catch-brace c-cleanup-list)
  638
+		     (eq last-command-char ?\()
  639
+		     (re-search-backward "}[ \t\n]*catch[ \t\n]*(" nil t)
  640
+		     (save-excursion
  641
+		       (setq mbeg (match-beginning 0)
  642
+			     mend (match-end 0))
  643
+		       (= mend here))
  644
+		     (not (c-in-literal)))
  645
+		(progn
  646
+		  (delete-region mbeg mend)
  647
+		  (insert "} catch (")))
  648
+	    (goto-char (- (point-max) pos))
  649
+	    ))
  650
+	(funcall old-blink-paren)))))
  651
+
574 652
 
575 653
 
576 654
 ;; better movement routines for ThisStyleOfVariablesCommonInCPlusPlus
@@ -639,6 +717,8 @@ Negative argument -N means move back to Nth preceding end of defun.
639 717
 An end of a defun occurs right after the close-parenthesis that matches
640 718
 the open-parenthesis that starts a defun; see `beginning-of-defun'."
641 719
   (interactive "p")
  720
+  (if (not arg)
  721
+      (setq arg 1))
642 722
   (if (< arg 0)
643 723
       (c-beginning-of-defun (- arg))
644 724
     (while (> arg 0)
@@ -646,9 +726,9 @@ the open-parenthesis that starts a defun; see `beginning-of-defun'."
646 726
       (while (and (c-safe (down-list 1) t)
647 727
 		  (not (eq (char-before) ?{)))
648 728
 	(forward-char -1)
649  
-	(forward-sexp))
  729
+	(c-forward-sexp))
650 730
       (c-beginning-of-defun 1)
651  
-      (forward-sexp 1)
  731
+      (c-forward-sexp 1)
652 732
       (setq arg (1- arg)))
653 733
     (forward-line 1))
654 734
   (c-keep-region-active))
@@ -734,20 +814,13 @@ comment."
734 814
 	;; perhaps they should be changed, but that'd likely break a
735 815
 	;; lot in cc-engine.
736 816
 	(goto-char here)
737  
-	;; Move out of any enclosing non-`{ }' parens.
738  
-	(let ((last (point)))
739  
-	  (while (and (c-safe (progn (up-list 1) t))
740  
-		      (/= (char-before) ?\}))
741  
-	    (setq last (point)))
742  
-	  (goto-char last))
743 817
 	(if (> count 0)
744 818
 	    (if (condition-case nil
745 819
 		    ;; Stop before `{' and after `;', `{', `}' and
746  
-		    ;; `};' when not followed by `}', but on the other
747  
-		    ;; side of the syntactic ws.  Also stop before
748  
-		    ;; `}', but only to catch comments.  Move by sexps
749  
-		    ;; and move into `{ }', but not into any other
750  
-		    ;; other type of paren.
  820
+		    ;; `};' when not followed by `}' or `)', but on
  821
+		    ;; the other side of the syntactic ws.  Also stop
  822
+		    ;; before `}', but only to catch comments.  Move
  823
+		    ;; by sexps and move into parens.
751 824
 		    (catch 'done
752 825
 		      (let (last)
753 826
 			(while t
@@ -767,33 +840,37 @@ comment."
767 840
 				((progn (backward-char)
768 841
 					(looking-at "[;{}]"))
769 842
 				 (if (or (= here last)
770  
-					 (= (char-after last) ?}))
  843
+					 (memq (char-after last) '(?\) ?})))
771 844
 				     (if (and (= (char-before) ?})
772 845
 					      (= (char-after) ?\;))
773 846
 					 (backward-char))
774 847
 				   (goto-char last)
775 848
 				   (throw 'done t)))
776  
-				((or (= (char-syntax (char-after)) ?\))
777  
-				     (= (char-syntax (char-after)) ?\"))
  849
+				((= (char-syntax (char-after)) ?\")
778 850
 				 (forward-char)
779  
-				 (backward-sexp))
  851
+				 (c-backward-sexp))
780 852
 				))))
781 853
 		  (error
782 854
 		   (goto-char (point-min))
783 855
 		   t))
784 856
 		(setq count (1- count)))
785 857
 	  (if (condition-case nil
786  
-		  ;; Stop before `{' and `}' and after `;', `}' and
787  
-		  ;; `};'.  Also stop after `{', but only to catch
788  
-		  ;; comments.  Move by sexps and move into `{ }', but
789  
-		  ;; not into any other other type of paren.
  858
+		  ;; Stop before `{' and `}', but on the other side of
  859
+		  ;; the syntactic ws, and after `;', `}' and `};'.
  860
+		  ;; Only stop before `{' if at top level or inside
  861
+		  ;; braces, though.  Also stop after `{', but only to
  862
+		  ;; catch comments.  Move by sexps and move into
  863
+		  ;; parens.
790 864
 		  (catch 'done
791 865
 		    (let (last)
792 866
 		      (while t
793 867
 			(setq last (point))
794 868
 			(c-forward-syntactic-ws)
795 869
 			(cond ((= (char-after) ?{)
796  
-			       (if (= here last)
  870
+			       (if (or (= here last)
  871
+				       (save-excursion
  872
+					 (and (c-safe (progn (up-list -1) t))
  873
+					      (/= (char-after) ?{))))
797 874
 				   (progn (forward-char)
798 875
 					  (throw 'done nil))
799 876
 				 (goto-char last)
@@ -805,9 +882,8 @@ comment."
805 882
 			      ((looking-at ";\\|};?")
806 883
 			       (goto-char (match-end 0))
807 884
 			       (throw 'done t))
808  
-			      ((or (= (char-syntax (char-after)) ?\()
809  
-				   (= (char-syntax (char-after)) ?\"))
810  
-			       (forward-sexp))
  885
+			      ((= (char-syntax (char-after)) ?\")
  886
+			       (c-forward-sexp))
811 887
 			      (t
812 888
 			       (forward-char))
813 889
 			      ))))
@@ -855,7 +931,8 @@ comment."
855 931
    c-electric-star
856 932
    c-electric-semi&comma
857 933
    c-electric-lt-gt
858  
-   c-electric-colon))
  934
+   c-electric-colon
  935
+   c-electric-paren))
859 936
 (put 'c-electric-delete    'delete-selection 'supersede) ; delsel
860 937
 (put 'c-electric-delete    'pending-delete   'supersede) ; pending-del
861 938
 (put 'c-electric-backspace 'delete-selection 'supersede) ; delsel
@@ -883,13 +960,13 @@ comment."
883 960
 	 ((or (looking-at "^#[ \t]*endif[ \t]*")
884 961
 	      (looking-at "^#[ \t]*else[ \t]*"))
885 962
 	  7)
886  
-	 ;; CASE 3: when comment-column is nil, calculate the offset
887  
-	 ;; according to c-offsets-alist.  E.g. identical to hitting
888  
-	 ;; TAB.
  963
+	 ;; CASE 3: when c-indent-comments-syntactically-p is t,
  964
+	 ;; calculate the offset according to c-offsets-alist.
  965
+	 ;; E.g. identical to hitting TAB.
889 966
 	 ((and c-indent-comments-syntactically-p
890 967
 	       (save-excursion
891 968
 		 (skip-chars-forward " \t")
892  
-		 (or (looking-at comment-start)
  969
+		 (or (looking-at c-comment-start-regexp)
893 970
 		     (eolp))))
894 971
 	  (let ((syntax (c-guess-basic-syntax)))
895 972
 	    ;; BOGOSITY ALERT: if we're looking at the eol, its
@@ -944,7 +1021,8 @@ comment."
944 1021
   (let ((literal (c-in-literal))
945 1022
 	at-comment-col)
946 1023
     (cond
947  
-     ((eq literal 'string))
  1024
+     ((eq literal 'string)
  1025
+      (insert ?\n))
948 1026
      ((or (not c-comment-continuation-stars)
949 1027
 	  (not literal))
950 1028
       (indent-new-comment-line soft))
@@ -975,15 +1053,15 @@ comment."
975 1053
 	  (c-indent-line))))))
976 1054
 
977 1055
 ;; advice for indent-new-comment-line for older Emacsen
978  
-(if (boundp 'comment-line-break-function)
979  
-    nil
980  
-  (require 'advice)
981  
-  (defadvice indent-new-comment-line (around c-line-break-advice activate)
982  
-    (if (or (not c-buffer-is-cc-mode)
983  
-	    (not (c-in-literal))
984  
-	    (not c-comment-continuation-stars))
985  
-	ad-do-it
986  
-      (c-comment-line-break-function (ad-get-arg 0)))))
  1056
+(or (boundp 'comment-line-break-function)
  1057
+    (defadvice indent-new-comment-line (around c-line-break-advice
  1058
+					       activate preactivate)
  1059
+      "Calls c-comment-line-break-function if in a comment in CC Mode."
  1060
+      (if (or (not c-buffer-is-cc-mode)
  1061
+	      (not (c-in-literal))
  1062
+	      (not c-comment-continuation-stars))
  1063
+	  ad-do-it
  1064
+	(c-comment-line-break-function (ad-get-arg 0)))))
987 1065
 
988 1066
 ;; used by outline-minor-mode
989 1067
 (defun c-outline-level ()
@@ -1093,7 +1171,7 @@ of the expression are preserved.
1093 1171
   just inserts a tab character, or the equivalent number of spaces,
1094 1172
   depending on the variable `indent-tabs-mode'."
1095 1173
 
1096  
-  (interactive "*P")
  1174
+  (interactive "P")
1097 1175
   (let ((bod (c-point 'bod)))
1098 1176
     (if whole-exp
1099 1177
 	;; If arg, always indent this line as C
@@ -1104,7 +1182,7 @@ of the expression are preserved.
1104 1182
 	    (if (eq c-tab-always-indent t)
1105 1183
 		(beginning-of-line))
1106 1184
 	    (setq beg (point))
1107  
-	    (forward-sexp 1)
  1185
+	    (c-forward-sexp 1)
1108 1186
 	    (setq end (point))
1109 1187
 	    (goto-char beg)
1110 1188
 	    (forward-line 1)
@@ -1156,7 +1234,7 @@ Optional SHUTUP-P if non-nil, inhibits message printing and error checking."
1156 1234
 				(memq (char-after) '(?\( ?\[ ?\{))
1157 1235
 				(point)))))))
1158 1236
 	  ;; find balanced expression end
1159  
-	  (setq end (and (c-safe (progn (forward-sexp 1) t))
  1237
+	  (setq end (and (c-safe (progn (c-forward-sexp 1) t))
1160 1238
 			 (point-marker)))
1161 1239
 	  ;; sanity check
1162 1240
 	  (and (not start)
@@ -1247,18 +1325,18 @@ Optional SHUTUP-P if non-nil, inhibits message printing and error checking."
1247 1325
 		    (while (< (point) nextline)
1248 1326
 		      (condition-case nil
1249 1327
 			  (progn
1250  
-			    (forward-sexp 1)
  1328
+			    (c-forward-sexp 1)
1251 1329
 			    (setq sexpend (point)))
1252 1330
 			(error (setq sexpend nil)
1253 1331
 			       (goto-char nextline)))
1254 1332
 		      (c-forward-syntactic-ws))
1255 1333
 		    (if sexpend
1256  
-			(progn 
  1334
+			(progn
1257 1335
 			  ;; make sure the sexp we found really starts on the
1258 1336
 			  ;; current line and extends past it
1259 1337
 			  (goto-char sexpend)
1260 1338
 			  (setq sexpend (point-marker))
1261  
-			  (c-safe (backward-sexp 1))
  1339
+			  (c-safe (c-backward-sexp 1))
1262 1340
 			  (setq sexpbeg (point))))
1263 1341
 		    (if (and sexpbeg (< sexpbeg fence))
1264 1342
 			(setq sexpbeg fence)))
@@ -1295,30 +1373,68 @@ Optional SHUTUP-P if non-nil, inhibits message printing and error checking."
1295 1373
 	))))
1296 1374
 
1297 1375
 (defun c-mark-function ()
1298  
-  "Put mark at end of a C, C++, or Objective-C defun, point at beginning."
  1376
+  "Put mark at end of current top-level defun, point at beginning."
1299 1377
   (interactive)
1300 1378
   (let ((here (point))
1301  
-	;; there should be a c-point position for 'eod
1302  
-	(eod  (save-excursion (end-of-defun) (point)))
1303  
-	(state (c-parse-state))
1304  
-	brace)
1305  
-    (while state
1306  
-      (setq brace (car state))
1307  
-      (if (consp brace)
1308  
-	  (goto-char (cdr brace))
1309  
-	(goto-char brace))
1310  
-      (setq state (cdr state)))
1311  
-    (if (eq (char-after) ?{)
1312  
-	(progn
1313  
-	  (forward-line -1)
1314  
-	  (while (not (or (bobp)
1315  
-			  (looking-at "[ \t]*$")))
1316  
-	    (forward-line -1)))
1317  
-      (forward-line 1)
1318  
-      (skip-chars-forward " \t\n"))
  1379
+	(eod (c-point 'eod))
  1380
+	(state (c-parse-state)))
  1381
+    ;; Are we sitting at the top level, someplace between either the
  1382
+    ;; beginning of buffer, or the nearest preceding defun?  If so,
  1383
+    ;; try first to figure out whether we're sitting on the
  1384
+    ;; introduction to a top-level defun, in which case we want to
  1385
+    ;; mark the entire defun we're sitting on.
  1386
+    ;;
  1387
+    ;; If we're sitting on anything else at the top-level, we want to
  1388
+    ;; just mark the statement that we're on
  1389
+    (if (or (and (consp (car state))
  1390
+		 (= (length state) 1))
  1391
+	    (null state))
  1392
+	;; Are we in the whitespace after the nearest preceding defun?
  1393
+	(if (and state
  1394
+		 (looking-at "[ \t]*$")
  1395
+		 (= (save-excursion
  1396
+		      (c-backward-syntactic-ws)
  1397
+		      (skip-chars-backward ";")
  1398
+		      (point))
  1399
+		    (cdar state)))
  1400
+	    (progn
  1401
+	      (setq eod (point))
  1402
+	      (goto-char (caar state))
  1403
+	      (c-beginning-of-statement-1))
  1404
+	  (if (= ?{ (save-excursion
  1405
+		      (c-end-of-statement-1)
  1406
+		      (char-before)))
  1407
+	      ;; We must be in a defuns's introduction
  1408
+	      (progn
  1409
+		(c-end-of-statement-1)
  1410
+		(skip-chars-backward "{")
  1411
+		(c-beginning-of-statement-1)
  1412
+		(c-forward-syntactic-ws))
  1413
+	    ;; Just mark the statement
  1414
+	    (c-end-of-statement-1)
  1415
+	    (forward-line 1)
  1416
+	    (setq eod (point))
  1417
+	    (c-beginning-of-statement-1)))
  1418
+      ;; We are inside some enclosing brace structure, so we first
  1419
+      ;; need to find our way to the least enclosing brace.  Then, in
  1420
+      ;; both cases, we to mark the region from the beginning of the
  1421
+      ;; current statement, until the end of the next following defun
  1422
+      (while (and state)
  1423
+	(or (consp (car state))
  1424
+	    (goto-char (car state)))
  1425
+	(setq state (cdr state)))
  1426
+      (c-beginning-of-statement-1))
1319 1427
     (push-mark here)
1320 1428
     (push-mark eod nil t)))
1321 1429
 
  1430
+(defun c-indent-line-or-region ()
  1431
+  "When the region is active, indent it.  Otherwise indent the current line."
  1432
+  ;; Emacs has a variable called mark-active, XEmacs uses region-active-p
  1433
+  (interactive)
  1434
+  (if (c-region-is-active-p)
  1435
+      (c-indent-region (region-beginning) (region-end))
  1436
+    (c-indent-command)))
  1437
+
1322 1438
 
1323 1439
 ;; for progress reporting
1324 1440
 (defvar c-progress-info nil)
@@ -1384,7 +1500,7 @@ With an argument, deletes the backslashes.
1384 1500
 This function does not modify blank lines at the start of the region.
1385 1501
 If the region ends at the start of a line, it always deletes the
1386 1502
 backslash (if any) at the end of the previous line.
1387  
- 
  1503
+
1388 1504
 You can put the region around an entire macro definition and use this
1389 1505
 command to conveniently insert and align the necessary backslashes."
1390 1506
   (interactive "*r\nP")
@@ -1548,65 +1664,69 @@ Optional prefix ARG means justify paragraph as well."
1548 1664
 		     t)))
1549 1665
 	  ;; Inside a comment: fill one comment paragraph.
1550 1666
 	  (let ((fill-prefix
1551  
-		 ;; The prefix for each line of this paragraph
1552  
-		 ;; is the appropriate part of the start of this line,
1553  
-		 ;; up to the column at which text should be indented.
1554  
-		 (save-excursion
1555  
-		   (beginning-of-line)
1556  
-		   (if (looking-at ".*/\\*.*\\*/")
1557  
-		       (progn (re-search-forward comment-start-skip)
1558  
-			      (make-string (current-column) ?\ ))
1559  
-		     (if first-line
1560  
-			 (forward-line 1)
1561  
-		       (if (and (looking-at "[ \t]*\\*/")
1562  
-				(not (save-excursion
1563  
-				       (forward-line -1)
1564  
-				       (looking-at ".*/\\*"))))
1565  
-			   (forward-line -1)))
1566  
-
1567  
-		     (let ((line-width (progn (end-of-line) (current-column))))
1568  
-		       (beginning-of-line)
1569  
-		       (prog1
1570  
-			   (buffer-substring
1571  
-			    (point)
1572  
-
1573  
-			    ;; How shall we decide where the end of the
1574  
-			    ;; fill-prefix is?
1575  
-			    (progn
1576  
-			      (skip-chars-forward " \t*" (c-point 'eol))
1577  
-			      ;; kludge alert, watch out for */, in
1578  
-			      ;; which case fill-prefix should *not*
1579  
-			      ;; be "*"!
1580  
-			      (if (and (eq (char-after) ?/)
1581  
-				       (eq (char-before) ?*))
1582  
-				  (forward-char -1))
1583  
-			      (point)))
1584  
-
1585  
-			 ;; If the comment is only one line followed
1586  
-			 ;; by a blank line, calling move-to-column
1587  
-			 ;; above may have added some spaces and tabs
1588  
-			 ;; to the end of the line; the fill-paragraph
1589  
-			 ;; function will then delete it and the
1590  
-			 ;; newline following it, so we'll lose a
1591  
-			 ;; blank line when we shouldn't.  So delete
1592  
-			 ;; anything move-to-column added to the end
1593  
-			 ;; of the line.  We record the line width
1594  
-			 ;; instead of the position of the old line
1595  
-			 ;; end because move-to-column might break a
1596  
-			 ;; tab into spaces, and the new characters
1597  
-			 ;; introduced there shouldn't be deleted.
1598  
-
1599  
-			 ;; If you can see a better way to do this,
1600  
-			 ;; please make the change.  This seems very
1601  
-			 ;; messy to me.
1602  
-			 (delete-region (progn (move-to-column line-width)
1603  
-					       (point))
1604  
-					(progn (end-of-line) (point))))))))
  1667
+		 (or
  1668
+		  ;; Keep user set fill prefix if any.
  1669
+		  fill-prefix
  1670
+		  ;; The prefix for each line of this paragraph
  1671
+		  ;; is the appropriate part of the start of this line,
  1672
+		  ;; up to the column at which text should be indented.
  1673
+		  (save-excursion
  1674
+		    (beginning-of-line)
  1675
+		    (if (looking-at ".*/\\*.*\\*/")
  1676
+			(progn (re-search-forward comment-start-skip)
  1677
+			       (make-string (current-column) ?\ ))
  1678
+		      (if first-line
  1679
+			  (forward-line 1)
  1680
+			(if (and (looking-at "[ \t]*\\*/")
  1681
+				 (not (save-excursion
  1682
+					(forward-line -1)
  1683
+					(looking-at ".*/\\*"))))
  1684
+			    (forward-line -1)))
  1685
+
  1686
+		      (let ((line-width (progn (end-of-line)
  1687
+					       (current-column))))
  1688
+			(beginning-of-line)
  1689
+			(prog1
  1690
+			    (buffer-substring
  1691
+			     (point)
  1692
+
  1693
+			     ;; How shall we decide where the end of the
  1694
+			     ;; fill-prefix is?
  1695
+			     (progn
  1696
+			       (skip-chars-forward " \t*" (c-point 'eol))
  1697
+			       ;; kludge alert, watch out for */, in
  1698
+			       ;; which case fill-prefix should *not*
  1699
+			       ;; be "*"!
  1700
+			       (if (and (eq (char-after) ?/)
  1701
+					(eq (char-before) ?*))
  1702
+				   (forward-char -1))
  1703
+			       (point)))
  1704
+
  1705
+			  ;; If the comment is only one line followed
  1706
+			  ;; by a blank line, calling move-to-column
  1707
+			  ;; above may have added some spaces and tabs
  1708
+			  ;; to the end of the line; the fill-paragraph
  1709
+			  ;; function will then delete it and the
  1710
+			  ;; newline following it, so we'll lose a
  1711
+			  ;; blank line when we shouldn't.  So delete
  1712
+			  ;; anything move-to-column added to the end
  1713
+			  ;; of the line.  We record the line width
  1714
+			  ;; instead of the position of the old line
  1715
+			  ;; end because move-to-column might break a
  1716
+			  ;; tab into spaces, and the new characters
  1717
+			  ;; introduced there shouldn't be deleted.
  1718
+
  1719
+			  ;; If you can see a better way to do this,
  1720
+			  ;; please make the change.  This seems very
  1721
+			  ;; messy to me.
  1722
+			  (delete-region (progn (move-to-column line-width)
  1723
+						(point))
  1724
+					 (progn (end-of-line) (point)))))))))
1605 1725
 
1606 1726
 		;; Lines containing just a comment start or just an end
1607 1727
 		;; should not be filled into paragraphs they are next
1608 1728
 		;; to.
1609  
-		(paragraph-start (if (eq major-mode 'java-mode)
  1729
+		(paragraph-start (if (c-major-mode-is 'java-mode)
1610 1730
 				     (concat paragraph-start
1611 1731
 					     re1 "\\("
1612 1732
 					     c-Java-javadoc-paragraph-start
@@ -1695,8 +1815,7 @@ Optional prefix ARG means justify paragraph as well."
1695 1815
 		   (goto-char (car limits))
1696 1816
 		   (end-of-line)
1697 1817
 		   (< (point) (cdr limits))))
1698  
-	    (let (fill-prefix
1699  
-		  fill-paragraph-function)
  1818
+	    (let (fill-paragraph-function)
1700 1819
 	      (save-restriction
1701 1820
 		(narrow-to-region (save-excursion
1702 1821
 				    (goto-char (1+ (car limits)))
7  lisp/progmodes/cc-compat.el
... ...
@@ -1,9 +1,9 @@
1 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 Free Software Foundation, Inc.
  3
+;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc.
4 4
 
5 5
 ;; Author:     1994-1997 Barry A. Warsaw
6  
-;; Maintainer: cc-mode-help@python.org
  6
+;; Maintainer: bug-cc-mode@gnu.org
7 7
 ;; Created:    August 1994, split from cc-mode.el
8 8
 ;; Version:    See cc-mode.el
9 9
 ;; Keywords:   c languages oop
@@ -40,6 +40,7 @@
40 40
 ;;; Code:
41 41
 
42 42
 (eval-when-compile
  43
+  (require 'cc-defs)
43 44
   (require 'cc-styles)
44 45
   (require 'cc-engine))
45 46
 
@@ -114,7 +115,7 @@ This is in addition to c-continued-statement-offset.")
114 115
 	      ;; line
115 116
 	      (progn
116 117
 		(if (eq (char-before) ?\))
117  
-		    (forward-sexp -1))
  118
+		    (c-forward-sexp -1))
118 119
 		;; Get initial indentation of the line we are on.
119 120
 		(current-indentation)))))
120 121
       (- bocm-lossage curcol))))
66  lisp/progmodes/cc-defs.el
@@ -2,10 +2,11 @@
2 2
 
3 3
 ;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc.
4 4
 
5  
-;; Authors:    1992-1997 Barry A. Warsaw
  5
+;; Authors:    1998 Barry A. Warsaw and Martin Stjernholm
  6
+;;             1992-1997 Barry A. Warsaw
6 7
 ;;             1987 Dave Detlefs and Stewart Clamen
7 8
 ;;             1985 Richard M. Stallman
8  
-;; Maintainer: cc-mode-help@python.org
  9
+;; Maintainer: bug-cc-mode@gnu.org
9 10
 ;; Created:    22-Apr-1997 (split from cc-mode.el)
10 11
 ;; Version:    See cc-mode.el
11 12
 ;; Keywords:   c languages oop
@@ -28,6 +29,25 @@
28 29
 ;; Boston, MA 02111-1307, USA.
29 30
 
30 31
 
  32
+;; Get all the necessary compile time definitions.
  33
+(require 'custom)
  34
+(require 'cc-menus)
  35
+(require 'derived)			;only necessary in Emacs 20
  36
+
  37
+;; cc-mode-19.el contains compatibility macros that should be compiled
  38
+;; in if needed.
  39
+(if (or (not (fboundp 'functionp))
  40
+	(not (condition-case nil
  41
+		 (progn (char-before) t)
  42
+	       (error nil)))
  43
+	(not (condition-case nil
  44
+		 (progn (char-after) t)
  45
+	       (error nil)))
  46
+	(not (fboundp 'when))
  47
+	(not (fboundp 'unless)))
  48
+    (require 'cc-mode-19))
  49
+
  50
+
31 51
 (defsubst c-point (position)
32 52
   ;; Returns the value of point at certain commonly referenced POSITIONs.
33 53
   ;; POSITION can be one of the following symbols:
@@ -35,6 +55,7 @@
35 55
   ;; bol  -- beginning of line
36 56
   ;; eol  -- end of line
37 57
   ;; bod  -- beginning of defun
  58
+  ;; eod  -- end of defun
38 59
   ;; boi  -- back to indentation
39 60
   ;; ionl -- indentation of next line
40 61
   ;; iopl -- indentation of previous line
@@ -55,14 +76,14 @@
55 76
      ((eq position 'ionl)
56 77
       (forward-line 1)
57 78
       (back-to-indentation))
  79
+     ((eq position 'eod)  (c-end-of-defun))
58 80
      ((eq position 'bod)
59 81
       (if (and (fboundp 'buffer-syntactic-context-depth)
60 82
 	       c-enable-xemacs-performance-kludge-p)
61 83
 	  ;; XEmacs only.  This can improve the performance of
62 84
 	  ;; c-parse-state to between 3 and 60 times faster when
63  
-	  ;; braces are hung.  It can cause c-parse-state to be
64  
-	  ;; slightly slower when braces are not hung, but general
65  
-	  ;; editing appears to be still about as fast.
  85
+	  ;; braces are hung.  It can also degrade performance by
  86
+	  ;; about as much when braces are not hung.
66 87
 	  (let (pos)
67 88
 	    (while (not pos)
68 89
 	      (save-restriction
@@ -106,12 +127,31 @@
106 127
 	(point)
107 128
       (goto-char here))))
108 129
 
  130
+
109 131
 (defmacro c-safe (&rest body)
110 132
   ;; safely execute BODY, return nil if an error occurred
111 133
   (` (condition-case nil
112 134
 	 (progn (,@ body))
113 135
        (error nil))))
114 136
 
  137
+(defmacro c-forward-sexp (&optional arg)
  138
+  ;; like forward-sexp except
  139
+  ;;   1. this is much stripped down from the XEmacs version
  140
+  ;;   2. this cannot be used as a command, so we're insulated from
  141
+  ;;      XEmacs' losing efforts to make forward-sexp more user
  142
+  ;;      friendly
  143
+  ;;   3. Preserves the semantics most of CC Mode is based on
  144
+  (or arg (setq arg 1))
  145
+  `(goto-char (or (scan-sexps (point) ,arg)
  146
+		  ,(if (numberp arg)
  147
+		       (if (> arg 0) `(point-max) `(point-min))
  148
+		     `(if (> ,arg 0) (point-max) (point-min))))))
  149
+
  150
+(defmacro c-backward-sexp (&optional arg)
  151
+  ;; See c-forward-sexp and reverse directions
  152
+  (or arg (setq arg 1))
  153
+  `(c-forward-sexp ,(if (numberp arg) (- arg) `(- ,arg))))
  154
+
115 155
 (defmacro c-add-syntax (symbol &optional relpos)
116 156
   ;; a simple macro to append the syntax in symbol to the syntax list.
117 157
   ;; try to increase performance by using this macro
@@ -163,6 +203,22 @@
163 203
   (and (boundp 'zmacs-region-stays)
164 204
        (setq zmacs-region-stays t)))
165 205
 
  206
+(defsubst c-region-is-active-p ()
  207
+  ;; Return t when the region is active.  The determination of region
  208
+  ;; activeness is different in both Emacs and XEmacs.
  209
+  (cond
  210
+   ;; XEmacs
  211
+   ((and (fboundp 'region-active-p)
  212
+	 zmacs-regions)
  213
+    (region-active-p))
  214
+   ;; Emacs
  215
+   ((boundp 'mark-active) mark-active)
  216
+   ;; fallback; shouldn't get here
  217
+   (t (mark t))))
  218
+
  219
+(defsubst c-major-mode-is (mode)
  220
+  (eq (derived-mode-class major-mode) mode))
  221
+
166 222
 
167 223
 (provide 'cc-defs)
168 224
 ;;; cc-defs.el ends here
912  lisp/progmodes/cc-engine.el
@@ -2,10 +2,11 @@
2 2
 
3 3
 ;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc.
4 4
 
5  
-;; Authors:    1992-1997 Barry A. Warsaw
  5
+;; Authors:    1998 Barry A. Warsaw and Martin Stjernholm
  6
+;;             1992-1997 Barry A. Warsaw
6 7
 ;;             1987 Dave Detlefs and Stewart Clamen
7 8
 ;;             1985 Richard M. Stallman
8  
-;; Maintainer: cc-mode-help@python.org
  9
+;; Maintainer: bug-cc-mode@gnu.org
9 10
 ;; Created:    22-Apr-1997 (split from cc-mode.el)
10 11
 ;; Version:    See cc-mode.el
11 12
 ;; Keywords:   c languages oop
@@ -28,6 +29,9 @@
28 29
 ;; Boston, MA 02111-1307, USA.
29 30
 
30 31
 
  32
+(eval-when-compile
  33
+  (require 'cc-defs))
  34
+
31 35
 ;; KLUDGE ALERT: c-maybe-labelp is used to pass information between
32 36
 ;; c-crosses-statement-barrier-p and c-beginning-of-statement-1.  A
33 37
 ;; better way should be implemented, but this will at least shut up
@@ -66,7 +70,7 @@
66 70
 	(if (bobp) (setq donep t)
67 71
 	  ;; go backwards one balanced expression, but be careful of
68 72
 	  ;; unbalanced paren being reached
69  
-	  (if (not (c-safe (progn (backward-sexp 1) t)))
  73
+	  (if (not (c-safe (progn (c-backward-sexp 1) t)))
70 74
 	      (progn
71 75
 		(if firstp
72 76
 		    (backward-up-list 1)
@@ -75,7 +79,7 @@
75 79
 		;; characters appearing at front of identifier
76 80
 		(save-excursion
77 81
 		  (c-backward-syntactic-ws lim)
78  
-		  (skip-chars-backward "-+!*&:.~ \t\n")
  82
+		  (skip-chars-backward "-+!*&:.~@ \t\n")
79 83
 		  (if (eq (char-before) ?\()
80 84
 		      (setq last-begin (point))))
81 85
 		(goto-char last-begin)
@@ -97,7 +101,7 @@
97 101
 	   ((or (looking-at c-conditional-key)
98 102
 		(and (eq (char-after) ?\()
99 103
 		     (save-excursion
100  
-		       (forward-sexp 1)
  104
+		       (c-forward-sexp 1)
101 105
 		       (c-forward-syntactic-ws)
102 106
 		       (not (eq (char-after) ?\;)))
103 107
 		     (let ((here (point))
@@ -117,17 +121,23 @@
117 121
 	    ;; are we in the middle of an else-if clause?
118 122
 	    (if (save-excursion
119 123
 		  (and (not substmt-p)
120  
-		       (c-safe (progn (forward-sexp -1) t))
  124
+		       (c-safe (progn (c-forward-sexp -1) t))
121 125
 		       (looking-at "\\<else\\>[ \t\n]+\\<if\\>")
122 126
 		       (not (c-in-literal lim))))
123 127
 		(progn
124  
-		  (forward-sexp -1)
  128
+		  (c-forward-sexp -1)
125 129
 		  (c-backward-to-start-of-if lim)))
126 130
 	    ;; are we sitting at an else clause, that we are not a
127 131
 	    ;; substatement of?
128 132
 	    (if (and (not substmt-p)
129 133
 		     (looking-at "\\<else\\>[^_]"))
130 134
 		(c-backward-to-start-of-if lim))
  135
+	    ;; a finally or a series of catches?
  136
+	    (if (not substmt-p)
  137
+		(while (looking-at "\\<\\(catch\\|finally\\)\\>[^_]")
  138
+		  (c-safe (c-backward-sexp 2))
  139
+		  (if (eq (char-after) ?\()
  140
+		      (c-safe (c-backward-sexp)))))
131