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

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

[elpa] externals/phps-mode 43bf350 216/405: Added tests for token-less l


From: Stefan Monnier
Subject: [elpa] externals/phps-mode 43bf350 216/405: Added tests for token-less lines
Date: Sat, 13 Jul 2019 10:00:16 -0400 (EDT)

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

    Added tests for token-less lines
---
 phps-mode-functions.el      | 41 ++++++++++++++++++++++-------------------
 phps-mode-test-functions.el |  8 +++++++-
 2 files changed, 29 insertions(+), 20 deletions(-)

diff --git a/phps-mode-functions.el b/phps-mode-functions.el
index b208b65..d5bd9da 100644
--- a/phps-mode-functions.el
+++ b/phps-mode-functions.el
@@ -229,19 +229,12 @@
 
                         (when (equal after-special-control-structure-token 
'T_SWITCH)
                           ;; (message "Opening switch, increase curly brackets 
to %s" curly-bracket-level)
-                          (push curly-bracket-level switch-curly-stack)
-                          (setq allow-custom-column-increment t)
-                          (setq curly-bracket-level (1+ curly-bracket-level)))
+                          (push curly-bracket-level switch-curly-stack))
 
                       ;; Is it the start of an alternative control structure?
                       (if (string= token ":")
 
                           (progn
-
-                            (when (equal after-special-control-structure-token 
'T_SWITCH)
-                              (setq alternative-control-structure-level (1+ 
alternative-control-structure-level))
-                              (setq allow-custom-column-increment t))
-
                             (setq alternative-control-structure-level (1+ 
alternative-control-structure-level))
 
                             (when phps-mode-functions-verbose
@@ -261,9 +254,15 @@
                   (setq after-special-control-structure-token nil)
                   (setq after-special-control-structure-first-on-line nil)))
 
-                ;; Support extra special control structures (CASE)
+                ;; Support extra special control structures (CASE:)
                 (when (and after-extra-special-control-structure
                            (string= token ":"))
+
+                  (when phps-mode-functions-verbose
+                    (message "Started CASE"))
+
+                  (setq alternative-control-structure-level (1+ 
alternative-control-structure-level))
+                  
                   (setq line-contained-nesting-increase t)
                   (when after-extra-special-control-structure-first-on-line
                     (setq first-token-is-nesting-decrease t))
@@ -394,16 +393,6 @@
                       (setq column-level-start column-level)
 
 
-                      ;; Indent token-less lines here in between last tokens 
if distance is more than 1 line
-                      (when (and (> next-token-start-line-number (1+ 
token-start-line-number))
-                                 (not (equal token 'T_CLOSE_TAG)))
-                        (let ((token-line-number-diff (1- (- 
token-start-line-number next-token-start-line-number))))
-                          (while (>= token-line-number-diff 0)
-                            (puthash (- token-start-line-number 
token-line-number-diff) `(,column-level-start ,tuning-level) line-indents)
-                            ;; (message "Saved line %s indent %s %s" (- 
token-end-line-number token-line-number-diff) column-level tuning-level)
-                            (setq token-line-number-diff (1- 
token-line-number-diff)))))
-
-
                       ;; Support temporarily pre-indent
                       (when temp-pre-indent
                         (setq column-level-start temp-pre-indent)
@@ -482,6 +471,20 @@
                           (setq tuning-level 0)))
 
 
+;; Indent token-less lines here in between last tokens if distance is more 
than 1 line
+                      (when (and (> next-token-start-line-number (1+ 
token-end-line-number))
+                                 (not (equal token 'T_CLOSE_TAG)))
+
+                        (when phps-mode-functions-verbose
+                          (message "\nDetected token-less lines between %s and 
%s, should have indent: %s\n" token-end-line-number 
next-token-start-line-number column-level))
+
+                        (let ((token-line-number-diff (1- (- 
next-token-start-line-number token-end-line-number))))
+                          (while (>= token-line-number-diff 0)
+                            (puthash (- next-token-start-line-number 
token-line-number-diff) `(,column-level ,tuning-level) line-indents)
+                            ;; (message "Saved line %s indent %s %s" (- 
token-end-line-number token-line-number-diff) column-level tuning-level)
+                            (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)
diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el
index e765760..affdf09 100644
--- a/phps-mode-test-functions.el
+++ b/phps-mode-test-functions.el
@@ -123,6 +123,12 @@
    ;; (message "Tokens: %s" phps-mode-lexer-tokens)
    (should (equal '((1 (0 0)) (2 (1 0)) (3 (0 0))) 
(phps-mode-test-functions--hash-to-list 
(phps-mode-functions-get-lines-indent)))))
 
+  (phps-mode-test-with-buffer
+   "<?php\nif (true) {\n\n\n    echo 'here';\n\n}"
+   "Regular if-expression white token-less lines"
+   ;; (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 (0 0))) (phps-mode-test-functions--hash-to-list 
(phps-mode-functions-get-lines-indent)))))
+
   )
 
 (defun phps-mode-test-functions-get-lines-indent-multi-line-assignments ()
@@ -276,7 +282,7 @@
    "<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)))))
+   (should (equal '((1 (0 0)) (2 (1 0)) (3 (2 0)) (4 (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>"



reply via email to

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