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 17, 2022
1 parent 817ac84 commit f926139
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 4 deletions.
35 changes: 32 additions & 3 deletions lisp/php-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
(require 'regexp-opt)
(defvar add-log-current-defun-header-regexp)
(defvar add-log-current-defun-function)
(defvar c-syntactic-context)
(defvar c-vsemi-status-unknown-p)
(defvar syntax-propertize-via-font-lock))

Expand Down Expand Up @@ -603,11 +604,39 @@ 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 'arglist-cont-nonempty c-syntactic-context) nil)
((assq 'defun-block-intro c-syntactic-context) nil)
((assq 'defun-close c-syntactic-context) nil)
((assq 'statement-cont 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
2 changes: 1 addition & 1 deletion tests/indent/issue-623.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@

$arr = [
$object->something() // ###php-mode-test### ((indent 4))
/* comment */ ->something() // ###php-mode-test### ((indent 4))
/* comment */ ->something() // ###php-mode-test### ((indent 8))
->something(), // ###php-mode-test### ((indent 8))
]; // ###php-mode-test### ((indent 0))
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 f926139

Please sign in to comment.