branch: externals/phps-mode
commit dd1cb7a130a7b512daf977d1045ded7570cd3e0e
Author: Christian Johansson <christ...@cvj.se>
Commit: Christian Johansson <christ...@cvj.se>

    Fixed indentation of special case single line alternative control structure
---
 phps-mode-analyzer.el            | 12 +++++++++---
 phps-mode.el                     |  2 +-
 test/phps-mode-test-functions.el |  5 +++++
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/phps-mode-analyzer.el b/phps-mode-analyzer.el
index 6465f40..7a9de58 100644
--- a/phps-mode-analyzer.el
+++ b/phps-mode-analyzer.el
@@ -2204,6 +2204,7 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
               (round-bracket-level 0)
               (square-bracket-level 0)
               (alternative-control-structure-level 0)
+              (alternative-control-structure-line 0)
               (in-concatenation nil)
               (in-concatenation-round-bracket-level nil)
               (in-concatenation-square-bracket-level nil)
@@ -2608,7 +2609,9 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
 
                   ;; Handle the else if case
                   (if (equal 'T_IF token)
-                      (setq after-special-control-structure-token token)
+                      (progn
+                        (setq after-special-control-structure-token token)
+                        (setq alternative-control-structure-line 
token-start-line-number))
 
                     ;; Is token not a curly bracket - because that is a 
ordinary control structure syntax
                     (if (string= token "{")
@@ -2653,10 +2656,12 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
                             token))
 
                           (setq in-inline-control-structure t)
-                          (setq temp-pre-indent (1+ column-level)))))
+                          (when (< alternative-control-structure-line 
token-start-line-number)
+                            (setq temp-pre-indent (1+ column-level))))))
 
                     (setq after-special-control-structure nil)
-                    (setq after-special-control-structure-token nil)))
+                    (setq after-special-control-structure-token nil)
+                    (setq alternative-control-structure-line nil)))
 
                 ;; Support extra special control structures (CASE)
                 (when (and after-extra-special-control-structure
@@ -2708,6 +2713,7 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL."
                           (equal token 'T_DEFAULT))
                   (setq after-special-control-structure round-bracket-level)
                   (setq after-special-control-structure-token token)
+                  (setq alternative-control-structure-line 
token-start-line-number)
                   (setq nesting-key token)
                   (setq special-control-structure-started-this-line t)
 
diff --git a/phps-mode.el b/phps-mode.el
index e07816e..08ac499 100644
--- a/phps-mode.el
+++ b/phps-mode.el
@@ -6,7 +6,7 @@
 ;; Maintainer: Christian Johansson <christ...@cvj.se>
 ;; Created: 3 Mar 2018
 ;; Modified: 11 Nov 2019
-;; Version: 0.3.11
+;; Version: 0.3.12
 ;; Keywords: tools, convenience
 ;; URL: https://github.com/cjohansson/emacs-phps-mode
 
diff --git a/test/phps-mode-test-functions.el b/test/phps-mode-test-functions.el
index c5e3a3d..a82909f 100644
--- a/test/phps-mode-test-functions.el
+++ b/test/phps-mode-test-functions.el
@@ -275,6 +275,11 @@
     (should (equal '((1 (0 0)) (2 (1 0)) (3 (2 0)) (4 (1 0)) (5 (1 0)) (6 (0 
0)) (7 (0 0)) (8 (0 0)) (9 (1 0)) (10 (0 0)) (11 (0 0)) (12 (0 0)) (13 (1 0)) 
(14 (0 0))) (phps-mode-test-hash-to-list 
(phps-mode-functions-get-lines-indent)))))
    )
 
+  (phps-mode-test-with-buffer
+   "<?php\n\n    if ($fullInfo) $fullInfo = unserialize ($fullInfo);\n    else 
array();\n\n"
+   "Indentation for single-line inline control structures."
+   (should (equal '((1 (0 0)) (2 (0 0)) (3 (0 0)) (4 (0 0))) 
(phps-mode-test-hash-to-list (phps-mode-functions-get-lines-indent)))))
+
   )
 
 (defun phps-mode-test-functions-get-lines-indent-psr-2 ()

Reply via email to