[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 2e16122284 153/212: Improved indentation on l
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode 2e16122284 153/212: Improved indentation on line after closing bracket and comma |
Date: |
Wed, 26 Jan 2022 01:51:17 -0500 (EST) |
branch: externals/phps-mode
commit 2e16122284b0aa8a2accc059675e309c7b8d3778
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Improved indentation on line after closing bracket and comma
---
phps-mode-indent.el | 55 ++++++++++++++++++++++++++++++-------------
test/phps-mode-test-indent.el | 4 ++++
2 files changed, 42 insertions(+), 17 deletions(-)
diff --git a/phps-mode-indent.el b/phps-mode-indent.el
index 7415e78641..9286b0568a 100644
--- a/phps-mode-indent.el
+++ b/phps-mode-indent.el
@@ -1045,6 +1045,10 @@
;; '25'
;; ],
;; 25
+ ;; or
+ ;; if (myFunction(
+ ;; random(),
+ ;; heredom(),
((string-match-p
"[])][\t ]*,[\t ]*\\(\\?>[\t\n ]*\\)?$"
previous-line-string)
@@ -1056,12 +1060,13 @@
(search-backward-regexp "," nil t) ;; Skip trailing comma
(let ((not-found-bracket-start t)
(reference-line)
- (parenthesis-level 1))
+ (found-colon)
+ (parenthesis-level 0))
(while
(and
not-found-bracket-start
(search-backward-regexp
- "\\()[][(),]\\|=>\\)"
+ "\\([][(),]\\|=>\\)"
nil
t))
(let ((match (match-string-no-properties 0)))
@@ -1073,7 +1078,9 @@
(setq
parenthesis-level
(1+ parenthesis-level))
- (when (= parenthesis-level 0)
+ (when (and
+ (= parenthesis-level 1)
+ found-colon)
(setq
not-found-bracket-start
nil)))
@@ -1083,28 +1090,42 @@
(string= "]" match))
(setq
parenthesis-level
- (1- parenthesis-level))
+ (1- parenthesis-level)))
+
+ ;; The second occurence of a colon
+ ;; is a significant marker of
+ ;; a starting bracket row
+ ((string= "," match)
(when (= parenthesis-level 0)
- (setq
- not-found-bracket-start
- nil)))
+ (if found-colon
+ (setq
+ not-found-bracket-start
+ nil)
+ (setq
+ found-colon
+ t)
+ (setq
+ reference-line
+ (buffer-substring-no-properties
+ (line-beginning-position)
+ (line-end-position))))))
- (t
- (when (= parenthesis-level 1)
+ ;; The first occurrence of a =>
+ ;; is a significant marker of
+ ;; a starting bracket row
+ ((string= "=>" match)
+ (when (= parenthesis-level 0)
+ (setq
+ reference-line
+ (buffer-substring-no-properties
+ (line-beginning-position)
+ (line-end-position)))
(setq
not-found-bracket-start
nil)))
)))
- ;; Found line were bracket started?
- (unless not-found-bracket-start
- (setq
- reference-line
- (buffer-substring-no-properties
- (line-beginning-position)
- (line-end-position))))
-
(when reference-line
;; (message "reference-line-2: %S" reference-line)
(setq
diff --git a/test/phps-mode-test-indent.el b/test/phps-mode-test-indent.el
index df03474b0d..084307093e 100644
--- a/test/phps-mode-test-indent.el
+++ b/test/phps-mode-test-indent.el
@@ -352,6 +352,10 @@
"<?php\nclass MyClass\n{\n public function getOperators()\n {\n
return array(\n '' => __(\n 'None',\n
'domain'\n ),\n '-' => __(\n
'Subtraction',\n 'domain'\n ),\n '+' =>
__(\n 'Addition',\n 'domain'\n ),\n
);\n }\n}\n"
"Method that returns multi-line array")
+ (phps-mode-test-indent--should-equal
+ "<?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")
+
)
(defun phps-mode-test-indent--get-lines-indent-psr-2 ()
- [elpa] externals/phps-mode d9cbe630b3 068/212: Passing bookkeeping of variables inside echo statements, (continued)
- [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, 2022/01/26
- [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 <=
- [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
- [elpa] externals/phps-mode 5432a61340 162/212: Improved indentation around closing of multi-dimensional brackets, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 28a5302e08 148/212: Passing indentation on line after closing bracket and command and were current line starts with closing bracket, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode be61c94dc3 165/212: Added TODO item, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode c65d433a73 138/212: Improved indentation around multi-line function-calls, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode f537965850 168/212: Improved indentation on lines after lines that ends with semicolon, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 6d8544d7fa 171/212: Added two more failing tests for indentation, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 616e3dc7ea 172/212: Added a TODO file, Christian Johansson, 2022/01/26