Mercurial > hg > xemacs-beta
comparison lisp/cc-mode/cc-engine.el @ 171:929b76928fce r20-3b12
Import from CVS: tag r20-3b12
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:47:52 +0200 |
parents | 5a88923fcbfe |
children | 2d532a89d707 |
comparison
equal
deleted
inserted
replaced
170:98a42ee61975 | 171:929b76928fce |
---|---|
5 ;; Authors: 1992-1997 Barry A. Warsaw | 5 ;; Authors: 1992-1997 Barry A. Warsaw |
6 ;; 1987 Dave Detlefs and Stewart Clamen | 6 ;; 1987 Dave Detlefs and Stewart Clamen |
7 ;; 1985 Richard M. Stallman | 7 ;; 1985 Richard M. Stallman |
8 ;; Maintainer: cc-mode-help@python.org | 8 ;; Maintainer: cc-mode-help@python.org |
9 ;; Created: 22-Apr-1997 (split from cc-mode.el) | 9 ;; Created: 22-Apr-1997 (split from cc-mode.el) |
10 ;; Version: 5.11 | 10 ;; Version: 5.12 |
11 ;; Keywords: c languages oop | 11 ;; Keywords: c languages oop |
12 | 12 |
13 ;; This file is part of GNU Emacs. | 13 ;; This file is part of GNU Emacs. |
14 | 14 |
15 ;; GNU Emacs is free software; you can redistribute it and/or modify | 15 ;; GNU Emacs is free software; you can redistribute it and/or modify |
24 | 24 |
25 ;; You should have received a copy of the GNU General Public License | 25 ;; You should have received a copy of the GNU General Public License |
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the | 26 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
28 ;; Boston, MA 02111-1307, USA. | 28 ;; Boston, MA 02111-1307, USA. |
29 | |
30 | |
31 ;; utilities | |
32 (defmacro c-add-syntax (symbol &optional relpos) | |
33 ;; a simple macro to append the syntax in symbol to the syntax list. | |
34 ;; try to increase performance by using this macro | |
35 (` (setq syntax (cons (cons (, symbol) (, relpos)) syntax)))) | |
36 | |
37 (defsubst c-auto-newline () | |
38 ;; if auto-newline feature is turned on, insert a newline character | |
39 ;; and return t, otherwise return nil. | |
40 (and c-auto-newline | |
41 (not (c-in-literal)) | |
42 (not (newline)))) | |
43 | |
44 (defsubst c-intersect-lists (list alist) | |
45 ;; return the element of ALIST that matches the first element found | |
46 ;; in LIST. Uses assq. | |
47 (let (match) | |
48 (while (and list | |
49 (not (setq match (assq (car list) alist)))) | |
50 (setq list (cdr list))) | |
51 match)) | |
52 | |
53 (defsubst c-lookup-lists (list alist1 alist2) | |
54 ;; first, find the first entry from LIST that is present in ALIST1, | |
55 ;; then find the entry in ALIST2 for that entry. | |
56 (assq (car (c-intersect-lists list alist1)) alist2)) | |
57 | 29 |
58 | 30 |
59 ;; WARNING: Be *exceptionally* careful about modifications to this | 31 ;; WARNING: Be *exceptionally* careful about modifications to this |
60 ;; function! Much of CC Mode depends on this Doing The Right Thing. | 32 ;; function! Much of CC Mode depends on this Doing The Right Thing. |
61 ;; If you break it you will be sorry. | 33 ;; If you break it you will be sorry. |
72 ;; implemented. | 44 ;; implemented. |
73 maybe-labelp saved | 45 maybe-labelp saved |
74 (last-begin (point))) | 46 (last-begin (point))) |
75 ;; first check for bare semicolon | 47 ;; first check for bare semicolon |
76 (if (and (progn (c-backward-syntactic-ws lim) | 48 (if (and (progn (c-backward-syntactic-ws lim) |
77 (= (preceding-char) ?\;)) | 49 (eq (char-before) ?\;)) |
78 (c-safe (progn (forward-char -1) | 50 (c-safe (progn (forward-char -1) |
79 (setq saved (point)) | 51 (setq saved (point)) |
80 t)) | 52 t)) |
81 (progn (c-backward-syntactic-ws lim) | 53 (progn (c-backward-syntactic-ws lim) |
82 (memq (preceding-char) '(?\; ?{ ?} ?:))) | 54 (memq (char-before) '(?\; ?{ ?} ?:))) |
83 ) | 55 ) |
84 (setq last-begin saved) | 56 (setq last-begin saved) |
85 (goto-char last-begin) | 57 (goto-char last-begin) |
86 (while (not donep) | 58 (while (not donep) |
87 ;; stop at beginning of buffer | 59 ;; stop at beginning of buffer |
96 ;; skip over any unary operators, or other special | 68 ;; skip over any unary operators, or other special |
97 ;; characters appearing at front of identifier | 69 ;; characters appearing at front of identifier |
98 (save-excursion | 70 (save-excursion |
99 (c-backward-syntactic-ws lim) | 71 (c-backward-syntactic-ws lim) |
100 (skip-chars-backward "-+!*&:.~ \t\n") | 72 (skip-chars-backward "-+!*&:.~ \t\n") |
101 (if (= (preceding-char) ?\() | 73 (if (eq (char-before) ?\() |
102 (setq last-begin (point)))) | 74 (setq last-begin (point)))) |
103 (goto-char last-begin) | 75 (goto-char last-begin) |
104 (setq last-begin (point) | 76 (setq last-begin (point) |
105 donep t))) | 77 donep t))) |
106 | 78 |
115 (beginning-of-line)) | 87 (beginning-of-line)) |
116 ;; CASE 2: some other kind of literal? | 88 ;; CASE 2: some other kind of literal? |
117 ((c-in-literal lim)) | 89 ((c-in-literal lim)) |
118 ;; CASE 3: are we looking at a conditional keyword? | 90 ;; CASE 3: are we looking at a conditional keyword? |
119 ((or (looking-at c-conditional-key) | 91 ((or (looking-at c-conditional-key) |
120 (and (= (following-char) ?\() | 92 (and (eq (char-after) ?\() |
121 (save-excursion | 93 (save-excursion |
122 (forward-sexp 1) | 94 (forward-sexp 1) |
123 (c-forward-syntactic-ws) | 95 (c-forward-syntactic-ws) |
124 (/= (following-char) ?\;)) | 96 (not (eq (char-after) ?\;))) |
125 (let ((here (point)) | 97 (let ((here (point)) |
126 (foundp (progn | 98 (foundp (progn |
127 (c-backward-syntactic-ws lim) | 99 (c-backward-syntactic-ws lim) |
128 (forward-word -1) | 100 (forward-word -1) |
129 (and lim | 101 (and lim |
224 (while (and (not crossedp) | 196 (while (and (not crossedp) |
225 (< (point) to)) | 197 (< (point) to)) |
226 (skip-chars-forward "^;{}:" to) | 198 (skip-chars-forward "^;{}:" to) |
227 (if (not (c-in-literal lim)) | 199 (if (not (c-in-literal lim)) |
228 (progn | 200 (progn |
229 (if (memq (following-char) '(?\; ?{ ?})) | 201 (if (memq (char-after) '(?\; ?{ ?})) |
230 (setq crossedp t) | 202 (setq crossedp t) |
231 (if (= (following-char) ?:) | 203 (if (eq (char-after) ?:) |
232 (setq maybe-labelp t)) | 204 (setq maybe-labelp t)) |
233 (forward-char 1)) | 205 (forward-char 1)) |
234 (setq lim (point))) | 206 (setq lim (point))) |
235 (forward-char 1)))) | 207 (forward-char 1)))) |
236 (error (setq crossedp nil))) | 208 (error (setq crossedp nil))) |
253 (narrow-to-region lim (point)) | 225 (narrow-to-region lim (point)) |
254 (while (/= here (point)) | 226 (while (/= here (point)) |
255 (setq here (point)) | 227 (setq here (point)) |
256 (forward-comment hugenum) | 228 (forward-comment hugenum) |
257 ;; skip preprocessor directives | 229 ;; skip preprocessor directives |
258 (if (and (= (following-char) ?#) | 230 (if (and (eq (char-after) ?#) |
259 (= (c-point 'boi) (point))) | 231 (= (c-point 'boi) (point))) |
260 (end-of-line) | 232 (end-of-line) |
261 ))))) | 233 ))))) |
262 | 234 |
263 (defun c-backward-syntactic-ws (&optional lim) | 235 (defun c-backward-syntactic-ws (&optional lim) |
309 (setq c-in-literal-cache (vector (point) rtn))) | 281 (setq c-in-literal-cache (vector (point) rtn))) |
310 rtn))) | 282 rtn))) |
311 | 283 |
312 | 284 |
313 ;; utilities for moving and querying around syntactic elements | 285 ;; utilities for moving and querying around syntactic elements |
286 (defvar c-parsing-error nil) | |
314 | 287 |
315 (defun c-parse-state () | 288 (defun c-parse-state () |
316 ;; Finds and records all open parens between some important point | 289 ;; Finds and records all open parens between some important point |
317 ;; earlier in the file and point. | 290 ;; earlier in the file and point. |
318 ;; | 291 ;; |
319 ;; if there's a state cache, return it | 292 ;; if there's a state cache, return it |
293 (setq c-parsing-error nil) | |
320 (if (boundp 'c-state-cache) c-state-cache | 294 (if (boundp 'c-state-cache) c-state-cache |
321 (let* (at-bob | 295 (let* (at-bob |
322 (pos (save-excursion | 296 (pos (save-excursion |
323 ;; go back 2 bods, but ignore any bogus positions | 297 ;; go back 2 bods, but ignore any bogus positions |
324 ;; returned by beginning-of-defun (i.e. open paren | 298 ;; returned by beginning-of-defun (i.e. open paren |
325 ;; in column zero) | 299 ;; in column zero) |
326 (let ((cnt 2)) | 300 (let ((cnt 2)) |
327 (while (not (or at-bob (zerop cnt))) | 301 (while (not (or at-bob (zerop cnt))) |
328 (beginning-of-defun) | 302 (beginning-of-defun) |
329 (if (= (following-char) ?\{) | 303 (if (eq (char-after) ?\{) |
330 (setq cnt (1- cnt))) | 304 (setq cnt (1- cnt))) |
331 (if (bobp) | 305 (if (bobp) |
332 (setq at-bob t)))) | 306 (setq at-bob t)))) |
333 (point))) | 307 (point))) |
334 (here (save-excursion | 308 (here (save-excursion |
349 (<= sexp-end here)) | 323 (<= sexp-end here)) |
350 ;; we want to record both the start and end | 324 ;; we want to record both the start and end |
351 ;; of this sexp, but we only want to record | 325 ;; of this sexp, but we only want to record |
352 ;; the last-most of any of them before here | 326 ;; the last-most of any of them before here |
353 (progn | 327 (progn |
354 (if (= (char-after (1- pos)) ?\{) | 328 (if (eq (char-after (1- pos)) ?\{) |
355 (setq state (cons (cons (1- pos) sexp-end) | 329 (setq state (cons (cons (1- pos) sexp-end) |
356 (if (consp (car state)) | 330 (if (consp (car state)) |
357 (cdr state) | 331 (cdr state) |
358 state)))) | 332 state)))) |
359 (setq pos sexp-end)) | 333 (setq pos sexp-end)) |
367 (if (and (not pos) (not at-bob) | 341 (if (and (not pos) (not at-bob) |
368 (setq placeholder | 342 (setq placeholder |
369 (c-safe (scan-lists last-pos 1 1))) | 343 (c-safe (scan-lists last-pos 1 1))) |
370 ;;(char-after (1- placeholder)) | 344 ;;(char-after (1- placeholder)) |
371 (<= placeholder here) | 345 (<= placeholder here) |
372 (= (char-after (1- placeholder)) ?\})) | 346 (eq (char-after (1- placeholder)) ?\})) |
373 (while t | 347 (while t |
374 (setq last-bod (c-safe (scan-lists last-bod -1 1))) | 348 (setq last-bod (c-safe (scan-lists last-bod -1 1))) |
375 (if (not last-bod) | 349 (if (not last-bod) |
376 (error "unbalanced close brace at position %d" | 350 (progn |
377 (1- placeholder)) | 351 ;; bogus, but what can we do here? |
352 (setq c-parsing-error (1- placeholder)) | |
353 (throw 'backup-bod nil)) | |
378 (setq at-bob (= last-bod (point-min)) | 354 (setq at-bob (= last-bod (point-min)) |
379 pos last-bod) | 355 pos last-bod) |
380 (if (= (char-after last-bod) ?\{) | 356 (if (= (char-after last-bod) ?\{) |
381 (throw 'backup-bod t))) | 357 (throw 'backup-bod t))) |
382 )) ;end-if | 358 )) ;end-if |
470 (placeholder (progn | 446 (placeholder (progn |
471 (back-to-indentation) | 447 (back-to-indentation) |
472 (point)))) | 448 (point)))) |
473 (c-backward-syntactic-ws lim) | 449 (c-backward-syntactic-ws lim) |
474 (while (and (> (point) lim) | 450 (while (and (> (point) lim) |
475 (memq (preceding-char) '(?, ?:)) | 451 (memq (char-before) '(?, ?:)) |
476 (progn | 452 (progn |
477 (beginning-of-line) | 453 (beginning-of-line) |
478 (setq placeholder (point)) | 454 (setq placeholder (point)) |
479 (skip-chars-forward " \t") | 455 (skip-chars-forward " \t") |
480 (not (looking-at c-class-key)) | 456 (not (looking-at c-class-key)) |
507 (save-excursion | 483 (save-excursion |
508 (c-backward-syntactic-ws) | 484 (c-backward-syntactic-ws) |
509 (let ((checkpoint (or containing (point)))) | 485 (let ((checkpoint (or containing (point)))) |
510 (goto-char checkpoint) | 486 (goto-char checkpoint) |
511 ;; could be looking at const specifier | 487 ;; could be looking at const specifier |
512 (if (and (= (preceding-char) ?t) | 488 (if (and (eq (char-before) ?t) |
513 (forward-word -1) | 489 (forward-word -1) |
514 (looking-at "\\<const\\>")) | 490 (looking-at "\\<const\\>")) |
515 (c-backward-syntactic-ws) | 491 (c-backward-syntactic-ws) |
516 ;; otherwise, we could be looking at a hanging member init | 492 ;; otherwise, we could be looking at a hanging member init |
517 ;; colon | 493 ;; colon |
518 (goto-char checkpoint) | 494 (goto-char checkpoint) |
519 (if (and (= (preceding-char) ?:) | 495 (if (and (eq (char-before) ?:) |
520 (progn | 496 (progn |
521 (forward-char -1) | 497 (forward-char -1) |
522 (c-backward-syntactic-ws) | 498 (c-backward-syntactic-ws) |
523 (looking-at "[ \t\n]*:\\([^:]+\\|$\\)"))) | 499 (looking-at "[ \t\n]*:\\([^:]+\\|$\\)"))) |
524 nil | 500 nil |
525 (goto-char checkpoint)) | 501 (goto-char checkpoint)) |
526 ) | 502 ) |
527 (and (= (preceding-char) ?\)) | 503 (and (eq (char-before) ?\)) |
528 ;; check if we are looking at a method def | 504 ;; check if we are looking at a method def |
529 (or (not c-method-key) | 505 (or (not c-method-key) |
530 (progn | 506 (progn |
531 (forward-sexp -1) | 507 (forward-sexp -1) |
532 (forward-char -1) | 508 (forward-char -1) |
533 (c-backward-syntactic-ws) | 509 (c-backward-syntactic-ws) |
534 (not (or (= (preceding-char) ?-) | 510 (not (or (memq (char-before) '(?- ?+)) |
535 (= (preceding-char) ?+) | |
536 ;; or a class category | 511 ;; or a class category |
537 (progn | 512 (progn |
538 (forward-sexp -2) | 513 (forward-sexp -2) |
539 (looking-at c-class-key)) | 514 (looking-at c-class-key)) |
540 ))))) | 515 ))))) |
679 (error "consp search-end: %s" search-end)) | 654 (error "consp search-end: %s" search-end)) |
680 ;; if search-end is nil, or if the search-end character isn't an | 655 ;; if search-end is nil, or if the search-end character isn't an |
681 ;; open brace, we are definitely not in a class | 656 ;; open brace, we are definitely not in a class |
682 (if (or (not search-end) | 657 (if (or (not search-end) |
683 (< search-end (point-min)) | 658 (< search-end (point-min)) |
684 (/= (char-after search-end) ?{)) | 659 (not (eq (char-after search-end) ?{))) |
685 nil | 660 nil |
686 ;; now, we need to look more closely at search-start. if | 661 ;; now, we need to look more closely at search-start. if |
687 ;; search-start is nil, then our start boundary is really | 662 ;; search-start is nil, then our start boundary is really |
688 ;; point-min. | 663 ;; point-min. |
689 (if (not search-start) | 664 (if (not search-start) |
737 ((let ((skipchars "^;=)")) | 712 ((let ((skipchars "^;=)")) |
738 ;; try to see if we found the `class' keyword | 713 ;; try to see if we found the `class' keyword |
739 ;; inside a template arg list | 714 ;; inside a template arg list |
740 (save-excursion | 715 (save-excursion |
741 (skip-chars-backward "^<>" search-start) | 716 (skip-chars-backward "^<>" search-start) |
742 (if (= (preceding-char) ?<) | 717 (if (eq (char-before) ?<) |
743 (setq skipchars (concat skipchars ">")))) | 718 (setq skipchars (concat skipchars ">")))) |
744 (skip-chars-forward skipchars search-end) | 719 (skip-chars-forward skipchars search-end) |
745 (/= (point) search-end)) | 720 (/= (point) search-end)) |
746 (setq foundp nil)) | 721 (setq foundp nil)) |
747 ))) | 722 ))) |
783 (progn | 758 (progn |
784 (forward-sexp -1) | 759 (forward-sexp -1) |
785 (forward-sexp 1) | 760 (forward-sexp 1) |
786 (c-forward-syntactic-ws containing-sexp)) | 761 (c-forward-syntactic-ws containing-sexp)) |
787 (error (setq failedp t))) | 762 (error (setq failedp t))) |
788 (if (or failedp (/= (following-char) ?=)) | 763 (if (or failedp (not (eq (char-after) ?=))) |
789 ;; lets see if we're nested. find the most nested | 764 ;; lets see if we're nested. find the most nested |
790 ;; containing brace | 765 ;; containing brace |
791 (setq containing-sexp (car brace-state) | 766 (setq containing-sexp (car brace-state) |
792 brace-state (cdr brace-state)) | 767 brace-state (cdr brace-state)) |
793 ;; we've hit the beginning of the aggregate list | 768 ;; we've hit the beginning of the aggregate list |
915 | 890 |
916 ;; cache char before and after indent point, and move point to | 891 ;; cache char before and after indent point, and move point to |
917 ;; the most likely position to perform the majority of tests | 892 ;; the most likely position to perform the majority of tests |
918 (goto-char indent-point) | 893 (goto-char indent-point) |
919 (skip-chars-forward " \t") | 894 (skip-chars-forward " \t") |
920 (setq char-after-ip (following-char)) | 895 (setq char-after-ip (char-after)) |
921 (c-backward-syntactic-ws lim) | 896 (c-backward-syntactic-ws lim) |
922 (setq char-before-ip (preceding-char)) | 897 (setq char-before-ip (char-before)) |
923 (goto-char indent-point) | 898 (goto-char indent-point) |
924 (skip-chars-forward " \t") | 899 (skip-chars-forward " \t") |
925 | 900 |
926 ;; are we in a literal? | 901 ;; are we in a literal? |
927 (setq literal (c-in-literal lim)) | 902 (setq literal (c-in-literal lim)) |
947 ;; CASE 5: Line is at top level. | 922 ;; CASE 5: Line is at top level. |
948 ((null containing-sexp) | 923 ((null containing-sexp) |
949 (cond | 924 (cond |
950 ;; CASE 5A: we are looking at a defun, class, or | 925 ;; CASE 5A: we are looking at a defun, class, or |
951 ;; inline-inclass method opening brace | 926 ;; inline-inclass method opening brace |
952 ((= char-after-ip ?{) | 927 ((eq char-after-ip ?{) |
953 (cond | 928 (cond |
954 ;; CASE 5A.1: extern declaration | 929 ;; CASE 5A.1: extern declaration |
955 ((save-excursion | 930 ((save-excursion |
956 (goto-char indent-point) | 931 (goto-char indent-point) |
957 (skip-chars-forward " \t") | 932 (skip-chars-forward " \t") |
959 (looking-at "extern[^_]") | 934 (looking-at "extern[^_]") |
960 (progn | 935 (progn |
961 (setq placeholder (point)) | 936 (setq placeholder (point)) |
962 (forward-sexp 1) | 937 (forward-sexp 1) |
963 (c-forward-syntactic-ws) | 938 (c-forward-syntactic-ws) |
964 (= (following-char) ?\")))) | 939 (eq (char-after) ?\")))) |
965 (goto-char placeholder) | 940 (goto-char placeholder) |
966 (c-add-syntax 'extern-lang-open (c-point 'boi))) | 941 (c-add-syntax 'extern-lang-open (c-point 'boi))) |
967 ;; CASE 5A.2: we are looking at a class opening brace | 942 ;; CASE 5A.2: we are looking at a class opening brace |
968 ((save-excursion | 943 ((save-excursion |
969 (goto-char indent-point) | 944 (goto-char indent-point) |
994 (if (looking-at "typedef[^_]") | 969 (if (looking-at "typedef[^_]") |
995 (progn (forward-sexp 1) | 970 (progn (forward-sexp 1) |
996 (c-forward-syntactic-ws indent-point))) | 971 (c-forward-syntactic-ws indent-point))) |
997 (setq placeholder (c-point 'boi)) | 972 (setq placeholder (c-point 'boi)) |
998 (and (or (looking-at "enum[ \t\n]+") | 973 (and (or (looking-at "enum[ \t\n]+") |
999 (= char-before-ip ?=)) | 974 (eq char-before-ip ?=)) |
1000 (save-excursion | 975 (save-excursion |
1001 (skip-chars-forward "^;(" indent-point) | 976 (skip-chars-forward "^;(" indent-point) |
1002 (not (memq (following-char) '(?\; ?\())) | 977 (not (memq (char-after) '(?\; ?\())) |
1003 ))) | 978 ))) |
1004 (c-add-syntax 'brace-list-open placeholder)) | 979 (c-add-syntax 'brace-list-open placeholder)) |
1005 ;; CASE 5A.4: inline defun open | 980 ;; CASE 5A.4: inline defun open |
1006 ((and inclass-p (not inextern-p)) | 981 ((and inclass-p (not inextern-p)) |
1007 (c-add-syntax 'inline-open) | 982 (c-add-syntax 'inline-open) |
1013 ))) | 988 ))) |
1014 ;; CASE 5B: first K&R arg decl or member init | 989 ;; CASE 5B: first K&R arg decl or member init |
1015 ((c-just-after-func-arglist-p) | 990 ((c-just-after-func-arglist-p) |
1016 (cond | 991 (cond |
1017 ;; CASE 5B.1: a member init | 992 ;; CASE 5B.1: a member init |
1018 ((or (= char-before-ip ?:) | 993 ((or (eq char-before-ip ?:) |
1019 (= char-after-ip ?:)) | 994 (eq char-after-ip ?:)) |
1020 ;; this line should be indented relative to the beginning | 995 ;; this line should be indented relative to the beginning |
1021 ;; of indentation for the topmost-intro line that contains | 996 ;; of indentation for the topmost-intro line that contains |
1022 ;; the prototype's open paren | 997 ;; the prototype's open paren |
1023 ;; TBD: is the following redundant? | 998 ;; TBD: is the following redundant? |
1024 (if (= char-before-ip ?:) | 999 (if (eq char-before-ip ?:) |
1025 (forward-char -1)) | 1000 (forward-char -1)) |
1026 (c-backward-syntactic-ws lim) | 1001 (c-backward-syntactic-ws lim) |
1027 ;; TBD: is the preceding redundant? | 1002 ;; TBD: is the preceding redundant? |
1028 (if (= (preceding-char) ?:) | 1003 (if (eq (char-before) ?:) |
1029 (progn (forward-char -1) | 1004 (progn (forward-char -1) |
1030 (c-backward-syntactic-ws lim))) | 1005 (c-backward-syntactic-ws lim))) |
1031 (if (= (preceding-char) ?\)) | 1006 (if (eq (char-before) ?\)) |
1032 (backward-sexp 1)) | 1007 (backward-sexp 1)) |
1033 (setq placeholder (point)) | 1008 (setq placeholder (point)) |
1034 (save-excursion | 1009 (save-excursion |
1035 (and (c-safe (backward-sexp 1) t) | 1010 (and (c-safe (backward-sexp 1) t) |
1036 (looking-at "throw[^_]") | 1011 (looking-at "throw[^_]") |
1052 (c-add-syntax 'func-decl-cont (c-point 'boi)) | 1027 (c-add-syntax 'func-decl-cont (c-point 'boi)) |
1053 ))) | 1028 ))) |
1054 ;; CASE 5C: inheritance line. could be first inheritance | 1029 ;; CASE 5C: inheritance line. could be first inheritance |
1055 ;; line, or continuation of a multiple inheritance | 1030 ;; line, or continuation of a multiple inheritance |
1056 ((or (and c-baseclass-key (looking-at c-baseclass-key)) | 1031 ((or (and c-baseclass-key (looking-at c-baseclass-key)) |
1057 (and (or (= char-before-ip ?:) | 1032 (and (or (eq char-before-ip ?:) |
1058 ;; watch out for scope operator | 1033 ;; watch out for scope operator |
1059 (save-excursion | 1034 (save-excursion |
1060 (and (= char-after-ip ?:) | 1035 (and (eq char-after-ip ?:) |
1061 (c-safe (progn (forward-char 1) t)) | 1036 (c-safe (progn (forward-char 1) t)) |
1062 (/= (following-char) ?:) | 1037 (not (eq (char-after) ?:)) |
1063 ))) | 1038 ))) |
1064 (save-excursion | 1039 (save-excursion |
1065 (c-backward-syntactic-ws lim) | 1040 (c-backward-syntactic-ws lim) |
1066 (if (= char-before-ip ?:) | 1041 (if (eq char-before-ip ?:) |
1067 (progn | 1042 (progn |
1068 (forward-char -1) | 1043 (forward-char -1) |
1069 (c-backward-syntactic-ws lim))) | 1044 (c-backward-syntactic-ws lim))) |
1070 (back-to-indentation) | 1045 (back-to-indentation) |
1071 (looking-at c-class-key))) | 1046 (looking-at c-class-key))) |
1089 (not (c-crosses-statement-barrier-p (cdr injava-inher) | 1064 (not (c-crosses-statement-barrier-p (cdr injava-inher) |
1090 (point))) | 1065 (point))) |
1091 )) | 1066 )) |
1092 (cond | 1067 (cond |
1093 ;; CASE 5C.1: non-hanging colon on an inher intro | 1068 ;; CASE 5C.1: non-hanging colon on an inher intro |
1094 ((= char-after-ip ?:) | 1069 ((eq char-after-ip ?:) |
1095 (c-backward-syntactic-ws lim) | 1070 (c-backward-syntactic-ws lim) |
1096 (c-add-syntax 'inher-intro (c-point 'boi)) | 1071 (c-add-syntax 'inher-intro (c-point 'boi)) |
1097 ;; don't add inclass symbol since relative point already | 1072 ;; don't add inclass symbol since relative point already |
1098 ;; contains any class offset | 1073 ;; contains any class offset |
1099 ) | 1074 ) |
1100 ;; CASE 5C.2: hanging colon on an inher intro | 1075 ;; CASE 5C.2: hanging colon on an inher intro |
1101 ((= char-before-ip ?:) | 1076 ((eq char-before-ip ?:) |
1102 (c-add-syntax 'inher-intro (c-point 'boi)) | 1077 (c-add-syntax 'inher-intro (c-point 'boi)) |
1103 (and inclass-p (c-add-syntax 'inclass (aref inclass-p 0)))) | 1078 (and inclass-p (c-add-syntax 'inclass (aref inclass-p 0)))) |
1104 ;; CASE 5C.3: in a Java implements/extends | 1079 ;; CASE 5C.3: in a Java implements/extends |
1105 (injava-inher | 1080 (injava-inher |
1106 (let ((where (cdr injava-inher)) | 1081 (let ((where (cdr injava-inher)) |
1123 ;; don't add inclass symbol since relative point already | 1098 ;; don't add inclass symbol since relative point already |
1124 ;; contains any class offset | 1099 ;; contains any class offset |
1125 ))) | 1100 ))) |
1126 ;; CASE 5D: this could be a top-level compound statement or a | 1101 ;; CASE 5D: this could be a top-level compound statement or a |
1127 ;; member init list continuation | 1102 ;; member init list continuation |
1128 ((= char-before-ip ?,) | 1103 ((eq char-before-ip ?,) |
1129 (goto-char indent-point) | 1104 (goto-char indent-point) |
1130 (c-backward-syntactic-ws lim) | 1105 (c-backward-syntactic-ws lim) |
1131 (while (and (< lim (point)) | 1106 (while (and (< lim (point)) |
1132 (= (preceding-char) ?,)) | 1107 (eq (char-before) ?,)) |
1133 ;; this will catch member inits with multiple | 1108 ;; this will catch member inits with multiple |
1134 ;; line arglists | 1109 ;; line arglists |
1135 (forward-char -1) | 1110 (forward-char -1) |
1136 (c-backward-syntactic-ws (c-point 'bol)) | 1111 (c-backward-syntactic-ws (c-point 'bol)) |
1137 (if (= (preceding-char) ?\)) | 1112 (if (eq (char-before) ?\)) |
1138 (backward-sexp 1)) | 1113 (backward-sexp 1)) |
1139 ;; now continue checking | 1114 ;; now continue checking |
1140 (beginning-of-line) | 1115 (beginning-of-line) |
1141 (c-backward-syntactic-ws lim)) | 1116 (c-backward-syntactic-ws lim)) |
1142 (cond | 1117 (cond |
1143 ;; CASE 5D.1: hanging member init colon, but watch out | 1118 ;; CASE 5D.1: hanging member init colon, but watch out |
1144 ;; for bogus matches on access specifiers inside classes. | 1119 ;; for bogus matches on access specifiers inside classes. |
1145 ((and (= (preceding-char) ?:) | 1120 ((and (eq (char-before) ?:) |
1146 (save-excursion | 1121 (save-excursion |
1147 (forward-word -1) | 1122 (forward-word -1) |
1148 (not (looking-at c-access-key)))) | 1123 (not (looking-at c-access-key)))) |
1149 (goto-char indent-point) | 1124 (goto-char indent-point) |
1150 (c-backward-syntactic-ws lim) | 1125 (c-backward-syntactic-ws lim) |
1154 ;; point is the member init above us | 1129 ;; point is the member init above us |
1155 ) | 1130 ) |
1156 ;; CASE 5D.2: non-hanging member init colon | 1131 ;; CASE 5D.2: non-hanging member init colon |
1157 ((progn | 1132 ((progn |
1158 (c-forward-syntactic-ws indent-point) | 1133 (c-forward-syntactic-ws indent-point) |
1159 (= (following-char) ?:)) | 1134 (eq (char-after) ?:)) |
1160 (skip-chars-forward " \t:") | 1135 (skip-chars-forward " \t:") |
1161 (c-add-syntax 'member-init-cont (point))) | 1136 (c-add-syntax 'member-init-cont (point))) |
1162 ;; CASE 5D.3: perhaps a multiple inheritance line? | 1137 ;; CASE 5D.3: perhaps a multiple inheritance line? |
1163 ((looking-at c-inher-key) | 1138 ((looking-at c-inher-key) |
1164 (c-add-syntax 'inher-cont (c-point 'boi))) | 1139 (c-add-syntax 'inher-cont (c-point 'boi))) |
1165 ;; CASE 5D.4: perhaps a template list continuation? | 1140 ;; CASE 5D.4: perhaps a template list continuation? |
1166 ((save-excursion | 1141 ((save-excursion |
1167 (skip-chars-backward "^<" lim) | 1142 (skip-chars-backward "^<" lim) |
1168 ;; not sure if this is the right test, but it should | 1143 ;; not sure if this is the right test, but it should |
1169 ;; be fast and mostly accurate. | 1144 ;; be fast and mostly accurate. |
1170 (and (= (preceding-char) ?<) | 1145 (and (eq (char-before) ?<) |
1171 (not (c-in-literal lim)))) | 1146 (not (c-in-literal lim)))) |
1172 ;; we can probably indent it just like and arglist-cont | 1147 ;; we can probably indent it just like and arglist-cont |
1173 (c-add-syntax 'arglist-cont (point))) | 1148 (c-add-syntax 'arglist-cont (point))) |
1174 ;; CASE 5D.5: perhaps a top-level statement-cont | 1149 ;; CASE 5D.5: perhaps a top-level statement-cont |
1175 (t | 1150 (t |
1188 (looking-at c-access-key)) | 1163 (looking-at c-access-key)) |
1189 (c-add-syntax 'access-label (c-point 'bonl)) | 1164 (c-add-syntax 'access-label (c-point 'bonl)) |
1190 (c-add-syntax 'inclass (aref inclass-p 0))) | 1165 (c-add-syntax 'inclass (aref inclass-p 0))) |
1191 ;; CASE 5F: extern-lang-close? | 1166 ;; CASE 5F: extern-lang-close? |
1192 ((and inextern-p | 1167 ((and inextern-p |
1193 (= char-after-ip ?})) | 1168 (eq char-after-ip ?})) |
1194 (c-add-syntax 'extern-lang-close (aref inclass-p 1))) | 1169 (c-add-syntax 'extern-lang-close (aref inclass-p 1))) |
1195 ;; CASE 5G: we are looking at the brace which closes the | 1170 ;; CASE 5G: we are looking at the brace which closes the |
1196 ;; enclosing nested class decl | 1171 ;; enclosing nested class decl |
1197 ((and inclass-p | 1172 ((and inclass-p |
1198 (= char-after-ip ?}) | 1173 (eq char-after-ip ?}) |
1199 (save-excursion | 1174 (save-excursion |
1200 (save-restriction | 1175 (save-restriction |
1201 (widen) | 1176 (widen) |
1202 (forward-char 1) | 1177 (forward-char 1) |
1203 (and | 1178 (and |
1221 (re-search-backward "^[^ \^L\t\n#]" nil 'move) | 1196 (re-search-backward "^[^ \^L\t\n#]" nil 'move) |
1222 (point)))) | 1197 (point)))) |
1223 (save-excursion | 1198 (save-excursion |
1224 (c-backward-syntactic-ws limit) | 1199 (c-backward-syntactic-ws limit) |
1225 (setq placeholder (point)) | 1200 (setq placeholder (point)) |
1226 (while (and (memq (preceding-char) '(?\; ?,)) | 1201 (while (and (memq (char-before) '(?\; ?,)) |
1227 (> (point) limit)) | 1202 (> (point) limit)) |
1228 (beginning-of-line) | 1203 (beginning-of-line) |
1229 (setq placeholder (point)) | 1204 (setq placeholder (point)) |
1230 (c-backward-syntactic-ws limit)) | 1205 (c-backward-syntactic-ws limit)) |
1231 (and (= (preceding-char) ?\)) | 1206 (and (eq (char-before) ?\)) |
1232 (or (not c-method-key) | 1207 (or (not c-method-key) |
1233 (progn | 1208 (progn |
1234 (forward-sexp -1) | 1209 (forward-sexp -1) |
1235 (forward-char -1) | 1210 (forward-char -1) |
1236 (c-backward-syntactic-ws) | 1211 (c-backward-syntactic-ws) |
1237 (not (or (= (preceding-char) ?-) | 1212 (not (or (memq (char-before) '(?- ?+)) |
1238 (= (preceding-char) ?+) | |
1239 ;; or a class category | 1213 ;; or a class category |
1240 (progn | 1214 (progn |
1241 (forward-sexp -2) | 1215 (forward-sexp -2) |
1242 (looking-at c-class-key)) | 1216 (looking-at c-class-key)) |
1243 ))))) | 1217 ))))) |
1258 (c-safe (progn (backward-sexp 1) t)) | 1232 (c-safe (progn (backward-sexp 1) t)) |
1259 (looking-at c-access-key))) | 1233 (looking-at c-access-key))) |
1260 (backward-sexp 1) | 1234 (backward-sexp 1) |
1261 (c-backward-syntactic-ws lim)) | 1235 (c-backward-syntactic-ws lim)) |
1262 (or (bobp) | 1236 (or (bobp) |
1263 (memq (preceding-char) '(?\; ?\})))) | 1237 (memq (char-before) '(?\; ?\})))) |
1264 ;; real beginning-of-line could be narrowed out due to | 1238 ;; real beginning-of-line could be narrowed out due to |
1265 ;; enclosure in a class block | 1239 ;; enclosure in a class block |
1266 (save-restriction | 1240 (save-restriction |
1267 (widen) | 1241 (widen) |
1268 (c-add-syntax 'topmost-intro (c-point 'bol)) | 1242 (c-add-syntax 'topmost-intro (c-point 'bol)) |
1288 (c-add-syntax 'topmost-intro-cont (c-point 'boi))) | 1262 (c-add-syntax 'topmost-intro-cont (c-point 'boi))) |
1289 )) ; end CASE 5 | 1263 )) ; end CASE 5 |
1290 ;; CASE 6: line is an expression, not a statement. Most | 1264 ;; CASE 6: line is an expression, not a statement. Most |
1291 ;; likely we are either in a function prototype or a function | 1265 ;; likely we are either in a function prototype or a function |
1292 ;; call argument list | 1266 ;; call argument list |
1293 ((/= (char-after containing-sexp) ?{) | 1267 ((not (eq (char-after containing-sexp) ?{)) |
1294 (c-backward-syntactic-ws containing-sexp) | 1268 (c-backward-syntactic-ws containing-sexp) |
1295 (cond | 1269 (cond |
1296 ;; CASE 6A: we are looking at the arglist closing paren | 1270 ;; CASE 6A: we are looking at the arglist closing paren |
1297 ((and (/= char-before-ip ?,) | 1271 ((and (not (eq char-before-ip ?,)) |
1298 (memq char-after-ip '(?\) ?\]))) | 1272 (memq char-after-ip '(?\) ?\]))) |
1299 (goto-char containing-sexp) | 1273 (goto-char containing-sexp) |
1300 (c-add-syntax 'arglist-close (c-point 'boi))) | 1274 (c-add-syntax 'arglist-close (c-point 'boi))) |
1301 ;; CASE 6B: we are looking at the first argument in an empty | 1275 ;; CASE 6B: we are looking at the first argument in an empty |
1302 ;; argument list. Use arglist-close if we're actually | 1276 ;; argument list. Use arglist-close if we're actually |
1311 (and (c-safe (progn (forward-sexp -1) t)) | 1285 (and (c-safe (progn (forward-sexp -1) t)) |
1312 (looking-at "\\<for\\>[^_]"))) | 1286 (looking-at "\\<for\\>[^_]"))) |
1313 (goto-char (1+ containing-sexp)) | 1287 (goto-char (1+ containing-sexp)) |
1314 (c-forward-syntactic-ws indent-point) | 1288 (c-forward-syntactic-ws indent-point) |
1315 (c-beginning-of-statement-1 containing-sexp) | 1289 (c-beginning-of-statement-1 containing-sexp) |
1316 (if (= char-before-ip ?\;) | 1290 (if (eq char-before-ip ?\;) |
1317 (c-add-syntax 'statement (point)) | 1291 (c-add-syntax 'statement (point)) |
1318 (c-add-syntax 'statement-cont (point)) | 1292 (c-add-syntax 'statement-cont (point)) |
1319 )) | 1293 )) |
1320 ;; CASE 6D: maybe a continued method call. This is the case | 1294 ;; CASE 6D: maybe a continued method call. This is the case |
1321 ;; when we are inside a [] bracketed exp, and what precede | 1295 ;; when we are inside a [] bracketed exp, and what precede |
1322 ;; the opening bracket is not an identifier. | 1296 ;; the opening bracket is not an identifier. |
1323 ((and c-method-key | 1297 ((and c-method-key |
1324 (= (char-after containing-sexp) ?\[) | 1298 (eq (char-after containing-sexp) ?\[) |
1325 (save-excursion | 1299 (save-excursion |
1326 (goto-char (1- containing-sexp)) | 1300 (goto-char (1- containing-sexp)) |
1327 (c-backward-syntactic-ws (c-point 'bod)) | 1301 (c-backward-syntactic-ws (c-point 'bod)) |
1328 (if (not (looking-at c-symbol-key)) | 1302 (if (not (looking-at c-symbol-key)) |
1329 (c-add-syntax 'objc-method-call-cont containing-sexp)) | 1303 (c-add-syntax 'objc-method-call-cont containing-sexp)) |
1358 (looking-at c-baseclass-key))) | 1332 (looking-at c-baseclass-key))) |
1359 (goto-char indent-point) | 1333 (goto-char indent-point) |
1360 (skip-chars-forward " \t") | 1334 (skip-chars-forward " \t") |
1361 (cond | 1335 (cond |
1362 ;; CASE 7A: non-hanging colon on an inher intro | 1336 ;; CASE 7A: non-hanging colon on an inher intro |
1363 ((= char-after-ip ?:) | 1337 ((eq char-after-ip ?:) |
1364 (c-backward-syntactic-ws lim) | 1338 (c-backward-syntactic-ws lim) |
1365 (c-add-syntax 'inher-intro (c-point 'boi))) | 1339 (c-add-syntax 'inher-intro (c-point 'boi))) |
1366 ;; CASE 7B: hanging colon on an inher intro | 1340 ;; CASE 7B: hanging colon on an inher intro |
1367 ((= char-before-ip ?:) | 1341 ((eq char-before-ip ?:) |
1368 (c-add-syntax 'inher-intro (c-point 'boi))) | 1342 (c-add-syntax 'inher-intro (c-point 'boi))) |
1369 ;; CASE 7C: a continued inheritance line | 1343 ;; CASE 7C: a continued inheritance line |
1370 (t | 1344 (t |
1371 (c-beginning-of-inheritance-list lim) | 1345 (c-beginning-of-inheritance-list lim) |
1372 (c-add-syntax 'inher-cont (point)) | 1346 (c-add-syntax 'inher-cont (point)) |
1373 ))) | 1347 ))) |
1374 ;; CASE 8: we are inside a brace-list | 1348 ;; CASE 8: we are inside a brace-list |
1375 ((setq placeholder (c-inside-bracelist-p containing-sexp state)) | 1349 ((setq placeholder (c-inside-bracelist-p containing-sexp state)) |
1376 (cond | 1350 (cond |
1377 ;; CASE 8A: brace-list-close brace | 1351 ;; CASE 8A: brace-list-close brace |
1378 ((and (= char-after-ip ?}) | 1352 ((and (eq char-after-ip ?}) |
1379 (c-safe (progn (forward-char 1) | 1353 (c-safe (progn (forward-char 1) |
1380 (backward-sexp 1) | 1354 (backward-sexp 1) |
1381 t)) | 1355 t)) |
1382 (= (point) containing-sexp)) | 1356 (= (point) containing-sexp)) |
1383 (c-add-syntax 'brace-list-close (c-point 'boi))) | 1357 (c-add-syntax 'brace-list-close (c-point 'boi))) |
1385 ((save-excursion | 1359 ((save-excursion |
1386 (goto-char indent-point) | 1360 (goto-char indent-point) |
1387 (c-backward-syntactic-ws containing-sexp) | 1361 (c-backward-syntactic-ws containing-sexp) |
1388 (= (point) (1+ containing-sexp))) | 1362 (= (point) (1+ containing-sexp))) |
1389 (goto-char containing-sexp) | 1363 (goto-char containing-sexp) |
1390 ;;(if (= char-after-ip ?{) | |
1391 ;;(c-add-syntax 'brace-list-open (c-point 'boi)) | |
1392 (c-add-syntax 'brace-list-intro (c-point 'boi)) | 1364 (c-add-syntax 'brace-list-intro (c-point 'boi)) |
1393 ) | 1365 ) |
1394 ;;)) ; end CASE 8B | 1366 ;;)) ; end CASE 8B |
1395 ;; CASE 8C: this is just a later brace-list-entry | 1367 ;; CASE 8C: this is just a later brace-list-entry |
1396 (t (goto-char (1+ containing-sexp)) | 1368 (t (goto-char (1+ containing-sexp)) |
1397 (c-forward-syntactic-ws indent-point) | 1369 (c-forward-syntactic-ws indent-point) |
1398 (if (= char-after-ip ?{) | 1370 (if (eq char-after-ip ?{) |
1399 (c-add-syntax 'brace-list-open (point)) | 1371 (c-add-syntax 'brace-list-open (point)) |
1400 (c-add-syntax 'brace-list-entry (point)) | 1372 (c-add-syntax 'brace-list-entry (point)) |
1401 )) ; end CASE 8C | 1373 )) ; end CASE 8C |
1402 )) ; end CASE 8 | 1374 )) ; end CASE 8 |
1403 ;; CASE 9: A continued statement | 1375 ;; CASE 9: A continued statement |
1414 (goto-char placeholder) | 1386 (goto-char placeholder) |
1415 (if (looking-at c-conditional-key) | 1387 (if (looking-at c-conditional-key) |
1416 (progn | 1388 (progn |
1417 (c-safe (c-skip-conditional)) | 1389 (c-safe (c-skip-conditional)) |
1418 (c-forward-syntactic-ws) | 1390 (c-forward-syntactic-ws) |
1419 (if (memq (following-char) '(?\;)) | 1391 (if (eq (char-after) ?\;) |
1420 (progn | 1392 (progn |
1421 (forward-char 1) | 1393 (forward-char 1) |
1422 (c-forward-syntactic-ws))) | 1394 (c-forward-syntactic-ws))) |
1423 (point)) | 1395 (point)) |
1424 nil)))) | 1396 nil)))) |
1425 (cond | 1397 (cond |
1426 ;; CASE 9A: substatement | 1398 ;; CASE 9A: substatement |
1427 ((and after-cond-placeholder | 1399 ((and after-cond-placeholder |
1428 (>= after-cond-placeholder indent-point)) | 1400 (>= after-cond-placeholder indent-point)) |
1429 (goto-char placeholder) | 1401 (goto-char placeholder) |
1430 (if (= char-after-ip ?{) | 1402 (if (eq char-after-ip ?{) |
1431 (c-add-syntax 'substatement-open (c-point 'boi)) | 1403 (c-add-syntax 'substatement-open (c-point 'boi)) |
1432 (c-add-syntax 'substatement (c-point 'boi)))) | 1404 (c-add-syntax 'substatement (c-point 'boi)))) |
1433 ;; CASE 9B: open braces for class or brace-lists | 1405 ;; CASE 9B: open braces for class or brace-lists |
1434 ((= char-after-ip ?{) | 1406 ((eq char-after-ip ?{) |
1435 (cond | 1407 (cond |
1436 ;; CASE 9B.1: class-open | 1408 ;; CASE 9B.1: class-open |
1437 ((save-excursion | 1409 ((save-excursion |
1438 (goto-char indent-point) | 1410 (goto-char indent-point) |
1439 (skip-chars-forward " \t{") | 1411 (skip-chars-forward " \t{") |
1444 (c-add-syntax 'class-open placeholder)) | 1416 (c-add-syntax 'class-open placeholder)) |
1445 ;; CASE 9B.2: brace-list-open | 1417 ;; CASE 9B.2: brace-list-open |
1446 ((or (save-excursion | 1418 ((or (save-excursion |
1447 (goto-char placeholder) | 1419 (goto-char placeholder) |
1448 (looking-at "\\<enum\\>")) | 1420 (looking-at "\\<enum\\>")) |
1449 (= char-before-ip ?=)) | 1421 (eq char-before-ip ?=)) |
1450 (c-add-syntax 'brace-list-open placeholder)) | 1422 (c-add-syntax 'brace-list-open placeholder)) |
1451 ;; CASE 9B.3: catch-all for unknown construct. | 1423 ;; CASE 9B.3: catch-all for unknown construct. |
1452 (t | 1424 (t |
1453 ;; Can and should I add an extensibility hook here? | 1425 ;; Can and should I add an extensibility hook here? |
1454 ;; Something like c-recognize-hook so support for | 1426 ;; Something like c-recognize-hook so support for |
1512 ((looking-at c-label-key) | 1484 ((looking-at c-label-key) |
1513 (goto-char containing-sexp) | 1485 (goto-char containing-sexp) |
1514 (c-add-syntax 'label (c-point 'boi))) | 1486 (c-add-syntax 'label (c-point 'boi))) |
1515 ;; CASE 14: block close brace, possibly closing the defun or | 1487 ;; CASE 14: block close brace, possibly closing the defun or |
1516 ;; the class | 1488 ;; the class |
1517 ((= char-after-ip ?}) | 1489 ((eq char-after-ip ?}) |
1518 (let* ((lim (c-safe-position containing-sexp fullstate)) | 1490 (let* ((lim (c-safe-position containing-sexp fullstate)) |
1519 (relpos (save-excursion | 1491 (relpos (save-excursion |
1520 (goto-char containing-sexp) | 1492 (goto-char containing-sexp) |
1521 (if (/= (point) (c-point 'boi)) | 1493 (if (/= (point) (c-point 'boi)) |
1522 (c-beginning-of-statement-1 lim)) | 1494 (c-beginning-of-statement-1 lim)) |
1576 (back-to-indentation) | 1548 (back-to-indentation) |
1577 (setq placeholder (point)) | 1549 (setq placeholder (point)) |
1578 (looking-at c-switch-label-key))) | 1550 (looking-at c-switch-label-key))) |
1579 (goto-char indent-point) | 1551 (goto-char indent-point) |
1580 (skip-chars-forward " \t") | 1552 (skip-chars-forward " \t") |
1581 (if (= (following-char) ?{) | 1553 (if (eq (char-after) ?{) |
1582 (c-add-syntax 'statement-case-open placeholder) | 1554 (c-add-syntax 'statement-case-open placeholder) |
1583 (c-add-syntax 'statement-case-intro placeholder))) | 1555 (c-add-syntax 'statement-case-intro placeholder))) |
1584 ;; CASE 15B: continued statement | 1556 ;; CASE 15B: continued statement |
1585 ((= char-before-ip ?,) | 1557 ((eq char-before-ip ?,) |
1586 (c-add-syntax 'statement-cont (c-point 'boi))) | 1558 (c-add-syntax 'statement-cont (c-point 'boi))) |
1587 ;; CASE 15C: a question/colon construct? But make sure | 1559 ;; CASE 15C: a question/colon construct? But make sure |
1588 ;; what came before was not a label, and what comes after | 1560 ;; what came before was not a label, and what comes after |
1589 ;; is not a globally scoped function call! | 1561 ;; is not a globally scoped function call! |
1590 ((or (and (memq char-before-ip '(?: ??)) | 1562 ((or (and (memq char-before-ip '(?: ??)) |
1606 relpos done) | 1578 relpos done) |
1607 (goto-char indent-point) | 1579 (goto-char indent-point) |
1608 (c-beginning-of-statement-1 safepos) | 1580 (c-beginning-of-statement-1 safepos) |
1609 ;; It is possible we're on the brace that opens a nested | 1581 ;; It is possible we're on the brace that opens a nested |
1610 ;; function. | 1582 ;; function. |
1611 (if (and (= (following-char) ?{) | 1583 (if (and (eq (char-after) ?{) |
1612 (save-excursion | 1584 (save-excursion |
1613 (c-backward-syntactic-ws safepos) | 1585 (c-backward-syntactic-ws safepos) |
1614 (/= (preceding-char) ?\;))) | 1586 (not (eq (char-before) ?\;)))) |
1615 (c-beginning-of-statement-1 safepos)) | 1587 (c-beginning-of-statement-1 safepos)) |
1616 (if (and inswitch-p | 1588 (if (and inswitch-p |
1617 (looking-at c-switch-label-key)) | 1589 (looking-at c-switch-label-key)) |
1618 (progn | 1590 (progn |
1619 (goto-char placeholder) | 1591 (goto-char placeholder) |
1626 (c-beginning-of-statement-1 safepos) | 1598 (c-beginning-of-statement-1 safepos) |
1627 (if (= relpos (c-point 'boi)) | 1599 (if (= relpos (c-point 'boi)) |
1628 (setq done t)) | 1600 (setq done t)) |
1629 (setq relpos (c-point 'boi))) | 1601 (setq relpos (c-point 'boi))) |
1630 (c-add-syntax 'statement relpos) | 1602 (c-add-syntax 'statement relpos) |
1631 (if (= char-after-ip ?{) | 1603 (if (eq char-after-ip ?{) |
1632 (c-add-syntax 'block-open)))) | 1604 (c-add-syntax 'block-open)))) |
1633 ;; CASE 15E: first statement in an inline, or first | 1605 ;; CASE 15E: first statement in an inline, or first |
1634 ;; statement in a top-level defun. we can tell this is it | 1606 ;; statement in a top-level defun. we can tell this is it |
1635 ;; if there are no enclosing braces that haven't been | 1607 ;; if there are no enclosing braces that haven't been |
1636 ;; narrowed out by a class (i.e. don't use bod here!) | 1608 ;; narrowed out by a class (i.e. don't use bod here!) |
1644 ;; if not at boi, then defun-opening braces are hung on | 1616 ;; if not at boi, then defun-opening braces are hung on |
1645 ;; right side, so we need a different relpos | 1617 ;; right side, so we need a different relpos |
1646 (if (/= (point) (c-point 'boi)) | 1618 (if (/= (point) (c-point 'boi)) |
1647 (progn | 1619 (progn |
1648 (c-backward-syntactic-ws) | 1620 (c-backward-syntactic-ws) |
1649 (c-safe (forward-sexp (if (= (preceding-char) ?\)) | 1621 (c-safe (forward-sexp (if (eq (char-before) ?\)) |
1650 -1 -2))) | 1622 -1 -2))) |
1651 ;; looking at a Java throws clause following a | 1623 ;; looking at a Java throws clause following a |
1652 ;; method's parameter list | 1624 ;; method's parameter list |
1653 (c-beginning-of-statement-1) | 1625 (c-beginning-of-statement-1) |
1654 )) | 1626 )) |
1658 (if (/= (point) (c-point 'boi)) | 1630 (if (/= (point) (c-point 'boi)) |
1659 (c-beginning-of-statement-1 | 1631 (c-beginning-of-statement-1 |
1660 (if (= (point) lim) | 1632 (if (= (point) lim) |
1661 (c-safe-position (point) state) lim))) | 1633 (c-safe-position (point) state) lim))) |
1662 (c-add-syntax 'statement-block-intro (c-point 'boi)) | 1634 (c-add-syntax 'statement-block-intro (c-point 'boi)) |
1663 (if (= char-after-ip ?{) | 1635 (if (eq char-after-ip ?{) |
1664 (c-add-syntax 'block-open))) | 1636 (c-add-syntax 'block-open))) |
1665 )) | 1637 )) |
1666 ) | 1638 ) |
1667 | 1639 |
1668 ;; now we need to look at any modifiers | 1640 ;; now we need to look at any modifiers |
1677 (c-add-syntax 'friend)) | 1649 (c-add-syntax 'friend)) |
1678 ;; return the syntax | 1650 ;; return the syntax |
1679 syntax)))) | 1651 syntax)))) |
1680 | 1652 |
1681 | 1653 |
1654 (defun c-echo-parsing-error () | |
1655 (if (not c-parsing-error) | |
1656 nil | |
1657 (message "unbalanced close brace at bufpos %d -- INDENTATION IS SUSPECT!" | |
1658 c-parsing-error) | |
1659 (ding)) | |
1660 c-parsing-error) | |
1661 | |
1682 ;; indent via syntactic language elements | 1662 ;; indent via syntactic language elements |
1683 (defun c-indent-line (&optional syntax) | 1663 (defun c-indent-line (&optional syntax) |
1684 ;; indent the current line as C/C++/ObjC code. Optional SYNTAX is the | 1664 ;; indent the current line as C/C++/ObjC code. Optional SYNTAX is the |
1685 ;; syntactic information for the current line. Returns the amount of | 1665 ;; syntactic information for the current line. Returns the amount of |
1686 ;; indentation change | 1666 ;; indentation change |
1687 (let* ((c-syntactic-context (or syntax (c-guess-basic-syntax))) | 1667 (let* ((c-syntactic-context (or syntax (c-guess-basic-syntax))) |
1688 (pos (- (point-max) (point))) | 1668 (pos (- (point-max) (point))) |
1689 (indent (apply '+ (mapcar 'c-get-offset c-syntactic-context))) | 1669 (indent (apply '+ (mapcar 'c-get-offset c-syntactic-context))) |
1690 (shift-amt (- (current-indentation) indent))) | 1670 (shift-amt (- (current-indentation) indent))) |
1691 (and c-echo-syntactic-information-p | 1671 (and c-echo-syntactic-information-p |
1672 (not (c-echo-parsing-error)) | |
1692 (message "syntax: %s, indent= %d" c-syntactic-context indent)) | 1673 (message "syntax: %s, indent= %d" c-syntactic-context indent)) |
1693 (if (zerop shift-amt) | 1674 (if (zerop shift-amt) |
1694 nil | 1675 nil |
1695 (delete-region (c-point 'bol) (c-point 'boi)) | 1676 (delete-region (c-point 'bol) (c-point 'boi)) |
1696 (beginning-of-line) | 1677 (beginning-of-line) |
1709 "Show syntactic information for current line. | 1690 "Show syntactic information for current line. |
1710 With universal argument, inserts the analysis as a comment on that line." | 1691 With universal argument, inserts the analysis as a comment on that line." |
1711 (interactive "P") | 1692 (interactive "P") |
1712 (let ((syntax (c-guess-basic-syntax))) | 1693 (let ((syntax (c-guess-basic-syntax))) |
1713 (if (not (consp arg)) | 1694 (if (not (consp arg)) |
1714 (message "syntactic analysis: %s" syntax) | 1695 (if (not (c-echo-parsing-error)) |
1696 (message "syntactic analysis: %s" syntax)) | |
1715 (indent-for-comment) | 1697 (indent-for-comment) |
1716 (insert (format "%s" syntax)) | 1698 (insert (format "%s" syntax)) |
1717 )) | 1699 )) |
1718 (c-keep-region-active)) | 1700 (c-keep-region-active)) |
1719 | 1701 |