Skip to content

Commit eef97db

Browse files
jorissteynEric James Michael Ritz
authored and
Eric James Michael Ritz
committed
Fix indent-line function for statements at bol
Resolves issue #184 Signed-off-by: Eric James Michael Ritz <[email protected]>
1 parent 78fd7e8 commit eef97db

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

php-mode-test.el

+10
Original file line numberDiff line numberDiff line change
@@ -526,4 +526,14 @@ style from Drupal."
526526
(call-interactively 'indent-for-tab-command)
527527
(should (= (current-column) equal-indentation)))))
528528

529+
(ert-deftest php-mode-test-issue-184()
530+
"Test indent-line for statements and heredoc end at beginning of lines"
531+
(with-php-mode-test ("issue-184.php")
532+
(search-forward "html;")
533+
(php-cautious-indent-line)
534+
(should (eq (current-indentation) 0))
535+
(search-forward "return;")
536+
(php-cautious-indent-line)
537+
(should (eq (current-indentation) c-basic-offset))))
538+
529539
;;; php-mode-test.el ends here

php-mode.el

+2-1
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,8 @@ example `html-mode'. Known such libraries are:\n\t"
829829
(move-beginning-of-line nil)
830830
;; Don't indent heredoc end mark
831831
(save-match-data
832-
(unless (looking-at "[a-zA-Z0-9_]+;\n")
832+
(unless (and (looking-at "[a-zA-Z0-9_]+;\n")
833+
(php-in-string-p))
833834
(setq doit t)))
834835
(goto-char here)
835836
(when doit

tests/issue-184.php

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/**
4+
* GitHub Issue: https://github.com/ejmr/php-mode/issues/184
5+
*
6+
* Test indentation of statements at beginning of line.
7+
*
8+
* The termination of a heredoc is always fixed bol, but php-mode must
9+
* detect that not all statements at column 0 are the end of a
10+
* heredoc.
11+
*/
12+
13+
function test() {
14+
$html = <<<html
15+
<a href="#"></a>
16+
html;
17+
18+
return;
19+
}

0 commit comments

Comments
 (0)