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

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

[elpa] externals/phps-mode 097be241c6 3/5: Fix for switch case indentati


From: Christian Johansson
Subject: [elpa] externals/phps-mode 097be241c6 3/5: Fix for switch case indentation with semicolon
Date: Thu, 28 Jul 2022 04:38:58 -0400 (EDT)

branch: externals/phps-mode
commit 097be241c6e6ba8a3ba3af4186ed20b95c15c37e
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>

    Fix for switch case indentation with semicolon
---
 TODO.md                       |  8 ------
 phps-mode-indent.el           | 62 +++++++++++++++++++++----------------------
 test/phps-mode-test-indent.el |  4 +++
 3 files changed, 35 insertions(+), 39 deletions(-)

diff --git a/TODO.md b/TODO.md
index c2c57ef2fb..8d5b2e1b6f 100644
--- a/TODO.md
+++ b/TODO.md
@@ -2,14 +2,6 @@
 
 ## Indentation
 
-### Alternative switch case
-
-switch($case) {
-    case 1:
-    case 2;
-    echo 'here';
-}
-
 ### Multi-line function call with named arguments
 
 function myFunction(
diff --git a/phps-mode-indent.el b/phps-mode-indent.el
index f0ea149d44..e8c1e4d11c 100644
--- a/phps-mode-indent.el
+++ b/phps-mode-indent.el
@@ -1259,6 +1259,37 @@
                    new-indentation
                    (- new-indentation tab-width))))
 
+               ;; LINE AFTER CASE DEFINITION
+               ;; case true:
+               ;;     echo 'here';
+               ;; or
+               ;; case true;
+               ;;     echo 'here';
+               ;; or
+               ;; default:
+               ;;     echo 'here';
+               ;; or
+               ;; default;
+               ;;     echo 'here';
+               ((and
+                 (not
+                  (string-match-p
+                   "^[\t ]*\\(case[\t ]+\\|default\\)"
+                   current-line-string))
+                 (or
+                  (string-match-p
+                   "^[\t ]*case[\t ]+.*\\(;\\|:\\)[\t ]*$"
+                   previous-line-string)
+                  (string-match-p
+                   "^[\t ]*default.*\\(;\\|:\\)[\t ]*$"
+                   previous-line-string)))
+                (setq
+                 match-type
+                 'line-after-case-definition)
+                (setq
+                 new-indentation
+                 (+ new-indentation tab-width)))
+
                ;; LINE AFTER LINE THATS ENDS WITH SEMICOLON
                ;; $var .=
                ;;     'hello';
@@ -1704,37 +1735,6 @@
                  new-indentation
                  (+ new-indentation tab-width)))
 
-               ;; LINE AFTER CASE DEFINITION
-               ;; case true:
-               ;;     echo 'here';
-               ;; or
-               ;; case true;
-               ;;     echo 'here';
-               ;; or
-               ;; default:
-               ;;     echo 'here';
-               ;; or
-               ;; default;
-               ;;     echo 'here';
-               ((and
-                 (not
-                  (string-match-p
-                   "^[\t ]*\\(case[\t ]+\\|default\\)"
-                   current-line-string))
-                 (or
-                  (string-match-p
-                   "^[\t ]*case[\t ]+.*\\(;\\|:\\)[\t ]*$"
-                   previous-line-string)
-                  (string-match-p
-                   "^[\t ]*default.*\\(;\\|:\\)[\t ]*$"
-                   previous-line-string)))
-                (setq
-                 match-type
-                 'line-after-case-definition)
-                (setq
-                 new-indentation
-                 (+ new-indentation tab-width)))
-
                )
 
               (phps-mode-debug-message
diff --git a/test/phps-mode-test-indent.el b/test/phps-mode-test-indent.el
index dbee99a611..769e382c5c 100644
--- a/test/phps-mode-test-indent.el
+++ b/test/phps-mode-test-indent.el
@@ -796,6 +796,10 @@
    "<?php\nenum Suit\n{\n    case Hearts;\n    case Diamonds;\n    case 
Clubs;\n    case Spades;\n}"
    "Basic Enumeration")
 
+  (phps-mode-test-indent--should-equal
+   "<?php\nswitch($case) {\n    case 1;\n        echo 'here';\n}\n"
+   "Switch case statement with semicolon")
+
   )
 
 (defun phps-mode-test-indent--get-lines-indent-psr-2 ()



reply via email to

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