diff options
| author | Stefan Monnier | 2020-05-12 16:51:55 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2020-05-12 16:52:11 -0400 |
| commit | 45fa5e97248360369c19feaee9479d22be544c8c (patch) | |
| tree | e6c377cded35e953fa244a9e3f574dfdf7e1717e | |
| parent | 3b170f04f494e58b0afe3f8a36d7f5ceeb9f07a9 (diff) | |
| download | emacs-45fa5e97248360369c19feaee9479d22be544c8c.tar.gz emacs-45fa5e97248360369c19feaee9479d22be544c8c.zip | |
* lisp/emacs-lisp/syntax.el: Fix bug#41195
Allow use of `syntax-ppss-flush-cache` in `syntax-propertize-function`.
(syntax-propertize--inhibit-flush): New var.
(syntax-propertize): Bind it.
(syntax-ppss-flush-cache): Test it.
| -rw-r--r-- | lisp/emacs-lisp/syntax.el | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/lisp/emacs-lisp/syntax.el b/lisp/emacs-lisp/syntax.el index 3294378754a..46dc8d9ade8 100644 --- a/lisp/emacs-lisp/syntax.el +++ b/lisp/emacs-lisp/syntax.el | |||
| @@ -63,9 +63,10 @@ override the buffer's syntax table for special syntactic constructs that | |||
| 63 | cannot be handled just by the buffer's syntax-table. | 63 | cannot be handled just by the buffer's syntax-table. |
| 64 | 64 | ||
| 65 | The specified function may call `syntax-ppss' on any position | 65 | The specified function may call `syntax-ppss' on any position |
| 66 | before END, but it should not call `syntax-ppss-flush-cache', | 66 | before END, but if it calls `syntax-ppss' on some |
| 67 | which means that it should not call `syntax-ppss' on some | 67 | position and later modifies the buffer on some earlier position, |
| 68 | position and later modify the buffer on some earlier position.") | 68 | then it is its responsability to call `syntax-ppss-flush-cache' to flush |
| 69 | the now obsolete ppss info from the cache.") | ||
| 69 | 70 | ||
| 70 | (defvar syntax-propertize-chunk-size 500) | 71 | (defvar syntax-propertize-chunk-size 500) |
| 71 | 72 | ||
| @@ -320,6 +321,11 @@ END) suitable for `syntax-propertize-function'." | |||
| 320 | (defvar-local syntax-ppss-table nil | 321 | (defvar-local syntax-ppss-table nil |
| 321 | "Syntax-table to use during `syntax-ppss', if any.") | 322 | "Syntax-table to use during `syntax-ppss', if any.") |
| 322 | 323 | ||
| 324 | (defvar-local syntax-propertize--inhibit-flush nil | ||
| 325 | "If non-nil, `syntax-ppss-flush-cache' only flushes the ppss cache. | ||
| 326 | Otherwise it flushes both the ppss cache and the properties | ||
| 327 | set by `syntax-propertize'") | ||
| 328 | |||
| 323 | (defun syntax-propertize (pos) | 329 | (defun syntax-propertize (pos) |
| 324 | "Ensure that syntax-table properties are set until POS (a buffer point)." | 330 | "Ensure that syntax-table properties are set until POS (a buffer point)." |
| 325 | (when (< syntax-propertize--done pos) | 331 | (when (< syntax-propertize--done pos) |
| @@ -375,8 +381,13 @@ END) suitable for `syntax-propertize-function'." | |||
| 375 | ;; (message "syntax-propertizing from %s to %s" start end) | 381 | ;; (message "syntax-propertizing from %s to %s" start end) |
| 376 | (remove-text-properties start end | 382 | (remove-text-properties start end |
| 377 | '(syntax-table nil syntax-multiline nil)) | 383 | '(syntax-table nil syntax-multiline nil)) |
| 378 | ;; Avoid recursion! | 384 | ;; Make sure we only let-bind it buffer-locally. |
| 379 | (let ((syntax-propertize--done most-positive-fixnum)) | 385 | (make-local-variable 'syntax-propertize--inhibit-flush) |
| 386 | ;; Let-bind `syntax-propertize--done' to avoid infinite recursion! | ||
| 387 | (let ((syntax-propertize--done most-positive-fixnum) | ||
| 388 | ;; Let `syntax-propertize-function' call | ||
| 389 | ;; `syntax-ppss-flush-cache' without worries. | ||
| 390 | (syntax-propertize--inhibit-flush t)) | ||
| 380 | (funcall syntax-propertize-function start end))))))))) | 391 | (funcall syntax-propertize-function start end))))))))) |
| 381 | 392 | ||
| 382 | ;;; Link syntax-propertize with syntax.c. | 393 | ;;; Link syntax-propertize with syntax.c. |
| @@ -455,7 +466,8 @@ These are valid when the buffer has no restriction.") | |||
| 455 | (defun syntax-ppss-flush-cache (beg &rest ignored) | 466 | (defun syntax-ppss-flush-cache (beg &rest ignored) |
| 456 | "Flush the cache of `syntax-ppss' starting at position BEG." | 467 | "Flush the cache of `syntax-ppss' starting at position BEG." |
| 457 | ;; Set syntax-propertize to refontify anything past beg. | 468 | ;; Set syntax-propertize to refontify anything past beg. |
| 458 | (setq syntax-propertize--done (min beg syntax-propertize--done)) | 469 | (unless syntax-propertize--inhibit-flush |
| 470 | (setq syntax-propertize--done (min beg syntax-propertize--done))) | ||
| 459 | ;; Flush invalid cache entries. | 471 | ;; Flush invalid cache entries. |
| 460 | (dolist (cell (list syntax-ppss-wide syntax-ppss-narrow)) | 472 | (dolist (cell (list syntax-ppss-wide syntax-ppss-narrow)) |
| 461 | (pcase cell | 473 | (pcase cell |