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

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

[elpa] externals/phps-mode 3853ddf32a 099/212: Passed another concatenat


From: Christian Johansson
Subject: [elpa] externals/phps-mode 3853ddf32a 099/212: Passed another concatenation test for indentation
Date: Wed, 26 Jan 2022 01:51:01 -0500 (EST)

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

    Passed another concatenation test for indentation
---
 phps-mode-indent.el           | 103 +++++++++++++++++++++++++++++++++++++-----
 test/phps-mode-test-indent.el |  28 +++++++++---
 2 files changed, 113 insertions(+), 18 deletions(-)

diff --git a/phps-mode-indent.el b/phps-mode-indent.el
index 32ad502648..e6e228eee2 100644
--- a/phps-mode-indent.el
+++ b/phps-mode-indent.el
@@ -85,7 +85,7 @@
   "If STRING end with closing bracket, return it, otherwise nil."
   (phps-mode-indent--string-ends-with-regexp
    string
-   "\\([\]})[]\\)[\t ]*"))
+   "\\([\]})]\\)[\t ]*"))
 
 (defun phps-mode-indent--string-ends-with-opening-bracket (string)
   "If STRING end with opening bracket, return it, otherwise nil."
@@ -131,7 +131,7 @@
 
           ;; (message "\nCurrent line: %S" current-line-string)
 
-          ;; TODO Try to find previous 2 non-empty lines
+          ;; Try to find previous 2 non-empty lines
           (let ((line-is-empty-p t)
                 (searching-previous-lines 2))
             (while (and
@@ -371,20 +371,19 @@
 
                 )
 
+              ;; $variable = array(
+              ;;     'random' =>
+              ;;         'hello'
+              ;; );
+              ;; or
+              ;; $variable = [
+              ;;     'random' =>
+              ;;         'hello'
+              ;; ];
               (when
                   (string-match-p
                    "[\t ]*\\()\\|]\\);[\t ]*$"
                    current-line-string)
-
-                ;; $variable = array(
-                ;;     'random' =>
-                ;;         'hello'
-                ;; );
-                ;; or
-                ;; $variable = [
-                ;;     'random' =>
-                ;;         'hello'
-                ;; ];
                 (let ((old-point (point))
                       (still-looking t)
                       (bracket-count -1))
@@ -423,6 +422,86 @@
 
                 )
 
+              ;; echo 'Something'
+              ;;     . 'more';
+              ;; or
+              ;; echo 'Something' .
+              ;;     'more';
+              (when (or
+                     (string-match-p
+                      "^[\t ]*\\."
+                      current-line-string)
+                     (string-match-p
+                      "\\.[\t ]*$"
+                      previous-line-string))
+
+                ;; If previous line matched ending .
+                ;; we must backtrack at least two lines
+                ;; to find a good reference indentation
+                (let ((old-point (point))
+                      (match-string)
+                      (previous-concatenation)
+                      (keep-searching 1)
+                      (concat-was-trailing-p
+                       (string-match-p
+                        "\\.[\t ]*$"
+                        previous-line-string))
+                      (previous-concatenation2))
+                  (when concat-was-trailing-p
+                    (setq
+                     keep-searching
+                     2))
+                  (while keep-searching
+                    (let ((previous-expression
+                           (search-backward-regexp
+                            "\\(^[\t ]*\\.\\|\\.[\t ]*$\\|[{}=;]\\)" nil t)))
+                      (if previous-expression
+                          (progn
+                            (setq
+                             match-string
+                             (match-string-no-properties 0))
+                            (if (string-match-p
+                                 "[{}=;]"
+                                 match-string)
+                                (setq
+                                 keep-searching
+                                 nil)
+                              (setq
+                               keep-searching
+                               (1- keep-searching))
+                              (when (= keep-searching 0)
+                                (setq
+                                 keep-searching
+                                 nil)
+                                (when concat-was-trailing-p
+                                  (goto-char previous-concatenation2))
+                                (setq
+                                 previous-concatenation
+                                 match-string))
+                              (setq
+                               previous-concatenation2
+                               (point))))
+                        keep-searching
+                        nil)))
+
+                  (if previous-concatenation
+                      (let ((first-concatenated-line-indent
+                             (phps-mode-indent--string-indentation
+                              (buffer-substring-no-properties
+                               (line-beginning-position)
+                               (line-end-position)))))
+                        ;; We use previous concatenated lines indent
+                        (setq
+                         new-indentation
+                         first-concatenated-line-indent))
+                    ;; This is the first concatenated line so we indent it
+                    (setq
+                     new-indentation
+                     (+ new-indentation tab-width)))
+
+                  ;; Reset point
+                  (goto-char old-point)))
+
               (when (> previous-bracket-level 0)
                 (if (< previous-bracket-level tab-width)
                     (setq new-indentation (+ new-indentation 1))
diff --git a/test/phps-mode-test-indent.el b/test/phps-mode-test-indent.el
index 90667c7f3f..b0daebc4f2 100644
--- a/test/phps-mode-test-indent.el
+++ b/test/phps-mode-test-indent.el
@@ -348,19 +348,35 @@
    "Array assignment with double arrow elements on four lines with trailing 
comma #2")
 
   (phps-mode-test-indent--should-equal
-   "<?php\n$variable = array(\n    'random4');\n$variable = true;\n"
-   "Array assignment on two lines")
+   "<?php\n$var = 'A line' \n    . 'last line here';\necho 'was here';"
+   "Concatenated single-quoted-string multiple-lines in assignment")
 
   (phps-mode-test-indent--should-equal
-   "<?php\n$var = 'A line' .\n    'more text here' .\n    'last line here';"
-   "Concatenated single-quoted-string multiple-lines in assignment")
+   "<?php\n$var = 'A line' .\n    'last line here';\necho 'was here';"
+   "Concatenated single-quoted-string multiple-lines in assignment #2")
+
+  (phps-mode-test-indent--should-equal
+   "<?php\n$var = 'A line' \n    . 'more text here'\n    . 'last line 
here';\necho 'was here';"
+   "Concatenated single-quoted-string multiple-lines in assignment #3")
+
+  (phps-mode-test-indent--should-equal
+   "<?php\n$var = 'A line' .\n    'more text here' .\n    'last line 
here';\necho 'was here';"
+   "Concatenated single-quoted-string multiple-lines in assignment #4")
+
+  (phps-mode-test-indent--should-equal
+   "<?php\n$var = 'A line' \n    . 'more text here'\n    . 'even more text'\n  
  . 'last line here';\necho 'was here';"
+   "Concatenated single-quoted-string multiple-lines in assignment #5")
+
+  (phps-mode-test-indent--should-equal
+   "<?php\n$var = 'A line' .\n    'more text here' .\n    'even more text' .\n 
   'last line here';\necho 'was here';"
+   "Concatenated single-quoted-string multiple-lines in assignment #6")
 
   (phps-mode-test-indent--should-equal
-   "<?php\n$var .=\n    'A line';"
+   "<?php\n$var .=\n    'A line';\necho 'was here';"
    "Concatenated equal single-quoted-string on multiple-lines in assignment")
 
   (phps-mode-test-indent--should-equal
-   "<?php\n$var *=\n    25;"
+   "<?php\n$var *=\n    25;\necho 'was here';"
    "Multiplication equal assignment on multiple-lines")
 
   (phps-mode-test-indent--should-equal



reply via email to

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