1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

CC Mode. Fix fontification bug with unterminated quotes on adjacent lines

In particular, with these unterminated quotes on each of two adjacent lines,
the following text was spuriously fontified with string face.

* lisp/progmodes/cc-defs.el
(c-search-backward-char-property-with-value-on-char): New macro.

* lisp/progmodes/cc-mode.el (c-clear-string-fences): Check whether there is an
unmatched quote at a lower buffer position which should match the current
quote, rather than wrongly assuming the latter is unmatched and marking it
with a punctuation syntax.
(c-font-lock-fontify-region): Ensure all pertinent parts of the buffer have
string fence properties applied before performing any syntactic operations on
it; in particular, this applies to a quote at an earlier buffer position which
"matches" one inside the region about to be fontified.
This commit is contained in:
Alan Mackenzie 2019-11-30 21:22:55 +00:00
parent 3c278b4999
commit 757e66afdc
2 changed files with 95 additions and 38 deletions

View file

@ -1340,6 +1340,29 @@ nil; point is then left undefined."
(search-forward-regexp "\\(\n\\|.\\)") ; to set the match-data.
(point))))
(defmacro c-search-backward-char-property-with-value-on-char
(property value char &optional limit)
"Search backward for a text-property PROPERTY having value VALUE on a
character with value CHAR.
LIMIT bounds the search. The value comparison is done with `equal'.
PROPERTY must be a constant.
Leave point just before 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-min)))
(-value- ,value))
(while
(and
(progn (skip-chars-backward char-skip -limit-)
(> (point) -limit-))
(not (equal (c-get-char-property (1- (point)) ,property) -value-)))
(backward-char))
(when (> (point) -limit-)
(search-backward-regexp "\\(\n\\|.\\)") ; 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