emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/phps-mode 4e5be4f8f8 112/212: More indentation work for


From: Christian Johansson
Subject: [elpa] externals/phps-mode 4e5be4f8f8 112/212: More indentation work for mixed PHP/HTML content
Date: Wed, 26 Jan 2022 01:51:08 -0500 (EST)

branch: externals/phps-mode
commit 4e5be4f8f8232c9e632a1f450c9450316b00e68f
Author: Christian Johansson <christian@cvj.se>
Commit: Christian Johansson <christian@cvj.se>

    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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]