diff options
| author | Alan Mackenzie | 2019-04-23 09:16:05 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2019-04-23 09:16:05 +0000 |
| commit | 0d5caa9a0c668d06ab650392bd52ad03a4dfbd1a (patch) | |
| tree | 4de7b5bce32722274c6d153de30e042b1516890f | |
| parent | 085929ca9309a170b5b4252448f1291e3db2b594 (diff) | |
| download | emacs-0d5caa9a0c668d06ab650392bd52ad03a4dfbd1a.tar.gz emacs-0d5caa9a0c668d06ab650392bd52ad03a4dfbd1a.zip | |
Optimize for typing characters into long C++ raw strings.
* lisp/progmodes/cc-fonts.el (c-font-lock-complex-decl-prepare)
(c-font-lock-objc-methods) (c-font-lock-declarations, c-font-lock-enum-tail)
(c-font-lock-cut-off-declarators, c-font-lock-enclosing-decls): If the chunk
been fontified consists entirely of comments and strings, don't attempt to
perform the function's action.
* lisp/progmodes/cc-mode.el (c-before-change-check-unbalanced-strings): Don't
expand (c-new-BEG c-new-END) unnecessarily to the entire raw string being
fontified.
(c-fl-decl-start, c-fl-decl-end): When in a (raw or otherwise) string, don't
return a position outside of the string (which used to cause unneeded
fontification).
| -rw-r--r-- | lisp/progmodes/cc-fonts.el | 804 | ||||
| -rw-r--r-- | lisp/progmodes/cc-mode.el | 166 |
2 files changed, 492 insertions, 478 deletions
diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el index 5832f1f451c..4a5cf5719be 100644 --- a/lisp/progmodes/cc-fonts.el +++ b/lisp/progmodes/cc-fonts.el | |||
| @@ -880,48 +880,51 @@ casts and declarations are fontified. Used on level 2 and higher." | |||
| 880 | (when (bobp) | 880 | (when (bobp) |
| 881 | (c-clear-found-types)) | 881 | (c-clear-found-types)) |
| 882 | 882 | ||
| 883 | ;; Clear the c-type char properties which mark the region, to recalculate | 883 | (c-skip-comments-and-strings limit) |
| 884 | ;; them properly. The most interesting properties are those put on the | 884 | (when (< (point) limit) |
| 885 | ;; closest token before the region. | 885 | |
| 886 | (save-excursion | 886 | ;; Clear the c-type char properties which mark the region, to recalculate |
| 887 | (let ((pos (point))) | 887 | ;; them properly. The most interesting properties are those put on the |
| 888 | (c-backward-syntactic-ws) | 888 | ;; closest token before the region. |
| 889 | (c-clear-char-properties | 889 | (save-excursion |
| 890 | (if (and (not (bobp)) | 890 | (let ((pos (point))) |
| 891 | (memq (c-get-char-property (1- (point)) 'c-type) | 891 | (c-backward-syntactic-ws) |
| 892 | '(c-decl-arg-start | 892 | (c-clear-char-properties |
| 893 | c-decl-end | 893 | (if (and (not (bobp)) |
| 894 | c-decl-id-start | 894 | (memq (c-get-char-property (1- (point)) 'c-type) |
| 895 | c-decl-type-start))) | 895 | '(c-decl-arg-start |
| 896 | (1- (point)) | 896 | c-decl-end |
| 897 | pos) | 897 | c-decl-id-start |
| 898 | limit 'c-type))) | 898 | c-decl-type-start))) |
| 899 | 899 | (1- (point)) | |
| 900 | ;; Update `c-state-cache' to the beginning of the region. This will | 900 | pos) |
| 901 | ;; make `c-beginning-of-syntax' go faster when it's used later on, | 901 | limit 'c-type))) |
| 902 | ;; and it's near the point most of the time. | 902 | |
| 903 | (c-parse-state) | 903 | ;; Update `c-state-cache' to the beginning of the region. This will |
| 904 | 904 | ;; make `c-beginning-of-syntax' go faster when it's used later on, | |
| 905 | ;; Check if the fontified region starts inside a declarator list so | 905 | ;; and it's near the point most of the time. |
| 906 | ;; that `c-font-lock-declarators' should be called at the start. | 906 | (c-parse-state) |
| 907 | ;; The declared identifiers are font-locked correctly as types, if | 907 | |
| 908 | ;; that is what they are. | 908 | ;; Check if the fontified region starts inside a declarator list so |
| 909 | (let ((prop (save-excursion | 909 | ;; that `c-font-lock-declarators' should be called at the start. |
| 910 | (c-backward-syntactic-ws) | 910 | ;; The declared identifiers are font-locked correctly as types, if |
| 911 | (unless (bobp) | 911 | ;; that is what they are. |
| 912 | (c-get-char-property (1- (point)) 'c-type))))) | 912 | (let ((prop (save-excursion |
| 913 | (when (memq prop '(c-decl-id-start c-decl-type-start)) | 913 | (c-backward-syntactic-ws) |
| 914 | (c-forward-syntactic-ws limit) | 914 | (unless (bobp) |
| 915 | (c-font-lock-declarators limit t (eq prop 'c-decl-type-start) | 915 | (c-get-char-property (1- (point)) 'c-type))))) |
| 916 | (not (c-bs-at-toplevel-p (point)))))) | 916 | (when (memq prop '(c-decl-id-start c-decl-type-start)) |
| 917 | 917 | (c-forward-syntactic-ws limit) | |
| 918 | (setq c-font-lock-context ;; (c-guess-font-lock-context) | 918 | (c-font-lock-declarators limit t (eq prop 'c-decl-type-start) |
| 919 | (save-excursion | 919 | (not (c-bs-at-toplevel-p (point)))))) |
| 920 | (if (and c-cpp-expr-intro-re | 920 | |
| 921 | (c-beginning-of-macro) | 921 | (setq c-font-lock-context ;; (c-guess-font-lock-context) |
| 922 | (looking-at c-cpp-expr-intro-re)) | 922 | (save-excursion |
| 923 | 'in-cpp-expr))) | 923 | (if (and c-cpp-expr-intro-re |
| 924 | nil) | 924 | (c-beginning-of-macro) |
| 925 | (looking-at c-cpp-expr-intro-re)) | ||
| 926 | 'in-cpp-expr))) | ||
| 927 | nil)) | ||
| 925 | 928 | ||
| 926 | (defun c-font-lock-<>-arglists (limit) | 929 | (defun c-font-lock-<>-arglists (limit) |
| 927 | ;; This function will be called from font-lock for a region bounded by POINT | 930 | ;; This function will be called from font-lock for a region bounded by POINT |
| @@ -936,73 +939,76 @@ casts and declarations are fontified. Used on level 2 and higher." | |||
| 936 | ;; | 939 | ;; |
| 937 | ;; This function might do hidden buffer changes. | 940 | ;; This function might do hidden buffer changes. |
| 938 | 941 | ||
| 939 | (let (;; The font-lock package in Emacs is known to clobber | 942 | (c-skip-comments-and-strings limit) |
| 940 | ;; `parse-sexp-lookup-properties' (when it exists). | 943 | (when (< (point) limit) |
| 941 | (parse-sexp-lookup-properties | ||
| 942 | (cc-eval-when-compile | ||
| 943 | (boundp 'parse-sexp-lookup-properties))) | ||
| 944 | (c-parse-and-markup-<>-arglists t) | ||
| 945 | c-restricted-<>-arglists | ||
| 946 | id-start id-end id-face pos kwd-sym) | ||
| 947 | 944 | ||
| 948 | (while (and (< (point) limit) | 945 | (let (;; The font-lock package in Emacs is known to clobber |
| 949 | (re-search-forward c-opt-<>-arglist-start limit t)) | 946 | ;; `parse-sexp-lookup-properties' (when it exists). |
| 947 | (parse-sexp-lookup-properties | ||
| 948 | (cc-eval-when-compile | ||
| 949 | (boundp 'parse-sexp-lookup-properties))) | ||
| 950 | (c-parse-and-markup-<>-arglists t) | ||
| 951 | c-restricted-<>-arglists | ||
| 952 | id-start id-end id-face pos kwd-sym) | ||
| 950 | 953 | ||
| 951 | (setq id-start (match-beginning 1) | 954 | (while (and (< (point) limit) |
| 952 | id-end (match-end 1) | 955 | (re-search-forward c-opt-<>-arglist-start limit t)) |
| 953 | pos (point)) | ||
| 954 | 956 | ||
| 955 | (goto-char id-start) | 957 | (setq id-start (match-beginning 1) |
| 956 | (unless (c-skip-comments-and-strings limit) | 958 | id-end (match-end 1) |
| 957 | (setq kwd-sym nil | 959 | pos (point)) |
| 958 | c-restricted-<>-arglists nil | ||
| 959 | id-face (get-text-property id-start 'face)) | ||
| 960 | |||
| 961 | (if (cond | ||
| 962 | ((eq id-face 'font-lock-type-face) | ||
| 963 | ;; The identifier got the type face so it has already been | ||
| 964 | ;; handled in `c-font-lock-declarations'. | ||
| 965 | nil) | ||
| 966 | |||
| 967 | ((eq id-face 'font-lock-keyword-face) | ||
| 968 | (when (looking-at c-opt-<>-sexp-key) | ||
| 969 | ;; There's a special keyword before the "<" that tells | ||
| 970 | ;; that it's an angle bracket arglist. | ||
| 971 | (setq kwd-sym (c-keyword-sym (match-string 1))))) | ||
| 972 | |||
| 973 | (t | ||
| 974 | ;; There's a normal identifier before the "<". If we're not in | ||
| 975 | ;; a declaration context then we set `c-restricted-<>-arglists' | ||
| 976 | ;; to avoid recognizing templates in function calls like "foo (a | ||
| 977 | ;; < b, c > d)". | ||
| 978 | (c-backward-syntactic-ws) | ||
| 979 | (when (and (memq (char-before) '(?\( ?,)) | ||
| 980 | (not (eq (get-text-property (1- (point)) 'c-type) | ||
| 981 | 'c-decl-arg-start))) | ||
| 982 | (setq c-restricted-<>-arglists t)) | ||
| 983 | t)) | ||
| 984 | 960 | ||
| 985 | (progn | 961 | (goto-char id-start) |
| 986 | (goto-char (1- pos)) | 962 | (unless (c-skip-comments-and-strings limit) |
| 987 | ;; Check for comment/string both at the identifier and | 963 | (setq kwd-sym nil |
| 988 | ;; at the "<". | 964 | c-restricted-<>-arglists nil |
| 989 | (unless (c-skip-comments-and-strings limit) | 965 | id-face (get-text-property id-start 'face)) |
| 990 | 966 | ||
| 991 | (c-fontify-types-and-refs () | 967 | (if (cond |
| 992 | (when (c-forward-<>-arglist (c-keyword-member | 968 | ((eq id-face 'font-lock-type-face) |
| 993 | kwd-sym 'c-<>-type-kwds)) | 969 | ;; The identifier got the type face so it has already been |
| 994 | (when (and c-opt-identifier-concat-key | 970 | ;; handled in `c-font-lock-declarations'. |
| 995 | (not (get-text-property id-start 'face))) | 971 | nil) |
| 996 | (c-forward-syntactic-ws) | 972 | |
| 997 | (cond ((looking-at c-opt-identifier-concat-key) | 973 | ((eq id-face 'font-lock-keyword-face) |
| 998 | (c-put-font-lock-face id-start id-end | 974 | (when (looking-at c-opt-<>-sexp-key) |
| 999 | c-reference-face-name)) | 975 | ;; There's a special keyword before the "<" that tells |
| 1000 | ((eq (char-after) ?\()) | 976 | ;; that it's an angle bracket arglist. |
| 1001 | (t (c-put-font-lock-face id-start id-end | 977 | (setq kwd-sym (c-keyword-sym (match-string 1))))) |
| 1002 | 'font-lock-type-face)))))) | 978 | |
| 1003 | 979 | (t | |
| 1004 | (goto-char pos))) | 980 | ;; There's a normal identifier before the "<". If we're not in |
| 1005 | (goto-char pos))))) | 981 | ;; a declaration context then we set `c-restricted-<>-arglists' |
| 982 | ;; to avoid recognizing templates in function calls like "foo (a | ||
| 983 | ;; < b, c > d)". | ||
| 984 | (c-backward-syntactic-ws) | ||
| 985 | (when (and (memq (char-before) '(?\( ?,)) | ||
| 986 | (not (eq (get-text-property (1- (point)) 'c-type) | ||
| 987 | 'c-decl-arg-start))) | ||
| 988 | (setq c-restricted-<>-arglists t)) | ||
| 989 | t)) | ||
| 990 | |||
| 991 | (progn | ||
| 992 | (goto-char (1- pos)) | ||
| 993 | ;; Check for comment/string both at the identifier and | ||
| 994 | ;; at the "<". | ||
| 995 | (unless (c-skip-comments-and-strings limit) | ||
| 996 | |||
| 997 | (c-fontify-types-and-refs () | ||
| 998 | (when (c-forward-<>-arglist (c-keyword-member | ||
| 999 | kwd-sym 'c-<>-type-kwds)) | ||
| 1000 | (when (and c-opt-identifier-concat-key | ||
| 1001 | (not (get-text-property id-start 'face))) | ||
| 1002 | (c-forward-syntactic-ws) | ||
| 1003 | (cond ((looking-at c-opt-identifier-concat-key) | ||
| 1004 | (c-put-font-lock-face id-start id-end | ||
| 1005 | c-reference-face-name)) | ||
| 1006 | ((eq (char-after) ?\()) | ||
| 1007 | (t (c-put-font-lock-face id-start id-end | ||
| 1008 | 'font-lock-type-face)))))) | ||
| 1009 | |||
| 1010 | (goto-char pos))) | ||
| 1011 | (goto-char pos)))))) | ||
| 1006 | nil) | 1012 | nil) |
| 1007 | 1013 | ||
| 1008 | (defun c-font-lock-declarators (limit list types not-top | 1014 | (defun c-font-lock-declarators (limit list types not-top |
| @@ -1311,227 +1317,229 @@ casts and declarations are fontified. Used on level 2 and higher." | |||
| 1311 | ;; This function might do hidden buffer changes. | 1317 | ;; This function might do hidden buffer changes. |
| 1312 | 1318 | ||
| 1313 | ;;(message "c-font-lock-declarations search from %s to %s" (point) limit) | 1319 | ;;(message "c-font-lock-declarations search from %s to %s" (point) limit) |
| 1320 | (c-skip-comments-and-strings limit) | ||
| 1321 | (when (< (point) limit) | ||
| 1322 | |||
| 1323 | (save-restriction | ||
| 1324 | (let (;; The position where `c-find-decl-spots' last stopped. | ||
| 1325 | start-pos | ||
| 1326 | ;; o - 'decl if we're in an arglist containing declarations | ||
| 1327 | ;; (but if `c-recognize-paren-inits' is set it might also be | ||
| 1328 | ;; an initializer arglist); | ||
| 1329 | ;; o - '<> if the arglist is of angle bracket type; | ||
| 1330 | ;; o - 'arglist if it's some other arglist; | ||
| 1331 | ;; o - nil, if not in an arglist at all. This includes the | ||
| 1332 | ;; parenthesized condition which follows "if", "while", etc. | ||
| 1333 | context | ||
| 1334 | ;; A list of starting positions of possible type declarations, or of | ||
| 1335 | ;; the typedef preceding one, if any. | ||
| 1336 | last-cast-end | ||
| 1337 | ;; The result from `c-forward-decl-or-cast-1'. | ||
| 1338 | decl-or-cast | ||
| 1339 | ;; The maximum of the end positions of all the checked type | ||
| 1340 | ;; decl expressions in the successfully identified | ||
| 1341 | ;; declarations. The position might be either before or | ||
| 1342 | ;; after the syntactic whitespace following the last token | ||
| 1343 | ;; in the type decl expression. | ||
| 1344 | (max-type-decl-end 0) | ||
| 1345 | ;; Same as `max-type-decl-*', but used when we're before | ||
| 1346 | ;; `token-pos'. | ||
| 1347 | (max-type-decl-end-before-token 0) | ||
| 1348 | ;; End of <..> construct which has had c-<>-arg-sep c-type | ||
| 1349 | ;; properties set within it. | ||
| 1350 | (max-<>-end 0) | ||
| 1351 | ;; Set according to the context to direct the heuristics for | ||
| 1352 | ;; recognizing C++ templates. | ||
| 1353 | c-restricted-<>-arglists | ||
| 1354 | ;; Turn on recording of identifier ranges in | ||
| 1355 | ;; `c-forward-decl-or-cast-1' and `c-forward-label' for | ||
| 1356 | ;; later fontification. | ||
| 1357 | (c-record-type-identifiers t) | ||
| 1358 | label-type | ||
| 1359 | c-record-ref-identifiers | ||
| 1360 | ;; Make `c-forward-type' calls mark up template arglists if | ||
| 1361 | ;; it finds any. That's necessary so that we later will | ||
| 1362 | ;; stop inside them to fontify types there. | ||
| 1363 | (c-parse-and-markup-<>-arglists t) | ||
| 1364 | ;; The font-lock package in Emacs is known to clobber | ||
| 1365 | ;; `parse-sexp-lookup-properties' (when it exists). | ||
| 1366 | (parse-sexp-lookup-properties | ||
| 1367 | (cc-eval-when-compile | ||
| 1368 | (boundp 'parse-sexp-lookup-properties)) | ||
| 1369 | )) | ||
| 1370 | |||
| 1371 | ;; Below we fontify a whole declaration even when it crosses the limit, | ||
| 1372 | ;; to avoid gaps when jit/lazy-lock fontifies the file a block at a | ||
| 1373 | ;; time. That is however annoying during editing, e.g. the following is | ||
| 1374 | ;; a common situation while the first line is being written: | ||
| 1375 | ;; | ||
| 1376 | ;; my_variable | ||
| 1377 | ;; some_other_variable = 0; | ||
| 1378 | ;; | ||
| 1379 | ;; font-lock will put the limit at the beginning of the second line | ||
| 1380 | ;; here, and if we go past it we'll fontify "my_variable" as a type and | ||
| 1381 | ;; "some_other_variable" as an identifier, and the latter will not | ||
| 1382 | ;; correct itself until the second line is changed. To avoid that we | ||
| 1383 | ;; narrow to the limit if the region to fontify is a single line. | ||
| 1384 | (if (<= limit (c-point 'bonl)) | ||
| 1385 | (narrow-to-region | ||
| 1386 | (point-min) | ||
| 1387 | (save-excursion | ||
| 1388 | ;; Narrow after any operator chars following the limit though, | ||
| 1389 | ;; since those characters can be useful in recognizing a | ||
| 1390 | ;; declaration (in particular the '{' that opens a function body | ||
| 1391 | ;; after the header). | ||
| 1392 | (goto-char limit) | ||
| 1393 | (skip-chars-forward c-nonsymbol-chars) | ||
| 1394 | (point)))) | ||
| 1395 | |||
| 1396 | (c-find-decl-spots | ||
| 1397 | limit | ||
| 1398 | c-decl-start-re | ||
| 1399 | (eval c-maybe-decl-faces) | ||
| 1400 | |||
| 1401 | (lambda (match-pos inside-macro &optional toplev) | ||
| 1402 | ;; Note to maintainers: don't use `limit' inside this lambda form; | ||
| 1403 | ;; c-find-decl-spots sometimes narrows to less than `limit'. | ||
| 1404 | (setq start-pos (point)) | ||
| 1405 | (when | ||
| 1406 | ;; The result of the form below is true when we don't recognize a | ||
| 1407 | ;; declaration or cast, and we don't recognize a "non-decl", | ||
| 1408 | ;; typically a brace list. | ||
| 1409 | (if (or (and (eq (get-text-property (point) 'face) | ||
| 1410 | 'font-lock-keyword-face) | ||
| 1411 | (looking-at c-not-decl-init-keywords)) | ||
| 1412 | (and c-macro-with-semi-re | ||
| 1413 | (looking-at c-macro-with-semi-re))) ; 2008-11-04 | ||
| 1414 | ;; Don't do anything more if we're looking at a keyword that | ||
| 1415 | ;; can't start a declaration. | ||
| 1416 | t | ||
| 1417 | |||
| 1418 | ;; Set `context' and `c-restricted-<>-arglists'. Look for | ||
| 1419 | ;; "<" for the sake of C++-style template arglists. | ||
| 1420 | ;; Ignore "(" when it's part of a control flow construct | ||
| 1421 | ;; (e.g. "for ("). | ||
| 1422 | (let ((got-context | ||
| 1423 | (c-get-fontification-context | ||
| 1424 | match-pos | ||
| 1425 | (< match-pos (if inside-macro | ||
| 1426 | max-type-decl-end-before-token | ||
| 1427 | max-type-decl-end)) | ||
| 1428 | toplev))) | ||
| 1429 | (setq context (car got-context) | ||
| 1430 | c-restricted-<>-arglists (cdr got-context))) | ||
| 1431 | |||
| 1432 | ;; Check we haven't missed a preceding "typedef". | ||
| 1433 | (when (not (looking-at c-typedef-key)) | ||
| 1434 | (c-backward-syntactic-ws) | ||
| 1435 | (c-backward-token-2) | ||
| 1436 | (or (looking-at c-typedef-key) | ||
| 1437 | (goto-char start-pos))) | ||
| 1438 | |||
| 1439 | ;; In QT, "more" is an irritating keyword that expands to nothing. | ||
| 1440 | ;; We skip over it to prevent recognition of "more slots: <symbol>" | ||
| 1441 | ;; as a bitfield declaration. | ||
| 1442 | (when (and (c-major-mode-is 'c++-mode) | ||
| 1443 | (looking-at | ||
| 1444 | (concat "\\(more\\)\\([^" c-symbol-chars "]\\|$\\)"))) | ||
| 1445 | (goto-char (match-end 1)) | ||
| 1446 | (c-forward-syntactic-ws)) | ||
| 1314 | 1447 | ||
| 1315 | (save-restriction | 1448 | ;; Now analyze the construct. |
| 1316 | (let (;; The position where `c-find-decl-spots' last stopped. | 1449 | (if (eq context 'not-decl) |
| 1317 | start-pos | 1450 | (progn |
| 1318 | ;; o - 'decl if we're in an arglist containing declarations | 1451 | (setq decl-or-cast nil) |
| 1319 | ;; (but if `c-recognize-paren-inits' is set it might also be | 1452 | (if (c-syntactic-re-search-forward |
| 1320 | ;; an initializer arglist); | 1453 | "," (min limit (point-max)) 'at-limit t) |
| 1321 | ;; o - '<> if the arglist is of angle bracket type; | 1454 | (c-put-char-property (1- (point)) 'c-type 'c-not-decl)) |
| 1322 | ;; o - 'arglist if it's some other arglist; | 1455 | nil) |
| 1323 | ;; o - nil, if not in an arglist at all. This includes the | 1456 | (setq decl-or-cast |
| 1324 | ;; parenthesized condition which follows "if", "while", etc. | 1457 | (c-forward-decl-or-cast-1 |
| 1325 | context | 1458 | match-pos context last-cast-end)) |
| 1326 | ;; A list of starting positions of possible type declarations, or of | 1459 | |
| 1327 | ;; the typedef preceding one, if any. | 1460 | ;; Ensure that c-<>-arg-sep c-type properties are in place on the |
| 1328 | last-cast-end | 1461 | ;; commas separating the arguments inside template/generic <..>s. |
| 1329 | ;; The result from `c-forward-decl-or-cast-1'. | 1462 | (when (and (eq (char-before match-pos) ?<) |
| 1330 | decl-or-cast | 1463 | (> match-pos max-<>-end)) |
| 1331 | ;; The maximum of the end positions of all the checked type | 1464 | (save-excursion |
| 1332 | ;; decl expressions in the successfully identified | 1465 | (goto-char match-pos) |
| 1333 | ;; declarations. The position might be either before or | 1466 | (c-backward-token-2) |
| 1334 | ;; after the syntactic whitespace following the last token | 1467 | (if (and |
| 1335 | ;; in the type decl expression. | 1468 | (eq (char-after) ?<) |
| 1336 | (max-type-decl-end 0) | 1469 | (let ((c-restricted-<>-arglists |
| 1337 | ;; Same as `max-type-decl-*', but used when we're before | 1470 | (save-excursion |
| 1338 | ;; `token-pos'. | 1471 | (c-backward-token-2) |
| 1339 | (max-type-decl-end-before-token 0) | 1472 | (and |
| 1340 | ;; End of <..> construct which has had c-<>-arg-sep c-type | 1473 | (not (looking-at c-opt-<>-sexp-key)) |
| 1341 | ;; properties set within it. | 1474 | (progn (c-backward-syntactic-ws) |
| 1342 | (max-<>-end 0) | 1475 | (memq (char-before) '(?\( ?,))) |
| 1343 | ;; Set according to the context to direct the heuristics for | 1476 | (not (eq (c-get-char-property (1- (point)) |
| 1344 | ;; recognizing C++ templates. | 1477 | 'c-type) |
| 1345 | c-restricted-<>-arglists | 1478 | 'c-decl-arg-start)))))) |
| 1346 | ;; Turn on recording of identifier ranges in | 1479 | (c-forward-<>-arglist nil))) |
| 1347 | ;; `c-forward-decl-or-cast-1' and `c-forward-label' for | 1480 | (setq max-<>-end (point))))) |
| 1348 | ;; later fontification. | 1481 | |
| 1349 | (c-record-type-identifiers t) | 1482 | (cond |
| 1350 | label-type | 1483 | ((eq decl-or-cast 'cast) |
| 1351 | c-record-ref-identifiers | 1484 | ;; Save the position after the previous cast so we can feed |
| 1352 | ;; Make `c-forward-type' calls mark up template arglists if | 1485 | ;; it to `c-forward-decl-or-cast-1' in the next round. That |
| 1353 | ;; it finds any. That's necessary so that we later will | 1486 | ;; helps it discover cast chains like "(a) (b) c". |
| 1354 | ;; stop inside them to fontify types there. | 1487 | (setq last-cast-end (point)) |
| 1355 | (c-parse-and-markup-<>-arglists t) | 1488 | (c-fontify-recorded-types-and-refs) |
| 1356 | ;; The font-lock package in Emacs is known to clobber | 1489 | nil) |
| 1357 | ;; `parse-sexp-lookup-properties' (when it exists). | 1490 | |
| 1358 | (parse-sexp-lookup-properties | 1491 | (decl-or-cast |
| 1359 | (cc-eval-when-compile | 1492 | ;; We've found a declaration. |
| 1360 | (boundp 'parse-sexp-lookup-properties)) | 1493 | |
| 1361 | )) | 1494 | ;; Set `max-type-decl-end' or `max-type-decl-end-before-token' |
| 1362 | 1495 | ;; under the assumption that we're after the first type decl | |
| 1363 | ;; Below we fontify a whole declaration even when it crosses the limit, | 1496 | ;; expression in the declaration now. That's not really true; |
| 1364 | ;; to avoid gaps when jit/lazy-lock fontifies the file a block at a | 1497 | ;; we could also be after a parenthesized initializer |
| 1365 | ;; time. That is however annoying during editing, e.g. the following is | 1498 | ;; expression in C++, but this is only used as a last resort |
| 1366 | ;; a common situation while the first line is being written: | 1499 | ;; to slant ambiguous expression/declarations, and overall |
| 1367 | ;; | 1500 | ;; it's worth the risk to occasionally fontify an expression |
| 1368 | ;; my_variable | 1501 | ;; as a declaration in an initializer expression compared to |
| 1369 | ;; some_other_variable = 0; | 1502 | ;; getting ambiguous things in normal function prototypes |
| 1370 | ;; | 1503 | ;; fontified as expressions. |
| 1371 | ;; font-lock will put the limit at the beginning of the second line | 1504 | (if inside-macro |
| 1372 | ;; here, and if we go past it we'll fontify "my_variable" as a type and | 1505 | (when (> (point) max-type-decl-end-before-token) |
| 1373 | ;; "some_other_variable" as an identifier, and the latter will not | 1506 | (setq max-type-decl-end-before-token (point))) |
| 1374 | ;; correct itself until the second line is changed. To avoid that we | 1507 | (when (> (point) max-type-decl-end) |
| 1375 | ;; narrow to the limit if the region to fontify is a single line. | 1508 | (setq max-type-decl-end (point)))) |
| 1376 | (if (<= limit (c-point 'bonl)) | 1509 | (goto-char start-pos) |
| 1377 | (narrow-to-region | 1510 | (c-font-lock-single-decl limit decl-or-cast match-pos |
| 1378 | (point-min) | 1511 | context |
| 1379 | (save-excursion | 1512 | (or toplev (nth 4 decl-or-cast)))) |
| 1380 | ;; Narrow after any operator chars following the limit though, | 1513 | |
| 1381 | ;; since those characters can be useful in recognizing a | 1514 | (t t)))) |
| 1382 | ;; declaration (in particular the '{' that opens a function body | 1515 | |
| 1383 | ;; after the header). | 1516 | ;; It was a false alarm. Check if we're in a label (or other |
| 1384 | (goto-char limit) | 1517 | ;; construct with `:' except bitfield) instead. |
| 1385 | (skip-chars-forward c-nonsymbol-chars) | 1518 | (goto-char start-pos) |
| 1386 | (point)))) | 1519 | (when (setq label-type (c-forward-label t match-pos nil)) |
| 1387 | 1520 | ;; Can't use `c-fontify-types-and-refs' here since we | |
| 1388 | (c-find-decl-spots | 1521 | ;; use the label face at times. |
| 1389 | limit | 1522 | (cond ((eq label-type 'goto-target) |
| 1390 | c-decl-start-re | 1523 | (c-put-font-lock-face (caar c-record-ref-identifiers) |
| 1391 | (eval c-maybe-decl-faces) | 1524 | (cdar c-record-ref-identifiers) |
| 1392 | 1525 | c-label-face-name)) | |
| 1393 | (lambda (match-pos inside-macro &optional toplev) | 1526 | ((eq label-type 'qt-1kwd-colon) |
| 1394 | ;; Note to maintainers: don't use `limit' inside this lambda form; | 1527 | (c-put-font-lock-face (caar c-record-ref-identifiers) |
| 1395 | ;; c-find-decl-spots sometimes narrows to less than `limit'. | 1528 | (cdar c-record-ref-identifiers) |
| 1396 | (setq start-pos (point)) | ||
| 1397 | (when | ||
| 1398 | ;; The result of the form below is true when we don't recognize a | ||
| 1399 | ;; declaration or cast, and we don't recognize a "non-decl", | ||
| 1400 | ;; typically a brace list. | ||
| 1401 | (if (or (and (eq (get-text-property (point) 'face) | ||
| 1402 | 'font-lock-keyword-face) | ||
| 1403 | (looking-at c-not-decl-init-keywords)) | ||
| 1404 | (and c-macro-with-semi-re | ||
| 1405 | (looking-at c-macro-with-semi-re))) ; 2008-11-04 | ||
| 1406 | ;; Don't do anything more if we're looking at a keyword that | ||
| 1407 | ;; can't start a declaration. | ||
| 1408 | t | ||
| 1409 | |||
| 1410 | ;; Set `context' and `c-restricted-<>-arglists'. Look for | ||
| 1411 | ;; "<" for the sake of C++-style template arglists. | ||
| 1412 | ;; Ignore "(" when it's part of a control flow construct | ||
| 1413 | ;; (e.g. "for ("). | ||
| 1414 | (let ((got-context | ||
| 1415 | (c-get-fontification-context | ||
| 1416 | match-pos | ||
| 1417 | (< match-pos (if inside-macro | ||
| 1418 | max-type-decl-end-before-token | ||
| 1419 | max-type-decl-end)) | ||
| 1420 | toplev))) | ||
| 1421 | (setq context (car got-context) | ||
| 1422 | c-restricted-<>-arglists (cdr got-context))) | ||
| 1423 | |||
| 1424 | ;; Check we haven't missed a preceding "typedef". | ||
| 1425 | (when (not (looking-at c-typedef-key)) | ||
| 1426 | (c-backward-syntactic-ws) | ||
| 1427 | (c-backward-token-2) | ||
| 1428 | (or (looking-at c-typedef-key) | ||
| 1429 | (goto-char start-pos))) | ||
| 1430 | |||
| 1431 | ;; In QT, "more" is an irritating keyword that expands to nothing. | ||
| 1432 | ;; We skip over it to prevent recognition of "more slots: <symbol>" | ||
| 1433 | ;; as a bitfield declaration. | ||
| 1434 | (when (and (c-major-mode-is 'c++-mode) | ||
| 1435 | (looking-at | ||
| 1436 | (concat "\\(more\\)\\([^" c-symbol-chars "]\\|$\\)"))) | ||
| 1437 | (goto-char (match-end 1)) | ||
| 1438 | (c-forward-syntactic-ws)) | ||
| 1439 | |||
| 1440 | ;; Now analyze the construct. | ||
| 1441 | (if (eq context 'not-decl) | ||
| 1442 | (progn | ||
| 1443 | (setq decl-or-cast nil) | ||
| 1444 | (if (c-syntactic-re-search-forward | ||
| 1445 | "," (min limit (point-max)) 'at-limit t) | ||
| 1446 | (c-put-char-property (1- (point)) 'c-type 'c-not-decl)) | ||
| 1447 | nil) | ||
| 1448 | (setq decl-or-cast | ||
| 1449 | (c-forward-decl-or-cast-1 | ||
| 1450 | match-pos context last-cast-end)) | ||
| 1451 | |||
| 1452 | ;; Ensure that c-<>-arg-sep c-type properties are in place on the | ||
| 1453 | ;; commas separating the arguments inside template/generic <..>s. | ||
| 1454 | (when (and (eq (char-before match-pos) ?<) | ||
| 1455 | (> match-pos max-<>-end)) | ||
| 1456 | (save-excursion | ||
| 1457 | (goto-char match-pos) | ||
| 1458 | (c-backward-token-2) | ||
| 1459 | (if (and | ||
| 1460 | (eq (char-after) ?<) | ||
| 1461 | (let ((c-restricted-<>-arglists | ||
| 1462 | (save-excursion | ||
| 1463 | (c-backward-token-2) | ||
| 1464 | (and | ||
| 1465 | (not (looking-at c-opt-<>-sexp-key)) | ||
| 1466 | (progn (c-backward-syntactic-ws) | ||
| 1467 | (memq (char-before) '(?\( ?,))) | ||
| 1468 | (not (eq (c-get-char-property (1- (point)) | ||
| 1469 | 'c-type) | ||
| 1470 | 'c-decl-arg-start)))))) | ||
| 1471 | (c-forward-<>-arglist nil))) | ||
| 1472 | (setq max-<>-end (point))))) | ||
| 1473 | |||
| 1474 | (cond | ||
| 1475 | ((eq decl-or-cast 'cast) | ||
| 1476 | ;; Save the position after the previous cast so we can feed | ||
| 1477 | ;; it to `c-forward-decl-or-cast-1' in the next round. That | ||
| 1478 | ;; helps it discover cast chains like "(a) (b) c". | ||
| 1479 | (setq last-cast-end (point)) | ||
| 1480 | (c-fontify-recorded-types-and-refs) | ||
| 1481 | nil) | ||
| 1482 | |||
| 1483 | (decl-or-cast | ||
| 1484 | ;; We've found a declaration. | ||
| 1485 | |||
| 1486 | ;; Set `max-type-decl-end' or `max-type-decl-end-before-token' | ||
| 1487 | ;; under the assumption that we're after the first type decl | ||
| 1488 | ;; expression in the declaration now. That's not really true; | ||
| 1489 | ;; we could also be after a parenthesized initializer | ||
| 1490 | ;; expression in C++, but this is only used as a last resort | ||
| 1491 | ;; to slant ambiguous expression/declarations, and overall | ||
| 1492 | ;; it's worth the risk to occasionally fontify an expression | ||
| 1493 | ;; as a declaration in an initializer expression compared to | ||
| 1494 | ;; getting ambiguous things in normal function prototypes | ||
| 1495 | ;; fontified as expressions. | ||
| 1496 | (if inside-macro | ||
| 1497 | (when (> (point) max-type-decl-end-before-token) | ||
| 1498 | (setq max-type-decl-end-before-token (point))) | ||
| 1499 | (when (> (point) max-type-decl-end) | ||
| 1500 | (setq max-type-decl-end (point)))) | ||
| 1501 | (goto-char start-pos) | ||
| 1502 | (c-font-lock-single-decl limit decl-or-cast match-pos | ||
| 1503 | context | ||
| 1504 | (or toplev (nth 4 decl-or-cast)))) | ||
| 1505 | |||
| 1506 | (t t)))) | ||
| 1507 | |||
| 1508 | ;; It was a false alarm. Check if we're in a label (or other | ||
| 1509 | ;; construct with `:' except bitfield) instead. | ||
| 1510 | (goto-char start-pos) | ||
| 1511 | (when (setq label-type (c-forward-label t match-pos nil)) | ||
| 1512 | ;; Can't use `c-fontify-types-and-refs' here since we | ||
| 1513 | ;; use the label face at times. | ||
| 1514 | (cond ((eq label-type 'goto-target) | ||
| 1515 | (c-put-font-lock-face (caar c-record-ref-identifiers) | ||
| 1516 | (cdar c-record-ref-identifiers) | ||
| 1517 | c-label-face-name)) | ||
| 1518 | ((eq label-type 'qt-1kwd-colon) | ||
| 1519 | (c-put-font-lock-face (caar c-record-ref-identifiers) | ||
| 1520 | (cdar c-record-ref-identifiers) | ||
| 1521 | 'font-lock-keyword-face)) | ||
| 1522 | ((eq label-type 'qt-2kwds-colon) | ||
| 1523 | (mapc | ||
| 1524 | (lambda (kwd) | ||
| 1525 | (c-put-font-lock-face (car kwd) (cdr kwd) | ||
| 1526 | 'font-lock-keyword-face)) | 1529 | 'font-lock-keyword-face)) |
| 1527 | c-record-ref-identifiers))) | 1530 | ((eq label-type 'qt-2kwds-colon) |
| 1528 | (setq c-record-ref-identifiers nil) | 1531 | (mapc |
| 1529 | ;; `c-forward-label' has probably added a `c-decl-end' | 1532 | (lambda (kwd) |
| 1530 | ;; marker, so return t to `c-find-decl-spots' to signal | 1533 | (c-put-font-lock-face (car kwd) (cdr kwd) |
| 1531 | ;; that. | 1534 | 'font-lock-keyword-face)) |
| 1532 | t)))) | 1535 | c-record-ref-identifiers))) |
| 1533 | 1536 | (setq c-record-ref-identifiers nil) | |
| 1534 | nil))) | 1537 | ;; `c-forward-label' has probably added a `c-decl-end' |
| 1538 | ;; marker, so return t to `c-find-decl-spots' to signal | ||
| 1539 | ;; that. | ||
| 1540 | t)))) | ||
| 1541 | |||
| 1542 | nil)))) | ||
| 1535 | 1543 | ||
| 1536 | (defun c-font-lock-enum-body (limit) | 1544 | (defun c-font-lock-enum-body (limit) |
| 1537 | ;; Fontify the identifiers of each enum we find by searching forward. | 1545 | ;; Fontify the identifiers of each enum we find by searching forward. |
| @@ -1561,19 +1569,21 @@ casts and declarations are fontified. Used on level 2 and higher." | |||
| 1561 | ;; | 1569 | ;; |
| 1562 | ;; Note that this function won't attempt to fontify beyond the end of the | 1570 | ;; Note that this function won't attempt to fontify beyond the end of the |
| 1563 | ;; current enum block, if any. | 1571 | ;; current enum block, if any. |
| 1564 | (let* ((paren-state (c-parse-state)) | 1572 | (c-skip-comments-and-strings limit) |
| 1565 | (encl-pos (c-most-enclosing-brace paren-state))) | 1573 | (when (< (point) limit) |
| 1566 | (when (and | 1574 | (let* ((paren-state (c-parse-state)) |
| 1567 | encl-pos | 1575 | (encl-pos (c-most-enclosing-brace paren-state))) |
| 1568 | (eq (char-after encl-pos) ?\{) | 1576 | (when (and |
| 1569 | (save-excursion | 1577 | encl-pos |
| 1570 | (goto-char encl-pos) | 1578 | (eq (char-after encl-pos) ?\{) |
| 1571 | (c-backward-over-enum-header))) | 1579 | (save-excursion |
| 1572 | (c-syntactic-skip-backward "^{," nil t) | 1580 | (goto-char encl-pos) |
| 1573 | (c-put-char-property (1- (point)) 'c-type 'c-decl-id-start) | 1581 | (c-backward-over-enum-header))) |
| 1582 | (c-syntactic-skip-backward "^{," nil t) | ||
| 1583 | (c-put-char-property (1- (point)) 'c-type 'c-decl-id-start) | ||
| 1574 | 1584 | ||
| 1575 | (c-forward-syntactic-ws) | 1585 | (c-forward-syntactic-ws) |
| 1576 | (c-font-lock-declarators limit t nil t))) | 1586 | (c-font-lock-declarators limit t nil t)))) |
| 1577 | nil) | 1587 | nil) |
| 1578 | 1588 | ||
| 1579 | (defun c-font-lock-cut-off-declarators (limit) | 1589 | (defun c-font-lock-cut-off-declarators (limit) |
| @@ -1585,46 +1595,48 @@ casts and declarations are fontified. Used on level 2 and higher." | |||
| 1585 | ;; font-lock-keyword-face. It always returns NIL to inhibit this and | 1595 | ;; font-lock-keyword-face. It always returns NIL to inhibit this and |
| 1586 | ;; prevent a repeat invocation. See elisp/lispref page "Search-based | 1596 | ;; prevent a repeat invocation. See elisp/lispref page "Search-based |
| 1587 | ;; fontification". | 1597 | ;; fontification". |
| 1588 | (let ((here (point)) | 1598 | (c-skip-comments-and-strings limit) |
| 1589 | (decl-search-lim (c-determine-limit 1000)) | 1599 | (when (< (point) limit) |
| 1590 | paren-state encl-pos token-end context decl-or-cast | 1600 | (let ((here (point)) |
| 1591 | start-pos top-level c-restricted-<>-arglists | 1601 | (decl-search-lim (c-determine-limit 1000)) |
| 1592 | c-recognize-knr-p) ; Strictly speaking, bogus, but it | 1602 | paren-state encl-pos token-end context decl-or-cast |
| 1603 | start-pos top-level c-restricted-<>-arglists | ||
| 1604 | c-recognize-knr-p) ; Strictly speaking, bogus, but it | ||
| 1593 | ; speeds up lisp.h tremendously. | 1605 | ; speeds up lisp.h tremendously. |
| 1594 | (save-excursion | 1606 | (save-excursion |
| 1595 | (when (not (c-back-over-member-initializers)) | 1607 | (when (not (c-back-over-member-initializers)) |
| 1596 | (unless (or (eobp) | 1608 | (unless (or (eobp) |
| 1597 | (looking-at "\\s(\\|\\s)")) | 1609 | (looking-at "\\s(\\|\\s)")) |
| 1598 | (forward-char)) | 1610 | (forward-char)) |
| 1599 | (c-syntactic-skip-backward "^;{}" decl-search-lim t) | 1611 | (c-syntactic-skip-backward "^;{}" decl-search-lim t) |
| 1600 | (when (eq (char-before) ?}) | 1612 | (when (eq (char-before) ?}) |
| 1601 | (c-go-list-backward) ; brace block of struct, etc.? | 1613 | (c-go-list-backward) ; brace block of struct, etc.? |
| 1602 | (c-syntactic-skip-backward "^;{}" decl-search-lim t)) | 1614 | (c-syntactic-skip-backward "^;{}" decl-search-lim t)) |
| 1603 | (when (or (bobp) | 1615 | (when (or (bobp) |
| 1604 | (memq (char-before) '(?\; ?{ ?}))) | 1616 | (memq (char-before) '(?\; ?{ ?}))) |
| 1605 | (setq token-end (point)) | 1617 | (setq token-end (point)) |
| 1606 | (c-forward-syntactic-ws here) | 1618 | (c-forward-syntactic-ws here) |
| 1607 | (when (< (point) here) | 1619 | (when (< (point) here) |
| 1608 | ;; We're now putatively at the declaration. | 1620 | ;; We're now putatively at the declaration. |
| 1609 | (setq start-pos (point)) | 1621 | (setq start-pos (point)) |
| 1610 | (setq paren-state (c-parse-state)) | 1622 | (setq paren-state (c-parse-state)) |
| 1611 | ;; At top level or inside a "{"? | 1623 | ;; At top level or inside a "{"? |
| 1612 | (if (or (not (setq encl-pos | 1624 | (if (or (not (setq encl-pos |
| 1613 | (c-most-enclosing-brace paren-state))) | 1625 | (c-most-enclosing-brace paren-state))) |
| 1614 | (eq (char-after encl-pos) ?\{)) | 1626 | (eq (char-after encl-pos) ?\{)) |
| 1615 | (progn | 1627 | (progn |
| 1616 | (setq top-level (c-at-toplevel-p)) | 1628 | (setq top-level (c-at-toplevel-p)) |
| 1617 | (let ((got-context (c-get-fontification-context | 1629 | (let ((got-context (c-get-fontification-context |
| 1618 | token-end nil top-level))) | 1630 | token-end nil top-level))) |
| 1619 | (setq context (car got-context) | 1631 | (setq context (car got-context) |
| 1620 | c-restricted-<>-arglists (cdr got-context))) | 1632 | c-restricted-<>-arglists (cdr got-context))) |
| 1621 | (setq decl-or-cast | 1633 | (setq decl-or-cast |
| 1622 | (c-forward-decl-or-cast-1 token-end context nil)) | 1634 | (c-forward-decl-or-cast-1 token-end context nil)) |
| 1623 | (when (consp decl-or-cast) | 1635 | (when (consp decl-or-cast) |
| 1624 | (goto-char start-pos) | 1636 | (goto-char start-pos) |
| 1625 | (c-font-lock-single-decl limit decl-or-cast token-end | 1637 | (c-font-lock-single-decl limit decl-or-cast token-end |
| 1626 | context top-level)))))))) | 1638 | context top-level)))))))) |
| 1627 | nil)) | 1639 | nil))) |
| 1628 | 1640 | ||
| 1629 | (defun c-font-lock-enclosing-decls (limit) | 1641 | (defun c-font-lock-enclosing-decls (limit) |
| 1630 | ;; Fontify the declarators of (nested) declarations we're in the middle of. | 1642 | ;; Fontify the declarators of (nested) declarations we're in the middle of. |
| @@ -1636,27 +1648,29 @@ casts and declarations are fontified. Used on level 2 and higher." | |||
| 1636 | ;; font-lock-keyword-face. It always returns NIL to inhibit this and | 1648 | ;; font-lock-keyword-face. It always returns NIL to inhibit this and |
| 1637 | ;; prevent a repeat invocation. See elisp/lispref page "Search-based | 1649 | ;; prevent a repeat invocation. See elisp/lispref page "Search-based |
| 1638 | ;; Fontification". | 1650 | ;; Fontification". |
| 1639 | (let* ((paren-state (c-parse-state)) | 1651 | (c-skip-comments-and-strings limit) |
| 1640 | (decl-search-lim (c-determine-limit 1000)) | 1652 | (when (< (point) limit) |
| 1641 | in-typedef ps-elt) | 1653 | (let* ((paren-state (c-parse-state)) |
| 1642 | ;; Are we in any nested struct/union/class/etc. braces? | 1654 | (decl-search-lim (c-determine-limit 1000)) |
| 1643 | (while paren-state | 1655 | in-typedef ps-elt) |
| 1644 | (setq ps-elt (car paren-state) | 1656 | ;; Are we in any nested struct/union/class/etc. braces? |
| 1645 | paren-state (cdr paren-state)) | 1657 | (while paren-state |
| 1646 | (when (and (atom ps-elt) | 1658 | (setq ps-elt (car paren-state) |
| 1647 | (eq (char-after ps-elt) ?\{)) | 1659 | paren-state (cdr paren-state)) |
| 1648 | (goto-char ps-elt) | 1660 | (when (and (atom ps-elt) |
| 1649 | (c-syntactic-skip-backward "^;{}" decl-search-lim) | 1661 | (eq (char-after ps-elt) ?\{)) |
| 1650 | (c-forward-syntactic-ws) | ||
| 1651 | (setq in-typedef (looking-at c-typedef-key)) | ||
| 1652 | (if in-typedef (c-forward-over-token-and-ws)) | ||
| 1653 | (when (and c-opt-block-decls-with-vars-key | ||
| 1654 | (looking-at c-opt-block-decls-with-vars-key)) | ||
| 1655 | (goto-char ps-elt) | 1662 | (goto-char ps-elt) |
| 1656 | (when (c-safe (c-forward-sexp)) | 1663 | (c-syntactic-skip-backward "^;{}" decl-search-lim) |
| 1657 | (c-forward-syntactic-ws) | 1664 | (c-forward-syntactic-ws) |
| 1658 | (c-font-lock-declarators limit t in-typedef | 1665 | (setq in-typedef (looking-at c-typedef-key)) |
| 1659 | (not (c-bs-at-toplevel-p (point)))))))))) | 1666 | (if in-typedef (c-forward-over-token-and-ws)) |
| 1667 | (when (and c-opt-block-decls-with-vars-key | ||
| 1668 | (looking-at c-opt-block-decls-with-vars-key)) | ||
| 1669 | (goto-char ps-elt) | ||
| 1670 | (when (c-safe (c-forward-sexp)) | ||
| 1671 | (c-forward-syntactic-ws) | ||
| 1672 | (c-font-lock-declarators limit t in-typedef | ||
| 1673 | (not (c-bs-at-toplevel-p (point))))))))))) | ||
| 1660 | 1674 | ||
| 1661 | (defun c-font-lock-raw-strings (limit) | 1675 | (defun c-font-lock-raw-strings (limit) |
| 1662 | ;; Fontify C++ raw strings. | 1676 | ;; Fontify C++ raw strings. |
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el index 35de7566c78..27ed04fea52 100644 --- a/lisp/progmodes/cc-mode.el +++ b/lisp/progmodes/cc-mode.el | |||
| @@ -1192,8 +1192,6 @@ Note that the style variables are always made local to the buffer." | |||
| 1192 | (beg-literal-type (and beg-limits | 1192 | (beg-literal-type (and beg-limits |
| 1193 | (c-literal-type beg-limits)))) | 1193 | (c-literal-type beg-limits)))) |
| 1194 | 1194 | ||
| 1195 | (when (eq end-literal-type 'string) | ||
| 1196 | (setq c-new-END (max c-new-END (cdr end-limits)))) | ||
| 1197 | ;; It is possible the buffer change will include inserting a string quote. | 1195 | ;; It is possible the buffer change will include inserting a string quote. |
| 1198 | ;; This could have the effect of flipping the meaning of any following | 1196 | ;; This could have the effect of flipping the meaning of any following |
| 1199 | ;; quotes up until the next unescaped EOL. Also guard against the change | 1197 | ;; quotes up until the next unescaped EOL. Also guard against the change |
| @@ -1282,7 +1280,6 @@ Note that the style variables are always made local to the buffer." | |||
| 1282 | 1280 | ||
| 1283 | (when (and (eq beg-literal-type 'string) | 1281 | (when (and (eq beg-literal-type 'string) |
| 1284 | (memq (char-after (car beg-limits)) c-string-delims)) | 1282 | (memq (char-after (car beg-limits)) c-string-delims)) |
| 1285 | (setq c-new-BEG (min c-new-BEG (car beg-limits))) | ||
| 1286 | (c-clear-char-property (car beg-limits) 'syntax-table) | 1283 | (c-clear-char-property (car beg-limits) 'syntax-table) |
| 1287 | (c-truncate-semi-nonlit-pos-cache (car beg-limits)))))) | 1284 | (c-truncate-semi-nonlit-pos-cache (car beg-limits)))))) |
| 1288 | 1285 | ||
| @@ -1832,6 +1829,9 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".") | |||
| 1832 | ;; declaration is one which does not start outside of struct braces (and | 1829 | ;; declaration is one which does not start outside of struct braces (and |
| 1833 | ;; similar) enclosing POS. Brace list braces here are not "similar". | 1830 | ;; similar) enclosing POS. Brace list braces here are not "similar". |
| 1834 | ;; | 1831 | ;; |
| 1832 | ;; POS being in a literal does not count as being in a declaration (on | ||
| 1833 | ;; pragmatic grounds). | ||
| 1834 | ;; | ||
| 1835 | ;; This function is called indirectly from font locking stuff - either from | 1835 | ;; This function is called indirectly from font locking stuff - either from |
| 1836 | ;; c-after-change (to prepare for after-change font-locking) or from font | 1836 | ;; c-after-change (to prepare for after-change font-locking) or from font |
| 1837 | ;; lock context (etc.) fontification. | 1837 | ;; lock context (etc.) fontification. |
| @@ -1842,92 +1842,92 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".") | |||
| 1842 | capture-opener | 1842 | capture-opener |
| 1843 | bod-lim bo-decl) | 1843 | bod-lim bo-decl) |
| 1844 | (goto-char (c-point 'bol new-pos)) | 1844 | (goto-char (c-point 'bol new-pos)) |
| 1845 | (when lit-start ; Comment or string. | 1845 | (unless lit-start |
| 1846 | (goto-char lit-start)) | 1846 | (setq bod-lim (c-determine-limit 500)) |
| 1847 | (setq bod-lim (c-determine-limit 500)) | 1847 | |
| 1848 | 1848 | ;; In C++ Mode, first check if we are within a (possibly nested) lambda | |
| 1849 | ;; In C++ Mode, first check if we are within a (possibly nested) lambda | 1849 | ;; form capture list. |
| 1850 | ;; form capture list. | 1850 | (when (c-major-mode-is 'c++-mode) |
| 1851 | (when (c-major-mode-is 'c++-mode) | 1851 | (let ((paren-state (c-parse-state)) |
| 1852 | (let ((paren-state (c-parse-state)) | 1852 | opener) |
| 1853 | opener) | 1853 | (save-excursion |
| 1854 | (save-excursion | 1854 | (while (setq opener (c-pull-open-brace paren-state)) |
| 1855 | (while (setq opener (c-pull-open-brace paren-state)) | 1855 | (goto-char opener) |
| 1856 | (goto-char opener) | 1856 | (if (c-looking-at-c++-lambda-capture-list) |
| 1857 | (if (c-looking-at-c++-lambda-capture-list) | 1857 | (setq capture-opener (point))))))) |
| 1858 | (setq capture-opener (point))))))) | 1858 | |
| 1859 | 1859 | (while | |
| 1860 | (while | 1860 | ;; Go to a less nested declaration each time round this loop. |
| 1861 | ;; Go to a less nested declaration each time round this loop. | 1861 | (and |
| 1862 | (and | 1862 | (setq old-pos (point)) |
| 1863 | (setq old-pos (point)) | 1863 | (let (pseudo) |
| 1864 | (let (pseudo) | 1864 | (while |
| 1865 | (while | 1865 | (progn |
| 1866 | (progn | 1866 | (c-syntactic-skip-backward "^;{}" bod-lim t) |
| 1867 | (c-syntactic-skip-backward "^;{}" bod-lim t) | 1867 | (and (eq (char-before) ?}) |
| 1868 | (and (eq (char-before) ?}) | 1868 | (save-excursion |
| 1869 | (save-excursion | 1869 | (backward-char) |
| 1870 | (backward-char) | 1870 | (setq pseudo (c-cheap-inside-bracelist-p (c-parse-state)))))) |
| 1871 | (setq pseudo (c-cheap-inside-bracelist-p (c-parse-state)))))) | 1871 | (goto-char pseudo)) |
| 1872 | (goto-char pseudo)) | 1872 | t) |
| 1873 | t) | 1873 | (> (point) bod-lim) |
| 1874 | (> (point) bod-lim) | 1874 | (progn (c-forward-syntactic-ws) |
| 1875 | (progn (c-forward-syntactic-ws) | 1875 | ;; Have we got stuck in a comment at EOB? |
| 1876 | ;; Have we got stuck in a comment at EOB? | 1876 | (not (and (eobp) |
| 1877 | (not (and (eobp) | 1877 | (c-literal-start)))) |
| 1878 | (c-literal-start)))) | 1878 | (< (point) old-pos) |
| 1879 | (< (point) old-pos) | 1879 | (progn (setq bo-decl (point)) |
| 1880 | (progn (setq bo-decl (point)) | 1880 | (or (not (looking-at c-protection-key)) |
| 1881 | (or (not (looking-at c-protection-key)) | 1881 | (c-forward-keyword-clause 1))) |
| 1882 | (c-forward-keyword-clause 1))) | 1882 | (progn |
| 1883 | (progn | 1883 | ;; Are we looking at a keyword such as "template" or |
| 1884 | ;; Are we looking at a keyword such as "template" or | 1884 | ;; "typedef" which can decorate a type, or the type itself? |
| 1885 | ;; "typedef" which can decorate a type, or the type itself? | 1885 | (when (or (looking-at c-prefix-spec-kwds-re) |
| 1886 | (when (or (looking-at c-prefix-spec-kwds-re) | 1886 | (c-forward-type t)) |
| 1887 | (c-forward-type t)) | 1887 | ;; We've found another candidate position. |
| 1888 | ;; We've found another candidate position. | 1888 | (setq new-pos (min new-pos bo-decl)) |
| 1889 | (setq new-pos (min new-pos bo-decl)) | 1889 | (goto-char bo-decl)) |
| 1890 | (goto-char bo-decl)) | 1890 | t) |
| 1891 | t) | 1891 | ;; Try and go out a level to search again. |
| 1892 | ;; Try and go out a level to search again. | 1892 | (progn |
| 1893 | (progn | 1893 | (c-backward-syntactic-ws bod-lim) |
| 1894 | (c-backward-syntactic-ws bod-lim) | 1894 | (and (> (point) bod-lim) |
| 1895 | (and (> (point) bod-lim) | 1895 | (or (memq (char-before) '(?\( ?\[)) |
| 1896 | (or (memq (char-before) '(?\( ?\[)) | 1896 | (and (eq (char-before) ?\<) |
| 1897 | (and (eq (char-before) ?\<) | 1897 | (eq (c-get-char-property |
| 1898 | (eq (c-get-char-property | 1898 | (1- (point)) 'syntax-table) |
| 1899 | (1- (point)) 'syntax-table) | 1899 | c-<-as-paren-syntax)) |
| 1900 | c-<-as-paren-syntax)) | 1900 | (and (eq (char-before) ?{) |
| 1901 | (and (eq (char-before) ?{) | 1901 | (save-excursion |
| 1902 | (save-excursion | 1902 | (backward-char) |
| 1903 | (backward-char) | 1903 | (consp (c-looking-at-or-maybe-in-bracelist)))) |
| 1904 | (consp (c-looking-at-or-maybe-in-bracelist)))) | 1904 | ))) |
| 1905 | ))) | 1905 | (not (bobp))) |
| 1906 | (not (bobp))) | 1906 | (backward-char)) ; back over (, [, <. |
| 1907 | (backward-char)) ; back over (, [, <. | 1907 | (when (and capture-opener (< capture-opener new-pos)) |
| 1908 | (when (and capture-opener (< capture-opener new-pos)) | 1908 | (setq new-pos capture-opener)) |
| 1909 | (setq new-pos capture-opener)) | 1909 | (and (/= new-pos pos) new-pos)))) |
| 1910 | (and (/= new-pos pos) new-pos))) | ||
| 1911 | 1910 | ||
| 1912 | (defun c-fl-decl-end (pos) | 1911 | (defun c-fl-decl-end (pos) |
| 1913 | ;; If POS is inside a declarator, return the end of the token that follows | 1912 | ;; If POS is inside a declarator, return the end of the token that follows |
| 1914 | ;; the declarator, otherwise return nil. | 1913 | ;; the declarator, otherwise return nil. POS being in a literal does not |
| 1914 | ;; count as being in a declarator (on pragmatic grounds). | ||
| 1915 | (goto-char pos) | 1915 | (goto-char pos) |
| 1916 | (let ((lit-start (c-literal-start)) | 1916 | (let ((lit-start (c-literal-start)) |
| 1917 | pos1) | 1917 | pos1) |
| 1918 | (if lit-start (goto-char lit-start)) | 1918 | (unless lit-start |
| 1919 | (c-backward-syntactic-ws) | 1919 | (c-backward-syntactic-ws) |
| 1920 | (when (setq pos1 (c-on-identifier)) | 1920 | (when (setq pos1 (c-on-identifier)) |
| 1921 | (goto-char pos1) | 1921 | (goto-char pos1) |
| 1922 | (let ((lim (save-excursion | 1922 | (let ((lim (save-excursion |
| 1923 | (and (c-beginning-of-macro) | 1923 | (and (c-beginning-of-macro) |
| 1924 | (progn (c-end-of-macro) (point)))))) | 1924 | (progn (c-end-of-macro) (point)))))) |
| 1925 | (when (and (c-forward-declarator lim) | 1925 | (when (and (c-forward-declarator lim) |
| 1926 | (or (not (eq (char-after) ?\()) | 1926 | (or (not (eq (char-after) ?\()) |
| 1927 | (c-go-list-forward nil lim)) | 1927 | (c-go-list-forward nil lim)) |
| 1928 | (eq (c-forward-token-2 1 nil lim) 0)) | 1928 | (eq (c-forward-token-2 1 nil lim) 0)) |
| 1929 | (c-backward-syntactic-ws) | 1929 | (c-backward-syntactic-ws) |
| 1930 | (point)))))) | 1930 | (point))))))) |
| 1931 | 1931 | ||
| 1932 | (defun c-change-expand-fl-region (_beg _end _old-len) | 1932 | (defun c-change-expand-fl-region (_beg _end _old-len) |
| 1933 | ;; Expand the region (c-new-BEG c-new-END) to an after-change font-lock | 1933 | ;; Expand the region (c-new-BEG c-new-END) to an after-change font-lock |