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

CC Mode: Fix the timing of application and removal of string fence properties

This fixes bug #36897.

* lisp/progmodes/cc-mode.el (c-before-change-check-unbalanced-strings): Check
string fence text properties are actually present on string delimiters before
trying to remove them.
(c-before-change): Amend the nesting of unwind-protect, widen,
c-restore-string-fences, and c-clear-string-fences.  Move
invalidate-state-cache to outside of the widening.
(c-after-change): Amend the nesting of unwind-protect, widen,
c-restore-string-fences, and c-clear-string-fences.
This commit is contained in:
Alan Mackenzie 2019-08-02 11:24:38 +00:00
parent ccc52f1d97
commit 2ca12bb3de

View file

@ -1426,8 +1426,11 @@ Note that the style variables are always made local to the buffer."
(and c-multiline-string-start-char
(not (c-characterp c-multiline-string-start-char))))
(when (and (eq end-literal-type 'string)
(not (eq (char-before (cdr end-limits)) ?\()))
(c-remove-string-fences (1- (cdr end-limits)))
(not (eq (char-before (cdr end-limits)) ?\())
(memq (char-after (car end-limits)) c-string-delims)
(equal (c-get-char-property (car end-limits) 'syntax-table)
'(15)))
(c-remove-string-fences (car end-limits))
(setq c-new-END (max c-new-END (cdr end-limits))))
(when (and (eq beg-literal-type 'string)
@ -1864,12 +1867,12 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".")
;; property changes.
(when (fboundp 'syntax-ppss)
(setq c-syntax-table-hwm most-positive-fixnum))
(unwind-protect
(progn
(c-restore-string-fences (point-min) (point-max))
(save-restriction
(save-match-data
(widen)
(save-restriction
(save-match-data
(widen)
(unwind-protect
(progn
(c-restore-string-fences (point-min) (point-max))
(save-excursion
;; Are we inserting/deleting stuff in the middle of an
;; identifier?
@ -1896,8 +1899,8 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".")
'font-lock-comment-face)
(previous-single-property-change end 'face))
end)))
(when (>= end1 beg) ; Don't hassle about changes
; entirely in comments.
(when (>= end1 beg) ; Don't hassle about changes entirely in
; comments.
;; Find a limit for the search for a `c-type' property
(while
(and (/= (skip-chars-backward "^;{}") 0)
@ -1924,12 +1927,11 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".")
(buffer-substring-no-properties (point) type-pos)))
(goto-char end1)
(skip-chars-forward "^;{}") ;FIXME!!! loop for
;comment, maybe
(skip-chars-forward "^;{}") ; FIXME!!! loop for
; comment, maybe
(setq lim (point))
(setq term-pos
(or (c-next-single-property-change end 'c-type nil lim)
lim))
(or (c-next-single-property-change end 'c-type nil lim) lim))
(setq c-maybe-stale-found-type
(list type marked-id
type-pos term-pos
@ -1940,14 +1942,13 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".")
(if c-get-state-before-change-functions
(mapc (lambda (fn)
(funcall fn beg end))
c-get-state-before-change-functions))
)))
;; The following must be done here rather than in
;; `c-after-change' because newly inserted parens would foul
;; up the invalidation algorithm.
(c-invalidate-state-cache beg)
(c-truncate-lit-pos-cache beg))
(c-clear-string-fences))))
c-get-state-before-change-functions))))
(c-clear-string-fences))))
(c-truncate-lit-pos-cache beg)
;; The following must be done here rather than in `c-after-change'
;; because newly inserted parens would foul up the invalidation
;; algorithm.
(c-invalidate-state-cache beg)))
(defvar c-in-after-change-fontification nil)
(make-variable-buffer-local 'c-in-after-change-fontification)
@ -1991,19 +1992,17 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".")
;; When `combine-after-change-calls' is used we might get calls
;; with regions outside the current narrowing. This has been
;; observed in Emacs 20.7.
(unwind-protect
(progn
(c-restore-string-fences (point-min) (point-max))
(save-restriction
(save-match-data ; c-recognize-<>-arglists changes match-data
(widen)
(save-restriction
(save-match-data ; c-recognize-<>-arglists changes match-data
(widen)
(unwind-protect
(progn
(c-restore-string-fences (point-min) (point-max))
(when (> end (point-max))
;; Some emacsen might return positions past the
;; end. This has been observed in Emacs 20.7 when
;; rereading a buffer changed on disk (haven't been
;; able to minimize it, but Emacs 21.3 appears to
;; work).
;; Some emacsen might return positions past the end. This
;; has been observed in Emacs 20.7 when rereading a buffer
;; changed on disk (haven't been able to minimize it, but
;; Emacs 21.3 appears to work).
(setq end (point-max))
(when (> beg end)
(setq beg end)))
@ -2034,8 +2033,8 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".")
(save-excursion
(mapc (lambda (fn)
(funcall fn beg end old-len))
c-before-font-lock-functions)))))
(c-clear-string-fences))))
c-before-font-lock-functions)))
(c-clear-string-fences))))))
;; A workaround for syntax-ppss's failure to notice syntax-table text
;; property changes.
(when (fboundp 'syntax-ppss)