Skip to content

Commit 4efafb8

Browse files
committed
Fix indentation of expression continuation in arglist
1 parent 8b52378 commit 4efafb8

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

Diff for: lisp/php-mode.el

+24-1
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,30 @@ but only if the setting is enabled."
607607
(c-lineup-cascaded-calls langelem)
608608
(save-excursion
609609
(beginning-of-line)
610-
(if (looking-at-p "\\s-*->") '+ nil))))
610+
(let ((beginning-of-langelem (cdr langelem))
611+
(beginning-of-current-line (point))
612+
start)
613+
(skip-chars-forward " ")
614+
(cond
615+
((looking-at-p "->") '+)
616+
((looking-at-p "[:?]") '+)
617+
((looking-at-p "[,;]") nil)
618+
;; Is the previous line terminated with `,' ?
619+
((progn
620+
(forward-line -1)
621+
(end-of-line)
622+
(skip-chars-backward " ")
623+
(backward-char 1)
624+
(while (and (< beginning-of-langelem (point))
625+
(setq start (php-in-string-or-comment-p)))
626+
(goto-char start)
627+
(skip-chars-backward " ")
628+
(backward-char 1))
629+
(and (not (eq (point) beginning-of-current-line))
630+
(not (looking-at-p ","))
631+
(not (php-in-string-or-comment-p))))
632+
'+)
633+
(t nil))))))
611634

612635
(defun php-c-looking-at-or-maybe-in-bracelist (&optional _containing-sexp lim)
613636
"Replace `c-looking-at-or-maybe-in-bracelist'.

Diff for: tests/indent/issue-702.php

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
PHP_VERSION_ID > 80000
4+
? 'foo'
5+
: 'bar';
6+
7+
$a = [
8+
'key' => PHP_VERSION_ID > 80000
9+
? 'foo'
10+
: 'bar',
11+
true &&
12+
false,
13+
false
14+
|| true,
15+
'value1'
16+
,
17+
'value2'
18+
,
19+
];
20+
21+
var_dump(
22+
PHP_VERSION_ID > 80000
23+
? 'foo'
24+
: 'bar',
25+
true && // ###php-mode-test### ((indent 4))
26+
false,
27+
false // ###php-mode-test### ((indent 4))
28+
|| true, // ###php-mode-test### ((indent 8))
29+
// ###php-mode-test### ((indent 4))
30+
1 // ###php-mode-test### ((indent 4))
31+
+ 2 // ###php-mode-test### ((indent 8))
32+
/ 3, // ###php-mode-test### ((indent 8))
33+
'value1' // ###php-mode-test### ((indent 4))
34+
, // ###php-mode-test### ((indent 4))
35+
'value2' // ###php-mode-test### ((indent 4))
36+
, // ###php-mode-test### ((indent 4))
37+
);

Diff for: tests/php-mode-test.el

+4
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,10 @@ Meant for `php-mode-test-issue-503'."
646646
"Proper alignment object -> accessor."
647647
(with-php-mode-test ("indent/issue-623.php" :indent t :magic t)))
648648

649+
(ert-deftest php-mode-test-issue-702 ()
650+
"Proper alignment arglist."
651+
(with-php-mode-test ("indent/issue-702.php" :indent t :magic t)))
652+
649653
(ert-deftest php-mode-test-php74 ()
650654
"Test highlighting language constructs added in PHP 7.4."
651655
(with-php-mode-test ("7.4/arrow-function.php" :faces t))

0 commit comments

Comments
 (0)