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

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

[elpa] externals/phps-mode 55b3087 333/405: Optimized lexer calling, do


From: Stefan Monnier
Subject: [elpa] externals/phps-mode 55b3087 333/405: Optimized lexer calling, do not call when using (indent-line)
Date: Sat, 13 Jul 2019 10:00:43 -0400 (EDT)

branch: externals/phps-mode
commit 55b3087d118d8b07eca0c19109bef6b1f34a8bc6
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>

    Optimized lexer calling, do not call when using (indent-line)
---
 phps-mode-functions.el |   3 +-
 phps-mode-lexer.el     | 120 ++++++++++++++++++++++++-------------------------
 2 files changed, 62 insertions(+), 61 deletions(-)

diff --git a/phps-mode-functions.el b/phps-mode-functions.el
index cc80145..6fee6d1 100644
--- a/phps-mode-functions.el
+++ b/phps-mode-functions.el
@@ -756,7 +756,8 @@
               (phps-mode-lexer-move-tokens line-start indent-diff)
               (phps-mode-lexer-move-states line-start indent-diff)
 
-              )))))))
+              ;; Reset change flag
+              (phps-mode-functions-reset-buffer-changes-start))))))))
 
 (defun phps-mode-functions-after-change (start _stop _length)
   "Track buffer change from START to STOP with length LENGTH."
diff --git a/phps-mode-lexer.el b/phps-mode-lexer.el
index a47daca..abfd6ba 100644
--- a/phps-mode-lexer.el
+++ b/phps-mode-lexer.el
@@ -1685,67 +1685,67 @@
   "Run incremental lexer based on 
`(phps-mode-functions-get-buffer-changes-start)'."
   ;; (message "Running incremental lexer")
   (let ((change-start (phps-mode-functions-get-buffer-changes-start)))
-    (when (and change-start
-               (> change-start 1)
-               phps-mode-lexer-states)
-      (let ((state nil)
-            (state-stack nil)
-            (new-states '())
-            (states (nreverse phps-mode-lexer-states))
-            (previous-token-start nil)
-            (previous-token-end nil)
-            (tokens phps-mode-lexer-tokens))
-
-        ;; Find state and state stack before point of change
-        ;; also determine were previous token to change starts
-        (catch 'stop-iteration
-          (dolist (state-object states)
-            (let ((start (nth 0 state-object))
-                  (end (nth 1 state-object)))
-              (when (< end change-start)
-                (setq state (nth 2 state-object))
-                (setq state-stack (nth 3 state-object))
-                (setq previous-token-start start)
-                (setq previous-token-end end)
-                (push state-object new-states))
-              (when (> start change-start)
-                (throw 'stop-iteration nil)))))
-
-        (if (and state
-                 state-stack)
-            (let ((old-tokens '()))
-
-              ;; Build new list of tokens before point of change
-              (catch 'stop-iteration
-                (dolist (token tokens)
-                  (let ((_start (car (cdr token)))
-                        (end (cdr (cdr token))))
-                    (if (< end previous-token-end)
-                        (progn
-                          ;; NOTE Does following line make any difference?
-                          ;; (semantic-lex-push-token (semantic-lex-token 
token _start end))
-                          (push token old-tokens))
-                      (throw 'stop-iteration nil)))))
-              (setq old-tokens (nreverse old-tokens))
-
-              ;; Delete all overlays from point of change to end of buffer
-              (dolist (overlay (overlays-in previous-token-end (point-max)))
-                (delete-overlay overlay))
-              
-              (let* ((new-tokens (semantic-lex previous-token-start 
(point-max)))
-                     (appended-tokens (append old-tokens new-tokens)))
-                ;; (message "old-tokens: %s, new-tokens: %s" old-tokens 
new-tokens)
-                (setq phps-mode-lexer-tokens appended-tokens)
-                (setq phps-mode-lexer-STATE state)
-                (setq phps-mode-lexer-state_stack state-stack)
-                (setq phps-mode-lexer-states new-states)
+    (when change-start
+      (when (and (> change-start 1)
+                 phps-mode-lexer-states)
+        (let ((state nil)
+              (state-stack nil)
+              (new-states '())
+              (states (nreverse phps-mode-lexer-states))
+              (previous-token-start nil)
+              (previous-token-end nil)
+              (tokens phps-mode-lexer-tokens))
+
+          ;; Find state and state stack before point of change
+          ;; also determine were previous token to change starts
+          (catch 'stop-iteration
+            (dolist (state-object states)
+              (let ((start (nth 0 state-object))
+                    (end (nth 1 state-object)))
+                (when (< end change-start)
+                  (setq state (nth 2 state-object))
+                  (setq state-stack (nth 3 state-object))
+                  (setq previous-token-start start)
+                  (setq previous-token-end end)
+                  (push state-object new-states))
+                (when (> start change-start)
+                  (throw 'stop-iteration nil)))))
+
+          (if (and state
+                   state-stack)
+              (let ((old-tokens '()))
+
+                ;; Build new list of tokens before point of change
+                (catch 'stop-iteration
+                  (dolist (token tokens)
+                    (let ((_start (car (cdr token)))
+                          (end (cdr (cdr token))))
+                      (if (< end previous-token-end)
+                          (progn
+                            ;; NOTE Does following line make any difference?
+                            ;; (semantic-lex-push-token (semantic-lex-token 
token _start end))
+                            (push token old-tokens))
+                        (throw 'stop-iteration nil)))))
+                (setq old-tokens (nreverse old-tokens))
+
+                ;; Delete all overlays from point of change to end of buffer
+                (dolist (overlay (overlays-in previous-token-end (point-max)))
+                  (delete-overlay overlay))
                 
-                ;; (message "Rewinding lex to state: %s and stack: %s and 
states: %s and start: %s old tokens: %s" state state-stack new-states 
previous-token-start old-tokens)
-
-                ))
-          ;; (display-warning "phps-mode" (format "Found no state to rewind to 
for %s in stack %s, buffer point max: %s" change-start states (point-max)))
-          ))))
-  (phps-mode-lexer-run)
+                (let* ((new-tokens (semantic-lex previous-token-start 
(point-max)))
+                       (appended-tokens (append old-tokens new-tokens)))
+                  ;; (message "old-tokens: %s, new-tokens: %s" old-tokens 
new-tokens)
+                  (setq phps-mode-lexer-tokens appended-tokens)
+                  (setq phps-mode-lexer-STATE state)
+                  (setq phps-mode-lexer-state_stack state-stack)
+                  (setq phps-mode-lexer-states new-states)
+                  
+                  ;; (message "Rewinding lex to state: %s and stack: %s and 
states: %s and start: %s old tokens: %s" state state-stack new-states 
previous-token-start old-tokens)
+
+                  ))
+            ;; (display-warning "phps-mode" (format "Found no state to rewind 
to for %s in stack %s, buffer point max: %s" change-start states (point-max)))
+            )))
+      (phps-mode-lexer-run)))
   (phps-mode-functions-reset-buffer-changes-start))
 
 (define-lex phps-mode-lexer-lex



reply via email to

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