[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode db019887af 170/212: Passed new indentation te
From: |
Christian Johansson |
Subject: |
[elpa] externals/phps-mode db019887af 170/212: Passed new indentation tests |
Date: |
Wed, 26 Jan 2022 01:51:22 -0500 (EST) |
branch: externals/phps-mode
commit db019887afa12eaa3fb311300531dfbb82dceb92
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>
Passed new indentation tests
---
phps-mode-indent.el | 70 ++++++++++++++++++++-----------------------
test/phps-mode-test-indent.el | 18 +++++++----
2 files changed, 44 insertions(+), 44 deletions(-)
diff --git a/phps-mode-indent.el b/phps-mode-indent.el
index bc91f701f6..5210ccb3d7 100644
--- a/phps-mode-indent.el
+++ b/phps-mode-indent.el
@@ -911,73 +911,67 @@
match-type
'line-after-line-that-ends-with-semicolon)
- ;; Back-trace buffer from previous line
- ;; Determine if semi-colon ended an multi-line assignment or
bracket-less command or not
- ;; If it's on the same line we ignore it
+ ;; Back-trace buffer from previous line semi-colon
+ ;; find line where command started
+ ;; use that lines indentation for this line
(forward-line (* -1 move-length1))
(end-of-line)
(search-backward-regexp ";" nil t) ;; Skip the semi-colon
(let ((not-found t)
- (reference-line)
- (reference-indentation)
- (parenthesis-level 0))
+ (reference-line
+ (buffer-substring-no-properties
+ (line-beginning-position)
+ (line-end-position)))
+ (reference-indentation))
(while
(and
not-found
(search-backward-regexp
- "\\(;\\|{\\|[a-zA-Z_]+[a-zA-Z0-9_]*[\t
]*(\\|)\\|=$\\|=[^>]\\|return\\|echo[\t ]+\\|print[\t
]+\\|\n\\|<<<'?\"?[a-zA-Z0-9_]+'?\"?\\)"
+ "^[\t ]*[^\t ]+.*$"
nil
t))
(let ((match (match-string-no-properties 0)))
(cond
- ((string= match "\n"))
-
- ;; Start of HEREDOC / NOWDOC
+ ;; Commented out line
((string-match-p
- "<<<'?\"?[a-zA-Z0-9_]+'?\"?"
- match)
+ "^[\t ]*//"
+ match))
+
+ ;; A separate command
+ ((or
+ (string-match-p
+ "{[\t ]*$"
+ match)
+ (string-match-p
+ "\\(;\\|:\\)[\t ]*$"
+ match)
+ (string-match-p
+ "[\t ]*<\\?"
+ match))
(setq
not-found
nil))
- ;; Function call
- ((string-match-p
- "[a-zA-Z_]+[a-zA-Z0-9_]*[\t ]*("
- match)
+ (t
(setq
- parenthesis-level
- (1+ parenthesis-level))
- (when (= parenthesis-level 0)
- (setq
- not-found
- nil)))
+ reference-line
+ (buffer-substring-no-properties
+ (line-beginning-position)
+ (line-end-position))))
- ((string= match ")")
- (setq
- parenthesis-level
- (1- parenthesis-level)))
+ )))
- ((= parenthesis-level 0)
- (setq
- not-found
- nil)))))
(goto-char point)
(unless not-found
- (setq
- reference-line
- (buffer-substring-no-properties
- (line-beginning-position)
- (line-end-position)))
+ ;; (message "reference-line: %S" reference-line)
(setq
reference-indentation
(phps-mode-indent--string-indentation
reference-line))
- ;; TODO The line after should use the same indentation
- ;; as the line starting the command
- (setq
+ (setq
new-indentation
reference-indentation))))
diff --git a/test/phps-mode-test-indent.el b/test/phps-mode-test-indent.el
index e3d18a8643..2f8dd35f1e 100644
--- a/test/phps-mode-test-indent.el
+++ b/test/phps-mode-test-indent.el
@@ -31,18 +31,23 @@
(random (- line-max-position line-min-position)))))
(execute-kbd-macro (kbd "TAB"))))
-(defun phps-mode-test-indent--should-equal (string name)
- "Test indent of whole buffer containing STRING with NAME."
+(defun phps-mode-test-indent--should-equal (string name &optional new-string)
+ "Test indent of whole buffer containing STRING with NAME with optional
NEW-STRING."
(phps-mode-test--with-buffer
string
name
(message "Initial buffer:\n%S" string)
(phps-mode-test-indent--indent-whole-buffer)
- (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max))))
+ (let ((buffer-contents (buffer-substring-no-properties (point-min)
(point-max)))
+ (test-string string))
+ (when new-string
+ (setq
+ test-string
+ new-string))
(message "\nIndented buffer:\n%S" buffer-contents)
(should (equal
buffer-contents
- string)))))
+ test-string)))))
(defun phps-mode-test-indent--helpers ()
"Test helper functions."
@@ -245,7 +250,7 @@
"Return statements in class")
(phps-mode-test-indent--should-equal
- "$var = myFunction(\n 'setting');\necho 'here';\n"
+ "<?php\n$var = myFunction(\n 'setting');\necho 'here';\n"
"Multi-line assignment from function ending without opening bracket")
(phps-mode-test-indent--should-equal
@@ -406,7 +411,8 @@
(phps-mode-test-indent--should-equal
"<?php\nif (true) {\n echo 'here';\n/* something */\n echo
'there';\n}\n"
- "Line after commented out lines with wrong indentation")
+ "Line after commented out lines with wrong indentation"
+ "<?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"
- [elpa] externals/phps-mode e42646dc3a 058/212: Added SDT for isset() and empty(), (continued)
- [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, 2022/01/26
- [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 <=
- [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
- [elpa] externals/phps-mode e3bf9e8fed 059/212: SDT rules for some more infix operations, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 2bc31a0f83 065/212: Added TODO items, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode d802a669c0 061/212: Bookkeeping via AST working with isset() and !empty() scoped variables, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode d9115ec583 069/212: Cleaned up AST bookkeeping tests, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode f4d2164f8b 067/212: Bookkeeping via parser SDT passing static variables in function, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode e66abd00e5 064/212: Bookkeeping via AST passing nested isset() !empty() expressions, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 8b5ce22d87 072/212: Fixed issue with SDT for return statement, Christian Johansson, 2022/01/26
- [elpa] externals/phps-mode 491c82a2a1 071/212: Added TODO item for bookkeeping via AST, Christian Johansson, 2022/01/26