branch: externals/phps-mode commit 52c502c5ec73c9df0437294b1edf0ac027ea1337 Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
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)))) )