branch: externals/phps-mode commit abcfd01b57d7a05896ef699c78db4087c75eea03 Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
Started with function to gather current point data --- README.md | 3 ++- phps-functions.el | 11 ++++------- phps-lexer.el | 22 +++++++++++++++++++++- phps-test-lexer.el | 13 ++++++++++--- sample-php-files/class.php | 5 +++++ 5 files changed, 42 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 090c8de..51e9237 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,8 @@ With current progress estimates: * Flycheck support (100%) * Lexer based on official PHP re2c lexer (100%) * Syntax coloring based on lexer tokens (100%) -* PSR based indentation based on lexer tokens (0%) +* Incremental lexer and syntax coloring after changes (0%) +* PSR based indentation based on lexer tokens (20%) * Wisent LALR parser based on official PHP yacc parser automatically converted (60%) * Flymake support (0%) * Full integration with Emacs Semantic subsystem (0%) diff --git a/phps-functions.el b/phps-functions.el index 2366c43..48aac15 100644 --- a/phps-functions.el +++ b/phps-functions.el @@ -38,20 +38,17 @@ (defun phps-mode/indent-line () "Indent line." - (save-excursion - (move-beginning-of-line nil) - ) ) (defun phps-mode/indent-region () - "Indent region.") + "Indent region." + ) (defun phps-mode/functions-init () "PHP specific init-cleanup routines." - ;; (set (make-local-variable 'indent-line-function) 'phps-mode/indent-line) - ;; (set (make-local-variable 'indent-line-function) 'phps-mode/indent-region) - + ;; (set (make-local-variable 'indent-line-function) #'phps-mode/indent-line) + ;; (set (make-local-variable 'indent-line-function) #'phps-mode/indent-region) ) diff --git a/phps-lexer.el b/phps-lexer.el index 58c704b..d9b6493 100644 --- a/phps-lexer.el +++ b/phps-lexer.el @@ -1255,12 +1255,31 @@ ANY_CHAR' )) +(defun phps-mode/lexer-get-point-data() + "Return information about point in tokens." + (message "Point: %s in %s" (point) phps-mode/lexer-tokens) + (dolist (item phps-mode/lexer-tokens) + ) + ) + (defun phps-mode/lex--SETUP (start end) "Just prepare other lexers for lexing region START to END." (when (eq start 1) ;; (message "SETUP %s %s" start end) (phps-mode/BEGIN phps-mode/ST_INITIAL))) +;; TODO This function should track between what min and max region a specific buffer has been modified and then re-run lexer for that region when editor is idle, maybe use (buffer-name)) +;; maybe use 'auto-save-hook for this +(defun phps-mode/after-change-functions (start stop length) + "Track buffer change from START to STOP with length LENGTH." + (when (string= major-mode "phps-mode") + ;; (message "phps-mode/after-change-functions %s %s %s" start stop length) + )) + +(defun phps-mode/lex--RUN () + "Run lexer." + (interactive) + (setq phps-mode/lexer-tokens (semantic-lex-buffer))) (define-lex phps-mode/tags-lexer "Lexer that handles PHP buffers." @@ -1284,7 +1303,8 @@ ANY_CHAR' (setq semantic-lex-syntax-table phps-mode/syntax-table)) (setq semantic-lex-analyzer #'phps-mode/tags-lexer) (add-hook 'semantic-lex-reset-functions #'phps-mode/lex--SETUP) - (setq phps-mode/lexer-tokens (semantic-lex-buffer))) + (add-hook 'after-change-functions #'phps-mode/after-change-functions) + (phps-mode/lex--RUN)) (provide 'phps-mode/lexer) diff --git a/phps-test-lexer.el b/phps-test-lexer.el index b2744cc..a45db16 100644 --- a/phps-test-lexer.el +++ b/phps-test-lexer.el @@ -54,8 +54,6 @@ (kill-buffer test-buffer) )) -(defun phps-mode/token-stream-to-string (IGNORE)) - (defun phps-mode/test-lexer--script-boundaries () "Run test for lexer." @@ -239,7 +237,15 @@ (should (equal phps-mode/lexer-tokens '((T_OPEN_TAG 1 . 7) (T_START_HEREDOC 7 . 16) (T_ERROR 16 . 55))))) -) + ) + +(defun phps-mode/test-lexer-get-point-data () + "Return information about point in tokens." + (phps-mode/with-test-buffer + "<?php\nNAMESPACE MyNameSpace;\nCLASS MyClass {\n\tpublic function __construct() {\n\t\texit;\n\t}\n}\n" + (goto-char 30) + (phps-mode/lexer-get-point-data)) + ) (defun phps-mode/test-lexer () "Run test for lexer." @@ -250,6 +256,7 @@ (phps-mode/test-lexer--complex-tokens) (phps-mode/test-lexer--namespaces) (phps-mode/test-lexer--errors) + (phps-mode/test-lexer-get-point-data) ;; (message "\n-- Ran all tests for lexer. --") ) diff --git a/sample-php-files/class.php b/sample-php-files/class.php index 3fa7bf4..fef6bfe 100644 --- a/sample-php-files/class.php +++ b/sample-php-files/class.php @@ -28,4 +28,9 @@ class MyClass { $this->var = '\\'; } + public function heres_more_information() { + $var = '23ac'; + $var2 = '123'; + } + }