Mercurial > emacs
comparison lisp/progmodes/cc-engine.el @ 21106:5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
(c-collect-line-comments): Require same comment start column.
(c-guess-basic-syntax): Fixes for nesting of and
repeated defun-open's inside extern and namespace clauses. This
is done by passing a relpos to `inextern-lang' and `innamespace'.
Also, the relpos in `defun-open' is no longer always bol. It's
always bol when on the top level, however. Changed cases: 5A.5, 5I, 14A.
(c-forward-token-1, c-backward-token-1): New functions to move by tokens.
c-guess-basic-syntax): Fixes for Java 1.1 array initialization brace lists.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 08 Mar 1998 06:49:04 +0000 |
parents | 8f189ffad604 |
children | 5b0864259a4b |
comparison
equal
deleted
inserted
replaced
21105:b40ae72a5b26 | 21106:5e5fa0a34cb0 |
---|---|
269 (forward-comment hugenum) | 269 (forward-comment hugenum) |
270 (c-beginning-of-macro)) | 270 (c-beginning-of-macro)) |
271 (if lim (goto-char (max (point) lim))))) | 271 (if lim (goto-char (max (point) lim))))) |
272 | 272 |
273 | 273 |
274 ;; Moving by tokens, where a token is defined as all symbols and | |
275 ;; identifiers which aren't syntactic whitespace. COUNT specifies the | |
276 ;; number of tokens to move forward; a negative COUNT moves backward. | |
277 ;; If BALANCED is true, move over balanced parens, otherwise move into | |
278 ;; them. Also, if BALANCED is true, never move out of an enclosing | |
279 ;; paren. LIM sets the limit for the movement. Point is always left | |
280 ;; at the beginning of a token or at LIM. Returns the number of | |
281 ;; tokens left to move (positive or negative). If BALANCED is true, a | |
282 ;; move over a balanced paren counts as one. | |
283 | |
284 (defun c-forward-token-1 (&optional count balanced lim) | |
285 (let* ((jump-syntax (if balanced | |
286 '(?w ?_ ?\" ?\\ ?/ ?$ ?' ?\( ?\)) | |
287 '(?w ?_ ?\" ?\\ ?/ ?$ ?')))) | |
288 (or count (setq count 1)) | |
289 (condition-case nil | |
290 (while (progn | |
291 (c-forward-syntactic-ws lim) | |
292 (> count 0)) | |
293 (if (memq (char-syntax (char-after)) jump-syntax) | |
294 (goto-char (scan-sexps (point) 1)) | |
295 (forward-char)) | |
296 (setq count (1- count))) | |
297 (error | |
298 (and lim (> (point) lim) (goto-char lim)))) | |
299 count)) | |
300 | |
301 (defun c-backward-token-1 (&optional count balanced lim) | |
302 (let* ((jump-syntax (if balanced | |
303 '(?w ?_ ?\" ?\\ ?/ ?$ ?' ?\( ?\)) | |
304 '(?w ?_ ?\" ?\\ ?/ ?$ ?'))) | |
305 last) | |
306 (or count (setq count 1)) | |
307 (condition-case nil | |
308 (while (> count 0) | |
309 (setq last (point)) | |
310 (c-backward-syntactic-ws lim) | |
311 (if (memq (char-syntax (char-before)) jump-syntax) | |
312 (goto-char (scan-sexps (point) -1)) | |
313 (backward-char)) | |
314 (setq count (1- count))) | |
315 (error | |
316 (goto-char last) | |
317 (and lim (< (point) lim) (goto-char lim)))) | |
318 count)) | |
319 | |
320 | |
274 ;; Return `c' if in a C-style comment, `c++' if in a C++ style | 321 ;; Return `c' if in a C-style comment, `c++' if in a C++ style |
275 ;; comment, `string' if in a string literal, `pound' if on a | 322 ;; comment, `string' if in a string literal, `pound' if on a |
276 ;; preprocessor line, or nil if not in a comment at all. Optional LIM | 323 ;; preprocessor line, or nil if not in a comment at all. Optional LIM |
277 ;; is used as the backward limit of the search. If omitted, or nil, | 324 ;; is used as the backward limit of the search. If omitted, or nil, |
278 ;; `beginning-of-defun' is used." | 325 ;; `beginning-of-defun' is used." |
374 | 421 |
375 (defun c-collect-line-comments (range) | 422 (defun c-collect-line-comments (range) |
376 ;; If the argument is a cons of two buffer positions (such as | 423 ;; If the argument is a cons of two buffer positions (such as |
377 ;; returned by c-literal-limits), and that range contains a C++ | 424 ;; returned by c-literal-limits), and that range contains a C++ |
378 ;; style line comment, then an extended range is returned that | 425 ;; style line comment, then an extended range is returned that |
379 ;; contains all adjacent line comments (i.e. all comments with no | 426 ;; contains all adjacent line comments (i.e. all comments that |
380 ;; empty lines or non-whitespace characters between them). | 427 ;; starts in the same column with no empty lines or non-whitespace |
381 ;; Otherwise the argument is returned. | 428 ;; characters between them). Otherwise the argument is returned. |
382 (save-excursion | 429 (save-excursion |
383 (condition-case nil | 430 (condition-case nil |
384 (if (and (consp range) (progn | 431 (if (and (consp range) (progn |
385 (goto-char (car range)) | 432 (goto-char (car range)) |
386 (looking-at "//"))) | 433 (looking-at "//"))) |
387 (let ((beg (point))) | 434 (let ((col (current-column)) |
435 (beg (point)) | |
436 (end (cdr range))) | |
388 (while (and (not (bobp)) | 437 (while (and (not (bobp)) |
389 (forward-comment -1) | 438 (forward-comment -1) |
390 (looking-at "//")) | 439 (looking-at "//") |
440 (= col (current-column))) | |
391 (setq beg (point))) | 441 (setq beg (point))) |
392 (cons beg (progn | 442 (goto-char end) |
393 (goto-char (cdr range)) | 443 (while (progn |
394 (while (looking-at "[ \t]*//") | 444 (skip-chars-forward " \t") |
395 (forward-comment 1)) | 445 (and (looking-at "//") |
396 (point)))) | 446 (= col (current-column)))) |
447 (forward-comment 1) | |
448 (setq end (point))) | |
449 (cons beg end)) | |
397 range) | 450 range) |
398 (error range)))) | 451 (error range)))) |
399 | 452 |
400 | 453 |
401 | 454 |
848 ;; N.B.: This algorithm can potentially get confused by cpp macros | 901 ;; N.B.: This algorithm can potentially get confused by cpp macros |
849 ;; places in inconvenient locations. Its a trade-off we make for | 902 ;; places in inconvenient locations. Its a trade-off we make for |
850 ;; speed. | 903 ;; speed. |
851 (or | 904 (or |
852 ;; this will pick up enum lists | 905 ;; this will pick up enum lists |
853 (condition-case () | 906 (c-safe |
854 (save-excursion | 907 (save-excursion |
855 (goto-char containing-sexp) | 908 (goto-char containing-sexp) |
856 (forward-sexp -1) | 909 (forward-sexp -1) |
857 (if (and (or (looking-at "enum[\t\n ]+") | 910 (let (bracepos) |
858 (progn (forward-sexp -1) | 911 (if (and (or (looking-at "enum[\t\n ]+") |
859 (looking-at "enum[\t\n ]+"))) | 912 (progn (forward-sexp -1) |
860 (progn (c-end-of-statement-1) | 913 (looking-at "enum[\t\n ]+"))) |
861 (> (point) containing-sexp))) | 914 (setq bracepos (c-safe (scan-lists (point) 1 -1))) |
862 (point))) | 915 (not (c-crosses-statement-barrier-p (point) |
863 (error nil)) | 916 (- bracepos 2)))) |
917 (point))))) | |
864 ;; this will pick up array/aggregate init lists, even if they are nested. | 918 ;; this will pick up array/aggregate init lists, even if they are nested. |
865 (save-excursion | 919 (save-excursion |
866 (let (bufpos failedp) | 920 (let (bufpos okp) |
867 (while (and (not bufpos) | 921 (while (and (not bufpos) |
868 containing-sexp) | 922 containing-sexp) |
869 (if (consp containing-sexp) | 923 (if (consp containing-sexp) |
870 (setq containing-sexp (car brace-state) | 924 (setq containing-sexp (car brace-state) |
871 brace-state (cdr brace-state)) | 925 brace-state (cdr brace-state)) |
872 ;; see if significant character just before brace is an equal | 926 ;; see if the open brace is preceded by a = in this statement |
873 (goto-char containing-sexp) | 927 (goto-char containing-sexp) |
874 (setq failedp nil) | 928 (setq okp t) |
875 (condition-case () | 929 (while (and (setq okp (= (c-backward-token-1 1 t) 0)) |
876 (progn | 930 (not (memq (char-after) '(?= ?{ ?\;))))) |
877 (forward-sexp -1) | 931 (if (not (and okp (eq (char-after) ?=))) |
878 (forward-sexp 1) | |
879 (c-forward-syntactic-ws containing-sexp)) | |
880 (error (setq failedp t))) | |
881 (if (or failedp (not (eq (char-after) ?=))) | |
882 ;; lets see if we're nested. find the most nested | 932 ;; lets see if we're nested. find the most nested |
883 ;; containing brace | 933 ;; containing brace |
884 (setq containing-sexp (car brace-state) | 934 (setq containing-sexp (car brace-state) |
885 brace-state (cdr brace-state)) | 935 brace-state (cdr brace-state)) |
886 ;; we've hit the beginning of the aggregate list | 936 ;; we've hit the beginning of the aggregate list |
1107 (if (looking-at "typedef[^_]") | 1157 (if (looking-at "typedef[^_]") |
1108 (progn (forward-sexp 1) | 1158 (progn (forward-sexp 1) |
1109 (c-forward-syntactic-ws indent-point))) | 1159 (c-forward-syntactic-ws indent-point))) |
1110 (setq placeholder (c-point 'boi)) | 1160 (setq placeholder (c-point 'boi)) |
1111 (and (or (looking-at "enum[ \t\n]+") | 1161 (and (or (looking-at "enum[ \t\n]+") |
1112 (eq char-before-ip ?=)) | 1162 (save-excursion |
1163 (goto-char indent-point) | |
1164 (while (and (> (point) placeholder) | |
1165 (= (c-backward-token-1 1 t) 0) | |
1166 (/= (char-after) ?=))) | |
1167 (eq (char-after) ?=))) | |
1113 (save-excursion | 1168 (save-excursion |
1114 (skip-chars-forward "^;(" indent-point) | 1169 (skip-chars-forward "^;(" indent-point) |
1115 (not (memq (char-after) '(?\; ?\())) | 1170 (not (memq (char-after) '(?\; ?\())) |
1116 ))) | 1171 ))) |
1117 (c-add-syntax 'brace-list-open placeholder)) | 1172 (c-add-syntax 'brace-list-open placeholder)) |
1120 (c-add-syntax 'inline-open) | 1175 (c-add-syntax 'inline-open) |
1121 (c-add-syntax 'inclass (aref inclass-p 0))) | 1176 (c-add-syntax 'inclass (aref inclass-p 0))) |
1122 ;; CASE 5A.5: ordinary defun open | 1177 ;; CASE 5A.5: ordinary defun open |
1123 (t | 1178 (t |
1124 (goto-char placeholder) | 1179 (goto-char placeholder) |
1125 (c-add-syntax 'defun-open (c-point 'bol)) | 1180 (if inclass-p |
1181 (c-add-syntax 'defun-open (c-point 'boi)) | |
1182 (c-add-syntax 'defun-open (c-point 'bol))) | |
1126 ))) | 1183 ))) |
1127 ;; CASE 5B: first K&R arg decl or member init | 1184 ;; CASE 5B: first K&R arg decl or member init |
1128 ((c-just-after-func-arglist-p) | 1185 ((c-just-after-func-arglist-p) |
1129 (cond | 1186 (cond |
1130 ;; CASE 5B.1: a member init | 1187 ;; CASE 5B.1: a member init |
1300 ((and inclass-p | 1357 ((and inclass-p |
1301 c-access-key | 1358 c-access-key |
1302 (looking-at c-access-key)) | 1359 (looking-at c-access-key)) |
1303 (c-add-syntax 'access-label (c-point 'bonl)) | 1360 (c-add-syntax 'access-label (c-point 'bonl)) |
1304 (c-add-syntax 'inclass (aref inclass-p 0))) | 1361 (c-add-syntax 'inclass (aref inclass-p 0))) |
1305 ;; CASE 5F: extern-lang-close? | 1362 ;; CASE 5F: extern-lang-close or namespace-close? |
1306 ((and inenclosing-p | 1363 ((and inenclosing-p |
1307 (eq char-after-ip ?})) | 1364 (eq char-after-ip ?})) |
1308 (setq tmpsymbol (if (eq inenclosing-p 'extern) | 1365 (setq tmpsymbol (if (eq inenclosing-p 'extern) |
1309 'extern-lang-close | 1366 'extern-lang-close |
1310 'namespace-close)) | 1367 'namespace-close)) |
1387 (goto-char (aref inclass-p 1)) | 1444 (goto-char (aref inclass-p 1)) |
1388 (or (= (point) (c-point 'boi)) | 1445 (or (= (point) (c-point 'boi)) |
1389 (goto-char (aref inclass-p 0))) | 1446 (goto-char (aref inclass-p 0))) |
1390 (cond | 1447 (cond |
1391 ((eq inenclosing-p 'extern) | 1448 ((eq inenclosing-p 'extern) |
1392 (c-add-syntax 'inextern-lang)) | 1449 (c-add-syntax 'inextern-lang (c-point 'boi))) |
1393 ((eq inenclosing-p 'namespace) | 1450 ((eq inenclosing-p 'namespace) |
1394 (c-add-syntax 'innamespace)) | 1451 (c-add-syntax 'innamespace (c-point 'boi))) |
1395 (t (c-add-syntax 'inclass (c-point 'boi)))) | 1452 (t (c-add-syntax 'inclass (c-point 'boi)))) |
1396 )) | 1453 )) |
1397 )) | 1454 )) |
1398 ;; CASE 5J: we are at an ObjC or Java method definition | 1455 ;; CASE 5J: we are at an ObjC or Java method definition |
1399 ;; continuation line. | 1456 ;; continuation line. |
1564 (c-add-syntax 'class-open placeholder)) | 1621 (c-add-syntax 'class-open placeholder)) |
1565 ;; CASE 9B.2: brace-list-open | 1622 ;; CASE 9B.2: brace-list-open |
1566 ((or (save-excursion | 1623 ((or (save-excursion |
1567 (goto-char placeholder) | 1624 (goto-char placeholder) |
1568 (looking-at "\\<enum\\>")) | 1625 (looking-at "\\<enum\\>")) |
1569 (eq char-before-ip ?=)) | 1626 (save-excursion |
1627 (goto-char indent-point) | |
1628 (while (and (> (point) placeholder) | |
1629 (= (c-backward-token-1 1 t) 0) | |
1630 (/= (char-after) ?=))) | |
1631 (eq (char-after) ?=))) | |
1570 (c-add-syntax 'brace-list-open placeholder)) | 1632 (c-add-syntax 'brace-list-open placeholder)) |
1571 ;; CASE 9B.3: catch-all for unknown construct. | 1633 ;; CASE 9B.3: catch-all for unknown construct. |
1572 (t | 1634 (t |
1573 ;; Can and should I add an extensibility hook here? | 1635 ;; Can and should I add an extensibility hook here? |
1574 ;; Something like c-recognize-hook so support for | 1636 ;; Something like c-recognize-hook so support for |
1640 (goto-char containing-sexp) | 1702 (goto-char containing-sexp) |
1641 (if (/= (point) (c-point 'boi)) | 1703 (if (/= (point) (c-point 'boi)) |
1642 (c-beginning-of-statement-1 lim)) | 1704 (c-beginning-of-statement-1 lim)) |
1643 (c-point 'boi)))) | 1705 (c-point 'boi)))) |
1644 (cond | 1706 (cond |
1645 ;; CASE 14A: does this close an inline? | 1707 ;; CASE 14A: does this close an inline or a function in |
1646 ((let ((inclass-p (progn | 1708 ;; an extern block or namespace? |
1647 (goto-char containing-sexp) | 1709 ((progn |
1648 (c-search-uplist-for-classkey state)))) | 1710 (goto-char containing-sexp) |
1649 ;; inenclosing-p in higher level let* | 1711 (setq placeholder (c-search-uplist-for-classkey state))) |
1650 (setq inenclosing-p (and inclass-p | 1712 (goto-char (aref placeholder 0)) |
1651 (progn | 1713 (if (looking-at c-extra-toplevel-key) |
1652 (goto-char (aref inclass-p 0)) | 1714 (c-add-syntax 'defun-close relpos) |
1653 (looking-at c-extra-toplevel-key)))) | 1715 (c-add-syntax 'inline-close relpos))) |
1654 (and inclass-p (not inenclosing-p))) | |
1655 (c-add-syntax 'inline-close relpos)) | |
1656 ;; CASE 14B: if there an enclosing brace that hasn't | 1716 ;; CASE 14B: if there an enclosing brace that hasn't |
1657 ;; been narrowed out by a class, then this is a | 1717 ;; been narrowed out by a class, then this is a |
1658 ;; block-close | 1718 ;; block-close |
1659 ((and (not inenclosing-p) | 1719 ((and (not inenclosing-p) |
1660 (c-most-enclosing-brace state)) | 1720 (c-most-enclosing-brace state)) |