branch: externals/phps-mode commit 62b855ce0b20ab2886bf9641bc541fc80c325347 Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
Fixed a case with alternative indentation after array/object assignment --- phps-mode-lex-analyzer.el | 9 ++++++--- phps-mode.el | 4 ++-- test/phps-mode-test-lex-analyzer.el | 13 +++++++++++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/phps-mode-lex-analyzer.el b/phps-mode-lex-analyzer.el index 74f4a3d..3c5fa13 100644 --- a/phps-mode-lex-analyzer.el +++ b/phps-mode-lex-analyzer.el @@ -2059,7 +2059,10 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL." (setq not-found nil) )) ;; If it ended an assignment, decrease indentation - (when is-assignment + (when (and is-assignment + (> bracket-level -1)) + ;; NOTE stuff like $var = array(\n 4\n);\n + ;; will end assignment but also decrease bracket-level (setq new-indentation (- new-indentation tab-width)))) (goto-char point)) @@ -2113,11 +2116,11 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL." (defun phps-mode-lex-analyzer--string-ends-with-assignment-p (string) "Get bracket count for STRING." - (string-match-p "[\t ]*=$" string)) + (string-match-p "[\t ]*=[\t ]*$" string)) (defun phps-mode-lex-analyzer--string-ends-with-semicolon-p (string) "Get bracket count for STRING." - (string-match-p ";$" string)) + (string-match-p ";[\t ]*$" string)) (defun phps-mode-lex-analyzer--cancel-idle-timer () "Cancel idle timer." diff --git a/phps-mode.el b/phps-mode.el index 99cf923..107aa71 100644 --- a/phps-mode.el +++ b/phps-mode.el @@ -5,8 +5,8 @@ ;; Author: Christian Johansson <christ...@cvj.se> ;; Maintainer: Christian Johansson <christ...@cvj.se> ;; Created: 3 Mar 2018 -;; Modified: 17 Feb 2020 -;; Version: 0.3.33 +;; Modified: 18 Feb 2020 +;; Version: 0.3.34 ;; Keywords: tools, convenience ;; URL: https://github.com/cjohansson/emacs-phps-mode diff --git a/test/phps-mode-test-lex-analyzer.el b/test/phps-mode-test-lex-analyzer.el index 6bafa62..588388d 100644 --- a/test/phps-mode-test-lex-analyzer.el +++ b/test/phps-mode-test-lex-analyzer.el @@ -266,6 +266,19 @@ buffer-contents "<?php\nif ($here) {\n if ($wasHere)\n {\n \n }\n}\n\n")))) + (phps-mode-test--with-buffer + "<?php\nif ($myCondition)\n{\n $var = array(\n 'was here'\n );\n// Was here\n}\n" + "Alternative indentation on line after array declaration" + (goto-char 71) + (should (equal + (phps-mode-lex-analyzer--alternative-indentation) + 4)) + (let ((buffer-contents (buffer-substring-no-properties (point-min) (point-max)))) + (should (equal + buffer-contents + "<?php\nif ($myCondition)\n{\n $var = array(\n 'was here'\n );\n // Was here\n}\n" + )))) + ) (defun phps-mode-test-lex-analyzer--move-lines-indent ()