aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2016-07-12 13:16:02 +0000
committerAlan Mackenzie2016-07-12 13:16:02 +0000
commita1db933c5b68165879ada5ddf3c2585d1e7e893d (patch)
tree09821d2158098da3b98100feaea445ed95a2fbfd
parent2f67f8a145af8f185f644b1d094a03895a124ef1 (diff)
downloademacs-a1db933c5b68165879ada5ddf3c2585d1e7e893d.tar.gz
emacs-a1db933c5b68165879ada5ddf3c2585d1e7e893d.zip
Amend CC Mode to handle big C++ raw strings correctly.
Problems were caused by such a string spanning jit-lock chunks, and by a flaw in the +-500 bytes boundaries imposed for macros. * lisp/progmodes/cc-mode.el (c-extend-region-for-CPP): Check the +-500 byte macro boundaries here. (c-extend-font-lock-region-for-macros): Remove the check on the +-500 byte lower boundary. Fix the check on the upper boundary. * lisp/progmodes/cc-fonts.el (c-font-lock-raw-strings): Handle the starting point already being within a raw string. * lisp/progmodes/cc-engine.el (c-raw-string-pos) (c-depropertize-raw-strings-in-region, c-after-change-re-mark-raw-strings): Modify regexp element "\\{,16\\}" to "\\{0,16\\}" for greater compatibility with other Emacsen.
-rw-r--r--lisp/progmodes/cc-engine.el10
-rw-r--r--lisp/progmodes/cc-fonts.el66
-rw-r--r--lisp/progmodes/cc-mode.el22
3 files changed, 57 insertions, 41 deletions
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 48b9e5ebbcd..8648bece70a 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -6039,7 +6039,7 @@ comment at the start of cc-engine.el for more info."
6039 (search-backward "\"" (max (- (point) 17) (point-min)) t)) 6039 (search-backward "\"" (max (- (point) 17) (point-min)) t))
6040 (not (bobp))))) 6040 (not (bobp)))))
6041 (eq (char-before) ?R) 6041 (eq (char-before) ?R)
6042 (looking-at "\"\\([^ ()\\\n\r\t]\\{,16\\}\\)(")) 6042 (looking-at "\"\\([^ ()\\\n\r\t]\\{0,16\\}\\)("))
6043 (setq open-quote-pos (point) 6043 (setq open-quote-pos (point)
6044 open-paren-pos (match-end 1) 6044 open-paren-pos (match-end 1)
6045 id (match-string-no-properties 1)) 6045 id (match-string-no-properties 1))
@@ -6121,7 +6121,7 @@ comment at the start of cc-engine.el for more info."
6121 (concat "\\(" ; 1 6121 (concat "\\(" ; 1
6122 c-anchored-cpp-prefix ; 2 6122 c-anchored-cpp-prefix ; 2
6123 "\\)\\|\\(" ; 3 6123 "\\)\\|\\(" ; 3
6124 "R\"\\([^ ()\\\n\r\t]\\{,16\\}\\)(" ; 4 6124 "R\"\\([^ ()\\\n\r\t]\\{0,16\\}\\)(" ; 4
6125 "\\)") 6125 "\\)")
6126 finish t)) 6126 finish t))
6127 (when (save-excursion 6127 (when (save-excursion
@@ -6140,7 +6140,7 @@ comment at the start of cc-engine.el for more info."
6140 (goto-char (match-end 2)) ; after the "#". 6140 (goto-char (match-end 2)) ; after the "#".
6141 (while (and (< (point) eom) 6141 (while (and (< (point) eom)
6142 (c-syntactic-re-search-forward 6142 (c-syntactic-re-search-forward
6143 "R\"\\([^ ()\\\n\r\t]\\{,16\\}\\)(" eom t)) 6143 "R\"\\([^ ()\\\n\r\t]\\{0,16\\}\\)(" eom t))
6144 (c-depropertize-raw-string 6144 (c-depropertize-raw-string
6145 (match-string-no-properties 1) ; id 6145 (match-string-no-properties 1) ; id
6146 (1+ (match-beginning 0)) ; open quote 6146 (1+ (match-beginning 0)) ; open quote
@@ -6275,7 +6275,7 @@ comment at the start of cc-engine.el for more info."
6275 (concat "\\(" ; 1 6275 (concat "\\(" ; 1
6276 c-anchored-cpp-prefix ; 2 6276 c-anchored-cpp-prefix ; 2
6277 "\\)\\|\\(" ; 3 6277 "\\)\\|\\(" ; 3
6278 "R\"\\([^ ()\\\n\r\t]\\{,16\\}\\)(" ; 4 6278 "R\"\\([^ ()\\\n\r\t]\\{0,16\\}\\)(" ; 4
6279 "\\)") 6279 "\\)")
6280 c-new-END t)) 6280 c-new-END t))
6281 (when (save-excursion 6281 (when (save-excursion
@@ -6294,7 +6294,7 @@ comment at the start of cc-engine.el for more info."
6294 (goto-char (match-end 2)) ; after the "#". 6294 (goto-char (match-end 2)) ; after the "#".
6295 (while (and (< (point) eom) 6295 (while (and (< (point) eom)
6296 (c-syntactic-re-search-forward 6296 (c-syntactic-re-search-forward
6297 "R\"\\([^ ()\\\n\r\t]\\{,16\\}\\)(" eom t)) 6297 "R\"\\([^ ()\\\n\r\t]\\{0,16\\}\\)(" eom t))
6298 (c-propertize-raw-string-opener 6298 (c-propertize-raw-string-opener
6299 (match-string-no-properties 1) ; id 6299 (match-string-no-properties 1) ; id
6300 (1+ (match-beginning 0)) ; open quote 6300 (1+ (match-beginning 0)) ; open quote
diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el
index dfc2c061217..b45686c81b0 100644
--- a/lisp/progmodes/cc-fonts.el
+++ b/lisp/progmodes/cc-fonts.el
@@ -1542,33 +1542,45 @@ casts and declarations are fontified. Used on level 2 and higher."
1542 ;; font-lock-keyword-face. It always returns NIL to inhibit this and 1542 ;; font-lock-keyword-face. It always returns NIL to inhibit this and
1543 ;; prevent a repeat invocation. See elisp/lispref page "Search-based 1543 ;; prevent a repeat invocation. See elisp/lispref page "Search-based
1544 ;; Fontification". 1544 ;; Fontification".
1545 (while (search-forward-regexp 1545 (let* ((state (c-state-semi-pp-to-literal (point)))
1546 "R\\(\"\\)\\([^ ()\\\n\r\t]\\{,16\\}\\)(" limit t) 1546 (string-start (and (eq (cadr state) 'string)
1547 (when 1547 (car (cddr state))))
1548 (or (and (eobp) 1548 (raw-id (and string-start
1549 (eq (c-get-char-property (1- (point)) 'face) 1549 (save-excursion
1550 'font-lock-warning-face)) 1550 (goto-char string-start)
1551 (eq (c-get-char-property (point) 'face) 'font-lock-string-face) 1551 (and (eq (char-before) ?R)
1552 (and (equal (c-get-char-property (match-end 2) 'syntax-table) '(1)) 1552 (looking-at "\"\\([^ ()\\\n\r\t]\\{0,16\\}\\)(")
1553 (equal (c-get-char-property (match-beginning 1) 'syntax-table) 1553 (match-string-no-properties 1))))))
1554 '(1)))) 1554 (while (< (point) limit)
1555 (let ((paren-prop (c-get-char-property (1- (point)) 'syntax-table))) 1555 (if raw-id
1556 (if paren-prop 1556 (progn
1557 (progn 1557 (if (search-forward-regexp (concat ")\\(" (regexp-quote raw-id) "\\)\"")
1558 (c-put-font-lock-face (match-beginning 0) (match-end 0) 1558 limit 'limit)
1559 'font-lock-warning-face) 1559 (c-put-font-lock-face (match-beginning 1) (point) 'default))
1560 (when 1560 (setq raw-id nil))
1561 (and 1561
1562 (equal paren-prop '(15)) 1562 (when (search-forward-regexp
1563 (not (c-search-forward-char-property 'syntax-table '(15) limit))) 1563 "R\\(\"\\)\\([^ ()\\\n\r\t]\\{0,16\\}\\)(" limit 'limit)
1564 (goto-char limit))) 1564 (when
1565 (c-put-font-lock-face (match-beginning 1) (match-end 2) 'default) 1565 (or (and (eobp)
1566 (when (search-forward-regexp 1566 (eq (c-get-char-property (1- (point)) 'face)
1567 (concat ")\\(" (regexp-quote (match-string-no-properties 2)) 1567 'font-lock-warning-face))
1568 "\\)\"") 1568 (eq (c-get-char-property (point) 'face) 'font-lock-string-face)
1569 limit t) 1569 (and (equal (c-get-char-property (match-end 2) 'syntax-table) '(1))
1570 (c-put-font-lock-face (match-beginning 1) (point) 1570 (equal (c-get-char-property (match-beginning 1) 'syntax-table)
1571 'default)))))) 1571 '(1))))
1572 (let ((paren-prop (c-get-char-property (1- (point)) 'syntax-table)))
1573 (if paren-prop
1574 (progn
1575 (c-put-font-lock-face (match-beginning 0) (match-end 0)
1576 'font-lock-warning-face)
1577 (when
1578 (and
1579 (equal paren-prop '(15))
1580 (not (c-search-forward-char-property 'syntax-table '(15) limit)))
1581 (goto-char limit)))
1582 (c-put-font-lock-face (match-beginning 1) (match-end 2) 'default)
1583 (setq raw-id (match-string-no-properties 2)))))))))
1572 nil) 1584 nil)
1573 1585
1574(c-lang-defconst c-simple-decl-matchers 1586(c-lang-defconst c-simple-decl-matchers
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index 6711a02c93a..04d2ed6e8d5 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -924,14 +924,16 @@ Note that the style variables are always made local to the buffer."
924 ;; before change function. 924 ;; before change function.
925 (goto-char c-new-BEG) 925 (goto-char c-new-BEG)
926 (c-beginning-of-macro) 926 (c-beginning-of-macro)
927 (setq c-new-BEG (point)) 927 (when (< (point) c-new-BEG)
928 (setq c-new-BEG (max (point) (c-determine-limit 500 c-new-BEG))))
928 929
929 (goto-char c-new-END) 930 (goto-char c-new-END)
930 (when (c-beginning-of-macro) 931 (when (c-beginning-of-macro)
931 (c-end-of-macro) 932 (c-end-of-macro)
932 (or (eobp) (forward-char))) ; Over the terminating NL which may be marked 933 (or (eobp) (forward-char))) ; Over the terminating NL which may be marked
933 ; with a c-cpp-delimiter category property 934 ; with a c-cpp-delimiter category property
934 (setq c-new-END (point))) 935 (when (> (point) c-new-END)
936 (setq c-new-END (min (point) (c-determine-+ve-limit 500 c-new-END)))))
935 937
936(defun c-depropertize-new-text (beg end old-len) 938(defun c-depropertize-new-text (beg end old-len)
937 ;; Remove from the new text in (BEG END) any and all text properties which 939 ;; Remove from the new text in (BEG END) any and all text properties which
@@ -959,15 +961,17 @@ Note that the style variables are always made local to the buffer."
959 ;; Point is undefined on both entry and exit to this function. The buffer 961 ;; Point is undefined on both entry and exit to this function. The buffer
960 ;; will have been widened on entry. 962 ;; will have been widened on entry.
961 ;; 963 ;;
964 ;; c-new-BEG has already been extended in `c-extend-region-for-CPP' so we
965 ;; don't need to repeat the exercise here.
966 ;;
962 ;; This function is in the C/C++/ObjC value of `c-before-font-lock-functions'. 967 ;; This function is in the C/C++/ObjC value of `c-before-font-lock-functions'.
963 (goto-char endd) 968 (goto-char endd)
964 (if (c-beginning-of-macro) 969 (when (c-beginning-of-macro)
965 (c-end-of-macro)) 970 (c-end-of-macro)
966 (setq c-new-END (max endd c-new-END (point))) 971 ;; Determine the region, (c-new-BEG c-new-END), which will get font
967 ;; Determine the region, (c-new-BEG c-new-END), which will get font 972 ;; locked. This restricts the region should there be long macros.
968 ;; locked. This restricts the region should there be long macros. 973 (setq c-new-END (min (max c-new-END (point))
969 (setq c-new-BEG (max c-new-BEG (c-determine-limit 500 begg)) 974 (c-determine-+ve-limit 500 c-new-END)))))
970 c-new-END (min c-new-END (c-determine-+ve-limit 500 endd))))
971 975
972(defun c-neutralize-CPP-line (beg end) 976(defun c-neutralize-CPP-line (beg end)
973 ;; BEG and END bound a region, typically a preprocessor line. Put a 977 ;; BEG and END bound a region, typically a preprocessor line. Put a