branch: externals/phps-mode commit 80da137f7a2bb47046b5c6fc8f636d0c145431a7 Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
Preparations for adding alternative and inline syntax --- phps-mode-functions.el | 32 +++++++++++++++++++------------- phps-mode-test-functions.el | 32 ++++++++++++++++---------------- 2 files changed, 35 insertions(+), 29 deletions(-) diff --git a/phps-mode-functions.el b/phps-mode-functions.el index 788781c..2a450dd 100644 --- a/phps-mode-functions.el +++ b/phps-mode-functions.el @@ -50,16 +50,18 @@ (let ((start-curly-bracket-level (nth 1 start)) (start-round-bracket-level (nth 2 start)) (start-square-bracket-level (nth 3 start)) - (_start-inline-function-level (nth 4 start)) - (start-token-number (nth 5 start)) + (start-inline-control-structure-level (nth 4 start)) + (start-alternative-control-structure-level (nth 5 start)) + (start-token-number (nth 6 start)) (end-curly-bracket-level (nth 1 end)) (end-round-bracket-level (nth 2 end)) (end-square-bracket-level (nth 3 end)) - (_end-inline-function-level (nth 4 end)) - (end-token-number (nth 5 end)) - (in-doc-comment (nth 6 start))) - (let* ((indent-start (+ start-curly-bracket-level start-round-bracket-level start-square-bracket-level)) - (indent-end (+ end-curly-bracket-level end-round-bracket-level end-square-bracket-level)) + (end-inline-control-structure-level (nth 4 end)) + (end-alternative-control-structure-level (nth 5 end)) + (end-token-number (nth 6 end)) + (in-doc-comment (nth 7 start))) + (let* ((indent-start (+ start-curly-bracket-level start-round-bracket-level start-square-bracket-level start-inline-control-structure-level start-alternative-control-structure-level)) + (indent-end (+ end-curly-bracket-level end-round-bracket-level end-square-bracket-level end-inline-control-structure-level end-alternative-control-structure-level)) (indent-level indent-start) (indent-adjust 0)) ;; (message "indent-start %s, indent-end %s" indent-start indent-end) @@ -194,7 +196,8 @@ ;; (message "phps-mode-functions-after-change %s %s %s" start stop length) )) -;; TODO This function needs to keep track of alternative syntax for control structures +;; TODO This function needs to keep track of alternative syntax for the control structures: if, while, for, foreach, and switch +;; TODO This function needs to keep track of inline syntax for the control structures: if, while, for, foreach, and switch (defun phps-mode-functions-get-point-data () "Return information about point in tokens." @@ -208,16 +211,19 @@ (start-curly-bracket-level 0) (start-round-bracket-level 0) (start-square-bracket-level 0) - (start-inline-function-level 0) + (start-inline-control-structure-level 0) + (start-alternative-control-structure-level 0) (start-token-number nil) (end-in-scripting nil) (end-curly-bracket-level 0) (end-round-bracket-level 0) (end-square-bracket-level 0) - (end-inline-function-level 0) + (end-inline-control-structure-level 0) + (end-alternative-control-structure-level 0) (end-token-number nil) (line-in-doc-comment nil) - (found-line-tokens nil)) + (found-line-tokens nil) + (_after-special-control-structure nil)) (catch 'stop-iteration (dolist (item phps-mode-lexer-tokens) (let ((token (car item)) @@ -236,7 +242,7 @@ (<= token-end line-end)) (setq found-line-tokens t)) - ;; When end of token is equal or less to current point + ;; When end of token is equal or less to beginning of current line (when (<= token-end line-beginning) (when (null start-token-number) (setq start-token-number -1)) @@ -284,7 +290,7 @@ (when (not found-line-tokens) (setq start-token-number nil) (setq end-token-number nil)) - (let ((data (list (list start-in-scripting start-curly-bracket-level start-round-bracket-level start-square-bracket-level start-inline-function-level start-token-number line-in-doc-comment) (list end-in-scripting end-curly-bracket-level end-round-bracket-level end-square-bracket-level end-inline-function-level end-token-number line-in-doc-comment)))) + (let ((data (list (list start-in-scripting start-curly-bracket-level start-round-bracket-level start-square-bracket-level start-inline-control-structure-level start-alternative-control-structure-level start-token-number line-in-doc-comment) (list end-in-scripting end-curly-bracket-level end-round-bracket-level end-square-bracket-level end-inline-control-structure-level end-alternative-control-structure-level end-token-number line-in-doc-comment)))) ;; (message "data: %s" data) data))))) diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el index 51e8b57..19f95a8 100644 --- a/phps-mode-test-functions.el +++ b/phps-mode-test-functions.el @@ -256,82 +256,82 @@ (phps-mode-test-with-buffer "<?php\nNAMESPACE MyNameSpace;\nCLASS MyClass {\n\tpublic function __construct() {\n\t\texit;\n\t}\n}\n" (goto-char 35) - (should (equal (list (list t 0 0 0 0 3 nil) (list t 1 0 0 0 6 nil)) (phps-mode-functions-get-point-data)))) + (should (equal (list (list t 0 0 0 0 0 3 nil) (list t 1 0 0 0 0 6 nil)) (phps-mode-functions-get-point-data)))) (phps-mode-test-with-buffer "<html><head><title><?php echo $title; ?></title><body>Bla bla</body></html>" (goto-char 15) - (should (equal (list (list nil 0 0 0 0 nil nil) (list nil 0 0 0 0 5 nil)) (phps-mode-functions-get-point-data)))) + (should (equal (list (list nil 0 0 0 0 0 nil nil) (list nil 0 0 0 0 0 5 nil)) (phps-mode-functions-get-point-data)))) (phps-mode-test-with-buffer "<html><head><title><?php echo $title; ?>\n</title><body>Bla bla</body></html>" (goto-char 50) - (should (equal (list (list nil 0 0 0 0 nil nil) (list nil 0 0 0 0 nil nil)) (phps-mode-functions-get-point-data)))) + (should (equal (list (list nil 0 0 0 0 0 nil nil) (list nil 0 0 0 0 0 nil nil)) (phps-mode-functions-get-point-data)))) (phps-mode-test-with-buffer "<html><head><title></title><body>Bla bla</body></html>" (goto-char 15) - (should (equal (list (list nil 0 0 0 0 nil nil) (list nil 0 0 0 0 nil nil)) (phps-mode-functions-get-point-data)))) + (should (equal (list (list nil 0 0 0 0 0 nil nil) (list nil 0 0 0 0 0 nil nil)) (phps-mode-functions-get-point-data)))) (phps-mode-test-with-buffer "<html><head><title><?php echo $title; ?></title><body>Bla bla</body></html>" (goto-char 30) - (should (equal (list (list nil 0 0 0 0 nil nil) (list nil 0 0 0 0 5 nil)) (phps-mode-functions-get-point-data)))) + (should (equal (list (list nil 0 0 0 0 0 nil nil) (list nil 0 0 0 0 0 5 nil)) (phps-mode-functions-get-point-data)))) (phps-mode-test-with-buffer "<html><head><title><?php echo $title; ?></title><body>Bla bla</body></html>" (goto-char 50) - (should (equal (list (list nil 0 0 0 0 nil nil) (list nil 0 0 0 0 5 nil)) (phps-mode-functions-get-point-data)))) + (should (equal (list (list nil 0 0 0 0 0 nil nil) (list nil 0 0 0 0 0 5 nil)) (phps-mode-functions-get-point-data)))) (phps-mode-test-with-buffer "<html><head><title><?php if ($myCondition) { \n if ($mySeconCondition) { echo $title; } } ?></title><body>Bla bla</body></html>" (goto-char 48) - (should (equal (list (list t 1 0 0 0 5 nil) (list nil 0 0 0 0 17 nil)) (phps-mode-functions-get-point-data)))) + (should (equal (list (list t 1 0 0 0 0 5 nil) (list nil 0 0 0 0 0 17 nil)) (phps-mode-functions-get-point-data)))) (phps-mode-test-with-buffer "<html><head><title><?php if ($myCondition) { if ($mySeconCondition) {\n echo $title;\n} } ?></title><body>Bla bla</body></html>" (goto-char 72) - (should (equal (list (list t 2 0 0 0 10 nil) (list t 2 0 0 0 13 nil)) (phps-mode-functions-get-point-data)))) + (should (equal (list (list t 2 0 0 0 0 10 nil) (list t 2 0 0 0 0 13 nil)) (phps-mode-functions-get-point-data)))) (phps-mode-test-with-buffer "<html><head><title><?php if ($myCondition) {\nif ($mySeconCondition) {\necho $title;\n}\n}\n ?></title><body>Bla bla</body></html>" (goto-char 84) - (should (equal (list (list t 2 0 0 0 13 nil) (list t 1 0 0 0 14 nil)) (phps-mode-functions-get-point-data)))) + (should (equal (list (list t 2 0 0 0 0 13 nil) (list t 1 0 0 0 0 14 nil)) (phps-mode-functions-get-point-data)))) (phps-mode-test-with-buffer "<html><head><title><?php if ($myCondition) { if ($mySeconCondition) { echo $title; } } ?></title><body>Bla bla</body></html>" (goto-char 100) - (should (equal (list (list nil 0 0 0 0 nil nil) (list nil 0 0 0 0 17 nil)) (phps-mode-functions-get-point-data)))) + (should (equal (list (list nil 0 0 0 0 0 nil nil) (list nil 0 0 0 0 0 17 nil)) (phps-mode-functions-get-point-data)))) (phps-mode-test-with-buffer "<?php /**\n * My first line\n * My second line\n **/" (goto-char 20) - (should (equal (list (list t 0 0 0 0 nil t) (list t 0 0 0 0 nil t)) (phps-mode-functions-get-point-data)))) + (should (equal (list (list t 0 0 0 0 0 nil t) (list t 0 0 0 0 0 nil t)) (phps-mode-functions-get-point-data)))) (phps-mode-test-with-buffer "<?php /**\n * My first line\n * My second line\n **/" (goto-char 9) - (should (equal (list (list nil 0 0 0 0 nil nil) (list t 0 0 0 0 1 nil)) (phps-mode-functions-get-point-data)))) + (should (equal (list (list nil 0 0 0 0 0 nil nil) (list t 0 0 0 0 0 1 nil)) (phps-mode-functions-get-point-data)))) (phps-mode-test-with-buffer "<?php /**\n * My first line\n * My second line\n **/" (goto-char 50) - (should (equal (list (list t 0 0 0 0 nil t) (list t 0 0 0 0 nil t)) (phps-mode-functions-get-point-data)))) + (should (equal (list (list t 0 0 0 0 0 nil t) (list t 0 0 0 0 0 nil t)) (phps-mode-functions-get-point-data)))) (phps-mode-test-with-buffer "<?php\n$variable = array(\n'random4');\n$variable = true;\n" (goto-char 29) - (should (equal (list (list t 0 1 0 0 4 nil) (list t 0 0 0 0 7 nil)) (phps-mode-functions-get-point-data)))) + (should (equal (list (list t 0 1 0 0 0 4 nil) (list t 0 0 0 0 0 7 nil)) (phps-mode-functions-get-point-data)))) (phps-mode-test-with-buffer "<?php\nif (empty(\n$this->var\n) && !empty($this->var)\n) {\n$this->var = 'abc123';\n}\n" (goto-char 54) - (should (equal (list (list t 0 1 0 0 16 nil) (list t 1 0 0 0 18 nil)) (phps-mode-functions-get-point-data)))) + (should (equal (list (list t 0 1 0 0 0 16 nil) (list t 1 0 0 0 0 18 nil)) (phps-mode-functions-get-point-data)))) (phps-mode-test-with-buffer "<?php\n$var = [\n 'random' => [\n 'hello',\n ],\n];\n" (goto-char 46) - (should (equal (list (list t 0 0 2 0 6 nil) (list t 0 0 2 0 8 nil)) (phps-mode-functions-get-point-data)))) + (should (equal (list (list t 0 0 2 0 0 6 nil) (list t 0 0 2 0 0 8 nil)) (phps-mode-functions-get-point-data)))) )