aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/emacs-lisp/syntax.el24
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
63cannot be handled just by the buffer's syntax-table. 63cannot be handled just by the buffer's syntax-table.
64 64
65The specified function may call `syntax-ppss' on any position 65The specified function may call `syntax-ppss' on any position
66before END, but it should not call `syntax-ppss-flush-cache', 66before END, but if it calls `syntax-ppss' on some
67which means that it should not call `syntax-ppss' on some 67position and later modifies the buffer on some earlier position,
68position and later modify the buffer on some earlier position.") 68then it is its responsability to call `syntax-ppss-flush-cache' to flush
69the 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.
326Otherwise it flushes both the ppss cache and the properties
327set 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