branch: externals/phps-mode
commit 1a62f48783bd16814ba5c13efd1457df2022ee66
Author: Christian Johansson <[email protected]>
Commit: Christian Johansson <[email protected]>
Improved indentation in cases with multi-expressions last line does not
start with closing bracket
---
phps-mode-indent.el | 19 ++++++++++++++-----
test/phps-mode-test-indent.el | 16 ++++++++++++++++
2 files changed, 30 insertions(+), 5 deletions(-)
diff --git a/phps-mode-indent.el b/phps-mode-indent.el
index 7bf729de48..4d5441e765 100644
--- a/phps-mode-indent.el
+++ b/phps-mode-indent.el
@@ -196,8 +196,6 @@
(1+ move-length)))))
(goto-char point)
- ;; TODO Need to fix issue were indentation differs if you are at the
start or end of current line
-
(if previous-line-is-empty-p
(indent-line-to
(phps-mode-indent--string-indentation
@@ -845,6 +843,14 @@
;; OKASDOKASD
;; EOD;
;; echo 'here';
+ ;; or
+ ;; $var = myFunction(
+ ;; 'expression');
+ ;; echo 'here';
+ ;; or
+ ;; return myFunction(
+ ;; 'expression');
+ ;; echo 'here';
((and
previous-line-ends-with-terminus
(string= previous-line-ends-with-terminus ";")
@@ -871,7 +877,7 @@
(and
not-found
(search-backward-regexp
- "\\(;\\|{\\|(\\|)\\|=$\\|=[^>]\\|echo[\t ]+\\|print[\t
]+\\|\n\\|<<<'?\"?[a-zA-Z0-9]+'?\"?\\)"
+ "\\(;\\|{\\|(\\|)\\|=$\\|=[^>]\\|return\\|echo[\t
]+\\|print[\t ]+\\|\n\\|<<<'?\"?[a-zA-Z0-9]+'?\"?\\)"
nil
t))
(let ((match (match-string-no-properties 0)))
@@ -899,7 +905,7 @@
(setq is-assignment (string-match-p "=" match))
(setq is-bracket-less-command
(string-match-p
- "\\(echo[\t ]+\\|print[\t ]+\\)"
+ "\\(echo[\t ]+\\|print[\t ]+\\|return[\t ]+\\)"
match))
(setq not-found nil)))))
@@ -959,12 +965,15 @@
;; echo 'here';
;; NOTE stuff like $var = array(\n 4\n);\n
;; will end assignment but also decrease
previous-bracket-level
+ ;; NOTE but cases like $var = array(\n 4);\n should pass
(when (and
(not is-same-line-p)
(or
(and
is-assignment
- (not bracket-opened-on-first-line))
+ (or
+ (not bracket-opened-on-first-line)
+ (not previous-line-starts-with-closing-bracket)))
is-bracket-less-command))
(setq
new-indentation
diff --git a/test/phps-mode-test-indent.el b/test/phps-mode-test-indent.el
index de45caa306..fc2d2ce036 100644
--- a/test/phps-mode-test-indent.el
+++ b/test/phps-mode-test-indent.el
@@ -228,6 +228,22 @@
"<?php
\n\nif (true) {\n // Was here\n}"
"If condition after a mixed newline encoded file")
+ (phps-mode-test-indent--should-equal
+ "<?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"
+ "Tested chaining of object")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n\nif ($there) {\n if ($something) {\n $var = [\n
[\n [\n 'abc' => 1,\n
'def' => 2,\n ]\n ]\n ];\n }\n}\n"
+ "Nested array with square bracket syntax")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n\nclass MyClass\n{\n function myFunction1()\n {\n
return tester(\n '123');\n }\n function myFunction2()\n {\n
return (count(self::$stuff) > 0 ?\n self::$stuff : false);\n
}\n}\n"
+ "Return statements in class")
+
+ (phps-mode-test-indent--should-equal
+ "$var = myFunction(\n 'setting');\necho 'here';\n"
+ "Multi-line assignment from function ending without opening bracket")
+
)
(defun phps-mode-test-indent--get-lines-indent-psr-2 ()