[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode cdbcd5ebe6 154/212: Added a new failing inden
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode cdbcd5ebe6 154/212: Added a new failing indent test and made it pass |
Date: |
Wed, 26 Jan 2022 01:51:18 -0500 (EST) |
branch: externals/phps-mode
commit cdbcd5ebe6e30f3d27e0f9d32a5d29107de142b0
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Added a new failing indent test and made it pass
---
phps-mode-indent.el | 211 ++++++++----------------------------------
test/phps-mode-test-indent.el | 4 +
2 files changed, 45 insertions(+), 170 deletions(-)
diff --git a/phps-mode-indent.el b/phps-mode-indent.el
index 9286b0568a..dad22b2b38 100644
--- a/phps-mode-indent.el
+++ b/phps-mode-indent.el
@@ -1049,8 +1049,21 @@
;; if (myFunction(
;; random(),
;; heredom(),
+ ;; or
+ ;; 'name' =>
+ ;; $myObject->getName(),
+ ;; 'age' =>
+ ;; or
+ ;; myFunction(
+ ;; 'my Argument',
+ ;; 'my second argument'
+ ;; or
+ ;; myFunction(
+ ;; [
+ ;; 2,
+ ;; 3,
((string-match-p
- "[])][\t ]*,[\t ]*\\(\\?>[\t\n ]*\\)?$"
+ ",[\t ]*\\(\\?>[\t\n ]*\\)?$"
previous-line-string)
;; Backtrack first to line were bracket started
@@ -1061,6 +1074,7 @@
(let ((not-found-bracket-start t)
(reference-line)
(found-colon)
+ (reference-line-started-bracket)
(parenthesis-level 0))
(while
(and
@@ -1078,9 +1092,16 @@
(setq
parenthesis-level
(1+ parenthesis-level))
- (when (and
- (= parenthesis-level 1)
- found-colon)
+ (when (= parenthesis-level 1)
+ (unless found-colon
+ (setq
+ reference-line-started-bracket
+ t)
+ (setq
+ reference-line
+ (buffer-substring-no-properties
+ (line-beginning-position)
+ (line-end-position))))
(setq
not-found-bracket-start
nil)))
@@ -1131,7 +1152,22 @@
(setq
new-indentation
(phps-mode-indent--string-indentation
- reference-line)))
+ reference-line))
+ (when reference-line-started-bracket
+ (let ((reference-bracket-level
+ (phps-mode-indent--get-string-brackets-count
+ reference-line)))
+ ;; (message "reference-bracket-level: %S"
reference-bracket-level)
+ ;; define('_PRIVATE_ROOT',
+ ;; 'here');
+ ;; or
+ ;; ['abc',
+ ;; 'def'];
+ (when (> reference-bracket-level 0)
+ (setq
+ new-indentation
+ (+ new-indentation tab-width)))))
+ )
(when current-line-starts-with-closing-bracket
(setq
@@ -1140,171 +1176,6 @@
(goto-char point))
- ;; 'name' =>
- ;; $myObject->getName(),
- ;; 'age' =>
- ;; or
- ;; myFunction(
- ;; 'my Argument',
- ;; 'my second argument'
- ;; or
- ;; myFunction(
- ;; [
- ;; 2,
- ;; 3,
- ((and
- previous-line-ends-with-terminus
- (string= previous-line-ends-with-terminus ","))
-
- ;; Back-trace buffer from previous line
- ;; Determine if comma was part of array or function argument
or bracket-less command
- ;; If it started on the same line we ignore it
- (forward-line (* -1 move-length1))
- (end-of-line)
- (search-backward-regexp "," nil t) ;; Skip the colon
-
- ;; (message
- ;; "at-line-start: %S"
- ;; (buffer-substring-no-properties
- ;; (line-beginning-position)
- ;; (line-end-position)))
-
- (let ((not-found t)
- (reference-line)
- (reference-indentation)
- (parenthesis-level 0)
- (is-declared-on-same-line-p)
- (is-same-line-p t))
- (while
- (and
- not-found
- (search-backward-regexp
- "\\([a-zA-Z_]+[a-zA-Z0-9_]*[\t
]*(\\|=>\\|,\\|[\])[]\\|\n\\)"
- nil
- t))
- (let ((match (match-string-no-properties 0)))
- (cond
-
- ((string= match "\n")
- (setq
- is-same-line-p
- nil))
-
- ((string-match-p
- "[a-zA-Z_]+[a-zA-Z0-9_]*[\t ]*("
- match)
- (setq
- parenthesis-level
- (1+ parenthesis-level))
- (when (= parenthesis-level 1)
- (setq
- is-declared-on-same-line-p
- is-same-line-p)
- (setq
- not-found
- nil)))
-
- ((string= match "[")
- (setq
- parenthesis-level
- (1+ parenthesis-level))
- (when (= parenthesis-level 1)
- (setq
- is-declared-on-same-line-p
- is-same-line-p)
- (setq
- not-found
- nil)))
-
- ((or
- (string= match ")")
- (string= match "]"))
- (setq
- parenthesis-level
- (1- parenthesis-level)))
-
- ((= parenthesis-level 0)
- (setq
- not-found
- nil)))))
-
- (unless not-found
- (setq
- reference-line
- (buffer-substring-no-properties
- (line-beginning-position)
- (line-end-position)))
-
- ;; sprintf(__(
- ;; 'Error %s', <-- use this indentation as reference
instead
- ;; $error
- ;; but ignore
- ;; return array(
- ;; '' => __(
- ;; 'None',
- ;; 'domain'
- ;; ),
- ;; '-' =>
- (when (and
- (not is-same-line-p)
- (string-match-p
- "[[(][\t ]*$"
- reference-line))
- (forward-line 1)
- (setq
- reference-line
- (buffer-substring-no-properties
- (line-beginning-position)
- (line-end-position))))
-
- (setq
- reference-indentation
- (phps-mode-indent--string-indentation
- reference-line)))
-
- ;; (message "not-found: %S" not-found)
- ;; (message "reference-line: %S" reference-line)
- ;; (message "reference-indentation: %S"
reference-indentation)
- ;; (message
- ;; "at-line-end: %S"
- ;; (buffer-substring-no-properties
- ;; (line-beginning-position)
- ;; (line-end-position)))
- ;; (message "is-declared-on-same-line-p: %S"
is-declared-on-same-line-p)
-
- (when reference-indentation
- (setq
- new-indentation
- reference-indentation))
-
- ;; myFunction(
- ;; 'arg',
- ;; );
- ;; or
- ;; 'weight' =>
- ;; 1.2,
- ;; ]);
- (when current-line-starts-with-closing-bracket
- (setq
- new-indentation
- (- new-indentation tab-width)))
-
- ;; define('_PRIVATE_ROOT',
- ;; 'here');
- ;; or
- ;; ['abc',
- ;; 'def'];
- (when (and
- (not current-line-starts-with-closing-bracket)
- is-declared-on-same-line-p)
- (setq
- new-indentation
- (+ new-indentation tab-width)))
-
- (goto-char point)
-
- ))
-
;; $var .=
;; 'hello';
;; echo 'here';
diff --git a/test/phps-mode-test-indent.el b/test/phps-mode-test-indent.el
index 084307093e..ccc7744874 100644
--- a/test/phps-mode-test-indent.el
+++ b/test/phps-mode-test-indent.el
@@ -356,6 +356,10 @@
"<?php\nfunction myFunction()\n{\n if (!isset($randomize)) {\n
if (true) {\n throw new \Exception(sprintf(\n __(\n
'Library not found at %s',\n 'domain'\n
),\n $path\n ));\n }\n }\n
return false;\n}\n"
"Multi-line throw statement")
+ (phps-mode-test-indent--should-equal
+ "<?php\n\nforeach ($datas as $data) {\n if (\n stripos(\n
$data,\n ' , '\n ) !== false\n ) {\n $explode
= explode(\n ' , ',\n $data\n );\n if (\n
!empty($explode)\n && is_array($explode)\n &&
isset(\n $explode[0],\n $explode[1]\n
)\n ) {\n $name = trim($explode[1]);\n }\n }\n}\n"
+ "Line after multi-line function call inside if condition list")
+
)
(defun phps-mode-test-indent--get-lines-indent-psr-2 ()
- [elpa] externals/phps-mode 20ad1fae08 132/212: Improved indentation arround multi-line object operators, (continued)
- [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
- [elpa] externals/phps-mode 2ef1168cb1 155/212: Added new failing indentation tests, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 519888fe79 150/212: Added another failing indent test, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 7ec071188a 137/212: Added more indent unit tests for nested function calls, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 837412c0e5 140/212: Improved indentation on lines starting with a closing bracket, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode cdbcd5ebe6 154/212: Added a new failing indent test and made it pass,
Christian Johansson <=
- [elpa] externals/phps-mode c2a7af2a98 142/212: Updated copyright years, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 91fb5402cd 158/212: Added another failing indentation and made it pass, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 66d4352052 169/212: Added more failing indent tests, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 0ca0e447b8 167/212: Improved indentation on lines starting with a closing bracket, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 18221a85f0 177/212: Added failing parse test for multiple swith case conditions, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode a2c61b9e7c 174/212: Started refactoring of indentation functions, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode e15d602e46 179/212: More TODO items, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 22c4f31716 178/212: Added TODO items, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode c05d97fc31 182/212: Disabled debug-mode in this branch, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode d095e757e6 186/212: Added failing imenu test, Christian Johansson, 2022/01/26