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

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

[elpa] externals/phps-mode 552eada 264/405: Tuning of incremental logic


From: Stefan Monnier
Subject: [elpa] externals/phps-mode 552eada 264/405: Tuning of incremental logic
Date: Sat, 13 Jul 2019 10:00:29 -0400 (EDT)

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

    Tuning of incremental logic
---
 phps-mode-functions.el        |  8 ++++++++
 phps-mode-lexer.el            | 29 +++++++++++------------------
 phps-mode-test-integration.el | 17 +++++++----------
 3 files changed, 26 insertions(+), 28 deletions(-)

diff --git a/phps-mode-functions.el b/phps-mode-functions.el
index 7b4b935..69d302e 100644
--- a/phps-mode-functions.el
+++ b/phps-mode-functions.el
@@ -48,6 +48,14 @@
 
 ;; TODO Add support for automatic parenthesis, bracket, square-bracket, 
single-quote and double-quote encapsulations
 
+(defun phps-mode-functions-get-buffer-changes-start ()
+  "Get buffer change start."
+  phps-mode-functions-buffer-changes-start)
+
+(defun phps-mode-functions-reset-buffer-changes-start ()
+  "Reset buffer change start."
+  (setq phps-mode-functions-buffer-changes-start nil))
+
 (defun phps-mode-functions-process-current-buffer ()
   "Process current buffer, generate indentations and Imenu."
   (unless phps-mode-functions-processed-buffer
diff --git a/phps-mode-lexer.el b/phps-mode-lexer.el
index 44c60c8..4aae63a 100644
--- a/phps-mode-lexer.el
+++ b/phps-mode-lexer.el
@@ -36,6 +36,9 @@
 ;;; Code:
 
 
+(autoload 'phps-mode-function-get-buffer-changes-start "phps-mode-functions")
+(autoload 'phps-mode-functions-reset-buffer-changes-start 
"phps-mode-functions")
+
 (require 'semantic)
 (require 'semantic/lex)
 
@@ -1284,18 +1287,11 @@ ANY_CHAR'
              phps-mode-functions-processed-buffer)
     (setq phps-mode-functions-processed-buffer nil))
 
-  ;; TODO Delete all overlays after point of change if it's incremental
-
   ;; Does lexer start from the beginning of buffer?
   (when (and (eq start 1)
              end)
     (delete-all-overlays)
 
-    ;; Rest buffer changes flag
-    (when (and (boundp 'phps-mode-lexer-buffer-changes--start)
-               phps-mode-lexer-buffer-changes--start)
-      (setq phps-mode-lexer-buffer-changes--start nil))
-
     (setq phps-mode-lexer-states nil)
     (phps-mode-lexer-BEGIN phps-mode-lexer-ST_INITIAL)))
 
@@ -1351,16 +1347,16 @@ ANY_CHAR'
     new-tokens))
 
 (defun phps-mode-lexer-run-incremental ()
-  "Run incremental lexer based on `phps-mode-lexer-buffer-changes-start'."
-  (when (and (boundp 'phps-mode-functions-buffer-changes-start)
-             phps-mode-functions-buffer-changes-start
+  "Run incremental lexer based on 
`(phps-mode-functions-get-buffer-changes-start)'."
+  (when (and (phps-mode-functions-get-buffer-changes-start)
              phps-mode-lexer-states)
     (let ((state nil)
           (state-stack nil)
           (new-states '())
           (states (nreverse phps-mode-lexer-states))
-          (change-start phps-mode-functions-buffer-changes-start)
+          (change-start (phps-mode-functions-get-buffer-changes-start))
           (previous-token-start nil)
+          (previous-token-end nil)
           (tokens phps-mode-lexer-tokens))
       ;; (message "Looking for state to rewind to for %s in stack %s" 
change-start states)
 
@@ -1374,6 +1370,7 @@ ANY_CHAR'
               (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)))))
@@ -1386,13 +1383,13 @@ ANY_CHAR'
             (catch 'stop-iteration
               (dolist (token tokens)
                 (let ((start (car (cdr token))))
-                  (if (< start previous-token-start)
+                  (if (< start previous-token-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-start (point-max)))
+            (dolist (overlay (overlays-in previous-token-end (point-max)))
               (delete-overlay overlay))
             
             (let* ((new-tokens (semantic-lex previous-token-start (point-max)))
@@ -1410,7 +1407,7 @@ ANY_CHAR'
               ))
         ;; (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)))
-    (setq phps-mode-functions-buffer-changes-start nil)))
+    (phps-mode-functions-reset-buffer-changes-start)))
 
 (define-lex phps-mode-lexer-tags-lexer
   "Lexer that handles PHP buffers."
@@ -1430,14 +1427,10 @@ ANY_CHAR'
 
 (defun phps-mode-lexer-init ()
   "Initialize lexer."
-
   (when (boundp 'phps-mode-syntax-table)
     (setq semantic-lex-syntax-table phps-mode-syntax-table))
-
   (setq semantic-lex-analyzer #'phps-mode-lexer-tags-lexer)
-
   (add-hook 'semantic-lex-reset-functions #'phps-mode-lexer-setup)
-
   (phps-mode-lexer-run))
 
 (provide 'phps-mode-lexer)
diff --git a/phps-mode-test-integration.el b/phps-mode-test-integration.el
index 4d37fcb..a6fc0cc 100644
--- a/phps-mode-test-integration.el
+++ b/phps-mode-test-integration.el
@@ -33,7 +33,9 @@
 (autoload 'phps-mode-functions-indent-line "phps-mode-functions")
 (autoload 'phps-mode-functions-get-lines-indent "phps-mode-functions")
 (autoload 'phps-mode-functions-get-imenu "phps-mode-functions")
+(autoload 'phps-mode-functions-get-buffer-changes-start "phps-mode-functions")
 (autoload 'phps-mode-test-hash-to-list "phps-mode-test")
+(autoload 'phps-mode-lexer-get-tokens "phps-mode-lexer")
 (autoload 'should "ert")
 
 (defun phps-mode-test-integration-incremental ()
@@ -44,10 +46,8 @@
    "Integration-test for regular PHP with namespaces, classes and functions"
 
    ;; Tokens
-   (when (and (boundp 'phps-mode-lexer-tokens)
-              phps-mode-lexer-tokens)
-     ;; (message "Tokens %s" phps-mode-lexer-tokens)
-     (should (equal phps-mode-lexer-tokens '((T_OPEN_TAG 1 . 7) (T_NAMESPACE 7 
. 16) (T_STRING 17 . 28) ("{" 29 . 30) (T_CLASS 35 . 40) (T_STRING 41 . 48) 
("{" 53 . 54) (T_PUBLIC 63 . 69) (T_FUNCTION 70 . 78) (T_STRING 79 . 89) ("(" 
89 . 90) (")" 90 . 91) ("{" 100 . 101) (T_ECHO 114 . 118) 
(T_CONSTANT_ENCAPSED_STRING 119 . 133) (";" 133 . 134) ("}" 143 . 144) ("}" 149 
. 150) ("}" 151 . 152)))))
+   ;; (message "Tokens %s" phps-mode-lexer-tokens)
+   (should (equal (phps-mode-lexer-get-tokens) '((T_OPEN_TAG 1 . 7) 
(T_NAMESPACE 7 . 16) (T_STRING 17 . 28) ("{" 29 . 30) (T_CLASS 35 . 40) 
(T_STRING 41 . 48) ("{" 53 . 54) (T_PUBLIC 63 . 69) (T_FUNCTION 70 . 78) 
(T_STRING 79 . 89) ("(" 89 . 90) (")" 90 . 91) ("{" 100 . 101) (T_ECHO 114 . 
118) (T_CONSTANT_ENCAPSED_STRING 119 . 133) (";" 133 . 134) ("}" 143 . 144) 
("}" 149 . 150) ("}" 151 . 152))))
 
    ;; Indentation
    (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (1 0)) (5 (1 0)) (6 (2 
0)) (7 (2 0)) (8 (3 0)) (9 (2 0)) (10 (1 0)) (11 (0 0))) 
(phps-mode-test-hash-to-list (phps-mode-functions-get-lines-indent))))
@@ -60,17 +60,14 @@
    (insert "\n\n        public function myFunctionB()\n        {\n            
echo 'my second statement';\n        }\n")
 
    ;; Verify stored point of change
-   (when (boundp 'phps-mode-functions-buffer-changes-start)
-     (should (equal phps-mode-functions-buffer-changes-start 144)))
+   (should (equal (phps-mode-functions-get-buffer-changes-start) 144))
 
    ;; Run incremental lexer
    (phps-mode-lexer-run-incremental)
 
    ;; Tokens
-   (when (and (boundp 'phps-mode-lexer-tokens)
-              phps-mode-lexer-tokens)
-     ;; (message "Tokens %s" phps-mode-lexer-tokens)
-     (should (equal phps-mode-lexer-tokens '((T_OPEN_TAG 1 . 7) (T_NAMESPACE 7 
. 16) (T_STRING 17 . 28) ("{" 29 . 30) (T_CLASS 35 . 40) (T_STRING 41 . 48) 
("{" 53 . 54) (T_PUBLIC 63 . 69) (T_FUNCTION 70 . 78) (T_STRING 79 . 89) ("(" 
89 . 90) (")" 90 . 91) ("{" 100 . 101) (T_ECHO 114 . 118) 
(T_CONSTANT_ENCAPSED_STRING 119 . 133) (";" 133 . 134) ("}" 143 . 144) 
(T_PUBLIC 154 . 160) (T_FUNCTION 161 . 169) (T_STRING 170 . 181) ("(" 181 . 
182) (")" 182 . 183) ("{" 192 . 193) (T_ECHO 206 . 210 [...]
+   ;; (message "Tokens %s" (phps-mode-lexer-get-tokens))
+   (should (equal (phps-mode-lexer-get-tokens) '((T_OPEN_TAG 1 . 7) 
(T_NAMESPACE 7 . 16) (T_STRING 17 . 28) ("{" 29 . 30) (T_CLASS 35 . 40) 
(T_STRING 41 . 48) ("{" 53 . 54) (T_PUBLIC 63 . 69) (T_FUNCTION 70 . 78) 
(T_STRING 79 . 89) ("(" 89 . 90) (")" 90 . 91) ("{" 100 . 101) (T_ECHO 114 . 
118) (T_CONSTANT_ENCAPSED_STRING 119 . 133) (";" 133 . 134) (";" 133 . 134) 
("}" 143 . 144) (T_PUBLIC 154 . 160) (T_FUNCTION 161 . 169) (T_STRING 170 . 
181) ("(" 181 . 182) (")" 182 . 183) ("{" 192 . 19 [...]
 
    ;; Indentation
    ;; (message "indent: %s" (phps-mode-test-hash-to-list 
(phps-mode-functions-get-lines-indent)))



reply via email to

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