branch: externals/phps-mode
commit db019887afa12eaa3fb311300531dfbb82dceb92
Author: Christian Johansson <[email protected]>
Commit: Christian Johansson <[email protected]>
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"