[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 1a62f48783 130/212: Improved indentation in c
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode 1a62f48783 130/212: Improved indentation in cases with multi-expressions last line does not start with closing bracket |
Date: |
Wed, 26 Jan 2022 01:51:12 -0500 (EST) |
branch: externals/phps-mode
commit 1a62f48783bd16814ba5c13efd1457df2022ee66
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
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 ()
- [elpa] externals/phps-mode b469f0ffbb 088/212: Passing indentation for multi-line class implements, (continued)
- [elpa] externals/phps-mode b469f0ffbb 088/212: Passing indentation for multi-line class implements, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode f69df4fdf6 083/212: Moved indentation to separate file and test, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 481deb6331 082/212: More work on indentation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode fe9cb90c44 097/212: Passing indent test for some multi-line assignments, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode c9f715a1fd 093/212: Improved comments, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode f0ab7a2cdb 095/212: Passed tests for inline control structures, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 08f57c1d36 107/212: Added TODO item for indent, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 3853ddf32a 099/212: Passed another concatenation test for indentation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 1ed09d42f5 111/212: Passing another indent test, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode d205d8392f 113/212: Passed another indent test, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 1a62f48783 130/212: Improved indentation in cases with multi-expressions last line does not start with closing bracket,
Christian Johansson <=
- [elpa] externals/phps-mode a3b9559880 121/212: Improved indent support for nested switch case, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode b4bf3caeb3 118/212: Added TODO note, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode b9956e278f 120/212: Indent support for closing bracket after closing multi-line assignment, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 4b4a821e6e 115/212: Started refactor of indent code, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 20ad1fae08 132/212: Improved indentation arround multi-line object operators, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 5f09905a1a 126/212: Fixed issue with bookkeeping and imenu not being stored, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode dc361309e0 124/212: Passing all indentation tests, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode a62e6be40e 133/212: Fixed indentation on line after print_r, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 5391551287 143/212: Added a new indent test and made it pass, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode ffda8f1b5c 128/212: Added TODO item, Christian Johansson, 2022/01/26