emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/php-mode 6513efaf6f 4/4: Merge pull request #703 from emac


From: ELPA Syncer
Subject: [nongnu] elpa/php-mode 6513efaf6f 4/4: Merge pull request #703 from emacs-php/fix/indentation
Date: Sat, 17 Sep 2022 15:59:00 -0400 (EDT)

branch: elpa/php-mode
commit 6513efaf6fd062aaa5ed542a710394553fe1c4e1
Merge: 817ac846f1 ff16da2c53
Author: USAMI Kenta <tadsan@pixiv.com>
Commit: GitHub <noreply@github.com>

    Merge pull request #703 from emacs-php/fix/indentation
    
    Fix indentation of expression continuation in arglist
---
 CHANGELOG.md               | 15 ++++++++++++++-
 lisp/php-mode.el           | 35 ++++++++++++++++++++++++++++++++---
 tests/indent/issue-623.php |  2 +-
 tests/indent/issue-702.php | 37 +++++++++++++++++++++++++++++++++++++
 tests/php-mode-test.el     |  5 +++++
 5 files changed, 89 insertions(+), 5 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2da0a4077a..be5eb0448c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,7 +2,20 @@
 
 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.
 
-<!-- ## Unreleased -->
+## Unreleased
+
+### Changed
+
+ * Make continued expressions inside lists (arguments and arrays, etc.) have 
the same indent width as outside the list ([#703])
+ * (internal) Improved readability of test failures about indentation ([#707])
+
+### Fixed
+
+ * Removed invalid definitions that caused errors in some expressions ([#704])
+
+[#703]: https://github.com/emacs-php/php-mode/pull/703
+[#704]: https://github.com/emacs-php/php-mode/pull/704
+[#707]: https://github.com/emacs-php/php-mode/pull/707
 
 ## [1.24.1] - 2022-10-08
 
diff --git a/lisp/php-mode.el b/lisp/php-mode.el
index cff90b08e2..aef3f3c806 100644
--- a/lisp/php-mode.el
+++ b/lisp/php-mode.el
@@ -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))
 
@@ -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'.
diff --git a/tests/indent/issue-623.php b/tests/indent/issue-623.php
index d1059fefff..833d8e4eff 100644
--- a/tests/indent/issue-623.php
+++ b/tests/indent/issue-623.php
@@ -12,6 +12,6 @@ var_dump(
 
 $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))
diff --git a/tests/indent/issue-702.php b/tests/indent/issue-702.php
new file mode 100644
index 0000000000..3ef717e479
--- /dev/null
+++ b/tests/indent/issue-702.php
@@ -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))
+);
diff --git a/tests/php-mode-test.el b/tests/php-mode-test.el
index 3a9c4de4d4..6e10a9914e 100644
--- a/tests/php-mode-test.el
+++ b/tests/php-mode-test.el
@@ -66,6 +66,7 @@ be processed."
              (lambda (offset)
                (let ((current-offset (current-indentation)))
                  (unless (eq current-offset offset)
+                   (warn "line: %d context: %s\n" (line-number-at-pos) 
(c-guess-basic-syntax))
                    (list :line (line-number-at-pos)
                          :expected offset
                          :actual current-offset))))))
@@ -649,6 +650,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))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]