[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 0c9d4d7fe9 08/15: Passing test for indenting
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode 0c9d4d7fe9 08/15: Passing test for indenting multi-line chaining expressions |
Date: |
Fri, 4 Mar 2022 14:13:03 -0500 (EST) |
branch: externals/phps-mode
commit 0c9d4d7fe94c9459c1e28f634cf783de07dc432d
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Passing test for indenting multi-line chaining expressions
---
TODO.md | 25 +------------
phps-mode-indent.el | 81 +++++++++++++++++++++++++++++++++++++------
test/phps-mode-test-indent.el | 56 ++++++++++++++++++++++++++++--
3 files changed, 125 insertions(+), 37 deletions(-)
diff --git a/TODO.md b/TODO.md
index e5f36d9383..ebc8a95cac 100644
--- a/TODO.md
+++ b/TODO.md
@@ -2,30 +2,7 @@
## Indentation
-* Case 1
-
-```php
-<?php
-if (true) {
- $table = $installer->getConnection()
- ->newTable($installer->getTable('my_table'))
- ->addColumn();
-}
-```
-
-* Case 2
-
-```php
-<?php
-if (true) {
- $criteria = $this->searchCriteriaBuilder
- ->addFilter('status', $status)
- ->addFilter(method', 'my_method_' . $object->getId())
- ->create();
-}
-```
-
-* Case 3
+* Case
```php
<?php
diff --git a/phps-mode-indent.el b/phps-mode-indent.el
index 44821bb110..2fc87c2ca5 100644
--- a/phps-mode-indent.el
+++ b/phps-mode-indent.el
@@ -373,34 +373,70 @@
(end-of-line)
(let ((not-found-bracket-start t)
(parenthesis-level 0)
+ (string-concatenation)
+ (found-chain-on-this-line)
+ (reference-line-previous)
+ (reference-line-delta)
+ (reference-line-previous-delta)
+ (line-delta 0)
(same-line-p t)
- (found-chain-on-this-line))
+ (rewind-reference-line))
(while
(and
not-found-bracket-start
(search-backward-regexp
- "\\([][{}()=\n]\\|->\\)"
+ "\\([][{}()=\n;]\\|->\\|^[\ t]*\\.\\|\\.[\t ]*$\\)"
nil
t))
(let ((match (match-string-no-properties 0)))
- ;; (message "match: %S" match)
(cond
+ ((string-match-p
+ "\\(^[\ t]*\\.\\|\\.[\t ]*$\\)"
+ match)
+ (setq
+ string-concatenation
+ t)
+ (setq
+ not-found-bracket-start
+ nil))
+
((string= "\n" match)
+ (setq
+ same-line-p
+ nil)
(if found-chain-on-this-line
(progn
+ (setq
+ reference-line-previous
+ reference-line)
+ (setq
+ reference-line-previous-delta
+ reference-line-delta)
(setq
reference-line
found-chain-on-this-line)
(setq
found-chain-on-this-line
- nil))
+ 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))
(setq
- same-line-p
- nil))
+ line-delta
+ (1- line-delta)))
((string= "->" match)
(setq
@@ -409,7 +445,11 @@
(line-beginning-position)
(line-end-position))))
- ((string= "=" match)
+ ((or
+ (string= "=" match)
+ (and
+ (not same-line-p)
+ (string= ";" match)))
(setq
not-found-bracket-start
nil))
@@ -422,6 +462,12 @@
parenthesis-level
(1+ parenthesis-level))
(when (= parenthesis-level 1)
+ (setq
+ rewind-reference-line
+ t)
+ (setq
+ line-delta
+ (1+ line-delta))
(setq
not-found-bracket-start
nil)))
@@ -435,10 +481,23 @@
(1- parenthesis-level)))
)))
- (message "reference-line: %S" reference-line)
- (if same-line-p
- nil
- reference-line)))))
+
+ (when (or
+ rewind-reference-line
+ not-found-bracket-start)
+ (setq
+ reference-line
+ reference-line-previous)
+ (setq
+ reference-line-delta
+ reference-line-previous-delta))
+
+ (if (and
+ reference-line
+ reference-line-delta
+ (not (= reference-line-delta 0)))
+ reference-line
+ nil)))))
(defun phps-mode-indent--get-previous-reference-command-line ()
"Get previous line that is a command (if any)."
diff --git a/test/phps-mode-test-indent.el b/test/phps-mode-test-indent.el
index 8f86925124..d899b065ce 100644
--- a/test/phps-mode-test-indent.el
+++ b/test/phps-mode-test-indent.el
@@ -221,13 +221,17 @@
(phps-mode-indent--get-previous-start-of-chaining)
" ->newTable($installer->getTable('my_table'))")))
+ (message "Passed chaining test #1")
+
(with-temp-buffer
(insert "<?php\nif (true) {\n $table = $installer->getConnection()\n
->newTable($installer->getTable('my_table'))\n ->addColumn();\n}\n")
(goto-char 73)
(should
(equal
(phps-mode-indent--get-previous-start-of-chaining)
- " ->newTable($installer->getTable('my_table'))")))
+ nil)))
+
+ (message "Passed chaining test #2")
(with-temp-buffer
(insert "<?php\nif (true) {\n $criteria =
$this->searchCriteriaBuilder\n ->addFilter('status', $status)\n
->addFilter(method', 'my_method_' . $object->getId())\n
->create();\n}\n")
@@ -237,6 +241,8 @@
(phps-mode-indent--get-previous-start-of-chaining)
" ->addFilter('status', $status)")))
+ (message "Passed chaining test #3")
+
(with-temp-buffer
(insert "<?php\nif (true) {\n $criteria =
$this->searchCriteriaBuilder\n ->addFilter('status', $status)\n
->addFilter(method', 'my_method_' . $object->getId())\n
->create();\n}\n")
(goto-char 135)
@@ -245,13 +251,17 @@
(phps-mode-indent--get-previous-start-of-chaining)
" ->addFilter('status', $status)")))
+ (message "Passed chaining test #4")
+
(with-temp-buffer
(insert "<?php\nif (true) {\n $criteria =
$this->searchCriteriaBuilder\n ->addFilter('status', $status)\n
->addFilter(method', 'my_method_' . $object->getId())\n
->create();\n}\n")
(goto-char 96)
(should
(equal
(phps-mode-indent--get-previous-start-of-chaining)
- " ->addFilter('status', $status)")))
+ nil)))
+
+ (message "Passed chaining test #5")
(with-temp-buffer
(insert "<?php\nif (true) {\n $criteria =
$this->searchCriteriaBuilder\n ->addFilter('status', $status)\n
->addFilter(method', 'my_method_' . $object->getId())\n
->create();\n}\n")
@@ -261,6 +271,48 @@
(phps-mode-indent--get-previous-start-of-chaining)
nil)))
+ (message "Passed chaining test #6")
+
+ (with-temp-buffer
+ (insert "<?php\n$var = 500 .\n \"200\" .\n 100.0 .\n '200' .\n
$this->getTail()\n ->getBottom();")
+ (goto-char 90)
+ (should
+ (equal
+ (phps-mode-indent--get-previous-start-of-chaining)
+ " $this->getTail()")))
+
+ (message "Passed chaining test #7")
+
+ (with-temp-buffer
+ (insert "<?php\nif ($myCondition) {\n
$myObject->myMethod(myClass::class)\n ->myMethod2($myArgument2)\n
->myMethod3($myArgument3);\n}")
+ (goto-char 121)
+ (should
+ (equal
+ (phps-mode-indent--get-previous-start-of-chaining)
+ " ->myMethod2($myArgument2)")))
+
+ (message "Passed chaining test #8")
+
+ (with-temp-buffer
+ (insert "<?php\nif ($myCondition) {\n
$myObject->myMethod(myClass::class)\n ->myMethod2($myArgument2)\n
->myMethod3($myArgument3);\n}")
+ (goto-char 85)
+ (should
+ (equal
+ (phps-mode-indent--get-previous-start-of-chaining)
+ nil)))
+
+ (message "Passed chaining test #9")
+
+ (with-temp-buffer
+ (insert "<?php\n$myObject->myMethod(myClass::class)\n
->myMethod2($myArgument2)\n ->myMethod3($myArgument3);\n")
+ (goto-char 55)
+ (should
+ (equal
+ (phps-mode-indent--get-previous-start-of-chaining)
+ nil)))
+
+ (message "Passed chaining test #10")
+
(should
(equal
(phps-mode-indent--get-html-string-bracket-level "<!DOCTYPE html>")
- [elpa] externals/phps-mode updated (35870e4cb1 -> 3349852f21), Christian Johansson, 2022/03/04
- [elpa] externals/phps-mode f494fde442 06/15: Added TODO-item, Christian Johansson, 2022/03/04
- [elpa] externals/phps-mode 5fbc73bd43 01/15: Added TODO case, Christian Johansson, 2022/03/04
- [elpa] externals/phps-mode 027b102d71 04/15: Added failing indentation tests, Christian Johansson, 2022/03/04
- [elpa] externals/phps-mode b5f38a926f 05/15: More work on indentation around multi-line chained objects, Christian Johansson, 2022/03/04
- [elpa] externals/phps-mode 0c9d4d7fe9 08/15: Passing test for indenting multi-line chaining expressions,
Christian Johansson <=
- [elpa] externals/phps-mode fd36f650e6 10/15: Added TODO items, Christian Johansson, 2022/03/04
- [elpa] externals/phps-mode 67c3beb075 12/15: Added TODO item for failing indentation, Christian Johansson, 2022/03/04
- [elpa] externals/phps-mode f7f8ea26b1 02/15: Improved cache writing method, Christian Johansson, 2022/03/04
- [elpa] externals/phps-mode 9a852fd48e 03/15: Added another failing indentation case, Christian Johansson, 2022/03/04
- [elpa] externals/phps-mode 8d77fbdfdb 13/15: Improved indentation around switch case branches, Christian Johansson, 2022/03/04
- [elpa] externals/phps-mode d1d1d4b9a7 14/15: Updated version and modified date, Christian Johansson, 2022/03/04
- [elpa] externals/phps-mode 9ac4797803 09/15: Passed indentation test for line after comment block, Christian Johansson, 2022/03/04
- [elpa] externals/phps-mode 5d420ba200 11/15: Formatted TODO-items better, Christian Johansson, 2022/03/04
- [elpa] externals/phps-mode 3349852f21 15/15: Added TODO item, Christian Johansson, 2022/03/04
- [elpa] externals/phps-mode f619fe6911 07/15: Started on helper function for calculating indentation for multi-line chaining expressions, Christian Johansson, 2022/03/04