emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 468517c: CC Mode: Add a workaround for syntax-ppss


From: Alan Mackenzie
Subject: [Emacs-diffs] master 468517c: CC Mode: Add a workaround for syntax-ppss ignoring syntax-table prop changes
Date: Wed, 12 Jun 2019 15:21:43 -0400 (EDT)

branch: master
commit 468517c8b8322b07e202a2036e718e182ec569db
Author: Alan Mackenzie <address@hidden>
Commit: Alan Mackenzie <address@hidden>

    CC Mode: Add a workaround for syntax-ppss ignoring syntax-table prop changes
    
    * lisp/progmodes/cc-engine.el (c-truncate-lit-pos-cache): Maintain the new
    variable c-syntax-table-hwm after buffer changes.
    
    * lisp/progmodes/cc-mode.el (c-syntax-table-hwm): New variable.
    (c-before-change): Set c-syntax-table-hwm to "infinity".
    (c-after-change): Call syntax-ppss-flush-cache, just before a font locking 
is
    due to take place.
---
 lisp/progmodes/cc-engine.el |  9 ++++++++-
 lisp/progmodes/cc-mode.el   | 16 +++++++++++++++-
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 13b38b4..1ded3f0 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -155,6 +155,7 @@
 (defvar c-doc-line-join-re)
 (defvar c-doc-bright-comment-start-re)
 (defvar c-doc-line-join-end-ch)
+(defvar c-syntax-table-hwm)
 
 
 ;; Make declarations for all the `c-lang-defvar' variables in cc-langs.
@@ -3003,7 +3004,13 @@ comment at the start of cc-engine.el for more info."
   ;; higher than that position.
   (setq c-lit-pos-cache-limit (min c-lit-pos-cache-limit pos)
        c-semi-near-cache-limit (min c-semi-near-cache-limit pos)
-       c-full-near-cache-limit (min c-full-near-cache-limit pos)))
+       c-full-near-cache-limit (min c-full-near-cache-limit pos))
+  (when (fboundp 'syntax-ppss)
+    ;; Also keep track of where we need to truncate `syntax-ppss''s cache to.
+    ;; Actually we shouldn't have to touch this thing (which we do not use),
+    ;; but its design forces us to.  Hopefully this will be fixed in a future
+    ;; version of Emacs.
+    (setq c-syntax-table-hwm (min c-syntax-table-hwm pos))))
 
 
 ;; A system for finding noteworthy parens before the point.
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index 6afcb08..b8e21e2 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -888,6 +888,12 @@ Note that the style variables are always made local to the 
buffer."
 
 
 ;;; Change hooks, linking with Font Lock and electric-indent-mode.
+(defvar c-syntax-table-hwm most-positive-fixnum)
+;; A workaround for `syntax-ppss''s failure to take account of changes in
+;; syntax-table text properties.  This variable gets set to the lowest
+;; position where the syntax-table text property is changed, and that value
+;; gets supplied to `syntax-ppss-flush-cache' just before a font locking is
+;; due to take place.
 
 (defun c-called-from-text-property-change-p ()
   ;; Is the primitive which invoked `before-change-functions' or
@@ -1672,6 +1678,10 @@ Note that this is a strict tail, so won't match, e.g. 
\"0x....\".")
     ;; (c-new-BEG c-new-END) will be the region to fontify.
     (setq c-new-BEG beg  c-new-END end)
     (setq c-maybe-stale-found-type nil)
+    ;; A workaround for syntax-ppss's failure to notice syntax-table text
+    ;; property changes.
+    (when (fboundp 'syntax-ppss)
+      (setq c-syntax-table-hwm most-positive-fixnum))
     (save-restriction
       (save-match-data
        (widen)
@@ -1823,7 +1833,11 @@ 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-before-font-lock-functions))))))
+  ;; A workaround for syntax-ppss's failure to notice syntax-table text
+  ;; property changes.
+  (when (fboundp 'syntax-ppss)
+    (syntax-ppss-flush-cache c-syntax-table-hwm)))
 
 (defun c-doc-fl-decl-start (pos)
   ;; If the line containing POS is in a doc comment continued line (as defined



reply via email to

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