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

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

[elpa] externals/phps-mode 00c0ab9 194/405: Nesting-stack algorithm hand


From: Stefan Monnier
Subject: [elpa] externals/phps-mode 00c0ab9 194/405: Nesting-stack algorithm handles class declaration indents
Date: Sat, 13 Jul 2019 10:00:11 -0400 (EDT)

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

    Nesting-stack algorithm handles class declaration indents
---
 phps-mode-functions.el      | 16 +++++++++-------
 phps-mode-test-functions.el | 36 ++++++++++++++++++------------------
 2 files changed, 27 insertions(+), 25 deletions(-)

diff --git a/phps-mode-functions.el b/phps-mode-functions.el
index 3434e9c..165d6ea 100644
--- a/phps-mode-functions.el
+++ b/phps-mode-functions.el
@@ -90,7 +90,8 @@
               (tokens (nreverse phps-mode-lexer-tokens))
               (nesting-stack nil)
               (changed-nesting-stack-in-line nil)
-              (after-class-declaration nil))
+              (after-class-declaration nil)
+              (class-declaration-started-this-line nil))
 
           (push `(END_PARSE ,(point-max) . ,(point-max)) tokens)
 
@@ -143,10 +144,9 @@
                           (setq in-class-declaration nil)
                           (setq in-class-declaration-level 0)
 
-                          ;; TODO Should only do this if class-declaration was 
not started on this line
-                          (setq column-level (1- column-level))
-                          (setq nesting-start (1- nesting-start))
-                          (pop nesting-stack)
+                          (when (not class-declaration-started-this-line)
+                            (setq column-level (1- column-level))
+                            (pop nesting-stack))
 
                           (when first-token-on-line
 
@@ -161,7 +161,8 @@
                         (setq in-class-declaration-level 1)))
                   (when (equal token 'T_CLASS)
                     (setq in-class-declaration t)
-                    (setq in-class-declaration-level 1)))
+                    (setq in-class-declaration-level 1)
+                    (setq class-declaration-started-this-line t)))
 
                 ;; Keep track of curly bracket level
                 (when (or (equal token 'T_CURLY_OPEN)
@@ -455,7 +456,8 @@
                         (setq line-contained-nesting-increase nil)
                         (setq line-contained-nesting-decrease nil)
                         (setq in-assignment-started-this-line nil)
-                        (setq changed-nesting-stack-in-line nil)))
+                        (setq changed-nesting-stack-in-line nil)
+                        (setq class-declaration-started-this-line nil)))
 
                   ;; Current token is not first
                   (setq first-token-on-line nil)
diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el
index dfc3668..16bb3f4 100644
--- a/phps-mode-test-functions.el
+++ b/phps-mode-test-functions.el
@@ -48,17 +48,6 @@
   "Test `phps-mode-functions-get-lines-indent' function."
   
   (phps-mode-test-with-buffer
-   "<html><head><title><?php\nif ($myCondition) {\n    if ($mySecondCondition) 
{\n        echo $title;\n    } else if ($mySecondCondition) {\n        echo 
$title4;\n    } else {\n        echo $title2;\n        echo $title3;\n    }\n} 
?></title><body>Bla bla</body></html>"
-   "Mixed HTML/PHP"
-   (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (1 0)) (6 (2 
0)) (7 (1 0)) (8 (2 0)) (9 (2 0)) (10 (1 0)) (11 (0 0))) 
(phps-mode-test-functions--hash-to-list 
(phps-mode-functions-get-lines-indent)))))
-
-  (phps-mode-test-with-buffer
-   "<?php\nif (myFirstCondition()) {\n    $this->var = 'abc123';\n} else {\n   
 $this->var = 'def456';\n}\n"
-   "Regular else expression indent calculation"
-   ;; (message "Tokens %s point %s" phps-mode-lexer-tokens (point))
-   (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (0 0)) (5 (1 0)) (6 (0 
0))) (phps-mode-test-functions--hash-to-list 
(phps-mode-functions-get-lines-indent)))))
-
-  (phps-mode-test-with-buffer
    "<?php\nif (true):\n    echo 'Something';\nelseif (true):\n    echo 
'Something';\nelse:\n    echo 'Something else';\n    echo 'Something else 
again';\nendif;\necho true;\n"
    "Alternative control structures"
    (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (0 0)) (5 (1 0)) (6 (0 
0)) (7 (1 0)) (8 (1 0)) (9 (0 0)) (10 (0 0))) 
(phps-mode-test-functions--hash-to-list 
(phps-mode-functions-get-lines-indent)))))
@@ -119,12 +108,6 @@
    ;; (message "Tokens: %s" phps-mode-lexer-tokens)
    (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (0 0))) 
(phps-mode-test-functions--hash-to-list 
(phps-mode-functions-get-lines-indent)))))
 
-  (phps-mode-test-with-buffer
-   "<html><head><title><?php if ($myCondition) {\nif ($mySeconCondition) 
{\necho $title2;\n\n} ?></title><body>Bla bla</body></html>"
-   "Mixed HTML/PHP 2"
-   ;; (message "Tokens: %s" phps-mode-lexer-tokens)
-   (should (equal '((1 (0 0)) (2 (1 0)) (3 (2 0)) (5 (1 0))) 
(phps-mode-test-functions--hash-to-list 
(phps-mode-functions-get-lines-indent)))))
-
   ;; NOTE Maybe concatenated strings spanning multiple lines outside 
assignments should have indentation?
   
   (phps-mode-test-with-buffer
@@ -231,7 +214,7 @@
    (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (1 0)) (5 (0 0))) 
(phps-mode-test-functions--hash-to-list 
(phps-mode-functions-get-lines-indent)))))
 
   (phps-mode-test-with-buffer
-   "<?php\nif (myFunction(\ntrue)\n) {\n    echo 'was here';\n}\n"
+   "<?php\nif (myFunction(\n    true)\n) {\n    echo 'was here';\n}\n"
    "If expression spanning multiple lines 5"
    ;; (message "Tokens: %s" phps-mode-lexer-tokens)
    (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (0 0)) (5 (1 0)) (6 (0 
0))) (phps-mode-test-functions--hash-to-list 
(phps-mode-functions-get-lines-indent)))))
@@ -242,6 +225,23 @@
    ;; (message "Tokens: %s" phps-mode-lexer-tokens)
    (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (1 0)) (6 (2 
0)) (7 (1 0)) (8 (0 0))) (phps-mode-test-functions--hash-to-list 
(phps-mode-functions-get-lines-indent)))))
 
+  (phps-mode-test-with-buffer
+   "<html><head><title><?php if ($myCondition) {\n    if ($mySeconCondition) 
{\n        echo $title2;\n\n    } ?></title><body>Bla bla</body></html>"
+   "Mixed HTML/PHP with if expression"
+   ;; (message "Tokens: %s" phps-mode-lexer-tokens)
+   (should (equal '((1 (0 0)) (2 (1 0)) (3 (2 0)) (5 (1 0))) 
(phps-mode-test-functions--hash-to-list 
(phps-mode-functions-get-lines-indent)))))
+
+  (phps-mode-test-with-buffer
+   "<html><head><title><?php\nif ($myCondition) {\n    if ($mySecondCondition) 
{\n        echo $title;\n    } else if ($mySecondCondition) {\n        echo 
$title4;\n    } else {\n        echo $title2;\n        echo $title3;\n    }\n} 
?></title><body>Bla bla</body></html>"
+   "Mixed HTML/PHP with if expression 2"
+   (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (1 0)) (6 (2 
0)) (7 (1 0)) (8 (2 0)) (9 (2 0)) (10 (1 0)) (11 (0 0))) 
(phps-mode-test-functions--hash-to-list 
(phps-mode-functions-get-lines-indent)))))
+
+  (phps-mode-test-with-buffer
+   "<?php\nif (myFirstCondition()) {\n    $this->var = 'abc123';\n} else {\n   
 $this->var = 'def456';\n}\n"
+   "Regular else expression indent calculation"
+   ;; (message "Tokens %s point %s" phps-mode-lexer-tokens (point))
+   (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (0 0)) (5 (1 0)) (6 (0 
0))) (phps-mode-test-functions--hash-to-list 
(phps-mode-functions-get-lines-indent)))))
+
   )
 
 (defun phps-mode-test-functions-indent-line ()



reply via email to

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