[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode fe9cb90c44 097/212: Passing indent test for s
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode fe9cb90c44 097/212: Passing indent test for some multi-line assignments |
Date: |
Wed, 26 Jan 2022 01:51:01 -0500 (EST) |
branch: externals/phps-mode
commit fe9cb90c441d975f917b58a4d848072597fb74fb
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Passing indent test for some multi-line assignments
---
phps-mode-indent.el | 52 +++++++++++++++++++++++++++++++++++++++++++
test/phps-mode-test-indent.el | 20 ++++++++---------
2 files changed, 62 insertions(+), 10 deletions(-)
diff --git a/phps-mode-indent.el b/phps-mode-indent.el
index edb3978a0c..32ad502648 100644
--- a/phps-mode-indent.el
+++ b/phps-mode-indent.el
@@ -371,6 +371,58 @@
)
+ (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))
+
+ ;; Try to backtrack buffer until we reach start of bracket
+ (while
+ (and
+ still-looking
+ (search-backward-regexp
+ "\\((\\|]\\|\\[\\|)\\)" nil t))
+ (let ((match-string (match-string-no-properties 0)))
+ (cond
+ ((or
+ (string= match-string "(")
+ (string= match-string "["))
+ (setq bracket-count (1+ bracket-count)))
+ ((or
+ (string= match-string ")")
+ (string= match-string "]"))
+ (setq bracket-count (1- bracket-count)))))
+ (when (= bracket-count 0)
+ (setq still-looking nil)))
+
+ ;; Did we find bracket start line?
+ (unless still-looking
+ (let ((bracket-start-indentation
+ (phps-mode-indent--string-indentation
+ (buffer-substring-no-properties
+ (line-beginning-position)
+ (line-end-position)))))
+ ;; Use its indentation for this line as well
+ (setq new-indentation bracket-start-indentation)))
+
+ ;; 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 9d4eaff741..cff7c9be2e 100644
--- a/test/phps-mode-test-indent.el
+++ b/test/phps-mode-test-indent.el
@@ -317,11 +317,19 @@
(phps-mode-test-indent--should-equal
"<?php\n$variable = array(\n 'random4'\n);\n$variable = true;\n"
- "Array assignment on three lines")
+ "Array assignment on three lines without trailing comma")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n$variable = array(\n 'random4',\n);\n$variable = true;\n"
+ "Array assignment on three lines with trailing comma")
(phps-mode-test-indent--should-equal
"<?php\n$variable = array(\n 'random4' =>\n 'hello'\n);"
- "Array assignment with double arrow elements on four lines")
+ "Array assignment with double arrow elements on four lines without trailing
comma")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n$variable = array(\n 'random4' =>\n 'hello',\n);"
+ "Array assignment with double arrow elements on four lines with trailing
comma")
(phps-mode-test-indent--should-equal
"<?php\n$variable = array(\n 'random4');\n$variable = true;\n"
@@ -393,14 +401,6 @@
"<?php\nforeach ($array as $value):\n echo 'Something';\n echo
'Something';\nendforeach;\necho 'Something else';\n"
"Alternative control structures basic foreach-endforeach flow")
- (phps-mode-test-indent--should-equal
- "<?php\nif (true):\n echo 'Something';\nelseif (true\n && true\n):\n
echo 'Something';\nelse:\n echo 'Something else';\n echo 'Something
else again';\nendif;\necho true;\n"
- "Alternative control structures with multi-line elseif 1")
-
- (phps-mode-test-indent--should-equal
- "<?php\nif (true):\n echo 'Something';\nelseif (true\n && true):\n
echo 'Something';\nelse:\n echo 'Something else';\n echo 'Something else
again';\nendif;\necho true;\n"
- "Alternative control structures with multi-line elseif 2")
-
)
(defun phps-mode-test-indent--get-lines-indent-classes ()
- [elpa] externals/phps-mode e66abd00e5 064/212: Bookkeeping via AST passing nested isset() !empty() expressions, (continued)
- [elpa] externals/phps-mode e66abd00e5 064/212: Bookkeeping via AST passing nested isset() !empty() expressions, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 8b5ce22d87 072/212: Fixed issue with SDT for return statement, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 491c82a2a1 071/212: Added TODO item for bookkeeping via AST, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 5ec32f5f5a 076/212: Bookkeeping via AST passing all tests, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 228f212127 080/212: Starting on removing the old process tokens in string function, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 5b1f5b4774 079/212: Improved format of SDT, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 3f3a8bb0fa 081/212: Major refactor of indent tests, Christian Johansson, 2022/01/26
- [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 <=
- [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, 2022/01/26
- [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