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

[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)



reply via email to

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