[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 79e61f4 171/405: Fixed indentation with assig
From: |
Stefan Monnier |
Subject: |
[elpa] externals/phps-mode 79e61f4 171/405: Fixed indentation with assignment lines on only one line |
Date: |
Sat, 13 Jul 2019 10:00:06 -0400 (EDT) |
branch: externals/phps-mode
commit 79e61f4903fd03b421348056ef84303a3e594670
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>
Fixed indentation with assignment lines on only one line
---
phps-mode-functions.el | 15 ++++++++++-----
phps-mode-test-functions.el | 20 +++++++++++++++-----
2 files changed, 25 insertions(+), 10 deletions(-)
diff --git a/phps-mode-functions.el b/phps-mode-functions.el
index 2de738d..72e268c 100644
--- a/phps-mode-functions.el
+++ b/phps-mode-functions.el
@@ -77,6 +77,7 @@
(allow-custom-column-decrement nil)
(in-assignment nil)
(in-assignment-level 0)
+ (in-assignment-started-this-line nil)
(in-class-declaration nil)
(in-class-declaration-level 0))
@@ -124,14 +125,14 @@
(when first-token-is-nesting-increase
(setq column-level (1+ column-level))))
- (message "new line %s or last token at %s, %s %s.%s (%s -
%s) = %s %s %s %s %s [%s %s] %s %s %s" token-start-line-number token last-token
column-level tuning-level nesting-start nesting-end round-bracket-level
square-bracket-level curly-bracket-level alternative-control-structure-level
inline-control-structure-level first-token-is-nesting-decrease
first-token-is-nesting-increase in-assignment-level in-assignment-level
in-class-declaration-level)
+ ;; (message "new line %s or last token at %s, %s %s.%s (%s
- %s) = %s %s %s %s %s [%s %s] %s %s %s" token-start-line-number token
last-token column-level tuning-level nesting-start nesting-end
round-bracket-level square-bracket-level curly-bracket-level
alternative-control-structure-level inline-control-structure-level
first-token-is-nesting-decrease first-token-is-nesting-increase in-assignment
in-assignment-level in-class-declaration-level)
;; Put indent-level to hash-table
(when (> last-line-number 0)
(puthash last-line-number `(,column-level ,tuning-level)
line-indents))
(when (> token-end-line-number token-start-line-number)
- (message "Token %s starts at %s and ends at %s" token
token-start-line-number token-end-line-number)
+ ;; (message "Token %s starts at %s and ends at %s" token
token-start-line-number token-end-line-number)
(when (equal token 'T_DOC_COMMENT)
(setq tuning-level 1))
@@ -167,7 +168,8 @@
(setq first-token-is-nesting-increase nil)
(setq first-token-is-nesting-decrease nil)
(setq in-assignment-level 0)
- (setq in-class-declaration-level 0)))
+ (setq in-class-declaration-level 0)
+ (setq in-assignment-started-this-line nil)))
(setq first-token-on-line nil)
(when (> token-end-line-number token-start-line-number)
;; (message "Token not first on line %s starts at %s and
ends at %s" token token-start-line-number token-end-line-number)
@@ -314,17 +316,20 @@
(if (string= token ";")
(progn
(setq in-assignment nil)
+ (when in-assignment-started-this-line
+ (setq in-assignment-level 0))
;; (message "Assignment ended at semi-colon")
)
(when (and first-token-on-line
(not in-heredoc))
(setq in-assignment-level 1)
- (message "In assignment on new-line at %s" token)
+ ;; (message "In assignment on new-line at %s" token)
))
(when (and (not after-special-control-structure)
(string= token "="))
;; (message "Started assignment")
(setq in-assignment t)
+ (setq in-assignment-started-this-line t)
(setq in-assignment-level 1)))
;; Did we encounter a token that supports extra special
alternative control structures?
@@ -393,7 +398,7 @@
(when first-token-is-nesting-increase
(setq column-level (1+ column-level))))
- (message "last token at %s %s.%s (%s - %s) = %s %s %s %s %s [%s
%s] %s %s" last-token column-level tuning-level nesting-start nesting-end
round-bracket-level square-bracket-level curly-bracket-level
alternative-control-structure-level inline-control-structure-level
first-token-is-nesting-decrease first-token-is-nesting-increase
in-assignment-level in-class-declaration-level)
+ ;; (message "last token at %s %s.%s (%s - %s) = %s %s %s %s %s [%s
%s] %s %s" last-token column-level tuning-level nesting-start nesting-end
round-bracket-level square-bracket-level curly-bracket-level
alternative-control-structure-level inline-control-structure-level
first-token-is-nesting-decrease first-token-is-nesting-increase
in-assignment-level in-class-declaration-level)
;; Put indent-level to hash-table
(puthash last-line-number `(,column-level ,tuning-level)
line-indents))
diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el
index 27763fb..57af0eb 100644
--- a/phps-mode-test-functions.el
+++ b/phps-mode-test-functions.el
@@ -59,6 +59,12 @@
(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)))))
@@ -90,6 +96,12 @@
(should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 0)) (5 (1 0)) (6 (1
0)) (7 (1 0)) (8 (1 0))) (phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
(phps-mode-test-with-buffer
+ "<?php\n$variable = array(\n 'random4');\n$variable = true;\n"
+ "Array assignment on only two lines"
+ ;; (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
"<?php\n$str = <<<'EOD'\nExample of string\nspanning multiple lines\nusing
nowdoc syntax.\nEOD;\n"
"Multi-line NOWDOC string"
;; (message "Tokens: %s" phps-mode-lexer-tokens)
@@ -122,7 +134,7 @@
(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)
+ ;; (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?
@@ -234,16 +246,14 @@
(let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
(should (equal buffer-contents "<?php\n/**\n* My first line\n* My second
line\n **/\n"))))
- ;; TODO Fix this and also indentation for class implements
-
(phps-mode-test-with-buffer
- "<?php\n$variable = array(\n'random4');\n$variable = true;\n"
+ "<?php\n$variable = array(\n 'random4');\n$variable = true;\n"
"Round bracket test 1"
(goto-char 30)
(phps-mode-functions-indent-line)
;; (message "Tokens %s point %s" phps-mode-lexer-tokens (point))
(let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
- (should (equal buffer-contents "<?php\n$variable = array(\n
'random4');\n$variable = true;\n"))))
+ (should (equal buffer-contents "<?php\n$variable =
array(\n'random4');\n$variable = true;\n"))))
(phps-mode-test-with-buffer
"<?php\nadd_filter(\n\"views_{$screen->id}\",'__return_empty_array'\n);"
- [elpa] externals/phps-mode 3718931 156/405: Basic tests for indentation calculation passes, (continued)
- [elpa] externals/phps-mode 3718931 156/405: Basic tests for indentation calculation passes, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 13e9148 159/405: Indentation unit test for assignment is passing, Stefan Monnier, 2019/07/13
- [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 <=
- [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, 2019/07/13
- [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