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

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

[elpa] externals/phps-mode 6776468 037/405: Started worked with adding r


From: Stefan Monnier
Subject: [elpa] externals/phps-mode 6776468 037/405: Started worked with adding references to tokens from point meta information
Date: Sat, 13 Jul 2019 09:59:35 -0400 (EDT)

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

    Started worked with adding references to tokens from point meta information
---
 phps-functions.el      |  3 ++-
 phps-lexer.el          | 15 ++++++++++++---
 phps-test-functions.el |  9 ++++++++-
 phps-test-lexer.el     | 18 ++++++++++--------
 4 files changed, 32 insertions(+), 13 deletions(-)

diff --git a/phps-functions.el b/phps-functions.el
index 1d26588..cc2bc7a 100644
--- a/phps-functions.el
+++ b/phps-functions.el
@@ -50,7 +50,8 @@
             (let* ((indent-start (* (+ (nth 1 start) (nth 2 start)) 4))
                    (indent-end (* (+ (nth 1 end) (nth 2 end)) 4))
                    (indent-diff 0))
-              (when (> indent-start indent-end)
+              (when (and (> indent-start indent-end)
+                         (looking-at-p "^[][ \t)(}{};]+\\($\\|?>\\)"))
                 (setq indent-diff (- indent-start indent-end)))
               (setq indent-level (- indent-start indent-diff))
               (message "inside scripting, start: %s, end: %s, indenting to 
column %s " start end indent-level)
diff --git a/phps-lexer.el b/phps-lexer.el
index da663ec..8c545d4 100644
--- a/phps-lexer.el
+++ b/phps-lexer.el
@@ -47,6 +47,9 @@
 (defvar phps-mode/lexer-tokens nil
   "Last lexer tokens.")
 
+(defvar phps-mode/buffer-changes--start nil
+  "Start of buffer changes, nil if none.")
+
 
 ;; SETTINGS
 
@@ -1268,10 +1271,12 @@ ANY_CHAR'
           (start-brace-level 0)
           (start-parenthesis-level 0)
           (start-inline-function-level 0)
+          (start-token-number 0)
           (end-in-scripting nil)
           (end-brace-level 0)
           (end-parenthesis-level 0)
-          (end-inline-function-level 0))
+          (end-inline-function-level 0)
+          (end-token-number 0))
       (catch 'stop-iteration
         (dolist (item phps-mode/lexer-tokens)
           (let ((token (car item))
@@ -1285,6 +1290,7 @@ ANY_CHAR'
 
             ;; When start of token is equal or less to current point
             (when (< start position)
+              (setq start-token-number (+ start-token-number 1))
               (pcase token
                 ('T_OPEN_TAG (setq start-in-scripting t))
                 ('T_OPEN_TAG_WITH_ECHO (setq start-in-scripting t))
@@ -1297,6 +1303,7 @@ ANY_CHAR'
 
             ;; When start of token is equal or less to end of curent line
             (when (< start line-end)
+              (setq end-token-number (+ end-token-number 1))
               (pcase token
                 ('T_OPEN_TAG (setq end-in-scripting t))
                 ('T_OPEN_TAG_WITH_ECHO (setq end-in-scripting t))
@@ -1308,7 +1315,7 @@ ANY_CHAR'
                 (_)))
             
             )))
-      (let ((data (list (list start-in-scripting start-brace-level 
start-parenthesis-level start-inline-function-level) (list end-in-scripting 
end-brace-level end-parenthesis-level end-inline-function-level))))
+      (let ((data (list (list start-in-scripting start-brace-level 
start-parenthesis-level start-inline-function-level start-token-number) (list 
end-in-scripting end-brace-level end-parenthesis-level 
end-inline-function-level end-token-number))))
         ;; (message "data: %s" data)
         data)
       )))
@@ -1317,6 +1324,7 @@ ANY_CHAR'
   "Just prepare other lexers for lexing region START to END."
   (when (eq start 1)
     ;; (message "SETUP %s %s" start end)
+    (setq phps-mode/buffer-changes--start nil)
     (phps-mode/BEGIN phps-mode/ST_INITIAL)))
 
 ;; TODO This function should track between what min and max region a specific 
buffer has been modified and then re-run lexer for that region when editor is 
idle, maybe use (buffer-name))
@@ -1324,7 +1332,8 @@ ANY_CHAR'
 (defun phps-mode/after-change-functions (start stop length)
   "Track buffer change from START to STOP with length LENGTH."
   (when (string= major-mode "phps-mode")
-    ;; (message "phps-mode/after-change-functions %s %s %s" start stop length)
+    (setq phps-mode/buffer-changes--start start)
+    (message "phps-mode/after-change-functions %s %s %s" start stop length)
   ))
 
 (defun phps-mode/lex--RUN ()
diff --git a/phps-test-functions.el b/phps-test-functions.el
index f5f637f..3f6543e 100644
--- a/phps-test-functions.el
+++ b/phps-test-functions.el
@@ -81,13 +81,20 @@
    (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
      (should (equal buffer-contents  "<?php\n$variable = array(\n    
'random'\n);\n$variable = true;\n"))))
 
-(phps-mode/with-test-buffer
+  (phps-mode/with-test-buffer
    "<?php\n$variable = array(\n    'random'\n    );\n$variable = true;\n"
    (goto-char 39)
    (phps-mode/indent-line)
    (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
      (should (equal buffer-contents  "<?php\n$variable = array(\n    
'random'\n);\n$variable = true;\n"))))
 
+  (phps-mode/with-test-buffer
+   "<?php\n$variable = array(\n'random');\n$variable = true;\n"
+   (goto-char 29)
+   (phps-mode/indent-line)
+   (let ((buffer-contents (buffer-substring-no-properties (point-min) 
(point-max))))
+     (should (equal buffer-contents  "<?php\n$variable = array(\n    
'random');\n$variable = true;\n"))))
+
   )
 
 (defun phps-mod/test-functions ()
diff --git a/phps-test-lexer.el b/phps-test-lexer.el
index 997b96b..eb1af34 100644
--- a/phps-test-lexer.el
+++ b/phps-test-lexer.el
@@ -255,47 +255,49 @@
   (phps-mode/with-test-buffer
    "<?php\nNAMESPACE MyNameSpace;\nCLASS MyClass {\n\tpublic function 
__construct() {\n\t\texit;\n\t}\n}\n"
    (goto-char 35)
-   (should (equal (list (list t 0 0 0) (list t 1 0 0)) 
(phps-mode/lexer-get-point-data))))
+   (should (equal (list (list t 0 0 0 4) (list t 1 0 0 7)) 
(phps-mode/lexer-get-point-data))))
 
   (phps-mode/with-test-buffer
    "<html><head><title><?php echo $title; ?></title><body>Bla 
bla</body></html>"
    (goto-char 15)
-   (should (equal (list (list nil 0 0 0) (list nil 0 0 0)) 
(phps-mode/lexer-get-point-data))))
+   (should (equal (list (list nil 0 0 0 0) (list nil 0 0 0 6)) 
(phps-mode/lexer-get-point-data))))
 
   (phps-mode/with-test-buffer
    "<html><head><title><?php echo $title; ?></title><body>Bla 
bla</body></html>"
    (goto-char 30)
-   (should (equal (list (list nil 0 0 0) (list nil 0 0 0)) 
(phps-mode/lexer-get-point-data))))
+   (should (equal (list (list nil 0 0 0 0) (list nil 0 0 0 6)) 
(phps-mode/lexer-get-point-data))))
 
   (phps-mode/with-test-buffer
    "<html><head><title><?php echo $title; ?></title><body>Bla 
bla</body></html>"
    (goto-char 50)
-   (should (equal (list (list nil 0 0 0) (list nil 0 0 0)) 
(phps-mode/lexer-get-point-data))))
+   (should (equal (list (list nil 0 0 0 0) (list nil 0 0 0 6)) 
(phps-mode/lexer-get-point-data))))
 
   (phps-mode/with-test-buffer
    "<html><head><title><?php if ($myCondition) { \n   if ($mySeconCondition) { 
echo $title; } } ?></title><body>Bla bla</body></html>"
    ;; (message "Tokens: %s" phps-mode/lexer-tokens)
    (goto-char 48)
-   (should (equal (list (list t 1 0 0) (list nil 0 0 0)) 
(phps-mode/lexer-get-point-data))))
+   (should (equal (list (list t 1 0 0 6) (list nil 0 0 0 18)) 
(phps-mode/lexer-get-point-data))))
 
   (phps-mode/with-test-buffer
    "<html><head><title><?php if ($myCondition) { if ($mySeconCondition) {\n 
echo $title;\n} } ?></title><body>Bla bla</body></html>"
    (goto-char 72)
-   (should (equal (list (list t 2 0 0) (list t 2 0 0)) 
(phps-mode/lexer-get-point-data))))
+   (should (equal (list (list t 2 0 0 11) (list t 2 0 0 14)) 
(phps-mode/lexer-get-point-data))))
 
   (phps-mode/with-test-buffer
    "<html><head><title><?php if ($myCondition) {\nif ($mySeconCondition) 
{\necho $title;\n}\n}\n ?></title><body>Bla bla</body></html>"
    (goto-char 84)
-   (should (equal (list (list t 2 0 0) (list t 1 0 0)) 
(phps-mode/lexer-get-point-data))))
+   (should (equal (list (list t 2 0 0 14) (list t 1 0 0 15)) 
(phps-mode/lexer-get-point-data))))
 
   (phps-mode/with-test-buffer
    "<html><head><title><?php if ($myCondition) { if ($mySeconCondition) { echo 
$title; } } ?></title><body>Bla bla</body></html>"
    
    (goto-char 100)
-   (should (equal (list (list nil 0 0 0) (list nil 0 0 0)) 
(phps-mode/lexer-get-point-data))))
+   (should (equal (list (list nil 0 0 0 0) (list nil 0 0 0 18)) 
(phps-mode/lexer-get-point-data))))
 
   )
 
+;; TODO Test this: $wpdb->get_var("SELECT post_parent FROM $wpdb->posts WHERE 
ID = '".$id."'");
+
 (defun phps-mode/test-lexer ()
   "Run test for lexer."
   ;; (message "-- Running all tests for lexer... --\n")



reply via email to

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