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

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

[elpa] externals/phps-mode c6e4deec40 4/9: Improved indentation for chai


From: Christian Johansson
Subject: [elpa] externals/phps-mode c6e4deec40 4/9: Improved indentation for chained expressions
Date: Mon, 15 Jan 2024 08:24:59 -0500 (EST)

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

    Improved indentation for chained expressions
---
 phps-mode-indent.el           | 27 ++++++++++++---------------
 test/phps-mode-test-indent.el | 18 ++++++++++++++----
 2 files changed, 26 insertions(+), 19 deletions(-)

diff --git a/phps-mode-indent.el b/phps-mode-indent.el
index 665cc9387b..9ce4595577 100644
--- a/phps-mode-indent.el
+++ b/phps-mode-indent.el
@@ -391,10 +391,11 @@ Optionally start FROM-END-OF-LINE."
             (and
              not-found-bracket-start
              (search-backward-regexp
-              "\\([][{}()=\n;]\\|->\\|^[\ t]*\\.\\|\\.[\t ]*$\\)"
+              "\\(=>\\|[][{}()=\n;]\\|->\\|^[\ t]*\\.\\|\\.[\t ]*$\\)"
               nil
               t))
           (let ((match (match-string-no-properties 0)))
+            ;; (message "match: %S" match)
             (cond
 
              ((string-match-p
@@ -404,7 +405,13 @@ Optionally start FROM-END-OF-LINE."
                not-found-bracket-start
                nil))
 
+             ((string= "=>" match))
+
              ((string= "\n" match)
+              (when (and
+                     same-line-p
+                     (> parenthesis-level 0))
+                (setq parenthesis-level 0))
               (setq
                same-line-p
                nil)
@@ -424,19 +431,7 @@ Optionally start FROM-END-OF-LINE."
                      nil)
                     (setq
                      reference-line-delta
-                     line-delta))
-                (setq
-                 reference-line
-                 nil)
-                (setq
-                 reference-line-delta
-                 nil)
-                (setq
-                 reference-line-previous
-                 nil)
-                (setq
-                 reference-line-previous-delta
-                 nil))
+                     line-delta)))
               (setq
                line-delta
                (1- line-delta)))
@@ -464,7 +459,9 @@ Optionally start FROM-END-OF-LINE."
               (setq
                parenthesis-level
                (1+ parenthesis-level))
-              (when (= parenthesis-level 1)
+              (when (and
+                     (not same-line-p)
+                     (= parenthesis-level 1))
                 (setq
                  rewind-reference-line
                  t)
diff --git a/test/phps-mode-test-indent.el b/test/phps-mode-test-indent.el
index f20ea2f876..4dd25a6104 100644
--- a/test/phps-mode-test-indent.el
+++ b/test/phps-mode-test-indent.el
@@ -325,6 +325,16 @@ STRING with NAME with optional NEW-STRING."
 
   (message "Passed chaining test #10")
 
+  (with-temp-buffer
+    (insert "<?php\n\nif ($you) {\n    if ($here) {\n        if ($true) {\n    
        if ($a = 23) {\n                $myObject->build(array(\n               
     'name' => 'Trueman',\n                    'sku' => 25.0\n                
))\n                ->test()\n                    ->validate()\n                
        ->give();\n            }\n        }\n    }\n}\n")
+    (goto-char 272)
+    (should
+     (equal
+      (phps-mode-indent--get-previous-start-of-chaining)
+      "                ->test()")))
+
+  (message "Passed chaining test #11")
+
   (should
    (equal
     (phps-mode-indent--get-html-string-bracket-level "<!DOCTYPE html>")
@@ -668,7 +678,7 @@ STRING with NAME with optional NEW-STRING."
    "Line after multi-line function call inside if condition list")
 
   (phps-mode-test-indent--should-equal
-   "<?php\n\nif (\n    (!isset(Meta()->login)\n        || !$name = 
Meta()->login->name())\n        && $override\n) {\n    echo 'here';\n}\n"
+   "<?php\n\nif (\n    (!isset(Meta()->login)\n        || !$name = 
Meta()->login->name())\n    && $override\n) {\n    echo 'here';\n}\n"
    "Line after multi-line condition in parenthesis")
 
   (phps-mode-test-indent--should-equal
@@ -676,7 +686,7 @@ STRING with NAME with optional NEW-STRING."
    "Line after variable not equal condition")
 
   (phps-mode-test-indent--should-equal
-   "<?php\n\nif (\n    (is_array($data)\n        && !empty($data['index'])\n   
     && (is_a($data['index'], 'Index')\n            || is_a($data['Index'], 
'Index2')))\n    || is_a($data, 'WC_Index')\n) {\n\n}\n"
+   "<?php\n\nif (\n    (is_array($data)\n        && !empty($data['index'])\n   
     && (is_a($data['index'], 'Index')\n            || is_a($data['Index'], 
'Index2')))\n    || is_a($data, 'WC_Index')\n) {\n    \n}\n"
    "Line after multi-line condition in parenthesis 2")
 
   (phps-mode-test-indent--should-equal
@@ -713,7 +723,7 @@ STRING with NAME with optional NEW-STRING."
    "<?php\nif (true) {\n    echo 'here';\n    /* something */\n    echo 
'there';\n}\n")
 
   (phps-mode-test-indent--should-equal
-   "<?php\nif (true) {\n    $variable1 = (true\n        ? true\n        : 
false);\n\n    $variable2 = (true\n        ? true\n        : false);\n\n    
$variable3 = myFunction(true);\n    echo 'here';\n\n}\n"
+   "<?php\nif (true) {\n    $variable1 = (true\n        ? true\n        : 
false);\n    \n    $variable2 = (true\n        ? true\n        : false);\n    
\n    $variable3 = myFunction(true);\n    echo 'here';\n    \n}\n"
    "Line after multi-line parenthesized logical expression in assignment")
 
   (phps-mode-test-indent--should-equal
@@ -757,7 +767,7 @@ STRING with NAME with optional NEW-STRING."
    "Plain HTML markup")
 
   (phps-mode-test-indent--should-equal
-   "<?php\n\nif (true) {\n    if (\n        true\n    ) {\n        return 
false;\n    }\n\n    /**\n     * My first line,\n     * my second line.\n     
*\n     * @since Module 1.0.0\n     */\n    echo 'here';\n\n}\n"
+   "<?php\n\nif (true) {\n    if (\n        true\n    ) {\n        return 
false;\n    }\n    \n    /**\n     * My first line,\n     * my second line.\n   
  *\n     * @since Module 1.0.0\n     */\n    echo 'here';\n    \n}\n"
    "Doc-comment ending with comma and dot.")
 
   (phps-mode-test-indent--should-equal



reply via email to

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