summaryrefslogtreecommitdiff
path: root/lisp/progmodes/cc-defs.el
diff options
context:
space:
mode:
authorAlan Mackenzie <acm@muc.de>2019-03-27 11:50:53 +0000
committerAlan Mackenzie <acm@muc.de>2019-03-27 11:50:53 +0000
commit29ec1e48883dbdce8f9f81ac25d9ec38c474cdcb (patch)
treece9c31a6c3c6d4c0b521b24264294f897a4c4216 /lisp/progmodes/cc-defs.el
parentc26704483726d454cd554406d41dd7bfde537454 (diff)
downloademacs-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-defs.el')
-rw-r--r--lisp/progmodes/cc-defs.el76
1 files changed, 58 insertions, 18 deletions
diff --git a/lisp/progmodes/cc-defs.el b/lisp/progmodes/cc-defs.el
index 97272ca9d21..87ddf3ac1e2 100644
--- a/lisp/progmodes/cc-defs.el
+++ b/lisp/progmodes/cc-defs.el
@@ -212,6 +212,13 @@ This variant works around bugs in `eval-when-compile' in various
`(cl-delete-duplicates ,cl-seq ,@cl-keys)
`(delete-duplicates ,cl-seq ,@cl-keys))))
+(defmacro c-font-lock-flush (beg end)
+ "Declare the region BEG...END's fontification as out-of-date.
+On XEmacs and older Emacsen, this refontifies that region immediately."
+ (if (fboundp 'font-lock-flush)
+ `(font-lock-flush ,beg ,end)
+ `(font-lock-fontify-region ,beg ,end)))
+
(defmacro c-point (position &optional point)
"Return the value of certain commonly referenced POSITIONs relative to POINT.
The current point is used if POINT isn't specified. POSITION can be
@@ -258,10 +265,12 @@ to it is returned. This function does not modify the point or the mark."
((eq position 'eoll)
`(save-excursion
,@(if point `((goto-char ,point)))
- (while (progn
- (end-of-line)
- (prog1 (eq (logand 1 (skip-chars-backward "\\\\")) 1)))
- (beginning-of-line 2))
+ (while (and
+ (not (eobp))
+ (progn
+ (end-of-line)
+ (prog1 (eq (logand 1 (skip-chars-backward "\\\\")) 1))))
+ (forward-line))
(end-of-line)
(point)))
@@ -1214,7 +1223,7 @@ Leave point just after the character, and set the match data on
this character, and return point. If the search fails, return
nil; point is then left undefined."
`(let ((char-skip (concat "^" (char-to-string ,char)))
- (-limit- ,limit)
+ (-limit- (or ,limit (point-max)))
(-value- ,value))
(while
(and
@@ -1226,15 +1235,39 @@ nil; point is then left undefined."
(search-forward-regexp ".") ; to set the match-data.
(point))))
+(defmacro c-search-forward-char-property-without-value-on-char
+ (property value char &optional limit)
+ "Search forward for a character CHAR without text property PROPERTY having
+a value CHAR.
+LIMIT bounds the search. The value comparison is done with `equal'.
+PROPERTY must be a constant.
+
+Leave point just after the character, and set the match data on
+this character, and return point. If the search fails, return
+nil; point is then left undefined."
+ `(let ((char-skip (concat "^" (char-to-string ,char)))
+ (-limit- (or ,limit (point-max)))
+ (-value- ,value))
+ (while
+ (and
+ (progn (skip-chars-forward char-skip -limit-)
+ (< (point) -limit-))
+ (equal (c-get-char-property (point) ,property) -value-))
+ (forward-char))
+ (when (< (point) -limit-)
+ (search-forward-regexp ".") ; to set the match-data.
+ (point))))
+
(defun c-clear-char-property-with-value-on-char-function (from to property
value char)
"Remove all text-properties PROPERTY with value VALUE on
characters with value CHAR from the region [FROM, TO), as tested
by `equal'. These properties are assumed to be over individual
characters, having been put there by c-put-char-property. POINT
-remains unchanged."
+remains unchanged. Return the position of the first removed
+property, or nil."
(let ((place from)
- )
+ first)
(while ; loop round occurrences of (PROPERTY VALUE)
(progn
(while ; loop round changes in PROPERTY till we find VALUE
@@ -1243,28 +1276,34 @@ remains unchanged."
(not (equal (get-text-property place property) value)))
(setq place (c-next-single-property-change place property nil to)))
(< place to))
- (if (eq (char-after place) char)
- (remove-text-properties place (1+ place) (cons property nil)))
+ (when (eq (char-after place) char)
+ (remove-text-properties place (1+ place) (cons property nil))
+ (or first (setq first place)))
;; Do we have to do anything with stickiness here?
- (setq place (1+ place)))))
+ (setq place (1+ place)))
+ first))
(defmacro c-clear-char-property-with-value-on-char (from to property value char)
"Remove all text-properties PROPERTY with value VALUE on
characters with value CHAR from the region [FROM, TO), as tested
by `equal'. These properties are assumed to be over individual
characters, having been put there by c-put-char-property. POINT
-remains unchanged."
+remains unchanged. Return the position of the first removed
+property, or nil."
(if c-use-extents
;; XEmacs
`(let ((-property- ,property)
- (-char- ,char))
+ (-char- ,char)
+ (first (1+ (point-max))))
(map-extents (lambda (ext val)
- (if (and (equal (extent-property ext -property-) val)
- (eq (char-after
- (extent-start-position ext))
- -char-))
- (delete-extent ext)))
- nil ,from ,to ,value nil -property-))
+ (when (and (equal (extent-property ext -property-) val)
+ (eq (char-after
+ (extent-start-position ext))
+ -char-))
+ (setq first (min first (extent-start-position ext)))
+ (delete-extent ext)))
+ nil ,from ,to ,value nil -property-)
+ (and (<= first (point-max)) first))
;; GNU Emacs
`(c-clear-char-property-with-value-on-char-function ,from ,to ,property
,value ,char)))
@@ -1316,6 +1355,7 @@ with value CHAR in the region [FROM to)."
;(eval-after-load "edebug" ; 2006-07-09: def-edebug-spec is now in subr.el.
; '(progn
(def-edebug-spec cc-eval-when-compile (&rest def-form))
+(def-edebug-spec c-font-lock-flush t)
(def-edebug-spec c--mapcan t)
(def-edebug-spec c--set-difference (form form &rest [symbolp form]))
(def-edebug-spec c--intersection (form form &rest [symbolp form]))