Skip to content

Commit

Permalink
Fix indentation of expression continuation in arglist
Browse files Browse the repository at this point in the history
  • Loading branch information
zonuexe committed Sep 15, 2022
1 parent 817ac84 commit c7c36ae
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 3 deletions.
32 changes: 29 additions & 3 deletions lisp/php-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -603,11 +603,37 @@ might be to handle switch and goto labels differently."
(defun php-lineup-cascaded-calls (langelem)
"Line up chained methods using `c-lineup-cascaded-calls',
but only if the setting is enabled."
(if php-mode-lineup-cascaded-calls
(c-lineup-cascaded-calls langelem)
(cond
(php-mode-lineup-cascaded-calls (c-lineup-cascaded-calls langelem))
((assq 'defun-block-intro c-syntactic-context) nil)
((assq 'defun-close c-syntactic-context) nil)
(t
(save-excursion
(beginning-of-line)
(if (looking-at-p "\\s-*->") '+ nil))))
(let ((beginning-of-langelem (cdr langelem))
(beginning-of-current-line (point))
start)
(skip-chars-forward " ")
(cond
((looking-at-p "->") '+)
((looking-at-p "[:?]") '+)
((looking-at-p "[,;]") nil)
;; Is the previous line terminated with `,' ?
((progn
(forward-line -1)
(end-of-line)
(skip-chars-backward " ")
(backward-char 1)
(while (and (< beginning-of-langelem (point))
(setq start (php-in-string-or-comment-p)))
(goto-char start)
(skip-chars-backward " ")
(backward-char 1))
(and (not (eq (point) beginning-of-current-line))
(not (looking-at-p ","))
(not (php-in-string-or-comment-p))))
'+)
(t nil)))))))

(defun php-c-looking-at-or-maybe-in-bracelist (&optional _containing-sexp lim)
"Replace `c-looking-at-or-maybe-in-bracelist'.
Expand Down
37 changes: 37 additions & 0 deletions tests/indent/issue-702.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

PHP_VERSION_ID === 80000
? 'foo'
: 'bar';

$a = [
'key' => PHP_VERSION_ID === 80000
? 'foo'
: 'bar',
true &&
false,
false
|| true,
'value1'
,
'value2'
,
];

var_dump(
PHP_VERSION_ID === 80000
? 'foo'
: 'bar',
true && // ###php-mode-test### ((indent 4))
false,
false // ###php-mode-test### ((indent 4))
|| true, // ###php-mode-test### ((indent 8))
// ###php-mode-test### ((indent 4))
1 // ###php-mode-test### ((indent 4))
+ 2 // ###php-mode-test### ((indent 8))
/ 3, // ###php-mode-test### ((indent 8))
'value1' // ###php-mode-test### ((indent 4))
, // ###php-mode-test### ((indent 4))
'value2' // ###php-mode-test### ((indent 4))
, // ###php-mode-test### ((indent 4))
);
4 changes: 4 additions & 0 deletions tests/php-mode-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,10 @@ Meant for `php-mode-test-issue-503'."
"Proper alignment object -> accessor."
(with-php-mode-test ("indent/issue-623.php" :indent t :magic t)))

(ert-deftest php-mode-test-issue-702 ()
"Proper alignment arglist."
(with-php-mode-test ("indent/issue-702.php" :indent t :magic t)))

(ert-deftest php-mode-test-php74 ()
"Test highlighting language constructs added in PHP 7.4."
(with-php-mode-test ("7.4/arrow-function.php" :faces t))
Expand Down

0 comments on commit c7c36ae

Please sign in to comment.