branch: externals/phps-mode commit 4098f46f2ce9296836b6eacc04430bbaa232d11b Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
Started with incremental lexer --- phps-functions.el | 5 +++++ phps-lexer.el | 13 +++++++++++-- phps-mode.el | 3 +++ sample-php-files/class.php | 8 ++++++-- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/phps-functions.el b/phps-functions.el index bcd50ce..8b1538d 100644 --- a/phps-functions.el +++ b/phps-functions.el @@ -41,6 +41,7 @@ (autoload 'phps-mode/lexer-get-point-data "phps-lexer") +;; TODO Should also format white-space inside the line, i.e. after function declarations (defun phps-mode/indent-line () "Indent line." (let ((data (phps-mode/lexer-get-point-data))) @@ -92,6 +93,7 @@ ;; (message "inside scripting, start: %s, end: %s, indenting to column %s " start end indent-level) (indent-line-to (* indent-level tab-width))))))))) +;; TODO Implement this (defun phps-mode/indent-region () "Indent region." ) @@ -101,6 +103,9 @@ (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") + (when (and (not phps-mode/buffer-changes--start) + (boundp 'phps-mode/idle-interval)) + (run-with-idle-timer phps-mode/idle-interval nil #'phps-mode/run-incremental-lex)) (setq phps-mode/buffer-changes--start start) (message "phps-mode/after-change-functions %s %s %s" start stop length) )) diff --git a/phps-lexer.el b/phps-lexer.el index 37e1c56..04b0edd 100644 --- a/phps-lexer.el +++ b/phps-lexer.el @@ -1327,9 +1327,11 @@ ANY_CHAR' (defun phps-mode/lex--SETUP (start end) "Just prepare other lexers for lexing region START to END." - (when (eq start 1) + (when (and (eq start 1) + end) ;; (message "SETUP %s %s" start end) - (setq phps-mode/buffer-changes--start nil) + (when (boundp 'phps-mode/buffer-changes--start) + (setq phps-mode/buffer-changes--start nil)) (phps-mode/BEGIN phps-mode/ST_INITIAL))) (defun phps-mode/lex--RUN () @@ -1337,6 +1339,13 @@ ANY_CHAR' (interactive) (setq phps-mode/lexer-tokens (semantic-lex-buffer))) +(defun phps-mode/run-incremental-lex () + "Run incremental lexer based on `phps-mode/buffer-changes--start'." + (when (boundp 'phps-mode/buffer-changes--start) + (message "Should run incremental lex here %s - %s" phps-mode/buffer-changes--start (point-max)) + (semantic-lex phps-mode/buffer-changes--start (point-max)) + (setq phps-mode/buffer-changes--start nil))) + (define-lex phps-mode/tags-lexer "Lexer that handles PHP buffers." diff --git a/phps-mode.el b/phps-mode.el index d950c00..cc4a714 100644 --- a/phps-mode.el +++ b/phps-mode.el @@ -60,6 +60,9 @@ (defvar phps-mode/use-psr-2 t "Whether to use PSR-2 guidelines for white-space or not.") +(defvar phps-mode/idle-interval 1 + "Idle seconds before running incremental lexer.") + (define-derived-mode phps-mode prog-mode "PHPs" "Major mode for PHP with Semantic integration." diff --git a/sample-php-files/class.php b/sample-php-files/class.php index 50c292a..c7ac743 100644 --- a/sample-php-files/class.php +++ b/sample-php-files/class.php @@ -4,16 +4,20 @@ * @todo was here */ -class MyClass { +class MyClass +{ /** * @var string */ - private $var = 'abc'; + private $var = 'abcdef'; public function myMethod() { echo "Some stuff here"; // Just a comment + if ($this->var) { + + } } public function myMethod2() {