[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode c6e4deec40 4/9: Improved indentation for chai
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode c6e4deec40 4/9: Improved indentation for chained expressions |
Date: |
Mon, 15 Jan 2024 08:24:59 -0500 (EST) |
branch: externals/phps-mode
commit c6e4deec405d580482c37422b171987f8f6b9ed3
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Improved indentation for chained expressions
---
phps-mode-indent.el | 27 ++++++++++++---------------
test/phps-mode-test-indent.el | 18 ++++++++++++++----
2 files changed, 26 insertions(+), 19 deletions(-)
diff --git a/phps-mode-indent.el b/phps-mode-indent.el
index 665cc9387b..9ce4595577 100644
--- a/phps-mode-indent.el
+++ b/phps-mode-indent.el
@@ -391,10 +391,11 @@ Optionally start FROM-END-OF-LINE."
(and
not-found-bracket-start
(search-backward-regexp
- "\\([][{}()=\n;]\\|->\\|^[\ t]*\\.\\|\\.[\t ]*$\\)"
+ "\\(=>\\|[][{}()=\n;]\\|->\\|^[\ t]*\\.\\|\\.[\t ]*$\\)"
nil
t))
(let ((match (match-string-no-properties 0)))
+ ;; (message "match: %S" match)
(cond
((string-match-p
@@ -404,7 +405,13 @@ Optionally start FROM-END-OF-LINE."
not-found-bracket-start
nil))
+ ((string= "=>" match))
+
((string= "\n" match)
+ (when (and
+ same-line-p
+ (> parenthesis-level 0))
+ (setq parenthesis-level 0))
(setq
same-line-p
nil)
@@ -424,19 +431,7 @@ Optionally start FROM-END-OF-LINE."
nil)
(setq
reference-line-delta
- line-delta))
- (setq
- reference-line
- nil)
- (setq
- reference-line-delta
- nil)
- (setq
- reference-line-previous
- nil)
- (setq
- reference-line-previous-delta
- nil))
+ line-delta)))
(setq
line-delta
(1- line-delta)))
@@ -464,7 +459,9 @@ Optionally start FROM-END-OF-LINE."
(setq
parenthesis-level
(1+ parenthesis-level))
- (when (= parenthesis-level 1)
+ (when (and
+ (not same-line-p)
+ (= parenthesis-level 1))
(setq
rewind-reference-line
t)
diff --git a/test/phps-mode-test-indent.el b/test/phps-mode-test-indent.el
index f20ea2f876..4dd25a6104 100644
--- a/test/phps-mode-test-indent.el
+++ b/test/phps-mode-test-indent.el
@@ -325,6 +325,16 @@ STRING with NAME with optional NEW-STRING."
(message "Passed chaining test #10")
+ (with-temp-buffer
+ (insert "<?php\n\nif ($you) {\n if ($here) {\n if ($true) {\n
if ($a = 23) {\n $myObject->build(array(\n
'name' => 'Trueman',\n 'sku' => 25.0\n
))\n ->test()\n ->validate()\n
->give();\n }\n }\n }\n}\n")
+ (goto-char 272)
+ (should
+ (equal
+ (phps-mode-indent--get-previous-start-of-chaining)
+ " ->test()")))
+
+ (message "Passed chaining test #11")
+
(should
(equal
(phps-mode-indent--get-html-string-bracket-level "<!DOCTYPE html>")
@@ -668,7 +678,7 @@ STRING with NAME with optional NEW-STRING."
"Line after multi-line function call inside if condition list")
(phps-mode-test-indent--should-equal
- "<?php\n\nif (\n (!isset(Meta()->login)\n || !$name =
Meta()->login->name())\n && $override\n) {\n echo 'here';\n}\n"
+ "<?php\n\nif (\n (!isset(Meta()->login)\n || !$name =
Meta()->login->name())\n && $override\n) {\n echo 'here';\n}\n"
"Line after multi-line condition in parenthesis")
(phps-mode-test-indent--should-equal
@@ -676,7 +686,7 @@ STRING with NAME with optional NEW-STRING."
"Line after variable not equal condition")
(phps-mode-test-indent--should-equal
- "<?php\n\nif (\n (is_array($data)\n && !empty($data['index'])\n
&& (is_a($data['index'], 'Index')\n || is_a($data['Index'],
'Index2')))\n || is_a($data, 'WC_Index')\n) {\n\n}\n"
+ "<?php\n\nif (\n (is_array($data)\n && !empty($data['index'])\n
&& (is_a($data['index'], 'Index')\n || is_a($data['Index'],
'Index2')))\n || is_a($data, 'WC_Index')\n) {\n \n}\n"
"Line after multi-line condition in parenthesis 2")
(phps-mode-test-indent--should-equal
@@ -713,7 +723,7 @@ STRING with NAME with optional NEW-STRING."
"<?php\nif (true) {\n echo 'here';\n /* something */\n echo
'there';\n}\n")
(phps-mode-test-indent--should-equal
- "<?php\nif (true) {\n $variable1 = (true\n ? true\n :
false);\n\n $variable2 = (true\n ? true\n : false);\n\n
$variable3 = myFunction(true);\n echo 'here';\n\n}\n"
+ "<?php\nif (true) {\n $variable1 = (true\n ? true\n :
false);\n \n $variable2 = (true\n ? true\n : false);\n
\n $variable3 = myFunction(true);\n echo 'here';\n \n}\n"
"Line after multi-line parenthesized logical expression in assignment")
(phps-mode-test-indent--should-equal
@@ -757,7 +767,7 @@ STRING with NAME with optional NEW-STRING."
"Plain HTML markup")
(phps-mode-test-indent--should-equal
- "<?php\n\nif (true) {\n if (\n true\n ) {\n return
false;\n }\n\n /**\n * My first line,\n * my second line.\n
*\n * @since Module 1.0.0\n */\n echo 'here';\n\n}\n"
+ "<?php\n\nif (true) {\n if (\n true\n ) {\n return
false;\n }\n \n /**\n * My first line,\n * my second line.\n
*\n * @since Module 1.0.0\n */\n echo 'here';\n \n}\n"
"Doc-comment ending with comma and dot.")
(phps-mode-test-indent--should-equal
- [elpa] externals/phps-mode updated (378f886bdb -> 70559d0374), Christian Johansson, 2024/01/15
- [elpa] externals/phps-mode 9d5a82910a 1/9: Garbage collection fix for parser generation, Christian Johansson, 2024/01/15
- [elpa] externals/phps-mode c6e4deec40 4/9: Improved indentation for chained expressions,
Christian Johansson <=
- [elpa] externals/phps-mode ba5e20dcc6 7/9: Fixed more byte-compilation notices, Christian Johansson, 2024/01/15
- [elpa] externals/phps-mode 9e9f4f9fb2 8/9: Updated copyright years, Christian Johansson, 2024/01/15
- [elpa] externals/phps-mode 70559d0374 9/9: Updated modified date and version, Christian Johansson, 2024/01/15
- [elpa] externals/phps-mode 8e92fccb49 2/9: Using PHP 8.3 grammar for parser generation, Christian Johansson, 2024/01/15
- [elpa] externals/phps-mode 738adb2eca 3/9: Work on indentation errors Emacs 29.1, Christian Johansson, 2024/01/15
- [elpa] externals/phps-mode 52556fd141 5/9: Fixes for byte-compilation notices, Christian Johansson, 2024/01/15
- [elpa] externals/phps-mode 616fd806df 6/9: Updated version of parser generator library, Christian Johansson, 2024/01/15