diff options
| author | Gerd Moellmann | 2000-07-24 11:11:20 +0000 |
|---|---|---|
| committer | Gerd Moellmann | 2000-07-24 11:11:20 +0000 |
| commit | ce8c7486aa4e5de4394748abf594a8a160f7f8fc (patch) | |
| tree | 1aa050f096caeabec9c2316400921956afcc97a9 | |
| parent | e29cacf2d11d0e10fdec4d56604cbb7572d4e5b0 (diff) | |
| download | emacs-ce8c7486aa4e5de4394748abf594a8a160f7f8fc.tar.gz emacs-ce8c7486aa4e5de4394748abf594a8a160f7f8fc.zip | |
(c-looking-at-inexpr-block): Replaced a call to
c-beginning-of-statement-1 that caused a bad case of recursion
which could consume a lot of CPU in large classes in languages
that have in-expression classes (i.e. Java and Pike).
(c-guess-basic-syntax): Check for in-expression
statements before top level constructs (i.e. case 6 is moved
before case 5 and is now case 4) to catch in-expression
classes in top level expressions correctly.
(c-guess-basic-syntax): Less naive handling of
objc-method-intro. Case 4 removed and case 5I added.
(c-beginning-of-inheritance-list,
c-guess-basic-syntax): Fixed recognition of inheritance lists
when the lines begins with a comma.
(c-forward-syntactic-ws): Fixed an infloop bug
when the buffer ends with a macro continuation char.
(c-guess-basic-syntax): Added support for
function definitions as statements in Pike. The first
statement in a lambda block is now labeled defun-block-intro
instead of statement-block-intro.
(c-narrow-out-enclosing-class): Whack the state
so that the class surrounding point is selected, not the one
innermost in the state.
(c-guess-basic-syntax): Fixed bug in
recognition of switch labels having hanging multiline
statements.
(c-beginning-of-member-init-list): Broke out
some code in c-guess-basic-syntax to a separate function.
(c-just-after-func-arglist-p): Fixed
recognition of member inits with multiple line arglists.
(c-guess-basic-syntax): New case 5B.3 to detect
member-init-cont when the commas are in funny places.
(c-looking-at-bos): New helper function.
(c-looking-at-inexpr-block): More tests to tell
inexpr and toplevel classes apart in Pike.
(c-guess-basic-syntax): Fixed bogus recognition
of case 9A.
(c-guess-basic-syntax): Made the cpp-macro
a syntax modifier like comment-intro, to make it possible to
get syntactic indentation for preprocessor directives. It's
incompatible wrt to lineup functions on cpp-macro, but it has
no observable effect in the 99.9% common case where cpp-macro
is set to -1000.
(c-guess-basic-syntax): Fixed bug with missed
member-init-cont when the preceding arglist is several lines.
(c-beginning-of-statement-1): Fixed bug where
we were left at comments preceding the first statement when
reaching the beginning of the buffer.
(c-beginning-of-closest-statement): New helper
function to go back to the closest preceding statement start,
which could be inside a conditional statement.
(c-guess-basic-syntax): Use
c-beginning-of-closest-statement in cases 10B.2, 17B and 17C.
(c-guess-basic-syntax): Better handling of
arglist-intro, arglist-cont-nonempty and arglist-close when
the arglist is nested inside parens. Cases 7A, 7C and 7F
changed.
(c-beginning-of-statement-1): Fixed handling of
multiline Pike type decls.
(c-guess-basic-syntax): Fixed bug with
fully::qualified::names in C++ member init lists. Preamble in
case 5D changed.
| -rw-r--r-- | lisp/progmodes/cc-engine.el | 418 |
1 files changed, 292 insertions, 126 deletions
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index 08ed5eb2664..f857264e0ff 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el | |||
| @@ -1,8 +1,9 @@ | |||
| 1 | ;;; cc-engine.el --- core syntax guessing engine for CC mode | 1 | ;;; cc-engine.el --- core syntax guessing engine for CC mode |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1985,1987,1992-1999 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1985,1987,1992-2000 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Authors: 1998-1999 Barry A. Warsaw and Martin Stjernholm | 5 | ;; Authors: 2000- Martin Stjernholm |
| 6 | ;; 1998-1999 Barry A. Warsaw and Martin Stjernholm | ||
| 6 | ;; 1992-1997 Barry A. Warsaw | 7 | ;; 1992-1997 Barry A. Warsaw |
| 7 | ;; 1987 Dave Detlefs and Stewart Clamen | 8 | ;; 1987 Dave Detlefs and Stewart Clamen |
| 8 | ;; 1985 Richard M. Stallman | 9 | ;; 1985 Richard M. Stallman |
| @@ -90,8 +91,7 @@ | |||
| 90 | (if (eq (char-before) ?\() | 91 | (if (eq (char-before) ?\() |
| 91 | (setq last-begin (point)))) | 92 | (setq last-begin (point)))) |
| 92 | (goto-char last-begin) | 93 | (goto-char last-begin) |
| 93 | (setq last-begin (point) | 94 | (setq donep t))) |
| 94 | donep t))) | ||
| 95 | 95 | ||
| 96 | (setq c-maybe-labelp nil) | 96 | (setq c-maybe-labelp nil) |
| 97 | ;; see if we're in a literal. if not, then this bufpos may be | 97 | ;; see if we're in a literal. if not, then this bufpos may be |
| @@ -155,7 +155,12 @@ | |||
| 155 | ;; CASE 4: are we looking at a label? (But we handle | 155 | ;; CASE 4: are we looking at a label? (But we handle |
| 156 | ;; switch labels later.) | 156 | ;; switch labels later.) |
| 157 | ((and (looking-at c-label-key) | 157 | ((and (looking-at c-label-key) |
| 158 | (not (looking-at "default\\>")))) | 158 | (not (looking-at "default\\>")) |
| 159 | (not (and (c-major-mode-is 'pike-mode) | ||
| 160 | (save-excursion | ||
| 161 | ;; Not inside a Pike type declaration? | ||
| 162 | (and (c-safe (backward-up-list 1) t) | ||
| 163 | (eq (char-after) ?\())))))) | ||
| 159 | ;; CASE 5: is this the first time we're checking? | 164 | ;; CASE 5: is this the first time we're checking? |
| 160 | (firstp (setq firstp nil | 165 | (firstp (setq firstp nil |
| 161 | substmt-p (not (c-crosses-statement-barrier-p | 166 | substmt-p (not (c-crosses-statement-barrier-p |
| @@ -184,14 +189,15 @@ | |||
| 184 | (if (looking-at c-switch-label-key) | 189 | (if (looking-at c-switch-label-key) |
| 185 | t | 190 | t |
| 186 | (goto-char here) | 191 | (goto-char here) |
| 187 | nil)) | 192 | nil))))) |
| 188 | (looking-at c-label-key)))) | ||
| 189 | ;; CASE 8: ObjC or Java method def | 193 | ;; CASE 8: ObjC or Java method def |
| 190 | ((and c-method-key | 194 | ((and c-method-key |
| 191 | (setq last-begin (c-in-method-def-p))) | 195 | (setq last-begin (c-in-method-def-p))) |
| 192 | (setq donep t)) | 196 | (setq donep t)) |
| 193 | ;; CASE 9: nothing special | 197 | ;; CASE 9: Normal token. At bob, we can end up at ws or a |
| 194 | (t (setq last-begin (point))) | 198 | ;; comment, and last-begin shouldn't be updated then. |
| 199 | ((not (looking-at "\\s \\|/[/*]")) | ||
| 200 | (setq last-begin (point))) | ||
| 195 | )))) | 201 | )))) |
| 196 | (goto-char last-begin) | 202 | (goto-char last-begin) |
| 197 | ;; We always want to skip over the non-whitespace modifier | 203 | ;; We always want to skip over the non-whitespace modifier |
| @@ -268,8 +274,8 @@ | |||
| 268 | ;; skip preprocessor directives | 274 | ;; skip preprocessor directives |
| 269 | (when (and (eq (char-after) ?#) | 275 | (when (and (eq (char-after) ?#) |
| 270 | (= (c-point 'boi) (point))) | 276 | (= (c-point 'boi) (point))) |
| 271 | (while (eq (char-before (c-point 'eol)) ?\\) | 277 | (while (and (eq (char-before (c-point 'eol)) ?\\) |
| 272 | (forward-line 1)) | 278 | (= (forward-line 1) 0))) |
| 273 | (end-of-line)) | 279 | (end-of-line)) |
| 274 | ) | 280 | ) |
| 275 | (if lim (goto-char (min (point) lim))))) | 281 | (if lim (goto-char (min (point) lim))))) |
| @@ -769,17 +775,20 @@ | |||
| 769 | ;; Go to the first non-whitespace after the colon that starts a | 775 | ;; Go to the first non-whitespace after the colon that starts a |
| 770 | ;; multiple inheritance introduction. Optional LIM is the farthest | 776 | ;; multiple inheritance introduction. Optional LIM is the farthest |
| 771 | ;; back we should search. | 777 | ;; back we should search. |
| 772 | (let ((lim (or lim (c-point 'bod))) | 778 | (let* ((lim (or lim (c-point 'bod))) |
| 773 | (placeholder (progn | 779 | (placeholder (progn |
| 774 | (back-to-indentation) | 780 | (back-to-indentation) |
| 775 | (point)))) | 781 | (point))) |
| 782 | (chr (char-after))) | ||
| 776 | (c-backward-syntactic-ws lim) | 783 | (c-backward-syntactic-ws lim) |
| 777 | (while (and (> (point) lim) | 784 | (while (and (> (point) lim) |
| 778 | (memq (char-before) '(?, ?:)) | 785 | (or (eq chr ?,) |
| 786 | (memq (char-before) '(?, ?:))) | ||
| 779 | (progn | 787 | (progn |
| 780 | (beginning-of-line) | 788 | (beginning-of-line) |
| 781 | (setq placeholder (point)) | 789 | (setq placeholder (point)) |
| 782 | (skip-chars-forward " \t") | 790 | (skip-chars-forward " \t") |
| 791 | (setq chr (char-after)) | ||
| 783 | (not (looking-at c-class-key)) | 792 | (not (looking-at c-class-key)) |
| 784 | )) | 793 | )) |
| 785 | (c-backward-syntactic-ws lim)) | 794 | (c-backward-syntactic-ws lim)) |
| @@ -831,6 +840,15 @@ brace." | |||
| 831 | ;; otherwise, we could be looking at a hanging member init | 840 | ;; otherwise, we could be looking at a hanging member init |
| 832 | ;; colon | 841 | ;; colon |
| 833 | (goto-char checkpoint) | 842 | (goto-char checkpoint) |
| 843 | (while (eq (char-before) ?,) | ||
| 844 | ;; this will catch member inits with multiple | ||
| 845 | ;; line arglists | ||
| 846 | (forward-char -1) | ||
| 847 | (c-backward-syntactic-ws (c-point 'bol)) | ||
| 848 | (if (eq (char-before) ?\)) | ||
| 849 | (c-backward-sexp 2) | ||
| 850 | (c-backward-sexp 1)) | ||
| 851 | (c-backward-syntactic-ws)) | ||
| 834 | (if (and (eq (char-before) ?:) | 852 | (if (and (eq (char-before) ?:) |
| 835 | (progn | 853 | (progn |
| 836 | (forward-char -1) | 854 | (forward-char -1) |
| @@ -937,9 +955,64 @@ brace." | |||
| 937 | ((looking-at "\\<else\\>[ \t]+\\<if\\>") 3) | 955 | ((looking-at "\\<else\\>[ \t]+\\<if\\>") 3) |
| 938 | ;; do, else, try, finally | 956 | ;; do, else, try, finally |
| 939 | ((looking-at "\\<\\(do\\|else\\|try\\|finally\\)\\>") 1) | 957 | ((looking-at "\\<\\(do\\|else\\|try\\|finally\\)\\>") 1) |
| 940 | ;; for, if, while, switch, catch, synchronized | 958 | ;; for, if, while, switch, catch, synchronized, foreach |
| 941 | (t 2)))) | 959 | (t 2)))) |
| 942 | 960 | ||
| 961 | (defun c-beginning-of-closest-statement (&optional lim) | ||
| 962 | ;; Go back to the closest preceding statement start. | ||
| 963 | (let ((start (point)) | ||
| 964 | (label-re (concat c-label-key "\\|" | ||
| 965 | c-switch-label-key)) | ||
| 966 | stmtbeg) | ||
| 967 | (if c-access-key | ||
| 968 | (setq label-re (concat label-re "\\|" c-access-key))) | ||
| 969 | (c-beginning-of-statement-1 lim) | ||
| 970 | (while (and (when (<= (point) start) | ||
| 971 | (setq stmtbeg (point))) | ||
| 972 | (cond | ||
| 973 | ((looking-at label-re) | ||
| 974 | ;; Skip a label. | ||
| 975 | (goto-char (match-end 0)) | ||
| 976 | t) | ||
| 977 | ((looking-at c-conditional-key) | ||
| 978 | ;; Skip a conditional statement. | ||
| 979 | (c-safe (c-skip-conditional) t)) | ||
| 980 | (t nil))) | ||
| 981 | (c-forward-syntactic-ws start)) | ||
| 982 | (if stmtbeg | ||
| 983 | (goto-char stmtbeg)))) | ||
| 984 | |||
| 985 | (defun c-beginning-of-member-init-list (&optional limit) | ||
| 986 | ;; Goes to the beginning of a member init list (i.e. just after the | ||
| 987 | ;; ':') if inside one. Returns t in that case, nil otherwise. | ||
| 988 | (or limit | ||
| 989 | (setq limit (point-min))) | ||
| 990 | (skip-chars-forward " \t") | ||
| 991 | (if (eq (char-after) ?,) | ||
| 992 | (forward-char 1) | ||
| 993 | (c-backward-syntactic-ws limit)) | ||
| 994 | (while (and (< limit (point)) | ||
| 995 | (eq (char-before) ?,)) | ||
| 996 | ;; this will catch member inits with multiple | ||
| 997 | ;; line arglists | ||
| 998 | (forward-char -1) | ||
| 999 | (c-backward-syntactic-ws) | ||
| 1000 | (if (eq (char-before) ?\)) | ||
| 1001 | (c-backward-sexp 2) | ||
| 1002 | (c-backward-sexp 1)) | ||
| 1003 | ;; Skip backwards over a fully::qualified::name. | ||
| 1004 | (c-backward-syntactic-ws limit) | ||
| 1005 | (while (and (eq (char-before) ?:) | ||
| 1006 | (save-excursion | ||
| 1007 | (forward-char -1) | ||
| 1008 | (eq (char-before) ?:))) | ||
| 1009 | (backward-char 2) | ||
| 1010 | (c-backward-sexp 1)) | ||
| 1011 | ;; now continue checking | ||
| 1012 | (c-backward-syntactic-ws limit)) | ||
| 1013 | (and (< limit (point)) | ||
| 1014 | (eq (char-before) ?:))) | ||
| 1015 | |||
| 943 | (defun c-skip-case-statement-forward (state &optional lim) | 1016 | (defun c-skip-case-statement-forward (state &optional lim) |
| 944 | ;; skip forward over case/default bodies, with optional maximal | 1017 | ;; skip forward over case/default bodies, with optional maximal |
| 945 | ;; limit. if no next case body is found, nil is returned and point | 1018 | ;; limit. if no next case body is found, nil is returned and point |
| @@ -1204,7 +1277,7 @@ brace." | |||
| 1204 | 1277 | ||
| 1205 | (defun c-looking-at-special-brace-list (&optional lim) | 1278 | (defun c-looking-at-special-brace-list (&optional lim) |
| 1206 | ;; If we're looking at the start of a pike-style list, ie `({ })', | 1279 | ;; If we're looking at the start of a pike-style list, ie `({ })', |
| 1207 | ;; `([ ])', `(< >)' etc, a cons of a cons its starting and ending | 1280 | ;; `([ ])', `(< >)' etc, a cons of a cons of its starting and ending |
| 1208 | ;; positions and its entry in c-special-brace-lists is returned, nil | 1281 | ;; positions and its entry in c-special-brace-lists is returned, nil |
| 1209 | ;; otherwise. The ending position is nil if the list is still open. | 1282 | ;; otherwise. The ending position is nil if the list is still open. |
| 1210 | ;; LIM is the limit for forward search. The point may either be at | 1283 | ;; LIM is the limit for forward search. The point may either be at |
| @@ -1252,6 +1325,17 @@ brace." | |||
| 1252 | (cons (list beg) type))))) | 1325 | (cons (list beg) type))))) |
| 1253 | (error nil)))) | 1326 | (error nil)))) |
| 1254 | 1327 | ||
| 1328 | (defun c-looking-at-bos () | ||
| 1329 | ;; Returns nil if inside a statement or declaration. | ||
| 1330 | (save-excursion | ||
| 1331 | (c-backward-syntactic-ws) | ||
| 1332 | (or (bobp) | ||
| 1333 | (memq (char-before) '(?\; ?})) | ||
| 1334 | (and (eq (char-before) ?{) | ||
| 1335 | (not (and c-special-brace-lists | ||
| 1336 | (progn (backward-char) | ||
| 1337 | (c-looking-at-special-brace-list)))))))) | ||
| 1338 | |||
| 1255 | (defun c-looking-at-inexpr-block (&optional lim) | 1339 | (defun c-looking-at-inexpr-block (&optional lim) |
| 1256 | ;; Returns non-nil if we're looking at the beginning of a block | 1340 | ;; Returns non-nil if we're looking at the beginning of a block |
| 1257 | ;; inside an expression. The value returned is actually a cons of | 1341 | ;; inside an expression. The value returned is actually a cons of |
| @@ -1277,7 +1361,17 @@ brace." | |||
| 1277 | (setq res | 1361 | (setq res |
| 1278 | (cond ((and block-follows | 1362 | (cond ((and block-follows |
| 1279 | c-inexpr-class-key | 1363 | c-inexpr-class-key |
| 1280 | (looking-at c-inexpr-class-key)) | 1364 | (looking-at c-inexpr-class-key) |
| 1365 | (or (not (looking-at c-class-key)) | ||
| 1366 | (let ((prev (point))) | ||
| 1367 | (while (and (= (c-backward-token-1 1 t lim) | ||
| 1368 | 0) | ||
| 1369 | (>= (point) lim) | ||
| 1370 | (eq (char-syntax (char-after)) | ||
| 1371 | ?w)) | ||
| 1372 | (setq prev (point))) | ||
| 1373 | (goto-char prev) | ||
| 1374 | (not (c-looking-at-bos))))) | ||
| 1281 | (cons 'inexpr-class (point))) | 1375 | (cons 'inexpr-class (point))) |
| 1282 | ((and c-inexpr-block-key | 1376 | ((and c-inexpr-block-key |
| 1283 | (looking-at c-inexpr-block-key)) | 1377 | (looking-at c-inexpr-block-key)) |
| @@ -1336,6 +1430,7 @@ brace." | |||
| 1336 | 1430 | ||
| 1337 | (defun c-narrow-out-enclosing-class (state lim) | 1431 | (defun c-narrow-out-enclosing-class (state lim) |
| 1338 | ;; narrow the buffer so that the enclosing class is hidden | 1432 | ;; narrow the buffer so that the enclosing class is hidden |
| 1433 | (setq state (c-whack-state (point) state)) | ||
| 1339 | (let (inclass-p) | 1434 | (let (inclass-p) |
| 1340 | (and state | 1435 | (and state |
| 1341 | (setq inclass-p (c-search-uplist-for-classkey state)) | 1436 | (setq inclass-p (c-search-uplist-for-classkey state)) |
| @@ -1370,9 +1465,6 @@ brace." | |||
| 1370 | (case-fold-search nil) | 1465 | (case-fold-search nil) |
| 1371 | (fullstate (c-parse-state)) | 1466 | (fullstate (c-parse-state)) |
| 1372 | (state fullstate) | 1467 | (state fullstate) |
| 1373 | (in-method-intro-p (and (c-major-mode-is 'objc-mode) | ||
| 1374 | c-method-key | ||
| 1375 | (looking-at c-method-key))) | ||
| 1376 | literal containing-sexp char-before-ip char-after-ip lim | 1468 | literal containing-sexp char-before-ip char-after-ip lim |
| 1377 | syntax placeholder c-in-literal-cache inswitch-p | 1469 | syntax placeholder c-in-literal-cache inswitch-p |
| 1378 | tmpsymbol keyword injava-inher special-brace-list | 1470 | tmpsymbol keyword injava-inher special-brace-list |
| @@ -1403,7 +1495,6 @@ brace." | |||
| 1403 | (skip-chars-forward " \t}") | 1495 | (skip-chars-forward " \t}") |
| 1404 | (skip-chars-backward " \t") | 1496 | (skip-chars-backward " \t") |
| 1405 | (while (and state | 1497 | (while (and state |
| 1406 | (not in-method-intro-p) | ||
| 1407 | (not containing-sexp)) | 1498 | (not containing-sexp)) |
| 1408 | (setq containing-sexp (car state) | 1499 | (setq containing-sexp (car state) |
| 1409 | state (cdr state)) | 1500 | state (cdr state)) |
| @@ -1415,8 +1506,9 @@ brace." | |||
| 1415 | ;; otherwise, ignore this element | 1506 | ;; otherwise, ignore this element |
| 1416 | (setq containing-sexp nil)) | 1507 | (setq containing-sexp nil)) |
| 1417 | ;; ignore the bufpos if its been narrowed out by the | 1508 | ;; ignore the bufpos if its been narrowed out by the |
| 1418 | ;; containing class | 1509 | ;; containing class or does not contain the indent point |
| 1419 | (if (<= containing-sexp (point-min)) | 1510 | (if (or (<= containing-sexp (point-min)) |
| 1511 | (>= containing-sexp indent-point)) | ||
| 1420 | (setq containing-sexp nil))))) | 1512 | (setq containing-sexp nil))))) |
| 1421 | 1513 | ||
| 1422 | ;; set the limit on the farthest back we need to search | 1514 | ;; set the limit on the farthest back we need to search |
| @@ -1447,17 +1539,31 @@ brace." | |||
| 1447 | ;; CASE 2: in a C or C++ style comment. | 1539 | ;; CASE 2: in a C or C++ style comment. |
| 1448 | ((memq literal '(c c++)) | 1540 | ((memq literal '(c c++)) |
| 1449 | (c-add-syntax literal (car (c-literal-limits lim)))) | 1541 | (c-add-syntax literal (car (c-literal-limits lim)))) |
| 1450 | ;; CASE 3: in a cpp preprocessor macro | 1542 | ;; CASE 3: in a cpp preprocessor macro continuation. |
| 1451 | ((eq literal 'pound) | 1543 | ((and (eq literal 'pound) |
| 1452 | (let ((boi (c-point 'boi)) | 1544 | (/= (save-excursion |
| 1453 | (macrostart (progn (c-beginning-of-macro lim) (point)))) | 1545 | (c-beginning-of-macro lim) |
| 1454 | (setq tmpsymbol (if (= boi macrostart) | 1546 | (setq placeholder (point))) |
| 1455 | 'cpp-macro | 1547 | (c-point 'boi))) |
| 1456 | 'cpp-macro-cont)) | 1548 | (c-add-syntax 'cpp-macro-cont placeholder)) |
| 1457 | (c-add-syntax tmpsymbol macrostart))) | 1549 | ;; CASE 4: In-expression statement. |
| 1458 | ;; CASE 4: in an objective-c method intro | 1550 | ((and (or c-inexpr-class-key c-inexpr-block-key c-lambda-key) |
| 1459 | (in-method-intro-p | 1551 | (setq placeholder (c-looking-at-inexpr-block))) |
| 1460 | (c-add-syntax 'objc-method-intro (c-point 'boi))) | 1552 | (setq tmpsymbol (assq (car placeholder) |
| 1553 | '((inexpr-class . class-open) | ||
| 1554 | (inexpr-statement . block-open)))) | ||
| 1555 | (if tmpsymbol | ||
| 1556 | ;; It's a statement block or an anonymous class. | ||
| 1557 | (setq tmpsymbol (cdr tmpsymbol)) | ||
| 1558 | ;; It's a Pike lambda. Check whether we are between the | ||
| 1559 | ;; lambda keyword and the argument list or at the defun | ||
| 1560 | ;; opener. | ||
| 1561 | (setq tmpsymbol (if (eq char-after-ip ?{) | ||
| 1562 | 'inline-open | ||
| 1563 | 'lambda-intro-cont))) | ||
| 1564 | (goto-char (cdr placeholder)) | ||
| 1565 | (c-add-syntax tmpsymbol (c-point 'boi)) | ||
| 1566 | (c-add-syntax (car placeholder))) | ||
| 1461 | ;; CASE 5: Line is at top level. | 1567 | ;; CASE 5: Line is at top level. |
| 1462 | ((null containing-sexp) | 1568 | ((null containing-sexp) |
| 1463 | (cond | 1569 | (cond |
| @@ -1578,7 +1684,11 @@ brace." | |||
| 1578 | (c-recognize-knr-p | 1684 | (c-recognize-knr-p |
| 1579 | (c-add-syntax 'knr-argdecl-intro (c-point 'boi)) | 1685 | (c-add-syntax 'knr-argdecl-intro (c-point 'boi)) |
| 1580 | (if inclass-p (c-add-class-syntax 'inclass inclass-p))) | 1686 | (if inclass-p (c-add-class-syntax 'inclass inclass-p))) |
| 1581 | ;; CASE 5B.3: Nether region after a C++ or Java func | 1687 | ;; CASE 5B.3: Inside a member init list. |
| 1688 | ((c-beginning-of-member-init-list lim) | ||
| 1689 | (c-forward-syntactic-ws) | ||
| 1690 | (c-add-syntax 'member-init-cont (point))) | ||
| 1691 | ;; CASE 5B.4: Nether region after a C++ or Java func | ||
| 1582 | ;; decl, which could include a `throws' declaration. | 1692 | ;; decl, which could include a `throws' declaration. |
| 1583 | (t | 1693 | (t |
| 1584 | (c-beginning-of-statement-1 lim) | 1694 | (c-beginning-of-statement-1 lim) |
| @@ -1586,7 +1696,12 @@ brace." | |||
| 1586 | ))) | 1696 | ))) |
| 1587 | ;; CASE 5C: inheritance line. could be first inheritance | 1697 | ;; CASE 5C: inheritance line. could be first inheritance |
| 1588 | ;; line, or continuation of a multiple inheritance | 1698 | ;; line, or continuation of a multiple inheritance |
| 1589 | ((or (and c-baseclass-key (looking-at c-baseclass-key)) | 1699 | ((or (and c-baseclass-key |
| 1700 | (progn | ||
| 1701 | (when (eq char-after-ip ?,) | ||
| 1702 | (skip-chars-forward " \t") | ||
| 1703 | (forward-char)) | ||
| 1704 | (looking-at c-baseclass-key))) | ||
| 1590 | (and (or (eq char-before-ip ?:) | 1705 | (and (or (eq char-before-ip ?:) |
| 1591 | ;; watch out for scope operator | 1706 | ;; watch out for scope operator |
| 1592 | (save-excursion | 1707 | (save-excursion |
| @@ -1667,29 +1782,11 @@ brace." | |||
| 1667 | (not (looking-at "[;{<,]")))) | 1782 | (not (looking-at "[;{<,]")))) |
| 1668 | (eq (char-after) ?,))) | 1783 | (eq (char-after) ?,))) |
| 1669 | (goto-char indent-point) | 1784 | (goto-char indent-point) |
| 1670 | (c-backward-syntactic-ws lim) | 1785 | (c-beginning-of-member-init-list lim) |
| 1671 | (while (and (< lim (point)) | ||
| 1672 | (eq (char-before) ?,)) | ||
| 1673 | ;; this will catch member inits with multiple | ||
| 1674 | ;; line arglists | ||
| 1675 | (forward-char -1) | ||
| 1676 | (c-backward-syntactic-ws (c-point 'bol)) | ||
| 1677 | (if (eq (char-before) ?\)) | ||
| 1678 | (c-backward-sexp 2) | ||
| 1679 | (c-backward-sexp 1)) | ||
| 1680 | ;; now continue checking | ||
| 1681 | (c-backward-syntactic-ws lim)) | ||
| 1682 | (cond | 1786 | (cond |
| 1683 | ;; CASE 5D.1: hanging member init colon, but watch out | 1787 | ;; CASE 5D.1: hanging member init colon, but watch out |
| 1684 | ;; for bogus matches on access specifiers inside classes. | 1788 | ;; for bogus matches on access specifiers inside classes. |
| 1685 | ((and (save-excursion | 1789 | ((and (save-excursion |
| 1686 | ;; There might be member inits on the first line too. | ||
| 1687 | (while (and (> (point) lim) | ||
| 1688 | (eq (char-before) ?,) | ||
| 1689 | (= (c-backward-token-1 2 t lim) 0) | ||
| 1690 | (eq (char-after) ?\() | ||
| 1691 | (= (c-backward-token-1 1 t lim) 0)) | ||
| 1692 | (c-backward-syntactic-ws lim)) | ||
| 1693 | (setq placeholder (point)) | 1790 | (setq placeholder (point)) |
| 1694 | (c-backward-token-1 1 t lim) | 1791 | (c-backward-token-1 1 t lim) |
| 1695 | (and (eq (char-after) ?:) | 1792 | (and (eq (char-after) ?:) |
| @@ -1697,11 +1794,15 @@ brace." | |||
| 1697 | (save-excursion | 1794 | (save-excursion |
| 1698 | (goto-char placeholder) | 1795 | (goto-char placeholder) |
| 1699 | (back-to-indentation) | 1796 | (back-to-indentation) |
| 1700 | (and | 1797 | (or |
| 1701 | (if c-access-key (not (looking-at c-access-key)) t) | 1798 | (/= (car (save-excursion |
| 1702 | (not (looking-at c-class-key)) | 1799 | (parse-partial-sexp (point) placeholder))) |
| 1703 | (if c-bitfield-key (not (looking-at c-bitfield-key)) t)) | 1800 | 0) |
| 1704 | )) | 1801 | (and |
| 1802 | (if c-access-key (not (looking-at c-access-key)) t) | ||
| 1803 | (not (looking-at c-class-key)) | ||
| 1804 | (if c-bitfield-key (not (looking-at c-bitfield-key)) t)) | ||
| 1805 | ))) | ||
| 1705 | (goto-char placeholder) | 1806 | (goto-char placeholder) |
| 1706 | (c-forward-syntactic-ws) | 1807 | (c-forward-syntactic-ws) |
| 1707 | (c-add-syntax 'member-init-cont (point)) | 1808 | (c-add-syntax 'member-init-cont (point)) |
| @@ -1806,7 +1907,11 @@ brace." | |||
| 1806 | (not (looking-at "typedef[ \t\n]+")))) | 1907 | (not (looking-at "typedef[ \t\n]+")))) |
| 1807 | (goto-char placeholder) | 1908 | (goto-char placeholder) |
| 1808 | (c-add-syntax 'knr-argdecl (c-point 'boi))) | 1909 | (c-add-syntax 'knr-argdecl (c-point 'boi))) |
| 1809 | ;; CASE 5I: we are at the topmost level, make sure we skip | 1910 | ;; CASE 5I: ObjC method definition. |
| 1911 | ((and c-method-key | ||
| 1912 | (looking-at c-method-key)) | ||
| 1913 | (c-add-syntax 'objc-method-intro (c-point 'boi))) | ||
| 1914 | ;; CASE 5J: we are at the topmost level, make sure we skip | ||
| 1810 | ;; back past any access specifiers | 1915 | ;; back past any access specifiers |
| 1811 | ((progn | 1916 | ((progn |
| 1812 | (c-backward-syntactic-ws lim) | 1917 | (c-backward-syntactic-ws lim) |
| @@ -1838,7 +1943,7 @@ brace." | |||
| 1838 | (t (c-add-class-syntax 'inclass inclass-p))) | 1943 | (t (c-add-class-syntax 'inclass inclass-p))) |
| 1839 | )) | 1944 | )) |
| 1840 | )) | 1945 | )) |
| 1841 | ;; CASE 5J: we are at an ObjC or Java method definition | 1946 | ;; CASE 5K: we are at an ObjC or Java method definition |
| 1842 | ;; continuation line. | 1947 | ;; continuation line. |
| 1843 | ((and c-method-key | 1948 | ((and c-method-key |
| 1844 | (progn | 1949 | (progn |
| @@ -1846,36 +1951,19 @@ brace." | |||
| 1846 | (beginning-of-line) | 1951 | (beginning-of-line) |
| 1847 | (looking-at c-method-key))) | 1952 | (looking-at c-method-key))) |
| 1848 | (c-add-syntax 'objc-method-args-cont (point))) | 1953 | (c-add-syntax 'objc-method-args-cont (point))) |
| 1849 | ;; CASE 5K: we are at the first argument of a template | 1954 | ;; CASE 5L: we are at the first argument of a template |
| 1850 | ;; arglist that begins on the previous line. | 1955 | ;; arglist that begins on the previous line. |
| 1851 | ((eq (char-before) ?<) | 1956 | ((eq (char-before) ?<) |
| 1852 | (c-beginning-of-statement-1 lim) | 1957 | (c-beginning-of-statement-1 lim) |
| 1853 | (c-forward-syntactic-ws) | 1958 | (c-forward-syntactic-ws) |
| 1854 | (c-add-syntax 'template-args-cont (c-point 'boi))) | 1959 | (c-add-syntax 'template-args-cont (c-point 'boi))) |
| 1855 | ;; CASE 5L: we are at a topmost continuation line | 1960 | ;; CASE 5M: we are at a topmost continuation line |
| 1856 | (t | 1961 | (t |
| 1857 | (c-beginning-of-statement-1 lim) | 1962 | (c-beginning-of-statement-1 lim) |
| 1858 | (c-forward-syntactic-ws) | 1963 | (c-forward-syntactic-ws) |
| 1859 | (c-add-syntax 'topmost-intro-cont (c-point 'boi))) | 1964 | (c-add-syntax 'topmost-intro-cont (c-point 'boi))) |
| 1860 | )) ; end CASE 5 | 1965 | )) ; end CASE 5 |
| 1861 | ;; CASE 6: In-expression statement. | 1966 | ;; (CASE 6 has been removed.) |
| 1862 | ((and (or c-inexpr-class-key c-inexpr-block-key c-lambda-key) | ||
| 1863 | (setq placeholder (c-looking-at-inexpr-block))) | ||
| 1864 | (setq tmpsymbol (assq (car placeholder) | ||
| 1865 | '((inexpr-class . class-open) | ||
| 1866 | (inexpr-statement . block-open)))) | ||
| 1867 | (if tmpsymbol | ||
| 1868 | ;; It's a statement block or an anonymous class. | ||
| 1869 | (setq tmpsymbol (cdr tmpsymbol)) | ||
| 1870 | ;; It's a Pike lambda. Check whether we are between the | ||
| 1871 | ;; lambda keyword and the argument list or at the defun | ||
| 1872 | ;; opener. | ||
| 1873 | (setq tmpsymbol (if (eq char-after-ip ?{) | ||
| 1874 | 'inline-open | ||
| 1875 | 'lambda-intro-cont))) | ||
| 1876 | (goto-char (cdr placeholder)) | ||
| 1877 | (c-add-syntax tmpsymbol (c-point 'boi)) | ||
| 1878 | (c-add-syntax (car placeholder))) | ||
| 1879 | ;; CASE 7: line is an expression, not a statement. Most | 1967 | ;; CASE 7: line is an expression, not a statement. Most |
| 1880 | ;; likely we are either in a function prototype or a function | 1968 | ;; likely we are either in a function prototype or a function |
| 1881 | ;; call argument list | 1969 | ;; call argument list |
| @@ -1893,7 +1981,13 @@ brace." | |||
| 1893 | (not (eq char-before-ip ?,))) | 1981 | (not (eq char-before-ip ?,))) |
| 1894 | (memq char-after-ip '(?\) ?\]))) | 1982 | (memq char-after-ip '(?\) ?\]))) |
| 1895 | (goto-char containing-sexp) | 1983 | (goto-char containing-sexp) |
| 1896 | (c-add-syntax 'arglist-close (c-point 'boi))) | 1984 | (setq placeholder (c-point 'boi)) |
| 1985 | (when (and (c-safe (backward-up-list 1) t) | ||
| 1986 | (> (point) placeholder)) | ||
| 1987 | (forward-char) | ||
| 1988 | (skip-chars-forward " \t") | ||
| 1989 | (setq placeholder (point))) | ||
| 1990 | (c-add-syntax 'arglist-close placeholder)) | ||
| 1897 | ;; CASE 7B: Looking at the opening brace of an | 1991 | ;; CASE 7B: Looking at the opening brace of an |
| 1898 | ;; in-expression block or brace list. | 1992 | ;; in-expression block or brace list. |
| 1899 | ((eq char-after-ip ?{) | 1993 | ((eq char-after-ip ?{) |
| @@ -1912,7 +2006,13 @@ brace." | |||
| 1912 | ;; looking at a close paren or bracket. | 2006 | ;; looking at a close paren or bracket. |
| 1913 | ((memq char-before-ip '(?\( ?\[)) | 2007 | ((memq char-before-ip '(?\( ?\[)) |
| 1914 | (goto-char containing-sexp) | 2008 | (goto-char containing-sexp) |
| 1915 | (c-add-syntax 'arglist-intro (c-point 'boi))) | 2009 | (setq placeholder (c-point 'boi)) |
| 2010 | (when (and (c-safe (backward-up-list 1) t) | ||
| 2011 | (> (point) placeholder)) | ||
| 2012 | (forward-char) | ||
| 2013 | (skip-chars-forward " \t") | ||
| 2014 | (setq placeholder (point))) | ||
| 2015 | (c-add-syntax 'arglist-intro placeholder)) | ||
| 1916 | ;; CASE 7D: we are inside a conditional test clause. treat | 2016 | ;; CASE 7D: we are inside a conditional test clause. treat |
| 1917 | ;; these things as statements | 2017 | ;; these things as statements |
| 1918 | ((save-excursion | 2018 | ((save-excursion |
| @@ -1951,7 +2051,13 @@ brace." | |||
| 1951 | (skip-chars-backward " \t([") | 2051 | (skip-chars-backward " \t([") |
| 1952 | (<= (point) containing-sexp))) | 2052 | (<= (point) containing-sexp))) |
| 1953 | (goto-char containing-sexp) | 2053 | (goto-char containing-sexp) |
| 1954 | (c-add-syntax 'arglist-cont-nonempty (c-point 'boi))) | 2054 | (setq placeholder (c-point 'boi)) |
| 2055 | (when (and (c-safe (backward-up-list 1) t) | ||
| 2056 | (> (point) placeholder)) | ||
| 2057 | (forward-char) | ||
| 2058 | (skip-chars-forward " \t") | ||
| 2059 | (setq placeholder (point))) | ||
| 2060 | (c-add-syntax 'arglist-cont-nonempty placeholder)) | ||
| 1955 | ;; CASE 7G: we are looking at just a normal arglist | 2061 | ;; CASE 7G: we are looking at just a normal arglist |
| 1956 | ;; continuation line | 2062 | ;; continuation line |
| 1957 | (t (c-beginning-of-statement-1 containing-sexp) | 2063 | (t (c-beginning-of-statement-1 containing-sexp) |
| @@ -1990,6 +2096,9 @@ brace." | |||
| 1990 | (cond | 2096 | (cond |
| 1991 | ;; CASE 9A: In the middle of a special brace list opener. | 2097 | ;; CASE 9A: In the middle of a special brace list opener. |
| 1992 | ((and (consp special-brace-list) | 2098 | ((and (consp special-brace-list) |
| 2099 | (save-excursion | ||
| 2100 | (goto-char containing-sexp) | ||
| 2101 | (eq (char-after) ?\()) | ||
| 1993 | (eq char-after-ip (car (cdr special-brace-list)))) | 2102 | (eq char-after-ip (car (cdr special-brace-list)))) |
| 1994 | (goto-char (car (car special-brace-list))) | 2103 | (goto-char (car (car special-brace-list))) |
| 1995 | (skip-chars-backward " \t") | 2104 | (skip-chars-backward " \t") |
| @@ -2118,9 +2227,18 @@ brace." | |||
| 2118 | ;; adjusts brace-list-open for brace lists as | 2227 | ;; adjusts brace-list-open for brace lists as |
| 2119 | ;; top-level constructs, and brace lists inside | 2228 | ;; top-level constructs, and brace lists inside |
| 2120 | ;; statements is a completely different context. | 2229 | ;; statements is a completely different context. |
| 2121 | (goto-char placeholder) | 2230 | (goto-char indent-point) |
| 2231 | (c-beginning-of-closest-statement) | ||
| 2122 | (c-add-syntax 'statement-cont (c-point 'boi))) | 2232 | (c-add-syntax 'statement-cont (c-point 'boi))) |
| 2123 | ;; CASE 10B.3: catch-all for unknown construct. | 2233 | ;; CASE 10B.3: The body of a function declared inside a |
| 2234 | ;; normal block. This can only occur in Pike. | ||
| 2235 | ((and (c-major-mode-is 'pike-mode) | ||
| 2236 | (progn | ||
| 2237 | (goto-char indent-point) | ||
| 2238 | (not (c-looking-at-bos)))) | ||
| 2239 | (c-beginning-of-closest-statement) | ||
| 2240 | (c-add-syntax 'defun-open (c-point 'boi))) | ||
| 2241 | ;; CASE 10B.4: catch-all for unknown construct. | ||
| 2124 | (t | 2242 | (t |
| 2125 | ;; Can and should I add an extensibility hook here? | 2243 | ;; Can and should I add an extensibility hook here? |
| 2126 | ;; Something like c-recognize-hook so support for | 2244 | ;; Something like c-recognize-hook so support for |
| @@ -2243,7 +2361,15 @@ brace." | |||
| 2243 | ;; been narrowed out by a class, then this is a | 2361 | ;; been narrowed out by a class, then this is a |
| 2244 | ;; block-close | 2362 | ;; block-close |
| 2245 | ((and (not inenclosing-p) | 2363 | ((and (not inenclosing-p) |
| 2246 | (c-most-enclosing-brace state)) | 2364 | (c-most-enclosing-brace state) |
| 2365 | (or (not (c-major-mode-is 'pike-mode)) | ||
| 2366 | ;; In Pike it can be a defun-close of a | ||
| 2367 | ;; function declared in a statement block. Let | ||
| 2368 | ;; it through to be handled below. | ||
| 2369 | (or (c-looking-at-bos) | ||
| 2370 | (progn | ||
| 2371 | (c-beginning-of-statement-1) | ||
| 2372 | (looking-at c-conditional-key))))) | ||
| 2247 | (c-add-syntax 'block-close relpos)) | 2373 | (c-add-syntax 'block-close relpos)) |
| 2248 | ;; CASE 16D: find out whether we're closing a top-level | 2374 | ;; CASE 16D: find out whether we're closing a top-level |
| 2249 | ;; class or a defun | 2375 | ;; class or a defun |
| @@ -2278,10 +2404,12 @@ brace." | |||
| 2278 | ((and inswitch-p | 2404 | ((and inswitch-p |
| 2279 | (progn | 2405 | (progn |
| 2280 | (goto-char indent-point) | 2406 | (goto-char indent-point) |
| 2281 | (c-backward-syntactic-ws containing-sexp) | 2407 | (c-beginning-of-statement-1 containing-sexp) |
| 2282 | (back-to-indentation) | ||
| 2283 | (setq placeholder (point)) | 2408 | (setq placeholder (point)) |
| 2284 | (looking-at c-switch-label-key))) | 2409 | (beginning-of-line) |
| 2410 | (when (re-search-forward c-switch-label-key | ||
| 2411 | (max placeholder (c-point 'eol)) t) | ||
| 2412 | (setq placeholder (match-beginning 0))))) | ||
| 2285 | (goto-char indent-point) | 2413 | (goto-char indent-point) |
| 2286 | (skip-chars-forward " \t") | 2414 | (skip-chars-forward " \t") |
| 2287 | (if (eq (char-after) ?{) | 2415 | (if (eq (char-after) ?{) |
| @@ -2289,6 +2417,8 @@ brace." | |||
| 2289 | (c-add-syntax 'statement-case-intro placeholder))) | 2417 | (c-add-syntax 'statement-case-intro placeholder))) |
| 2290 | ;; CASE 17B: continued statement | 2418 | ;; CASE 17B: continued statement |
| 2291 | ((eq char-before-ip ?,) | 2419 | ((eq char-before-ip ?,) |
| 2420 | (goto-char indent-point) | ||
| 2421 | (c-beginning-of-closest-statement) | ||
| 2292 | (c-add-syntax 'statement-cont (c-point 'boi))) | 2422 | (c-add-syntax 'statement-cont (c-point 'boi))) |
| 2293 | ;; CASE 17C: a question/colon construct? But make sure | 2423 | ;; CASE 17C: a question/colon construct? But make sure |
| 2294 | ;; what came before was not a label, and what comes after | 2424 | ;; what came before was not a label, and what comes after |
| @@ -2305,6 +2435,8 @@ brace." | |||
| 2305 | (skip-chars-forward " \t") | 2435 | (skip-chars-forward " \t") |
| 2306 | ;; watch out for scope operator | 2436 | ;; watch out for scope operator |
| 2307 | (not (looking-at "::"))))) | 2437 | (not (looking-at "::"))))) |
| 2438 | (goto-char indent-point) | ||
| 2439 | (c-beginning-of-closest-statement) | ||
| 2308 | (c-add-syntax 'statement-cont (c-point 'boi))) | 2440 | (c-add-syntax 'statement-cont (c-point 'boi))) |
| 2309 | ;; CASE 17D: any old statement | 2441 | ;; CASE 17D: any old statement |
| 2310 | ((< (point) indent-point) | 2442 | ((< (point) indent-point) |
| @@ -2322,9 +2454,8 @@ brace." | |||
| 2322 | (if (and inswitch-p | 2454 | (if (and inswitch-p |
| 2323 | (looking-at c-switch-label-key)) | 2455 | (looking-at c-switch-label-key)) |
| 2324 | (progn | 2456 | (progn |
| 2325 | (goto-char placeholder) | 2457 | (goto-char (match-end 0)) |
| 2326 | (end-of-line) | 2458 | (c-forward-syntactic-ws))) |
| 2327 | (c-forward-sexp -1))) | ||
| 2328 | (setq relpos (c-point 'boi)) | 2459 | (setq relpos (c-point 'boi)) |
| 2329 | (while (and (not done) | 2460 | (while (and (not done) |
| 2330 | (<= safepos (point)) | 2461 | (<= safepos (point)) |
| @@ -2343,11 +2474,14 @@ brace." | |||
| 2343 | (c-looking-at-inexpr-block))) | 2474 | (c-looking-at-inexpr-block))) |
| 2344 | (goto-char containing-sexp) | 2475 | (goto-char containing-sexp) |
| 2345 | (back-to-indentation) | 2476 | (back-to-indentation) |
| 2346 | (if (= containing-sexp (point)) | 2477 | (let ((block-intro (if (eq (car placeholder) 'inlambda) |
| 2347 | (c-add-syntax 'statement-block-intro (point)) | 2478 | 'defun-block-intro |
| 2348 | (goto-char (cdr placeholder)) | 2479 | 'statement-block-intro))) |
| 2349 | (c-add-syntax 'statement-block-intro (c-point 'boi)) | 2480 | (if (= containing-sexp (point)) |
| 2350 | (c-add-syntax (car placeholder))) | 2481 | (c-add-syntax block-intro (point)) |
| 2482 | (goto-char (cdr placeholder)) | ||
| 2483 | (c-add-syntax block-intro (c-point 'boi)) | ||
| 2484 | (c-add-syntax (car placeholder)))) | ||
| 2351 | (if (eq char-after-ip ?{) | 2485 | (if (eq char-after-ip ?{) |
| 2352 | (c-add-syntax 'block-open))) | 2486 | (c-add-syntax 'block-open))) |
| 2353 | ;; CASE 17F: first statement in an inline, or first | 2487 | ;; CASE 17F: first statement in an inline, or first |
| @@ -2373,7 +2507,17 @@ brace." | |||
| 2373 | (c-beginning-of-statement-1) | 2507 | (c-beginning-of-statement-1) |
| 2374 | )) | 2508 | )) |
| 2375 | (c-add-syntax 'defun-block-intro (c-point 'boi))) | 2509 | (c-add-syntax 'defun-block-intro (c-point 'boi))) |
| 2376 | ;; CASE 17G: first statement in a block | 2510 | ;; CASE 17G: First statement in a function declared inside |
| 2511 | ;; a normal block. This can only occur in Pike. | ||
| 2512 | ((and (c-major-mode-is 'pike-mode) | ||
| 2513 | (progn | ||
| 2514 | (goto-char containing-sexp) | ||
| 2515 | (and (not (c-looking-at-bos)) | ||
| 2516 | (progn | ||
| 2517 | (c-beginning-of-statement-1) | ||
| 2518 | (not (looking-at c-conditional-key)))))) | ||
| 2519 | (c-add-syntax 'defun-block-intro (c-point 'boi))) | ||
| 2520 | ;; CASE 17H: first statement in a block | ||
| 2377 | (t (goto-char containing-sexp) | 2521 | (t (goto-char containing-sexp) |
| 2378 | (if (/= (point) (c-point 'boi)) | 2522 | (if (/= (point) (c-point 'boi)) |
| 2379 | (c-beginning-of-statement-1 | 2523 | (c-beginning-of-statement-1 |
| @@ -2384,17 +2528,24 @@ brace." | |||
| 2384 | (c-add-syntax 'block-open))) | 2528 | (c-add-syntax 'block-open))) |
| 2385 | )) | 2529 | )) |
| 2386 | ) | 2530 | ) |
| 2387 | |||
| 2388 | ;; now we need to look at any modifiers | 2531 | ;; now we need to look at any modifiers |
| 2389 | (goto-char indent-point) | 2532 | (goto-char indent-point) |
| 2390 | (skip-chars-forward " \t") | 2533 | (skip-chars-forward " \t") |
| 2391 | ;; are we looking at a comment only line? | 2534 | (cond |
| 2392 | (if (looking-at c-comment-start-regexp) | 2535 | ;; are we looking at a comment only line? |
| 2393 | (c-add-syntax 'comment-intro)) | 2536 | ((looking-at c-comment-start-regexp) |
| 2394 | ;; we might want to give additional offset to friends (in C++). | 2537 | (c-add-syntax 'comment-intro)) |
| 2395 | (if (and (c-major-mode-is 'c++-mode) | 2538 | ;; we might want to give additional offset to friends (in C++). |
| 2396 | (looking-at c-C++-friend-key)) | 2539 | ((and (c-major-mode-is 'c++-mode) |
| 2397 | (c-add-syntax 'friend)) | 2540 | (looking-at c-C++-friend-key)) |
| 2541 | (c-add-syntax 'friend)) | ||
| 2542 | ;; Start of a preprocessor directive? | ||
| 2543 | ((and (eq literal 'pound) | ||
| 2544 | (= (save-excursion | ||
| 2545 | (c-beginning-of-macro lim) | ||
| 2546 | (setq placeholder (point))) | ||
| 2547 | (c-point 'boi))) | ||
| 2548 | (c-add-syntax 'cpp-macro))) | ||
| 2398 | ;; return the syntax | 2549 | ;; return the syntax |
| 2399 | syntax)))) | 2550 | syntax)))) |
| 2400 | 2551 | ||
| @@ -2407,31 +2558,46 @@ brace." | |||
| 2407 | (ding)) | 2558 | (ding)) |
| 2408 | c-parsing-error) | 2559 | c-parsing-error) |
| 2409 | 2560 | ||
| 2410 | ;; indent via syntactic language elements | 2561 | (defun c-shift-line-indentation (shift-amt) |
| 2411 | (defun c-indent-line (&optional syntax) | 2562 | (let ((pos (- (point-max) (point))) |
| 2412 | ;; indent the current line as C/C++/ObjC code. Optional SYNTAX is the | 2563 | (col (current-indentation))) |
| 2413 | ;; syntactic information for the current line. Returns the amount of | ||
| 2414 | ;; indentation change (in columns). | ||
| 2415 | (let* ((c-syntactic-context (or syntax (c-guess-basic-syntax))) | ||
| 2416 | (pos (- (point-max) (point))) | ||
| 2417 | (indent (apply '+ (mapcar 'c-get-offset c-syntactic-context))) | ||
| 2418 | (shift-amt (- (current-indentation) indent))) | ||
| 2419 | (and c-echo-syntactic-information-p | ||
| 2420 | (not (c-echo-parsing-error)) | ||
| 2421 | (message "syntax: %s, indent= %d" c-syntactic-context indent)) | ||
| 2422 | (if (zerop shift-amt) | 2564 | (if (zerop shift-amt) |
| 2423 | nil | 2565 | nil |
| 2424 | (delete-region (c-point 'bol) (c-point 'boi)) | 2566 | (delete-region (c-point 'bol) (c-point 'boi)) |
| 2425 | (beginning-of-line) | 2567 | (beginning-of-line) |
| 2426 | (indent-to indent)) | 2568 | (indent-to (+ col shift-amt))) |
| 2427 | (if (< (point) (c-point 'boi)) | 2569 | (if (< (point) (c-point 'boi)) |
| 2428 | (back-to-indentation) | 2570 | (back-to-indentation) |
| 2429 | ;; If initial point was within line's indentation, position after | 2571 | ;; If initial point was within line's indentation, position after |
| 2430 | ;; the indentation. Else stay at same point in text. | 2572 | ;; the indentation. Else stay at same point in text. |
| 2431 | (if (> (- (point-max) pos) (point)) | 2573 | (if (> (- (point-max) pos) (point)) |
| 2432 | (goto-char (- (point-max) pos))) | 2574 | (goto-char (- (point-max) pos)))))) |
| 2433 | ) | 2575 | |
| 2434 | (run-hooks 'c-special-indent-hook) | 2576 | (defun c-indent-line (&optional syntax) |
| 2577 | ;; Indent the current line as C/C++/ObjC code, if | ||
| 2578 | ;; c-syntactic-indentation is non-nil. Optional SYNTAX is the | ||
| 2579 | ;; syntactic information for the current line. Returns the amount | ||
| 2580 | ;; of indentation change (in columns). | ||
| 2581 | (let (shift-amt) | ||
| 2582 | (if c-syntactic-indentation | ||
| 2583 | (let* ((c-syntactic-context (or syntax (c-guess-basic-syntax))) | ||
| 2584 | (indent (apply '+ (mapcar 'c-get-offset c-syntactic-context)))) | ||
| 2585 | (and c-echo-syntactic-information-p | ||
| 2586 | (not (c-echo-parsing-error)) | ||
| 2587 | (message "syntax: %s, indent= %d" c-syntactic-context indent)) | ||
| 2588 | (setq shift-amt (- indent (current-indentation))) | ||
| 2589 | (c-shift-line-indentation shift-amt) | ||
| 2590 | (run-hooks 'c-special-indent-hook)) | ||
| 2591 | (let ((indent 0)) | ||
| 2592 | (save-excursion | ||
| 2593 | (while (and (= (forward-line -1) 0) | ||
| 2594 | (if (looking-at "\\s-*$") | ||
| 2595 | t | ||
| 2596 | (back-to-indentation) | ||
| 2597 | (setq indent (current-indentation)) | ||
| 2598 | nil)))) | ||
| 2599 | (setq shift-amt (- indent (current-indentation))) | ||
| 2600 | (c-shift-line-indentation shift-amt))) | ||
| 2435 | shift-amt)) | 2601 | shift-amt)) |
| 2436 | 2602 | ||
| 2437 | (defun c-show-syntactic-information (arg) | 2603 | (defun c-show-syntactic-information (arg) |