Skip to content

Commit 6513efa

Browse files
authored
Merge pull request #703 from emacs-php/fix/indentation
Fix indentation of expression continuation in arglist
2 parents 817ac84 + ff16da2 commit 6513efa

File tree

5 files changed

+89
-5
lines changed

5 files changed

+89
-5
lines changed

CHANGELOG.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,20 @@
22

33
All notable changes of the PHP Mode 1.19.1 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
44

5-
<!-- ## Unreleased -->
5+
## Unreleased
6+
7+
### Changed
8+
9+
* Make continued expressions inside lists (arguments and arrays, etc.) have the same indent width as outside the list ([#703])
10+
* (internal) Improved readability of test failures about indentation ([#707])
11+
12+
### Fixed
13+
14+
* Removed invalid definitions that caused errors in some expressions ([#704])
15+
16+
[#703]: https://github.com/emacs-php/php-mode/pull/703
17+
[#704]: https://github.com/emacs-php/php-mode/pull/704
18+
[#707]: https://github.com/emacs-php/php-mode/pull/707
619

720
## [1.24.1] - 2022-10-08
821

lisp/php-mode.el

+32-3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
(require 'regexp-opt)
8383
(defvar add-log-current-defun-header-regexp)
8484
(defvar add-log-current-defun-function)
85+
(defvar c-syntactic-context)
8586
(defvar c-vsemi-status-unknown-p)
8687
(defvar syntax-propertize-via-font-lock))
8788

@@ -603,11 +604,39 @@ might be to handle switch and goto labels differently."
603604
(defun php-lineup-cascaded-calls (langelem)
604605
"Line up chained methods using `c-lineup-cascaded-calls',
605606
but only if the setting is enabled."
606-
(if php-mode-lineup-cascaded-calls
607-
(c-lineup-cascaded-calls langelem)
607+
(cond
608+
(php-mode-lineup-cascaded-calls (c-lineup-cascaded-calls langelem))
609+
((assq 'arglist-cont-nonempty c-syntactic-context) nil)
610+
((assq 'defun-block-intro c-syntactic-context) nil)
611+
((assq 'defun-close c-syntactic-context) nil)
612+
((assq 'statement-cont c-syntactic-context) nil)
613+
(t
608614
(save-excursion
609615
(beginning-of-line)
610-
(if (looking-at-p "\\s-*->") '+ nil))))
616+
(let ((beginning-of-langelem (cdr langelem))
617+
(beginning-of-current-line (point))
618+
start)
619+
(skip-chars-forward " ")
620+
(cond
621+
((looking-at-p "->") '+)
622+
((looking-at-p "[:?]") '+)
623+
((looking-at-p "[,;]") nil)
624+
;; Is the previous line terminated with `,' ?
625+
((progn
626+
(forward-line -1)
627+
(end-of-line)
628+
(skip-chars-backward " ")
629+
(backward-char 1)
630+
(while (and (< beginning-of-langelem (point))
631+
(setq start (php-in-string-or-comment-p)))
632+
(goto-char start)
633+
(skip-chars-backward " ")
634+
(backward-char 1))
635+
(and (not (eq (point) beginning-of-current-line))
636+
(not (looking-at-p ","))
637+
(not (php-in-string-or-comment-p))))
638+
'+)
639+
(t nil)))))))
611640

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

tests/indent/issue-623.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212

1313
$arr = [
1414
$object->something() // ###php-mode-test### ((indent 4))
15-
/* comment */ ->something() // ###php-mode-test### ((indent 4))
15+
/* comment */ ->something() // ###php-mode-test### ((indent 8))
1616
->something(), // ###php-mode-test### ((indent 8))
1717
]; // ###php-mode-test### ((indent 0))

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+
);

tests/php-mode-test.el

+5
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ be processed."
6666
(lambda (offset)
6767
(let ((current-offset (current-indentation)))
6868
(unless (eq current-offset offset)
69+
(warn "line: %d context: %s\n" (line-number-at-pos) (c-guess-basic-syntax))
6970
(list :line (line-number-at-pos)
7071
:expected offset
7172
:actual current-offset))))))
@@ -649,6 +650,10 @@ Meant for `php-mode-test-issue-503'."
649650
"Proper alignment object -> accessor."
650651
(with-php-mode-test ("indent/issue-623.php" :indent t :magic t)))
651652

653+
(ert-deftest php-mode-test-issue-702 ()
654+
"Proper alignment arglist."
655+
(with-php-mode-test ("indent/issue-702.php" :indent t :magic t)))
656+
652657
(ert-deftest php-mode-test-php74 ()
653658
"Test highlighting language constructs added in PHP 7.4."
654659
(with-php-mode-test ("7.4/arrow-function.php" :faces t))

0 commit comments

Comments
 (0)