diff options
author | Alan Mackenzie <acm@muc.de> | 2019-03-27 11:50:53 +0000 |
---|---|---|
committer | Alan Mackenzie <acm@muc.de> | 2019-03-27 11:50:53 +0000 |
commit | 29ec1e48883dbdce8f9f81ac25d9ec38c474cdcb (patch) | |
tree | ce9c31a6c3c6d4c0b521b24264294f897a4c4216 /lisp/progmodes/cc-fonts.el | |
parent | c26704483726d454cd554406d41dd7bfde537454 (diff) | |
download | emacs-29ec1e48883dbdce8f9f81ac25d9ec38c474cdcb.tar.gz |
Improve C++ raw string fontification.
Integrate the handling of raw string and ordinary string fontification.
* lisp/progmodes/cc-defs.el (c-font-lock-flush)
(c-search-forward-char-property-without-value-on-char): new macros.
(c-point): In the 'eoll arm, check for eobp.
(c-search-forward-char-property-with-value-on-char): Handle the &optional
limit argument being nil.
(c-clear-char-property-with-value-on-char-function)
(c-clear-char-property-with-value-on-char): Return the position of the first
cleared property.
* lisp/progmodes/cc-engine.el (c-find-decl-prefix-search): Don't spuriously
recognize the change of face at a ) as the start of a string (a
"pseudo match").
(c-old-beg-rs c-old-end-rs): New variables.
(c-raw-string-pos): Analyze raw string delimiters more carefully.
(c-raw-string-in-end-delim): New function.
(c-depropertize-raw-string): Largely rewritten.
(c-before-change-check-raw-strings): New functionality: only remove the
syntax-table text properties from raw strings whose delimiters are about to
change.
(c-propertize-raw-string-id): New function.
(c-after-change-re-mark-raw-strings): Remove, incorporating functionality into
other functions.
(c-propertize-raw-string-opener): Largely rewritten.
(c-after-change-re-mark-raw-strings): Removed.
(c-after-change-unmark-raw-strings, c-after-change-unmark-raw-strings): New
functions.
* lisp/progmodes/cc-fonts.el (c-font-lock-raw-strings): Largely rewritten.
* lisp/progmodes/cc-langs.el (c-before-font-lock-functions): Replace
c-after-change-re-mark-unbalanced-strings by
c-after-change-mark-abnormal-strings in the t, c+objc, c++ and java sections.
Add c-after-change-unmark-raw-strings and remove
c-after-change-re-mark-raw-strings from the c++ section.
* lisp/progmodes/cc-mode.el (c-old-BEG c-old-END): Remove.
(c-old-END-literality): New variable.
(c-depropertize-CPP): Remove syntax-table properties from raw strings within
macros.
(c-before-change-check-unbalanced-strings): Call
c-truncate-semi-nonlit-pos-cache to preserve the integrity of the cache.
(c-before-change-check-unbalanced-strings): Call
c-truncate-semi-nonlit-pos-cache, largely rewritten.
(c-after-change-re-mark-unbalanced-strings): Renamed to
c-after-change-mark-abnormal-strings. Call c-maybe-re-mark-raw-string.
Diffstat (limited to 'lisp/progmodes/cc-fonts.el')
-rw-r--r-- | lisp/progmodes/cc-fonts.el | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el index 0b41eff1577..e7a3748af43 100644 --- a/lisp/progmodes/cc-fonts.el +++ b/lisp/progmodes/cc-fonts.el @@ -1674,25 +1674,36 @@ casts and declarations are fontified. Used on level 2 and higher." (goto-char string-start) (and (eq (char-before) ?R) (looking-at "\"\\([^ ()\\\n\r\t]\\{0,16\\}\\)(") - (match-string-no-properties 1)))))) + (match-string-no-properties 1))))) + (content-start (and raw-id (point)))) + ;; We go round the next loop twice per raw string, once for each "end". (while (< (point) limit) (if raw-id + ;; Search for the raw string end delimiter (progn - (if (search-forward-regexp (concat ")\\(" (regexp-quote raw-id) "\\)\"") - limit 'limit) - (c-put-font-lock-face (match-beginning 1) (point) 'default)) + (when (search-forward-regexp (concat ")\\(" (regexp-quote raw-id) "\\)\"") + limit 'limit) + (c-put-font-lock-face content-start (match-beginning 1) + 'font-lock-string-face) + (c-remove-font-lock-face (match-beginning 1) (point))) (setq raw-id nil)) - + ;; Search for the start of a raw string. (when (search-forward-regexp "R\\(\"\\)\\([^ ()\\\n\r\t]\\{0,16\\}\\)(" limit 'limit) (when - (or (and (eobp) - (eq (c-get-char-property (1- (point)) 'face) - 'font-lock-warning-face)) - (eq (c-get-char-property (point) 'face) 'font-lock-string-face) - (and (equal (c-get-char-property (match-end 2) 'syntax-table) '(1)) - (equal (c-get-char-property (match-beginning 1) 'syntax-table) - '(1)))) + ;; Make sure we're not in a comment or string. + (and + (not (memq (c-get-char-property (match-beginning 0) 'face) + '(font-lock-comment-face font-lock-comment-delimiter-face + font-lock-string-face))) + (or (and (eobp) + (eq (c-get-char-property (1- (point)) 'face) + 'font-lock-warning-face)) + (not (eq (c-get-char-property (point) 'face) 'font-lock-comment-face)) + ;; (eq (c-get-char-property (point) 'face) 'font-lock-string-face) + (and (equal (c-get-char-property (match-end 2) 'syntax-table) '(1)) + (equal (c-get-char-property (match-beginning 1) 'syntax-table) + '(1))))) (let ((paren-prop (c-get-char-property (1- (point)) 'syntax-table))) (if paren-prop (progn @@ -1703,8 +1714,9 @@ casts and declarations are fontified. Used on level 2 and higher." (equal paren-prop '(15)) (not (c-search-forward-char-property 'syntax-table '(15) limit))) (goto-char limit))) - (c-put-font-lock-face (match-beginning 1) (match-end 2) 'default) - (setq raw-id (match-string-no-properties 2))))))))) + (c-remove-font-lock-face (match-beginning 0) (match-end 2)) + (setq raw-id (match-string-no-properties 2)) + (setq content-start (match-end 0))))))))) nil) (defun c-font-lock-c++-lambda-captures (limit) |