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

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

[nongnu] elpa/php-mode f926139d41 1/4: Fix indentation of expression con


From: ELPA Syncer
Subject: [nongnu] elpa/php-mode f926139d41 1/4: Fix indentation of expression continuation in arglist
Date: Sat, 17 Sep 2022 15:59:00 -0400 (EDT)

branch: elpa/php-mode
commit f926139d415e0e17e0fb3a46aa81f72a7a77be08
Author: USAMI Kenta <tadsan@zonu.me>
Commit: USAMI Kenta <tadsan@zonu.me>

    Fix indentation of expression continuation in arglist
---
 lisp/php-mode.el           | 35 ++++++++++++++++++++++++++++++++---
 tests/indent/issue-623.php |  2 +-
 tests/indent/issue-702.php | 37 +++++++++++++++++++++++++++++++++++++
 tests/php-mode-test.el     |  4 ++++
 4 files changed, 74 insertions(+), 4 deletions(-)

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..bcddc7bf10 100644
--- a/tests/php-mode-test.el
+++ b/tests/php-mode-test.el
@@ -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))



reply via email to

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