branch: externals/phps-mode commit 8e5741493c0efc58415fe3d34fae039fd7c7a5f3 Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
Improved alternative indentation with trailing opening bracket on line with previous multiple closing brackets --- phps-mode-lex-analyzer.el | 11 ++++++++++- phps-mode.el | 4 ++-- test/phps-mode-test-lex-analyzer.el | 7 +++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/phps-mode-lex-analyzer.el b/phps-mode-lex-analyzer.el index e683e94..f9a2ecb 100644 --- a/phps-mode-lex-analyzer.el +++ b/phps-mode-lex-analyzer.el @@ -2020,6 +2020,7 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL." (current-line-starts-with-closing-bracket (phps-mode-lex-analyzer--string-starts-with-closing-bracket-p current-line-string)) (line-starts-with-closing-bracket (phps-mode-lex-analyzer--string-starts-with-closing-bracket-p line-string)) (line-ends-with-assignment (phps-mode-lex-analyzer--string-ends-with-assignment-p line-string)) + (line-ends-with-opening-bracket (phps-mode-lex-analyzer--string-ends-with-opening-bracket-p line-string)) (line-ends-with-semicolon (phps-mode-lex-analyzer--string-ends-with-semicolon-p line-string)) (bracket-level (phps-mode-lex-analyzer--get-string-brackets-count line-string))) (setq new-indentation old-indentation) @@ -2043,6 +2044,10 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL." (when line-ends-with-assignment (setq new-indentation (+ new-indentation tab-width))) + (when (and line-ends-with-opening-bracket + (< bracket-level 0)) + (setq new-indentation (+ new-indentation tab-width))) + (when line-ends-with-semicolon ;; Back-trace buffer from previous line ;; Determine if semi-colon ended an assignment or not @@ -2111,9 +2116,13 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL." "Get bracket count for STRING." (string-match-p "^[\t ]*\\([\]})[]\\|</[a-zA-Z]+\\|/>\\)" string)) +(defun phps-mode-lex-analyzer--string-ends-with-opening-bracket-p (string) + "Get bracket count for STRING." + (string-match-p "\\([\[{(]\\|<[a-zA-Z]+\\)[\t ]*$" string)) + (defun phps-mode-lex-analyzer--string-ends-with-assignment-p (string) "Get bracket count for STRING." - (string-match-p "[\t ]*=[\t ]*$" string)) + (string-match-p "=[\t ]*$" string)) (defun phps-mode-lex-analyzer--string-ends-with-semicolon-p (string) "Get bracket count for STRING." diff --git a/phps-mode.el b/phps-mode.el index 0c0b1a2..2555c2e 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: 14 Apr 2020 -;; Version: 0.3.40 +;; Modified: 15 Apr 2020 +;; Version: 0.3.41 ;; 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 3824060..625574d 100644 --- a/test/phps-mode-test-lex-analyzer.el +++ b/test/phps-mode-test-lex-analyzer.el @@ -296,6 +296,13 @@ "<?php\nif ($myCondition == 2) {\n echo 'store_vars: <pre>' . print_r($store_vars, true) . '</pre>';\n echo 'search_ids: <pre>' . print_r($search_ids, true) . '</pre>';\n}" )))) + (phps-mode-test--with-buffer + "<?php\nif (is_array(\n $array\n)) {\n echo 'was here';\n}" + "Alternative indentation after trailing opening bracket while closing two earlier on line" + (goto-char 41) + (should (equal + (phps-mode-lex-analyzer--alternative-indentation) + 4))) )