From 4bac5ce11823ac8b69cbfc34a83be82f017f5ab3 Mon Sep 17 00:00:00 2001 From: Fanael Linithien Date: Thu, 6 Nov 2014 19:55:11 +0100 Subject: [PATCH] Don't flush the syntax-ppss cache unless necessary. --- rainbow-delimiters.el | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/rainbow-delimiters.el b/rainbow-delimiters.el index 548516c..00988c6 100644 --- a/rainbow-delimiters.el +++ b/rainbow-delimiters.el @@ -255,17 +255,23 @@ Used by font-lock for dynamic highlighting." (when rainbow-delimiters-mode (font-lock-add-keywords nil rainbow-delimiters--font-lock-keywords 'append) (set (make-local-variable 'jit-lock-contextually) t) - ;; `syntax-begin-function' may break the assumption we rely on that - ;; `syntax-ppss' is exactly equivalent to `parse-partial-sexp' from - ;; `point-min'. Just don't use it, the performance hit should be negligible. - (set (make-local-variable 'syntax-begin-function) nil) - ;; Obsolete equivalent of `syntax-begin-function'. - (when (boundp 'font-lock-beginning-of-syntax-function) - (with-no-warnings - (set (make-local-variable 'font-lock-beginning-of-syntax-function) nil))) - ;; We modified `syntax-begin-function', so flush the cache to avoid getting - ;; cached values that used the old value. - (syntax-ppss-flush-cache 0)) + (let ((flush-needed nil)) + (when syntax-begin-function + ;; `syntax-begin-function' may break the assumption we rely on that + ;; `syntax-ppss' is exactly equivalent to `parse-partial-sexp' from + ;; `point-min'. Just don't use it, the performance hit should be + ;; negligible. + (setq flush-needed t) + (set (make-local-variable 'syntax-begin-function) nil)) + ;; Obsolete equivalent of `syntax-begin-function'. + (when (bound-and-true-p font-lock-beginning-of-syntax-function) + (setq flush-needed t) + (with-no-warnings + (set (make-local-variable 'font-lock-beginning-of-syntax-function) nil))) + (when flush-needed + ;; We modified `syntax-begin-function', so flush the cache to avoid + ;; getting cached values that used the old value. + (syntax-ppss-flush-cache 0)))) (when font-lock-mode (if (fboundp 'font-lock-flush) (font-lock-flush)