[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 3853ddf32a 099/212: Passed another concatenat
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode 3853ddf32a 099/212: Passed another concatenation test for indentation |
Date: |
Wed, 26 Jan 2022 01:51:01 -0500 (EST) |
branch: externals/phps-mode
commit 3853ddf32a0c1e1df16709a173243a95e47624e7
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Passed another concatenation test for indentation
---
phps-mode-indent.el | 103 +++++++++++++++++++++++++++++++++++++-----
test/phps-mode-test-indent.el | 28 +++++++++---
2 files changed, 113 insertions(+), 18 deletions(-)
diff --git a/phps-mode-indent.el b/phps-mode-indent.el
index 32ad502648..e6e228eee2 100644
--- a/phps-mode-indent.el
+++ b/phps-mode-indent.el
@@ -85,7 +85,7 @@
"If STRING end with closing bracket, return it, otherwise nil."
(phps-mode-indent--string-ends-with-regexp
string
- "\\([\]})[]\\)[\t ]*"))
+ "\\([\]})]\\)[\t ]*"))
(defun phps-mode-indent--string-ends-with-opening-bracket (string)
"If STRING end with opening bracket, return it, otherwise nil."
@@ -131,7 +131,7 @@
;; (message "\nCurrent line: %S" current-line-string)
- ;; TODO Try to find previous 2 non-empty lines
+ ;; Try to find previous 2 non-empty lines
(let ((line-is-empty-p t)
(searching-previous-lines 2))
(while (and
@@ -371,20 +371,19 @@
)
+ ;; $variable = array(
+ ;; 'random' =>
+ ;; 'hello'
+ ;; );
+ ;; or
+ ;; $variable = [
+ ;; 'random' =>
+ ;; 'hello'
+ ;; ];
(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))
@@ -423,6 +422,86 @@
)
+ ;; echo 'Something'
+ ;; . 'more';
+ ;; or
+ ;; echo 'Something' .
+ ;; 'more';
+ (when (or
+ (string-match-p
+ "^[\t ]*\\."
+ current-line-string)
+ (string-match-p
+ "\\.[\t ]*$"
+ previous-line-string))
+
+ ;; If previous line matched ending .
+ ;; we must backtrack at least two lines
+ ;; to find a good reference indentation
+ (let ((old-point (point))
+ (match-string)
+ (previous-concatenation)
+ (keep-searching 1)
+ (concat-was-trailing-p
+ (string-match-p
+ "\\.[\t ]*$"
+ previous-line-string))
+ (previous-concatenation2))
+ (when concat-was-trailing-p
+ (setq
+ keep-searching
+ 2))
+ (while keep-searching
+ (let ((previous-expression
+ (search-backward-regexp
+ "\\(^[\t ]*\\.\\|\\.[\t ]*$\\|[{}=;]\\)" nil t)))
+ (if previous-expression
+ (progn
+ (setq
+ match-string
+ (match-string-no-properties 0))
+ (if (string-match-p
+ "[{}=;]"
+ match-string)
+ (setq
+ keep-searching
+ nil)
+ (setq
+ keep-searching
+ (1- keep-searching))
+ (when (= keep-searching 0)
+ (setq
+ keep-searching
+ nil)
+ (when concat-was-trailing-p
+ (goto-char previous-concatenation2))
+ (setq
+ previous-concatenation
+ match-string))
+ (setq
+ previous-concatenation2
+ (point))))
+ keep-searching
+ nil)))
+
+ (if previous-concatenation
+ (let ((first-concatenated-line-indent
+ (phps-mode-indent--string-indentation
+ (buffer-substring-no-properties
+ (line-beginning-position)
+ (line-end-position)))))
+ ;; We use previous concatenated lines indent
+ (setq
+ new-indentation
+ first-concatenated-line-indent))
+ ;; This is the first concatenated line so we indent it
+ (setq
+ new-indentation
+ (+ new-indentation tab-width)))
+
+ ;; 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 90667c7f3f..b0daebc4f2 100644
--- a/test/phps-mode-test-indent.el
+++ b/test/phps-mode-test-indent.el
@@ -348,19 +348,35 @@
"Array assignment with double arrow elements on four lines with trailing
comma #2")
(phps-mode-test-indent--should-equal
- "<?php\n$variable = array(\n 'random4');\n$variable = true;\n"
- "Array assignment on two lines")
+ "<?php\n$var = 'A line' \n . 'last line here';\necho 'was here';"
+ "Concatenated single-quoted-string multiple-lines in assignment")
(phps-mode-test-indent--should-equal
- "<?php\n$var = 'A line' .\n 'more text here' .\n 'last line here';"
- "Concatenated single-quoted-string multiple-lines in assignment")
+ "<?php\n$var = 'A line' .\n 'last line here';\necho 'was here';"
+ "Concatenated single-quoted-string multiple-lines in assignment #2")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n$var = 'A line' \n . 'more text here'\n . 'last line
here';\necho 'was here';"
+ "Concatenated single-quoted-string multiple-lines in assignment #3")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n$var = 'A line' .\n 'more text here' .\n 'last line
here';\necho 'was here';"
+ "Concatenated single-quoted-string multiple-lines in assignment #4")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n$var = 'A line' \n . 'more text here'\n . 'even more text'\n
. 'last line here';\necho 'was here';"
+ "Concatenated single-quoted-string multiple-lines in assignment #5")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\n$var = 'A line' .\n 'more text here' .\n 'even more text' .\n
'last line here';\necho 'was here';"
+ "Concatenated single-quoted-string multiple-lines in assignment #6")
(phps-mode-test-indent--should-equal
- "<?php\n$var .=\n 'A line';"
+ "<?php\n$var .=\n 'A line';\necho 'was here';"
"Concatenated equal single-quoted-string on multiple-lines in assignment")
(phps-mode-test-indent--should-equal
- "<?php\n$var *=\n 25;"
+ "<?php\n$var *=\n 25;\necho 'was here';"
"Multiplication equal assignment on multiple-lines")
(phps-mode-test-indent--should-equal
- [elpa] externals/phps-mode 228f212127 080/212: Starting on removing the old process tokens in string function, (continued)
- [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, 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 <=
- [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
- [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