From f5cf35b700709c2495a38936b92c14cb69ea03a4 Mon Sep 17 00:00:00 2001 From: Vasilij Schneidermann Date: Mon, 9 Oct 2017 21:06:48 +0200 Subject: [PATCH] Use `buffer-chars-modified-tick` to reparse less --- rjsx-mode.el | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/rjsx-mode.el b/rjsx-mode.el index 5f22c70..14b48db 100644 --- a/rjsx-mode.el +++ b/rjsx-mode.el @@ -775,14 +775,16 @@ closing tag was parsed." (throw 'rjsx-eof-while-parsing t)) (t (js2-add-to-string c))))))) +(js2-deflocal rjsx-buffer-chars-modified-tick 0 "Variable holding the last per-buffer value of `buffer-chars-modified-tick'.") + (defun rjsx-maybe-reparse () "Called before accessing the parse tree. For small buffers, will do an immediate reparse to ensure the parse tree is up to date." - ;; TODO: We could look at the last parse time and the last buffer - ;; modification time to avoid some reparsing - (when (<= (point-max) rjsx-max-size-for-frequent-reparse) - (js2-reparse))) + (when (and (<= (point-max) rjsx-max-size-for-frequent-reparse) + (/= rjsx-buffer-chars-modified-tick (buffer-chars-modified-tick))) + (js2-reparse) + (setq rjsx-buffer-chars-modified-tick (buffer-chars-modified-tick)))) (defun rjsx--tag-at-point () "Return the JSX tag at point, if any, or nil."