[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 806bb902b3 122/212: Improved indentation for
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode 806bb902b3 122/212: Improved indentation for chaining objects |
Date: |
Wed, 26 Jan 2022 01:51:12 -0500 (EST) |
branch: externals/phps-mode
commit 806bb902b3c053fda3c9aac846191a43a1a1fb58
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Improved indentation for chaining objects
---
phps-mode-indent.el | 116 ++++++++++++++++++++++++++++++++++++++++--
test/phps-mode-test-indent.el | 2 +-
2 files changed, 112 insertions(+), 6 deletions(-)
diff --git a/phps-mode-indent.el b/phps-mode-indent.el
index ee117ead07..7b7318eb69 100644
--- a/phps-mode-indent.el
+++ b/phps-mode-indent.el
@@ -762,12 +762,14 @@
(parenthesis-level 0)
(is-bracket-less-command nil)
(is-same-line-p t)
+ (is-object-chaining)
+ (is-object-chaining-on-same-line)
(bracket-opened-on-first-line))
(while
(and
not-found
(search-backward-regexp
- "\\(;\\|{\\|(\\|)\\|=\\|echo[\t ]+\\|print[\t
]+\\|\n\\|<<<'?\"?[a-zA-Z0-9]+'?\"?\\)"
+ "\\(;\\|{\\|(\\|)\\|=\\|echo[\t ]+\\|print[\t
]+\\|\n\\|<<<'?\"?[a-zA-Z0-9]+'?\"?\\|->\\)"
nil
t))
(let ((match (match-string-no-properties 0)))
@@ -791,6 +793,14 @@
(setq
parenthesis-level
(1- parenthesis-level)))
+ ((string= match "->")
+ (when (= parenthesis-level 0)
+ (setq
+ is-object-chaining
+ t)
+ (setq
+ is-object-chaining-on-same-line
+ is-same-line-p)))
((= parenthesis-level 0)
(setq is-assignment (string= match "="))
(setq is-bracket-less-command
@@ -799,11 +809,13 @@
match))
(setq not-found nil)))))
- (when (and
- (not is-same-line-p)
+ (when (or
(and
- is-assignment
- (not bracket-opened-on-first-line)))
+ (not is-same-line-p)
+ is-assignment)
+ (and
+ (not is-object-chaining-on-same-line)
+ is-object-chaining))
(setq
new-indentation
(- new-indentation tab-width)))
@@ -980,6 +992,100 @@
new-indentation
(+ new-indentation tab-width)))
+ ;; $myObject->myFunction()
+ ;; ->myFunction2()
+ ((string-match-p
+ "->"
+ previous-line-string)
+ (let ((not-found t)
+ (started-chaining-on-this-line t)
+ (is-assignment)
+ (is-string-concatenation)
+ (parenthesis-level 0)
+ (is-bracket-less-command)
+ (is-same-line-p t)
+ (bracket-opened-on-first-line))
+ (while
+ (and
+ not-found
+ (search-backward-regexp
+ "\\(;\\|{\\|(\\|)\\|=\\|->\\|echo[\t ]+\\|print[\t
]+\\|\n\\|^[\t ]*\\.\\|\\.[\t ]*$\\)"
+ nil
+ t))
+ (let ((match (match-string-no-properties 0)))
+ (cond
+
+ ((string=
+ "->"
+ match)
+ (setq
+ started-chaining-on-this-line
+ is-same-line-p))
+
+ ((string=
+ "\n"
+ match)
+ (setq
+ is-same-line-p
+ nil))
+
+ ((or
+ (string=
+ "echo"
+ match)
+ (string=
+ "print"
+ match))
+ (setq
+ is-bracket-less-command
+ t)
+ (setq
+ not-found
+ nil))
+
+ ((or
+ (string=
+ ";"
+ match)
+ (string=
+ "}"
+ match))
+ (setq
+ not-found
+ nil))
+
+ ((string=
+ "="
+ match)
+ (setq
+ is-assignment
+ t)
+ (setq
+ not-found
+ nil))
+
+ ((string-match-p
+ "\\(^[\t ]*\\.\\|\\.[\t ]*\\)$"
+ match)
+ (setq
+ is-string-concatenation
+ t)
+ (setq
+ not-found
+ nil))
+
+ )))
+
+ (when (and
+ (not is-assignment)
+ (not is-string-concatenation)
+ (not started-chaining-on-this-line)
+ (not is-bracket-less-command))
+ (setq
+ new-indentation
+ (+ new-indentation tab-width))))
+ (goto-char point))
+
;; /**
;; *
;; */
diff --git a/test/phps-mode-test-indent.el b/test/phps-mode-test-indent.el
index 010b841b6f..f74feaa133 100644
--- a/test/phps-mode-test-indent.el
+++ b/test/phps-mode-test-indent.el
@@ -198,7 +198,7 @@
"Indentation of chained class method calls outside of assignments and
conditionals")
(phps-mode-test-indent--should-equal
- "<?php\n\n$myVar = $myClass->meMethod()\n ->mySecondMethod()\n
->myThirdMethod()\n->myFourthFunction(\n $myVariable\n);"
+ "<?php\n\n$myVar = $myClass->meMethod()\n ->mySecondMethod()\n
->myThirdMethod()\n ->myFourthFunction(\n $myVariable\n );"
"Indentation for chained object operators in assignment with method call
with arguments")
(phps-mode-test-indent--should-equal
- [elpa] externals/phps-mode e95df1027b 042/212: Reverted old tests for imenu and bookkeeping for lex-analyzer, (continued)
- [elpa] externals/phps-mode e95df1027b 042/212: Reverted old tests for imenu and bookkeeping for lex-analyzer, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode a65c8af308 008/212: Extract ast code into separate file and test, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 23c001c33f 037/212: Moved parser SDT to separate file, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 261121f096 056/212: Fixed incorrect information in debug output in test, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode e8a47de694 052/212: Work on supported arrow functions for bookkeeping via AST, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 5686703a6b 074/212: Passing bookkeeping via AST for $this inside arrow function body inside class method, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode a9d0e941df 066/212: Started on SDT for static variables statement, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode a8fecdfd68 055/212: Bookkeeping of variables inside arrow functions now working, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode e42646dc3a 058/212: Added SDT for isset() and empty(), Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 9ad46d061e 057/212: Bookkeeping via AST passing two more tests, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 806bb902b3 122/212: Improved indentation for chaining objects,
Christian Johansson <=
- [elpa] externals/phps-mode cc3bf03786 123/212: Improved indentation after ending assignment expression, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 3162dca5c4 159/212: Added two more failing indentation tests, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 1e44021653 163/212: Added more failing indent tests, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode e7aff3f69d 157/212: Passed more indentation tests, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode db7121941c 156/212: Passing indention on line after not equals condition, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode d072fe5315 136/212: Improved indentation around array elements, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode f880ba2d62 164/212: Improved indentation on lines after assignment that ends with closing bracket, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode db019887af 170/212: Passed new indentation tests, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 781356557c 194/212: More adjustments to indent helper to find previous command, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 0735959c08 209/212: Using silent cache write, Christian Johansson, 2022/01/26