emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/javaimp fa39a78: Make javaimp--parse-dirty-pos a marker


From: Filipp Gunbin
Subject: [elpa] externals/javaimp fa39a78: Make javaimp--parse-dirty-pos a marker
Date: Thu, 18 Nov 2021 13:04:12 -0500 (EST)

branch: externals/javaimp
commit fa39a78fb0a6499b5838e51a7788337154e1821e
Author: Filipp Gunbin <fgunbin@fastmail.fm>
Commit: Filipp Gunbin <fgunbin@fastmail.fm>

    Make javaimp--parse-dirty-pos a marker
---
 javaimp-parse.el | 67 ++++++++++++++++++++++++++++----------------------------
 javaimp-tests.el |  9 ++++++--
 2 files changed, 41 insertions(+), 35 deletions(-)

diff --git a/javaimp-parse.el b/javaimp-parse.el
index 7d28cc4..3ff62c3 100644
--- a/javaimp-parse.el
+++ b/javaimp-parse.el
@@ -31,9 +31,12 @@
 (defconst javaimp--parse-stmt-keyword-maxlen
   (seq-max (mapcar #'length javaimp--parse-stmt-keywords)))
 
-(defvar-local javaimp--parse-dirty-pos 'init
-  "Buffer position after which all parsed information should be
-considered as stale.  Usually set by modification change hooks.")
+(defvar-local javaimp--parse-dirty-pos nil
+  "Marker which points to a buffer position after which all parsed
+information should be considered as stale.  Usually set by
+modification change hooks.  Nil value means we haven't yet parsed
+anything in the buffer.  A marker pointing nowhere means
+everything's up-to-date.")
 
 (defsubst javaimp--parse-substr-before-< (str)
   (let ((end (string-search "<" str)))
@@ -368,34 +371,32 @@ it's set to 'unknown' too."
       parent)))
 
 (defun javaimp--parse-all-scopes ()
-  "Entry point to the scope parsing.  Parses scopes in this
-buffer which are after `javaimp--parse-dirty-pos', if it is
-non-nil.  Resets this variable after parsing is done."
-  (when javaimp--parse-dirty-pos
-    (javaimp--parse-ensure-buffer-setup)
-    ;; cc-mode sets some costly modification hooks, we can inhibit
-    ;; them because we update only our private props here
-    (let ((inhibit-modification-hooks t))
-      (with-silent-modifications
-        (remove-text-properties javaimp--parse-dirty-pos (point-max)
-                                '(javaimp-parse-scope nil))
-        (goto-char (point-max))
-        (let ((parse-sexp-ignore-comments t)
-              (parse-sexp-lookup-properties nil))
-          (with-syntax-table javaimp-syntax-table
-            (while (javaimp--parse-rsb-keyword "{" javaimp--parse-dirty-pos t)
-              (save-excursion
-                (forward-char)
-                ;; Set props at this brace and all the way up
-                (javaimp--parse-scopes nil))))))
-      (setq javaimp--parse-dirty-pos nil))))
-
-(defun javaimp--parse-ensure-buffer-setup ()
+  "Entry point to the scope parsing.  Parses scopes in this buffer
+which are after `javaimp--parse-dirty-pos', if it points
+anywhere.  Makes it point nowhere when done."
+  (unless javaimp--parse-dirty-pos
+    (setq javaimp--parse-dirty-pos (point-min-marker))
+    (javaimp--parse-setup-buffer))
+  (when (marker-position javaimp--parse-dirty-pos)
+    (with-silent-modifications          ;we update only private props
+      (remove-text-properties javaimp--parse-dirty-pos (point-max)
+                              '(javaimp-parse-scope nil))
+      (goto-char (point-max))
+      (let ((parse-sexp-ignore-comments t)
+            ;; Can be removed when we no longer rely on cc-mode
+            (parse-sexp-lookup-properties nil))
+        (with-syntax-table javaimp-syntax-table
+          (while (javaimp--parse-rsb-keyword "{" javaimp--parse-dirty-pos t)
+            (save-excursion
+              (forward-char)
+              ;; Set props at this brace and all the way up
+              (javaimp--parse-scopes nil))))))
+    (set-marker javaimp--parse-dirty-pos nil)))
+
+(defun javaimp--parse-setup-buffer ()
   ;; FIXME This may be done in major/minor mode setup
-  (when (eq javaimp--parse-dirty-pos 'init)
-    (setq javaimp--parse-dirty-pos (point-min))
-    (setq syntax-ppss-table javaimp-syntax-table)
-    (add-hook 'after-change-functions #'javaimp--parse-update-dirty-pos)))
+  (setq syntax-ppss-table javaimp-syntax-table)
+  (add-hook 'after-change-functions #'javaimp--parse-update-dirty-pos))
 
 (defun javaimp--parse-class-abstract-methods ()
   (goto-char (point-max))
@@ -439,10 +440,10 @@ non-nil.  Resets this variable after parsing is done."
 
 (defun javaimp--parse-update-dirty-pos (beg _end _old-len)
   "Function to add to `after-change-functions' hook."
-  (when (or (not javaimp--parse-dirty-pos)
-            (and (numberp javaimp--parse-dirty-pos)
+  (when (and javaimp--parse-dirty-pos
+             (or (not (marker-position javaimp--parse-dirty-pos))
                  (< beg javaimp--parse-dirty-pos)))
-    (setq javaimp--parse-dirty-pos beg)))
+    (set-marker javaimp--parse-dirty-pos beg)))
 
 
 ;; Functions intended to be called from other parts of javaimp.  They
diff --git a/javaimp-tests.el b/javaimp-tests.el
index 6bc2e81..16de66a 100644
--- a/javaimp-tests.el
+++ b/javaimp-tests.el
@@ -187,12 +187,17 @@ package commented.block;
   (with-temp-buffer
     (insert-file-contents
      (concat javaimp--basedir "testdata/test1-misc-classes.java"))
+    (should-not javaimp--parse-dirty-pos)
+    ;;
     ;; parse full buffer
     (javaimp-test--check-named-scopes)
+    (should javaimp--parse-dirty-pos)
+    (should-not (marker-position javaimp--parse-dirty-pos))
     ;;
-    ;; reparse half of buffer
-    (setq javaimp--parse-dirty-pos (/ (- (point-max) (point-min)) 2))
+    ;; reparse half of the buffer
+    (set-marker javaimp--parse-dirty-pos (/ (- (point-max) (point-min)) 2))
     (javaimp-test--check-named-scopes)
+    (should-not (marker-position javaimp--parse-dirty-pos))
     ;;
     ;; don't reparse
     (javaimp-test--check-named-scopes)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]