branch: externals/phps-mode commit cc3bf037861fbbedc9eaaba24a1c2e429777aaa8 Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
Improved indentation after ending assignment expression --- phps-mode-indent.el | 31 ++++++++++++++++++------------- test/phps-mode-test-indent.el | 4 ++-- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/phps-mode-indent.el b/phps-mode-indent.el index 7b7318eb69..a56a14534f 100644 --- a/phps-mode-indent.el +++ b/phps-mode-indent.el @@ -250,6 +250,7 @@ ;; (message "current-line-starts-with-closing-bracket: %S" current-line-starts-with-closing-bracket) ;; (message "current-line-starts-with-opening-bracket: %S" current-line-starts-with-opening-bracket) ;; (message "previous-line-ends-with-opening-bracket: %S" previous-line-ends-with-opening-bracket) + ;; (message "previous-line-ends-with-terminus: %S" previous-line-ends-with-terminus) ;; (message "previous-bracket-level: %S" previous-bracket-level) ;; (message "previous-indentation: %S" previous-indentation) @@ -930,16 +931,15 @@ ;; When we have an assignment ;; keep track if bracket was opened on first ;; line - (when (and - is-assignment - (string-match-p - "[([]" - (buffer-substring-no-properties - (line-beginning-position) - (line-end-position)))) - (setq - bracket-opened-on-first-line - t)) + (when is-assignment + (let ((start-bracket-count + (phps-mode-indent--get-string-brackets-count + (buffer-substring-no-properties + (line-beginning-position) + (line-end-position))))) + (setq + bracket-opened-on-first-line + (> start-bracket-count 0)))) ;; echo 'there' . ;; 'here'; @@ -994,9 +994,14 @@ ;; $myObject->myFunction() ;; ->myFunction2() - ((string-match-p - "->" - previous-line-string) + ;; but ignore + ;; $myObject->test( + ;; 'here' + ((and + (not previous-line-ends-with-opening-bracket) + (string-match-p + "->" + previous-line-string)) (let ((not-found t) (started-chaining-on-this-line t) (is-assignment) diff --git a/test/phps-mode-test-indent.el b/test/phps-mode-test-indent.el index f74feaa133..3ba781f7b2 100644 --- a/test/phps-mode-test-indent.el +++ b/test/phps-mode-test-indent.el @@ -202,11 +202,11 @@ "Indentation for chained object operators in assignment with method call with arguments") (phps-mode-test-indent--should-equal - "<?php\n\n$myResult = !empty($myVar->myMethod3)\n && $myVar->myMethod\n && $myVar->myMethod2;\n" + "<?php\n\n$myResult = !empty($myVar->myMethod3)\n && $myVar->myMethod\n && $myVar->myMethod2;\necho 'here';" "Indentation for chained object operators in assignment") (phps-mode-test-indent--should-equal - "<?php\n$array = [\n 'second' => [\n 'hello' => true\n ]\n];\n\n$array = array(\n 'second' => array(\n 'third' => true\n )\n);" + "<?php\n$array = [\n 'second' => [\n 'hello' => true\n ]\n];\n\n$array = array(\n 'second' => array(\n 'third' => true\n )\n);" "Indent multi-dimensional arrays without trailing commas") (phps-mode-test-indent--should-equal