emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 2ca12bb: CC Mode: Fix the timing of application and


From: Alan Mackenzie
Subject: [Emacs-diffs] master 2ca12bb: CC Mode: Fix the timing of application and removal of string fence properties
Date: Fri, 2 Aug 2019 07:26:50 -0400 (EDT)

branch: master
commit 2ca12bb3de7f76446c102bb1e133f6ac03f7d8be
Author: Alan Mackenzie <address@hidden>
Commit: Alan Mackenzie <address@hidden>

    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.
---
 lisp/progmodes/cc-mode.el | 71 +++++++++++++++++++++++------------------------
 1 file changed, 35 insertions(+), 36 deletions(-)

diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index 5e373b6..60a9de5 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]