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

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

[elpa] externals/phps-mode 52c502c 139/405: Improved logic for doc-comme


From: Stefan Monnier
Subject: [elpa] externals/phps-mode 52c502c 139/405: Improved logic for doc-comment tracking
Date: Sat, 13 Jul 2019 10:00:00 -0400 (EDT)

branch: externals/phps-mode
commit 52c502c5ec73c9df0437294b1edf0ac027ea1337
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>

    Improved logic for doc-comment tracking
---
 phps-mode-functions.el      | 43 ++++++++++++++++++++++++-------------------
 phps-mode-test-functions.el | 24 +++++++++++++++++++++---
 2 files changed, 45 insertions(+), 22 deletions(-)

diff --git a/phps-mode-functions.el b/phps-mode-functions.el
index 69d413e..f5a6985 100644
--- a/phps-mode-functions.el
+++ b/phps-mode-functions.el
@@ -135,25 +135,30 @@
                           (equal token 'T_ELSEIF))
                   (setq after-special-control-structure round-bracket-level))
 
-                ;; Keep track of in scripting
-                (when (or (equal token 'T_OPEN_TAG)
-                          (equal token 'T_OPEN_TAG_WITH_ECHO))
-                  (setq in-scripting t))
-                (when (equal token 'T_CLOSE_TAG)
-                  (setq in-scripting nil))
-
-                ;; Keep track of whether we are inside a doc-comment
-                (when (equal token 'T_DOC_COMMENT)
-                  (setq in-doc-comment token-end))
-                (when (and in-doc-comment
-                           (> token-start in-doc-comment))
-                  (setq in-doc-comment nil))
-
-                ;; Keep track of whether we are inside a HEREDOC or NOWDOC
-                (when (equal token 'T_START_HEREDOC)
-                  (setq in-heredoc t))
-                (when (equal token 'T_END_HEREDOC)
-                  (setq in-heredoc nil))
+                ;; Does token end before current line begins?
+                (when (< token-start line-beginning)
+
+                  ;; Keep track of in scripting
+                  (when (or (equal token 'T_OPEN_TAG)
+                            (equal token 'T_OPEN_TAG_WITH_ECHO))
+                    (setq in-scripting t))
+                  (when (equal token 'T_CLOSE_TAG)
+                    (setq in-scripting nil))
+
+                  ;; Keep track of whether we are inside a doc-comment
+                  (when (equal token 'T_DOC_COMMENT)
+                    (setq in-doc-comment token-end))
+                  (when (and in-doc-comment
+                             (> token-start in-doc-comment))
+                    (setq in-doc-comment nil))
+
+                  ;; Keep track of whether we are inside a HEREDOC or NOWDOC
+                  (when (equal token 'T_START_HEREDOC)
+                    (setq in-heredoc t))
+                  (when (equal token 'T_END_HEREDOC)
+                    (setq in-heredoc nil))
+
+                  )
 
                 ;; Are we on a new line?
                 (when (> token-line-number last-line-number)
diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el
index e5b89b1..7a91214 100644
--- a/phps-mode-test-functions.el
+++ b/phps-mode-test-functions.el
@@ -37,26 +37,44 @@
 (defun phps-mode-test-functions-get-current-line-indent ()
   "Test `phps-mode-functions-get-current-line-indent' function."
 
+  ;; Mixed HTML/PHP
+
   (phps-mode-test-with-buffer
-   "<html><head><title><?php if ($myCondition) {\nif ($mySeconCondition) 
{\necho $title;\n\n} ?></title><body>Bla bla</body></html>"
+   "<html><head><title><?php\nif ($myCondition) {\nif ($mySeconCondition) 
{\necho $title;\n\n} ?></title><body>Bla bla</body></html>"
+   (goto-char 15)
+   (should (equal nil (phps-mode-functions-get-current-line-indent))))
+
+  (phps-mode-test-with-buffer
+   "<html><head><title><?php\nif ($myCondition) {\nif ($mySeconCondition) 
{\necho $title;\n\n} ?></title><body>Bla bla</body></html>"
    (goto-char 69)
    (should (equal '(1 0) (phps-mode-functions-get-current-line-indent))))
 
   (phps-mode-test-with-buffer
-   "<html><head><title><?php if ($myCondition) {\nif ($mySeconCondition) 
{\necho $title;\n\n} ?></title><body>Bla bla</body></html>"
+   "<html><head><title><?php\nif ($myCondition) {\nif ($mySeconCondition) 
{\necho $title;\n\n} ?></title><body>Bla bla</body></html>"
    (goto-char 40)
    (should (equal '(0 0) (phps-mode-functions-get-current-line-indent))))
 
   (phps-mode-test-with-buffer
-   "<html><head><title><?php if ($myCondition) {\nif ($mySeconCondition) 
{\necho $title;\n\n} ?></title><body>Bla bla</body></html>"
+   "<html><head><title><?php\nif ($myCondition) {\nif ($mySeconCondition) 
{\necho $title;\n\n} ?></title><body>Bla bla</body></html>"
    (goto-char 75)
    (should (equal '(2 0) (phps-mode-functions-get-current-line-indent))))
 
+  ;; DOC-COMMENT
+
   (phps-mode-test-with-buffer
    "<?php\n/**\n* Bla\n*/"
    (goto-char 13)
    (should (equal '(0 1) (phps-mode-functions-get-current-line-indent))))
 
+  (phps-mode-test-with-buffer
+   "<?php\n/**\n* Bla\n*/"
+   (goto-char 8)
+   (should (equal '(0 0) (phps-mode-functions-get-current-line-indent))))
+
+  (phps-mode-test-with-buffer
+   "<?php\n/**\n* Bla\n*/"
+   (goto-char 17)
+   (should (equal '(0 1) (phps-mode-functions-get-current-line-indent))))
 
   )
 



reply via email to

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