Skip to content

Commit 39f4306

Browse files
authored
Merge pull request #624 from emacs-php/fix/issue-632
Fix indentation of object operator (->) at the beginning of line
2 parents 4d0b4a0 + 25e0a9e commit 39f4306

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

php-mode.el

+5-2
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,11 @@ might be to handle switch and goto labels differently."
636636
(defun php-lineup-cascaded-calls (langelem)
637637
"Line up chained methods using `c-lineup-cascaded-calls',
638638
but only if the setting is enabled"
639-
(when php-mode-lineup-cascaded-calls
640-
(c-lineup-cascaded-calls langelem)))
639+
(if php-mode-lineup-cascaded-calls
640+
(c-lineup-cascaded-calls langelem)
641+
(save-excursion
642+
(beginning-of-line)
643+
(if (looking-at-p "\\s-*->") '+ nil))))
641644

642645
(c-add-style
643646
"php"

tests/indent/issue-623.php

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
$object = new DateTime();
4+
5+
$object->something()
6+
->something(); // ###php-mode-test### ((indent 4))
7+
8+
var_dump(
9+
$object->something() // ###php-mode-test### ((indent 4))
10+
->something(), // ###php-mode-test### ((indent 8))
11+
); // ###php-mode-test### ((indent 0))
12+
13+
$arr = [
14+
$object->something() // ###php-mode-test### ((indent 4))
15+
/* comment */ ->something() // ###php-mode-test### ((indent 4))
16+
->something(), // ###php-mode-test### ((indent 8))
17+
]; // ###php-mode-test### ((indent 0))

tests/php-mode-test.el

+4
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,10 @@ Meant for `php-mode-test-issue-503'."
645645
(goto-char (point-min))
646646
(should (eq (php-mode-test-in-function-p nil) nil))))
647647

648+
(ert-deftest php-mode-test-issue-623 ()
649+
"Proper alignment object -> accessor."
650+
(with-php-mode-test ("indent/issue-623.php" :indent t :magic t)))
651+
648652
(ert-deftest php-mode-test-php74 ()
649653
"Test highlighting language constructs added in PHP 7.4."
650654
(with-php-mode-test ("7.4/arrow-function.php" :faces t))

0 commit comments

Comments
 (0)