branch: externals/phps-mode
commit 4e5be4f8f8232c9e632a1f450c9450316b00e68f
Author: Christian Johansson <[email protected]>
Commit: Christian Johansson <[email protected]>
More indentation work for mixed PHP/HTML content
---
phps-mode-indent.el | 43 ++++++++++++++++++++++++++++---------------
test/phps-mode-test-indent.el | 2 +-
2 files changed, 29 insertions(+), 16 deletions(-)
diff --git a/phps-mode-indent.el b/phps-mode-indent.el
index 85c6427bc8..239360b04f 100644
--- a/phps-mode-indent.el
+++ b/phps-mode-indent.el
@@ -68,49 +68,56 @@
"If STRING start with closing bracket, return it, otherwise return nil."
(phps-mode-indent--string-starts-with-regexp
string
- "[\t ]*\\([\]})]\\)"
- 1))
+ "[\t ]*\\(<\\?php[\t\n ]*\\)?\\([\]})]\\)"
+ 2))
(defun phps-mode-indent--string-starts-with-opening-bracket (string)
"If STRING start with opening bracket return it otherwise nil."
(phps-mode-indent--string-starts-with-regexp
string
- "[\t ]*\\([\[{(]\\)"
- 1))
+ "[\t ]*\\(<\\?php[\t\n ]*\\)?\\([\[{(]\\)"
+ 2))
(defun phps-mode-indent--string-starts-with-opening-doc-comment (string)
"Does STRING start with opening doc comment?"
(phps-mode-indent--string-starts-with-regexp
string
- "[\t ]*\\(/\\*\\*\\)"
- 1))
+ "[\t ]*\\(<\\?php[\t\n ]*\\)?\\(/\\*\\*\\)"
+ 2))
(defun phps-mode-indent--string-ends-with-assignment (string)
"If STRING end with terminus, return it, otherwise return nil."
(phps-mode-indent--string-ends-with-regexp
string
- "\\(=>?\\)[\t ]*"
+ "\\(=>?\\)[\t ]*\\(\\?>[\t\n ]*\\)?"
1))
(defun phps-mode-indent--string-ends-with-closing-bracket (string)
"If STRING end with closing bracket, return it, otherwise nil."
(phps-mode-indent--string-ends-with-regexp
string
- "\\([\]})]\\)[\t ]*"
+ "\\([\]})]\\)[\t ]*\\(\\?>[\t\n ]*\\)?"
+ 1))
+
+(defun phps-mode-indent--string-ends-with-closing-doc-comment (string)
+ "If STRING end with closing doc comment, return it, otherwise nil."
+ (phps-mode-indent--string-ends-with-regexp
+ string
+ "\\(\\*/\\)[\t ]*\\(\\?>[\t\n ]*\\)?"
1))
(defun phps-mode-indent--string-ends-with-opening-bracket (string)
"If STRING end with opening bracket, return it, otherwise nil."
(phps-mode-indent--string-ends-with-regexp
string
- "\\([\[{(]\\)[\t ]*"
+ "\\([\[{(]\\)[\t ]*\\(\\?>[\t\n ]*\\)?"
1))
(defun phps-mode-indent--string-ends-with-terminus (string)
"If STRING end with terminus, return it, otherwise return nil."
(phps-mode-indent--string-ends-with-regexp
string
- "\\(;\\|,\\)[\t ]*"
+ "\\(;\\|,\\)[\t ]*\\(\\?>[\t\n ]*\\)?"
1))
@@ -215,6 +222,9 @@
(previous-line-starts-with-opening-doc-comment
(phps-mode-indent--string-starts-with-opening-doc-comment
previous-line-string))
+ (previous-line-starts-with-closing-doc-comment
+ (phps-mode-indent--string-ends-with-closing-doc-comment
+ previous-line-string))
(previous-line-ends-with-assignment
(phps-mode-indent--string-ends-with-assignment
previous-line-string))
@@ -533,10 +543,11 @@
(setq
new-indentation
first-concatenated-line-indent))
- ;; This is the first concatenated line so we indent it
- (setq
- new-indentation
- (+ new-indentation tab-width)))
+ (unless (= previous-bracket-level tab-width)
+ ;; This is the first concatenated line so we indent it
+ (setq
+ new-indentation
+ (+ new-indentation tab-width))))
;; Reset point
(goto-char old-point)))
@@ -660,7 +671,9 @@
(when current-line-starts-with-closing-bracket
(setq new-indentation (- new-indentation tab-width)))
- (when previous-line-starts-with-opening-doc-comment
+ (when (and
+ previous-line-starts-with-opening-doc-comment
+ (not previous-line-starts-with-closing-doc-comment))
(setq new-indentation (+ new-indentation 1)))
(when (and
diff --git a/test/phps-mode-test-indent.el b/test/phps-mode-test-indent.el
index 211c2cbb3a..907d8e51b0 100644
--- a/test/phps-mode-test-indent.el
+++ b/test/phps-mode-test-indent.el
@@ -122,7 +122,7 @@
"Concatenated single-quoted-string spanning multiple-lines inside function
2")
(phps-mode-test-indent--should-equal
- "<?php\necho <<<EOD\nExample of string\nspanning multiple lines\nusing
heredoc syntax.\nEOD;\n"
+ "<?php\necho <<<EOD\nExample of string\nspanning multiple lines\nusing
heredoc syntax\nEOD;\n"
"Multi-line HEREDOC string outside assignment")
(phps-mode-test-indent--should-equal