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

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

[elpa] externals/phps-mode 64fdee739e 4/5: Fixed indetation for multi-li


From: Christian Johansson
Subject: [elpa] externals/phps-mode 64fdee739e 4/5: Fixed indetation for multi-line function calls with named arguments
Date: Thu, 28 Jul 2022 04:38:58 -0400 (EDT)

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

    Fixed indetation for multi-line function calls with named arguments
---
 TODO.md                       | 16 ----------------
 phps-mode-indent.el           | 31 +++++++++++++++++++++++++++----
 test/phps-mode-test-indent.el |  4 ++++
 3 files changed, 31 insertions(+), 20 deletions(-)

diff --git a/TODO.md b/TODO.md
index 8d5b2e1b6f..9dcd153a52 100644
--- a/TODO.md
+++ b/TODO.md
@@ -1,21 +1,5 @@
 # TODO
 
-## Indentation
-
-### Multi-line function call with named arguments
-
-function myFunction(
-    $arg1,
-    $arg2
-) {
-}
-myFunction(
-    arg1:
-    $var1,
-    arg2:
-    $var2,
-);
-
 
 ## Code intelligence
 
diff --git a/phps-mode-indent.el b/phps-mode-indent.el
index e8c1e4d11c..5b5edd8096 100644
--- a/phps-mode-indent.el
+++ b/phps-mode-indent.el
@@ -228,7 +228,7 @@
             (and
              not-found-bracket-start
              (search-backward-regexp
-              "\\([][{}(),]\\|=>\\)"
+              "\\([][{}(),:]\\|=>\\)"
               nil
               t))
           (let ((match (match-string-no-properties 0)))
@@ -285,10 +285,12 @@
                     (line-beginning-position)
                     (line-end-position))))))
 
-             ;; The first occurrence of a =>
+             ;; The first occurrence of a => or :
              ;; is a significant marker of
              ;; a starting bracket row
-             ((string= "=>" match)
+             ((or
+               (string= "=>" match)
+               (string= ":" match))
               (when (= parenthesis-level 0)
                 (setq
                  reference-line
@@ -537,7 +539,7 @@
               ")[\ t]*:[\t ]*$"
               match)
              (string-match-p
-              "[^:]:[\t ]*$"
+              "\\(case\\|default\\).*:[\t ]*$"
               match)) ;; Like case '50':
             (setq
              not-found
@@ -895,6 +897,20 @@
                  new-indentation
                  (+ new-indentation tab-width)))
 
+               ;; LINE AFTER FUNCTION CALL WITH NAMED ARGUMENT
+               ;; arg1:
+               ;;     $something
+               ((and
+                 (string-match-p
+                  "^[\t ]*[a-zA-Z0-9_]+[\t ]*:[\t ]*$"
+                  previous-line-string))
+                (setq
+                 match-type
+                 'line-after-function-call-with-named-argument)
+                (setq
+                 new-indentation
+                 (+ new-indentation tab-width)))
+
                ;; LINE AFTER INLINE OR ALTERNATIVE ELSE / ELSEIF CONTROL 
STRUCTURE
                ;; else
                ;;     echo 'Something';
@@ -1215,6 +1231,13 @@
                ;;     [
                ;;         2,
                ;;         3,
+               ;; or
+               ;; myFunction(
+               ;;     arg1:
+               ;;         $var1,
+               ;;     arg2:
+               ;;         $var2,
+               ;; );
                ((string-match-p
                  ",[\t ]*\\(\\?>[\t\n ]*\\)?$"
                  previous-line-string)
diff --git a/test/phps-mode-test-indent.el b/test/phps-mode-test-indent.el
index 769e382c5c..17ed0ac240 100644
--- a/test/phps-mode-test-indent.el
+++ b/test/phps-mode-test-indent.el
@@ -800,6 +800,10 @@
    "<?php\nswitch($case) {\n    case 1;\n        echo 'here';\n}\n"
    "Switch case statement with semicolon")
 
+  (phps-mode-test-indent--should-equal
+   "<?php\nfunction myFunction(\n    $arg1,\n    $arg2\n) {\n}\nmyFunction(\n  
  arg1: $var1,\n    arg2: $var2,\n);\nmyFunction(\n    arg1:\n        $var1,\n  
  arg2:\n        $var2,\n);\n"
+   "Multi-line function call with named arguments")
+
   )
 
 (defun phps-mode-test-indent--get-lines-indent-psr-2 ()



reply via email to

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