[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 ()
- [elpa] externals/phps-mode b5c64c1 162/405: Added failing tests for HEREDOC and NOWDOC assignments, (continued)
- [elpa] externals/phps-mode b5c64c1 162/405: Added failing tests for HEREDOC and NOWDOC assignments, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode f283e4b 173/405: Added new failing unit tests for multiple-lines IF and single line class declaration, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 59474ea 180/405: Improved debugging messages, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 9659ab4 174/405: Added failing test for doc-comments are namespace and class, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode c5d8ec6 168/405: Indentation calculation for class implement working, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode f93765d 184/405: Improved code structure of indentation were nesting start and end equals, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 2af8abd 206/405: Made TODO notes in algorithm, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 7a538ac 200/405: Tests for alternative control structures passes, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 79e61f4 171/405: Fixed indentation with assignment lines on only one line, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode d18fddc 175/405: Fixed bug with indentation for indented doc-comments, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 00c0ab9 194/405: Nesting-stack algorithm handles class declaration indents,
Stefan Monnier <=
- [elpa] externals/phps-mode 8a76039 189/405: Started implementing nesting-stack, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode cf7dc07 210/405: Preparations for multi-line quoted indentation tests, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 208a788 208/405: Re-organized indent tests, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode c678fc1 209/405: New algorithm handles HEREDOC indentation, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode b6cf3a4 191/405: Started on new algorithm for indentation calculation based on stack, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode b2338cd 223/405: All tests for indentation passes, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 7a4b98e 215/405: More work on algorithm description, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 9031c3a 211/405: Merge branch 'master' of https://github.com/cjohansson/emacs-phps-mode, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 6105e5d 226/405: Added a new failing test for indetation, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 5f445cd 229/405: Fixed indentation for while expressions, Stefan Monnier, 2019/07/13