[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 0286660 224/405: Indentation passes new tests
From: |
Stefan Monnier |
Subject: |
[elpa] externals/phps-mode 0286660 224/405: Indentation passes new tests for concatenated strings |
Date: |
Sat, 13 Jul 2019 10:00:17 -0400 (EDT) |
branch: externals/phps-mode
commit 0286660c3cfd1c761414076aac6e5b60f03b00dd
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>
Indentation passes new tests for concatenated strings
---
phps-mode-functions.el | 34 ++++++++++++++++++++--------------
phps-mode-test-functions.el | 22 +++++++++++++++++-----
2 files changed, 37 insertions(+), 19 deletions(-)
diff --git a/phps-mode-functions.el b/phps-mode-functions.el
index cd7af95..e46506c 100644
--- a/phps-mode-functions.el
+++ b/phps-mode-functions.el
@@ -67,6 +67,7 @@
(round-bracket-level 0)
(square-bracket-level 0)
(alternative-control-structure-level 0)
+ (concatenation-level 0)
(column-level 0)
(column-level-start 0)
(tuning-level 0)
@@ -285,6 +286,21 @@
(setq first-token-is-nesting-decrease t))
(setq after-extra-special-control-structure nil))
+ ;; Keep track of concatenations
+ (when (and first-token-on-line
+ (string= token "."))
+ (when phps-mode-functions-verbose
+ (message "\nFound starting dot, indenting current line
with one.\n"))
+ (setq temp-pre-indent t)
+ (setq temp-pre-indent (1+ column-level)))
+ (when (> next-token-start-line-number token-end-line-number)
+ (if (string= token ".")
+ (progn
+ (when phps-mode-functions-verbose
+ (message "\nFound ending dot, indenting next line
with one.\n"))
+ (setq concatenation-level 1))
+ (setq concatenation-level 0)))
+
;; Did we reach a semicolon inside a inline block? Close the
inline block
(when (and in-inline-control-structure
(string= token ";")
@@ -319,9 +335,7 @@
(when phps-mode-functions-verbose
(message "\nDecreasing alternative control structure
nesting at %s to %s\n" token alternative-control-structure-level))
- )
-
- )
+ ))
;; Keep track of assignments
(if in-assignment
@@ -362,7 +376,7 @@
(when token
;; Calculate nesting
- (setq nesting-end (+ round-bracket-level square-bracket-level
curly-bracket-level alternative-control-structure-level in-assignment-level
in-class-declaration-level))
+ (setq nesting-end (+ round-bracket-level square-bracket-level
curly-bracket-level alternative-control-structure-level in-assignment-level
in-class-declaration-level concatenation-level))
;; Keep track of whether we are inside a HEREDOC or NOWDOC
(when (equal token 'T_START_HEREDOC)
@@ -417,6 +431,7 @@
;; Line logic
(progn
+
;; ;; Start indentation might differ from ending
indentation in cases like } else {
(setq column-level-start column-level)
@@ -510,17 +525,8 @@
(setq token-line-number-diff (1-
token-line-number-diff)))))
- ;; ;; When nesting decreases but ends with a nesting
increase, increase indent by one
- ;; (when (and (< nesting-end nesting-start)
- ;; line-contained-nesting-increase)
- ;; (setq column-level (1+ column-level))
- ;; (when phps-mode-functions-verbose
- ;; (message "Pushing %s to nesting-stack since is
lesser than %s" nesting-start nesting-end))
- ;; (push `(,nesting-start nesting-end) nesting-stack)
- ;; (message "New stack %s, start: %s end: %s"
nesting-stack (car (car nesting-stack)) (car (cdr (car nesting-stack)))))
-
;; Calculate indentation level at start of line
- (setq nesting-start (+ round-bracket-level
square-bracket-level curly-bracket-level alternative-control-structure-level
in-assignment-level in-class-declaration-level))
+ (setq nesting-start (+ round-bracket-level
square-bracket-level curly-bracket-level alternative-control-structure-level
in-assignment-level in-class-declaration-level concatenation-level))
;; Set initial values for tracking first token
(when (> token-start-line-number last-line-number)
diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el
index dddd995..00f23a2 100644
--- a/phps-mode-test-functions.el
+++ b/phps-mode-test-functions.el
@@ -85,14 +85,26 @@
(phps-mode-test-with-buffer
"<?php\necho \"A line\" .\n \"more text here\" .\n \"last line
here\";"
"Concatenated double-quoted-string spanning multiple-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)))))
+ (message "Tokens: %s" phps-mode-lexer-tokens)
+ (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 0)))
(phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
+
+ (phps-mode-test-with-buffer
+ "<?php\necho \"A line\"\n . \"more text here\"\n . \"last line
here\";"
+ "Concatenated double-quoted-string spanning multiple-lines 2"
+ (message "Tokens: %s" phps-mode-lexer-tokens)
+ (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 0)))
(phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
(phps-mode-test-with-buffer
"<?php\necho 'A line' .\n 'more text here' .\n 'last line here';"
"Concatenated single-quoted-string spanning multiple-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)))))
+ (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 0)))
(phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
+
+ (phps-mode-test-with-buffer
+ "<?php\necho 'A line'\n . 'more text here'\n . 'last line here';"
+ "Concatenated single-quoted-string spanning multiple-lines 2"
+ ;; (message "Tokens: %s" phps-mode-lexer-tokens)
+ (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (1 0)))
(phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
(phps-mode-test-with-buffer
"<?php\necho <<<EOD\nExample of string\nspanning multiple lines\nusing
heredoc syntax.\nEOD;\n"
@@ -156,7 +168,7 @@
"<?php\n$var =\n 500 .\n \"200\" .\n 100.0 .\n '200' .\n
$this->getTail()\n ->getBottom();"
"Multi-line assignments"
;; (message "Tokens: %s" phps-mode-lexer-tokens)
- (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)))))
+ (should (equal '((1 (0 0)) (2 (0 0)) (3 (1 0)) (4 (2 0)) (5 (2 0)) (6 (2
0)) (7 (2 0)) (8 (1 0))) (phps-mode-test-functions--hash-to-list
(phps-mode-functions-get-lines-indent)))))
)
@@ -553,8 +565,8 @@
(phps-mode-test-functions-get-lines-indent-inline-if)
(phps-mode-test-functions-get-lines-indent-alternative-if)
(phps-mode-test-functions-get-lines-indent-multi-line-assignments)
- (phps-mode-test-functions-get-lines-indent)
(phps-mode-test-functions-get-lines-indent-switch-case)
+ (phps-mode-test-functions-get-lines-indent)
(phps-mode-test-functions-indent-line))
(phps-mode-test-functions)
- [elpa] externals/phps-mode 811c499 220/405: New algorithm now works for switch, case syntax, (continued)
- [elpa] externals/phps-mode 811c499 220/405: New algorithm now works for switch, case syntax, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode d2e5a03 228/405: Updated indentation algorithm document and README, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 1aa0f90 238/405: Typo in README, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode da1cfd5 231/405: Adding failing lexer test, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode e6a8944 241/405: Started work on a lexer bug with expressions inside double quoted strings, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 0c49d6d 243/405: Removed debugging output, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 95ac15a 245/405: Imenu index now handles class extends and implements, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 67233ef 213/405: Fixed indent algorithm for multi-line strings, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 36a4b64 222/405: Added lost test for token-less lines again, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 70f2d46 242/405: Fixed lexer issue with multiple expressions inside double-quoted string, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 0286660 224/405: Indentation passes new tests for concatenated strings,
Stefan Monnier <=
- [elpa] externals/phps-mode f05d40a 230/405: Tests for lexer passes again after close_tag modification, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 1bc5713 227/405: New tests for concatenation passes, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode c71a97d 178/405: Started on refactored indentation calculation, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 8bb3918 249/405: Clean-up of unit test logging, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 9201d1c 246/405: Imenu index now handles functions with optional arguments, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 2c3239a 187/405: Adding new failing tests for indentation, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode d9a0119 183/405: Optimized indentation code by removing unused variables, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode a0cbcd1 186/405: More work on indentation of multi-line IF-expressions, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode d7c5f67 190/405: More work on nesting-stack, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 253839f 170/405: Added indentation unit tests for concatenated strings outside assignments, Stefan Monnier, 2019/07/13