From: Alan Mackenzie Date: Wed, 12 Jun 2019 19:17:22 +0000 (+0000) Subject: CC Mode: Add a workaround for syntax-ppss ignoring syntax-table prop changes X-Git-Tag: emacs-27.0.90~2603 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=468517c8b8322b07e202a2036e718e182ec569db;p=emacs.git 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. --- diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index 13b38b439a1..1ded3f081d8 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 6afcb08a7ca..b8e21e24013 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