aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBarry A. Warsaw1999-02-08 16:53:18 +0000
committerBarry A. Warsaw1999-02-08 16:53:18 +0000
commit0ec8351b955949a9d992fe033b0b61c04a76b2fa (patch)
treeb0b445d26a17cdd86442e73731c25d547a8dfe7d
parent32348c138b896b3a19e2814aaefd8e12cf0178ae (diff)
downloademacs-0ec8351b955949a9d992fe033b0b61c04a76b2fa.tar.gz
emacs-0ec8351b955949a9d992fe033b0b61c04a76b2fa.zip
Installed CC Mode 5.25.
-rw-r--r--lisp/progmodes/cc-align.el47
-rw-r--r--lisp/progmodes/cc-cmds.el507
-rw-r--r--lisp/progmodes/cc-compat.el7
-rw-r--r--lisp/progmodes/cc-defs.el66
-rw-r--r--lisp/progmodes/cc-engine.el912
-rw-r--r--lisp/progmodes/cc-langs.el114
-rw-r--r--lisp/progmodes/cc-menus.el28
-rw-r--r--lisp/progmodes/cc-mode.el174
-rw-r--r--lisp/progmodes/cc-styles.el173
-rw-r--r--lisp/progmodes/cc-vars.el99
10 files changed, 1514 insertions, 613 deletions
diff --git a/lisp/progmodes/cc-align.el b/lisp/progmodes/cc-align.el
index df10addae2f..c051172ce96 100644
--- a/lisp/progmodes/cc-align.el
+++ b/lisp/progmodes/cc-align.el
@@ -2,10 +2,11 @@
2 2
3;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc. 3;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc.
4 4
5;; Authors: 1992-1997 Barry A. Warsaw 5;; Authors: 1998 Barry A. Warsaw and Martin Stjernholm
6;; 1992-1997 Barry A. Warsaw
6;; 1987 Dave Detlefs and Stewart Clamen 7;; 1987 Dave Detlefs and Stewart Clamen
7;; 1985 Richard M. Stallman 8;; 1985 Richard M. Stallman
8;; Maintainer: cc-mode-help@python.org 9;; Maintainer: bug-cc-mode@gnu.org
9;; Created: 22-Apr-1997 (split from cc-mode.el) 10;; Created: 22-Apr-1997 (split from cc-mode.el)
10;; Version: See cc-mode.el 11;; Version: See cc-mode.el
11;; Keywords: c languages oop 12;; Keywords: c languages oop
@@ -28,6 +29,7 @@
28;; Boston, MA 02111-1307, USA. 29;; Boston, MA 02111-1307, USA.
29 30
30(eval-when-compile 31(eval-when-compile
32 (require 'cc-defs)
31 (require 'cc-vars) 33 (require 'cc-vars)
32 (require 'cc-engine) 34 (require 'cc-engine)
33 (require 'cc-langs)) 35 (require 'cc-langs))
@@ -57,7 +59,7 @@
57 (beginning-of-line) 59 (beginning-of-line)
58 (looking-at "[ \t]*)")) 60 (looking-at "[ \t]*)"))
59 (progn (goto-char (match-end 0)) 61 (progn (goto-char (match-end 0))
60 (forward-sexp -1) 62 (c-forward-sexp -1)
61 (forward-char 1) 63 (forward-char 1)
62 (c-forward-syntactic-ws) 64 (c-forward-syntactic-ws)
63 (- (current-column) langelem-col)) 65 (- (current-column) langelem-col))
@@ -111,9 +113,8 @@
111 (let (opencol spec) 113 (let (opencol spec)
112 (beginning-of-line) 114 (beginning-of-line)
113 (backward-up-list 1) 115 (backward-up-list 1)
114 (setq spec (if (fboundp 'c-looking-at-special-brace-list) 116 (setq spec (c-looking-at-special-brace-list))
115 (c-looking-at-special-brace-list))) 117 (if spec (goto-char (car (car spec))))
116 (if spec (goto-char (car spec)))
117 (setq opencol (current-column)) 118 (setq opencol (current-column))
118 (forward-char 1) 119 (forward-char 1)
119 (if spec (progn 120 (if spec (progn
@@ -194,9 +195,7 @@
194 (beginning-of-line) 195 (beginning-of-line)
195 (skip-chars-forward " \t") 196 (skip-chars-forward " \t")
196 (if (and (eq (following-char) ?{) 197 (if (and (eq (following-char) ?{)
197 (condition-case nil 198 (c-safe (progn (c-forward-sexp) t))
198 (progn (forward-sexp) t)
199 (error nil))
200 (<= (point) eol) 199 (<= (point) eol)
201 (eq (preceding-char) ?})) 200 (eq (preceding-char) ?}))
202 c-basic-offset 201 c-basic-offset
@@ -291,7 +290,11 @@
291 (if (c-in-literal (cdr langelem)) 290 (if (c-in-literal (cdr langelem))
292 (forward-char 1) 291 (forward-char 1)
293 (setq donep t))) 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 ;; there's no equal sign on the line 298 ;; there's no equal sign on the line
296 c-basic-offset 299 c-basic-offset
297 ;; calculate indentation column after equals and ws, unless 300 ;; calculate indentation column after equals and ws, unless
@@ -324,7 +327,7 @@
324 (current-column))) 327 (current-column)))
325 (target-col (progn 328 (target-col (progn
326 (forward-char) 329 (forward-char)
327 (forward-sexp) 330 (c-forward-sexp)
328 (skip-chars-forward " \t") 331 (skip-chars-forward " \t")
329 (if (eolp) 332 (if (eolp)
330 (+ open-bracket-col c-basic-offset) 333 (+ open-bracket-col c-basic-offset)
@@ -373,6 +376,26 @@
373 (+ curcol (- prev-col-column (current-column))) 376 (+ curcol (- prev-col-column (current-column)))
374 c-basic-offset))))) 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(defun c-lineup-dont-change (langelem) 399(defun c-lineup-dont-change (langelem)
377 ;; Do not change the indentation of the current line 400 ;; Do not change the indentation of the current line
378 (save-excursion 401 (save-excursion
@@ -394,7 +417,7 @@ ACTION associated with `block-close' syntax."
394 (setq langelem (assq 'block-close c-syntactic-context)) 417 (setq langelem (assq 'block-close c-syntactic-context))
395 (progn (goto-char (cdr langelem)) 418 (progn (goto-char (cdr langelem))
396 (if (eq (char-after) ?{) 419 (if (eq (char-after) ?{)
397 (c-safe (forward-sexp -1))) 420 (c-safe (c-forward-sexp -1)))
398 (looking-at "\\<do\\>[^_]"))) 421 (looking-at "\\<do\\>[^_]")))
399 '(before) 422 '(before)
400 '(before after))))) 423 '(before after)))))
diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el
index 5dfa7507041..dfe34be8e66 100644
--- a/lisp/progmodes/cc-cmds.el
+++ b/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;; 1987 Dave Detlefs and Stewart Clamen 7;; 1987 Dave Detlefs and Stewart Clamen
7;; 1985 Richard M. Stallman 8;; 1985 Richard M. Stallman
8;; Maintainer: cc-mode-help@python.org 9;; Maintainer: bug-cc-mode@gnu.org
9;; Created: 22-Apr-1997 (split from cc-mode.el) 10;; Created: 22-Apr-1997 (split from cc-mode.el)
10;; Version: See cc-mode.el 11;; Version: See cc-mode.el
11;; Keywords: c languages oop 12;; Keywords: c languages oop
@@ -29,6 +30,9 @@
29 30
30 31
31 32
33(eval-when-compile
34 (require 'cc-defs))
35
32(defun c-calculate-state (arg prevstate) 36(defun c-calculate-state (arg prevstate)
33 ;; Calculate the new state of PREVSTATE, t or nil, based on arg. If 37 ;; Calculate the new state of PREVSTATE, t or nil, based on arg. If
34 ;; arg is nil or zero, toggle the state. If arg is negative, turn 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
128nil, or point is inside a literal then the function in the variable 132nil, or point is inside a literal then the function in the variable
129`c-delete-function' is called." 133`c-delete-function' is called."
130 (interactive "*P") 134 (interactive "*P")
131 (if (and (boundp 'delete-key-deletes-forward) 135 (if (or (and (fboundp 'delete-forward-p) ;XEmacs 21
132 delete-key-deletes-forward) 136 (delete-forward-p))
137 (and (boundp 'delete-key-deletes-forward) ;XEmacs 20
138 delete-key-deletes-forward))
133 (if (or (not c-hungry-delete-key) 139 (if (or (not c-hungry-delete-key)
134 arg 140 arg
135 (c-in-literal)) 141 (c-in-literal))
@@ -148,9 +154,10 @@ Inserts a `#' character specially depending on the variable
148`c-electric-pound-behavior'. If a numeric ARG is supplied, or if 154`c-electric-pound-behavior'. If a numeric ARG is supplied, or if
149point is inside a literal, nothing special happens." 155point is inside a literal, nothing special happens."
150 (interactive "*P") 156 (interactive "*P")
151 (if (or (c-in-literal) 157 (if (or arg
152 arg 158 (not (memq 'alignleft c-electric-pound-behavior))
153 (not (memq 'alignleft c-electric-pound-behavior))) 159 (save-excursion (skip-chars-backward " \t") (not (bolp)))
160 (c-in-literal))
154 ;; do nothing special 161 ;; do nothing special
155 (self-insert-command (prefix-numeric-value arg)) 162 (self-insert-command (prefix-numeric-value arg))
156 ;; place the pound character at the left edge 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
173Also, the line is re-indented unless a numeric ARG is supplied, there 180Also, the line is re-indented unless a numeric ARG is supplied, there
174are non-whitespace characters present on the line after the brace, or 181are non-whitespace characters present on the line after the brace, or
175the brace is inserted inside a literal." 182the brace is inserted inside a literal.
183
184This function does various newline cleanups based on the value of
185`c-cleanup-list'."
176 (interactive "*P") 186 (interactive "*P")
177 (let* ((c-state-cache (c-parse-state)) 187 (let* ((c-state-cache (c-parse-state))
178 (safepos (c-safe-position (point) c-state-cache)) 188 (safepos (c-safe-position (point) c-state-cache))
@@ -180,8 +190,8 @@ the brace is inserted inside a literal."
180 ;; if we're in a literal, or we're not at the end of the line, or 190 ;; if we're in a literal, or we're not at the end of the line, or
181 ;; a numeric arg is provided, or auto-newlining is turned off, 191 ;; a numeric arg is provided, or auto-newlining is turned off,
182 ;; then just insert the character. 192 ;; then just insert the character.
183 (if (or literal arg 193 (if (or literal
184; (not c-auto-newline) 194 arg
185 (not (looking-at "[ \t]*$"))) 195 (not (looking-at "[ \t]*$")))
186 (self-insert-command (prefix-numeric-value arg)) 196 (self-insert-command (prefix-numeric-value arg))
187 (let* ((syms 197 (let* ((syms
@@ -191,11 +201,12 @@ the brace is inserted inside a literal."
191 '(class-open class-close defun-open defun-close 201 '(class-open class-close defun-open defun-close
192 inline-open inline-close 202 inline-open inline-close
193 brace-list-open brace-list-close 203 brace-list-open brace-list-close
194 brace-list-intro brace-list-entry 204 brace-list-intro brace-entry-open
195 block-open block-close 205 block-open block-close
196 substatement-open statement-case-open 206 substatement-open statement-case-open
197 extern-lang-open extern-lang-close 207 extern-lang-open extern-lang-close
198 namespace-open namespace-close 208 namespace-open namespace-close
209 inexpr-class-open inexpr-class-close
199 )) 210 ))
200 ;; we want to inhibit blinking the paren since this will 211 ;; we want to inhibit blinking the paren since this will
201 ;; be most disruptive. we'll blink it ourselves later on 212 ;; be most disruptive. we'll blink it ourselves later on
@@ -220,8 +231,32 @@ the brace is inserted inside a literal."
220 (c-guess-basic-syntax))) 231 (c-guess-basic-syntax)))
221 (newlines (and 232 (newlines (and
222 c-auto-newline 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 '(ignore before after))))) 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 ;; If syntax is a function symbol, then call it using the 260 ;; If syntax is a function symbol, then call it using the
226 ;; defined semantics. 261 ;; defined semantics.
227 (if (and (not (consp (cdr newlines))) 262 (if (and (not (consp (cdr newlines)))
@@ -234,29 +269,26 @@ the brace is inserted inside a literal."
234 ;; we leave the newline we've put in there before, 269 ;; we leave the newline we've put in there before,
235 ;; but we need to re-indent the line above 270 ;; but we need to re-indent the line above
236 (let ((pos (- (point-max) (point))) 271 (let ((pos (- (point-max) (point)))
237 (here (point)) 272 (here (point)))
238 (c-state-cache c-state-cache))
239 (forward-line -1) 273 (forward-line -1)
240 ;; we may need to update the cache. this should still be 274 (let ((c-state-cache (c-whack-state (point) c-state-cache)))
241 ;; faster than recalculating the state in many cases 275 ;; we may need to update the cache. this should
242 (save-excursion 276 ;; still be faster than recalculating the state
243 (save-restriction 277 ;; in many cases
244 (narrow-to-region here (point)) 278 (save-excursion
245 (if (and (c-safe (progn (backward-up-list -1) t)) 279 (save-restriction
246 (memq (char-before) '(?\) ?})) 280 (narrow-to-region here (point))
247 (progn (widen) 281 (if (and (c-safe (progn (backward-up-list -1) t))
248 (c-safe (progn (forward-sexp -1) t)))) 282 (memq (char-before) '(?\) ?}))
249 (setq c-state-cache 283 (progn (widen)
250 (c-hack-state (point) 'open c-state-cache)) 284 (c-safe (progn (c-forward-sexp -1)
251 (if (and (car c-state-cache) 285 t))))
252 (not (consp (car c-state-cache))) 286 (setq c-state-cache
253 (<= (point) (car c-state-cache))) 287 (c-hack-state (point) 'open c-state-cache)))))
254 (setq c-state-cache (cdr c-state-cache)) 288 (c-indent-line))
255 )))) 289 (setq c-state-cache (c-adjust-state (c-point 'bol) here
256 (let ((here (point)) 290 (- (point) (c-point 'bol))
257 (shift (c-indent-line))) 291 c-state-cache))
258 (setq c-state-cache (c-adjust-state (c-point 'bol) here
259 (- shift) c-state-cache)))
260 (goto-char (- (point-max) pos)) 292 (goto-char (- (point-max) pos))
261 ;; if the buffer has changed due to the indentation, we 293 ;; if the buffer has changed due to the indentation, we
262 ;; need to recalculate syntax for the current line, but 294 ;; need to recalculate syntax for the current line, but
@@ -291,10 +323,11 @@ the brace is inserted inside a literal."
291 ;; now adjust the line's indentation. don't update the state 323 ;; now adjust the line's indentation. don't update the state
292 ;; cache since c-guess-basic-syntax isn't called when the 324 ;; cache since c-guess-basic-syntax isn't called when the
293 ;; syntax is passed to c-indent-line 325 ;; syntax is passed to c-indent-line
294 (let ((here (point)) 326 (let* ((here (point)))
295 (shift (c-indent-line syntax))) 327 (c-indent-line syntax)
296 (setq c-state-cache (c-adjust-state (c-point 'bol) here 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 ;; Do all appropriate clean ups 331 ;; Do all appropriate clean ups
299 (let ((here (point)) 332 (let ((here (point))
300 (pos (- (point-max) (point))) 333 (pos (- (point-max) (point)))
@@ -325,22 +358,6 @@ the brace is inserted inside a literal."
325 (progn 358 (progn
326 (delete-region mbeg mend) 359 (delete-region mbeg mend)
327 (insert "} else {"))) 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 (goto-char (- (point-max) pos)) 361 (goto-char (- (point-max) pos))
345 ) 362 )
346 ;; does a newline go after the brace? 363 ;; does a newline go after the brace?
@@ -359,7 +376,7 @@ the brace is inserted inside a literal."
359 (c-backward-syntactic-ws safepos) 376 (c-backward-syntactic-ws safepos)
360 (funcall old-blink-paren))) 377 (funcall old-blink-paren)))
361 )))) 378 ))))
362 379
363(defun c-electric-slash (arg) 380(defun c-electric-slash (arg)
364 "Insert a slash character. 381 "Insert a slash character.
365 382
@@ -422,7 +439,10 @@ is determined.
422 439
423When semicolon is inserted, the line is re-indented unless a numeric 440When semicolon is inserted, the line is re-indented unless a numeric
424arg is supplied, point is inside a literal, or there are 441arg is supplied, point is inside a literal, or there are
425non-whitespace characters on the line following the semicolon." 442non-whitespace characters on the line following the semicolon.
443
444Based on the value of `c-cleanup-list', this function cleans up commas
445following brace lists and semicolons following defuns."
426 (interactive "*P") 446 (interactive "*P")
427 (let* ((lim (c-most-enclosing-brace (c-parse-state))) 447 (let* ((lim (c-most-enclosing-brace (c-parse-state)))
428 (literal (c-in-literal lim)) 448 (literal (c-in-literal lim))
@@ -435,9 +455,10 @@ non-whitespace characters on the line following the semicolon."
435 (self-insert-command (prefix-numeric-value arg)) 455 (self-insert-command (prefix-numeric-value arg))
436 ;; do some special stuff with the character 456 ;; do some special stuff with the character
437 (self-insert-command (prefix-numeric-value arg)) 457 (self-insert-command (prefix-numeric-value arg))
438 ;; do all cleanups, reindentations, and newline insertions, but 458 ;; do all cleanups and newline insertions if c-auto-newline is
439 ;; only if c-auto-newline is turned on 459 ;; turned on
440 (if (not c-auto-newline) nil 460 (if (not c-auto-newline)
461 (c-indent-line)
441 ;; clean ups 462 ;; clean ups
442 (let ((pos (- (point-max) (point)))) 463 (let ((pos (- (point-max) (point))))
443 (if (and (or (and 464 (if (and (or (and
@@ -524,10 +545,11 @@ value of `c-cleanup-list'."
524 (or (c-lookup-lists '(case-label label access-label) 545 (or (c-lookup-lists '(case-label label access-label)
525 syntax c-hanging-colons-alist) 546 syntax c-hanging-colons-alist)
526 (c-lookup-lists '(member-init-intro inher-intro) 547 (c-lookup-lists '(member-init-intro inher-intro)
527 (prog2 548 (let ((buffer-undo-list t))
528 (insert "\n") 549 (insert "\n")
529 (c-guess-basic-syntax) 550 (unwind-protect
530 (delete-char -1)) 551 (c-guess-basic-syntax)
552 (delete-char -1)))
531 c-hanging-colons-alist)))) 553 c-hanging-colons-alist))))
532 ;; indent the current line 554 ;; indent the current line
533 (c-indent-line syntax) 555 (c-indent-line syntax)
@@ -554,13 +576,10 @@ value of `c-cleanup-list'."
554 576
555(defun c-electric-lt-gt (arg) 577(defun c-electric-lt-gt (arg)
556 "Insert a less-than, or greater-than character. 578 "Insert a less-than, or greater-than character.
557When the auto-newline feature is turned on, as evidenced by the \"/a\" 579The line will be re-indented if the character inserted is the second
558or \"/ah\" string on the mode line, the line will be re-indented if 580of a C++ style stream operator and the buffer is in C++ mode.
559the character inserted is the second of a C++ style stream operator 581Exceptions are when a numeric argument is supplied, or point is inside
560and the buffer is in C++ mode. 582a literal, in which case the line will not be re-indented."
561
562The line will also not be re-indented if a numeric argument is
563supplied, or point is inside a literal."
564 (interactive "*P") 583 (interactive "*P")
565 (let ((indentp (and (not arg) 584 (let ((indentp (and (not arg)
566 (eq (char-before) last-command-char) 585 (eq (char-before) last-command-char)
@@ -571,6 +590,65 @@ supplied, or point is inside a literal."
571 (if indentp 590 (if indentp
572 (c-indent-line)))) 591 (c-indent-line))))
573 592
593(defun c-electric-paren (arg)
594 "Insert a parenthesis.
595
596If the auto-newline feature is turned on, as evidenced by the \"/a\"
597or \"/ah\" string on the mode line, some newline cleanups are done if
598appropriate; see the variable `c-cleanup-list'.
599
600Also, the line is re-indented unless a numeric ARG is supplied, there
601are non-whitespace characters present on the line after the colon, or
602the 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;; better movement routines for ThisStyleOfVariablesCommonInCPlusPlus 654;; better movement routines for ThisStyleOfVariablesCommonInCPlusPlus
@@ -639,6 +717,8 @@ Negative argument -N means move back to Nth preceding end of defun.
639An end of a defun occurs right after the close-parenthesis that matches 717An end of a defun occurs right after the close-parenthesis that matches
640the open-parenthesis that starts a defun; see `beginning-of-defun'." 718the open-parenthesis that starts a defun; see `beginning-of-defun'."
641 (interactive "p") 719 (interactive "p")
720 (if (not arg)
721 (setq arg 1))
642 (if (< arg 0) 722 (if (< arg 0)
643 (c-beginning-of-defun (- arg)) 723 (c-beginning-of-defun (- arg))
644 (while (> arg 0) 724 (while (> arg 0)
@@ -646,9 +726,9 @@ the open-parenthesis that starts a defun; see `beginning-of-defun'."
646 (while (and (c-safe (down-list 1) t) 726 (while (and (c-safe (down-list 1) t)
647 (not (eq (char-before) ?{))) 727 (not (eq (char-before) ?{)))
648 (forward-char -1) 728 (forward-char -1)
649 (forward-sexp)) 729 (c-forward-sexp))
650 (c-beginning-of-defun 1) 730 (c-beginning-of-defun 1)
651 (forward-sexp 1) 731 (c-forward-sexp 1)
652 (setq arg (1- arg))) 732 (setq arg (1- arg)))
653 (forward-line 1)) 733 (forward-line 1))
654 (c-keep-region-active)) 734 (c-keep-region-active))
@@ -734,20 +814,13 @@ comment."
734 ;; perhaps they should be changed, but that'd likely break a 814 ;; perhaps they should be changed, but that'd likely break a
735 ;; lot in cc-engine. 815 ;; lot in cc-engine.
736 (goto-char here) 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 (if (> count 0) 817 (if (> count 0)
744 (if (condition-case nil 818 (if (condition-case nil
745 ;; Stop before `{' and after `;', `{', `}' and 819 ;; Stop before `{' and after `;', `{', `}' and
746 ;; `};' when not followed by `}', but on the other 820 ;; `};' when not followed by `}' or `)', but on
747 ;; side of the syntactic ws. Also stop before 821 ;; the other side of the syntactic ws. Also stop
748 ;; `}', but only to catch comments. Move by sexps 822 ;; before `}', but only to catch comments. Move
749 ;; and move into `{ }', but not into any other 823 ;; by sexps and move into parens.
750 ;; other type of paren.
751 (catch 'done 824 (catch 'done
752 (let (last) 825 (let (last)
753 (while t 826 (while t
@@ -767,33 +840,37 @@ comment."
767 ((progn (backward-char) 840 ((progn (backward-char)
768 (looking-at "[;{}]")) 841 (looking-at "[;{}]"))
769 (if (or (= here last) 842 (if (or (= here last)
770 (= (char-after last) ?})) 843 (memq (char-after last) '(?\) ?})))
771 (if (and (= (char-before) ?}) 844 (if (and (= (char-before) ?})
772 (= (char-after) ?\;)) 845 (= (char-after) ?\;))
773 (backward-char)) 846 (backward-char))
774 (goto-char last) 847 (goto-char last)
775 (throw 'done t))) 848 (throw 'done t)))
776 ((or (= (char-syntax (char-after)) ?\)) 849 ((= (char-syntax (char-after)) ?\")
777 (= (char-syntax (char-after)) ?\"))
778 (forward-char) 850 (forward-char)
779 (backward-sexp)) 851 (c-backward-sexp))
780 )))) 852 ))))
781 (error 853 (error
782 (goto-char (point-min)) 854 (goto-char (point-min))
783 t)) 855 t))
784 (setq count (1- count))) 856 (setq count (1- count)))
785 (if (condition-case nil 857 (if (condition-case nil
786 ;; Stop before `{' and `}' and after `;', `}' and 858 ;; Stop before `{' and `}', but on the other side of
787 ;; `};'. Also stop after `{', but only to catch 859 ;; the syntactic ws, and after `;', `}' and `};'.
788 ;; comments. Move by sexps and move into `{ }', but 860 ;; Only stop before `{' if at top level or inside
789 ;; not into any other other type of paren. 861 ;; braces, though. Also stop after `{', but only to
862 ;; catch comments. Move by sexps and move into
863 ;; parens.
790 (catch 'done 864 (catch 'done
791 (let (last) 865 (let (last)
792 (while t 866 (while t
793 (setq last (point)) 867 (setq last (point))
794 (c-forward-syntactic-ws) 868 (c-forward-syntactic-ws)
795 (cond ((= (char-after) ?{) 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 (progn (forward-char) 874 (progn (forward-char)
798 (throw 'done nil)) 875 (throw 'done nil))
799 (goto-char last) 876 (goto-char last)
@@ -805,9 +882,8 @@ comment."
805 ((looking-at ";\\|};?") 882 ((looking-at ";\\|};?")
806 (goto-char (match-end 0)) 883 (goto-char (match-end 0))
807 (throw 'done t)) 884 (throw 'done t))
808 ((or (= (char-syntax (char-after)) ?\() 885 ((= (char-syntax (char-after)) ?\")
809 (= (char-syntax (char-after)) ?\")) 886 (c-forward-sexp))
810 (forward-sexp))
811 (t 887 (t
812 (forward-char)) 888 (forward-char))
813 )))) 889 ))))
@@ -855,7 +931,8 @@ comment."
855 c-electric-star 931 c-electric-star
856 c-electric-semi&comma 932 c-electric-semi&comma
857 c-electric-lt-gt 933 c-electric-lt-gt
858 c-electric-colon)) 934 c-electric-colon
935 c-electric-paren))
859(put 'c-electric-delete 'delete-selection 'supersede) ; delsel 936(put 'c-electric-delete 'delete-selection 'supersede) ; delsel
860(put 'c-electric-delete 'pending-delete 'supersede) ; pending-del 937(put 'c-electric-delete 'pending-delete 'supersede) ; pending-del
861(put 'c-electric-backspace 'delete-selection 'supersede) ; delsel 938(put 'c-electric-backspace 'delete-selection 'supersede) ; delsel
@@ -883,13 +960,13 @@ comment."
883 ((or (looking-at "^#[ \t]*endif[ \t]*") 960 ((or (looking-at "^#[ \t]*endif[ \t]*")
884 (looking-at "^#[ \t]*else[ \t]*")) 961 (looking-at "^#[ \t]*else[ \t]*"))
885 7) 962 7)
886 ;; CASE 3: when comment-column is nil, calculate the offset 963 ;; CASE 3: when c-indent-comments-syntactically-p is t,
887 ;; according to c-offsets-alist. E.g. identical to hitting 964 ;; calculate the offset according to c-offsets-alist.
888 ;; TAB. 965 ;; E.g. identical to hitting TAB.
889 ((and c-indent-comments-syntactically-p 966 ((and c-indent-comments-syntactically-p
890 (save-excursion 967 (save-excursion
891 (skip-chars-forward " \t") 968 (skip-chars-forward " \t")
892 (or (looking-at comment-start) 969 (or (looking-at c-comment-start-regexp)
893 (eolp)))) 970 (eolp))))
894 (let ((syntax (c-guess-basic-syntax))) 971 (let ((syntax (c-guess-basic-syntax)))
895 ;; BOGOSITY ALERT: if we're looking at the eol, its 972 ;; BOGOSITY ALERT: if we're looking at the eol, its
@@ -944,7 +1021,8 @@ comment."
944 (let ((literal (c-in-literal)) 1021 (let ((literal (c-in-literal))
945 at-comment-col) 1022 at-comment-col)
946 (cond 1023 (cond
947 ((eq literal 'string)) 1024 ((eq literal 'string)
1025 (insert ?\n))
948 ((or (not c-comment-continuation-stars) 1026 ((or (not c-comment-continuation-stars)
949 (not literal)) 1027 (not literal))
950 (indent-new-comment-line soft)) 1028 (indent-new-comment-line soft))
@@ -975,15 +1053,15 @@ comment."
975 (c-indent-line)))))) 1053 (c-indent-line))))))
976 1054
977;; advice for indent-new-comment-line for older Emacsen 1055;; advice for indent-new-comment-line for older Emacsen
978(if (boundp 'comment-line-break-function) 1056(or (boundp 'comment-line-break-function)
979 nil 1057 (defadvice indent-new-comment-line (around c-line-break-advice
980 (require 'advice) 1058 activate preactivate)
981 (defadvice indent-new-comment-line (around c-line-break-advice activate) 1059 "Calls c-comment-line-break-function if in a comment in CC Mode."
982 (if (or (not c-buffer-is-cc-mode) 1060 (if (or (not c-buffer-is-cc-mode)
983 (not (c-in-literal)) 1061 (not (c-in-literal))
984 (not c-comment-continuation-stars)) 1062 (not c-comment-continuation-stars))
985 ad-do-it 1063 ad-do-it
986 (c-comment-line-break-function (ad-get-arg 0))))) 1064 (c-comment-line-break-function (ad-get-arg 0)))))
987 1065
988;; used by outline-minor-mode 1066;; used by outline-minor-mode
989(defun c-outline-level () 1067(defun c-outline-level ()
@@ -1093,7 +1171,7 @@ of the expression are preserved.
1093 just inserts a tab character, or the equivalent number of spaces, 1171 just inserts a tab character, or the equivalent number of spaces,
1094 depending on the variable `indent-tabs-mode'." 1172 depending on the variable `indent-tabs-mode'."
1095 1173
1096 (interactive "*P") 1174 (interactive "P")
1097 (let ((bod (c-point 'bod))) 1175 (let ((bod (c-point 'bod)))
1098 (if whole-exp 1176 (if whole-exp
1099 ;; If arg, always indent this line as C 1177 ;; If arg, always indent this line as C
@@ -1104,7 +1182,7 @@ of the expression are preserved.
1104 (if (eq c-tab-always-indent t) 1182 (if (eq c-tab-always-indent t)
1105 (beginning-of-line)) 1183 (beginning-of-line))
1106 (setq beg (point)) 1184 (setq beg (point))
1107 (forward-sexp 1) 1185 (c-forward-sexp 1)
1108 (setq end (point)) 1186 (setq end (point))
1109 (goto-char beg) 1187 (goto-char beg)
1110 (forward-line 1) 1188 (forward-line 1)
@@ -1156,7 +1234,7 @@ Optional SHUTUP-P if non-nil, inhibits message printing and error checking."
1156 (memq (char-after) '(?\( ?\[ ?\{)) 1234 (memq (char-after) '(?\( ?\[ ?\{))
1157 (point))))))) 1235 (point)))))))
1158 ;; find balanced expression end 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 (point-marker))) 1238 (point-marker)))
1161 ;; sanity check 1239 ;; sanity check
1162 (and (not start) 1240 (and (not start)
@@ -1247,18 +1325,18 @@ Optional SHUTUP-P if non-nil, inhibits message printing and error checking."
1247 (while (< (point) nextline) 1325 (while (< (point) nextline)
1248 (condition-case nil 1326 (condition-case nil
1249 (progn 1327 (progn
1250 (forward-sexp 1) 1328 (c-forward-sexp 1)
1251 (setq sexpend (point))) 1329 (setq sexpend (point)))
1252 (error (setq sexpend nil) 1330 (error (setq sexpend nil)
1253 (goto-char nextline))) 1331 (goto-char nextline)))
1254 (c-forward-syntactic-ws)) 1332 (c-forward-syntactic-ws))
1255 (if sexpend 1333 (if sexpend
1256 (progn 1334 (progn
1257 ;; make sure the sexp we found really starts on the 1335 ;; make sure the sexp we found really starts on the
1258 ;; current line and extends past it 1336 ;; current line and extends past it
1259 (goto-char sexpend) 1337 (goto-char sexpend)
1260 (setq sexpend (point-marker)) 1338 (setq sexpend (point-marker))
1261 (c-safe (backward-sexp 1)) 1339 (c-safe (c-backward-sexp 1))
1262 (setq sexpbeg (point)))) 1340 (setq sexpbeg (point))))
1263 (if (and sexpbeg (< sexpbeg fence)) 1341 (if (and sexpbeg (< sexpbeg fence))
1264 (setq sexpbeg fence))) 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(defun c-mark-function () 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 (interactive) 1377 (interactive)
1300 (let ((here (point)) 1378 (let ((here (point))
1301 ;; there should be a c-point position for 'eod 1379 (eod (c-point 'eod))
1302 (eod (save-excursion (end-of-defun) (point))) 1380 (state (c-parse-state)))
1303 (state (c-parse-state)) 1381 ;; Are we sitting at the top level, someplace between either the
1304 brace) 1382 ;; beginning of buffer, or the nearest preceding defun? If so,
1305 (while state 1383 ;; try first to figure out whether we're sitting on the
1306 (setq brace (car state)) 1384 ;; introduction to a top-level defun, in which case we want to
1307 (if (consp brace) 1385 ;; mark the entire defun we're sitting on.
1308 (goto-char (cdr brace)) 1386 ;;
1309 (goto-char brace)) 1387 ;; If we're sitting on anything else at the top-level, we want to
1310 (setq state (cdr state))) 1388 ;; just mark the statement that we're on
1311 (if (eq (char-after) ?{) 1389 (if (or (and (consp (car state))
1312 (progn 1390 (= (length state) 1))
1313 (forward-line -1) 1391 (null state))
1314 (while (not (or (bobp) 1392 ;; Are we in the whitespace after the nearest preceding defun?
1315 (looking-at "[ \t]*$"))) 1393 (if (and state
1316 (forward-line -1))) 1394 (looking-at "[ \t]*$")
1317 (forward-line 1) 1395 (= (save-excursion
1318 (skip-chars-forward " \t\n")) 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 (push-mark here) 1427 (push-mark here)
1320 (push-mark eod nil t))) 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;; for progress reporting 1439;; for progress reporting
1324(defvar c-progress-info nil) 1440(defvar c-progress-info nil)
@@ -1384,7 +1500,7 @@ With an argument, deletes the backslashes.
1384This function does not modify blank lines at the start of the region. 1500This function does not modify blank lines at the start of the region.
1385If the region ends at the start of a line, it always deletes the 1501If the region ends at the start of a line, it always deletes the
1386backslash (if any) at the end of the previous line. 1502backslash (if any) at the end of the previous line.
1387 1503
1388You can put the region around an entire macro definition and use this 1504You can put the region around an entire macro definition and use this
1389command to conveniently insert and align the necessary backslashes." 1505command to conveniently insert and align the necessary backslashes."
1390 (interactive "*r\nP") 1506 (interactive "*r\nP")
@@ -1548,65 +1664,69 @@ Optional prefix ARG means justify paragraph as well."
1548 t))) 1664 t)))
1549 ;; Inside a comment: fill one comment paragraph. 1665 ;; Inside a comment: fill one comment paragraph.
1550 (let ((fill-prefix 1666 (let ((fill-prefix
1551 ;; The prefix for each line of this paragraph 1667 (or
1552 ;; is the appropriate part of the start of this line, 1668 ;; Keep user set fill prefix if any.
1553 ;; up to the column at which text should be indented. 1669 fill-prefix
1554 (save-excursion 1670 ;; The prefix for each line of this paragraph
1555 (beginning-of-line) 1671 ;; is the appropriate part of the start of this line,
1556 (if (looking-at ".*/\\*.*\\*/") 1672 ;; up to the column at which text should be indented.
1557 (progn (re-search-forward comment-start-skip) 1673 (save-excursion
1558 (make-string (current-column) ?\ )) 1674 (beginning-of-line)
1559 (if first-line 1675 (if (looking-at ".*/\\*.*\\*/")
1560 (forward-line 1) 1676 (progn (re-search-forward comment-start-skip)
1561 (if (and (looking-at "[ \t]*\\*/") 1677 (make-string (current-column) ?\ ))
1562 (not (save-excursion 1678 (if first-line
1563 (forward-line -1) 1679 (forward-line 1)
1564 (looking-at ".*/\\*")))) 1680 (if (and (looking-at "[ \t]*\\*/")
1565 (forward-line -1))) 1681 (not (save-excursion
1566 1682 (forward-line -1)
1567 (let ((line-width (progn (end-of-line) (current-column)))) 1683 (looking-at ".*/\\*"))))
1568 (beginning-of-line) 1684 (forward-line -1)))
1569 (prog1 1685
1570 (buffer-substring 1686 (let ((line-width (progn (end-of-line)
1571 (point) 1687 (current-column))))
1572 1688 (beginning-of-line)
1573 ;; How shall we decide where the end of the 1689 (prog1
1574 ;; fill-prefix is? 1690 (buffer-substring
1575 (progn 1691 (point)
1576 (skip-chars-forward " \t*" (c-point 'eol)) 1692
1577 ;; kludge alert, watch out for */, in 1693 ;; How shall we decide where the end of the
1578 ;; which case fill-prefix should *not* 1694 ;; fill-prefix is?
1579 ;; be "*"! 1695 (progn
1580 (if (and (eq (char-after) ?/) 1696 (skip-chars-forward " \t*" (c-point 'eol))
1581 (eq (char-before) ?*)) 1697 ;; kludge alert, watch out for */, in
1582 (forward-char -1)) 1698 ;; which case fill-prefix should *not*
1583 (point))) 1699 ;; be "*"!
1584 1700 (if (and (eq (char-after) ?/)
1585 ;; If the comment is only one line followed 1701 (eq (char-before) ?*))
1586 ;; by a blank line, calling move-to-column 1702 (forward-char -1))
1587 ;; above may have added some spaces and tabs 1703 (point)))
1588 ;; to the end of the line; the fill-paragraph 1704
1589 ;; function will then delete it and the 1705 ;; If the comment is only one line followed
1590 ;; newline following it, so we'll lose a 1706 ;; by a blank line, calling move-to-column
1591 ;; blank line when we shouldn't. So delete 1707 ;; above may have added some spaces and tabs
1592 ;; anything move-to-column added to the end 1708 ;; to the end of the line; the fill-paragraph
1593 ;; of the line. We record the line width 1709 ;; function will then delete it and the
1594 ;; instead of the position of the old line 1710 ;; newline following it, so we'll lose a
1595 ;; end because move-to-column might break a 1711 ;; blank line when we shouldn't. So delete
1596 ;; tab into spaces, and the new characters 1712 ;; anything move-to-column added to the end
1597 ;; introduced there shouldn't be deleted. 1713 ;; of the line. We record the line width
1598 1714 ;; instead of the position of the old line
1599 ;; If you can see a better way to do this, 1715 ;; end because move-to-column might break a
1600 ;; please make the change. This seems very 1716 ;; tab into spaces, and the new characters
1601 ;; messy to me. 1717 ;; introduced there shouldn't be deleted.
1602 (delete-region (progn (move-to-column line-width) 1718
1603 (point)) 1719 ;; If you can see a better way to do this,
1604 (progn (end-of-line) (point)))))))) 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 ;; Lines containing just a comment start or just an end 1726 ;; Lines containing just a comment start or just an end
1607 ;; should not be filled into paragraphs they are next 1727 ;; should not be filled into paragraphs they are next
1608 ;; to. 1728 ;; to.
1609 (paragraph-start (if (eq major-mode 'java-mode) 1729 (paragraph-start (if (c-major-mode-is 'java-mode)
1610 (concat paragraph-start 1730 (concat paragraph-start
1611 re1 "\\(" 1731 re1 "\\("
1612 c-Java-javadoc-paragraph-start 1732 c-Java-javadoc-paragraph-start
@@ -1695,8 +1815,7 @@ Optional prefix ARG means justify paragraph as well."
1695 (goto-char (car limits)) 1815 (goto-char (car limits))
1696 (end-of-line) 1816 (end-of-line)
1697 (< (point) (cdr limits)))) 1817 (< (point) (cdr limits))))
1698 (let (fill-prefix 1818 (let (fill-paragraph-function)
1699 fill-paragraph-function)
1700 (save-restriction 1819 (save-restriction
1701 (narrow-to-region (save-excursion 1820 (narrow-to-region (save-excursion
1702 (goto-char (1+ (car limits))) 1821 (goto-char (1+ (car limits)))
diff --git a/lisp/progmodes/cc-compat.el b/lisp/progmodes/cc-compat.el
index 0a8c15937ee..d7556a6084e 100644
--- a/lisp/progmodes/cc-compat.el
+++ b/lisp/progmodes/cc-compat.el
@@ -1,9 +1,9 @@
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 Free Software Foundation, Inc. 3;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc.
4 4
5;; Author: 1994-1997 Barry A. Warsaw 5;; Author: 1994-1997 Barry A. Warsaw
6;; Maintainer: cc-mode-help@python.org 6;; Maintainer: bug-cc-mode@gnu.org
7;; Created: August 1994, split from cc-mode.el 7;; Created: August 1994, split from cc-mode.el
8;; Version: See cc-mode.el 8;; Version: See cc-mode.el
9;; Keywords: c languages oop 9;; Keywords: c languages oop
@@ -40,6 +40,7 @@
40;;; Code: 40;;; Code:
41 41
42(eval-when-compile 42(eval-when-compile
43 (require 'cc-defs)
43 (require 'cc-styles) 44 (require 'cc-styles)
44 (require 'cc-engine)) 45 (require 'cc-engine))
45 46
@@ -114,7 +115,7 @@ This is in addition to c-continued-statement-offset.")
114 ;; line 115 ;; line
115 (progn 116 (progn
116 (if (eq (char-before) ?\)) 117 (if (eq (char-before) ?\))
117 (forward-sexp -1)) 118 (c-forward-sexp -1))
118 ;; Get initial indentation of the line we are on. 119 ;; Get initial indentation of the line we are on.
119 (current-indentation))))) 120 (current-indentation)))))
120 (- bocm-lossage curcol)))) 121 (- bocm-lossage curcol))))
diff --git a/lisp/progmodes/cc-defs.el b/lisp/progmodes/cc-defs.el
index 2aea9d9989d..2ae6c7bdcf0 100644
--- a/lisp/progmodes/cc-defs.el
+++ b/lisp/progmodes/cc-defs.el
@@ -2,10 +2,11 @@
2 2
3;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc. 3;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc.
4 4
5;; Authors: 1992-1997 Barry A. Warsaw 5;; Authors: 1998 Barry A. Warsaw and Martin Stjernholm
6;; 1992-1997 Barry A. Warsaw
6;; 1987 Dave Detlefs and Stewart Clamen 7;; 1987 Dave Detlefs and Stewart Clamen
7;; 1985 Richard M. Stallman 8;; 1985 Richard M. Stallman
8;; Maintainer: cc-mode-help@python.org 9;; Maintainer: bug-cc-mode@gnu.org
9;; Created: 22-Apr-1997 (split from cc-mode.el) 10;; Created: 22-Apr-1997 (split from cc-mode.el)
10;; Version: See cc-mode.el 11;; Version: See cc-mode.el
11;; Keywords: c languages oop 12;; Keywords: c languages oop
@@ -28,6 +29,25 @@
28;; Boston, MA 02111-1307, USA. 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(defsubst c-point (position) 51(defsubst c-point (position)
32 ;; Returns the value of point at certain commonly referenced POSITIONs. 52 ;; Returns the value of point at certain commonly referenced POSITIONs.
33 ;; POSITION can be one of the following symbols: 53 ;; POSITION can be one of the following symbols:
@@ -35,6 +55,7 @@
35 ;; bol -- beginning of line 55 ;; bol -- beginning of line
36 ;; eol -- end of line 56 ;; eol -- end of line
37 ;; bod -- beginning of defun 57 ;; bod -- beginning of defun
58 ;; eod -- end of defun
38 ;; boi -- back to indentation 59 ;; boi -- back to indentation
39 ;; ionl -- indentation of next line 60 ;; ionl -- indentation of next line
40 ;; iopl -- indentation of previous line 61 ;; iopl -- indentation of previous line
@@ -55,14 +76,14 @@
55 ((eq position 'ionl) 76 ((eq position 'ionl)
56 (forward-line 1) 77 (forward-line 1)
57 (back-to-indentation)) 78 (back-to-indentation))
79 ((eq position 'eod) (c-end-of-defun))
58 ((eq position 'bod) 80 ((eq position 'bod)
59 (if (and (fboundp 'buffer-syntactic-context-depth) 81 (if (and (fboundp 'buffer-syntactic-context-depth)
60 c-enable-xemacs-performance-kludge-p) 82 c-enable-xemacs-performance-kludge-p)
61 ;; XEmacs only. This can improve the performance of 83 ;; XEmacs only. This can improve the performance of
62 ;; c-parse-state to between 3 and 60 times faster when 84 ;; c-parse-state to between 3 and 60 times faster when
63 ;; braces are hung. It can cause c-parse-state to be 85 ;; braces are hung. It can also degrade performance by
64 ;; slightly slower when braces are not hung, but general 86 ;; about as much when braces are not hung.
65 ;; editing appears to be still about as fast.
66 (let (pos) 87 (let (pos)
67 (while (not pos) 88 (while (not pos)
68 (save-restriction 89 (save-restriction
@@ -106,12 +127,31 @@
106 (point) 127 (point)
107 (goto-char here)))) 128 (goto-char here))))
108 129
130
109(defmacro c-safe (&rest body) 131(defmacro c-safe (&rest body)
110 ;; safely execute BODY, return nil if an error occurred 132 ;; safely execute BODY, return nil if an error occurred
111 (` (condition-case nil 133 (` (condition-case nil
112 (progn (,@ body)) 134 (progn (,@ body))
113 (error nil)))) 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(defmacro c-add-syntax (symbol &optional relpos) 155(defmacro c-add-syntax (symbol &optional relpos)
116 ;; a simple macro to append the syntax in symbol to the syntax list. 156 ;; a simple macro to append the syntax in symbol to the syntax list.
117 ;; try to increase performance by using this macro 157 ;; try to increase performance by using this macro
@@ -163,6 +203,22 @@
163 (and (boundp 'zmacs-region-stays) 203 (and (boundp 'zmacs-region-stays)
164 (setq zmacs-region-stays t))) 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(provide 'cc-defs) 223(provide 'cc-defs)
168;;; cc-defs.el ends here 224;;; cc-defs.el ends here
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 31a26c3c3c3..8df67dd33ba 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -2,10 +2,11 @@
2 2
3;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc. 3;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc.
4 4
5;; Authors: 1992-1997 Barry A. Warsaw 5;; Authors: 1998 Barry A. Warsaw and Martin Stjernholm
6;; 1992-1997 Barry A. Warsaw
6;; 1987 Dave Detlefs and Stewart Clamen 7;; 1987 Dave Detlefs and Stewart Clamen
7;; 1985 Richard M. Stallman 8;; 1985 Richard M. Stallman
8;; Maintainer: cc-mode-help@python.org 9;; Maintainer: bug-cc-mode@gnu.org
9;; Created: 22-Apr-1997 (split from cc-mode.el) 10;; Created: 22-Apr-1997 (split from cc-mode.el)
10;; Version: See cc-mode.el 11;; Version: See cc-mode.el
11;; Keywords: c languages oop 12;; Keywords: c languages oop
@@ -28,6 +29,9 @@
28;; Boston, MA 02111-1307, USA. 29;; Boston, MA 02111-1307, USA.
29 30
30 31
32(eval-when-compile
33 (require 'cc-defs))
34
31;; KLUDGE ALERT: c-maybe-labelp is used to pass information between 35;; KLUDGE ALERT: c-maybe-labelp is used to pass information between
32;; c-crosses-statement-barrier-p and c-beginning-of-statement-1. A 36;; c-crosses-statement-barrier-p and c-beginning-of-statement-1. A
33;; better way should be implemented, but this will at least shut up 37;; better way should be implemented, but this will at least shut up
@@ -66,7 +70,7 @@
66 (if (bobp) (setq donep t) 70 (if (bobp) (setq donep t)
67 ;; go backwards one balanced expression, but be careful of 71 ;; go backwards one balanced expression, but be careful of
68 ;; unbalanced paren being reached 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 (progn 74 (progn
71 (if firstp 75 (if firstp
72 (backward-up-list 1) 76 (backward-up-list 1)
@@ -75,7 +79,7 @@
75 ;; characters appearing at front of identifier 79 ;; characters appearing at front of identifier
76 (save-excursion 80 (save-excursion
77 (c-backward-syntactic-ws lim) 81 (c-backward-syntactic-ws lim)
78 (skip-chars-backward "-+!*&:.~ \t\n") 82 (skip-chars-backward "-+!*&:.~@ \t\n")
79 (if (eq (char-before) ?\() 83 (if (eq (char-before) ?\()
80 (setq last-begin (point)))) 84 (setq last-begin (point))))
81 (goto-char last-begin) 85 (goto-char last-begin)
@@ -97,7 +101,7 @@
97 ((or (looking-at c-conditional-key) 101 ((or (looking-at c-conditional-key)
98 (and (eq (char-after) ?\() 102 (and (eq (char-after) ?\()
99 (save-excursion 103 (save-excursion
100 (forward-sexp 1) 104 (c-forward-sexp 1)
101 (c-forward-syntactic-ws) 105 (c-forward-syntactic-ws)
102 (not (eq (char-after) ?\;))) 106 (not (eq (char-after) ?\;)))
103 (let ((here (point)) 107 (let ((here (point))
@@ -117,17 +121,23 @@
117 ;; are we in the middle of an else-if clause? 121 ;; are we in the middle of an else-if clause?
118 (if (save-excursion 122 (if (save-excursion
119 (and (not substmt-p) 123 (and (not substmt-p)
120 (c-safe (progn (forward-sexp -1) t)) 124 (c-safe (progn (c-forward-sexp -1) t))
121 (looking-at "\\<else\\>[ \t\n]+\\<if\\>") 125 (looking-at "\\<else\\>[ \t\n]+\\<if\\>")
122 (not (c-in-literal lim)))) 126 (not (c-in-literal lim))))
123 (progn 127 (progn
124 (forward-sexp -1) 128 (c-forward-sexp -1)
125 (c-backward-to-start-of-if lim))) 129 (c-backward-to-start-of-if lim)))
126 ;; are we sitting at an else clause, that we are not a 130 ;; are we sitting at an else clause, that we are not a
127 ;; substatement of? 131 ;; substatement of?
128 (if (and (not substmt-p) 132 (if (and (not substmt-p)
129 (looking-at "\\<else\\>[^_]")) 133 (looking-at "\\<else\\>[^_]"))
130 (c-backward-to-start-of-if lim)) 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 ;; are we sitting at the while of a do-while? 141 ;; are we sitting at the while of a do-while?
132 (if (and (looking-at "\\<while\\>[^_]") 142 (if (and (looking-at "\\<while\\>[^_]")
133 (c-backward-to-start-of-do lim)) 143 (c-backward-to-start-of-do lim))
@@ -142,7 +152,14 @@
142 (point) last-begin)) 152 (point) last-begin))
143 last-begin (point))) 153 last-begin (point)))
144 ;; CASE 6: have we crossed a statement barrier? 154 ;; CASE 6: have we crossed a statement barrier?
145 ((c-crosses-statement-barrier-p (point) last-begin) 155 ((save-excursion
156 ;; Move over in-expression blocks before checking the
157 ;; barrier
158 (if (or (memq (char-after) '(?\( ?\[))
159 (and (eq (char-after) ?{)
160 (c-looking-at-inexpr-block lim)))
161 (c-forward-sexp 1))
162 (c-crosses-statement-barrier-p (point) last-begin))
146 (setq donep t)) 163 (setq donep t))
147 ;; CASE 7: ignore labels 164 ;; CASE 7: ignore labels
148 ((and c-maybe-labelp 165 ((and c-maybe-labelp
@@ -167,9 +184,11 @@
167 (t (setq last-begin (point))) 184 (t (setq last-begin (point)))
168 )))) 185 ))))
169 (goto-char last-begin) 186 (goto-char last-begin)
170 ;; we always do want to skip over non-whitespace modifier 187 ;; We always want to skip over the non-whitespace modifier
171 ;; characters that didn't get skipped above 188 ;; characters that can start a statement.
172 (skip-chars-backward "-+!*&:.~" (c-point 'boi)))) 189 (let ((lim (point)))
190 (skip-chars-backward "-+!*&~@ \t\n" (c-point 'boi))
191 (skip-chars-forward " \t\n" lim))))
173 192
174(defun c-end-of-statement-1 () 193(defun c-end-of-statement-1 ()
175 (condition-case nil 194 (condition-case nil
@@ -177,7 +196,7 @@
177 (while (and (not (eobp)) 196 (while (and (not (eobp))
178 (progn 197 (progn
179 (setq beg (point)) 198 (setq beg (point))
180 (forward-sexp 1) 199 (c-forward-sexp 1)
181 (setq end (point)) 200 (setq end (point))
182 (goto-char beg) 201 (goto-char beg)
183 (setq found nil) 202 (setq found nil)
@@ -208,7 +227,7 @@
208 (goto-char from) 227 (goto-char from)
209 (while (and (not crossedp) 228 (while (and (not crossedp)
210 (< (point) to)) 229 (< (point) to))
211 (skip-chars-forward "^;{}:" to) 230 (skip-chars-forward "^;{}:" (1- to))
212 (if (not (c-in-literal lim)) 231 (if (not (c-in-literal lim))
213 (progn 232 (progn
214 (if (memq (char-after) '(?\; ?{ ?})) 233 (if (memq (char-after) '(?\; ?{ ?}))
@@ -272,50 +291,101 @@
272 291
273 292
274;; Moving by tokens, where a token is defined as all symbols and 293;; Moving by tokens, where a token is defined as all symbols and
275;; identifiers which aren't syntactic whitespace. COUNT specifies the 294;; identifiers which aren't syntactic whitespace (note that "->" is
276;; number of tokens to move forward; a negative COUNT moves backward. 295;; considered to be two tokens). Point is always either left at the
277;; If BALANCED is true, move over balanced parens, otherwise move into 296;; beginning of a token or not moved at all. COUNT specifies the
278;; them. Also, if BALANCED is true, never move out of an enclosing 297;; number of tokens to move; a negative COUNT moves in the opposite
279;; paren. LIM sets the limit for the movement. Point is always left 298;; direction. A COUNT of 0 moves to the next token beginning only if
280;; at the beginning of a token or at LIM. Returns the number of 299;; not already at one. If BALANCED is true, move over balanced
300;; parens, otherwise move into them. Also, if BALANCED is true, never
301;; move out of an enclosing paren. LIM sets the limit for the
302;; movement and defaults to the point limit. Returns the number of
281;; tokens left to move (positive or negative). If BALANCED is true, a 303;; tokens left to move (positive or negative). If BALANCED is true, a
282;; move over a balanced paren counts as one. 304;; move over a balanced paren counts as one. Note that if COUNT is 0
305;; and no appropriate token beginning is found, 1 will be returned.
306;; Thus, a return value of 0 guarantees that point is at the requested
307;; position and a return value less (without signs) than COUNT
308;; guarantees that point is at the beginning of some token.
283 309
284(defun c-forward-token-1 (&optional count balanced lim) 310(defun c-forward-token-1 (&optional count balanced lim)
285 (let* ((jump-syntax (if balanced 311 (or count (setq count 1))
286 '(?w ?_ ?\" ?\\ ?/ ?$ ?' ?\( ?\)) 312 (if (< count 0)
287 '(?w ?_ ?\" ?\\ ?/ ?$ ?')))) 313 (- (c-backward-token-1 (- count) balanced lim))
288 (or count (setq count 1)) 314 (let ((jump-syntax (if balanced
289 (condition-case nil 315 '(?w ?_ ?\( ?\) ?\" ?\\ ?/ ?$ ?')
290 (while (progn 316 '(?w ?_ ?\" ?\\ ?/ ?')))
291 (c-forward-syntactic-ws lim) 317 (last (point))
292 (> count 0)) 318 (prev (point)))
293 (if (memq (char-syntax (char-after)) jump-syntax) 319 (if (/= (point)
294 (goto-char (scan-sexps (point) 1)) 320 (progn (c-forward-syntactic-ws) (point)))
295 (forward-char)) 321 ;; Skip whitespace. Count this as a move if we did in fact
296 (setq count (1- count))) 322 ;; move and aren't out of bounds.
297 (error 323 (or (eobp)
298 (and lim (> (point) lim) (goto-char lim)))) 324 (and lim (> (point) lim))
299 count)) 325 (setq count (max (1- count) 0))))
326 (if (and (= count 0)
327 (or (and (memq (char-syntax (or (char-after) ? )) '(?w ?_))
328 (memq (char-syntax (or (char-before) ? )) '(?w ?_)))
329 (eobp)))
330 ;; If count is zero we should jump if in the middle of a
331 ;; token or if there is whitespace between point and the
332 ;; following token beginning.
333 (setq count 1))
334 ;; Avoid having the limit tests inside the loop.
335 (save-restriction
336 (if lim (narrow-to-region (point-min) lim))
337 (if (eobp)
338 (goto-char last)
339 (condition-case nil
340 (while (> count 0)
341 (setq prev last
342 last (point))
343 (if (memq (char-syntax (char-after)) jump-syntax)
344 (goto-char (scan-sexps (point) 1))
345 (forward-char))
346 (c-forward-syntactic-ws lim)
347 (setq count (1- count)))
348 (error (goto-char last)))
349 (when (eobp)
350 (goto-char prev)
351 (setq count (1+ count)))))
352 count)))
300 353
301(defun c-backward-token-1 (&optional count balanced lim) 354(defun c-backward-token-1 (&optional count balanced lim)
302 (let* ((jump-syntax (if balanced 355 (or count (setq count 1))
303 '(?w ?_ ?\" ?\\ ?/ ?$ ?' ?\( ?\)) 356 (if (< count 0)
304 '(?w ?_ ?\" ?\\ ?/ ?$ ?'))) 357 (- (c-forward-token-1 (- count) balanced lim))
305 last) 358 (let ((jump-syntax (if balanced
306 (or count (setq count 1)) 359 '(?w ?_ ?\( ?\) ?\" ?\\ ?/ ?$ ?')
307 (condition-case nil 360 '(?w ?_ ?\" ?\\ ?/ ?')))
308 (while (> count 0) 361 last)
309 (setq last (point)) 362 (if (and (= count 0)
310 (c-backward-syntactic-ws lim) 363 (or (and (memq (char-syntax (or (char-after) ? )) '(?w ?_))
311 (if (memq (char-syntax (char-before)) jump-syntax) 364 (memq (char-syntax (or (char-before) ? )) '(?w ?_)))
312 (goto-char (scan-sexps (point) -1)) 365 (/= (point)
313 (backward-char)) 366 (save-excursion (c-forward-syntactic-ws) (point)))
314 (setq count (1- count))) 367 (eobp)))
315 (error 368 ;; If count is zero we should jump if in the middle of a
316 (goto-char last) 369 ;; token or if there is whitespace between point and the
317 (and lim (< (point) lim) (goto-char lim)))) 370 ;; following token beginning.
318 count)) 371 (setq count 1))
372 ;; Avoid having the limit tests inside the loop.
373 (save-restriction
374 (if lim (narrow-to-region lim (point-max)))
375 (or (bobp)
376 (progn
377 (condition-case nil
378 (while (progn
379 (setq last (point))
380 (> count 0))
381 (c-backward-syntactic-ws lim)
382 (if (memq (char-syntax (char-before)) jump-syntax)
383 (goto-char (scan-sexps (point) -1))
384 (backward-char))
385 (setq count (1- count)))
386 (error (goto-char last)))
387 (if (bobp) (goto-char last)))))
388 count)))
319 389
320 390
321;; Return `c' if in a C-style comment, `c++' if in a C++ style 391;; Return `c' if in a C-style comment, `c++' if in a C++ style
@@ -358,22 +428,29 @@
358(if (fboundp 'buffer-syntactic-context) 428(if (fboundp 'buffer-syntactic-context)
359 (defalias 'c-in-literal 'c-fast-in-literal)) 429 (defalias 'c-in-literal 'c-fast-in-literal))
360 430
361(defun c-literal-limits (&optional lim) 431(defun c-literal-limits (&optional lim near)
362 ;; Returns a cons of the beginning and end positions of the comment 432 ;; Returns a cons of the beginning and end positions of the comment
363 ;; or string surrounding point (including both delimiters), or nil 433 ;; or string surrounding point (including both delimiters), or nil
364 ;; if point isn't in one. This is the Emacs 19 version. 434 ;; if point isn't in one. If LIM is non-nil, it's used as the
435 ;; "safe" position to start parsing from. If NEAR is non-nil, then
436 ;; the limits of any literal next to point is returned. "Next to"
437 ;; means there's only [ \t] between point and the literal. The
438 ;; search for such a literal is done first in forward direction.
439 ;;
440 ;; This is the Emacs 19 version.
365 (save-excursion 441 (save-excursion
366 (let* ((lim (or lim (c-point 'bod))) 442 (let* ((pos (point))
443 (lim (or lim (c-point 'bod)))
367 (state (parse-partial-sexp lim (point)))) 444 (state (parse-partial-sexp lim (point))))
368 (cond ((nth 3 state) 445 (cond ((nth 3 state)
369 ;; String. Search backward for the start. 446 ;; String. Search backward for the start.
370 (while (nth 3 state) 447 (while (nth 3 state)
371 (search-backward (make-string 1 (nth 3 state))) 448 (search-backward (make-string 1 (nth 3 state)))
372 (setq state (parse-partial-sexp lim (point)))) 449 (setq state (parse-partial-sexp lim (point))))
373 (cons (point) (or (c-safe (forward-sexp 1) (point)) 450 (cons (point) (or (c-safe (c-forward-sexp 1) (point))
374 (point-max)))) 451 (point-max))))
375 ((nth 7 state) 452 ((nth 7 state)
376 ;; C++ comment. Search from bol for the comment starter. 453 ;; Line comment. Search from bol for the comment starter.
377 (beginning-of-line) 454 (beginning-of-line)
378 (setq state (parse-partial-sexp lim (point)) 455 (setq state (parse-partial-sexp lim (point))
379 lim (point)) 456 lim (point))
@@ -385,7 +462,7 @@
385 (backward-char 2) 462 (backward-char 2)
386 (cons (point) (progn (forward-comment 1) (point)))) 463 (cons (point) (progn (forward-comment 1) (point))))
387 ((nth 4 state) 464 ((nth 4 state)
388 ;; C comment. Search backward for the comment starter. 465 ;; Block comment. Search backward for the comment starter.
389 (while (nth 4 state) 466 (while (nth 4 state)
390 (search-backward "/*") ; Should never fail. 467 (search-backward "/*") ; Should never fail.
391 (setq state (parse-partial-sexp lim (point)))) 468 (setq state (parse-partial-sexp lim (point))))
@@ -395,18 +472,43 @@
395 ;; We're standing in a comment starter. 472 ;; We're standing in a comment starter.
396 (backward-char 2) 473 (backward-char 2)
397 (cons (point) (progn (forward-comment 1) (point)))) 474 (cons (point) (progn (forward-comment 1) (point))))
475 (near
476 (goto-char pos)
477 ;; Search forward for a literal.
478 (skip-chars-forward " \t")
479 (cond
480 ((eq (char-syntax (or (char-after) ?\ )) ?\") ; String.
481 (cons (point) (or (c-safe (c-forward-sexp 1) (point))
482 (point-max))))
483 ((looking-at "/[/*]") ; Line or block comment.
484 (cons (point) (progn (forward-comment 1) (point))))
485 (t
486 ;; Search backward.
487 (skip-chars-backward " \t")
488 (let ((end (point)) beg)
489 (cond
490 ((eq (char-syntax (or (char-before) ?\ )) ?\") ; String.
491 (setq beg (c-safe (c-backward-sexp 1) (point))))
492 ((and (c-safe (forward-char -2) t)
493 (looking-at "*/"))
494 ;; Block comment. Due to the nature of line
495 ;; comments, they will always be covered by the
496 ;; normal case above.
497 (goto-char end)
498 (forward-comment -1)
499 ;; If LIM is bogus, beg will be bogus.
500 (setq beg (point))))
501 (if beg (cons beg end))))))
398 )))) 502 ))))
399 503
400(defun c-literal-limits-fast (&optional lim) 504(defun c-literal-limits-fast (&optional lim)
401 ;; Returns a cons of the beginning and end positions of the comment 505 ;; Like c-literal-limits, but for emacsen whose `parse-partial-sexp'
402 ;; or string surrounding point (including both delimiters), or nil 506 ;; returns the pos of the comment start. FIXME: Add NEAR.
403 ;; if point isn't in one. This is for emacsen whose
404 ;; `parse-partial-sexp' returns the pos of the comment start.
405 (save-excursion 507 (save-excursion
406 (let ((state (parse-partial-sexp lim (point)))) 508 (let ((state (parse-partial-sexp lim (point))))
407 (cond ((nth 3 state) ; String. 509 (cond ((nth 3 state) ; String.
408 (goto-char (nth 8 state)) 510 (goto-char (nth 8 state))
409 (cons (point) (or (c-safe (forward-sexp 1) (point)) 511 (cons (point) (or (c-safe (c-forward-sexp 1) (point))
410 (point-max)))) 512 (point-max))))
411 ((nth 4 state) ; Comment. 513 ((nth 4 state) ; Comment.
412 (goto-char (nth 8 state)) 514 (goto-char (nth 8 state))
@@ -450,6 +552,19 @@
450 range) 552 range)
451 (error range)))) 553 (error range))))
452 554
555(defun c-literal-type (range)
556 ;; Convenience function that given the result of c-literal-limits,
557 ;; returns nil or the type of literal that the range surrounds.
558 ;; It's much faster than using c-in-literal and is intended to be
559 ;; used when you need both the type of a literal and its limits.
560 (if (consp range)
561 (save-excursion
562 (goto-char (car range))
563 (cond ((eq (char-syntax (or (char-after) ?\ )) ?\") 'string)
564 ((looking-at "//") 'c++)
565 (t 'c))) ; Assuming the range is valid.
566 range))
567
453 568
454 569
455;; utilities for moving and querying around syntactic elements 570;; utilities for moving and querying around syntactic elements
@@ -470,7 +585,19 @@
470 (let ((cnt 2)) 585 (let ((cnt 2))
471 (while (not (or at-bob (zerop cnt))) 586 (while (not (or at-bob (zerop cnt)))
472 (goto-char (c-point 'bod)) 587 (goto-char (c-point 'bod))
473 (if (eq (char-after) ?\{) 588 (if (and
589 (eq (char-after) ?\{)
590 ;; The following catches an obscure special
591 ;; case where the brace is preceded by an
592 ;; open paren. That can only legally occur
593 ;; with blocks inside expressions and in
594 ;; Pike special brace lists. Even so, this
595 ;; test is still bogus then, but hopefully
596 ;; good enough. (We don't want to use
597 ;; up-list here since it might be slow.)
598 (save-excursion
599 (c-backward-syntactic-ws)
600 (not (eq (char-before) ?\())))
474 (setq cnt (1- cnt))) 601 (setq cnt (1- cnt)))
475 (if (bobp) 602 (if (bobp)
476 (setq at-bob t)))) 603 (setq at-bob t))))
@@ -591,7 +718,7 @@
591 718
592(defun c-adjust-state (from to shift state) 719(defun c-adjust-state (from to shift state)
593 ;; Adjust all points in state that lie in the region FROM..TO by 720 ;; Adjust all points in state that lie in the region FROM..TO by
594 ;; SHIFT amount (as would be returned by c-indent-line). 721 ;; SHIFT amount.
595 (mapcar 722 (mapcar
596 (function 723 (function
597 (lambda (e) 724 (lambda (e)
@@ -669,13 +796,13 @@
669 ;; check if we are looking at a method def 796 ;; check if we are looking at a method def
670 (or (not c-method-key) 797 (or (not c-method-key)
671 (progn 798 (progn
672 (forward-sexp -1) 799 (c-forward-sexp -1)
673 (forward-char -1) 800 (forward-char -1)
674 (c-backward-syntactic-ws) 801 (c-backward-syntactic-ws)
675 (not (or (memq (char-before) '(?- ?+)) 802 (not (or (memq (char-before) '(?- ?+))
676 ;; or a class category 803 ;; or a class category
677 (progn 804 (progn
678 (forward-sexp -2) 805 (c-forward-sexp -2)
679 (looking-at c-class-key)) 806 (looking-at c-class-key))
680 ))))) 807 )))))
681 ))) 808 )))
@@ -695,7 +822,7 @@
695 ;; while is not associated with a do will throw an error 822 ;; while is not associated with a do will throw an error
696 (condition-case nil 823 (condition-case nil
697 (progn 824 (progn
698 (backward-sexp 1) 825 (c-backward-sexp 1)
699 (cond 826 (cond
700 ;; break infloop for illegal C code 827 ;; break infloop for illegal C code
701 ((bobp) (setq do-level 0)) 828 ((bobp) (setq do-level 0))
@@ -732,7 +859,7 @@
732 (not (zerop if-level))) 859 (not (zerop if-level)))
733 (c-backward-syntactic-ws) 860 (c-backward-syntactic-ws)
734 (condition-case nil 861 (condition-case nil
735 (backward-sexp 1) 862 (c-backward-sexp 1)
736 (error 863 (error
737 (if at-if 864 (if at-if
738 (throw 'orphan-if nil) 865 (throw 'orphan-if nil)
@@ -744,7 +871,7 @@
744 ((looking-at "if\\b[^_]") 871 ((looking-at "if\\b[^_]")
745 ;; check for else if... skip over 872 ;; check for else if... skip over
746 (let ((here (point))) 873 (let ((here (point)))
747 (c-safe (forward-sexp -1)) 874 (c-safe (c-forward-sexp -1))
748 (if (looking-at "\\<else\\>[ \t]+\\<if\\>") 875 (if (looking-at "\\<else\\>[ \t]+\\<if\\>")
749 nil 876 nil
750 (setq if-level (1- if-level)) 877 (setq if-level (1- if-level))
@@ -758,13 +885,13 @@
758(defun c-skip-conditional () 885(defun c-skip-conditional ()
759 ;; skip forward over conditional at point, including any predicate 886 ;; skip forward over conditional at point, including any predicate
760 ;; statements in parentheses. No error checking is performed. 887 ;; statements in parentheses. No error checking is performed.
761 (forward-sexp (cond 888 (c-forward-sexp (cond
762 ;; else if() 889 ;; else if()
763 ((looking-at "\\<else\\>[ \t]+\\<if\\>") 3) 890 ((looking-at "\\<else\\>[ \t]+\\<if\\>") 3)
764 ;; do, else, try, finally 891 ;; do, else, try, finally
765 ((looking-at "\\<\\(do\\|else\\|try\\|finally\\)\\>") 1) 892 ((looking-at "\\<\\(do\\|else\\|try\\|finally\\)\\>") 1)
766 ;; for, if, while, switch, catch, synchronized 893 ;; for, if, while, switch, catch, synchronized
767 (t 2)))) 894 (t 2))))
768 895
769(defun c-skip-case-statement-forward (state &optional lim) 896(defun c-skip-case-statement-forward (state &optional lim)
770 ;; skip forward over case/default bodies, with optional maximal 897 ;; skip forward over case/default bodies, with optional maximal
@@ -800,8 +927,8 @@
800 927
801(defun c-search-uplist-for-classkey (brace-state) 928(defun c-search-uplist-for-classkey (brace-state)
802 ;; search for the containing class, returning a 2 element vector if 929 ;; search for the containing class, returning a 2 element vector if
803 ;; found. aref 0 contains the bufpos of the class key, and aref 1 930 ;; found. aref 0 contains the bufpos of the boi of the class key
804 ;; contains the bufpos of the open brace. 931 ;; line, and aref 1 contains the bufpos of the open brace.
805 (if (null brace-state) 932 (if (null brace-state)
806 ;; no brace-state means we cannot be inside a class 933 ;; no brace-state means we cannot be inside a class
807 nil 934 nil
@@ -845,6 +972,9 @@
845 (goto-char search-start) 972 (goto-char search-start)
846 (let ((search-key (concat c-class-key "\\|" c-extra-toplevel-key)) 973 (let ((search-key (concat c-class-key "\\|" c-extra-toplevel-key))
847 foundp class match-end) 974 foundp class match-end)
975 (if c-inexpr-class-key
976 (setq search-key (concat search-key "\\|"
977 c-inexpr-class-key)))
848 (while (and (not foundp) 978 (while (and (not foundp)
849 (progn 979 (progn
850 (c-forward-syntactic-ws) 980 (c-forward-syntactic-ws)
@@ -868,8 +998,19 @@
868 ;; class definition, and not a forward decl, return 998 ;; class definition, and not a forward decl, return
869 ;; arg, template arg list, or an ObjC or Java method. 999 ;; arg, template arg list, or an ObjC or Java method.
870 ((and c-method-key 1000 ((and c-method-key
871 (re-search-forward c-method-key search-end t)) 1001 (re-search-forward c-method-key search-end t)
1002 (not (c-in-literal class)))
872 (setq foundp nil)) 1003 (setq foundp nil))
1004 ;; Check if this is an anonymous inner class.
1005 ((and c-inexpr-class-key
1006 (looking-at c-inexpr-class-key))
1007 (while (and (= (c-forward-token-1 1 t) 0)
1008 (looking-at "(\\|\\w\\|\\s_\\|\\.")))
1009 (if (eq (point) search-end)
1010 ;; We're done. Just trap this case in the cond.
1011 nil
1012 ;; False alarm; all conditions aren't satisfied.
1013 (setq foundp nil)))
873 ;; Its impossible to define a regexp for this, and 1014 ;; Its impossible to define a regexp for this, and
874 ;; nearly so to do it programmatically. 1015 ;; nearly so to do it programmatically.
875 ;; 1016 ;;
@@ -885,7 +1026,10 @@
885 (skip-chars-backward "^<>" search-start) 1026 (skip-chars-backward "^<>" search-start)
886 (if (eq (char-before) ?<) 1027 (if (eq (char-before) ?<)
887 (setq skipchars (concat skipchars ">")))) 1028 (setq skipchars (concat skipchars ">"))))
888 (skip-chars-forward skipchars search-end) 1029 (while (progn
1030 (skip-chars-forward skipchars search-end)
1031 (c-in-literal class))
1032 (forward-char))
889 (/= (point) search-end)) 1033 (/= (point) search-end))
890 (setq foundp nil)) 1034 (setq foundp nil))
891 ))) 1035 )))
@@ -906,10 +1050,10 @@
906 (c-safe 1050 (c-safe
907 (save-excursion 1051 (save-excursion
908 (goto-char containing-sexp) 1052 (goto-char containing-sexp)
909 (forward-sexp -1) 1053 (c-forward-sexp -1)
910 (let (bracepos) 1054 (let (bracepos)
911 (if (and (or (looking-at "enum[\t\n ]+") 1055 (if (and (or (looking-at "enum[\t\n ]+")
912 (progn (forward-sexp -1) 1056 (progn (c-forward-sexp -1)
913 (looking-at "enum[\t\n ]+"))) 1057 (looking-at "enum[\t\n ]+")))
914 (setq bracepos (c-safe (scan-lists (point) 1 -1))) 1058 (setq bracepos (c-safe (scan-lists (point) 1 -1)))
915 (not (c-crosses-statement-barrier-p (point) 1059 (not (c-crosses-statement-barrier-p (point)
@@ -917,29 +1061,183 @@
917 (point))))) 1061 (point)))))
918 ;; this will pick up array/aggregate init lists, even if they are nested. 1062 ;; this will pick up array/aggregate init lists, even if they are nested.
919 (save-excursion 1063 (save-excursion
920 (let (bufpos okp) 1064 (let ((class-key
1065 ;; Pike can have class definitions anywhere, so we must
1066 ;; check for the class key here.
1067 (and (c-major-mode-is 'pike-mode)
1068 (concat c-class-key "\\|" c-extra-toplevel-key)))
1069 bufpos lim braceassignp)
921 (while (and (not bufpos) 1070 (while (and (not bufpos)
922 containing-sexp) 1071 containing-sexp)
923 (if (consp containing-sexp) 1072 (if (consp containing-sexp)
924 (setq containing-sexp (car brace-state) 1073 (setq containing-sexp (car brace-state)
925 brace-state (cdr brace-state)) 1074 brace-state (cdr brace-state))
926 ;; see if the open brace is preceded by a = in this statement
927 (goto-char containing-sexp) 1075 (goto-char containing-sexp)
928 (setq okp t) 1076 (if (c-looking-at-inexpr-block)
929 (while (and (setq okp (= (c-backward-token-1 1 t) 0)) 1077 ;; We're in an in-expression block of some kind. Do
930 (not (memq (char-after) '(?= ?{ ?\;))))) 1078 ;; not check nesting.
931 (if (not (and okp (eq (char-after) ?=))) 1079 (setq containing-sexp nil)
932 ;; lets see if we're nested. find the most nested 1080 ;; see if the open brace is preceded by = or [...] in
933 ;; containing brace 1081 ;; this statement, but watch out for operator=
934 (setq containing-sexp (car brace-state) 1082 (setq lim (if (consp (car brace-state))
935 brace-state (cdr brace-state)) 1083 (cdr (car brace-state))
936 ;; we've hit the beginning of the aggregate list 1084 (car brace-state))
937 (c-beginning-of-statement-1 (c-most-enclosing-brace brace-state)) 1085 braceassignp 'dontknow)
938 (setq bufpos (point))) 1086 (while (and (eq braceassignp 'dontknow)
1087 (zerop (c-backward-token-1 1 t lim)))
1088 (cond ((eq (char-after) ?\;)
1089 (setq braceassignp nil))
1090 ((and class-key
1091 (looking-at class-key))
1092 (setq braceassignp nil))
1093 ((eq (char-after) ?=)
1094 ;; We've seen a =, but must check earlier tokens so
1095 ;; that it isn't something that should be ignored.
1096 (setq braceassignp 'maybe)
1097 (while (and (eq braceassignp 'maybe)
1098 (zerop (c-backward-token-1 1 t lim)))
1099 (setq braceassignp
1100 (cond
1101 ;; Check for operator =
1102 ((looking-at "operator\\>") nil)
1103 ;; Check for `<opchar>= (Pike)
1104 ((eq (char-after) ?`) nil)
1105 ((looking-at "\\s.") 'maybe)
1106 ;; make sure we're not in a C++ template
1107 ;; argument assignment
1108 ((save-excursion
1109 (let ((here (point))
1110 (pos< (progn
1111 (skip-chars-backward "^<")
1112 (point))))
1113 (and (c-major-mode-is 'c++-mode)
1114 (eq (char-before) ?<)
1115 (not (c-crosses-statement-barrier-p
1116 here pos<))
1117 (not (c-in-literal))
1118 )))
1119 nil)
1120 (t t)))))
1121 ((eq (char-after) ?\[)
1122 ;; In Java, an initialization brace list may
1123 ;; follow "new Foo[]", so check for []. Got to
1124 ;; watch out for the C++ "operator[]" defun,
1125 ;; though.
1126 (setq braceassignp
1127 (save-excursion
1128 (c-backward-token-1)
1129 (not (looking-at "operator\\>")))))
1130 ))
1131 (if (memq braceassignp '(nil dontknow))
1132 (if (eq (char-after) ?\;)
1133 ;; Brace lists can't contain a semicolon, so we're done.
1134 (setq containing-sexp nil)
1135 ;; lets see if we're nested. find the most nested
1136 ;; containing brace
1137 (setq containing-sexp (car brace-state)
1138 brace-state (cdr brace-state)))
1139 ;; we've hit the beginning of the aggregate list
1140 (c-beginning-of-statement-1
1141 (c-most-enclosing-brace brace-state))
1142 (setq bufpos (point))))
939 )) 1143 ))
940 bufpos)) 1144 bufpos))
941 )) 1145 ))
942 1146
1147(defun c-looking-at-special-brace-list (&optional lim)
1148 ;; If we're looking at the start of a pike-style list, ie `({ })',
1149 ;; `([ ])', `(< >)' etc, a cons of a cons its starting and ending
1150 ;; positions and its entry in c-special-brace-lists is returned, nil
1151 ;; otherwise. The ending position is nil if the list is still open.
1152 ;; LIM is the limit for forward search. The point may either be at
1153 ;; the `(' or at the following paren character. Tries to check the
1154 ;; matching closer, but assumes it's correct if no balanced paren is
1155 ;; found (i.e. the case `({ ... } ... )' is detected as _not_ being
1156 ;; a special brace list).
1157 (if c-special-brace-lists
1158 (condition-case ()
1159 (save-excursion
1160 (let ((beg (point))
1161 end type)
1162 (c-forward-syntactic-ws)
1163 (if (eq (char-after) ?\()
1164 (progn
1165 (forward-char 1)
1166 (c-forward-syntactic-ws)
1167 (setq type (assq (char-after) c-special-brace-lists)))
1168 (if (setq type (assq (char-after) c-special-brace-lists))
1169 (progn
1170 (c-backward-syntactic-ws)
1171 (forward-char -1)
1172 (setq beg (if (eq (char-after) ?\()
1173 (point)
1174 nil)))))
1175 (if (and beg type)
1176 (if (and (c-safe (goto-char beg)
1177 (c-forward-sexp 1)
1178 (setq end (point))
1179 (= (char-before) ?\)))
1180 (c-safe (goto-char beg)
1181 (forward-char 1)
1182 (c-forward-sexp 1)
1183 ;; Kludges needed to handle inner
1184 ;; chars both with and without
1185 ;; paren syntax.
1186 (or (/= (char-syntax (char-before)) ?\))
1187 (= (char-before) (cdr type)))))
1188 (if (or (/= (char-syntax (char-before)) ?\))
1189 (= (progn
1190 (c-forward-syntactic-ws)
1191 (point))
1192 (1- end)))
1193 (cons (cons beg end) type))
1194 (cons (list beg) type)))))
1195 (error nil))))
1196
1197(defun c-looking-at-inexpr-block (&optional lim)
1198 ;; Returns non-nil if we're looking at the beginning of a block
1199 ;; inside an expression. The value returned is actually a cons of
1200 ;; either 'inlambda, 'inexpr-statement or 'inexpr-class and the
1201 ;; position of the beginning of the construct. LIM limits the
1202 ;; backward search.
1203 (save-excursion
1204 (or lim (setq lim (point-min)))
1205 (if (and (eq (char-after) ?{)
1206 (progn (c-backward-syntactic-ws) (> (point) lim))
1207 (eq (char-before) ?\()
1208 (not (and c-special-brace-lists
1209 (c-looking-at-special-brace-list))))
1210 (cons 'inexpr-statement (point))
1211 (let (res)
1212 (while (and (not res)
1213 (= (c-backward-token-1 1 t lim) 0)
1214 (>= (point) lim)
1215 (looking-at "(\\|\\w\\|\\s_\\|\\."))
1216 (setq res
1217 (cond ((and c-inexpr-class-key
1218 (looking-at c-inexpr-class-key))
1219 (cons 'inexpr-class (point)))
1220 ((and c-inexpr-block-key
1221 (looking-at c-inexpr-block-key))
1222 (cons 'inexpr-statement (point)))
1223 ((and c-lambda-key
1224 (looking-at c-lambda-key))
1225 (cons 'inlambda (point))))))
1226 res))))
1227
1228(defun c-looking-at-inexpr-block-backward (&optional lim)
1229 ;; Returns non-nil if we're looking at the end of an in-expression
1230 ;; block, otherwise the same as `c-looking-at-inexpr-block'.
1231 (save-excursion
1232 (let ((lim (or lim (c-point 'bod))))
1233 (c-safe
1234 (c-backward-syntactic-ws lim)
1235 (if (eq (char-before) ?}) ; Recognize only a block currently.
1236 (progn
1237 (c-forward-sexp -1)
1238 (if (>= (point) lim)
1239 (c-looking-at-inexpr-block lim))))))))
1240
943 1241
944(defun c-most-enclosing-brace (state) 1242(defun c-most-enclosing-brace (state)
945 ;; return the bufpos of the most enclosing brace that hasn't been 1243 ;; return the bufpos of the most enclosing brace that hasn't been
@@ -997,6 +1295,19 @@
997 ;; return the class vector 1295 ;; return the class vector
998 inclass-p)) 1296 inclass-p))
999 1297
1298(defsubst c-add-class-syntax (symbol classkey)
1299 ;; The inclass and class-close syntactic symbols are added in
1300 ;; several places and some work is needed to fix everything.
1301 ;; Therefore it's collected here.
1302 (save-restriction
1303 (widen)
1304 (goto-char (aref classkey 1))
1305 (if (and (eq symbol 'inclass) (= (point) (c-point 'boi)))
1306 (c-add-syntax symbol (point))
1307 (c-add-syntax symbol (aref classkey 0))
1308 (if (and c-inexpr-class-key (c-looking-at-inexpr-block))
1309 (c-add-syntax 'inexpr-class)))))
1310
1000 1311
1001;; This function implements the main decision tree for determining the 1312;; This function implements the main decision tree for determining the
1002;; syntactic analysis of the current line of code. Yes, it's huge and 1313;; syntactic analysis of the current line of code. Yes, it's huge and
@@ -1010,12 +1321,12 @@
1010 (case-fold-search nil) 1321 (case-fold-search nil)
1011 (fullstate (c-parse-state)) 1322 (fullstate (c-parse-state))
1012 (state fullstate) 1323 (state fullstate)
1013 (in-method-intro-p (and (eq major-mode 'objc-mode) 1324 (in-method-intro-p (and (c-major-mode-is 'objc-mode)
1014 c-method-key 1325 c-method-key
1015 (looking-at c-method-key))) 1326 (looking-at c-method-key)))
1016 literal containing-sexp char-before-ip char-after-ip lim 1327 literal containing-sexp char-before-ip char-after-ip lim
1017 syntax placeholder c-in-literal-cache inswitch-p 1328 syntax placeholder c-in-literal-cache inswitch-p
1018 tmpsymbol keyword injava-inher 1329 tmpsymbol keyword injava-inher special-brace-list
1019 ;; narrow out any enclosing class or extern "C" block 1330 ;; narrow out any enclosing class or extern "C" block
1020 (inclass-p (c-narrow-out-enclosing-class state indent-point)) 1331 (inclass-p (c-narrow-out-enclosing-class state indent-point))
1021 inenclosing-p) 1332 inenclosing-p)
@@ -1028,7 +1339,7 @@
1028 (if (and inclass-p 1339 (if (and inclass-p
1029 (progn 1340 (progn
1030 (goto-char (aref inclass-p 0)) 1341 (goto-char (aref inclass-p 0))
1031 (looking-at c-extra-toplevel-key))) 1342 (looking-at (concat c-extra-toplevel-key "[^_]"))))
1032 (let ((enclosing (match-string 1))) 1343 (let ((enclosing (match-string 1)))
1033 (cond 1344 (cond
1034 ((string-equal enclosing "extern") 1345 ((string-equal enclosing "extern")
@@ -1104,23 +1415,26 @@
1104 ;; CASE 5: Line is at top level. 1415 ;; CASE 5: Line is at top level.
1105 ((null containing-sexp) 1416 ((null containing-sexp)
1106 (cond 1417 (cond
1107 ;; CASE 5A: we are looking at a defun, class, or 1418 ;; CASE 5A: we are looking at a defun, brace list, class,
1108 ;; inline-inclass method opening brace 1419 ;; or inline-inclass method opening brace
1109 ((eq char-after-ip ?{) 1420 ((setq special-brace-list
1421 (or (and c-special-brace-lists
1422 (c-looking-at-special-brace-list))
1423 (eq char-after-ip ?{)))
1110 (cond 1424 (cond
1111 ;; CASE 5A.1: extern language or namespace construct 1425 ;; CASE 5A.1: extern language or namespace construct
1112 ((save-excursion 1426 ((save-excursion
1113 (goto-char indent-point) 1427 (goto-char indent-point)
1114 (skip-chars-forward " \t") 1428 (skip-chars-forward " \t")
1115 (and (c-safe (progn (backward-sexp 2) t)) 1429 (and (c-safe (progn (c-backward-sexp 2) t))
1116 (looking-at c-extra-toplevel-key) 1430 (looking-at (concat c-extra-toplevel-key "[^_]"))
1117 (setq keyword (match-string 1) 1431 (setq keyword (match-string 1)
1118 placeholder (point)) 1432 placeholder (point))
1119 (or (and (string-equal keyword "namespace") 1433 (or (and (string-equal keyword "namespace")
1120 (setq tmpsymbol 'namespace-open)) 1434 (setq tmpsymbol 'namespace-open))
1121 (and (string-equal keyword "extern") 1435 (and (string-equal keyword "extern")
1122 (progn 1436 (progn
1123 (forward-sexp 1) 1437 (c-forward-sexp 1)
1124 (c-forward-syntactic-ws) 1438 (c-forward-syntactic-ws)
1125 (eq (char-after) ?\")) 1439 (eq (char-after) ?\"))
1126 (setq tmpsymbol 'extern-lang-open))) 1440 (setq tmpsymbol 'extern-lang-open)))
@@ -1155,25 +1469,28 @@
1155 (and (bobp) 1469 (and (bobp)
1156 (c-forward-syntactic-ws indent-point)) 1470 (c-forward-syntactic-ws indent-point))
1157 (if (looking-at "typedef[^_]") 1471 (if (looking-at "typedef[^_]")
1158 (progn (forward-sexp 1) 1472 (progn (c-forward-sexp 1)
1159 (c-forward-syntactic-ws indent-point))) 1473 (c-forward-syntactic-ws indent-point)))
1160 (setq placeholder (c-point 'boi)) 1474 (setq placeholder (c-point 'boi))
1161 (and (or (looking-at "enum[ \t\n]+") 1475 (or (consp special-brace-list)
1476 (and (or (looking-at "enum[ \t\n]+")
1477 (save-excursion
1478 (goto-char indent-point)
1479 (while (and (> (point) placeholder)
1480 (= (c-backward-token-1 1 t) 0)
1481 (/= (char-after) ?=)))
1482 (eq (char-after) ?=)))
1162 (save-excursion 1483 (save-excursion
1163 (goto-char indent-point) 1484 (while (and (< (point) indent-point)
1164 (while (and (> (point) placeholder) 1485 (= (c-forward-token-1 1 t) 0)
1165 (= (c-backward-token-1 1 t) 0) 1486 (not (memq (char-after) '(?\; ?\()))))
1166 (/= (char-after) ?=))) 1487 (not (memq (char-after) '(?\; ?\()))
1167 (eq (char-after) ?=))) 1488 ))))
1168 (save-excursion
1169 (skip-chars-forward "^;(" indent-point)
1170 (not (memq (char-after) '(?\; ?\()))
1171 )))
1172 (c-add-syntax 'brace-list-open placeholder)) 1489 (c-add-syntax 'brace-list-open placeholder))
1173 ;; CASE 5A.4: inline defun open 1490 ;; CASE 5A.4: inline defun open
1174 ((and inclass-p (not inenclosing-p)) 1491 ((and inclass-p (not inenclosing-p))
1175 (c-add-syntax 'inline-open) 1492 (c-add-syntax 'inline-open)
1176 (c-add-syntax 'inclass (aref inclass-p 0))) 1493 (c-add-class-syntax 'inclass inclass-p))
1177 ;; CASE 5A.5: ordinary defun open 1494 ;; CASE 5A.5: ordinary defun open
1178 (t 1495 (t
1179 (goto-char placeholder) 1496 (goto-char placeholder)
@@ -1199,12 +1516,12 @@
1199 (progn (forward-char -1) 1516 (progn (forward-char -1)
1200 (c-backward-syntactic-ws lim))) 1517 (c-backward-syntactic-ws lim)))
1201 (if (eq (char-before) ?\)) 1518 (if (eq (char-before) ?\))
1202 (backward-sexp 1)) 1519 (c-backward-sexp 1))
1203 (setq placeholder (point)) 1520 (setq placeholder (point))
1204 (save-excursion 1521 (save-excursion
1205 (and (c-safe (backward-sexp 1) t) 1522 (and (c-safe (c-backward-sexp 1) t)
1206 (looking-at "throw[^_]") 1523 (looking-at "throw[^_]")
1207 (c-safe (backward-sexp 1) t) 1524 (c-safe (c-backward-sexp 1) t)
1208 (setq placeholder (point)))) 1525 (setq placeholder (point))))
1209 (goto-char placeholder) 1526 (goto-char placeholder)
1210 (c-add-syntax 'member-init-intro (c-point 'boi)) 1527 (c-add-syntax 'member-init-intro (c-point 'boi))
@@ -1214,7 +1531,7 @@
1214 ;; CASE 5B.2: K&R arg decl intro 1531 ;; CASE 5B.2: K&R arg decl intro
1215 (c-recognize-knr-p 1532 (c-recognize-knr-p
1216 (c-add-syntax 'knr-argdecl-intro (c-point 'boi)) 1533 (c-add-syntax 'knr-argdecl-intro (c-point 'boi))
1217 (and inclass-p (c-add-syntax 'inclass (aref inclass-p 0)))) 1534 (if inclass-p (c-add-class-syntax 'inclass inclass-p)))
1218 ;; CASE 5B.3: Nether region after a C++ or Java func 1535 ;; CASE 5B.3: Nether region after a C++ or Java func
1219 ;; decl, which could include a `throws' declaration. 1536 ;; decl, which could include a `throws' declaration.
1220 (t 1537 (t
@@ -1240,7 +1557,7 @@
1240 (back-to-indentation) 1557 (back-to-indentation)
1241 (looking-at c-class-key))) 1558 (looking-at c-class-key)))
1242 ;; for Java 1559 ;; for Java
1243 (and (eq major-mode 'java-mode) 1560 (and (c-major-mode-is 'java-mode)
1244 (let ((fence (save-excursion 1561 (let ((fence (save-excursion
1245 (c-beginning-of-statement-1 lim) 1562 (c-beginning-of-statement-1 lim)
1246 (point))) 1563 (point)))
@@ -1250,7 +1567,7 @@
1250 (cond ((looking-at c-Java-special-key) 1567 (cond ((looking-at c-Java-special-key)
1251 (setq injava-inher (cons cont (point)) 1568 (setq injava-inher (cons cont (point))
1252 done t)) 1569 done t))
1253 ((or (not (c-safe (forward-sexp -1) t)) 1570 ((or (not (c-safe (c-forward-sexp -1) t))
1254 (<= (point) fence)) 1571 (<= (point) fence))
1255 (setq done t)) 1572 (setq done t))
1256 ) 1573 )
@@ -1270,7 +1587,7 @@
1270 ;; CASE 5C.2: hanging colon on an inher intro 1587 ;; CASE 5C.2: hanging colon on an inher intro
1271 ((eq char-before-ip ?:) 1588 ((eq char-before-ip ?:)
1272 (c-add-syntax 'inher-intro (c-point 'boi)) 1589 (c-add-syntax 'inher-intro (c-point 'boi))
1273 (and inclass-p (c-add-syntax 'inclass (aref inclass-p 0)))) 1590 (if inclass-p (c-add-class-syntax 'inclass inclass-p)))
1274 ;; CASE 5C.3: in a Java implements/extends 1591 ;; CASE 5C.3: in a Java implements/extends
1275 (injava-inher 1592 (injava-inher
1276 (let ((where (cdr injava-inher)) 1593 (let ((where (cdr injava-inher))
@@ -1305,21 +1622,36 @@
1305 (forward-char -1) 1622 (forward-char -1)
1306 (c-backward-syntactic-ws (c-point 'bol)) 1623 (c-backward-syntactic-ws (c-point 'bol))
1307 (if (eq (char-before) ?\)) 1624 (if (eq (char-before) ?\))
1308 (backward-sexp 1)) 1625 (c-backward-sexp 2)
1626 (c-backward-sexp 1))
1309 ;; now continue checking 1627 ;; now continue checking
1310 (beginning-of-line)
1311 (c-backward-syntactic-ws lim)) 1628 (c-backward-syntactic-ws lim))
1312 (cond 1629 (cond
1313 ;; CASE 5D.1: hanging member init colon, but watch out 1630 ;; CASE 5D.1: hanging member init colon, but watch out
1314 ;; for bogus matches on access specifiers inside classes. 1631 ;; for bogus matches on access specifiers inside classes.
1315 ((and (eq (char-before) ?:) 1632 ((and (save-excursion
1633 ;; There might be member inits on the first line too.
1634 (end-of-line)
1635 (while (and (> (point) lim)
1636 (eq (char-before) ?,)
1637 (= (c-backward-token-1 2 t lim) 0)
1638 (eq (char-after) ?\()
1639 (= (c-backward-token-1 1 t lim) 0))
1640 (c-backward-syntactic-ws lim))
1641 (setq placeholder (point))
1642 (c-backward-syntactic-ws lim)
1643 (eq (char-before) ?:))
1316 (save-excursion 1644 (save-excursion
1317 (forward-word -1) 1645 (goto-char placeholder)
1318 (not (looking-at c-access-key)))) 1646 (back-to-indentation)
1319 (goto-char indent-point) 1647 (and
1320 (c-backward-syntactic-ws lim) 1648 c-access-key
1321 (c-safe (backward-sexp 1)) 1649 (not (looking-at c-access-key))
1322 (c-add-syntax 'member-init-cont (c-point 'boi)) 1650 (not (looking-at c-class-key)))
1651 ))
1652 (goto-char placeholder)
1653 (c-forward-syntactic-ws)
1654 (c-add-syntax 'member-init-cont (point))
1323 ;; we do not need to add class offset since relative 1655 ;; we do not need to add class offset since relative
1324 ;; point is the member init above us 1656 ;; point is the member init above us
1325 ) 1657 )
@@ -1330,7 +1662,11 @@
1330 (skip-chars-forward " \t:") 1662 (skip-chars-forward " \t:")
1331 (c-add-syntax 'member-init-cont (point))) 1663 (c-add-syntax 'member-init-cont (point)))
1332 ;; CASE 5D.3: perhaps a multiple inheritance line? 1664 ;; CASE 5D.3: perhaps a multiple inheritance line?
1333 ((looking-at c-inher-key) 1665 ((save-excursion
1666 (c-beginning-of-statement-1 lim)
1667 (setq placeholder (point))
1668 (looking-at c-inher-key))
1669 (goto-char placeholder)
1334 (c-add-syntax 'inher-cont (c-point 'boi))) 1670 (c-add-syntax 'inher-cont (c-point 'boi)))
1335 ;; CASE 5D.4: perhaps a template list continuation? 1671 ;; CASE 5D.4: perhaps a template list continuation?
1336 ((save-excursion 1672 ((save-excursion
@@ -1338,9 +1674,12 @@
1338 (skip-chars-backward "^<" lim) 1674 (skip-chars-backward "^<" lim)
1339 ;; not sure if this is the right test, but it should 1675 ;; not sure if this is the right test, but it should
1340 ;; be fast and mostly accurate. 1676 ;; be fast and mostly accurate.
1677 (setq placeholder (point))
1341 (and (eq (char-before) ?<) 1678 (and (eq (char-before) ?<)
1342 (not (c-in-literal lim)))) 1679 (not (c-in-literal lim))))
1343 ;; we can probably indent it just like an arglist-cont 1680 ;; we can probably indent it just like an arglist-cont
1681 (goto-char placeholder)
1682 (c-beginning-of-statement-1 lim)
1344 (c-add-syntax 'template-args-cont (point))) 1683 (c-add-syntax 'template-args-cont (point)))
1345 ;; CASE 5D.5: perhaps a top-level statement-cont 1684 ;; CASE 5D.5: perhaps a top-level statement-cont
1346 (t 1685 (t
@@ -1358,7 +1697,7 @@
1358 c-access-key 1697 c-access-key
1359 (looking-at c-access-key)) 1698 (looking-at c-access-key))
1360 (c-add-syntax 'access-label (c-point 'bonl)) 1699 (c-add-syntax 'access-label (c-point 'bonl))
1361 (c-add-syntax 'inclass (aref inclass-p 0))) 1700 (c-add-class-syntax 'inclass inclass-p))
1362 ;; CASE 5F: extern-lang-close or namespace-close? 1701 ;; CASE 5F: extern-lang-close or namespace-close?
1363 ((and inenclosing-p 1702 ((and inenclosing-p
1364 (eq char-after-ip ?})) 1703 (eq char-after-ip ?}))
@@ -1374,16 +1713,10 @@
1374 (save-restriction 1713 (save-restriction
1375 (widen) 1714 (widen)
1376 (forward-char 1) 1715 (forward-char 1)
1377 (and 1716 (and (c-safe (progn (c-backward-sexp 1) t))
1378 (condition-case nil 1717 (= (point) (aref inclass-p 1))
1379 (progn (backward-sexp 1) t) 1718 ))))
1380 (error nil)) 1719 (c-add-class-syntax 'class-close inclass-p))
1381 (= (point) (aref inclass-p 1))
1382 ))))
1383 (save-restriction
1384 (widen)
1385 (goto-char (aref inclass-p 0))
1386 (c-add-syntax 'class-close (c-point 'boi))))
1387 ;; CASE 5H: we could be looking at subsequent knr-argdecls 1720 ;; CASE 5H: we could be looking at subsequent knr-argdecls
1388 ((and c-recognize-knr-p 1721 ((and c-recognize-knr-p
1389 ;; here we essentially use the hack that is used in 1722 ;; here we essentially use the hack that is used in
@@ -1405,13 +1738,13 @@
1405 (and (eq (char-before) ?\)) 1738 (and (eq (char-before) ?\))
1406 (or (not c-method-key) 1739 (or (not c-method-key)
1407 (progn 1740 (progn
1408 (forward-sexp -1) 1741 (c-forward-sexp -1)
1409 (forward-char -1) 1742 (forward-char -1)
1410 (c-backward-syntactic-ws) 1743 (c-backward-syntactic-ws)
1411 (not (or (memq (char-before) '(?- ?+)) 1744 (not (or (memq (char-before) '(?- ?+))
1412 ;; or a class category 1745 ;; or a class category
1413 (progn 1746 (progn
1414 (forward-sexp -2) 1747 (c-forward-sexp -2)
1415 (looking-at c-class-key)) 1748 (looking-at c-class-key))
1416 ))))) 1749 )))))
1417 )) 1750 ))
@@ -1428,9 +1761,9 @@
1428 c-access-key 1761 c-access-key
1429 (not (bobp)) 1762 (not (bobp))
1430 (save-excursion 1763 (save-excursion
1431 (c-safe (progn (backward-sexp 1) t)) 1764 (c-safe (progn (c-backward-sexp 1) t))
1432 (looking-at c-access-key))) 1765 (looking-at c-access-key)))
1433 (backward-sexp 1) 1766 (c-backward-sexp 1)
1434 (c-backward-syntactic-ws lim)) 1767 (c-backward-syntactic-ws lim))
1435 (or (bobp) 1768 (or (bobp)
1436 (memq (char-before) '(?\; ?\})))) 1769 (memq (char-before) '(?\; ?\}))))
@@ -1449,7 +1782,7 @@
1449 (c-add-syntax 'inextern-lang (c-point 'boi))) 1782 (c-add-syntax 'inextern-lang (c-point 'boi)))
1450 ((eq inenclosing-p 'namespace) 1783 ((eq inenclosing-p 'namespace)
1451 (c-add-syntax 'innamespace (c-point 'boi))) 1784 (c-add-syntax 'innamespace (c-point 'boi)))
1452 (t (c-add-syntax 'inclass (c-point 'boi)))) 1785 (t (c-add-class-syntax 'inclass inclass-p)))
1453 )) 1786 ))
1454 )) 1787 ))
1455 ;; CASE 5J: we are at an ObjC or Java method definition 1788 ;; CASE 5J: we are at an ObjC or Java method definition
@@ -1466,28 +1799,66 @@
1466 (c-forward-syntactic-ws) 1799 (c-forward-syntactic-ws)
1467 (c-add-syntax 'topmost-intro-cont (c-point 'boi))) 1800 (c-add-syntax 'topmost-intro-cont (c-point 'boi)))
1468 )) ; end CASE 5 1801 )) ; end CASE 5
1469 ;; CASE 6: line is an expression, not a statement. Most 1802 ;; CASE 6: In-expression statement.
1803 ((and (or c-inexpr-class-key c-inexpr-block-key c-lambda-key)
1804 (setq placeholder (c-looking-at-inexpr-block)))
1805 (setq tmpsymbol (assq (car placeholder)
1806 '((inexpr-class . class-open)
1807 (inexpr-statement . block-open))))
1808 (if tmpsymbol
1809 ;; It's a statement block or an anonymous class.
1810 (setq tmpsymbol (cdr tmpsymbol))
1811 ;; It's a Pike lambda. Check whether we are between the
1812 ;; lambda keyword and the argument list or at the defun
1813 ;; opener.
1814 (setq tmpsymbol
1815 (if (save-excursion
1816 (and (c-safe (c-forward-sexp -1) t)
1817 (looking-at c-lambda-key)))
1818 'lambda-intro-cont
1819 'inline-open)))
1820 (goto-char (cdr placeholder))
1821 (c-add-syntax tmpsymbol (c-point 'boi))
1822 (c-add-syntax (car placeholder)))
1823 ;; CASE 7: line is an expression, not a statement. Most
1470 ;; likely we are either in a function prototype or a function 1824 ;; likely we are either in a function prototype or a function
1471 ;; call argument list 1825 ;; call argument list
1472 ((not (eq (char-after containing-sexp) ?{)) 1826 ((not (or (and c-special-brace-lists
1827 (save-excursion
1828 (goto-char containing-sexp)
1829 (c-looking-at-special-brace-list)))
1830 (eq (char-after containing-sexp) ?{)))
1473 (c-backward-syntactic-ws containing-sexp) 1831 (c-backward-syntactic-ws containing-sexp)
1474 (cond 1832 (cond
1475 ;; CASE 6A: we are looking at the arglist closing paren 1833 ;; CASE 7A: we are looking at the arglist closing paren
1476 ((and (not (eq char-before-ip ?,)) 1834 ((and (not (eq char-before-ip ?,))
1477 (memq char-after-ip '(?\) ?\]))) 1835 (memq char-after-ip '(?\) ?\])))
1478 (goto-char containing-sexp) 1836 (goto-char containing-sexp)
1479 (c-add-syntax 'arglist-close (c-point 'boi))) 1837 (c-add-syntax 'arglist-close (c-point 'boi)))
1480 ;; CASE 6B: we are looking at the first argument in an empty 1838 ;; CASE 7B: Looking at the opening brace of an
1839 ;; in-expression block or brace list.
1840 ((eq char-after-ip ?{)
1841 (goto-char indent-point)
1842 (setq placeholder (c-point 'boi))
1843 (goto-char containing-sexp)
1844 (if (c-inside-bracelist-p placeholder
1845 (cons containing-sexp state))
1846 (progn
1847 (c-add-syntax 'brace-list-open (c-point 'boi))
1848 (c-add-syntax 'inexpr-class))
1849 (c-add-syntax 'block-open (c-point 'boi))
1850 (c-add-syntax 'inexpr-statement)))
1851 ;; CASE 7C: we are looking at the first argument in an empty
1481 ;; argument list. Use arglist-close if we're actually 1852 ;; argument list. Use arglist-close if we're actually
1482 ;; looking at a close paren or bracket. 1853 ;; looking at a close paren or bracket.
1483 ((memq char-before-ip '(?\( ?\[)) 1854 ((memq char-before-ip '(?\( ?\[))
1484 (goto-char containing-sexp) 1855 (goto-char containing-sexp)
1485 (c-add-syntax 'arglist-intro (c-point 'boi))) 1856 (c-add-syntax 'arglist-intro (c-point 'boi)))
1486 ;; CASE 6C: we are inside a conditional test clause. treat 1857 ;; CASE 7D: we are inside a conditional test clause. treat
1487 ;; these things as statements 1858 ;; these things as statements
1488 ((save-excursion 1859 ((save-excursion
1489 (goto-char containing-sexp) 1860 (goto-char containing-sexp)
1490 (and (c-safe (progn (forward-sexp -1) t)) 1861 (and (c-safe (progn (c-forward-sexp -1) t))
1491 (looking-at "\\<for\\>[^_]"))) 1862 (looking-at "\\<for\\>[^_]")))
1492 (goto-char (1+ containing-sexp)) 1863 (goto-char (1+ containing-sexp))
1493 (c-forward-syntactic-ws indent-point) 1864 (c-forward-syntactic-ws indent-point)
@@ -1496,7 +1867,7 @@
1496 (c-add-syntax 'statement (point)) 1867 (c-add-syntax 'statement (point))
1497 (c-add-syntax 'statement-cont (point)) 1868 (c-add-syntax 'statement-cont (point))
1498 )) 1869 ))
1499 ;; CASE 6D: maybe a continued method call. This is the case 1870 ;; CASE 7E: maybe a continued method call. This is the case
1500 ;; when we are inside a [] bracketed exp, and what precede 1871 ;; when we are inside a [] bracketed exp, and what precede
1501 ;; the opening bracket is not an identifier. 1872 ;; the opening bracket is not an identifier.
1502 ((and c-method-key 1873 ((and c-method-key
@@ -1507,7 +1878,7 @@
1507 (if (not (looking-at c-symbol-key)) 1878 (if (not (looking-at c-symbol-key))
1508 (c-add-syntax 'objc-method-call-cont containing-sexp)) 1879 (c-add-syntax 'objc-method-call-cont containing-sexp))
1509 ))) 1880 )))
1510 ;; CASE 6E: we are looking at an arglist continuation line, 1881 ;; CASE 7F: we are looking at an arglist continuation line,
1511 ;; but the preceding argument is on the same line as the 1882 ;; but the preceding argument is on the same line as the
1512 ;; opening paren. This case includes multi-line 1883 ;; opening paren. This case includes multi-line
1513 ;; mathematical paren groupings, but we could be on a 1884 ;; mathematical paren groupings, but we could be on a
@@ -1522,14 +1893,14 @@
1522 (<= (point) containing-sexp))) 1893 (<= (point) containing-sexp)))
1523 (goto-char containing-sexp) 1894 (goto-char containing-sexp)
1524 (c-add-syntax 'arglist-cont-nonempty (c-point 'boi))) 1895 (c-add-syntax 'arglist-cont-nonempty (c-point 'boi)))
1525 ;; CASE 6F: we are looking at just a normal arglist 1896 ;; CASE 7G: we are looking at just a normal arglist
1526 ;; continuation line 1897 ;; continuation line
1527 (t (c-beginning-of-statement-1 containing-sexp) 1898 (t (c-beginning-of-statement-1 containing-sexp)
1528 (forward-char 1) 1899 (forward-char 1)
1529 (c-forward-syntactic-ws indent-point) 1900 (c-forward-syntactic-ws indent-point)
1530 (c-add-syntax 'arglist-cont (c-point 'boi))) 1901 (c-add-syntax 'arglist-cont (c-point 'boi)))
1531 )) 1902 ))
1532 ;; CASE 7: func-local multi-inheritance line 1903 ;; CASE 8: func-local multi-inheritance line
1533 ((and c-baseclass-key 1904 ((and c-baseclass-key
1534 (save-excursion 1905 (save-excursion
1535 (goto-char indent-point) 1906 (goto-char indent-point)
@@ -1538,50 +1909,96 @@
1538 (goto-char indent-point) 1909 (goto-char indent-point)
1539 (skip-chars-forward " \t") 1910 (skip-chars-forward " \t")
1540 (cond 1911 (cond
1541 ;; CASE 7A: non-hanging colon on an inher intro 1912 ;; CASE 8A: non-hanging colon on an inher intro
1542 ((eq char-after-ip ?:) 1913 ((eq char-after-ip ?:)
1543 (c-backward-syntactic-ws lim) 1914 (c-backward-syntactic-ws lim)
1544 (c-add-syntax 'inher-intro (c-point 'boi))) 1915 (c-add-syntax 'inher-intro (c-point 'boi)))
1545 ;; CASE 7B: hanging colon on an inher intro 1916 ;; CASE 8B: hanging colon on an inher intro
1546 ((eq char-before-ip ?:) 1917 ((eq char-before-ip ?:)
1547 (c-add-syntax 'inher-intro (c-point 'boi))) 1918 (c-add-syntax 'inher-intro (c-point 'boi)))
1548 ;; CASE 7C: a continued inheritance line 1919 ;; CASE 8C: a continued inheritance line
1549 (t 1920 (t
1550 (c-beginning-of-inheritance-list lim) 1921 (c-beginning-of-inheritance-list lim)
1551 (c-add-syntax 'inher-cont (point)) 1922 (c-add-syntax 'inher-cont (point))
1552 ))) 1923 )))
1553 ;; CASE 8: we are inside a brace-list 1924 ;; CASE 9: we are inside a brace-list
1554 ((setq placeholder (c-inside-bracelist-p containing-sexp state)) 1925 ((setq special-brace-list
1926 (or (and c-special-brace-lists
1927 (save-excursion
1928 (goto-char containing-sexp)
1929 (c-looking-at-special-brace-list)))
1930 (c-inside-bracelist-p containing-sexp state)))
1555 (cond 1931 (cond
1556 ;; CASE 8A: brace-list-close brace 1932 ;; CASE 9A: In the middle of a special brace list opener.
1557 ((and (eq char-after-ip ?}) 1933 ((and (consp special-brace-list)
1558 (c-safe (progn (forward-char 1) 1934 (eq char-after-ip (car (cdr special-brace-list))))
1559 (backward-sexp 1) 1935 (goto-char (car (car special-brace-list)))
1560 t)) 1936 (c-beginning-of-statement-1 lim)
1561 (= (point) containing-sexp)) 1937 (c-forward-token-1 0)
1938 (if (looking-at "typedef\\>") (c-forward-token-1 1))
1939 (c-add-syntax 'brace-list-open (c-point 'boi)))
1940 ;; CASE 9B: brace-list-close brace
1941 ((if (consp special-brace-list)
1942 ;; Check special brace list closer.
1943 (progn
1944 (goto-char (car (car special-brace-list)))
1945 (save-excursion
1946 (goto-char indent-point)
1947 (back-to-indentation)
1948 (or
1949 ;; We were between the special close char and the `)'.
1950 (and (eq (char-after) ?\))
1951 (eq (1+ (point)) (cdr (car special-brace-list))))
1952 ;; We were before the special close char.
1953 (and (eq (char-after) (cdr (cdr special-brace-list)))
1954 (= (c-forward-token-1) 0)
1955 (eq (1+ (point)) (cdr (car special-brace-list)))))))
1956 ;; Normal brace list check.
1957 (and (eq char-after-ip ?})
1958 (c-safe (progn (forward-char 1)
1959 (c-backward-sexp 1)
1960 t))
1961 (= (point) containing-sexp)))
1562 (c-add-syntax 'brace-list-close (c-point 'boi))) 1962 (c-add-syntax 'brace-list-close (c-point 'boi)))
1563 ;; CASE 8B: we're looking at the first line in a brace-list 1963 (t
1564 ((save-excursion 1964 ;; Prepare for the rest of the cases below by going to the
1565 (goto-char indent-point) 1965 ;; token following the opening brace
1566 (c-backward-syntactic-ws containing-sexp) 1966 (if (consp special-brace-list)
1567 (= (point) (1+ containing-sexp))) 1967 (progn
1568 (goto-char containing-sexp) 1968 (goto-char (car (car special-brace-list)))
1569 (c-add-syntax 'brace-list-intro (c-point 'boi)) 1969 (c-forward-token-1 1 nil indent-point))
1570 ) 1970 (goto-char containing-sexp))
1571 ;;)) ; end CASE 8B 1971 (forward-char)
1572 ;; CASE 8C: this is just a later brace-list-entry 1972 (let ((start (point)))
1573 (t (goto-char (1+ containing-sexp))
1574 (c-forward-syntactic-ws indent-point) 1973 (c-forward-syntactic-ws indent-point)
1575 (if (eq char-after-ip ?{) 1974 (goto-char (max start (c-point 'bol))))
1576 (c-add-syntax 'brace-list-open (point)) 1975 (skip-chars-forward " \t\n\r" indent-point)
1577 (c-add-syntax 'brace-list-entry (point)) 1976 (cond
1578 )) ; end CASE 8C 1977 ;; CASE 9C: we're looking at the first line in a brace-list
1579 )) ; end CASE 8 1978 ((= (point) indent-point)
1580 ;; CASE 9: A continued statement 1979 (goto-char containing-sexp)
1581 ((and (not (memq char-before-ip '(?\; ?} ?:))) 1980 (c-add-syntax 'brace-list-intro (c-point 'boi))
1981 ) ; end CASE 9C
1982 ;; CASE 9D: this is just a later brace-list-entry or
1983 ;; brace-entry-open
1984 (t (if (or (eq char-after-ip ?{)
1985 (and c-special-brace-lists
1986 (save-excursion
1987 (goto-char indent-point)
1988 (c-forward-syntactic-ws (c-point 'eol))
1989 (c-looking-at-special-brace-list (point)))))
1990 (c-add-syntax 'brace-entry-open (point))
1991 (c-add-syntax 'brace-list-entry (point))
1992 )) ; end CASE 9D
1993 )))) ; end CASE 9
1994 ;; CASE 10: A continued statement
1995 ((and (not (memq char-before-ip '(?\; ?:)))
1996 (or (not (eq char-before-ip ?}))
1997 (c-looking-at-inexpr-block-backward containing-sexp))
1582 (> (point) 1998 (> (point)
1583 (save-excursion 1999 (save-excursion
1584 (c-beginning-of-statement-1 containing-sexp) 2000 (c-beginning-of-statement-1 containing-sexp)
2001 (c-forward-syntactic-ws)
1585 (setq placeholder (point)))) 2002 (setq placeholder (point))))
1586 (/= placeholder containing-sexp)) 2003 (/= placeholder containing-sexp))
1587 (goto-char indent-point) 2004 (goto-char indent-point)
@@ -1600,17 +2017,20 @@
1600 (point)) 2017 (point))
1601 nil)))) 2018 nil))))
1602 (cond 2019 (cond
1603 ;; CASE 9A: substatement 2020 ;; CASE 10A: substatement
1604 ((and after-cond-placeholder 2021 ((and after-cond-placeholder
1605 (>= after-cond-placeholder indent-point)) 2022 (>= after-cond-placeholder indent-point))
1606 (goto-char placeholder) 2023 (goto-char placeholder)
1607 (if (eq char-after-ip ?{) 2024 (if (eq char-after-ip ?{)
1608 (c-add-syntax 'substatement-open (c-point 'boi)) 2025 (c-add-syntax 'substatement-open (c-point 'boi))
1609 (c-add-syntax 'substatement (c-point 'boi)))) 2026 (c-add-syntax 'substatement (c-point 'boi))))
1610 ;; CASE 9B: open braces for class or brace-lists 2027 ;; CASE 10B: open braces for class or brace-lists
1611 ((eq char-after-ip ?{) 2028 ((setq special-brace-list
2029 (or (and c-special-brace-lists
2030 (c-looking-at-special-brace-list))
2031 (eq char-after-ip ?{)))
1612 (cond 2032 (cond
1613 ;; CASE 9B.1: class-open 2033 ;; CASE 10B.1: class-open
1614 ((save-excursion 2034 ((save-excursion
1615 (goto-char indent-point) 2035 (goto-char indent-point)
1616 (skip-chars-forward " \t{") 2036 (skip-chars-forward " \t{")
@@ -1619,8 +2039,9 @@
1619 (setq placeholder (aref decl 0))) 2039 (setq placeholder (aref decl 0)))
1620 )) 2040 ))
1621 (c-add-syntax 'class-open placeholder)) 2041 (c-add-syntax 'class-open placeholder))
1622 ;; CASE 9B.2: brace-list-open 2042 ;; CASE 10B.2: brace-list-open
1623 ((or (save-excursion 2043 ((or (consp special-brace-list)
2044 (save-excursion
1624 (goto-char placeholder) 2045 (goto-char placeholder)
1625 (looking-at "\\<enum\\>")) 2046 (looking-at "\\<enum\\>"))
1626 (save-excursion 2047 (save-excursion
@@ -1630,7 +2051,7 @@
1630 (/= (char-after) ?=))) 2051 (/= (char-after) ?=)))
1631 (eq (char-after) ?=))) 2052 (eq (char-after) ?=)))
1632 (c-add-syntax 'brace-list-open placeholder)) 2053 (c-add-syntax 'brace-list-open placeholder))
1633 ;; CASE 9B.3: catch-all for unknown construct. 2054 ;; CASE 10B.3: catch-all for unknown construct.
1634 (t 2055 (t
1635 ;; Can and should I add an extensibility hook here? 2056 ;; Can and should I add an extensibility hook here?
1636 ;; Something like c-recognize-hook so support for 2057 ;; Something like c-recognize-hook so support for
@@ -1640,7 +2061,7 @@
1640 (c-add-syntax 'statement-cont (c-point 'boi)) 2061 (c-add-syntax 'statement-cont (c-point 'boi))
1641 (c-add-syntax 'block-open)) 2062 (c-add-syntax 'block-open))
1642 )) 2063 ))
1643 ;; CASE 9C: iostream insertion or extraction operator 2064 ;; CASE 10C: iostream insertion or extraction operator
1644 ((looking-at "<<\\|>>") 2065 ((looking-at "<<\\|>>")
1645 (goto-char placeholder) 2066 (goto-char placeholder)
1646 (and after-cond-placeholder 2067 (and after-cond-placeholder
@@ -1654,7 +2075,7 @@
1654 (c-add-syntax 'stream-op (c-point 'boi)) 2075 (c-add-syntax 'stream-op (c-point 'boi))
1655 (c-backward-syntactic-ws lim) 2076 (c-backward-syntactic-ws lim)
1656 (c-add-syntax 'statement-cont (c-point 'boi)))) 2077 (c-add-syntax 'statement-cont (c-point 'boi))))
1657 ;; CASE 9D: continued statement. find the accurate 2078 ;; CASE 10D: continued statement. find the accurate
1658 ;; beginning of statement or substatement 2079 ;; beginning of statement or substatement
1659 (t 2080 (t
1660 (c-beginning-of-statement-1 after-cond-placeholder) 2081 (c-beginning-of-statement-1 after-cond-placeholder)
@@ -1667,11 +2088,11 @@
1667 (point))) 2088 (point)))
1668 (c-add-syntax 'statement-cont (point))) 2089 (c-add-syntax 'statement-cont (point)))
1669 ))) 2090 )))
1670 ;; CASE 10: an else clause? 2091 ;; CASE 11: an else clause?
1671 ((looking-at "\\<else\\>[^_]") 2092 ((looking-at "\\<else\\>[^_]")
1672 (c-backward-to-start-of-if containing-sexp) 2093 (c-backward-to-start-of-if containing-sexp)
1673 (c-add-syntax 'else-clause (c-point 'boi))) 2094 (c-add-syntax 'else-clause (c-point 'boi)))
1674 ;; CASE 11: Statement. But what kind? Lets see if its a 2095 ;; CASE 12: Statement. But what kind? Lets see if its a
1675 ;; while closure of a do/while construct 2096 ;; while closure of a do/while construct
1676 ((progn 2097 ((progn
1677 (goto-char indent-point) 2098 (goto-char indent-point)
@@ -1683,18 +2104,38 @@
1683 (looking-at "do\\b[^_]")) 2104 (looking-at "do\\b[^_]"))
1684 )) 2105 ))
1685 (c-add-syntax 'do-while-closure placeholder)) 2106 (c-add-syntax 'do-while-closure placeholder))
1686 ;; CASE 12: A case or default label 2107 ;; CASE 13: A catch or finally clause? This case is simpler
2108 ;; than if-else and do-while, because a block is required
2109 ;; after every try, catch and finally.
2110 ((save-excursion
2111 (and (cond ((c-major-mode-is 'c++-mode)
2112 (looking-at "\\<catch\\>[^_]"))
2113 ((c-major-mode-is 'java-mode)
2114 (looking-at "\\<\\(catch\\|finally\\)\\>[^_]")))
2115 (c-safe (c-backward-sexp) t)
2116 (eq (char-after) ?{)
2117 (c-safe (c-backward-sexp) t)
2118 (if (eq (char-after) ?\()
2119 (c-safe (c-backward-sexp) t)
2120 t)
2121 (looking-at "\\<\\(try\\|catch\\)\\>[^_]")
2122 (setq placeholder (c-point 'boi))))
2123 (c-add-syntax 'catch-clause placeholder))
2124 ;; CASE 14: A case or default label
1687 ((looking-at c-switch-label-key) 2125 ((looking-at c-switch-label-key)
1688 (goto-char containing-sexp) 2126 (goto-char containing-sexp)
1689 ;; check for hanging braces 2127 ;; check for hanging braces
1690 (if (/= (point) (c-point 'boi)) 2128 (if (/= (point) (c-point 'boi))
1691 (forward-sexp -1)) 2129 (c-forward-sexp -1))
1692 (c-add-syntax 'case-label (c-point 'boi))) 2130 (c-add-syntax 'case-label (c-point 'boi)))
1693 ;; CASE 13: any other label 2131 ;; CASE 15: any other label
1694 ((looking-at c-label-key) 2132 ((looking-at c-label-key)
1695 (goto-char containing-sexp) 2133 (goto-char containing-sexp)
2134 ;; check for hanging braces
2135 (if (/= (point) (c-point 'boi))
2136 (c-forward-sexp -1))
1696 (c-add-syntax 'label (c-point 'boi))) 2137 (c-add-syntax 'label (c-point 'boi)))
1697 ;; CASE 14: block close brace, possibly closing the defun or 2138 ;; CASE 16: block close brace, possibly closing the defun or
1698 ;; the class 2139 ;; the class
1699 ((eq char-after-ip ?}) 2140 ((eq char-after-ip ?})
1700 (let* ((lim (c-safe-position containing-sexp fullstate)) 2141 (let* ((lim (c-safe-position containing-sexp fullstate))
@@ -1704,32 +2145,47 @@
1704 (c-beginning-of-statement-1 lim)) 2145 (c-beginning-of-statement-1 lim))
1705 (c-point 'boi)))) 2146 (c-point 'boi))))
1706 (cond 2147 (cond
1707 ;; CASE 14A: does this close an inline or a function in 2148 ;; CASE 16A: closing a lambda defun or an in-expression
2149 ;; block?
2150 ((save-excursion
2151 (goto-char containing-sexp)
2152 (setq placeholder (c-looking-at-inexpr-block)))
2153 (setq tmpsymbol (if (eq (car placeholder) 'inlambda)
2154 'inline-close
2155 'block-close))
2156 (goto-char containing-sexp)
2157 (back-to-indentation)
2158 (if (= containing-sexp (point))
2159 (c-add-syntax tmpsymbol (point))
2160 (goto-char (cdr placeholder))
2161 (c-add-syntax tmpsymbol (c-point 'boi))
2162 (c-add-syntax (car placeholder))))
2163 ;; CASE 16B: does this close an inline or a function in
1708 ;; an extern block or namespace? 2164 ;; an extern block or namespace?
1709 ((progn 2165 ((progn
1710 (goto-char containing-sexp) 2166 (goto-char containing-sexp)
1711 (setq placeholder (c-search-uplist-for-classkey state))) 2167 (setq placeholder (c-search-uplist-for-classkey state)))
1712 (goto-char (aref placeholder 0)) 2168 (goto-char (aref placeholder 0))
1713 (if (looking-at c-extra-toplevel-key) 2169 (if (looking-at (concat c-extra-toplevel-key "[^_]"))
1714 (c-add-syntax 'defun-close relpos) 2170 (c-add-syntax 'defun-close relpos)
1715 (c-add-syntax 'inline-close relpos))) 2171 (c-add-syntax 'inline-close relpos)))
1716 ;; CASE 14B: if there an enclosing brace that hasn't 2172 ;; CASE 16C: if there an enclosing brace that hasn't
1717 ;; been narrowed out by a class, then this is a 2173 ;; been narrowed out by a class, then this is a
1718 ;; block-close 2174 ;; block-close
1719 ((and (not inenclosing-p) 2175 ((and (not inenclosing-p)
1720 (c-most-enclosing-brace state)) 2176 (c-most-enclosing-brace state))
1721 (c-add-syntax 'block-close relpos)) 2177 (c-add-syntax 'block-close relpos))
1722 ;; CASE 14C: find out whether we're closing a top-level 2178 ;; CASE 16D: find out whether we're closing a top-level
1723 ;; class or a defun 2179 ;; class or a defun
1724 (t 2180 (t
1725 (save-restriction 2181 (save-restriction
1726 (narrow-to-region (point-min) indent-point) 2182 (narrow-to-region (point-min) indent-point)
1727 (let ((decl (c-search-uplist-for-classkey (c-parse-state)))) 2183 (let ((decl (c-search-uplist-for-classkey (c-parse-state))))
1728 (if decl 2184 (if decl
1729 (c-add-syntax 'class-close (aref decl 0)) 2185 (c-add-class-syntax 'class-close decl)
1730 (c-add-syntax 'defun-close relpos))))) 2186 (c-add-syntax 'defun-close relpos)))))
1731 ))) 2187 )))
1732 ;; CASE 15: statement catchall 2188 ;; CASE 17: statement catchall
1733 (t 2189 (t
1734 ;; we know its a statement, but we need to find out if it is 2190 ;; we know its a statement, but we need to find out if it is
1735 ;; the first statement in a block 2191 ;; the first statement in a block
@@ -1746,7 +2202,7 @@
1746 (goto-char (match-end 0))) 2202 (goto-char (match-end 0)))
1747 (c-forward-syntactic-ws indent-point)) 2203 (c-forward-syntactic-ws indent-point))
1748 (cond 2204 (cond
1749 ;; CASE 15A: we are inside a case/default clause inside a 2205 ;; CASE 17A: we are inside a case/default clause inside a
1750 ;; switch statement. find out if we are at the statement 2206 ;; switch statement. find out if we are at the statement
1751 ;; just after the case/default label. 2207 ;; just after the case/default label.
1752 ((and inswitch-p 2208 ((and inswitch-p
@@ -1761,10 +2217,10 @@
1761 (if (eq (char-after) ?{) 2217 (if (eq (char-after) ?{)
1762 (c-add-syntax 'statement-case-open placeholder) 2218 (c-add-syntax 'statement-case-open placeholder)
1763 (c-add-syntax 'statement-case-intro placeholder))) 2219 (c-add-syntax 'statement-case-intro placeholder)))
1764 ;; CASE 15B: continued statement 2220 ;; CASE 17B: continued statement
1765 ((eq char-before-ip ?,) 2221 ((eq char-before-ip ?,)
1766 (c-add-syntax 'statement-cont (c-point 'boi))) 2222 (c-add-syntax 'statement-cont (c-point 'boi)))
1767 ;; CASE 15C: a question/colon construct? But make sure 2223 ;; CASE 17C: a question/colon construct? But make sure
1768 ;; what came before was not a label, and what comes after 2224 ;; what came before was not a label, and what comes after
1769 ;; is not a globally scoped function call! 2225 ;; is not a globally scoped function call!
1770 ((or (and (memq char-before-ip '(?: ??)) 2226 ((or (and (memq char-before-ip '(?: ??))
@@ -1780,7 +2236,7 @@
1780 ;; watch out for scope operator 2236 ;; watch out for scope operator
1781 (not (looking-at "::"))))) 2237 (not (looking-at "::")))))
1782 (c-add-syntax 'statement-cont (c-point 'boi))) 2238 (c-add-syntax 'statement-cont (c-point 'boi)))
1783 ;; CASE 15D: any old statement 2239 ;; CASE 17D: any old statement
1784 ((< (point) indent-point) 2240 ((< (point) indent-point)
1785 (let ((safepos (c-most-enclosing-brace fullstate)) 2241 (let ((safepos (c-most-enclosing-brace fullstate))
1786 relpos done) 2242 relpos done)
@@ -1798,7 +2254,7 @@
1798 (progn 2254 (progn
1799 (goto-char placeholder) 2255 (goto-char placeholder)
1800 (end-of-line) 2256 (end-of-line)
1801 (forward-sexp -1))) 2257 (c-forward-sexp -1)))
1802 (setq relpos (c-point 'boi)) 2258 (setq relpos (c-point 'boi))
1803 (while (and (not done) 2259 (while (and (not done)
1804 (<= safepos (point)) 2260 (<= safepos (point))
@@ -1810,7 +2266,21 @@
1810 (c-add-syntax 'statement relpos) 2266 (c-add-syntax 'statement relpos)
1811 (if (eq char-after-ip ?{) 2267 (if (eq char-after-ip ?{)
1812 (c-add-syntax 'block-open)))) 2268 (c-add-syntax 'block-open))))
1813 ;; CASE 15E: first statement in an inline, or first 2269 ;; CASE 17E: first statement in an in-expression block
2270 ((setq placeholder
2271 (save-excursion
2272 (goto-char containing-sexp)
2273 (c-looking-at-inexpr-block)))
2274 (goto-char containing-sexp)
2275 (back-to-indentation)
2276 (if (= containing-sexp (point))
2277 (c-add-syntax 'statement-block-intro (point))
2278 (goto-char (cdr placeholder))
2279 (c-add-syntax 'statement-block-intro (c-point 'boi))
2280 (c-add-syntax (car placeholder)))
2281 (if (eq char-after-ip ?{)
2282 (c-add-syntax 'block-open)))
2283 ;; CASE 17F: first statement in an inline, or first
1814 ;; statement in a top-level defun. we can tell this is it 2284 ;; statement in a top-level defun. we can tell this is it
1815 ;; if there are no enclosing braces that haven't been 2285 ;; if there are no enclosing braces that haven't been
1816 ;; narrowed out by a class (i.e. don't use bod here!) 2286 ;; narrowed out by a class (i.e. don't use bod here!)
@@ -1826,14 +2296,14 @@
1826 (if (/= (point) (c-point 'boi)) 2296 (if (/= (point) (c-point 'boi))
1827 (progn 2297 (progn
1828 (c-backward-syntactic-ws) 2298 (c-backward-syntactic-ws)
1829 (c-safe (forward-sexp (if (eq (char-before) ?\)) 2299 (c-safe (c-forward-sexp (if (eq (char-before) ?\))
1830 -1 -2))) 2300 -1 -2)))
1831 ;; looking at a Java throws clause following a 2301 ;; looking at a Java throws clause following a
1832 ;; method's parameter list 2302 ;; method's parameter list
1833 (c-beginning-of-statement-1) 2303 (c-beginning-of-statement-1)
1834 )) 2304 ))
1835 (c-add-syntax 'defun-block-intro (c-point 'boi))) 2305 (c-add-syntax 'defun-block-intro (c-point 'boi)))
1836 ;; CASE 15F: first statement in a block 2306 ;; CASE 17G: first statement in a block
1837 (t (goto-char containing-sexp) 2307 (t (goto-char containing-sexp)
1838 (if (/= (point) (c-point 'boi)) 2308 (if (/= (point) (c-point 'boi))
1839 (c-beginning-of-statement-1 2309 (c-beginning-of-statement-1
@@ -1852,7 +2322,7 @@
1852 (if (looking-at c-comment-start-regexp) 2322 (if (looking-at c-comment-start-regexp)
1853 (c-add-syntax 'comment-intro)) 2323 (c-add-syntax 'comment-intro))
1854 ;; we might want to give additional offset to friends (in C++). 2324 ;; we might want to give additional offset to friends (in C++).
1855 (if (and (eq major-mode 'c++-mode) 2325 (if (and (c-major-mode-is 'c++-mode)
1856 (looking-at c-C++-friend-key)) 2326 (looking-at c-C++-friend-key))
1857 (c-add-syntax 'friend)) 2327 (c-add-syntax 'friend))
1858 ;; return the syntax 2328 ;; return the syntax
@@ -1871,7 +2341,7 @@
1871(defun c-indent-line (&optional syntax) 2341(defun c-indent-line (&optional syntax)
1872 ;; indent the current line as C/C++/ObjC code. Optional SYNTAX is the 2342 ;; indent the current line as C/C++/ObjC code. Optional SYNTAX is the
1873 ;; syntactic information for the current line. Returns the amount of 2343 ;; syntactic information for the current line. Returns the amount of
1874 ;; indentation change 2344 ;; indentation change (in columns).
1875 (let* ((c-syntactic-context (or syntax (c-guess-basic-syntax))) 2345 (let* ((c-syntactic-context (or syntax (c-guess-basic-syntax)))
1876 (pos (- (point-max) (point))) 2346 (pos (- (point-max) (point)))
1877 (indent (apply '+ (mapcar 'c-get-offset c-syntactic-context))) 2347 (indent (apply '+ (mapcar 'c-get-offset c-syntactic-context)))
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el
index 96fdf35948e..912e36446bb 100644
--- a/lisp/progmodes/cc-langs.el
+++ b/lisp/progmodes/cc-langs.el
@@ -2,10 +2,11 @@
2 2
3;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc. 3;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc.
4 4
5;; Authors: 1992-1997 Barry A. Warsaw 5;; Authors: 1998 Barry A. Warsaw and Martin Stjernholm
6;; 1992-1997 Barry A. Warsaw
6;; 1987 Dave Detlefs and Stewart Clamen 7;; 1987 Dave Detlefs and Stewart Clamen
7;; 1985 Richard M. Stallman 8;; 1985 Richard M. Stallman
8;; Maintainer: cc-mode-help@python.org 9;; Maintainer: bug-cc-mode@gnu.org
9;; Created: 22-Apr-1997 (split from cc-mode.el) 10;; Created: 22-Apr-1997 (split from cc-mode.el)
10;; Version: See cc-mode.el 11;; Version: See cc-mode.el
11;; Keywords: c languages oop 12;; Keywords: c languages oop
@@ -29,7 +30,8 @@
29 30
30 31
31 32
32(require 'cc-defs) 33(eval-when-compile
34 (require 'cc-defs))
33 35
34;; Regular expressions and other values which must be parameterized on 36;; Regular expressions and other values which must be parameterized on
35;; a per-language basis. 37;; a per-language basis.
@@ -54,8 +56,10 @@
54;; keywords introducing class definitions. language specific 56;; keywords introducing class definitions. language specific
55(defconst c-C-class-key "\\(struct\\|union\\)") 57(defconst c-C-class-key "\\(struct\\|union\\)")
56(defconst c-C++-class-key "\\(class\\|struct\\|union\\)") 58(defconst c-C++-class-key "\\(class\\|struct\\|union\\)")
57(defconst c-C-extra-toplevel-key "\\(extern\\)[^_]") 59(defconst c-IDL-class-key "\\(class\\|struct\\|union\\|interface\\)")
58(defconst c-C++-extra-toplevel-key "\\(extern\\|namespace\\)[^_]") 60(defconst c-C-extra-toplevel-key "\\(extern\\)")
61(defconst c-C++-extra-toplevel-key "\\(extern\\|namespace\\)")
62(defconst c-IDL-extra-toplevel-key "\\(module\\)")
59 63
60(defconst c-ObjC-class-key 64(defconst c-ObjC-class-key
61 (concat 65 (concat
@@ -70,10 +74,12 @@
70 "\\(" c-protection-key "\\s +\\)?" 74 "\\(" c-protection-key "\\s +\\)?"
71 "\\(interface\\|class\\)\\s +" 75 "\\(interface\\|class\\)\\s +"
72 c-symbol-key ;name of the class 76 c-symbol-key ;name of the class
73 "\\(\\s *extends\\s *" c-symbol-key "\\)?" ;maybe followed by superclass 77 "\\(\\s *extends\\s *" c-symbol-key "\\)?" ;maybe followed by superclass
74 ;;"\\(\\s *implements *[^{]+{\\)?" ;maybe the adopted protocols list 78 ;;"\\(\\s *implements *[^{]+{\\)?" ;maybe the adopted protocols list
75 )) 79 ))
76 80
81(defconst c-Pike-class-key "class")
82
77(defvar c-class-key c-C-class-key) 83(defvar c-class-key c-C-class-key)
78(make-variable-buffer-local 'c-class-key) 84(make-variable-buffer-local 'c-class-key)
79 85
@@ -87,12 +93,14 @@
87(defconst c-C++-access-key (concat c-protection-key "[ \t]*:")) 93(defconst c-C++-access-key (concat c-protection-key "[ \t]*:"))
88(defconst c-ObjC-access-key (concat "@" c-protection-key)) 94(defconst c-ObjC-access-key (concat "@" c-protection-key))
89(defconst c-Java-access-key nil) 95(defconst c-Java-access-key nil)
96(defconst c-Pike-access-key nil)
90 97
91 98
92;; keywords introducing conditional blocks 99;; keywords introducing conditional blocks
93(defconst c-C-conditional-key nil) 100(defconst c-C-conditional-key nil)
94(defconst c-C++-conditional-key nil) 101(defconst c-C++-conditional-key nil)
95(defconst c-Java-conditional-key nil) 102(defconst c-Java-conditional-key nil)
103(defconst c-Pike-conditional-key nil)
96 104
97(let ((all-kws "for\\|if\\|do\\|else\\|while\\|switch") 105(let ((all-kws "for\\|if\\|do\\|else\\|while\\|switch")
98 (exc-kws "\\|try\\|catch") 106 (exc-kws "\\|try\\|catch")
@@ -101,7 +109,8 @@
101 (back "\\)\\b[^_]")) 109 (back "\\)\\b[^_]"))
102 (setq c-C-conditional-key (concat front all-kws back) 110 (setq c-C-conditional-key (concat front all-kws back)
103 c-C++-conditional-key (concat front all-kws exc-kws back) 111 c-C++-conditional-key (concat front all-kws exc-kws back)
104 c-Java-conditional-key (concat front all-kws exc-kws thr-kws back))) 112 c-Java-conditional-key (concat front all-kws exc-kws thr-kws back)
113 c-Pike-conditional-key (concat front all-kws "\\|foreach" back)))
105 114
106(defvar c-conditional-key c-C-conditional-key) 115(defvar c-conditional-key c-C-conditional-key)
107(make-variable-buffer-local 'c-conditional-key) 116(make-variable-buffer-local 'c-conditional-key)
@@ -166,6 +175,30 @@
166(defconst c-Java-javadoc-paragraph-start 175(defconst c-Java-javadoc-paragraph-start
167 "@\\(author\\|exception\\|param\\|return\\|see\\|version\\)") 176 "@\\(author\\|exception\\|param\\|return\\|see\\|version\\)")
168 177
178;; Regexp that starts lambda constructs.
179(defvar c-lambda-key nil)
180(make-variable-buffer-local 'c-lambda-key)
181(defconst c-Pike-lambda-key "\\<lambda\\>")
182
183;; Regexp that are followed by a statement block in expressions.
184(defvar c-inexpr-block-key nil)
185(make-variable-buffer-local 'c-inexpr-block-key)
186(defconst c-Pike-inexpr-block-key "\\<\\(catch\\|gauge\\)\\>")
187
188;; Regexp that may be followed by an anonymous class in expressions.
189(defvar c-inexpr-class-key nil)
190(make-variable-buffer-local 'c-inexpr-class-key)
191(defconst c-Java-inexpr-class-key "\\<new\\>")
192
193;; List of open- and close-chars that makes up a pike-style brace
194;; list, ie for a `([ ])' list there should be a cons (?\[ . ?\]) in
195;; this list.
196(defvar c-special-brace-lists nil)
197(make-variable-buffer-local 'c-special-brace-lists)
198(defconst c-Pike-special-brace-lists '((?{ . ?})
199 (?\[ . ?\])
200 (?< . ?>)))
201
169 202
170 203
171;; internal state variables 204;; internal state variables
@@ -188,11 +221,6 @@
188 221
189 222
190 223
191(defun c-use-java-style ()
192 "Institutes `java' indentation style.
193For use with the variable `java-mode-hook'."
194 (c-set-style "java"))
195
196(defun c-common-init () 224(defun c-common-init ()
197 ;; Common initializations for all modes. 225 ;; Common initializations for all modes.
198 ;; these variables should always be buffer local; they do not affect 226 ;; these variables should always be buffer local; they do not affect
@@ -212,6 +240,7 @@ For use with the variable `java-mode-hook'."
212 (make-local-variable 'outline-regexp) 240 (make-local-variable 'outline-regexp)
213 (make-local-variable 'outline-level) 241 (make-local-variable 'outline-level)
214 (make-local-variable 'adaptive-fill-regexp) 242 (make-local-variable 'adaptive-fill-regexp)
243 (make-local-variable 'adaptive-fill-mode)
215 (make-local-variable 'imenu-generic-expression) ;set in the mode functions 244 (make-local-variable 'imenu-generic-expression) ;set in the mode functions
216 ;; X/Emacs 20 only 245 ;; X/Emacs 20 only
217 (and (boundp 'comment-line-break-function) 246 (and (boundp 'comment-line-break-function)
@@ -235,7 +264,8 @@ For use with the variable `java-mode-hook'."
235 comment-start-skip "/\\*+ *\\|// *" 264 comment-start-skip "/\\*+ *\\|// *"
236 comment-multi-line nil 265 comment-multi-line nil
237 comment-line-break-function 'c-comment-line-break-function 266 comment-line-break-function 'c-comment-line-break-function
238 adaptive-fill-regexp nil) 267 adaptive-fill-regexp nil
268 adaptive-fill-mode nil)
239 ;; we have to do something special for c-offsets-alist so that the 269 ;; we have to do something special for c-offsets-alist so that the
240 ;; buffer local value has its own alist structure. 270 ;; buffer local value has its own alist structure.
241 (setq c-offsets-alist (copy-alist c-offsets-alist)) 271 (setq c-offsets-alist (copy-alist c-offsets-alist))
@@ -249,7 +279,17 @@ For use with the variable `java-mode-hook'."
249 (or (assq 'c-auto-hungry-string minor-mode-alist) 279 (or (assq 'c-auto-hungry-string minor-mode-alist)
250 (setq minor-mode-alist 280 (setq minor-mode-alist
251 (cons '(c-auto-hungry-string c-auto-hungry-string) 281 (cons '(c-auto-hungry-string c-auto-hungry-string)
252 minor-mode-alist)))) 282 minor-mode-alist)))
283 ;; now set the mode style based on c-default-style
284 (c-set-style (if (stringp c-default-style)
285 (if (c-major-mode-is 'java-mode)
286 "java"
287 c-default-style)
288 (or (cdr (assq major-mode c-default-style))
289 (cdr (assq 'other c-default-style))
290 "gnu")))
291 )
292
253 293
254(defun c-postprocess-file-styles () 294(defun c-postprocess-file-styles ()
255 "Function that post processes relevant file local variables. 295 "Function that post processes relevant file local variables.
@@ -277,6 +317,9 @@ Note that the style variables are always made local to the buffer."
277(add-hook 'hack-local-variables-hook 'c-postprocess-file-styles) 317(add-hook 'hack-local-variables-hook 'c-postprocess-file-styles)
278 318
279 319
320(defvar c-mode-base-map ()
321 "Keymap shared by all CC Mode related modes.")
322
280;; Common routines 323;; Common routines
281(defun c-make-inherited-keymap () 324(defun c-make-inherited-keymap ()
282 (let ((map (make-sparse-keymap))) 325 (let ((map (make-sparse-keymap)))
@@ -325,9 +368,6 @@ Note that the style variables are always made local to the buffer."
325 (modify-syntax-entry ?\^m "> b" table)) 368 (modify-syntax-entry ?\^m "> b" table))
326 369
327 370
328(defvar c-mode-base-map ()
329 "Keymap shared by all CC Mode related modes.")
330
331(if c-mode-base-map 371(if c-mode-base-map
332 nil 372 nil
333 ;; TBD: should we even worry about naming this keymap. My vote: no, 373 ;; TBD: should we even worry about naming this keymap. My vote: no,
@@ -340,6 +380,8 @@ Note that the style variables are always made local to the buffer."
340 (define-key c-mode-base-map ";" 'c-electric-semi&comma) 380 (define-key c-mode-base-map ";" 'c-electric-semi&comma)
341 (define-key c-mode-base-map "#" 'c-electric-pound) 381 (define-key c-mode-base-map "#" 'c-electric-pound)
342 (define-key c-mode-base-map ":" 'c-electric-colon) 382 (define-key c-mode-base-map ":" 'c-electric-colon)
383 (define-key c-mode-base-map "(" 'c-electric-paren)
384 (define-key c-mode-base-map ")" 'c-electric-paren)
343 ;; Separate M-BS from C-M-h. The former should remain 385 ;; Separate M-BS from C-M-h. The former should remain
344 ;; backward-kill-word. 386 ;; backward-kill-word.
345 (define-key c-mode-base-map [(control meta h)] 'c-mark-function) 387 (define-key c-mode-base-map [(control meta h)] 'c-mark-function)
@@ -396,26 +438,27 @@ Note that the style variables are always made local to the buffer."
396(defvar c-c++-menu nil) 438(defvar c-c++-menu nil)
397(defvar c-objc-menu nil) 439(defvar c-objc-menu nil)
398(defvar c-java-menu nil) 440(defvar c-java-menu nil)
441(defvar c-pike-menu nil)
399 442
400(defun c-mode-menu (modestr) 443(defun c-mode-menu (modestr)
401 (let ((m 444 (let ((m
402 '(["Comment Out Region" comment-region (mark t)] 445 '(["Comment Out Region" comment-region (c-region-is-active-p)]
403 ["Uncomment Region" 446 ["Uncomment Region"
404 (comment-region (region-beginning) (region-end) '(4)) 447 (comment-region (region-beginning) (region-end) '(4))
405 (mark t)] 448 (c-region-is-active-p)]
406 ["Fill Comment Paragraph" c-fill-paragraph t] 449 ["Fill Comment Paragraph" c-fill-paragraph t]
407 "---" 450 "---"
408 ["Indent Expression" c-indent-exp 451 ["Indent Expression" c-indent-exp
409 (memq (char-after) '(?\( ?\[ ?\{))] 452 (memq (char-after) '(?\( ?\[ ?\{))]
410 ["Indent Line" c-indent-command t] 453 ["Indent Line or Region" c-indent-line-or-region t]
411 ["Up Conditional" c-up-conditional t] 454 ["Up Conditional" c-up-conditional t]
412 ["Backward Conditional" c-backward-conditional t] 455 ["Backward Conditional" c-backward-conditional t]
413 ["Forward Conditional" c-forward-conditional t] 456 ["Forward Conditional" c-forward-conditional t]
414 ["Backward Statement" c-beginning-of-statement t] 457 ["Backward Statement" c-beginning-of-statement t]
415 ["Forward Statement" c-end-of-statement t] 458 ["Forward Statement" c-end-of-statement t]
416 "---" 459 "---"
417 ["Macro Expand Region" c-macro-expand (mark t)] 460 ["Macro Expand Region" c-macro-expand (c-region-is-active-p)]
418 ["Backslashify" c-backslash-region (mark t)] 461 ["Backslashify" c-backslash-region (c-region-is-active-p)]
419 ))) 462 )))
420 (cons modestr m))) 463 (cons modestr m)))
421 464
@@ -564,6 +607,33 @@ Note that the style variables are always made local to the buffer."
564(easy-menu-define c-idl-menu idl-mode-map "IDL Mode Commands" 607(easy-menu-define c-idl-menu idl-mode-map "IDL Mode Commands"
565 (c-mode-menu "IDL")) 608 (c-mode-menu "IDL"))
566 609
610
611;; Support for Pike
612
613(defvar pike-mode-abbrev-table nil
614 "Abbreviation table used in pike-mode buffers.")
615(define-abbrev-table 'pike-mode-abbrev-table ())
616
617(defvar pike-mode-map ()
618 "Keymap used in pike-mode buffers.")
619(if pike-mode-map
620 nil
621 (setq pike-mode-map (c-make-inherited-keymap))
622 ;; additional bindings
623 (define-key pike-mode-map "\C-c\C-e" 'c-macro-expand))
624
625;;;###autoload
626(defvar pike-mode-syntax-table nil
627 "Syntax table used in pike-mode buffers.")
628(if pike-mode-syntax-table
629 ()
630 (setq pike-mode-syntax-table (make-syntax-table))
631 (c-populate-syntax-table pike-mode-syntax-table)
632 (modify-syntax-entry ?@ "." pike-mode-syntax-table))
633
634(easy-menu-define c-pike-menu pike-mode-map "Pike Mode Commands"
635 (c-mode-menu "Pike"))
636
567 637
568 638
569(provide 'cc-langs) 639(provide 'cc-langs)
diff --git a/lisp/progmodes/cc-menus.el b/lisp/progmodes/cc-menus.el
index 7fbe653b6a2..87bd4ed6def 100644
--- a/lisp/progmodes/cc-menus.el
+++ b/lisp/progmodes/cc-menus.el
@@ -2,10 +2,11 @@
2 2
3;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc. 3;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc.
4 4
5;; Authors: 1992-1997 Barry A. Warsaw 5;; Authors: 1998 Barry A. Warsaw and Martin Stjernholm
6;; 1992-1997 Barry A. Warsaw
6;; 1987 Dave Detlefs and Stewart Clamen 7;; 1987 Dave Detlefs and Stewart Clamen
7;; 1985 Richard M. Stallman 8;; 1985 Richard M. Stallman
8;; Maintainer: cc-mode-help@python.org 9;; Maintainer: bug-cc-mode@gnu.org
9;; Created: 22-Apr-1997 (split from cc-mode.el) 10;; Created: 22-Apr-1997 (split from cc-mode.el)
10;; Version: See cc-mode.el 11;; Version: See cc-mode.el
11;; Keywords: c languages oop 12;; Keywords: c languages oop
@@ -27,10 +28,14 @@
27;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 28;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28;; Boston, MA 02111-1307, USA. 29;; Boston, MA 02111-1307, USA.
29 30
31;; Pull in Imenu when compiling, if it exists
32(eval-when-compile
33 (condition-case nil
34 (require 'imenu)
35 (error nil)))
36
30 37
31;; imenu integration 38;; imenu integration
32(eval-when-compile (require 'imenu))
33
34(defvar cc-imenu-c-prototype-macro-regexp nil 39(defvar cc-imenu-c-prototype-macro-regexp nil
35 "RE matching macro names used to conditionally specify function prototypes. 40 "RE matching macro names used to conditionally specify function prototypes.
36 41
@@ -117,7 +122,10 @@ A sample value might look like: `\\(_P\\|_PROTO\\)'.")
117 "^" ; beginning of line is required 122 "^" ; beginning of line is required
118 "\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a `template <...>' 123 "\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a `template <...>'
119 "class[ \t]+" 124 "class[ \t]+"
120 "\\([a-zA-Z0-9_]+\\)" ; the string we want to get 125 "\\(" ; the string we want to get
126 "[a-zA-Z0-9_]+" ; class name
127 "\\(<[^>]+>\\)?" ; possibly explicitely specialized
128 "\\)"
121 "[ \t]*[:{]" 129 "[ \t]*[:{]"
122 )) 2))) 130 )) 2)))
123 "Imenu generic expression for C++ mode. See `imenu-generic-expression'.") 131 "Imenu generic expression for C++ mode. See `imenu-generic-expression'.")
@@ -137,8 +145,8 @@ A sample value might look like: `\\(_P\\|_PROTO\\)'.")
137 "\\([A-Za-z0-9_-]+[ \t]*[[]?[]]?\\)" 145 "\\([A-Za-z0-9_-]+[ \t]*[[]?[]]?\\)"
138 "\\([ \t]\\)" 146 "\\([ \t]\\)"
139 "\\([A-Za-z0-9_-]+\\)" ; the string we want to get 147 "\\([A-Za-z0-9_-]+\\)" ; the string we want to get
140 "\\([ \t]*\\)(" 148 "\\([ \t]*\\)+("
141 "\\([][a-zA-Z,_1-9\n \t]*\\)" ; arguments 149 "\\([a-zA-Z,_1-9\n \t]*[[]?[]]?\\)*" ; arguments
142 ")[ \t]*" 150 ")[ \t]*"
143; "[^;(]" 151; "[^;(]"
144 "[,a-zA-Z_1-9\n \t]*{" 152 "[,a-zA-Z_1-9\n \t]*{"
@@ -307,7 +315,7 @@ Example:
307 (if (fboundp 'buffer-substring-no-properties) 315 (if (fboundp 'buffer-substring-no-properties)
308 'buffer-substring-no-properties 316 'buffer-substring-no-properties
309 'buffer-substring))) 317 'buffer-substring)))
310 (goto-char (point-max)) 318 (goto-char (point-max))
311 (imenu-progress-message stupid 0) 319 (imenu-progress-message stupid 0)
312 ;; 320 ;;
313 (while (re-search-backward cc-imenu-objc-generic-expression nil t) 321 (while (re-search-backward cc-imenu-objc-generic-expression nil t)
@@ -386,6 +394,10 @@ Example:
386 toplist 394 toplist
387 )) 395 ))
388 396
397;(defvar cc-imenu-pike-generic-expression
398; ())
399; FIXME: Please contribute one!
400
389 401
390(provide 'cc-menus) 402(provide 'cc-menus)
391;;; cc-menus.el ends here 403;;; cc-menus.el ends here
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index e222ce1b033..06e7a18b0d5 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -2,14 +2,15 @@
2 2
3;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc. 3;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc.
4 4
5;; Authors: 1992-1997 Barry A. Warsaw 5;; Authors: 1998 Barry A. Warsaw and Martin Stjernholm
6;; 1992-1997 Barry A. Warsaw
6;; 1987 Dave Detlefs and Stewart Clamen 7;; 1987 Dave Detlefs and Stewart Clamen
7;; 1985 Richard M. Stallman 8;; 1985 Richard M. Stallman
8;; Maintainer: cc-mode-help@python.org 9;; Maintainer: bug-cc-mode@gnu.org
9;; Created: a long, long, time ago. adapted from the original c-mode.el 10;; Created: a long, long, time ago. adapted from the original c-mode.el
10;; Keywords: c languages oop 11;; Keywords: c languages oop
11 12
12(defconst c-version "5.21" 13(defconst c-version "5.25"
13 "CC Mode version number.") 14 "CC Mode version number.")
14 15
15;; NOTE: Read the commentary below for the right way to submit bug reports! 16;; NOTE: Read the commentary below for the right way to submit bug reports!
@@ -35,13 +36,15 @@
35;;; Commentary: 36;;; Commentary:
36 37
37;; This package provides GNU Emacs major modes for editing C, C++, 38;; This package provides GNU Emacs major modes for editing C, C++,
38;; Objective-C, Java and IDL code. As of the latest Emacs and XEmacs 39;; Objective-C, Java, IDL and Pike code. As of the latest Emacs and
39;; releases, it is the default package for editing these languages. 40;; XEmacs releases, it is the default package for editing these
40;; This package is called "CC Mode", and should be spelled exactly 41;; languages. This package is called "CC Mode", and should be spelled
41;; this way. It supports K&R and ANSI C, ANSI C++, Objective-C, Java, 42;; exactly this way.
42;; and CORBA's IDL with a consistent indentation model across all 43
43;; modes. This indentation model is intuitive and very flexible, so 44;; CC Mode supports K&R and ANSI C, ANSI C++, Objective-C, Java,
44;; that almost any desired style of indentation can be supported. 45;; CORBA's IDL, and Pike with a consistent indentation model across
46;; all modes. This indentation model is intuitive and very flexible,
47;; so that almost any desired style of indentation can be supported.
45;; Installation, usage, and programming details are contained in an 48;; Installation, usage, and programming details are contained in an
46;; accompanying texinfo manual. 49;; accompanying texinfo manual.
47 50
@@ -51,17 +54,20 @@
51;; NOTE: This mode does not perform font-locking (a.k.a syntactic 54;; NOTE: This mode does not perform font-locking (a.k.a syntactic
52;; coloring, keyword highlighting, etc.) for any of the supported 55;; coloring, keyword highlighting, etc.) for any of the supported
53;; modes. Typically this is done by a package called font-lock.el 56;; modes. Typically this is done by a package called font-lock.el
54;; which I do *not* maintain. You should contact the Emacs 57;; which we do *not* maintain. You should contact the Emacs or XEmacs
55;; maintainers for questions about coloring or highlighting in any 58;; maintainers for questions about coloring or highlighting in any
56;; language mode. 59;; language mode.
57 60
58;; To submit bug reports, type "C-c C-b". These will be sent to 61;; To submit bug reports, type "C-c C-b". These will be sent to
59;; bug-gnu-emacs@prep.ai.mit.edu as well as cc-mode-help@python.org, 62;; bug-gnu-emacs@gnu.org (mirrored as the Usenet newsgroup
60;; and I'll read about them there (the former is mirrored as the 63;; gnu.emacs.bug) as well as bug-cc-mode@gnu.org, which directly
61;; Usenet newsgroup gnu.emacs.bug). Questions can sent to 64;; contacts the CC Mode maintainers. Questions can sent to
62;; help-gnu-emacs@prep.ai.mit.edu (mirrored as gnu.emacs.help) and/or 65;; help-gnu-emacs@gnu.org (mirrored as gnu.emacs.help) and/or
63;; cc-mode-help@python.org. Please do not send bugs or questions to 66;; bug-cc-mode@gnu.org. The old CC Mode contact address,
64;; my personal account. 67;; cc-mode-help@python.org is currently still active, but its use is
68;; discouraged. Please use bug-cc-mode@gnu.org instead. Please do
69;; not send bugs or questions to our personal accounts; we reserve the
70;; right to ignore such email!
65 71
66;; Many, many thanks go out to all the folks on the beta test list. 72;; Many, many thanks go out to all the folks on the beta test list.
67;; Without their patience, testing, insight, code contributions, and 73;; Without their patience, testing, insight, code contributions, and
@@ -70,27 +76,27 @@
70;; You can get the latest version of CC Mode, including PostScript 76;; You can get the latest version of CC Mode, including PostScript
71;; documentation and separate individual files from: 77;; documentation and separate individual files from:
72;; 78;;
73;; http://www.python.org/ftp/emacs/ 79;; http://www.python.org/emacs/cc-mode/
74 80;;
75;; Or if you don't have access to the World Wide Web, through 81;; You can join a moderated CC Mode announcement-only mailing list by
76;; anonymous ftp from: 82;; visiting
77;; 83;;
78;; ftp://ftp.python.org/pub/emacs 84;; http://www.python.org/mailman/listinfo/cc-mode-announce
79 85
80;;; Code: 86;;; Code:
81 87
82 88
83(require 'cc-defs) 89(defvar c-buffer-is-cc-mode nil
84 90 "Non-nil for all buffers with a `major-mode' derived from CC Mode.
85;; sigh. give in to the pressure, but make really sure all the 91Otherwise, this variable is nil. I.e. this variable is non-nil for
86;; definitions we need are here 92`c-mode', `c++-mode', `objc-mode', `java-mode', `idl-mode',
87(if (or (not (fboundp 'functionp)) 93`pike-mode', and any other non-CC Mode mode that calls
88 (not (fboundp 'char-before)) 94`c-initialize-cc-mode' (e.g. `awk-mode').")
89 (not (c-safe (char-after) t)) 95(make-variable-buffer-local 'c-buffer-is-cc-mode)
90 (not (fboundp 'when)) 96(put 'c-buffer-is-cc-mode 'permanent-local t)
91 (not (fboundp 'unless)))
92 (require 'cc-mode-19))
93 97
98(eval-and-compile
99 (require 'cc-defs))
94(require 'cc-menus) 100(require 'cc-menus)
95(require 'cc-vars) 101(require 'cc-vars)
96(require 'cc-engine) 102(require 'cc-engine)
@@ -99,15 +105,6 @@
99(require 'cc-styles) 105(require 'cc-styles)
100(require 'cc-cmds) 106(require 'cc-cmds)
101 107
102(defvar c-buffer-is-cc-mode nil
103 "Non-nil for all buffers with a `major-mode' derived from CC Mode.
104Otherwise, this variable is nil. I.e. this variable is non-nil for
105`c-mode', `c++-mode', `objc-mode', `java-mode', `idl-mode', and any
106other non-CC Mode mode that calls `c-initialize-cc-mode'
107\(e.g. `awk-mode').")
108(make-variable-buffer-local 'c-buffer-is-cc-mode)
109(put 'c-buffer-is-cc-mode 'permanent-local t)
110
111 108
112 109
113;; Other modes and packages which depend on CC Mode should do the 110;; Other modes and packages which depend on CC Mode should do the
@@ -118,16 +115,20 @@ other non-CC Mode mode that calls `c-initialize-cc-mode'
118;; (c-initialize-cc-mode) 115;; (c-initialize-cc-mode)
119 116
120;;;###autoload 117;;;###autoload
121(defun c-initialize-cc-mode (&optional skip-styles) 118(defun c-initialize-cc-mode ()
122 (setq c-buffer-is-cc-mode t) 119 (setq c-buffer-is-cc-mode t)
123 (let ((initprop 'cc-mode-is-initialized)) 120 (let ((initprop 'cc-mode-is-initialized)
124 ;; run the initialization hook, but only once 121 c-initialization-ok)
125 (or (get 'c-initialize-cc-mode initprop) 122 (unless (get 'c-initialize-cc-mode initprop)
126 (progn 123 (put 'c-initialize-cc-mode initprop t)
127 (or skip-styles 124 (c-initialize-builtin-style)
128 (c-initialize-builtin-style)) 125 (unwind-protect
129 (run-hooks 'c-initialization-hook) 126 (progn
130 (put 'c-initialize-cc-mode initprop t))) 127 (run-hooks 'c-initialization-hook)
128 (setq c-initialization-ok t))
129 ;; Will try initialization hooks again if they failed.
130 (unless c-initialization-ok
131 (put 'c-initialize-cc-mode initprop nil))))
131 )) 132 ))
132 133
133 134
@@ -163,7 +164,8 @@ Key bindings:
163 c-baseclass-key nil 164 c-baseclass-key nil
164 c-comment-start-regexp c-C++-comment-start-regexp 165 c-comment-start-regexp c-C++-comment-start-regexp
165 imenu-generic-expression cc-imenu-c-generic-expression 166 imenu-generic-expression cc-imenu-c-generic-expression
166 imenu-case-fold-search nil) 167 imenu-case-fold-search nil
168 )
167 (run-hooks 'c-mode-common-hook) 169 (run-hooks 'c-mode-common-hook)
168 (run-hooks 'c-mode-hook) 170 (run-hooks 'c-mode-hook)
169 (c-update-modeline)) 171 (c-update-modeline))
@@ -200,10 +202,12 @@ Key bindings:
200 c-conditional-key c-C++-conditional-key 202 c-conditional-key c-C++-conditional-key
201 c-comment-start-regexp c-C++-comment-start-regexp 203 c-comment-start-regexp c-C++-comment-start-regexp
202 c-class-key c-C++-class-key 204 c-class-key c-C++-class-key
205 c-extra-toplevel-key c-C++-extra-toplevel-key
203 c-access-key c-C++-access-key 206 c-access-key c-C++-access-key
204 c-recognize-knr-p nil 207 c-recognize-knr-p nil
205 imenu-generic-expression cc-imenu-c++-generic-expression 208 imenu-generic-expression cc-imenu-c++-generic-expression
206 imenu-case-fold-search nil) 209 imenu-case-fold-search nil
210 )
207 (run-hooks 'c-mode-common-hook) 211 (run-hooks 'c-mode-common-hook)
208 (run-hooks 'c++-mode-hook) 212 (run-hooks 'c++-mode-hook)
209 (c-update-modeline)) 213 (c-update-modeline))
@@ -288,11 +292,11 @@ Key bindings:
288 c-baseclass-key nil 292 c-baseclass-key nil
289 c-recognize-knr-p nil 293 c-recognize-knr-p nil
290 c-access-key c-Java-access-key 294 c-access-key c-Java-access-key
295 c-inexpr-class-key c-Java-inexpr-class-key
291 ;defun-prompt-regexp c-Java-defun-prompt-regexp 296 ;defun-prompt-regexp c-Java-defun-prompt-regexp
292 imenu-generic-expression cc-imenu-java-generic-expression 297 imenu-generic-expression cc-imenu-java-generic-expression
293 imenu-case-fold-search nil 298 imenu-case-fold-search nil
294 ) 299 )
295 (c-set-style "java")
296 (run-hooks 'c-mode-common-hook) 300 (run-hooks 'c-mode-common-hook)
297 (run-hooks 'java-mode-hook) 301 (run-hooks 'java-mode-hook)
298 (c-update-modeline)) 302 (c-update-modeline))
@@ -328,7 +332,8 @@ Key bindings:
328 comment-end "" 332 comment-end ""
329 c-conditional-key c-C++-conditional-key 333 c-conditional-key c-C++-conditional-key
330 c-comment-start-regexp c-C++-comment-start-regexp 334 c-comment-start-regexp c-C++-comment-start-regexp
331 c-class-key c-C++-class-key 335 c-class-key c-IDL-class-key
336 c-extra-toplevel-key c-IDL-extra-toplevel-key
332 c-access-key c-C++-access-key 337 c-access-key c-C++-access-key
333 c-recognize-knr-p nil 338 c-recognize-knr-p nil
334;; imenu-generic-expression cc-imenu-c++-generic-expression 339;; imenu-generic-expression cc-imenu-c++-generic-expression
@@ -339,11 +344,56 @@ Key bindings:
339 (c-update-modeline)) 344 (c-update-modeline))
340 345
341 346
347;;;###autoload
348(defun pike-mode ()
349 "Major mode for editing Pike code.
350To submit a problem report, enter `\\[c-submit-bug-report]' from an
351idl-mode buffer. This automatically sets up a mail buffer with
352version information already added. You just need to add a description
353of the problem, including a reproducible test case, and send the
354message.
355
356To see what version of CC Mode you are running, enter `\\[c-version]'.
357
358The hook variable `pike-mode-hook' is run with no args, if that value
359is bound and has a non-nil value. Also the common hook
360`c-mode-common-hook' is run first.
361
362Key bindings:
363\\{pike-mode-map}"
364 (interactive)
365 (c-initialize-cc-mode)
366 (kill-all-local-variables)
367 (set-syntax-table pike-mode-syntax-table)
368 (setq major-mode 'pike-mode
369 mode-name "Pike"
370 local-abbrev-table pike-mode-abbrev-table)
371 (use-local-map pike-mode-map)
372 (c-common-init)
373 (setq comment-start "// "
374 comment-end ""
375 c-conditional-key c-Pike-conditional-key
376 c-class-key c-Pike-class-key
377 c-method-key nil
378 c-baseclass-key nil
379 c-recognize-knr-p nil
380 c-access-key c-Pike-access-key
381 c-lambda-key c-Pike-lambda-key
382 c-inexpr-block-key c-Pike-inexpr-block-key
383 c-special-brace-lists c-Pike-special-brace-lists
384 ;imenu-generic-expression cc-imenu-java-generic-expression ;FIXME
385 ;imenu-case-fold-search nil ;FIXME
386 )
387 (run-hooks 'c-mode-common-hook)
388 (run-hooks 'pike-mode-hook)
389 (c-update-modeline))
390
391
342;; bug reporting 392;; bug reporting
343 393
344(defconst c-mode-help-address 394(defconst c-mode-help-address
345 "bug-gnu-emacs@prep.ai.mit.edu, cc-mode-help@python.org" 395 "bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org"
346 "Address for CC Mode bug reports.") 396 "Addresses for CC Mode bug reports.")
347 397
348(defun c-version () 398(defun c-version ()
349 "Echo the current version of CC Mode in the minibuffer." 399 "Echo the current version of CC Mode in the minibuffer."
@@ -373,6 +423,7 @@ Key bindings:
373 ((eq major-mode 'c-mode) "C") 423 ((eq major-mode 'c-mode) "C")
374 ((eq major-mode 'objc-mode) "ObjC") 424 ((eq major-mode 'objc-mode) "ObjC")
375 ((eq major-mode 'java-mode) "Java") 425 ((eq major-mode 'java-mode) "Java")
426 ((eq major-mode 'pike-mode) "Pike")
376 ) 427 )
377 ")") 428 ")")
378 (let ((vars (list 429 (let ((vars (list
@@ -394,6 +445,10 @@ Key bindings:
394 'c-label-minimum-indentation 445 'c-label-minimum-indentation
395 'defun-prompt-regexp 446 'defun-prompt-regexp
396 'tab-width 447 'tab-width
448 'comment-column
449 ;; A brain-damaged XEmacs only variable that, if
450 ;; set to nil can cause all kinds of chaos.
451 'signal-error-on-buffer-boundary
397 ))) 452 )))
398 (if (not (boundp 'defun-prompt-regexp)) 453 (if (not (boundp 'defun-prompt-regexp))
399 (delq 'defun-prompt-regexp vars) 454 (delq 'defun-prompt-regexp vars)
@@ -402,7 +457,10 @@ Key bindings:
402 (lambda () 457 (lambda ()
403 (insert 458 (insert
404 "Buffer Style: " style "\n\n" 459 "Buffer Style: " style "\n\n"
405 (if hook 460 (if (and hook
461 (or (/= (length hook) 1)
462 (not (eq (car hook) 'c-gnu-impose-minimum))
463 ))
406 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" 464 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
407 "c-special-indent-hook is set to '" 465 "c-special-indent-hook is set to '"
408 (format "%s" hook) 466 (format "%s" hook)
diff --git a/lisp/progmodes/cc-styles.el b/lisp/progmodes/cc-styles.el
index 6001207544c..f394a9b3fdc 100644
--- a/lisp/progmodes/cc-styles.el
+++ b/lisp/progmodes/cc-styles.el
@@ -2,10 +2,11 @@
2 2
3;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc. 3;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc.
4 4
5;; Authors: 1992-1997 Barry A. Warsaw 5;; Authors: 1998 Barry A. Warsaw and Martin Stjernholm
6;; 1992-1997 Barry A. Warsaw
6;; 1987 Dave Detlefs and Stewart Clamen 7;; 1987 Dave Detlefs and Stewart Clamen
7;; 1985 Richard M. Stallman 8;; 1985 Richard M. Stallman
8;; Maintainer: cc-mode-help@python.org 9;; Maintainer: bug-cc-mode@gnu.org
9;; Created: 22-Apr-1997 (split from cc-mode.el) 10;; Created: 22-Apr-1997 (split from cc-mode.el)
10;; Version: See cc-mode.el 11;; Version: See cc-mode.el
11;; Keywords: c languages oop 12;; Keywords: c languages oop
@@ -28,7 +29,12 @@
28;; Boston, MA 02111-1307, USA. 29;; Boston, MA 02111-1307, USA.
29 30
30 31
32;; explicit compile-time dependencies
33(eval-when-compile
34 (require 'cc-defs))
35
31 36
37;; Warning: don't eval-defun this constant or you'll break style inheritance.
32(defconst c-style-alist 38(defconst c-style-alist
33 '(("gnu" 39 '(("gnu"
34 (c-basic-offset . 2) 40 (c-basic-offset . 2)
@@ -41,6 +47,7 @@
41 (statement-cont . +) 47 (statement-cont . +)
42 (arglist-intro . c-lineup-arglist-intro-after-paren) 48 (arglist-intro . c-lineup-arglist-intro-after-paren)
43 (arglist-close . c-lineup-arglist) 49 (arglist-close . c-lineup-arglist)
50 (inline-open . 0)
44 )) 51 ))
45 (c-special-indent-hook . c-gnu-impose-minimum) 52 (c-special-indent-hook . c-gnu-impose-minimum)
46 (c-comment-continuation-stars . "") 53 (c-comment-continuation-stars . "")
@@ -104,6 +111,7 @@
104 (c-basic-offset . 8) 111 (c-basic-offset . 8)
105 (c-comment-only-line-offset . 0) 112 (c-comment-only-line-offset . 0)
106 (c-hanging-braces-alist . ((brace-list-open) 113 (c-hanging-braces-alist . ((brace-list-open)
114 (brace-entry-open)
107 (substatement-open after) 115 (substatement-open after)
108 (block-close . c-snug-do-while))) 116 (block-close . c-snug-do-while)))
109 (c-cleanup-list . (brace-else-brace)) 117 (c-cleanup-list . (brace-else-brace))
@@ -126,6 +134,7 @@
126 (c-hanging-braces-alist . ((brace-list-open) 134 (c-hanging-braces-alist . ((brace-list-open)
127 (brace-list-intro) 135 (brace-list-intro)
128 (brace-list-close) 136 (brace-list-close)
137 (brace-entry-open)
129 (substatement-open after) 138 (substatement-open after)
130 (block-close . c-snug-do-while) 139 (block-close . c-snug-do-while)
131 )) 140 ))
@@ -284,7 +293,7 @@ STYLE using `c-set-style' if the optional SET-P flag is non-nil."
284 293
285 294
286(defconst c-offsets-alist 295(defconst c-offsets-alist
287 '((string . -1000) 296 '((string . c-lineup-dont-change)
288 (c . c-lineup-C-comments) 297 (c . c-lineup-C-comments)
289 (defun-open . 0) 298 (defun-open . 0)
290 (defun-close . 0) 299 (defun-close . 0)
@@ -308,6 +317,7 @@ STYLE using `c-set-style' if the optional SET-P flag is non-nil."
308 (brace-list-close . 0) 317 (brace-list-close . 0)
309 (brace-list-intro . +) 318 (brace-list-intro . +)
310 (brace-list-entry . 0) 319 (brace-list-entry . 0)
320 (brace-entry-open . 0)
311 (statement . 0) 321 (statement . 0)
312 ;; some people might prefer 322 ;; some people might prefer
313 ;;(statement . c-lineup-runin-statements) 323 ;;(statement . c-lineup-runin-statements)
@@ -324,6 +334,7 @@ STYLE using `c-set-style' if the optional SET-P flag is non-nil."
324 (label . 2) 334 (label . 2)
325 (do-while-closure . 0) 335 (do-while-closure . 0)
326 (else-clause . 0) 336 (else-clause . 0)
337 (catch-clause . 0)
327 (comment-intro . c-lineup-comment) 338 (comment-intro . c-lineup-comment)
328 (arglist-intro . +) 339 (arglist-intro . +)
329 (arglist-cont . 0) 340 (arglist-cont . 0)
@@ -344,6 +355,10 @@ STYLE using `c-set-style' if the optional SET-P flag is non-nil."
344 (namespace-close . 0) 355 (namespace-close . 0)
345 (innamespace . +) 356 (innamespace . +)
346 (template-args-cont . +) 357 (template-args-cont . +)
358 (inlambda . c-lineup-inexpr-block)
359 (lambda-intro-cont . +)
360 (inexpr-statement . 0)
361 (inexpr-class . +)
347 ) 362 )
348 "Association list of syntactic element symbols and indentation offsets. 363 "Association list of syntactic element symbols and indentation offsets.
349As described below, each cons cell in this list has the form: 364As described below, each cons cell in this list has the form:
@@ -380,6 +395,13 @@ is called with a single argument containing the cons of the syntactic
380element symbol and the relative indent point. The function should 395element symbol and the relative indent point. The function should
381return an integer offset. 396return an integer offset.
382 397
398OFFSET can also be a list, in which case it is recursively evaluated
399using the semantics described above. The first element of the list to
400return a non-nil value succeeds. If none of the elements returns a
401non-nil value, then what happends depends on the value of
402`c-strict-syntax-p'. When `c-strict-syntax-p' is nil, then an offset
403of zero is used, otherwise an error is generated.
404
383Here is the current list of valid syntactic element symbols: 405Here is the current list of valid syntactic element symbols:
384 406
385 string -- inside multi-line string 407 string -- inside multi-line string
@@ -411,6 +433,8 @@ Here is the current list of valid syntactic element symbols:
411 brace-list-close -- close brace of an enum or static array list 433 brace-list-close -- close brace of an enum or static array list
412 brace-list-intro -- first line in an enum or static array list 434 brace-list-intro -- first line in an enum or static array list
413 brace-list-entry -- subsequent lines in an enum or static array list 435 brace-list-entry -- subsequent lines in an enum or static array list
436 brace-entry-open -- subsequent lines in an enum or static array
437 list that start with an open brace.
414 statement -- a C (or like) statement 438 statement -- a C (or like) statement
415 statement-cont -- a continuation of a C (or like) statement 439 statement-cont -- a continuation of a C (or like) statement
416 statement-block-intro -- the first line in a new statement block 440 statement-block-intro -- the first line in a new statement block
@@ -423,6 +447,7 @@ Here is the current list of valid syntactic element symbols:
423 label -- any ordinary label 447 label -- any ordinary label
424 do-while-closure -- the `while' that ends a do/while construct 448 do-while-closure -- the `while' that ends a do/while construct
425 else-clause -- the `else' of an if/else construct 449 else-clause -- the `else' of an if/else construct
450 catch-clause -- the `catch' or `finally' of a try/catch construct
426 comment-intro -- a line containing only a comment introduction 451 comment-intro -- a line containing only a comment introduction
427 arglist-intro -- the first line in an argument list 452 arglist-intro -- the first line in an argument list
428 arglist-cont -- subsequent argument list lines when no 453 arglist-cont -- subsequent argument list lines when no
@@ -450,8 +475,38 @@ Here is the current list of valid syntactic element symbols:
450 innamespace -- analogous to `inextern-lang' syntactic 475 innamespace -- analogous to `inextern-lang' syntactic
451 symbol, but used inside C++ namespace constructs 476 symbol, but used inside C++ namespace constructs
452 template-args-cont -- C++ template argument list continuations 477 template-args-cont -- C++ template argument list continuations
478 inlambda -- in the header or body of a lambda function
479 lambda-intro-cont -- continuation of the header of a lambda function
480 inexpr-statement -- the statement is inside an expression
481 inexpr-class -- the class is inside an expression
453") 482")
454 483
484(defun c-evaluate-offset (offset langelem symbol)
485 ;; offset can be a number, a function, a variable, a list, or one of
486 ;; the symbols + or -
487 (cond
488 ((eq offset '+) (setq offset c-basic-offset))
489 ((eq offset '-) (setq offset (- c-basic-offset)))
490 ((eq offset '++) (setq offset (* 2 c-basic-offset)))
491 ((eq offset '--) (setq offset (* 2 (- c-basic-offset))))
492 ((eq offset '*) (setq offset (/ c-basic-offset 2)))
493 ((eq offset '/) (setq offset (/ (- c-basic-offset) 2)))
494 ((functionp offset) (setq offset (funcall offset langelem)))
495 ((listp offset)
496 (setq offset
497 (let (done)
498 (while (and (not done) offset)
499 (setq done (c-evaluate-offset (car offset) langelem symbol)
500 offset (cdr offset)))
501 (if (not done)
502 (if c-strict-syntax-p
503 (error "No offset found for syntactic symbol %s" symbol)
504 0)
505 done))))
506 ((not (numberp offset)) (setq offset (symbol-value offset)))
507 )
508 offset)
509
455(defun c-get-offset (langelem) 510(defun c-get-offset (langelem)
456 ;; Get offset from LANGELEM which is a cons cell of the form: 511 ;; Get offset from LANGELEM which is a cons cell of the form:
457 ;; (SYMBOL . RELPOS). The symbol is matched against 512 ;; (SYMBOL . RELPOS). The symbol is matched against
@@ -462,30 +517,20 @@ Here is the current list of valid syntactic element symbols:
462 (relpos (cdr langelem)) 517 (relpos (cdr langelem))
463 (match (assq symbol c-offsets-alist)) 518 (match (assq symbol c-offsets-alist))
464 (offset (cdr-safe match))) 519 (offset (cdr-safe match)))
465 ;; offset can be a number, a function, a variable, or one of the 520 (if (not match)
466 ;; symbols + or - 521 (if c-strict-syntax-p
467 (cond 522 (error "No offset found for syntactic symbol %s" symbol)
468 ((not match) 523 (setq offset 0
469 (if c-strict-syntax-p 524 relpos 0))
470 (error "don't know how to indent a %s" symbol) 525 (setq offset (c-evaluate-offset offset langelem symbol)))
471 (setq offset 0
472 relpos 0)))
473 ((eq offset '+) (setq offset c-basic-offset))
474 ((eq offset '-) (setq offset (- c-basic-offset)))
475 ((eq offset '++) (setq offset (* 2 c-basic-offset)))
476 ((eq offset '--) (setq offset (* 2 (- c-basic-offset))))
477 ((eq offset '*) (setq offset (/ c-basic-offset 2)))
478 ((eq offset '/) (setq offset (/ (- c-basic-offset) 2)))
479 ((functionp offset) (setq offset (funcall offset langelem)))
480 ((not (numberp offset)) (setq offset (symbol-value offset)))
481 )
482 (+ (if (and relpos 526 (+ (if (and relpos
483 (< relpos (c-point 'bol))) 527 (< relpos (c-point 'bol)))
484 (save-excursion 528 (save-excursion
485 (goto-char relpos) 529 (goto-char relpos)
486 (current-column)) 530 (current-column))
487 0) 531 0)
488 offset))) 532 (c-evaluate-offset offset langelem symbol))
533 ))
489 534
490 535
491(defvar c-read-offset-history nil) 536(defvar c-read-offset-history nil)
@@ -493,12 +538,13 @@ Here is the current list of valid syntactic element symbols:
493(defun c-read-offset (langelem) 538(defun c-read-offset (langelem)
494 ;; read new offset value for LANGELEM from minibuffer. return a 539 ;; read new offset value for LANGELEM from minibuffer. return a
495 ;; legal value only 540 ;; legal value only
496 (let* ((oldoff (cdr-safe (assq langelem c-offsets-alist))) 541 (let* ((oldoff (cdr-safe (assq langelem c-offsets-alist)))
497 (defstr (format "(default %s): " oldoff)) 542 (symname (symbol-name langelem))
498 (errmsg (concat "Offset must be int, func, var, " 543 (defstr (format "(default %s): " oldoff))
499 "or in [+,-,++,--,*,/] " 544 (errmsg (concat "Offset must be int, func, var, list, "
500 defstr)) 545 "or [+,-,++,--,*,/] "
501 (prompt (concat "Offset " defstr)) 546 defstr))
547 (prompt (concat symname " offset " defstr))
502 offset input interned raw) 548 offset input interned raw)
503 (while (not offset) 549 (while (not offset)
504 (setq input (completing-read prompt obarray 'fboundp nil nil 550 (setq input (completing-read prompt obarray 'fboundp nil nil
@@ -563,8 +609,9 @@ offset for that syntactic element. Optional ADD says to add SYMBOL to
563 (eq offset '/) 609 (eq offset '/)
564 (integerp offset) 610 (integerp offset)
565 (functionp offset) 611 (functionp offset)
612 (listp offset)
566 (boundp offset) 613 (boundp offset)
567 (error "Offset must be int, func, var, or in [+,-,++,--,*,/]: %s" 614 (error "Offset must be int, func, var, list, or in [+,-,++,--,*,/]: %s"
568 offset)) 615 offset))
569 (let ((entry (assq symbol c-offsets-alist))) 616 (let ((entry (assq symbol c-offsets-alist)))
570 (if entry 617 (if entry
@@ -574,50 +621,46 @@ offset for that syntactic element. Optional ADD says to add SYMBOL to
574 (error "%s is not a valid syntactic symbol." symbol)))) 621 (error "%s is not a valid syntactic symbol." symbol))))
575 (c-keep-region-active)) 622 (c-keep-region-active))
576 623
577
578 624
625(defun c-copy-tree (tree)
626 (if (consp tree)
627 (cons (c-copy-tree (car tree))
628 (c-copy-tree (cdr tree)))
629 tree))
630
579(defun c-initialize-builtin-style () 631(defun c-initialize-builtin-style ()
580 ;; Dynamically append the default value of most variables. This is 632 ;; Dynamically append the default value of most variables. This is
581 ;; crucial because future c-set-style calls will always reset the 633 ;; crucial because future c-set-style calls will always reset the
582 ;; variables first to the `cc-mode' style before instituting the new 634 ;; variables first to the `cc-mode' style before instituting the new
583 ;; style. Only do this once! 635 ;; style. Only do this once!
584 (c-initialize-cc-mode t) 636 (unless (get 'c-initialize-builtin-style 'is-run)
585 (or (assoc "cc-mode" c-style-alist) 637 (put 'c-initialize-builtin-style 'is-run t)
586 (assoc "user" c-style-alist) 638 (c-initialize-cc-mode)
587 (progn 639 (or (assoc "cc-mode" c-style-alist)
588 (c-add-style "user" 640 (assoc "user" c-style-alist)
589 (mapcar 641 (progn
590 (function 642 (c-add-style "user"
591 (lambda (var) 643 (mapcar
592 (let ((val (symbol-value var))) 644 (function
593 (cons var (c-copy-tree val))))) 645 (lambda (var)
594 '(c-backslash-column 646 (let ((val (symbol-value var)))
595 c-basic-offset 647 (cons var (c-copy-tree val)))))
596 c-cleanup-list 648 '(c-backslash-column
597 c-comment-only-line-offset 649 c-basic-offset
598 c-electric-pound-behavior 650 c-cleanup-list
599 c-hanging-braces-alist 651 c-comment-only-line-offset
600 c-hanging-colons-alist 652 c-electric-pound-behavior
601 c-hanging-comment-starter-p 653 c-hanging-braces-alist
602 c-hanging-comment-ender-p 654 c-hanging-colons-alist
603 c-offsets-alist 655 c-hanging-comment-starter-p
604 ))) 656 c-hanging-comment-ender-p
605 (c-add-style "cc-mode" '("user")) 657 c-offsets-alist
606 ;; the default style is now GNU. This can be overridden in 658 )))
607 ;; c-mode-common-hook or {c,c++,objc,java}-mode-hook. 659 (c-add-style "cc-mode" '("user"))
608 (c-set-style c-default-style))) 660 ))
609 (if c-style-variables-are-local-p 661 (if c-style-variables-are-local-p
610 (c-make-styles-buffer-local))) 662 (c-make-styles-buffer-local))))
611 663
612(defun c-copy-tree (tree)
613 (if (consp tree)
614 (if (consp (cdr tree))
615 (cons (c-copy-tree (car tree))
616 (cons (c-copy-tree (cadr tree))
617 (c-copy-tree (cddr tree))))
618 (cons (c-copy-tree (car tree))
619 (c-copy-tree (cdr tree))))
620 tree))
621 664
622(defun c-make-styles-buffer-local (&optional this-buf-only-p) 665(defun c-make-styles-buffer-local (&optional this-buf-only-p)
623 "Make all CC Mode style variables buffer local. 666 "Make all CC Mode style variables buffer local.
diff --git a/lisp/progmodes/cc-vars.el b/lisp/progmodes/cc-vars.el
index 058ff138cbd..fd05cbdda10 100644
--- a/lisp/progmodes/cc-vars.el
+++ b/lisp/progmodes/cc-vars.el
@@ -2,10 +2,11 @@
2 2
3;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc. 3;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc.
4 4
5;; Authors: 1992-1997 Barry A. Warsaw 5;; Authors: 1998 Barry A. Warsaw and Martin Stjernholm
6;; 1992-1997 Barry A. Warsaw
6;; 1987 Dave Detlefs and Stewart Clamen 7;; 1987 Dave Detlefs and Stewart Clamen
7;; 1985 Richard M. Stallman 8;; 1985 Richard M. Stallman
8;; Maintainer: cc-mode-help@python.org 9;; Maintainer: bug-cc-mode@gnu.org
9;; Created: 22-Apr-1997 (split from cc-mode.el) 10;; Created: 22-Apr-1997 (split from cc-mode.el)
10;; Version: See cc-mode.el 11;; Version: See cc-mode.el
11;; Keywords: c languages oop 12;; Keywords: c languages oop
@@ -27,14 +28,18 @@
27;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 28;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28;; Boston, MA 02111-1307, USA. 29;; Boston, MA 02111-1307, USA.
29 30
31(eval-when-compile
32 (require 'cc-defs))
33
30(require 'custom) 34(require 'custom)
31 35
32 36
33(defcustom c-strict-syntax-p nil 37(defcustom c-strict-syntax-p nil
34 "*If non-nil, all syntactic symbols must be found in `c-offsets-alist'. 38 "*If non-nil, all syntactic symbols must be found in `c-offsets-alist'.
35If the syntactic symbol for a particular line does not match a symbol 39If the syntactic symbol for a particular line does not match a symbol
36in the offsets alist, an error is generated, otherwise no error is 40in the offsets alist, or if no non-nil offset value can be determined
37reported and the syntactic symbol is ignored." 41for a symbol, an error is generated, otherwise no error is reported
42and the syntactic symbol is ignored."
38 :type 'boolean 43 :type 'boolean
39 :group 'c) 44 :group 'c)
40 45
@@ -48,14 +53,23 @@ reported and the syntactic symbol is ignored."
48 :type 'integer 53 :type 'integer
49 :group 'c) 54 :group 'c)
50 55
56;; This widget will show up in newer versions of the Custom library
57(or (get 'other 'widget-type)
58 (define-widget 'other 'sexp
59 "Matches everything, but doesn't let the user edit the value.
60Useful as last item in a `choice' widget."
61 :tag "Other"
62 :format "%t%n"
63 :value 'other))
64
51(defcustom c-tab-always-indent t 65(defcustom c-tab-always-indent t
52 "*Controls the operation of the TAB key. 66 "*Controls the operation of the TAB key.
53If t, hitting TAB always just indents the current line. If nil, 67If t, hitting TAB always just indents the current line. If nil,
54hitting TAB indents the current line if point is at the left margin or 68hitting TAB indents the current line if point is at the left margin or
55in the line's indentation, otherwise it insert a `real' tab character 69in the line's indentation, otherwise it insert a `real' tab character
56\(see note\). If other than nil or t, then tab is inserted only 70\(see note\). If the symbol `other', then tab is inserted only within
57within literals -- defined as comments and strings -- and inside 71literals -- defined as comments and strings -- and inside preprocessor
58preprocessor directives, but line is always reindented. 72directives, but the line is always reindented.
59 73
60Note: The value of `indent-tabs-mode' will determine whether a real 74Note: The value of `indent-tabs-mode' will determine whether a real
61tab character will be inserted, or the equivalent number of space. 75tab character will be inserted, or the equivalent number of space.
@@ -69,7 +83,7 @@ by the `c-comment-only-line-offset' variable."
69 :format "%{C Tab Always Indent%}:\n The TAB key:\n%v" 83 :format "%{C Tab Always Indent%}:\n The TAB key:\n%v"
70 (const :tag "always indents, never inserts TAB" t) 84 (const :tag "always indents, never inserts TAB" t)
71 (const :tag "indents in left margin, otherwise inserts TAB" nil) 85 (const :tag "indents in left margin, otherwise inserts TAB" nil)
72 (const :tag "inserts TAB in literals, otherwise indent" other)) 86 (other :tag "inserts TAB in literals, otherwise indent" other))
73 :group 'c) 87 :group 'c)
74 88
75(defcustom c-insert-tab-function 'insert-tab 89(defcustom c-insert-tab-function 'insert-tab
@@ -129,7 +143,11 @@ mode name. Valid symbols are:
129 Clean up occurs when the open-brace after the 143 Clean up occurs when the open-brace after the
130 `else' is typed. 144 `else' is typed.
131 brace-elseif-brace -- similar to brace-else-brace, but cleans up 145 brace-elseif-brace -- similar to brace-else-brace, but cleans up
132 `} else if {' constructs. 146 `} else if (...) {' constructs. Clean up occurs
147 both after the open parenthesis and after the
148 open brace.
149 brace-catch-brace -- similar to brace-elseif-brace, but cleans up
150 `} catch (...) {' constructs.
133 empty-defun-braces -- cleans up empty defun braces by placing the 151 empty-defun-braces -- cleans up empty defun braces by placing the
134 braces on the same line. Clean up occurs when 152 braces on the same line. Clean up occurs when
135 the defun closing brace is typed. 153 the defun closing brace is typed.
@@ -150,16 +168,20 @@ mode name. Valid symbols are:
150 :type '(set 168 :type '(set
151 :extra-offset 8 169 :extra-offset 8
152 (const :tag "Put `} else {' on one line" brace-else-brace) 170 (const :tag "Put `} else {' on one line" brace-else-brace)
153 (const :tag "Put `} else if {' on one line" brace-elseif-brace) 171 (const :tag "Put `} else if (...) {' on one line" brace-elseif-brace)
172 (const :tag "Put `} catch (...) {' on one line" brace-catch-brace)
154 (const :tag "Put empty defun braces on one line" empty-defun-braces) 173 (const :tag "Put empty defun braces on one line" empty-defun-braces)
155 (const :tag "Put `},' in aggregates on one line" list-close-comma) 174 (const :tag "Put `},' in aggregates on one line" list-close-comma)
156 (const :tag "Put C++ style `::' on one line" scope-operator)) 175 (const :tag "Put C++ style `::' on one line" scope-operator))
157 :group 'c) 176 :group 'c)
158 177
159(defcustom c-hanging-braces-alist '((brace-list-open) 178(defcustom c-hanging-braces-alist '((brace-list-open)
179 (brace-entry-open)
160 (substatement-open after) 180 (substatement-open after)
161 (block-close . c-snug-do-while) 181 (block-close . c-snug-do-while)
162 (extern-lang-open after) 182 (extern-lang-open after)
183 (inexpr-class-open after)
184 (inexpr-class-close before)
163 ) 185 )
164 "*Controls the insertion of newlines before and after braces. 186 "*Controls the insertion of newlines before and after braces.
165This variable contains an association list with elements of the 187This variable contains an association list with elements of the
@@ -175,8 +197,12 @@ SYNTACTIC-SYMBOL can be any of: defun-open, defun-close, class-open,
175class-close, inline-open, inline-close, block-open, block-close, 197class-close, inline-open, inline-close, block-open, block-close,
176substatement-open, statement-case-open, extern-lang-open, 198substatement-open, statement-case-open, extern-lang-open,
177extern-lang-close, brace-list-open, brace-list-close, 199extern-lang-close, brace-list-open, brace-list-close,
178brace-list-intro, or brace-list-entry. See `c-offsets-alist' for 200brace-list-intro, brace-entry-open, inexpr-class-open, or
179details. 201inexpr-class-close. See `c-offsets-alist' for details, except for
202inexpr-class-open and inexpr-class-close, which doesn't have any
203corresponding symbols there. Those two symbols are used for the
204opening and closing braces, respectively, of anonymous inner classes
205in Java.
180 206
181ACTION can be either a function symbol or a list containing any 207ACTION can be either a function symbol or a list containing any
182combination of the symbols `before' or `after'. If the list is empty, 208combination of the symbols `before' or `after'. If the list is empty,
@@ -198,7 +224,8 @@ syntactic context for the brace line."
198 (const substatement-open) (const statement-case-open) 224 (const substatement-open) (const statement-case-open)
199 (const extern-lang-open) (const extern-lang-close) 225 (const extern-lang-open) (const extern-lang-close)
200 (const brace-list-open) (const brace-list-close) 226 (const brace-list-open) (const brace-list-close)
201 (const brace-list-intro) (const brace-list-entry)) 227 (const brace-list-intro) (const brace-entry-open)
228 (const inexpr-class-open) (const inexpr-class-close))
202 (choice :tag "Action" 229 (choice :tag "Action"
203 (set :format "Insert a newline %v" 230 (set :format "Insert a newline %v"
204 :extra-offset 38 231 :extra-offset 38
@@ -310,19 +337,42 @@ this variable to nil."
310 :group 'c) 337 :group 'c)
311 338
312(defcustom c-default-style "gnu" 339(defcustom c-default-style "gnu"
313 "*Style which gets installed by default. 340 "*Style which gets installed by default when a file is visited.
314 341
315The value of this variable can be any style defined in 342The value of this variable can be any style defined in
316`c-style-alist', including styles you add, if you add them before CC 343`c-style-alist', including styles you add. The value can also be an
317Mode gets initialized. Note that if you set any CC Mode variables in 344association list of major mode symbols to style names.
318the top-level of your .emacs file (i.e. *not* in a hook), these get 345
319incorporated into the `user' style so you would need to add: 346When the value is a string, all CC Mode major modes will install this
347style by default, except `java-mode', which always installs the
348\"java\" style (this is for backwards compatibility).
349
350When the value is an alist, the named style is installed. If the
351major mode is not listed in the alist, then the symbol `other' is
352looked up in the alist, and if found, the associated style is used.
353If `other' is not found in the alist, then \"gnu\" style is used.
354
355Note that if you set any CC Mode variables in the top-level of your
356.emacs file (i.e. *not* in a hook), these get incorporated into the
357`user' style, so you would need to add:
320 358
321 (setq c-default-style \"user\") 359 (setq c-default-style '((other . \"user\")))
322 360
323to see your customizations. This is also true if you use the Custom 361to see your customizations. This is also true if you use the Custom
324interface -- be sure to set the default style to `user'." 362interface -- be sure to set the default style to `user'.
325 :type 'string 363
364Finally, the default style gets installed before your mode hooks run,
365so you can always override the use of `c-default-style' by making
366calls to `c-set-style' in the appropriate mode hook."
367 :type '(choice string
368 (repeat :tag "" :menu-tag "Major mode list"
369 (cons :tag ""
370 (choice :tag "Mode"
371 (const c-mode) (const c++-mode) (const objc-mode)
372 (const java-mode) (const idl-mode)
373 (const pike-mode) (const other))
374 (string :tag "Style")
375 )))
326 :group 'c) 376 :group 'c)
327 377
328(defcustom c-style-variables-are-local-p nil 378(defcustom c-style-variables-are-local-p nil
@@ -387,15 +437,14 @@ This hook is only run once per Emacs session and can be used as a
387 :type 'hook 437 :type 'hook
388 :group 'c) 438 :group 'c)
389 439
390(defcustom c-enable-xemacs-performance-kludge-p t 440(defcustom c-enable-xemacs-performance-kludge-p nil
391 "*Enables a XEmacs only hack that may improve speed for some coding styles. 441 "*Enables a XEmacs only hack that may improve speed for some coding styles.
392For styles that hang top-level opening braces (as is common with JDK 442For styles that hang top-level opening braces (as is common with JDK
393Java coding styles) this can improve performance between 3 and 60 443Java coding styles) this can improve performance between 3 and 60
394times for core indentation functions (e.g. `c-parse-state'). For 444times for core indentation functions (e.g. `c-parse-state'). For
395styles that conform to the Emacs recommendation of putting these 445styles that conform to the Emacs recommendation of putting these
396braces in column zero, this may slightly degrade performance in some 446braces in column zero, this can degrade performance about as much.
397situations, but only by a few percentage points. This variable only 447This variable only has effect in XEmacs.")
398has effect in XEmacs.")
399 448
400 449
401;; Non-customizable variables, still part of the interface to CC Mode 450;; Non-customizable variables, still part of the interface to CC Mode