diff options
| author | Alan Mackenzie | 2019-06-12 19:17:22 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2019-06-12 19:17:22 +0000 |
| commit | 468517c8b8322b07e202a2036e718e182ec569db (patch) | |
| tree | 537e25522c5082f7d940aa0a1c70cd48fda953a3 | |
| parent | 2d71e68428b10c593da2dd411d70ed2b4a8632c0 (diff) | |
| download | emacs-468517c8b8322b07e202a2036e718e182ec569db.tar.gz emacs-468517c8b8322b07e202a2036e718e182ec569db.zip | |
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.
| -rw-r--r-- | lisp/progmodes/cc-engine.el | 9 | ||||
| -rw-r--r-- | 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 13b38b439a1..1ded3f081d8 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el | |||
| @@ -155,6 +155,7 @@ | |||
| 155 | (defvar c-doc-line-join-re) | 155 | (defvar c-doc-line-join-re) |
| 156 | (defvar c-doc-bright-comment-start-re) | 156 | (defvar c-doc-bright-comment-start-re) |
| 157 | (defvar c-doc-line-join-end-ch) | 157 | (defvar c-doc-line-join-end-ch) |
| 158 | (defvar c-syntax-table-hwm) | ||
| 158 | 159 | ||
| 159 | 160 | ||
| 160 | ;; Make declarations for all the `c-lang-defvar' variables in cc-langs. | 161 | ;; 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." | |||
| 3003 | ;; higher than that position. | 3004 | ;; higher than that position. |
| 3004 | (setq c-lit-pos-cache-limit (min c-lit-pos-cache-limit pos) | 3005 | (setq c-lit-pos-cache-limit (min c-lit-pos-cache-limit pos) |
| 3005 | c-semi-near-cache-limit (min c-semi-near-cache-limit pos) | 3006 | c-semi-near-cache-limit (min c-semi-near-cache-limit pos) |
| 3006 | c-full-near-cache-limit (min c-full-near-cache-limit pos))) | 3007 | c-full-near-cache-limit (min c-full-near-cache-limit pos)) |
| 3008 | (when (fboundp 'syntax-ppss) | ||
| 3009 | ;; Also keep track of where we need to truncate `syntax-ppss''s cache to. | ||
| 3010 | ;; Actually we shouldn't have to touch this thing (which we do not use), | ||
| 3011 | ;; but its design forces us to. Hopefully this will be fixed in a future | ||
| 3012 | ;; version of Emacs. | ||
| 3013 | (setq c-syntax-table-hwm (min c-syntax-table-hwm pos)))) | ||
| 3007 | 3014 | ||
| 3008 | 3015 | ||
| 3009 | ;; A system for finding noteworthy parens before the point. | 3016 | ;; 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." | |||
| 888 | 888 | ||
| 889 | 889 | ||
| 890 | ;;; Change hooks, linking with Font Lock and electric-indent-mode. | 890 | ;;; Change hooks, linking with Font Lock and electric-indent-mode. |
| 891 | (defvar c-syntax-table-hwm most-positive-fixnum) | ||
| 892 | ;; A workaround for `syntax-ppss''s failure to take account of changes in | ||
| 893 | ;; syntax-table text properties. This variable gets set to the lowest | ||
| 894 | ;; position where the syntax-table text property is changed, and that value | ||
| 895 | ;; gets supplied to `syntax-ppss-flush-cache' just before a font locking is | ||
| 896 | ;; due to take place. | ||
| 891 | 897 | ||
| 892 | (defun c-called-from-text-property-change-p () | 898 | (defun c-called-from-text-property-change-p () |
| 893 | ;; Is the primitive which invoked `before-change-functions' or | 899 | ;; 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....\".") | |||
| 1672 | ;; (c-new-BEG c-new-END) will be the region to fontify. | 1678 | ;; (c-new-BEG c-new-END) will be the region to fontify. |
| 1673 | (setq c-new-BEG beg c-new-END end) | 1679 | (setq c-new-BEG beg c-new-END end) |
| 1674 | (setq c-maybe-stale-found-type nil) | 1680 | (setq c-maybe-stale-found-type nil) |
| 1681 | ;; A workaround for syntax-ppss's failure to notice syntax-table text | ||
| 1682 | ;; property changes. | ||
| 1683 | (when (fboundp 'syntax-ppss) | ||
| 1684 | (setq c-syntax-table-hwm most-positive-fixnum)) | ||
| 1675 | (save-restriction | 1685 | (save-restriction |
| 1676 | (save-match-data | 1686 | (save-match-data |
| 1677 | (widen) | 1687 | (widen) |
| @@ -1823,7 +1833,11 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".") | |||
| 1823 | (save-excursion | 1833 | (save-excursion |
| 1824 | (mapc (lambda (fn) | 1834 | (mapc (lambda (fn) |
| 1825 | (funcall fn beg end old-len)) | 1835 | (funcall fn beg end old-len)) |
| 1826 | c-before-font-lock-functions))))))) | 1836 | c-before-font-lock-functions)))))) |
| 1837 | ;; A workaround for syntax-ppss's failure to notice syntax-table text | ||
| 1838 | ;; property changes. | ||
| 1839 | (when (fboundp 'syntax-ppss) | ||
| 1840 | (syntax-ppss-flush-cache c-syntax-table-hwm))) | ||
| 1827 | 1841 | ||
| 1828 | (defun c-doc-fl-decl-start (pos) | 1842 | (defun c-doc-fl-decl-start (pos) |
| 1829 | ;; If the line containing POS is in a doc comment continued line (as defined | 1843 | ;; If the line containing POS is in a doc comment continued line (as defined |