branch: externals/phps-mode commit a85266985c898cc4bfe955c8b9a5936394da23e9 Author: Christian Johansson <christ...@cvj.se> Commit: Christian Johansson <christ...@cvj.se>
Fix bug in syntax colouring, added debug outputs for incremental lexer --- phps-mode-functions.el | 14 +++++--------- phps-mode-lexer.el | 27 +++++++++++++++------------ 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/phps-mode-functions.el b/phps-mode-functions.el index ba1ab50..b3ae09b 100644 --- a/phps-mode-functions.el +++ b/phps-mode-functions.el @@ -46,7 +46,6 @@ ;; NOTE Also format white-space inside the line, i.e. after function declarations? -;; TODO Add support for automatic parenthesis, bracket, square-bracket, single-quote and double-quote encapsulations (defun phps-mode-functions-get-buffer-changes-start () "Get buffer change start." @@ -54,6 +53,7 @@ (defun phps-mode-functions-reset-buffer-changes-start () "Reset buffer change start." + (message "Reset flag for buffer changes") (setq phps-mode-functions-buffer-changes-start nil)) (defun phps-mode-functions-process-current-buffer () @@ -755,7 +755,7 @@ ))))))) -(defun phps-mode-functions-after-change (start _stop _length) +(defun phps-mode-functions-after-change (start stop _length) "Track buffer change from START to STOP with length LENGTH." (when (string= major-mode "phps-mode") @@ -763,15 +763,14 @@ (when (and (not phps-mode-functions-buffer-changes-start) (boundp 'phps-mode-idle-interval) phps-mode-idle-interval) - ;; (message "Enqueued incremental lexer") - + (message "Enqueued incremental lexer") (run-with-idle-timer phps-mode-idle-interval nil #'phps-mode-lexer-run-incremental)) ;; When point of change is not set or when start of new changes precedes old change - update the point (when (or (not phps-mode-functions-buffer-changes-start) (< start phps-mode-functions-buffer-changes-start)) - ;; (message "Setting start of changes from %s to %s" phps-mode-functions-buffer-changes-start start) - (setq phps-mode-functions-buffer-changes-start start)) + (setq phps-mode-functions-buffer-changes-start start) + (message "Setting start of changes to: %s-%s" phps-mode-functions-buffer-changes-start stop)) ;; (message "phps-mode-functions-after-change %s %s %s" start stop length) )) @@ -811,9 +810,6 @@ (set (make-local-variable 'comment-start) "/* ") (set (make-local-variable 'comment-end) " */") - ;; TODO Make (uncomment-region) work - ;; TODO Make selecting region and clicking ' wrap region in single quotes - ;; Support for change detection (add-hook 'after-change-functions #'phps-mode-functions-after-change)) diff --git a/phps-mode-lexer.el b/phps-mode-lexer.el index 5438252..1a52fae 100644 --- a/phps-mode-lexer.el +++ b/phps-mode-lexer.el @@ -211,32 +211,37 @@ (cond ((or + (string= token 'T_STRING) (string= token 'T_VARIABLE) (string= token 'T_STRING_VARNAME)) (overlay-put (make-overlay start end) 'font-lock-face 'font-lock-variable-name-face)) - ((or (string= token 'T_STRING) - (string= token 'T_NUM_STRING)) - (overlay-put (make-overlay start end) 'font-lock-face 'font-lock-string-face)) + ((or (string= token 'T_FUNCTION)) + (overlay-put (make-overlay start end) 'font-lock-face 'font-lock-function-name-face)) ((string= token 'T_INLINE_HTML) - (overlay-put (make-overlay start end) 'font-lock-face 'font-lock-reference-face)) + (overlay-put (make-overlay start end) 'font-lock-face 'font-lock-comment-delimiter-face)) ((string= token 'T_COMMENT) (overlay-put (make-overlay start end) 'font-lock-face 'font-lock-comment-face)) ((string= token 'T_DOC_COMMENT) - (overlay-put (make-overlay start end) 'font-lock-face 'font-lock-comment-delimiter-face)) + (overlay-put (make-overlay start end) 'font-lock-face 'font-lock-doc-face)) ((or (string= token 'T_CONSTANT_ENCAPSED_STRING) (string= token 'T_ENCAPSED_AND_WHITESPACE) + (string= token 'T_NUM_STRING) (string= token 'T_DNUMBER) (string= token 'T_LNUMBER) ) (overlay-put (make-overlay start end) 'font-lock-face 'font-lock-string-face)) ((or + (string= token 'T_CONST)) + (overlay-put (make-overlay start end) 'font-lock-face 'font-lock-constant-face)) + + ((or (string= token "?") (string= token "!") (string= token "<") @@ -257,8 +262,6 @@ (string= token 'T_NS_SEPARATOR) (string= token 'T_EXIT) (string= token 'T_DIE) - (string= token 'T_FUNCTION) - (string= token 'T_CONST) (string= token 'T_RETURN) (string= token 'T_YIELD_FROM) (string= token 'T_YIELD) @@ -1594,7 +1597,7 @@ (defun phps-mode-lexer-setup (start end) "Just prepare other lexers for lexing region START to END." - ;; (message "phps-mode-lexer-setup %s %s" start end) + (message "phps-mode-lexer-setup %s %s" start end) ;; Flag that buffer has not been processed (when (and (boundp 'phps-mode-functions-processed-buffer) @@ -1612,6 +1615,7 @@ (defun phps-mode-lexer-run () "Run lexer." (interactive) + (message "Running lexer") (setq phps-mode-lexer-tokens (semantic-lex-buffer))) (defun phps-mode-lexer-move-states (start diff) @@ -1662,6 +1666,7 @@ (defun phps-mode-lexer-run-incremental () "Run incremental lexer based on `(phps-mode-functions-get-buffer-changes-start)'." + (message "Running incremental lexer") (when (and (phps-mode-functions-get-buffer-changes-start) phps-mode-lexer-states) (let ((state nil) @@ -1718,14 +1723,12 @@ (setq phps-mode-lexer-state_stack state-stack) (setq phps-mode-lexer-states new-states) - ;; TODO Should clear overlays after point of change here ;; (message "Rewinding lex to state: %s and stack: %s and states: %s and start: %s old tokens: %s" state state-stack new-states previous-token-start old-tokens) - ;; TODO Here clear all tokens after previous-token-start and add new tokens to stack )) ;; (display-warning "phps-mode" (format "Found no state to rewind to for %s in stack %s, buffer point max: %s" change-start states (point-max))) - (phps-mode-lexer-run))) - (phps-mode-functions-reset-buffer-changes-start))) + (phps-mode-lexer-run)))) + (phps-mode-functions-reset-buffer-changes-start)) (define-lex phps-mode-lexer-lex "Call lexer analyzer action."