diff options
| author | Alan Mackenzie | 2017-12-21 17:49:14 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2017-12-21 17:55:59 +0000 |
| commit | 88ddf53ef086ee2f2e0ea729bc4afbf34d88d82b (patch) | |
| tree | 540cb7c167a90597cbeb7b6c88dbd9498d89e1e8 | |
| parent | de7de9cc0cfcef1c7651887fd36fc2a346dadd6c (diff) | |
| download | emacs-88ddf53ef086ee2f2e0ea729bc4afbf34d88d82b.tar.gz emacs-88ddf53ef086ee2f2e0ea729bc4afbf34d88d82b.zip | |
Fontify a CPP construct correctly when a comment follows without spaces
Do this by removing a broken optimization in the state cache which put
category text properties on a character between the end of the CPP construct
and the beginning of the comment. This can't work when there's no such
character.
* lisp/progmodes/cc-defs.el (c-cpp-delimiter, c-set-cpp-delimiters)
(c-clear-cpp-delimiters, c-comment-out-cpps, c-with-cpps-commented-out)
(c-with-all-but-one-cpps-commented-out): Remove.
* lisp/progmodes/cc-engine.el (c-no-comment-end-of-macro): Return the comment
start position rather than one character before it.
(c-invalidate-state-cache, c-parse-state): Remove the invocations of
c-with-all-but-one-cpps-commented-out and c-with-cpps-commented-out.
* lisp/progmodes/cc-mode.el (c-neutralize-syntax-in-and-mark-CPP): Rename to
c-neutralize-syntax-in-CPP and remove the bits which applied category
properties.
* lisp/progmodes/cc-langs.el (c-before-font-lock-functions): Incorporate the
new name of the function c-neutralize-syntax-in-CPP.
| -rw-r--r-- | lisp/progmodes/cc-defs.el | 53 | ||||
| -rw-r--r-- | lisp/progmodes/cc-engine.el | 27 | ||||
| -rw-r--r-- | lisp/progmodes/cc-langs.el | 4 | ||||
| -rw-r--r-- | lisp/progmodes/cc-mode.el | 26 |
4 files changed, 16 insertions, 94 deletions
diff --git a/lisp/progmodes/cc-defs.el b/lisp/progmodes/cc-defs.el index 973d97c2560..e837ce1973b 100644 --- a/lisp/progmodes/cc-defs.el +++ b/lisp/progmodes/cc-defs.el | |||
| @@ -1414,59 +1414,6 @@ with value CHAR in the region [FROM to)." | |||
| 1414 | 1414 | ||
| 1415 | ;;;;;;;;;;;;;;; | 1415 | ;;;;;;;;;;;;;;; |
| 1416 | 1416 | ||
| 1417 | (defconst c-cpp-delimiter '(14)) ; generic comment syntax | ||
| 1418 | ;; This is the value of the `category' text property placed on every # | ||
| 1419 | ;; which introduces a CPP construct and every EOL (or EOB, or character | ||
| 1420 | ;; preceding //, etc.) which terminates it. We can instantly "comment | ||
| 1421 | ;; out" all CPP constructs by giving `c-cpp-delimiter' a syntax-table | ||
| 1422 | ;; property '(14) (generic comment delimiter). | ||
| 1423 | (defmacro c-set-cpp-delimiters (beg end) | ||
| 1424 | ;; This macro does a hidden buffer change. | ||
| 1425 | `(progn | ||
| 1426 | (c-put-char-property ,beg 'category 'c-cpp-delimiter) | ||
| 1427 | (if (< ,end (point-max)) | ||
| 1428 | (c-put-char-property ,end 'category 'c-cpp-delimiter)))) | ||
| 1429 | (defmacro c-clear-cpp-delimiters (beg end) | ||
| 1430 | ;; This macro does a hidden buffer change. | ||
| 1431 | `(progn | ||
| 1432 | (c-clear-char-property ,beg 'category) | ||
| 1433 | (if (< ,end (point-max)) | ||
| 1434 | (c-clear-char-property ,end 'category)))) | ||
| 1435 | |||
| 1436 | (defsubst c-comment-out-cpps () | ||
| 1437 | ;; Render all preprocessor constructs syntactically commented out. | ||
| 1438 | (put 'c-cpp-delimiter 'syntax-table c-cpp-delimiter)) | ||
| 1439 | (defsubst c-uncomment-out-cpps () | ||
| 1440 | ;; Restore the syntactic visibility of preprocessor constructs. | ||
| 1441 | (put 'c-cpp-delimiter 'syntax-table nil)) | ||
| 1442 | |||
| 1443 | (defmacro c-with-cpps-commented-out (&rest forms) | ||
| 1444 | ;; Execute FORMS... whilst the syntactic effect of all characters in | ||
| 1445 | ;; all CPP regions is suppressed. In particular, this is to suppress | ||
| 1446 | ;; the syntactic significance of parens/braces/brackets to functions | ||
| 1447 | ;; such as `scan-lists' and `parse-partial-sexp'. | ||
| 1448 | `(unwind-protect | ||
| 1449 | (c-save-buffer-state () | ||
| 1450 | (c-comment-out-cpps) | ||
| 1451 | ,@forms) | ||
| 1452 | (c-save-buffer-state () | ||
| 1453 | (c-uncomment-out-cpps)))) | ||
| 1454 | |||
| 1455 | (defmacro c-with-all-but-one-cpps-commented-out (beg end &rest forms) | ||
| 1456 | ;; Execute FORMS... whilst the syntactic effect of all characters in | ||
| 1457 | ;; every CPP region APART FROM THE ONE BETWEEN BEG and END is | ||
| 1458 | ;; suppressed. | ||
| 1459 | `(unwind-protect | ||
| 1460 | (c-save-buffer-state () | ||
| 1461 | (save-restriction | ||
| 1462 | (widen) | ||
| 1463 | (c-clear-cpp-delimiters ,beg ,end)) | ||
| 1464 | ,`(c-with-cpps-commented-out ,@forms)) | ||
| 1465 | (c-save-buffer-state () | ||
| 1466 | (save-restriction | ||
| 1467 | (widen) | ||
| 1468 | (c-set-cpp-delimiters ,beg ,end))))) | ||
| 1469 | |||
| 1470 | (defmacro c-self-bind-state-cache (&rest forms) | 1417 | (defmacro c-self-bind-state-cache (&rest forms) |
| 1471 | ;; Bind the state cache to itself and execute the FORMS. Return the result | 1418 | ;; Bind the state cache to itself and execute the FORMS. Return the result |
| 1472 | ;; of the last FORM executed. It is assumed that no buffer changes will | 1419 | ;; of the last FORM executed. It is assumed that no buffer changes will |
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index 12ec8f74fea..7b9baee6f76 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el | |||
| @@ -238,8 +238,8 @@ | |||
| 238 | ;; `c-macro-cache'. | 238 | ;; `c-macro-cache'. |
| 239 | (defvar c-macro-cache-no-comment nil) | 239 | (defvar c-macro-cache-no-comment nil) |
| 240 | (make-variable-buffer-local 'c-macro-cache-no-comment) | 240 | (make-variable-buffer-local 'c-macro-cache-no-comment) |
| 241 | ;; Either nil, or the last character of the macro currently represented by | 241 | ;; Either nil, or the position of a comment which is open at the end of the |
| 242 | ;; `c-macro-cache' which isn't in a comment. */ | 242 | ;; macro represented by `c-macro-cache'. |
| 243 | 243 | ||
| 244 | (defun c-invalidate-macro-cache (beg _end) | 244 | (defun c-invalidate-macro-cache (beg _end) |
| 245 | ;; Called from a before-change function. If the change region is before or | 245 | ;; Called from a before-change function. If the change region is before or |
| @@ -382,8 +382,9 @@ comment at the start of cc-engine.el for more info." | |||
| 382 | (point))) | 382 | (point))) |
| 383 | 383 | ||
| 384 | (defun c-no-comment-end-of-macro () | 384 | (defun c-no-comment-end-of-macro () |
| 385 | ;; Go to the end of a CPP directive, or a pos just before which isn't in a | 385 | ;; Go to the start of the comment which is open at the end of the current |
| 386 | ;; comment. For this purpose, open strings are ignored. | 386 | ;; CPP directive, or to the end of that directive. For this purpose, open |
| 387 | ;; strings are ignored. | ||
| 387 | ;; | 388 | ;; |
| 388 | ;; This function must only be called from the beginning of a CPP construct. | 389 | ;; This function must only be called from the beginning of a CPP construct. |
| 389 | ;; | 390 | ;; |
| @@ -401,7 +402,7 @@ comment at the start of cc-engine.el for more info." | |||
| 401 | (setq s (parse-partial-sexp here there))) | 402 | (setq s (parse-partial-sexp here there))) |
| 402 | (when (and (nth 4 s) | 403 | (when (and (nth 4 s) |
| 403 | (not (eq (nth 7 s) 'syntax-table))) ; no pseudo comments. | 404 | (not (eq (nth 7 s) 'syntax-table))) ; no pseudo comments. |
| 404 | (goto-char (1- (nth 8 s)))) | 405 | (goto-char (nth 8 s))) |
| 405 | (setq c-macro-cache-no-comment (point))) | 406 | (setq c-macro-cache-no-comment (point))) |
| 406 | (point))) | 407 | (point))) |
| 407 | 408 | ||
| @@ -3862,14 +3863,7 @@ comment at the start of cc-engine.el for more info." | |||
| 3862 | (if (eval-when-compile (memq 'category-properties c-emacs-features)) | 3863 | (if (eval-when-compile (memq 'category-properties c-emacs-features)) |
| 3863 | ;; Emacs | 3864 | ;; Emacs |
| 3864 | (c-with-<->-as-parens-suppressed | 3865 | (c-with-<->-as-parens-suppressed |
| 3865 | (if (and c-state-old-cpp-beg | 3866 | (c-invalidate-state-cache-1 here)) |
| 3866 | (< c-state-old-cpp-beg here)) | ||
| 3867 | (c-with-all-but-one-cpps-commented-out | ||
| 3868 | c-state-old-cpp-beg | ||
| 3869 | c-state-old-cpp-end | ||
| 3870 | (c-invalidate-state-cache-1 here)) | ||
| 3871 | (c-with-cpps-commented-out | ||
| 3872 | (c-invalidate-state-cache-1 here)))) | ||
| 3873 | ;; XEmacs | 3867 | ;; XEmacs |
| 3874 | (c-invalidate-state-cache-1 here))) | 3868 | (c-invalidate-state-cache-1 here))) |
| 3875 | 3869 | ||
| @@ -3902,12 +3896,7 @@ comment at the start of cc-engine.el for more info." | |||
| 3902 | (if (eval-when-compile (memq 'category-properties c-emacs-features)) | 3896 | (if (eval-when-compile (memq 'category-properties c-emacs-features)) |
| 3903 | ;; Emacs | 3897 | ;; Emacs |
| 3904 | (c-with-<->-as-parens-suppressed | 3898 | (c-with-<->-as-parens-suppressed |
| 3905 | (if (and here-cpp-beg (> here-cpp-end here-cpp-beg)) | 3899 | (c-parse-state-1)) |
| 3906 | (c-with-all-but-one-cpps-commented-out | ||
| 3907 | here-cpp-beg here-cpp-end | ||
| 3908 | (c-parse-state-1)) | ||
| 3909 | (c-with-cpps-commented-out | ||
| 3910 | (c-parse-state-1)))) | ||
| 3911 | ;; XEmacs | 3900 | ;; XEmacs |
| 3912 | (c-parse-state-1)) | 3901 | (c-parse-state-1)) |
| 3913 | (setq c-state-old-cpp-beg | 3902 | (setq c-state-old-cpp-beg |
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el index 169b61c3dd3..12a15873b1a 100644 --- a/lisp/progmodes/cc-langs.el +++ b/lisp/progmodes/cc-langs.el | |||
| @@ -518,13 +518,13 @@ parameters \(point-min) and \(point-max).") | |||
| 518 | (c objc) '(c-depropertize-new-text | 518 | (c objc) '(c-depropertize-new-text |
| 519 | c-parse-quotes-after-change | 519 | c-parse-quotes-after-change |
| 520 | c-extend-font-lock-region-for-macros | 520 | c-extend-font-lock-region-for-macros |
| 521 | c-neutralize-syntax-in-and-mark-CPP | 521 | c-neutralize-syntax-in-CPP |
| 522 | c-change-expand-fl-region) | 522 | c-change-expand-fl-region) |
| 523 | c++ '(c-depropertize-new-text | 523 | c++ '(c-depropertize-new-text |
| 524 | c-parse-quotes-after-change | 524 | c-parse-quotes-after-change |
| 525 | c-extend-font-lock-region-for-macros | 525 | c-extend-font-lock-region-for-macros |
| 526 | c-after-change-re-mark-raw-strings | 526 | c-after-change-re-mark-raw-strings |
| 527 | c-neutralize-syntax-in-and-mark-CPP | 527 | c-neutralize-syntax-in-CPP |
| 528 | c-restore-<>-properties | 528 | c-restore-<>-properties |
| 529 | c-change-expand-fl-region) | 529 | c-change-expand-fl-region) |
| 530 | java '(c-depropertize-new-text | 530 | java '(c-depropertize-new-text |
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el index 22dea039cd1..4073a5a1b1a 100644 --- a/lisp/progmodes/cc-mode.el +++ b/lisp/progmodes/cc-mode.el | |||
| @@ -1016,15 +1016,10 @@ Note that the style variables are always made local to the buffer." | |||
| 1016 | t) | 1016 | t) |
| 1017 | (t nil))))))) | 1017 | (t nil))))))) |
| 1018 | 1018 | ||
| 1019 | (defun c-neutralize-syntax-in-and-mark-CPP (_begg _endd _old-len) | 1019 | (defun c-neutralize-syntax-in-CPP (_begg _endd _old-len) |
| 1020 | ;; (i) "Neutralize" every preprocessor line wholly or partially in the | 1020 | ;; "Neutralize" every preprocessor line wholly or partially in the changed |
| 1021 | ;; changed region. "Restore" lines which were CPP lines before the change | 1021 | ;; region. "Restore" lines which were CPP lines before the change and are |
| 1022 | ;; and are no longer so. | 1022 | ;; no longer so. |
| 1023 | ;; | ||
| 1024 | ;; (ii) Mark each CPP construct by placing a `category' property value | ||
| 1025 | ;; `c-cpp-delimiter' at its start and end. The marked characters are the | ||
| 1026 | ;; opening # and usually the terminating EOL, but sometimes the character | ||
| 1027 | ;; before a comment delimiter. | ||
| 1028 | ;; | 1023 | ;; |
| 1029 | ;; That is, set syntax-table properties on characters that would otherwise | 1024 | ;; That is, set syntax-table properties on characters that would otherwise |
| 1030 | ;; interact syntactically with those outside the CPP line(s). | 1025 | ;; interact syntactically with those outside the CPP line(s). |
| @@ -1044,12 +1039,7 @@ Note that the style variables are always made local to the buffer." | |||
| 1044 | (c-save-buffer-state (limits) | 1039 | (c-save-buffer-state (limits) |
| 1045 | ;; Clear 'syntax-table properties "punctuation": | 1040 | ;; Clear 'syntax-table properties "punctuation": |
| 1046 | ;; (c-clear-char-property-with-value c-new-BEG c-new-END 'syntax-table '(1)) | 1041 | ;; (c-clear-char-property-with-value c-new-BEG c-new-END 'syntax-table '(1)) |
| 1047 | 1042 | ;; The above is now done in `c-depropertize-CPP'. | |
| 1048 | ;; CPP "comment" markers: | ||
| 1049 | (if (eval-when-compile (memq 'category-properties c-emacs-features));Emacs. | ||
| 1050 | (c-clear-char-property-with-value | ||
| 1051 | c-new-BEG c-new-END 'category 'c-cpp-delimiter)) | ||
| 1052 | ;; FIXME!!! What about the "<" and ">" category properties? 2009-11-16 | ||
| 1053 | 1043 | ||
| 1054 | ;; Add needed properties to each CPP construct in the region. | 1044 | ;; Add needed properties to each CPP construct in the region. |
| 1055 | (goto-char c-new-BEG) | 1045 | (goto-char c-new-BEG) |
| @@ -1076,11 +1066,7 @@ Note that the style variables are always made local to the buffer." | |||
| 1076 | (goto-char (match-beginning 1)) | 1066 | (goto-char (match-beginning 1)) |
| 1077 | (setq mbeg (point)) | 1067 | (setq mbeg (point)) |
| 1078 | (if (> (c-no-comment-end-of-macro) mbeg) | 1068 | (if (> (c-no-comment-end-of-macro) mbeg) |
| 1079 | (progn | 1069 | (c-neutralize-CPP-line mbeg (point)) ; "punctuation" properties |
| 1080 | (c-neutralize-CPP-line mbeg (point)) ; "punctuation" properties | ||
| 1081 | (if (eval-when-compile | ||
| 1082 | (memq 'category-properties c-emacs-features)) ;Emacs. | ||
| 1083 | (c-set-cpp-delimiters mbeg (point)))) ; "comment" markers | ||
| 1084 | (forward-line)) ; no infinite loop with, e.g., "#//" | 1070 | (forward-line)) ; no infinite loop with, e.g., "#//" |
| 1085 | ))))) | 1071 | ))))) |
| 1086 | 1072 | ||