[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 2432928a86 096/212: Indentation passing more
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode 2432928a86 096/212: Indentation passing more tests for alternative control structures |
Date: |
Wed, 26 Jan 2022 01:51:01 -0500 (EST) |
branch: externals/phps-mode
commit 2432928a86f0a8904177613498f8c29a77a2340b
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Indentation passing more tests for alternative control structures
---
phps-mode-indent.el | 117 ++++++++++++++++++++++++++++++++----------
test/phps-mode-test-indent.el | 14 ++++-
2 files changed, 102 insertions(+), 29 deletions(-)
diff --git a/phps-mode-indent.el b/phps-mode-indent.el
index dcc143123e..edb3978a0c 100644
--- a/phps-mode-indent.el
+++ b/phps-mode-indent.el
@@ -249,11 +249,27 @@
;; if (true)
;; echo 'Something';
+ ;; or
+ ;; while (true)
+ ;; echo 'Something';
+ ;; or
+ ;; if (true):
+ ;; echo 'Something';
+ ;; or
+ ;; while (true):
+ ;; echo 'Something';
+ ;; or
+ ;; for ($i = 0; $i < 10; $i++):
+ ;; echo 'Something';
+ ;; or
+ ;; foreach ($array as $value):
+ ;; echo 'Something';
(when (and
- (not current-line-starts-with-closing-bracket)
- previous-line-ends-with-closing-bracket
- (string= previous-line-ends-with-closing-bracket ")")
- (string-match-p "^[\t ]*\\(if\\|while\\)[\t ]*("
previous-line-string))
+ current-line-ends-with-terminus
+ (string= current-line-ends-with-terminus ";")
+ (string-match-p
+ "^[\t ]*\\(if\\|while\\|for\\|foreach\\)[\t ]*(.+):?$"
+ previous-line-string))
(setq new-indentation (+ new-indentation tab-width)))
;; else
@@ -261,26 +277,73 @@
;; or
;; else if (true)
;; echo 'Something';
+ ;; or
+ ;; elseif (true)
+ ;; echo 'Something';
+ ;; or
+ ;; else:
+ ;; echo 'Something';
+ ;; or
+ ;; else if (true):
+ ;; echo 'Something';
+ ;; or
+ ;; elseif (true):
+ ;; echo 'Something';
(when (and
- (phps-mode-indent--string-starts-with-regexp
- previous-line-string
- "[\t ]*else")
- (not
- (phps-mode-indent--string-ends-with-regexp
- previous-line-string
- "{[\t ]*")))
- (setq new-indentation (+ new-indentation tab-width)))
+ current-line-ends-with-terminus
+ (string=
+ current-line-ends-with-terminus
+ ";")
+ (string-match-p
+ "^[\t ]*else\\([\t ]*$\\|.*\\()\\|:\\)$\\)"
+ previous-line-string))
+ (setq
+ new-indentation
+ (+ new-indentation tab-width)))
(when (and
previous-line-ends-with-terminus
- (string= previous-line-ends-with-terminus ";"))
+ (string=
+ previous-line-ends-with-terminus
+ ";"))
;; if (true)
;; echo 'Something';
;; else
- (when (phps-mode-indent--string-starts-with-regexp
- current-line-string "[\t ]*else")
- (setq new-indentation (- new-indentation tab-width)))
+ ;; or
+ ;; if (true):
+ ;; echo 'Something';
+ ;; else:
+ ;; or
+ ;; if (true)
+ ;; echo 'Something';
+ ;; elseif (false)
+ ;; or
+ ;; if (true):
+ ;; echo 'Something';
+ ;; elseif (false):
+ ;; or
+ ;; if (true):
+ ;; echo 'Something';
+ ;; endif;
+ ;; or
+ ;; while (true):
+ ;; echo 'Something';
+ ;; endwhile;
+ ;; or
+ ;; for ($i = 0; $i < 10; $i++):
+ ;; echo 'Something';
+ ;; endfor;
+ ;; or
+ ;; foreach ($array as $value):
+ ;; echo 'Something';
+ ;; endforeach;
+ (when (string-match-p
+ "^[\t ]*\\(else:?[\t ]*$\\|else.*):?$\\|endif;[\t
]*$\\|endfor;[\t ]*$\\|endforeach;[\t ]*$\\|endwhile;[\t ]*$\\)"
+ current-line-string)
+ (setq
+ new-indentation
+ (- new-indentation tab-width)))
;; if (true)
;; echo 'Something';
@@ -295,18 +358,16 @@
;; when (true)
;; echo 'Something';
;; echo 'Afterwards';
- (when (and
- (not
- (phps-mode-indent--string-ends-with-regexp
- previous2-line-string "{[\t ]*"))
- (or
- (phps-mode-indent--string-starts-with-regexp
- previous2-line-string "[\t ]*else")
- (phps-mode-indent--string-starts-with-regexp
- previous2-line-string "[\t ]*if[\t ]*(")
- (phps-mode-indent--string-starts-with-regexp
- previous2-line-string "[\t ]*while[\t ]*(")))
- (setq new-indentation (- new-indentation tab-width)))
+ ;; or
+ ;; elseif (true)
+ ;; echo 'Something';
+ ;; echo 'Afterwards';
+ (when (string-match-p
+ "[\t ]*\\(else[\t ]*$\\|else.*)[\t
]*$\\|if.*)$\\|while.*)$\\)"
+ previous2-line-string)
+ (setq
+ new-indentation
+ (- new-indentation tab-width)))
)
diff --git a/test/phps-mode-test-indent.el b/test/phps-mode-test-indent.el
index 588ba63ceb..9d4eaff741 100644
--- a/test/phps-mode-test-indent.el
+++ b/test/phps-mode-test-indent.el
@@ -379,7 +379,19 @@
(phps-mode-test-indent--should-equal
"<?php\nif (true):\n echo 'Something';\nelseif (true):\n echo
'Something';\nelse:\n echo 'Something else';\n echo 'Something else
again';\nendif;\necho true;\n"
- "Alternative control structures")
+ "Alternative control structures basic if-elseif-else flow")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nwhile (true):\n echo 'Something';\n echo
'Something';\nendwhile;\necho 'Something else';\n"
+ "Alternative control structures basic while-endwhile flow")
+
+ (phps-mode-test-indent--should-equal
+ "<?php\nfor ($i = 0; $i < 10; $i++):\n echo 'Something';\n echo
'Something';\nendfor;\necho 'Something else';\n"
+ "Alternative control structures basic for-endfor flow")
+
+ (phps-mode-test-indent--should-equal
+ "<?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"
- [elpa] externals/phps-mode a80c12ef14 005/212: Passing imenu-generation for file with multiple namespaces, (continued)
- [elpa] externals/phps-mode a80c12ef14 005/212: Passing imenu-generation for file with multiple namespaces, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 0071b40aae 007/212: Syntax coloring is now in separate file, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 1cc4aed616 016/212: Passing first bookkeeping test via generation via parser SDT, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode b3b27951bd 015/212: More work on bookkeeping, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 395a4ed045 036/212: Started on bookkeeping via parser SDT for properties, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 69341c9709 039/212: More working on bookkeeping of class properties via parser SDT, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode cefab36fa8 054/212: More work on bookkeeping arrow function variables, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode d9cbe630b3 068/212: Passing bookkeeping of variables inside echo statements, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 0919855a31 073/212: Added SDT for concat operation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 5df554fc47 070/212: Bookkeeping via AST properly handles $this reference in only non-static methods, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 2432928a86 096/212: Indentation passing more tests for alternative control structures,
Christian Johansson <=
- [elpa] externals/phps-mode cef879268b 103/212: Added two new tests for failing indentation for multi-line concatenated strings, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 40ce934c11 116/212: Indent support for string-doc in assignment, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode fbe600500f 135/212: More work on array and argument element indentation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 6cb18913e4 152/212: Improved indentation for lines ending with closing bracket and comma, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 26d7b64086 144/212: Added TODO item for indentation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 0e7eb04800 149/212: Passing indentation test for multiple function arguments with default values, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 2e16122284 153/212: Improved indentation on line after closing bracket and comma, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 1825ee499b 151/212: More wrestling with indentation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 29fee20e43 141/212: Passed all tests for indentation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 6a49784b8b 161/212: When indentation search previous code lines it skips commented out lines, Christian Johansson, 2022/01/26