branch: externals/phps-mode commit 2613e7206180450568bf48b11c4ae81b2bce6349 Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
Improved token-blind indentation and tests for the same --- phps-mode-analyzer.el | 7 ++++--- phps-mode.el | 2 +- test/phps-mode-test-functions.el | 28 ++++++++++++++++++++++++++-- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/phps-mode-analyzer.el b/phps-mode-analyzer.el index e901edb..d8418c6 100644 --- a/phps-mode-analyzer.el +++ b/phps-mode-analyzer.el @@ -3271,7 +3271,7 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL." (let ((new-indentation)) (save-excursion (let ((line-number (line-number-at-pos point)) - (move-length 1) + (move-length 0) (line-is-empty t) line-beginning-position line-end-position @@ -3287,9 +3287,9 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL." ) (when (> line-number 1) (while (and - (> (- line-number move-length) 0) + (> line-number 0) line-is-empty) - (forward-line (* move-length -1)) + (forward-line -1) (setq line-number (1- line-number)) (beginning-of-line) (setq line-beginning-position (line-beginning-position)) @@ -3299,6 +3299,7 @@ SQUARE-BRACKET-LEVEL and ROUND-BRACKET-LEVEL." (buffer-substring-no-properties line-beginning-position line-end-position) ) (setq line-is-empty (string-match-p "^[ \t\f\r\n]*$" line-string)) + (setq move-length (1+ move-length)) ) (unless line-is-empty diff --git a/phps-mode.el b/phps-mode.el index 1f6728c..131de4c 100644 --- a/phps-mode.el +++ b/phps-mode.el @@ -6,7 +6,7 @@ ;; Maintainer: Christian Johansson <christ...@cvj.se> ;; Created: 3 Mar 2018 ;; Modified: 21 Nov 2019 -;; Version: 0.3.16 +;; Version: 0.3.17 ;; Keywords: tools, convenience ;; URL: https://github.com/cjohansson/emacs-phps-mode diff --git a/test/phps-mode-test-functions.el b/test/phps-mode-test-functions.el index c63a228..f87c16d 100644 --- a/test/phps-mode-test-functions.el +++ b/test/phps-mode-test-functions.el @@ -76,7 +76,11 @@ (goto-char (point-max)) (should (equal (phps-mode-analyzer--alternative-indentation) - 0))) + 0)) + (let ((buffer-contents (buffer-substring-no-properties (point-min) (point-max)))) + (should (equal + buffer-contents + "<?php\nif ($myCondition) {\n echo 'I was here';\n}")))) (phps-mode-test-with-buffer "<?php\nif ($myCondition) {\necho 'I was here';\necho 'I was here again';\n}" @@ -92,7 +96,27 @@ (goto-char (point-max)) (should (equal (phps-mode-analyzer--alternative-indentation) - 0))) + 0)) + (let ((buffer-contents (buffer-substring-no-properties (point-min) (point-max)))) + (should (equal + buffer-contents + "<?php\nif ($myCondition) {\n echo 'I was here';\n echo 'I was here again';\n}")))) + + (phps-mode-test-with-buffer + "<?php\nif ($test) {\n if ($test2) {\n\n}\n}" + "Alternative indentation on nested if block with empty contents" + (goto-char 40) + (should (equal + (phps-mode-analyzer--alternative-indentation) + 4)) + (goto-char (point-max)) + (should (equal + (phps-mode-analyzer--alternative-indentation) + 0)) + (let ((buffer-contents (buffer-substring-no-properties (point-min) (point-max)))) + (should (equal + buffer-contents + "<?php\nif ($test) {\n if ($test2) {\n\n }\n}")))) )