branch: master commit 5e34bec7fcfaaaf9c7bd34bd718ea52d2f991dfe Author: Jackson Ray Hamilton <jack...@jacksonrayhamilton.com> Commit: Jackson Ray Hamilton <jack...@jacksonrayhamilton.com>
Cover malformed defun cases. --- context-coloring.el | 36 ++++++++++++++++++------------------ test/context-coloring-test.el | 6 +++++- test/fixtures/defun.el | 3 +++ 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 7787cb5..6954b10 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -420,24 +420,24 @@ generated by `js2-mode'." ((context-coloring-emacs-lisp-identifier-syntax-p child-1-syntax-code) (setq child-1-end (scan-sexps child-1-pos 1)) ;; defuns are global so use level 0 - (context-coloring-colorize-region child-1-pos child-1-end 0))) - (goto-char child-1-end) - ;; Lookahead for parameters - (skip-syntax-forward " " end) - (when (= 4 (logand #xFFFF (car (syntax-after (point))))) - (setq child-2-end (scan-sexps (point) 1)) - (setq defun-arglist (read (buffer-substring-no-properties - (point) - child-2-end))) - (while defun-arglist - (setq defun-arg (car defun-arglist)) - (when (and (symbolp defun-arg) - (string-match-p "\\`[^&:]" (symbol-name defun-arg))) - (context-coloring-scope-add-variable - (car scope-stack) - defun-arg)) - (setq defun-arglist (cdr defun-arglist)))) - (goto-char child-2-end) + (context-coloring-colorize-region child-1-pos child-1-end 0) + (goto-char child-1-end) + ;; Lookahead for parameters + (skip-syntax-forward " " end) + (when (= 4 (logand #xFFFF (car (syntax-after (point))))) + (setq child-2-end (scan-sexps (point) 1)) + (setq defun-arglist (read (buffer-substring-no-properties + (point) + child-2-end))) + (while defun-arglist + (setq defun-arg (car defun-arglist)) + (when (and (symbolp defun-arg) + (string-match-p "\\`[^&:]" (symbol-name defun-arg))) + (context-coloring-scope-add-variable + (car scope-stack) + defun-arg)) + (setq defun-arglist (cdr defun-arglist))) + (goto-char child-2-end)))) ;; Cleanup (setq in-defun-p nil)) (t diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el index 8bd91fd..393b4c7 100644 --- a/test/context-coloring-test.el +++ b/test/context-coloring-test.el @@ -1015,7 +1015,11 @@ see that function." (context-coloring-test-assert-region-level 40 53 1) ; def ghi jkl (context-coloring-test-assert-region-level 53 57 0) ; free (context-coloring-test-assert-region-level 57 59 1) ; )) - (context-coloring-test-assert-region-level 61 72 0)) ; (abc 1 2 3) + (context-coloring-test-assert-region-level 61 72 0) ; (abc 1 2 3) + (context-coloring-test-assert-region-level 74 81 1) ; (defun + (context-coloring-test-assert-region-level 81 82 0) ; a + (context-coloring-test-assert-region-level 82 83 1) ; ) + (context-coloring-test-assert-region-level 84 94 1)) ; (defun ()) (provide 'context-coloring-test) diff --git a/test/fixtures/defun.el b/test/fixtures/defun.el index 9ed7b7b..a5bd039 100644 --- a/test/fixtures/defun.el +++ b/test/fixtures/defun.el @@ -2,3 +2,6 @@ (+ def ghi jkl free)) (abc 1 2 3) + +(defun a) +(defun ())