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

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

[elpa] externals/phps-mode 2e16122284 153/212: Improved indentation on l


From: Christian Johansson
Subject: [elpa] externals/phps-mode 2e16122284 153/212: Improved indentation on line after closing bracket and comma
Date: Wed, 26 Jan 2022 01:51:17 -0500 (EST)

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

    Improved indentation on line after closing bracket and comma
---
 phps-mode-indent.el           | 55 ++++++++++++++++++++++++++++++-------------
 test/phps-mode-test-indent.el |  4 ++++
 2 files changed, 42 insertions(+), 17 deletions(-)

diff --git a/phps-mode-indent.el b/phps-mode-indent.el
index 7415e78641..9286b0568a 100644
--- a/phps-mode-indent.el
+++ b/phps-mode-indent.el
@@ -1045,6 +1045,10 @@
                ;;         '25'
                ;;     ],
                ;;     25
+               ;; or
+               ;; if (myFunction(
+               ;;     random(),
+               ;;     heredom(),
                ((string-match-p
                  "[])][\t ]*,[\t ]*\\(\\?>[\t\n ]*\\)?$"
                  previous-line-string)
@@ -1056,12 +1060,13 @@
                 (search-backward-regexp "," nil t) ;; Skip trailing comma
                 (let ((not-found-bracket-start t)
                       (reference-line)
-                      (parenthesis-level 1))
+                      (found-colon)
+                      (parenthesis-level 0))
                   (while
                       (and
                        not-found-bracket-start
                        (search-backward-regexp
-                        "\\()[][(),]\\|=>\\)"
+                        "\\([][(),]\\|=>\\)"
                         nil
                         t))
                     (let ((match (match-string-no-properties 0)))
@@ -1073,7 +1078,9 @@
                         (setq
                          parenthesis-level
                          (1+ parenthesis-level))
-                        (when (= parenthesis-level 0)
+                        (when (and
+                               (= parenthesis-level 1)
+                               found-colon)
                           (setq
                            not-found-bracket-start
                            nil)))
@@ -1083,28 +1090,42 @@
                          (string= "]" match))
                         (setq
                          parenthesis-level
-                         (1- parenthesis-level))
+                         (1- parenthesis-level)))
+
+                       ;; The second occurence of a colon
+                       ;; is a significant marker of
+                       ;; a starting bracket row
+                       ((string= "," match)
                         (when (= parenthesis-level 0)
-                          (setq
-                           not-found-bracket-start
-                           nil)))
+                          (if found-colon
+                              (setq
+                               not-found-bracket-start
+                               nil)
+                            (setq
+                             found-colon
+                             t)
+                            (setq
+                             reference-line
+                             (buffer-substring-no-properties
+                              (line-beginning-position)
+                              (line-end-position))))))
 
-                       (t
-                        (when (= parenthesis-level 1)
+                       ;; The first occurrence of a =>
+                       ;; is a significant marker of
+                       ;; a starting bracket row
+                       ((string= "=>" match)
+                        (when (= parenthesis-level 0)
+                          (setq
+                           reference-line
+                           (buffer-substring-no-properties
+                            (line-beginning-position)
+                            (line-end-position)))
                           (setq
                            not-found-bracket-start
                            nil)))
 
                        )))
 
-                  ;; Found line were bracket started?
-                  (unless not-found-bracket-start
-                    (setq
-                     reference-line
-                     (buffer-substring-no-properties
-                      (line-beginning-position)
-                      (line-end-position))))
-
                   (when reference-line
                     ;; (message "reference-line-2: %S" reference-line)
                     (setq
diff --git a/test/phps-mode-test-indent.el b/test/phps-mode-test-indent.el
index df03474b0d..084307093e 100644
--- a/test/phps-mode-test-indent.el
+++ b/test/phps-mode-test-indent.el
@@ -352,6 +352,10 @@
      "<?php\nclass MyClass\n{\n    public function getOperators()\n    {\n     
   return array(\n            '' => __(\n                'None',\n              
  'domain'\n            ),\n            '-' => __(\n                
'Subtraction',\n                'domain'\n            ),\n            '+' => 
__(\n                'Addition',\n                'domain'\n            ),\n    
    );\n    }\n}\n"
      "Method that returns multi-line array")
 
+    (phps-mode-test-indent--should-equal
+     "<?php\nfunction myFunction()\n{\n    if (!isset($randomize)) {\n        
if (true) {\n            throw new \Exception(sprintf(\n                __(\n   
                 'Library not found at %s',\n                    'domain'\n     
           ),\n                $path\n            ));\n        }\n    }\n    
return false;\n}\n"
+     "Multi-line throw statement")
+
   )
 
 (defun phps-mode-test-indent--get-lines-indent-psr-2 ()



reply via email to

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