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

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

[elpa] externals/phps-mode 781356557c 194/212: More adjustments to inden


From: Christian Johansson
Subject: [elpa] externals/phps-mode 781356557c 194/212: More adjustments to indent helper to find previous command
Date: Wed, 26 Jan 2022 01:51:26 -0500 (EST)

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

    More adjustments to indent helper to find previous command
---
 phps-mode-indent.el           | 54 +++++++++++++++++++++++++------------------
 test/phps-mode-test-indent.el | 12 ++++++++++
 2 files changed, 44 insertions(+), 22 deletions(-)

diff --git a/phps-mode-indent.el b/phps-mode-indent.el
index 374313fa40..d9d2c4697d 100644
--- a/phps-mode-indent.el
+++ b/phps-mode-indent.el
@@ -320,6 +320,7 @@
             nil
             t))
         (let ((match (match-string-no-properties 0)))
+          ;; (message "match: %S" match)
           (cond
 
            ;; Commented out line
@@ -353,32 +354,41 @@
               (line-beginning-position)
               (line-end-position))))
 
+           ;; A closing curly bracket is indicate of a distinct command
+           ((string-match-p
+             "}[\t ]*$"
+             match)
+            (when found-semi-colon
+              (setq
+               not-found
+               nil)))
+
            ;; A second semi-colon is always a indicator of
            ;; a end of a previous command
            ;; Some keywords always indicate a start of command
            ((string-match-p
-             "\\;[\t ]*$"
+             ";[\t ]*$"
              match)
-            (let ((is-statement
-                   (string-match-p
-                    "^[\t 
]*\\(endswitch\\|endforeach\\|endwhile\\|exit\\|die\\|echo[\t ]+.*\\)[\t ]*;$"
-                    (buffer-substring-no-properties
-                     (line-beginning-position)
-                     (line-end-position)))))
-              (if is-statement
-                  (progn
-                    (setq
-                     not-found
-                     nil)
-                    (setq
-                     reference-line
-                     (buffer-substring-no-properties
-                      (line-beginning-position)
-                      (line-end-position))))
-                (if found-semi-colon
-                    (setq
-                     not-found
-                     nil)
+            (if found-semi-colon
+                (setq
+                 not-found
+                 nil)
+              (let ((is-statement
+                     (string-match-p
+                      "^[\t 
]*\\(endswitch\\|endforeach\\|endwhile\\|exit\\|die\\|echo[\t ]+.*\\)[\t ]*;$"
+                      (buffer-substring-no-properties
+                       (line-beginning-position)
+                       (line-end-position)))))
+                (if is-statement
+                    (progn
+                      (setq
+                       not-found
+                       nil)
+                      (setq
+                       reference-line
+                       (buffer-substring-no-properties
+                        (line-beginning-position)
+                        (line-end-position))))
                   (setq
                    reference-line
                    (buffer-substring-no-properties
@@ -1080,7 +1090,7 @@
                 (setq
                  match-type
                  'line-after-line-that-ends-with-semicolon)
-                (end-of-line)
+                (beginning-of-line)
 
                 (when-let
                     ((reference-line
diff --git a/test/phps-mode-test-indent.el b/test/phps-mode-test-indent.el
index 33e7d39f61..fdb71bf3c6 100644
--- a/test/phps-mode-test-indent.el
+++ b/test/phps-mode-test-indent.el
@@ -149,6 +149,14 @@
       (phps-mode-indent--get-previous-reference-command-line)
       "    endswitch;")))
 
+  (with-temp-buffer
+    (insert "<?php\nif (!defined('VARIABLE')) {\n    
exit;\n}\n\nrequire_once(CONSTANT . 'path');\n$variable = myFunction1(\n    
'argument1',\n    'argument2'\n);\n")
+    (goto-char 92)
+    (should
+     (string=
+      (phps-mode-indent--get-previous-reference-command-line)
+      "require_once(CONSTANT . 'path');")))
+
   (with-temp-buffer
     (insert "<?php\nif (true) {\n    array(\n        8,\n    );")
     (goto-char (point-max))
@@ -545,6 +553,10 @@
    "<?php\nif ($random) {\n    if ($random) {\n        if ($random) {\n        
}\n    }\n    apply_filters(\n        'my_filter',\n        $random\n    );\n   
 return $random;\n}\n"
    "Line after line that ends a multi-line function call")
 
+  (phps-mode-test-indent--should-equal
+   "<?php\n\nif (!defined('VARIABLE')) {\n    
exit;\n}\n\nrequire_once(CONSTANT . 'path');\n$variable = myFunction1(\n    
'argument1',\n    'argument2'\n);\n\nif (is_logged_in()) {\n    $variable = 
myFunction2(\n        'argument1',\n        'argument2'\n    );\n    
require_once(CONSTANT . 'string');\n}\n"
+   "Mixed expressions and statements")
+
   )
 
 (defun phps-mode-test-indent--get-lines-indent-psr-2 ()



reply via email to

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