[elpa] master updated (e42b97b -> b525e2d)
jackson pushed a change to branch master. from e42b97b Update seq.el to version 1.7 new 056be97 Add URL to header. new eb429df Use lowercase for hex codes. new d9d901f Add basic elisp defun coloring. new 5e34bec Cover malformed defun cases. new 8919acd Add lambda coloring. new 62506ae Add quote and number coloring. new 636e6b9 Add elisp comments and strings support. new 284cfa6 Don't treat unbindables like variables. new 3e3141f Refactor elisp tests to use visual assertions. new 5acd088 Add non-recursive let* coloring. new 58b7474 Don't color function calls as level 0. new dd8d491 Also color defsubst. new 171883f Add let coloring. new b4072c1 Trivial refactoring for clarity. new c830ae5 Fix let* test. new ea3ff31 Pass let* test. new 926d74a Include binding order in let* test. new 29328af Add let test. new b28e896 Add complex nesting to let test. new bd9c147 Ignore the dot. new d7b2c92 Remove unused functions. new 0836b9f Add change hooks for elisp. new 08bf3e4 Ignore question marks. new 09ec36e Add interruption mechanism. new dc2f9a6 Refactor maybe-colorize-comments-and-strings. new a556195 Tweak iteration values, add logging. new 3fc5b20 Make dispatches fully redefinable. new 89f20e4 Improve interruptability of syntactic coloring. new ef544ef Fontify keywords. new 07c5852 Add idle change teardown function. new d24de46 Add TODO. new 5c5b429 Fix font-lock error. new c0a6689 Only set defaults when the mode is enabled. new 59a6c8e Fix timer disposal and timer buffer detection. new 88a921f Improve defun regexp. new 438cb33 Fix incorrect last fontified position. new 1d7761c Add constant comment test. new 4bbce56 Add test for interruption. new 4ff6e82 Remove verbose parsing. new 6392d1f Bind optional parameters earlier. new 708276e Compiler micro-optimizations. new 5051a70 Update documentation for emacs lisp. new 6a4ad31 Add derived mode support. new 3b6a391 Minor cleanup. new c6e173b Merge branch 'elisp' new 3bf805d Version 6.3.0. new b525e2d Merge commit '3bf805df83fe6f110f3e7e8ce2dc37e0cf6c14cb' from context-coloring Summary of changes: packages/context-coloring/README.md| 46 +- packages/context-coloring/context-coloring.el | 751 .../context-coloring/test/context-coloring-test.el | 275 +++- packages/context-coloring/test/fixtures/comment.el |3 + packages/context-coloring/test/fixtures/defun.el |7 + packages/context-coloring/test/fixtures/ignored.el |2 + .../context-coloring/test/fixtures/iteration.el|2 + packages/context-coloring/test/fixtures/lambda.el |3 + packages/context-coloring/test/fixtures/let*.el| 11 + packages/context-coloring/test/fixtures/let.el |8 + packages/context-coloring/test/fixtures/quote.el |4 + packages/context-coloring/test/fixtures/string.el |2 + 12 files changed, 947 insertions(+), 167 deletions(-) create mode 100644 packages/context-coloring/test/fixtures/comment.el create mode 100644 packages/context-coloring/test/fixtures/defun.el create mode 100644 packages/context-coloring/test/fixtures/ignored.el create mode 100644 packages/context-coloring/test/fixtures/iteration.el create mode 100644 packages/context-coloring/test/fixtures/lambda.el create mode 100644 packages/context-coloring/test/fixtures/let*.el create mode 100644 packages/context-coloring/test/fixtures/let.el create mode 100644 packages/context-coloring/test/fixtures/quote.el create mode 100644 packages/context-coloring/test/fixtures/string.el
[elpa] master 8919acd 05/47: Add lambda coloring.
branch: master commit 8919acd4b2c2104ed2538dbe9835befe361dec3b Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Add lambda coloring. --- context-coloring.el | 76 ++--- test/context-coloring-test.el | 11 ++ test/fixtures/lambda.el |3 ++ 3 files changed, 55 insertions(+), 35 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 6954b10..5f443dd 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -344,6 +344,7 @@ generated by `js2-mode'." (scope-stack `(,(context-coloring-make-scope -1 0))) ; -1 never matches a depth one-word-found-p in-defun-p + in-lambda-p function-call-p defun-arglist defun-arg @@ -390,15 +391,18 @@ generated by `js2-mode'." (setq child-0-string (buffer-substring-no-properties child-0-pos child-0-end)) (cond ((string-match-p "defun\\|defmacro" child-0-string) -(setq in-defun-p t) -(setq scope-stack (cons (context-coloring-make-scope - (nth 0 ppss) - (1+ (context-coloring-scope-get-level - (car scope-stack -scope-stack))) +(setq in-defun-p t)) + ((string-match-p "lambda" child-0-string) +(setq in-lambda-p t)) ;; Assume a global function call (t (setq function-call-p t) +(when (or in-defun-p in-lambda-p) + (setq scope-stack (cons (context-coloring-make-scope + (nth 0 ppss) + (1+ (context-coloring-scope-get-level +(car scope-stack + scope-stack))) ;; TODO: Probably redundant and wasteful (context-coloring-colorize-region token-pos (scan-sexps token-pos 1) @@ -408,38 +412,40 @@ generated by `js2-mode'." (context-coloring-colorize-region child-0-pos child-0-end 0) (setq function-call-p nil)) (cond - (in-defun-p + ((or in-defun-p in-lambda-p) (goto-char child-0-end) - ;; Lookahead for defun name - (skip-syntax-forward " " end) - (setq child-1-pos (point)) - (setq child-1-syntax (syntax-after child-1-pos)) - (setq child-1-syntax-code (logand #x (car child-1-syntax))) - (cond - ;; Word - ((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 + (when in-defun-p +;; Lookahead for defun name (skip-syntax-forward " " end) -(when (= 4 (logand #x (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 +(setq child-1-pos (point)) +(setq child-1-syntax (syntax-after child-1-pos)) +(setq child-1-syntax-code (logand #x (car child-1-syntax))) +(cond + ;; Word + ((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 #x (car (syntax-after (point) +(setq child-2-end (scan-sexps (point) 1)) +(setq defun-arglist (read (buffer-substring-no-properties +
[elpa] master 056be97 01/47: Add URL to header.
branch: master commit 056be97c4ebf24fa06d4d09407692f43c69b614d Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Add URL to header. --- context-coloring.el |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index d73773a..d32a27d 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -5,8 +5,8 @@ ;; Author: Jackson Ray Hamilton ;; Version: 6.2.1 ;; Keywords: convenience faces tools -;; Homepage: https://github.com/jacksonrayhamilton/context-coloring ;; Package-Requires: ((emacs "24") (js2-mode "20150126")) +;; URL: https://github.com/jacksonrayhamilton/context-coloring ;; This file is part of GNU Emacs.
[elpa] master 171883f 13/47: Add let coloring.
branch: master commit 171883fa4f044bc5c4acf0042531f1b160a8e7d6 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Add let coloring. --- context-coloring.el |8 +++- 1 files changed, 7 insertions(+), 1 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index a84a1b4..9c31314 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -375,6 +375,7 @@ generated by `js2-mode'." one-word-found-p in-defun-p in-lambda-p + in-let-p in-let*-p defun-arglist defun-arg @@ -472,10 +473,13 @@ generated by `js2-mode'." (setq in-defun-p t)) ((string-match-p "\\`lambda\\'" child-0-string) (setq in-lambda-p t)) + ((string-match-p "\\`let\\'" child-0-string) +(setq in-let-p t)) ((string-match-p "\\`let\\*\\'" child-0-string) (setq in-let*-p t) (when (or in-defun-p in-lambda-p + in-let-p in-let*-p) (setq scope-stack (cons (context-coloring-make-scope (nth 0 ppss) @@ -524,7 +528,8 @@ generated by `js2-mode'." ;; Cleanup (setq in-defun-p nil) (setq in-lambda-p nil)) - (in-let*-p + ((or in-let-p + in-let*-p) (goto-char child-0-end) ;; Lookahead for bindings (context-coloring-forward-sws) @@ -552,6 +557,7 @@ generated by `js2-mode'." (setq let-varlist (cdr let-varlist))) (goto-char child-1-end)) ;; Cleanup + (setq in-let-p nil) (setq in-let*-p nil)) (t (goto-char (cond
[elpa] master 636e6b9 07/47: Add elisp comments and strings support.
branch: master commit 636e6b9e655724be822605cb2971a2110bbd215f Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Add elisp comments and strings support. --- context-coloring.el | 22 ++- test/context-coloring-test.el | 132 + test/fixtures/comment.el |3 + test/fixtures/string.el |2 + 4 files changed, 104 insertions(+), 55 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index d5da9da..92e4578 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -345,6 +345,10 @@ generated by `js2-mode'." (or (= 2 syntax-code) (= 3 syntax-code))) +(defun context-coloring-forward-sws () + "Move forward through whitespace and comments." + (while (forward-comment 1))) + (defun context-coloring-emacs-lisp-colorize () "Color the current buffer by parsing emacs lisp sexps." (with-silent-modifications @@ -395,6 +399,18 @@ generated by `js2-mode'." (1+ token-pos (cond + ;; Resolve invalid state + ((cond + ;; Inside string? + ((nth 3 ppss) + (skip-syntax-forward "^\"" end) + (forward-char) + t) + ;; Inside comment? + ((nth 4 ppss) + (skip-syntax-forward "^>" end) ; comment ender + t))) + ;; Expression prefix ;; Has to come first in case of commas ((= 6 token-syntax-code) @@ -426,7 +442,7 @@ generated by `js2-mode'." ((= 4 token-syntax-code) (forward-char) ;; Lookahead for scopes / function calls -(skip-syntax-forward " " end) +(context-coloring-forward-sws) (setq child-0-pos (point)) (setq child-0-syntax (syntax-after child-0-pos)) (setq child-0-syntax-code (logand #x (car child-0-syntax))) @@ -463,7 +479,7 @@ generated by `js2-mode'." (goto-char child-0-end) (when in-defun-p ;; Lookahead for defun name -(skip-syntax-forward " " end) +(context-coloring-forward-sws) (setq child-1-pos (point)) (setq child-1-syntax (syntax-after child-1-pos)) (setq child-1-syntax-code (logand #x (car child-1-syntax))) @@ -475,7 +491,7 @@ generated by `js2-mode'." (context-coloring-colorize-region child-1-pos child-1-end 0) (goto-char child-1-end ;; Lookahead for parameters - (skip-syntax-forward " " end) + (context-coloring-forward-sws) (when (= 4 (logand #x (car (syntax-after (point) (setq child-2-end (scan-sexps (point) 1)) (setq defun-arglist (read (buffer-substring-no-properties diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el index 95c52e0..192d2ef 100644 --- a/test/context-coloring-test.el +++ b/test/context-coloring-test.el @@ -44,13 +44,12 @@ (defun context-coloring-test-setup () "Prepare before all tests." - (setq context-coloring-comments-and-strings nil)) + (setq context-coloring-syntactic-comments nil) + (setq context-coloring-syntactic-strings nil)) (defun context-coloring-test-cleanup () "Cleanup after all tests." - (setq context-coloring-comments-and-strings t) - (setq context-coloring-syntactic-comments nil) - (setq context-coloring-syntactic-strings nil) + (setq context-coloring-comments-and-strings nil) (setq context-coloring-js-block-scopes nil) (setq context-coloring-colorize-hook nil) (setq context-coloring-check-scopifier-version-hook nil) @@ -167,24 +166,22 @@ format." ',setup-function-name (,function-name) -(defmacro context-coloring-test-emacs-lisp-mode (fixture &rest body) - "Use FIXTURE as the subject matter for test logic in BODY." - `(context-coloring-test-with-fixture -,fixture -(emacs-lisp-mode) -(context-coloring-mode) -,@body)) - -(defmacro context-coloring-test-deftest-emacs-lisp-mode (name &rest body) +(cl-defmacro context-coloring-test-deftest-emacs-lisp-mode (name +body +&key setup) "Define a test for `emacs-lisp-mode' with name and fixture as -NAME, with BODY containing the assertions." +NAME, with BODY containing the assertions, and SETUP defining the +environment." (declare (indent defun)) (let ((test-name (intern (format "context-coloring-emacs-lisp-mode-%s" name))) (fixture (format "./fixtures/%s.el" name))) `(ert-deftest ,test-name () - (context-coloring-test-emacs-lisp-mode + (context-coloring-test-with-fixture ,fixture -,@body +(emacs-lisp-mode) +(when ,setup (funcall ,setup)) +
[elpa] master 3e3141f 09/47: Refactor elisp tests to use visual assertions.
branch: master commit 3e3141fd99a4a8662a1ed5777d0e8262a279974c Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Refactor elisp tests to use visual assertions. --- test/context-coloring-test.el | 163 +++-- test/fixtures/lambda.el |4 +- 2 files changed, 110 insertions(+), 57 deletions(-) diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el index 8e5b699..93e0517 100644 --- a/test/context-coloring-test.el +++ b/test/context-coloring-test.el @@ -186,6 +186,87 @@ environment." ;;; Assertion functions +(defun context-coloring-test-assert-position-level (position level) + "Assert that POSITION has LEVEL." + (let ((face (get-text-property position 'face)) +actual-level) +(when (not (and face +(let* ((face-string (symbol-name face)) + (matches (string-match + context-coloring-level-face-regexp + face-string))) + (when matches +(setq actual-level (string-to-number +(substring face-string + (match-beginning 1) + (match-end 1 +(= level actual-level) + (ert-fail (format (concat "Expected level at position %s, " +"which is \"%s\", to be %s; " +"but it was %s") +position +(buffer-substring-no-properties position (1+ position)) level +actual-level) + +(defun context-coloring-test-assert-position-face (position face-regexp) + "Assert that the face at POSITION satisfies FACE-REGEXP." + (let ((face (get-text-property position 'face))) +(when (or + ;; Pass a non-string to do an `eq' check (against a symbol or nil). + (unless (stringp face-regexp) + (not (eq face-regexp face))) + ;; Otherwise do the matching. + (when (stringp face-regexp) + (not (string-match-p face-regexp (symbol-name face) + (ert-fail (format (concat "Expected face at position %s, " +"which is \"%s\", to be %s; " +"but it was %s") +position +(buffer-substring-no-properties position (1+ position)) face-regexp +face) + +(defun context-coloring-test-assert-position-comment (position) + (context-coloring-test-assert-position-face + position "\\`font-lock-comment\\(-delimiter\\)?-face\\'")) + +(defun context-coloring-test-assert-position-string (position) + (context-coloring-test-assert-position-face position 'font-lock-string-face)) + +(defun context-coloring-test-assert-coloring (map) + "Assert that the current buffer's coloring matches MAP." + ;; Omit the superfluous, formatting-related leading newline. + (save-excursion +(goto-char (point-min)) +(let* ((map (substring map 1)) + (index 0) + char-string + char) + (while (< index (length map)) +(setq char-string (substring map index (1+ index))) +(setq char (string-to-char char-string)) +(cond + ;; Newline + ((= char 10) + (next-logical-line) + (beginning-of-line)) + ;; Number + ((and (>= char 48) + (<= char 57)) + (context-coloring-test-assert-position-level + (point) (string-to-number char-string)) + (forward-char)) + ;; ';' = Comment + ((= char 59) + (context-coloring-test-assert-position-comment (point)) + (forward-char)) + ;; 's' = String + ((= char 115) + (context-coloring-test-assert-position-string (point)) + (forward-char)) + (t + (forward-char))) +(setq index (1+ index)) + (defmacro context-coloring-test-assert-region (&rest body) "Assert something about the face of points in a region. Provides the free variables `i', `length', `point', `face' and @@ -1006,81 +1087,53 @@ see that function." (context-coloring-test-deftest-emacs-lisp-mode defun (lambda () -(context-coloring-test-assert-region-level 1 8 1); (defun -(context-coloring-test-assert-region-level 8 11 0) ; abc -(context-coloring-test-assert-region-level 11 39 1) ; (def ghi &optional jkl) ( -(context-coloring-test-assert-region-level 39 40 0) ; + -(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
[elpa] master 62506ae 06/47: Add quote and number coloring.
branch: master commit 62506ae9653eae070b1e329be2b7fc7a32572fbb Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Add quote and number coloring. --- context-coloring.el | 80 ++-- test/context-coloring-test.el | 17 + test/fixtures/quote.el|4 ++ 3 files changed, 89 insertions(+), 12 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 5f443dd..d5da9da 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -327,6 +327,20 @@ generated by `js2-mode'." ;; Assume global (or level 0))) +(defun context-coloring-make-backtick (end enabled) + (list + :end end + :enabled enabled)) + +(defun context-coloring-backtick-get-end (backtick) + (plist-get backtick :end)) + +(defun context-coloring-backtick-get-enabled (backtick) + (plist-get backtick :enabled)) + +(defun context-coloring-backtick-enabled-p (backtick-stack) + (context-coloring-backtick-get-enabled (car backtick-stack))) + (defun context-coloring-emacs-lisp-identifier-syntax-p (syntax-code) (or (= 2 syntax-code) (= 3 syntax-code))) @@ -342,6 +356,7 @@ generated by `js2-mode'." (last-ppss-pos (point)) (ppss (syntax-ppss)) (scope-stack `(,(context-coloring-make-scope -1 0))) ; -1 never matches a depth + (backtick-stack `(,(context-coloring-make-backtick -1 nil))) one-word-found-p in-defun-p in-lambda-p @@ -355,6 +370,7 @@ generated by `js2-mode'." token-pos token-syntax token-syntax-code + token-char child-0-pos child-0-end child-0-syntax @@ -365,7 +381,7 @@ generated by `js2-mode'." child-1-syntax child-1-syntax-code child-2-end) -(while (> end (progn (skip-syntax-forward "^()w_" end) +(while (> end (progn (skip-syntax-forward "^()w_'" end) (point))) (setq token-pos (point)) (setq token-syntax (syntax-after token-pos)) @@ -374,7 +390,38 @@ generated by `js2-mode'." ;; `skip-syntax-forward' leaves the point at the delimiter, move past ;; it. (setq token-syntax-code (logand #x (car token-syntax))) + (setq token-char (string-to-char (buffer-substring-no-properties +token-pos +(1+ token-pos (cond + + ;; Expression prefix + ;; Has to come first in case of commas + ((= 6 token-syntax-code) +(forward-char) +(cond + ;; Just outright skip top-level symbols + ((not (or (cadr backtick-stack) + (= token-char 96))) ; 96 = '`' + (goto-char (scan-sexps (point) 1))) + ((or (= token-char 96) ; 96 = '`' + (= token-char 44)) ; 44 = ',' + ;; Have to manage backticks + (setq backtick-stack (cons (context-coloring-make-backtick + (scan-sexps (point) 1) ; End of the backtick + (= token-char 96)) ; 96 = '`' + backtick-stack) + + ;; End backtick + ((and (cadr backtick-stack) + (>= (point) (context-coloring-backtick-get-end (car backtick-stack +(setq backtick-stack (cdr backtick-stack))) + + ;; Restricted by backtick + ((and (cadr backtick-stack) + (context-coloring-backtick-enabled-p backtick-stack)) +(forward-char)) + ;; Opening delimiter ((= 4 token-syntax-code) (forward-char) @@ -455,30 +502,39 @@ generated by `js2-mode'." (1+ token-pos)) ;; Cleanup (setq one-word-found-p nil)) + ;; Word (variable) ((context-coloring-emacs-lisp-identifier-syntax-p token-syntax-code) (setq variable-end (scan-sexps (point) 1)) (setq variable-string (buffer-substring-no-properties token-pos variable-end)) -(setq variable (intern variable-string)) -(setq variable-scope-level - (context-coloring-get-variable-level scope-stack variable)) -(when (/= variable-scope-level (context-coloring-scope-get-level -(car scope-stack))) - (context-coloring-colorize-region - token-pos - variable-end - variable-scope-level)) +(cond + ;; Ignore numbers + ((string-match-p "\\`[-+]?[0-9]" variable-string)) + (t + (setq variab
[elpa] master 5acd088 10/47: Add non-recursive let* coloring.
branch: master commit 5acd088cbb1a9115d77d71279eabc0e2d8e8ea93 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Add non-recursive let* coloring. --- context-coloring.el | 59 --- test/context-coloring-test.el | 78 - test/fixtures/let*.el |9 + 3 files changed, 109 insertions(+), 37 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 3bd2b0f..3a57b3f 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -341,6 +341,13 @@ generated by `js2-mode'." (defun context-coloring-backtick-enabled-p (backtick-stack) (context-coloring-backtick-get-enabled (car backtick-stack))) +(defun context-coloring-make-let-value (end) + (list + :end end)) + +(defun context-coloring-let-value-get-end (let-value) + (plist-get let-value :end)) + (defun context-coloring-emacs-lisp-identifier-syntax-p (syntax-code) (or (= 2 syntax-code) (= 3 syntax-code))) @@ -349,6 +356,9 @@ generated by `js2-mode'." "Move forward through whitespace and comments." (while (forward-comment 1))) +(defun context-coloring-at-open-parenthesis () + (= 4 (logand #x (car (syntax-after (point)) + (defun context-coloring-emacs-lisp-colorize () "Color the current buffer by parsing emacs lisp sexps." (with-silent-modifications @@ -361,12 +371,16 @@ generated by `js2-mode'." (ppss (syntax-ppss)) (scope-stack `(,(context-coloring-make-scope -1 0))) ; -1 never matches a depth (backtick-stack `(,(context-coloring-make-backtick -1 nil))) + (let-value-stack `(,(context-coloring-make-let-value -1))) one-word-found-p in-defun-p in-lambda-p + in-let*-p function-call-p defun-arglist defun-arg + let-varlist + let-var variable variable-end variable-string @@ -453,14 +467,18 @@ generated by `js2-mode'." (setq child-0-end (scan-sexps child-0-pos 1)) (setq child-0-string (buffer-substring-no-properties child-0-pos child-0-end)) (cond - ((string-match-p "defun\\|defmacro" child-0-string) + ((string-match-p "\\`defun\\'\\|\\`defmacro\\'" child-0-string) (setq in-defun-p t)) - ((string-match-p "lambda" child-0-string) + ((string-match-p "\\`lambda\\'" child-0-string) (setq in-lambda-p t)) + ((string-match-p "\\`let\\*\\'" child-0-string) +(setq in-let*-p t)) ;; Assume a global function call (t (setq function-call-p t) -(when (or in-defun-p in-lambda-p) +(when (or in-defun-p + in-lambda-p + in-let*-p) (setq scope-stack (cons (context-coloring-make-scope (nth 0 ppss) (1+ (context-coloring-scope-get-level @@ -475,7 +493,8 @@ generated by `js2-mode'." (context-coloring-colorize-region child-0-pos child-0-end 0) (setq function-call-p nil)) (cond - ((or in-defun-p in-lambda-p) + ((or in-defun-p + in-lambda-p) (goto-char child-0-end) (when in-defun-p ;; Lookahead for defun name @@ -492,7 +511,8 @@ generated by `js2-mode'." (goto-char child-1-end ;; Lookahead for parameters (context-coloring-forward-sws) - (when (= 4 (logand #x (car (syntax-after (point) + (when (context-coloring-at-open-parenthesis) +;; Actually it should be `child-1-end' for `lambda'. (setq child-2-end (scan-sexps (point) 1)) (setq defun-arglist (read (buffer-substring-no-properties (point) @@ -509,6 +529,35 @@ generated by `js2-mode'." ;; Cleanup (setq in-defun-p nil) (setq in-lambda-p nil)) + (in-let*-p + (goto-char child-0-end) + ;; Lookahead for bindings + (context-coloring-forward-sws) + (setq child-1-pos (point)) + (setq child-1-syntax (syntax-after child-1-pos)) + (setq child-1-syntax-code (logand #x (car child-1-syntax))) + (when (= 4 child-1-syntax-code) +(setq child-1-end (scan-sexps (point) 1)) +(setq let-varlist (read (buffer-substring-no-properties + (point) + child-1-end))) +(while let-varlist + (setq let-var (car let-varlist)) +
[elpa] master 08bf3e4 23/47: Ignore question marks.
branch: master commit 08bf3e4d6d1ef4d837e7c0ef5d2db4d661ce0715 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Ignore question marks. --- context-coloring.el |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 6c56d14..2c5f44b 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -402,7 +402,7 @@ generated by `js2-mode'." "\\`[^&:]") (defconst context-coloring-ignored-word-regexp - "\\`[-+]?[0-9]\\|\\`t\\'\\|\\`nil\\'\\|\\`\\.\\'") + "\\`[-+]?[0-9]\\|\\`t\\'\\|\\`nil\\'\\|\\`\\.\\'\\|\\`\\?\\'") (defconst context-coloring-COMMA-CHAR 44) (defconst context-coloring-BACKTICK-CHAR 96)
[elpa] master 5c5b429 32/47: Fix font-lock error.
branch: master commit 5c5b429efdc9ffdef75bf987b4fb57f6089439c7 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Fix font-lock error. --- context-coloring.el |1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 1e9553d..3a05bc2 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -193,6 +193,7 @@ the END point (exclusive) with the face corresponding to LEVEL." (or max (point-max))) ;; TODO: Make configurable at the dispatch level. (when (eq major-mode 'emacs-lisp-mode) + (font-lock-set-defaults) (font-lock-fontify-keywords-region (or min (point-min)) (or max (point-max
[elpa] master 88a921f 35/47: Improve defun regexp.
branch: master commit 88a921f641dccc268b3b35f07abbea1d1d8e30a6 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Improve defun regexp. --- context-coloring.el | 16 ++-- 1 files changed, 14 insertions(+), 2 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index ae5ed90..ead1a79 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -389,14 +389,26 @@ generated by `js2-mode'." (defun context-coloring-stack-depth-equal (stack depth) (= (plist-get (car stack) :depth) depth)) +(defun context-coloring-exact-regexp (word) + "Create a regexp that matches exactly WORD." + (concat "\\`" (regexp-quote word) "\\'")) + +(defun context-coloring-exact-or-regexp (words) + "Create a regexp that matches any exact word in WORDS." + (context-coloring-join + (mapcar 'context-coloring-exact-regexp words) "\\|")) + (defconst context-coloring-defun-regexp - "\\`defun\\'\\|\\`defmacro\\'\\|\\`defsubst\\'") + (context-coloring-exact-or-regexp + '("defun" "defun*" "defsubst" "defmacro" + "cl-defun" "cl-defsubst" "cl-defmacro"))) (defconst context-coloring-arglist-arg-regexp "\\`[^&:]") (defconst context-coloring-ignored-word-regexp - "\\`[-+]?[0-9]\\|\\`t\\'\\|\\`nil\\'\\|\\`\\.\\'\\|\\`\\?\\'") + (concat "\\`[-+]?[0-9]\\|" (context-coloring-exact-or-regexp + '("t" "nil" "." "?" (defconst context-coloring-COMMA-CHAR 44) (defconst context-coloring-BACKTICK-CHAR 96)
[elpa] master 29328af 18/47: Add let test.
branch: master commit 29328afbbf67a618a2e670671693ec2c48c8a717 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Add let test. --- test/context-coloring-test.el |8 test/fixtures/let.el |4 2 files changed, 12 insertions(+), 0 deletions(-) diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el index 1d154e2..f98d935 100644 --- a/test/context-coloring-test.el +++ b/test/context-coloring-test.el @@ -1136,6 +1136,14 @@ see that function." (x x () (x x 1 11 11 111 11 1 111))"))) +(context-coloring-test-deftest-emacs-lisp-mode let + (lambda () +(context-coloring-test-assert-coloring " + 11 + 11 01 + 11 11 + 1 1 1 11"))) + (context-coloring-test-deftest-emacs-lisp-mode let* (lambda () (context-coloring-test-assert-coloring " diff --git a/test/fixtures/let.el b/test/fixtures/let.el new file mode 100644 index 000..3b869ce --- /dev/null +++ b/test/fixtures/let.el @@ -0,0 +1,4 @@ +(let (a + (b a) + (c free)) + (and a b c free))
[elpa] master c830ae5 15/47: Fix let* test.
branch: master commit c830ae52b50bfd2c0c170a54b67ebc4139b2a7eb Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Fix let* test. --- test/context-coloring-test.el |6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el index c8a3532..64667a4 100644 --- a/test/context-coloring-test.el +++ b/test/context-coloring-test.el @@ -1142,12 +1142,12 @@ see that function." 1 11 11 11 11 11 - 1000 1 1 1 0 0 1 + 1 1 1 0 0 1 2 22 22 12 22 22 -2000 1 1 2 2 2 )) - 1000 1 1 1 0 0 11"))) + 1 1 2 2 2 )) + 1 1 1 0 0 11"))) (provide 'context-coloring-test)
[elpa] master 6392d1f 40/47: Bind optional parameters earlier.
branch: master commit 6392d1f3e0764414f019e4c76baf25b66101f5f6 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Bind optional parameters earlier. --- context-coloring.el | 10 +- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 057b4d8..c7a3f08 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -172,7 +172,9 @@ the END point (exclusive) with the face corresponding to LEVEL." (when (or context-coloring-comments-and-strings context-coloring-syntactic-comments context-coloring-syntactic-strings) -(let ((font-lock-syntactic-face-function +(let ((min (or min (point-min))) + (max (or max (point-max))) + (font-lock-syntactic-face-function (cond ((and context-coloring-syntactic-comments (not context-coloring-syntactic-strings)) @@ -183,12 +185,10 @@ the END point (exclusive) with the face corresponding to LEVEL." (t font-lock-syntactic-face-function (save-excursion -(font-lock-fontify-syntactically-region (or min (point-min)) -(or max (point-max))) +(font-lock-fontify-syntactically-region min max) ;; TODO: Make configurable at the dispatch level. (when (eq major-mode 'emacs-lisp-mode) - (font-lock-fontify-keywords-region (or min (point-min)) - (or max (point-max + (font-lock-fontify-keywords-region min max)) ;;; js2-mode colorization
[elpa] master dc2f9a6 25/47: Refactor maybe-colorize-comments-and-strings.
branch: master commit dc2f9a6e3b43e7559b9d2325031bdd79542e9cf1 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Refactor maybe-colorize-comments-and-strings. --- context-coloring.el | 30 +- 1 files changed, 13 insertions(+), 17 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 940b90d..22097a5 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -172,29 +172,25 @@ the END point (exclusive) with the face corresponding to LEVEL." "Tell `font-lock' to color a string but not a comment." (if (nth 3 state) font-lock-string-face nil)) -(defsubst context-coloring-maybe-colorize-comments-and-strings () +(defsubst context-coloring-maybe-colorize-comments-and-strings (&optional min max) "Color the current buffer's comments and strings if `context-coloring-comments-and-strings' is non-nil." (when (or context-coloring-comments-and-strings context-coloring-syntactic-comments context-coloring-syntactic-strings) -(let ((old-function font-lock-syntactic-face-function) - saved-function-p) - (cond - ((and context-coloring-syntactic-comments - (not context-coloring-syntactic-strings)) -(setq font-lock-syntactic-face-function - 'context-coloring-font-lock-syntactic-comment-function) -(setq saved-function-p t)) - ((and context-coloring-syntactic-strings - (not context-coloring-syntactic-comments)) -(setq font-lock-syntactic-face-function - 'context-coloring-font-lock-syntactic-string-function) -(setq saved-function-p t))) +(let ((font-lock-syntactic-face-function + (cond +((and context-coloring-syntactic-comments + (not context-coloring-syntactic-strings)) + 'context-coloring-font-lock-syntactic-comment-function) +((and context-coloring-syntactic-strings + (not context-coloring-syntactic-comments)) + 'context-coloring-font-lock-syntactic-string-function) +(t + font-lock-syntactic-face-function (save-excursion -(font-lock-fontify-syntactically-region (point-min) (point-max))) - (when saved-function-p -(setq font-lock-syntactic-face-function old-function) +(font-lock-fontify-syntactically-region (or min (point-min)) +(or max (point-max))) ;;; js2-mode colorization
[elpa] master 89f20e4 28/47: Improve interruptability of syntactic coloring.
branch: master commit 89f20e43358e92caa0a6232f9699aea89a362f1c Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Improve interruptability of syntactic coloring. --- context-coloring.el | 52 +++--- 1 files changed, 32 insertions(+), 20 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index d1c2d52..f21b323 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -172,6 +172,8 @@ the END point (exclusive) with the face corresponding to LEVEL." "Tell `font-lock' to color a string but not a comment." (if (nth 3 state) font-lock-string-face nil)) +;; TODO: Add specialized emacs-lisp version based on +;; `lisp-font-lock-syntactic-face-function'. (defsubst context-coloring-maybe-colorize-comments-and-strings (&optional min max) "Color the current buffer's comments and strings if `context-coloring-comments-and-strings' is non-nil." @@ -415,7 +417,7 @@ As of this writing, emacs lisp colorization seems to run at about 60,000 iterations per second. A default value of 1000 should provide visually \"instant\" updates at ~60 frames per second.") -(defvar context-coloring-verbose-parse t +(defvar context-coloring-verbose-parse nil "Log useful information pertaining to a parse.") (defun context-coloring-emacs-lisp-colorize () @@ -427,6 +429,8 @@ provide visually \"instant\" updates at ~60 frames per second.") (let* ((start-time (float-time)) (inhibit-point-motion-hooks t) (iteration-count 0) + (last-fontified-position (point)) + end-of-current-defun (end (point-max)) (last-ppss-pos (point)) (ppss (syntax-ppss)) @@ -466,11 +470,25 @@ provide visually \"instant\" updates at ~60 frames per second.") child-2-end) (while (> end (progn (skip-syntax-forward "^()w_'" end) (point))) - (and context-coloring-parse-interruptable-p - (zerop (% (setq iteration-count (1+ iteration-count)) - context-coloring-emacs-lisp-iterations-per-pause)) - (input-pending-p) - (throw 'interrupted t)) + ;; Sparingly-executed tasks. + (setq iteration-count (1+ iteration-count)) + (when (zerop (% iteration-count + context-coloring-emacs-lisp-iterations-per-pause)) +;; Fontify until the end of the current defun because doing it in +;; chunks based soley on point could result in partial +;; re-fontifications over the contents of scopes. +(setq end-of-current-defun (save-excursion + (end-of-defun) + (point))) +;; Fontify in chunks. +(context-coloring-maybe-colorize-comments-and-strings + last-fontified-position + end-of-current-defun) +(setq last-fontified-position end-of-current-defun) +(when (and context-coloring-parse-interruptable-p + (input-pending-p)) + (throw 'interrupted t))) + (setq token-pos (point)) (setq token-syntax (syntax-after token-pos)) (setq token-syntax-code (logand #x (car token-syntax))) @@ -701,10 +719,13 @@ provide visually \"instant\" updates at ~60 frames per second.") (setq popped-vars (cdr popped-vars )) +;; Fontify the last stretch. +(context-coloring-maybe-colorize-comments-and-strings + last-fontified-position + (point)) (when context-coloring-verbose-parse (message "Elapsed: %s; iterations: %s" - (- (float-time) start-time) iteration-count -(context-coloring-maybe-colorize-comments-and-strings))) + (- (float-time) start-time) iteration-count)) ;;; Shell command scopification / colorization @@ -847,11 +868,7 @@ should be numeric, e.g. \"2\", \"19700101\", \"1.2.3\", `context-coloring-mode' is enabled. `:teardown' - Arbitrary code to tear down this dispatch when -`context-coloring-mode' is disabled. - -`:interrupt' - Arbitrary code to run if parsing or coloring is -interrupted (for synchronous strategies like `:colorizer' and -`:scopifier')." +`context-coloring-mode' is disabled." (let ((modes (plist-get properties :modes)) (colorizer (plist-get properties :colorizer)) (scopifier (plist-get properties :scopifier)) @@ -1346,10 +1363,6 @@ Supported modes: `js-mode', `js3-mode'" 'emacs-lisp :modes '(emacs-lisp-mode) :colorizer 'context-coloring-emacs-lisp-colorize - ;; Comments and strings aren't colored till the end so it can be pretty ugly if - ;; you interrupt too far down the buffer. TODO: Still not very satisfying, - ;; seeing flashes of uncolored code occassionally. - :interrupt 'context-coloring-ma
[elpa] master b4072c1 14/47: Trivial refactoring for clarity.
branch: master commit b4072c1481873e4274cd187a76ae9d4afffae52c Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Trivial refactoring for clarity. --- context-coloring.el | 149 +++--- 1 files changed, 80 insertions(+), 69 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 9c31314..9e1e1ed 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -324,7 +324,7 @@ generated by `js2-mode'." (setq level (context-coloring-scope-get-level scope))) (t (setq scope-stack (cdr scope-stack) -;; Assume global +;; Assume a global variable. (or level 0))) (defun context-coloring-make-backtick (end enabled) @@ -341,37 +341,58 @@ generated by `js2-mode'." (defun context-coloring-backtick-enabled-p (backtick-stack) (context-coloring-backtick-get-enabled (car backtick-stack))) -(defun context-coloring-make-let-value (end) - (list - :end end)) +(defun context-coloring-forward-sws () + "Move forward through whitespace and comments." + (while (forward-comment 1))) -(defun context-coloring-let-value-get-end (let-value) - (plist-get let-value :end)) +(defun context-coloring-forward-sexp-position () + (scan-sexps (point) 1)) (defun context-coloring-emacs-lisp-identifier-syntax-p (syntax-code) (or (= 2 syntax-code) (= 3 syntax-code))) -(defun context-coloring-forward-sws () - "Move forward through whitespace and comments." - (while (forward-comment 1))) +(defun context-coloring-open-parenthesis-p (syntax-code) + (= 4 syntax-code)) + +(defun context-coloring-close-parenthesis-p (syntax-code) + (= 5 syntax-code)) -(defun context-coloring-at-open-parenthesis () +(defun context-coloring-expression-prefix-p (syntax-code) + (= 6 syntax-code)) + +(defun context-coloring-at-open-parenthesis-p () (= 4 (logand #x (car (syntax-after (point)) +(defun context-coloring-ppss-depth (ppss) + ;; Same as (nth 0 ppss). + (car ppss)) + +(defconst context-coloring-defun-regexp + "\\`defun\\'\\|\\`defmacro\\'\\|\\`defsubst\\'") + +(defconst context-coloring-arglist-arg-regexp + "\\`[^&:]") + +(defconst context-coloring-unbindable-constant-regexp + "\\`[-+]?[0-9]\\|\\`t\\'\\|\\`nil\\'") + +(defconst context-coloring-COMMA-CHAR 44) +(defconst context-coloring-BACKTICK-CHAR 96) + (defun context-coloring-emacs-lisp-colorize () "Color the current buffer by parsing emacs lisp sexps." (with-silent-modifications (save-excursion - ;; TODO: Can probably make this lazy to the nearest defun + ;; TODO: Can probably make this lazy to the nearest defun. (goto-char (point-min)) (let* ((inhibit-point-motion-hooks t) (end (point-max)) (last-ppss-pos (point)) (ppss (syntax-ppss)) - (scope-stack `(,(context-coloring-make-scope -1 0))) ; -1 never matches a depth - (backtick-stack `(,(context-coloring-make-backtick -1 nil))) - (let-value-stack `(,(context-coloring-make-let-value -1))) + ; -1 never matches a depth. This is a minor optimization. + (scope-stack `(,(context-coloring-make-scope -1 0))) + (backtick-stack '()) one-word-found-p in-defun-p in-lambda-p @@ -403,17 +424,13 @@ generated by `js2-mode'." (point))) (setq token-pos (point)) (setq token-syntax (syntax-after token-pos)) + (setq token-syntax-code (logand #x (car token-syntax))) + (setq token-char (char-after)) (setq ppss (parse-partial-sexp last-ppss-pos token-pos nil nil ppss)) (setq last-ppss-pos token-pos) - ;; `skip-syntax-forward' leaves the point at the delimiter, move past - ;; it. - (setq token-syntax-code (logand #x (car token-syntax))) - (setq token-char (string-to-char (buffer-substring-no-properties -token-pos -(1+ token-pos (cond - ;; Resolve invalid state + ;; Resolve an invalid state. ((cond ;; Inside string? ((nth 3 ppss) @@ -422,54 +439,49 @@ generated by `js2-mode'." t) ;; Inside comment? ((nth 4 ppss) - (skip-syntax-forward "^>" end) ; comment ender + (skip-syntax-forward "^>" end) t))) - ;; Expression prefix - ;; Has to come first in case of commas - ((= 6 token-syntax-code) + ;; Need to check early in case there's a comma. + ((context-coloring-expression-prefix-p token-syntax-code) (forward-char) (cond - ;; Just outright skip top-level symbols - ((not (or (cadr backtick-stack) - (= token-char 96))) ; 96 = '`' -
[elpa] master ea3ff31 16/47: Pass let* test.
branch: master commit ea3ff31c6c4183828b15d818a016d95bb8b58d24 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Pass let* test. --- context-coloring.el | 148 ++ 1 files changed, 112 insertions(+), 36 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 9e1e1ed..4a37389 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -341,6 +341,36 @@ generated by `js2-mode'." (defun context-coloring-backtick-enabled-p (backtick-stack) (context-coloring-backtick-get-enabled (car backtick-stack))) +(defun context-coloring-make-let-varlist (depth type) + (list + :depth depth + :type type + :vars '())) + +(defun context-coloring-let-varlist-get-depth (let-varlist) + (plist-get let-varlist :depth)) + +(defun context-coloring-let-varlist-get-type (let-varlist) + (plist-get let-varlist :type)) + +(defun context-coloring-let-varlist-add-var (let-varlist var) + (plist-put let-varlist :vars (cons var (plist-get let-varlist :vars + +(defun context-coloring-let-varlist-pop-vars (let-varlist) + (let ((type (context-coloring-let-varlist-get-type let-varlist)) +(vars (plist-get let-varlist :vars))) +(cond + ;; `let' binds all at once at the end. + ((eq type 'let) + (prog1 + vars +(plist-put let-varlist :vars '( + ;; `let*' binds incrementally. + ((eq type 'let*) + (prog1 + (list (car vars)) +(plist-put let-varlist :vars (cdr vars))) + (defun context-coloring-forward-sws () "Move forward through whitespace and comments." (while (forward-comment 1))) @@ -368,6 +398,9 @@ generated by `js2-mode'." ;; Same as (nth 0 ppss). (car ppss)) +(defun context-coloring-stack-depth-equal (stack depth) + (= (plist-get (car stack) :depth) depth)) + (defconst context-coloring-defun-regexp "\\`defun\\'\\|\\`defmacro\\'\\|\\`defsubst\\'") @@ -390,9 +423,13 @@ generated by `js2-mode'." (end (point-max)) (last-ppss-pos (point)) (ppss (syntax-ppss)) - ; -1 never matches a depth. This is a minor optimization. + ppss-depth + ;; -1 never matches a depth. This is a minor optimization. (scope-stack `(,(context-coloring-make-scope -1 0))) (backtick-stack '()) + (let-varlist-stack '()) + (let-var-stack '()) + popped-vars one-word-found-p in-defun-p in-lambda-p @@ -401,7 +438,7 @@ generated by `js2-mode'." defun-arglist defun-arg let-varlist - let-var + let-varlist-type variable variable-end variable-string @@ -481,14 +518,28 @@ generated by `js2-mode'." (setq child-0-end (scan-sexps child-0-pos 1)) (setq child-0-string (buffer-substring-no-properties child-0-pos child-0-end)) (cond + ;; Parse a var in a `let' varlist. + ((and + let-varlist-stack + (context-coloring-stack-depth-equal + let-varlist-stack + ;; 1- because we're inside the varlist. + (1- (context-coloring-ppss-depth ppss +(context-coloring-let-varlist-add-var + (car let-varlist-stack) + (intern child-0-string)) +(setq let-var-stack (cons (context-coloring-ppss-depth ppss) + let-var-stack))) ((string-match-p context-coloring-defun-regexp child-0-string) (setq in-defun-p t)) ((string-match-p "\\`lambda\\'" child-0-string) (setq in-lambda-p t)) ((string-match-p "\\`let\\'" child-0-string) -(setq in-let-p t)) +(setq in-let-p t) +(setq let-varlist-type 'let)) ((string-match-p "\\`let\\*\\'" child-0-string) -(setq in-let*-p t) +(setq in-let*-p t) +(setq let-varlist-type 'let*) (when (or in-defun-p in-lambda-p in-let-p @@ -544,31 +595,20 @@ generated by `js2-mode'." ((or in-let-p in-let*-p) (goto-char child-0-end) - ;; Look for bindings. + ;; Look for a varlist. (context-coloring-forward-sws) (setq child-1-pos (point)) (setq child-1-syntax (syntax-after child-1-pos)) (setq child-1-syntax-code (logand #x (car child-1-syntax))) - (when (= 4 child-1-syntax-code) -(setq child-1-end (context-coloring-forward-sexp-position)) -(setq let-varlist (read (buffer-substring-no-properties -
[elpa] master 59a6c8e 34/47: Fix timer disposal and timer buffer detection.
branch: master commit 59a6c8eac76fe32a2ae07e3b9c76668b3a81e907 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Fix timer disposal and timer buffer detection. --- context-coloring.el | 22 +- test/context-coloring-test.el |2 +- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index bf1d533..ae5ed90 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -47,12 +47,6 @@ (require 'js2-mode) -;;; Local variables - -(defvar-local context-coloring-buffer nil - "Reference to this buffer (for timers).") - - ;;; Utilities (defun context-coloring-join (strings delimiter) @@ -811,7 +805,7 @@ read the scopifier's response asynchronously and apply a parsed list of tokens to `context-coloring-apply-tokens'. Invoke CALLBACK when complete." - (let ((buffer context-coloring-buffer)) + (let ((buffer (current-buffer))) (context-coloring-scopify-shell-command command (lambda (output) @@ -913,9 +907,9 @@ used.") (context-coloring-kill-scopifier) (setq context-coloring-changed t)) -(defun context-coloring-maybe-colorize () +(defun context-coloring-maybe-colorize (buffer) "Colorize the current buffer if it has changed." - (when (and (eq context-coloring-buffer (window-buffer (selected-window))) + (when (and (eq buffer (current-buffer)) context-coloring-changed) (setq context-coloring-changed nil) (context-coloring-colorize))) @@ -1334,11 +1328,14 @@ Supported modes: `js-mode', `js3-mode'" "Setup idle change detection." (add-hook 'after-change-functions 'context-coloring-change-function nil t) + (add-hook + 'kill-buffer-hook 'context-coloring-teardown-idle-change-detection nil t) (setq context-coloring-colorize-idle-timer (run-with-idle-timer context-coloring-delay t - 'context-coloring-maybe-colorize))) + 'context-coloring-maybe-colorize + (current-buffer (defun context-coloring-teardown-idle-change-detection () "Teardown idle change detection." @@ -1346,6 +1343,8 @@ Supported modes: `js-mode', `js3-mode'" (when context-coloring-colorize-idle-timer (cancel-timer context-coloring-colorize-idle-timer)) (remove-hook + 'kill-buffer-hook 'context-coloring-teardown-idle-change-detection t) + (remove-hook 'after-change-functions 'context-coloring-change-function t)) @@ -1424,9 +1423,6 @@ elisp tracks, and asynchronously for shell command tracks." (font-lock-mode) (jit-lock-mode t)) -;; Remember this buffer. This value should not be dynamically-bound. -(setq context-coloring-buffer (current-buffer)) - ;; Font lock is incompatible with this mode; the converse is also true. (font-lock-mode 0) (jit-lock-mode nil) diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el index 9573119..5007c3c 100644 --- a/test/context-coloring-test.el +++ b/test/context-coloring-test.el @@ -474,7 +474,7 @@ FOREGROUND. Apply ARGUMENTS to (funcall done))) (insert " ") (set-window-buffer (selected-window) (current-buffer)) -(context-coloring-maybe-colorize))) +(context-coloring-maybe-colorize (current-buffer (context-coloring-mode (ert-deftest context-coloring-test-check-version ()
[elpa] master b28e896 19/47: Add complex nesting to let test.
branch: master commit b28e8969196beed4e1f8240cd5d5f49ea24d5000 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Add complex nesting to let test. --- test/context-coloring-test.el |6 +- test/fixtures/let.el |6 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el index f98d935..234084c 100644 --- a/test/context-coloring-test.el +++ b/test/context-coloring-test.el @@ -1141,7 +1141,11 @@ see that function." (context-coloring-test-assert-coloring " 11 11 01 - 11 11 + 11 1 + 11 22 + 22 02 + 22 22 + 2 2 2 2211 1 1 1 11"))) (context-coloring-test-deftest-emacs-lisp-mode let* diff --git a/test/fixtures/let.el b/test/fixtures/let.el index 3b869ce..11637b1 100644 --- a/test/fixtures/let.el +++ b/test/fixtures/let.el @@ -1,4 +1,8 @@ (let (a (b a) - (c free)) + (c free) + (d (let (a + (b a) + (c free)) + (and a b c free (and a b c free))
[elpa] master 09ec36e 24/47: Add interruption mechanism.
branch: master commit 09ec36ebac10776a5982dd220ad9b6d8fd678579 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Add interruption mechanism. --- context-coloring.el | 57 -- 1 files changed, 45 insertions(+), 12 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 2c5f44b..940b90d 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -407,6 +407,15 @@ generated by `js2-mode'." (defconst context-coloring-COMMA-CHAR 44) (defconst context-coloring-BACKTICK-CHAR 96) +(defvar context-coloring-parse-interruptable-p t + "Set this to nil to force parse to continue until finished.") + +(defvar context-coloring-tokens-per-pause 25 + "Pause after this many statements to check for user input. +If user input is pending, stop the parse. This makes for a +smoother user experience for large files. This appears to be +more or less how Eclipse, IntelliJ and other editors work.") + (defun context-coloring-emacs-lisp-colorize () "Color the current buffer by parsing emacs lisp sexps." (with-silent-modifications @@ -414,6 +423,7 @@ generated by `js2-mode'." ;; TODO: Can probably make this lazy to the nearest defun. (goto-char (point-min)) (let* ((inhibit-point-motion-hooks t) + (token-count 0) (end (point-max)) (last-ppss-pos (point)) (ppss (syntax-ppss)) @@ -453,6 +463,11 @@ generated by `js2-mode'." child-2-end) (while (> end (progn (skip-syntax-forward "^()w_'" end) (point))) + (and context-coloring-parse-interruptable-p + (zerop (% (setq token-count (1+ token-count)) + context-coloring-tokens-per-pause)) + (input-pending-p) + (throw 'interrupted t)) (setq token-pos (point)) (setq token-syntax (syntax-after token-pos)) (setq token-syntax-code (logand #x (car token-syntax))) @@ -826,7 +841,11 @@ should be numeric, e.g. \"2\", \"19700101\", \"1.2.3\", `context-coloring-mode' is enabled. `:teardown' - Arbitrary code to tear down this dispatch when -`context-coloring-mode' is disabled." +`context-coloring-mode' is disabled. + +`:interrupt' - Arbitrary code to run if parsing or coloring is +interrupted (for synchronous strategies like `:colorizer' and +`:scopifier')." (let ((modes (plist-get properties :modes)) (colorizer (plist-get properties :colorizer)) (scopifier (plist-get properties :scopifier)) @@ -1322,6 +1341,10 @@ Supported modes: `js-mode', `js3-mode'" 'emacs-lisp :modes '(emacs-lisp-mode) :colorizer 'context-coloring-emacs-lisp-colorize + ;; Comments and strings aren't colored till the end so it can be pretty ugly if + ;; you interrupt too far down the buffer. TODO: Still not very satisfying, + ;; seeing flashes of uncolored code occassionally. + :interrupt 'context-coloring-maybe-colorize-comments-and-strings :setup (lambda () (context-coloring-setup-idle-change-detection)) @@ -1338,18 +1361,28 @@ the current buffer, then execute it. Invoke CALLBACK when complete. It is invoked synchronously for elisp tracks, and asynchronously for shell command tracks." - (let ((dispatch (gethash major-mode context-coloring-mode-hash-table)) -colorizer -scopifier -command) + (let* ((dispatch (gethash major-mode context-coloring-mode-hash-table)) + (colorizer (plist-get dispatch :colorizer)) + (scopifier (plist-get dispatch :scopifier)) + (command (plist-get dispatch :command)) + (interrupt (plist-get dispatch :interrupt)) + interrupted-p) (cond - ((setq colorizer (plist-get dispatch :colorizer)) - (funcall colorizer) - (when callback (funcall callback))) - ((setq scopifier (plist-get dispatch :scopifier)) - (context-coloring-apply-tokens (funcall scopifier)) - (when callback (funcall callback))) - ((setq command (plist-get dispatch :command)) + ((or colorizer scopifier) + (setq interrupted-p +(catch 'interrupted + (cond + (colorizer +(funcall colorizer)) + (scopifier +(context-coloring-apply-tokens (funcall scopifier)) + (cond + (interrupted-p +(when interrupt (funcall interrupt)) +(setq context-coloring-changed t)) + (t +(when callback (funcall callback) + (command (context-coloring-scopify-and-colorize command callback)
[elpa] master 926d74a 17/47: Include binding order in let* test.
branch: master commit 926d74a0727f790e2c1d3fa64ad00d5d4174fcab Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Include binding order in let* test. --- test/context-coloring-test.el |6 -- test/fixtures/let*.el |4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el index 64667a4..1d154e2 100644 --- a/test/context-coloring-test.el +++ b/test/context-coloring-test.el @@ -1145,8 +1145,10 @@ see that function." 1 1 1 0 0 1 2 22 22 12 - 22 22 - 1 1 2 2 2 )) + 22 2 + 22 02 + 22 222 + 1 1 2 2 2 22 1 1 1 0 0 11"))) (provide 'context-coloring-test) diff --git a/test/fixtures/let*.el b/test/fixtures/let*.el index 967f866..44d743c 100644 --- a/test/fixtures/let*.el +++ b/test/fixtures/let*.el @@ -4,6 +4,8 @@ (and a b c d e free) (let* (d (e a) - (c free)) + (c free) + (g f) + (f g)) (and a b c d e free)) (and a b c d e free))
[elpa] master 4ff6e82 39/47: Remove verbose parsing.
branch: master commit 4ff6e82bf9462168fae71d41c520ddec48c3b109 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Remove verbose parsing. --- context-coloring.el | 11 ++- 1 files changed, 2 insertions(+), 9 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index b8407a5..057b4d8 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -425,17 +425,13 @@ As of this writing, emacs lisp colorization seems to run at about 60,000 iterations per second. A default value of 1000 should provide visually \"instant\" updates at ~60 frames per second.") -(defvar context-coloring-verbose-parse nil - "Log useful information pertaining to a parse.") - (defun context-coloring-emacs-lisp-colorize () "Color the current buffer by parsing emacs lisp sexps." (with-silent-modifications (save-excursion ;; TODO: Can probably make this lazy to the nearest defun. (goto-char (point-min)) - (let* ((start-time (float-time)) - (inhibit-point-motion-hooks t) + (let* ((inhibit-point-motion-hooks t) (iteration-count 0) (last-fontified-position (point)) beginning-of-current-defun @@ -740,10 +736,7 @@ provide visually \"instant\" updates at ~60 frames per second.") ;; Fontify the last stretch. (context-coloring-maybe-colorize-comments-and-strings last-fontified-position - (point)) -(when context-coloring-verbose-parse - (message "Elapsed: %s; iterations: %s" - (- (float-time) start-time) iteration-count)) + (point)) ;;; Shell command scopification / colorization
[elpa] master 07c5852 30/47: Add idle change teardown function.
branch: master commit 07c5852f857cba4c59a491a8d4d0f920a3d8f05a Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Add idle change teardown function. --- context-coloring.el | 25 +++-- 1 files changed, 11 insertions(+), 14 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index d491f88..ae6abea 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -1340,6 +1340,14 @@ Supported modes: `js-mode', `js3-mode'" t 'context-coloring-maybe-colorize))) +(defun context-coloring-teardown-idle-change-detection () + "Teardown idle change detection." + (context-coloring-kill-scopifier) + (when context-coloring-colorize-idle-timer +(cancel-timer context-coloring-colorize-idle-timer)) + (remove-hook + 'after-change-functions 'context-coloring-change-function t)) + ;;; Built-in dispatches @@ -1365,15 +1373,8 @@ Supported modes: `js-mode', `js3-mode'" 'emacs-lisp :modes '(emacs-lisp-mode) :colorizer 'context-coloring-emacs-lisp-colorize - :setup - (lambda () - (context-coloring-setup-idle-change-detection)) - :teardown - (lambda () - (when context-coloring-colorize-idle-timer - (cancel-timer context-coloring-colorize-idle-timer)) - (remove-hook -'after-change-functions 'context-coloring-change-function t))) + :setup 'context-coloring-setup-idle-change-detection + :teardown 'context-coloring-teardown-idle-change-detection) (defun context-coloring-dispatch (&optional callback) "Determine the optimal track for scopification / coloring of @@ -1412,16 +1413,12 @@ elisp tracks, and asynchronously for shell command tracks." nil " Context" nil (if (not context-coloring-mode) (progn -(context-coloring-kill-scopifier) -(when context-coloring-colorize-idle-timer - (cancel-timer context-coloring-colorize-idle-timer)) (let ((dispatch (gethash major-mode context-coloring-mode-hash-table))) (when dispatch (let ((command (plist-get dispatch :command)) (teardown (plist-get dispatch :teardown))) (when command -(remove-hook - 'after-change-functions 'context-coloring-change-function t)) +(context-coloring-teardown-idle-change-detection)) (when teardown (funcall teardown) (font-lock-mode)
[elpa] master 708276e 41/47: Compiler micro-optimizations.
branch: master commit 708276e60cf4fc3a6e76f2568df8093991d865ce Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Compiler micro-optimizations. --- context-coloring.el | 50 +- 1 files changed, 25 insertions(+), 25 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index c7a3f08..46561f8 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -290,22 +290,22 @@ generated by `js2-mode'." ;;; Emacs Lisp colorization -(defun context-coloring-make-scope (depth level) +(defsubst context-coloring-make-scope (depth level) (list :depth depth :level level :variables (make-hash-table))) -(defun context-coloring-scope-get-level (scope) +(defsubst context-coloring-scope-get-level (scope) (plist-get scope :level)) -(defun context-coloring-scope-add-variable (scope variable) +(defsubst context-coloring-scope-add-variable (scope variable) (puthash variable t (plist-get scope :variables))) -(defun context-coloring-scope-get-variable (scope variable) +(defsubst context-coloring-scope-get-variable (scope variable) (gethash variable (plist-get scope :variables))) -(defun context-coloring-get-variable-level (scope-stack variable) +(defsubst context-coloring-get-variable-level (scope-stack variable) (let* (scope level) (while (and scope-stack (not level)) @@ -318,33 +318,33 @@ generated by `js2-mode'." ;; Assume a global variable. (or level 0))) -(defun context-coloring-make-backtick (end enabled) +(defsubst context-coloring-make-backtick (end enabled) (list :end end :enabled enabled)) -(defun context-coloring-backtick-get-end (backtick) +(defsubst context-coloring-backtick-get-end (backtick) (plist-get backtick :end)) -(defun context-coloring-backtick-get-enabled (backtick) +(defsubst context-coloring-backtick-get-enabled (backtick) (plist-get backtick :enabled)) -(defun context-coloring-backtick-enabled-p (backtick-stack) +(defsubst context-coloring-backtick-enabled-p (backtick-stack) (context-coloring-backtick-get-enabled (car backtick-stack))) -(defun context-coloring-make-let-varlist (depth type) +(defsubst context-coloring-make-let-varlist (depth type) (list :depth depth :type type :vars '())) -(defun context-coloring-let-varlist-get-type (let-varlist) +(defsubst context-coloring-let-varlist-get-type (let-varlist) (plist-get let-varlist :type)) -(defun context-coloring-let-varlist-add-var (let-varlist var) +(defsubst context-coloring-let-varlist-add-var (let-varlist var) (plist-put let-varlist :vars (cons var (plist-get let-varlist :vars -(defun context-coloring-let-varlist-pop-vars (let-varlist) +(defsubst context-coloring-let-varlist-pop-vars (let-varlist) (let ((type (context-coloring-let-varlist-get-type let-varlist)) (vars (plist-get let-varlist :vars))) (cond @@ -359,41 +359,41 @@ generated by `js2-mode'." (list (car vars)) (plist-put let-varlist :vars (cdr vars))) -(defun context-coloring-forward-sws () +(defsubst context-coloring-forward-sws () "Move forward through whitespace and comments." (while (forward-comment 1))) -(defun context-coloring-forward-sexp-position () +(defsubst context-coloring-forward-sexp-position () (scan-sexps (point) 1)) -(defun context-coloring-emacs-lisp-identifier-syntax-p (syntax-code) +(defsubst context-coloring-emacs-lisp-identifier-syntax-p (syntax-code) (or (= 2 syntax-code) (= 3 syntax-code))) -(defun context-coloring-open-parenthesis-p (syntax-code) +(defsubst context-coloring-open-parenthesis-p (syntax-code) (= 4 syntax-code)) -(defun context-coloring-close-parenthesis-p (syntax-code) +(defsubst context-coloring-close-parenthesis-p (syntax-code) (= 5 syntax-code)) -(defun context-coloring-expression-prefix-p (syntax-code) +(defsubst context-coloring-expression-prefix-p (syntax-code) (= 6 syntax-code)) -(defun context-coloring-at-open-parenthesis-p () +(defsubst context-coloring-at-open-parenthesis-p () (= 4 (logand #x (car (syntax-after (point)) -(defun context-coloring-ppss-depth (ppss) +(defsubst context-coloring-ppss-depth (ppss) ;; Same as (nth 0 ppss). (car ppss)) -(defun context-coloring-stack-depth-equal (stack depth) +(defsubst context-coloring-stack-depth-equal (stack depth) (= (plist-get (car stack) :depth) depth)) -(defun context-coloring-exact-regexp (word) +(defsubst context-coloring-exact-regexp (word) "Create a regexp that matches exactly WORD." (concat "\\`" (regexp-quote word) "\\'")) -(defun context-coloring-exact-or-regexp (words) +(defsubst context-coloring-exact-or-regexp (words) "Create a regexp that matches any exact word in WORDS." (context-coloring-join (mapcar 'context-coloring-exact-regexp words) "\\|")) @@ -416,7 +416,7 @@ generated by `js2-mode'." (defvar context-coloring-parse-interruptable-p t "Set this to ni
[elpa] master 3bf805d 46/47: Version 6.3.0.
branch: master commit 3bf805df83fe6f110f3e7e8ce2dc37e0cf6c14cb Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Version 6.3.0. --- context-coloring.el | 12 +--- 1 files changed, 1 insertions(+), 11 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 5c3b76f..cb74ee7 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2014-2015 Free Software Foundation, Inc. ;; Author: Jackson Ray Hamilton -;; Version: 6.2.1 +;; Version: 6.3.0 ;; Keywords: convenience faces tools ;; Package-Requires: ((emacs "24") (js2-mode "20150126")) ;; URL: https://github.com/jacksonrayhamilton/context-coloring @@ -32,16 +32,6 @@ ;; By default, comments and strings are still highlighted syntactically. -;; To use with js2-mode, add the following to your init file: - -;; (require 'context-coloring) -;; (add-hook 'js2-mode-hook 'context-coloring-mode) - -;; To use with js-mode or js3-mode, install Node.js 0.10+ and the scopifier -;; executable: - -;; $ npm install -g scopifier - ;;; Code: (require 'js2-mode)
[elpa] master 3b6a391 44/47: Minor cleanup.
branch: master commit 3b6a3918ca329b1d836e492bd0b8403a1e696e65 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Minor cleanup. --- context-coloring.el | 37 - 1 files changed, 24 insertions(+), 13 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 0249a5d..5c3b76f 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -364,6 +364,7 @@ generated by `js2-mode'." (while (forward-comment 1))) (defsubst context-coloring-forward-sexp-position () + "Like vanilla `forward-sexp', but just return the position." (scan-sexps (point) 1)) (defsubst context-coloring-emacs-lisp-identifier-syntax-p (syntax-code) @@ -386,7 +387,7 @@ generated by `js2-mode'." ;; Same as (nth 0 ppss). (car ppss)) -(defsubst context-coloring-stack-depth-equal (stack depth) +(defsubst context-coloring-at-stack-depth-p (stack depth) (= (plist-get (car stack) :depth) depth)) (defsubst context-coloring-exact-regexp (word) @@ -398,11 +399,20 @@ generated by `js2-mode'." (context-coloring-join (mapcar 'context-coloring-exact-regexp words) "\\|")) -(defconst context-coloring-defun-regexp +(defconst context-coloring-emacs-lisp-defun-regexp (context-coloring-exact-or-regexp '("defun" "defun*" "defsubst" "defmacro" "cl-defun" "cl-defsubst" "cl-defmacro"))) +(defconst context-coloring-emacs-lisp-lambda-regexp + (context-coloring-exact-regexp "lambda")) + +(defconst context-coloring-emacs-lisp-let-regexp + (context-coloring-exact-regexp "let")) + +(defconst context-coloring-emacs-lisp-let*-regexp + (context-coloring-exact-regexp "let*")) + (defconst context-coloring-arglist-arg-regexp "\\`[^&:]") @@ -423,7 +433,7 @@ smoother user experience for large files. As of this writing, emacs lisp colorization seems to run at about 60,000 iterations per second. A default value of 1000 should -provide visually \"instant\" updates at ~60 frames per second.") +provide visually \"instant\" updates at 60 frames per second.") (defun context-coloring-emacs-lisp-colorize () "Color the current buffer by parsing emacs lisp sexps." @@ -432,11 +442,11 @@ provide visually \"instant\" updates at ~60 frames per second.") ;; TODO: Can probably make this lazy to the nearest defun. (goto-char (point-min)) (let* ((inhibit-point-motion-hooks t) + (end (point-max)) (iteration-count 0) (last-fontified-position (point)) beginning-of-current-defun end-of-current-defun - (end (point-max)) (last-ppss-pos (point)) (ppss (syntax-ppss)) ppss-depth @@ -565,7 +575,7 @@ provide visually \"instant\" updates at ~60 frames per second.") ;; Parse a var in a `let' varlist. ((and let-varlist-stack - (context-coloring-stack-depth-equal + (context-coloring-at-stack-depth-p let-varlist-stack ;; 1- because we're inside the varlist. (1- (context-coloring-ppss-depth ppss @@ -574,14 +584,14 @@ provide visually \"instant\" updates at ~60 frames per second.") (intern child-0-string)) (setq let-var-stack (cons (context-coloring-ppss-depth ppss) let-var-stack))) - ((string-match-p context-coloring-defun-regexp child-0-string) + ((string-match-p context-coloring-emacs-lisp-defun-regexp child-0-string) (setq in-defun-p t)) - ((string-match-p "\\`lambda\\'" child-0-string) + ((string-match-p context-coloring-emacs-lisp-lambda-regexp child-0-string) (setq in-lambda-p t)) - ((string-match-p "\\`let\\'" child-0-string) + ((string-match-p context-coloring-emacs-lisp-let-regexp child-0-string) (setq in-let-p t) (setq let-varlist-type 'let)) - ((string-match-p "\\`let\\*\\'" child-0-string) + ((string-match-p context-coloring-emacs-lisp-let*-regexp child-0-string) (setq in-let*-p t) (setq let-varlist-type 'let*) (when (or in-defun-p @@ -593,7 +603,8 @@ provide visually \"instant\" updates at ~60 frames per second.") (1+ (context-coloring-scope-get-level (car scope-stack scope-stack))) -;; TODO: Probably redundant and wasteful. +;; TODO: Maybe wasteful but doing this conditionally doesn't make +;; much of a difference. (context-coloring-colorize-region token-pos (scan-sexps token-pos 1) (context-coloring-scope-g
[elpa] master 6a4ad31 43/47: Add derived mode support.
branch: master commit 6a4ad31d4f86e6d1b129c17fb16deca9be148514 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Add derived mode support. --- context-coloring.el | 18 +++ test/context-coloring-test.el | 49 +++-- 2 files changed, 50 insertions(+), 17 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 23af23d..0249a5d 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -841,6 +841,15 @@ Invoke CALLBACK when complete." (defvar context-coloring-mode-hash-table (make-hash-table :test 'eq) "Map major mode names to dispatch property lists.") +(defun context-coloring-get-dispatch-for-mode (mode) + "Return the dispatch for MODE (or a derivative mode)." + (let ((parent mode) +dispatch) +(while (and parent +(not (setq dispatch (gethash parent context-coloring-mode-hash-table))) +(setq parent (get parent 'derived-mode-parent +dispatch)) + (defun context-coloring-define-dispatch (symbol &rest properties) "Define a new dispatch named SYMBOL with PROPERTIES. @@ -969,7 +978,7 @@ produces (1 0 0), \"19700101\" produces (19700101), etc." "Asynchronously invoke CALLBACK with a predicate indicating whether the current scopifier version satisfies the minimum version number required for the current major mode." - (let ((dispatch (gethash major-mode context-coloring-mode-hash-table))) + (let ((dispatch (context-coloring-get-dispatch-for-mode major-mode))) (when dispatch (let ((version (plist-get dispatch :version)) (command (plist-get dispatch :command))) @@ -1396,7 +1405,7 @@ the current buffer, then execute it. Invoke CALLBACK when complete. It is invoked synchronously for elisp tracks, and asynchronously for shell command tracks." - (let* ((dispatch (gethash major-mode context-coloring-mode-hash-table)) + (let* ((dispatch (context-coloring-get-dispatch-for-mode major-mode)) (colorizer (plist-get dispatch :colorizer)) (scopifier (plist-get dispatch :scopifier)) (command (plist-get dispatch :command)) @@ -1427,7 +1436,7 @@ elisp tracks, and asynchronously for shell command tracks." nil " Context" nil (if (not context-coloring-mode) (progn -(let ((dispatch (gethash major-mode context-coloring-mode-hash-table))) +(let ((dispatch (context-coloring-get-dispatch-for-mode major-mode))) (when dispatch (let ((command (plist-get dispatch :command)) (teardown (plist-get dispatch :teardown))) @@ -1448,8 +1457,7 @@ elisp tracks, and asynchronously for shell command tracks." ;; Safely change the valye of this function as necessary. (make-local-variable 'font-lock-syntactic-face-function) -;; TODO: Detect derived modes. -(let ((dispatch (gethash major-mode context-coloring-mode-hash-table))) +(let ((dispatch (context-coloring-get-dispatch-for-mode major-mode))) (if dispatch (progn (let ((command (plist-get dispatch :command)) diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el index 19f844b..e22ee29 100644 --- a/test/context-coloring-test.el +++ b/test/context-coloring-test.el @@ -348,8 +348,16 @@ EXPECTED-FACE." (context-coloring-test-assert-region-face start end 'font-lock-string-face)) +(defun context-coloring-test-get-last-message () + (let ((messages (split-string + (buffer-substring-no-properties +(point-min) +(point-max)) + "\n"))) +(car (nthcdr (- (length messages) 2) messages + (defun context-coloring-test-assert-message (expected buffer) - "Assert that message EXPECTED exists in BUFFER." + "Assert that message EXPECTED is at the end of BUFFER." (when (null (get-buffer buffer)) (ert-fail (format @@ -358,20 +366,28 @@ EXPECTED-FACE." "but the buffer did not have any messages.") buffer expected))) (with-current-buffer buffer -(let ((messages (split-string - (buffer-substring-no-properties - (point-min) - (point-max)) - "\n"))) - (let ((message (car (nthcdr (- (length messages) 2) messages -(when (not (equal message expected)) +(let ((message (context-coloring-test-get-last-message))) + (when (not (equal message expected)) +(ert-fail + (format + (concat + "Expected buffer `%s' to have message \"%s\", " + "but instead it was \"%s\"") + buffer expected + message)) + +(defun context-coloring-test-assert-not-message (expected buffer) + "Assert that message EXPECTED is not at the end of BUFFER." + (when (get-buffer buffer) +(with-current-buffer buffer + (let ((message (context-coloring-test-get-last-message))) +(when (equal
[elpa] master ef544ef 29/47: Fontify keywords.
branch: master commit ef544ef9c523cf1586bb3f84da3eae91f6a87c03 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Fontify keywords. --- context-coloring.el |8 +--- 1 files changed, 5 insertions(+), 3 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index f21b323..d491f88 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -172,8 +172,6 @@ the END point (exclusive) with the face corresponding to LEVEL." "Tell `font-lock' to color a string but not a comment." (if (nth 3 state) font-lock-string-face nil)) -;; TODO: Add specialized emacs-lisp version based on -;; `lisp-font-lock-syntactic-face-function'. (defsubst context-coloring-maybe-colorize-comments-and-strings (&optional min max) "Color the current buffer's comments and strings if `context-coloring-comments-and-strings' is non-nil." @@ -192,7 +190,11 @@ the END point (exclusive) with the face corresponding to LEVEL." font-lock-syntactic-face-function (save-excursion (font-lock-fontify-syntactically-region (or min (point-min)) -(or max (point-max))) +(or max (point-max))) +;; TODO: Make configurable at the dispatch level. +(when (eq major-mode 'emacs-lisp-mode) + (font-lock-fontify-keywords-region (or min (point-min)) + (or max (point-max ;;; js2-mode colorization
[elpa] master 1d7761c 37/47: Add constant comment test.
branch: master commit 1d7761cfe379df92226216ad0fa49aa7fb619cb3 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Add constant comment test. --- test/context-coloring-test.el | 23 +-- test/fixtures/depth.el|2 ++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el index 5007c3c..7466e23 100644 --- a/test/context-coloring-test.el +++ b/test/context-coloring-test.el @@ -212,9 +212,9 @@ environment." "Assert that the face at POSITION satisfies FACE-REGEXP." (let ((face (get-text-property position 'face))) (when (or - ;; Pass a non-string to do an `eq' check (against a symbol or nil). + ;; Pass a non-string to do an `equal' check (against a symbol or nil). (unless (stringp face-regexp) - (not (eq face-regexp face))) + (not (equal face-regexp face))) ;; Otherwise do the matching. (when (stringp face-regexp) (not (string-match-p face-regexp (symbol-name face) @@ -229,6 +229,10 @@ environment." (context-coloring-test-assert-position-face position "\\`font-lock-comment\\(-delimiter\\)?-face\\'")) +(defun context-coloring-test-assert-position-constant-comment (position) + (context-coloring-test-assert-position-face position '(font-lock-constant-face + font-lock-comment-face))) + (defun context-coloring-test-assert-position-string (position) (context-coloring-test-assert-position-face position 'font-lock-string-face)) @@ -260,6 +264,10 @@ environment." ((= char 59) (context-coloring-test-assert-position-comment (point)) (forward-char)) + ;; 'c' = Constant comment + ((= char 99) +(context-coloring-test-assert-position-constant-comment (point)) +(forward-char)) ;; 's' = String ((= char 115) (context-coloring-test-assert-position-string (point)) @@ -1163,6 +1171,17 @@ see that function." 1 1 2 2 2 22 1 1 1 0 0 11"))) +(context-coloring-test-deftest-emacs-lisp-mode depth + (lambda () +(let ((context-coloring-emacs-lisp-iterations-per-pause 1)) + (context-coloring-colorize) + (context-coloring-test-assert-coloring " +;; `cc' `cc' +(x x ())"))) + :setup (lambda () + (setq context-coloring-syntactic-comments t) + (setq context-coloring-syntactic-strings t))) + (provide 'context-coloring-test) ;;; context-coloring-test.el ends here diff --git a/test/fixtures/depth.el b/test/fixtures/depth.el new file mode 100644 index 000..c4e99ac --- /dev/null +++ b/test/fixtures/depth.el @@ -0,0 +1,2 @@ +;; `aa' `bb' +(defun a ())
[elpa] master 5051a70 42/47: Update documentation for emacs lisp.
branch: master commit 5051a7021e22ff7584e76161b8e437075c593870 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Update documentation for emacs lisp. --- README.md | 24 ++-- context-coloring.el |2 +- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index bc21b62..39c15cf 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,12 @@ By default, comments and strings are still highlighted syntactically. ## Features -- Supported languages: JavaScript - Light and dark (customizable) color schemes. -- Very fast for files under 1000 lines. +- JavaScript support: + - Very fast for files under 1000 lines. + - Script, function and block scopes (and even `catch` block scopes). +- Emacs Lisp support: + - `defun`, `lambda`, `let`, `let*`, quotes, backticks, commas. ## Installation @@ -51,7 +54,7 @@ make compile (require 'context-coloring) ``` -### scopifier (for non-js2-mode users) +### Dependencies (js-mode) ```bash npm install -g scopifier @@ -62,12 +65,15 @@ npm install -g scopifier Add the following to your init file: ```lisp -;; non-js2-mode users: +;; js-mode: (add-hook 'js-mode-hook 'context-coloring-mode) -;; js2-mode users: +;; js2-mode: (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode)) (add-hook 'js2-mode-hook 'context-coloring-mode) + +;; emacs-lisp-mode: +(add-hook 'emacs-lisp-mode-hook 'context-coloring-mode) ``` ## Customizing @@ -79,7 +85,8 @@ Add the following to your init file: - `context-coloring-syntactic-strings` (default: `t`): If non-nil, also color strings using `font-lock`. - `context-coloring-delay` (default: `0.25`; supported modes: `js-mode`, - `js3-mode`): Delay between a buffer update and colorization. + `js3-mode`, `emacs-lisp-mode`): Delay between a buffer update and + colorization. - `context-coloring-js-block-scopes` (default: `nil`; supported modes: `js2-mode`): If non-nil, also color block scopes in the scope hierarchy in JavaScript. @@ -170,6 +177,11 @@ When a `--version` argument is passed, a scopifier should print its version number and exit. This allows context-coloring to determine if an update is required. +Alternatively, you could implement a "colorizer" in Emacs Lisp. A colorizer +also handles the job of calling `context-coloring-colorize-region` to apply +colors to a buffer. A colorizer may have better performance than a scopifier +when parsing and coloring can be performed in the same pass. + [js2-mode]: https://github.com/mooz/js2-mode [node]: http://nodejs.org/download/ [scopifier]: https://github.com/jacksonrayhamilton/scopifier diff --git a/context-coloring.el b/context-coloring.el index 46561f8..23af23d 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -1336,7 +1336,7 @@ precedence, i.e. the car of `custom-enabled-themes'." Increase this if your machine is high-performing. Decrease it if it ain't. -Supported modes: `js-mode', `js3-mode'" +Supported modes: `js-mode', `js3-mode', `emacs-lisp-mode'" :group 'context-coloring) (defun context-coloring-setup-idle-change-detection ()
[elpa] master 4bbce56 38/47: Add test for interruption.
branch: master commit 4bbce5681327381e34a745a364c45650c0b43e27 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Add test for interruption. --- context-coloring.el | 18 ++ test/context-coloring-test.el| 26 -- test/fixtures/{depth.el => iteration.el} |0 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 585f325..b8407a5 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -438,6 +438,7 @@ provide visually \"instant\" updates at ~60 frames per second.") (inhibit-point-motion-hooks t) (iteration-count 0) (last-fontified-position (point)) + beginning-of-current-defun end-of-current-defun (end (point-max)) (last-ppss-pos (point)) @@ -485,13 +486,22 @@ provide visually \"instant\" updates at ~60 frames per second.") ;; Fontify until the end of the current defun because doing it in ;; chunks based soley on point could result in partial ;; re-fontifications over the contents of scopes. -(setq end-of-current-defun (save-excursion - (end-of-defun) - (point))) +(save-excursion + (end-of-defun) + (setq end-of-current-defun (point)) + (beginning-of-defun) + (setq beginning-of-current-defun (point))) + ;; Fontify in chunks. (context-coloring-maybe-colorize-comments-and-strings last-fontified-position - end-of-current-defun) + (cond + ;; We weren't actually in a defun, so don't color the next one, as + ;; that could result in `font-lock' properties being added to it. + ((> beginning-of-current-defun (point)) + (point)) + (t + end-of-current-defun))) (setq last-fontified-position (point)) (when (and context-coloring-parse-interruptable-p (input-pending-p)) diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el index 7466e23..19f844b 100644 --- a/test/context-coloring-test.el +++ b/test/context-coloring-test.el @@ -236,6 +236,9 @@ environment." (defun context-coloring-test-assert-position-string (position) (context-coloring-test-assert-position-face position 'font-lock-string-face)) +(defun context-coloring-test-assert-position-nil (position) + (context-coloring-test-assert-position-face position nil)) + (defun context-coloring-test-assert-coloring (map) "Assert that the current buffer's coloring matches MAP." ;; Omit the superfluous, formatting-related leading newline. Can't use @@ -268,6 +271,10 @@ environment." ((= char 99) (context-coloring-test-assert-position-constant-comment (point)) (forward-char)) + ;; 'n' = nil + ((= char 110) +(context-coloring-test-assert-position-nil (point)) +(forward-char)) ;; 's' = String ((= char 115) (context-coloring-test-assert-position-string (point)) @@ -1171,13 +1178,28 @@ see that function." 1 1 2 2 2 22 1 1 1 0 0 11"))) -(context-coloring-test-deftest-emacs-lisp-mode depth +(defun context-coloring-test-insert-unread-space () + (setq unread-command-events (cons '(t . 32) +unread-command-events))) + +(defun context-coloring-test-remove-faces () + (remove-text-properties (point-min) (point-max) '(face nil))) + +(context-coloring-test-deftest-emacs-lisp-mode iteration (lambda () (let ((context-coloring-emacs-lisp-iterations-per-pause 1)) (context-coloring-colorize) (context-coloring-test-assert-coloring " ;; `cc' `cc' -(x x ())"))) +(x x ())") + (context-coloring-test-remove-faces) + (context-coloring-test-insert-unread-space) + (context-coloring-colorize) + ;; The first iteration will color the first part of the comment, but + ;; that's it. Then it will be interrupted. + (context-coloring-test-assert-coloring " +;; +nn n nnn"))) :setup (lambda () (setq context-coloring-syntactic-comments t) (setq context-coloring-syntactic-strings t))) diff --git a/test/fixtures/depth.el b/test/fixtures/iteration.el similarity index 100% rename from test/fixtures/depth.el rename to test/fixtures/iteration.el
[elpa] master d24de46 31/47: Add TODO.
branch: master commit d24de46c7c737df8a1438c7e5ba000fd375dce9e Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Add TODO. --- context-coloring.el |1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index ae6abea..1e9553d 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -1434,6 +1434,7 @@ elisp tracks, and asynchronously for shell command tracks." ;; Safely change the valye of this function as necessary. (make-local-variable 'font-lock-syntactic-face-function) +;; TODO: Detect derived modes. (let ((dispatch (gethash major-mode context-coloring-mode-hash-table))) (if dispatch (progn
[elpa] master eb429df 02/47: Use lowercase for hex codes.
branch: master commit eb429dfab8d9265dbdda91547f72e00818e39df2 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Use lowercase for hex codes. --- README.md | 22 +++--- context-coloring.el | 80 +- 2 files changed, 51 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index 6c895de..bc21b62 100644 --- a/README.md +++ b/README.md @@ -96,17 +96,17 @@ You can define your own theme colors too: ```lisp (context-coloring-define-theme 'zenburn - :colors '("#DCDCCC" - "#93E0E3" - "#BFEBBF" - "#F0DFAF" - "#DFAF8F" - "#CC9393" - "#DC8CC3" - "#94BFF3" - "#9FC59F" - "#D0BF8F" - "#DCA3A3")) + :colors '("#dcdccc" + "#93e0e3" + "#bfebbf" + "#f0dfaf" + "#dfaf8f" + "#cc9393" + "#dc8cc3" + "#94bff3" + "#9fc59f" + "#d0bf8f" + "#dca3a3")) ``` See `C-h f context-coloring-define-theme` for more info on theme parameters. diff --git a/context-coloring.el b/context-coloring.el index d32a27d..c5c7d3f 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -793,7 +793,7 @@ precedence, i.e. the car of `custom-enabled-themes'." "#5180b3" "#ab75c3" "#cd7542" - "#dF9522" + "#df9522" "#454545")) (context-coloring-define-theme @@ -827,27 +827,27 @@ precedence, i.e. the car of `custom-enabled-themes'." 'leuven :recede t :colors '("#33" - "#FF" - "#6434A3" - "#BA36A5" - "#D0372D" - "#036A07" + "#ff" + "#6434a3" + "#ba36a5" + "#d0372d" + "#036a07" "#006699" - "#006FE0" + "#006fe0" "#808080")) (context-coloring-define-theme 'monokai :recede t - :colors '("#F8F8F2" - "#66D9EF" - "#A1EFE4" - "#A6E22E" - "#E6DB74" - "#FD971F" - "#F92672" - "#FD5FF0" - "#AE81FF")) + :colors '("#f8f8f2" + "#66d9ef" + "#a1efe4" + "#a6e22e" + "#e6db74" + "#fd971f" + "#f92672" + "#fd5ff0" + "#ae81ff")) (context-coloring-define-theme 'solarized @@ -865,26 +865,26 @@ precedence, i.e. the car of `custom-enabled-themes'." "#dc322f" "#d33682" "#6c71c4" - "#69B7F0" - "#69CABF" - "#B4C342" - "#DEB542" - "#F2804F" - "#FF6E64" - "#F771AC" - "#9EA0E5")) + "#69b7f0" + "#69cabf" + "#b4c342" + "#deb542" + "#f2804f" + "#ff6e64" + "#f771ac" + "#9ea0e5")) (context-coloring-define-theme 'spacegray :recede t :colors '("#ff" - "#89AAEB" - "#C189EB" + "#89aaeb" + "#c189eb" "#bf616a" - "#DCA432" + "#dca432" "#ebcb8b" - "#B4EB89" - "#89EBCA")) + "#b4eb89" + "#89ebca")) (context-coloring-define-theme 'tango @@ -906,17 +906,17 @@ precedence, i.e. the car of `custom-enabled-themes'." (context-coloring-define-theme 'zenburn :recede t - :colors '("#DCDCCC" - "#93E0E3" - "#BFEBBF" - "#F0DFAF" - "#DFAF8F" - "#CC9393" - "#DC8CC3" - "#94BFF3" - "#9FC59F" - "#D0BF8F" - "#DCA3A3")) + :colors '("#dcdccc" + "#93e0e3" + "#bfebbf" + "#f0dfaf" + "#dfaf8f" + "#cc9393" + "#dc8cc3" + "#94bff3" + "#9fc59f" + "#d0bf8f" + "#dca3a3")) ;;; Minor mode
[elpa] master d7b2c92 21/47: Remove unused functions.
branch: master commit d7b2c927664bf65962d7b8d893e56e1a2e38c623 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Remove unused functions. --- context-coloring.el |6 -- 1 files changed, 0 insertions(+), 6 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 6f161c6..f217694 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -302,9 +302,6 @@ generated by `js2-mode'." :level level :variables (make-hash-table))) -(defun context-coloring-scope-get-depth (scope) - (plist-get scope :depth)) - (defun context-coloring-scope-get-level (scope) (plist-get scope :level)) @@ -347,9 +344,6 @@ generated by `js2-mode'." :type type :vars '())) -(defun context-coloring-let-varlist-get-depth (let-varlist) - (plist-get let-varlist :depth)) - (defun context-coloring-let-varlist-get-type (let-varlist) (plist-get let-varlist :type))
[elpa] master c0a6689 33/47: Only set defaults when the mode is enabled.
branch: master commit c0a66895bf685ebbf36614b89ca2b187e3f4e351 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Only set defaults when the mode is enabled. --- context-coloring.el |4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 3a05bc2..bf1d533 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -193,7 +193,6 @@ the END point (exclusive) with the face corresponding to LEVEL." (or max (point-max))) ;; TODO: Make configurable at the dispatch level. (when (eq major-mode 'emacs-lisp-mode) - (font-lock-set-defaults) (font-lock-fontify-keywords-region (or min (point-min)) (or max (point-max @@ -1432,6 +1431,9 @@ elisp tracks, and asynchronously for shell command tracks." (font-lock-mode 0) (jit-lock-mode nil) +;; ...but we do use font-lock functions here. +(font-lock-set-defaults) + ;; Safely change the valye of this function as necessary. (make-local-variable 'font-lock-syntactic-face-function)
[elpa] master 284cfa6 08/47: Don't treat unbindables like variables.
branch: master commit 284cfa6f6743c270c6dc8e9a383c29e450ad3ade Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Don't treat unbindables like variables. --- context-coloring.el |6 -- test/context-coloring-test.el |5 + test/fixtures/unbindable.el |2 ++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 92e4578..3bd2b0f 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -526,8 +526,10 @@ generated by `js2-mode'." token-pos variable-end)) (cond - ;; Ignore numbers - ((string-match-p "\\`[-+]?[0-9]" variable-string)) + ;; Ignore constants such as numbers, keywords, t, nil. These can't + ;; be rebound, so they should be treated like syntax. + ((string-match-p "\\`[-+]?[0-9]\\|\\`t\\'\\|\\`nil\\'" variable-string)) + ((keywordp (read variable-string))) (t (setq variable (intern variable-string)) (setq variable-scope-level diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el index 192d2ef..8e5b699 100644 --- a/test/context-coloring-test.el +++ b/test/context-coloring-test.el @@ -1077,6 +1077,11 @@ see that function." :setup (lambda () (setq context-coloring-syntactic-strings t))) +(context-coloring-test-deftest-emacs-lisp-mode unbindable + (lambda () +(context-coloring-test-assert-region-level 20 40 1) ; 1 +1 -1 1.0 :a t nil +)) + (provide 'context-coloring-test) ;;; context-coloring-test.el ends here diff --git a/test/fixtures/unbindable.el b/test/fixtures/unbindable.el new file mode 100644 index 000..d5bb47f --- /dev/null +++ b/test/fixtures/unbindable.el @@ -0,0 +1,2 @@ +(defun a () + (+ a 1 +1 -1 1.0 :a t nil))
[elpa] master a556195 26/47: Tweak iteration values, add logging.
branch: master commit a5561959ebcdca49de518b7e8a40785bde5a52bf Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Tweak iteration values, add logging. --- context-coloring.el | 28 +++- 1 files changed, 19 insertions(+), 9 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 22097a5..a513947 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -406,11 +406,17 @@ generated by `js2-mode'." (defvar context-coloring-parse-interruptable-p t "Set this to nil to force parse to continue until finished.") -(defvar context-coloring-tokens-per-pause 25 - "Pause after this many statements to check for user input. +(defvar context-coloring-emacs-lisp-iterations-per-pause 1000 + "Pause after this many iterations to check for user input. If user input is pending, stop the parse. This makes for a -smoother user experience for large files. This appears to be -more or less how Eclipse, IntelliJ and other editors work.") +smoother user experience for large files. + +As of this writing, emacs lisp colorization seems to run at about +60,000 iterations per second. A default value of 1000 should +provide visually \"instant\" updates at ~60 frames per second.") + +(defvar context-coloring-verbose-parse t + "Log useful information pertaining to a parse.") (defun context-coloring-emacs-lisp-colorize () "Color the current buffer by parsing emacs lisp sexps." @@ -418,8 +424,9 @@ more or less how Eclipse, IntelliJ and other editors work.") (save-excursion ;; TODO: Can probably make this lazy to the nearest defun. (goto-char (point-min)) - (let* ((inhibit-point-motion-hooks t) - (token-count 0) + (let* ((start-time (float-time)) + (inhibit-point-motion-hooks t) + (iteration-count 0) (end (point-max)) (last-ppss-pos (point)) (ppss (syntax-ppss)) @@ -460,8 +467,8 @@ more or less how Eclipse, IntelliJ and other editors work.") (while (> end (progn (skip-syntax-forward "^()w_'" end) (point))) (and context-coloring-parse-interruptable-p - (zerop (% (setq token-count (1+ token-count)) - context-coloring-tokens-per-pause)) + (zerop (% (setq iteration-count (1+ iteration-count)) + context-coloring-emacs-lisp-iterations-per-pause)) (input-pending-p) (throw 'interrupted t)) (setq token-pos (point)) @@ -693,7 +700,10 @@ more or less how Eclipse, IntelliJ and other editors work.") (context-coloring-scope-add-variable (car scope-stack) (car popped-vars)) (setq popped-vars (cdr popped-vars - + )) +(when context-coloring-verbose-parse + (message "Elapsed: %s; iterations: %s" + (- (float-time) start-time) iteration-count (context-coloring-maybe-colorize-comments-and-strings)))
[elpa] master 0836b9f 22/47: Add change hooks for elisp.
branch: master commit 0836b9f6ea7531d2d0be8fcd8a84418fc3fb09ad Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Add change hooks for elisp. --- context-coloring.el | 103 +-- 1 files changed, 59 insertions(+), 44 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index f217694..6c56d14 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -842,49 +842,6 @@ should be numeric, e.g. \"2\", \"19700101\", \"1.2.3\", (when (null (gethash mode context-coloring-mode-hash-table)) (puthash mode properties context-coloring-mode-hash-table) -(context-coloring-define-dispatch - 'javascript-node - :modes '(js-mode js3-mode) - :executable "scopifier" - :command "scopifier" - :version "v1.1.1") - -(context-coloring-define-dispatch - 'javascript-js2 - :modes '(js2-mode) - :colorizer 'context-coloring-js2-colorize - :setup - (lambda () - (add-hook 'js2-post-parse-callbacks 'context-coloring-colorize nil t)) - :teardown - (lambda () - (remove-hook 'js2-post-parse-callbacks 'context-coloring-colorize t))) - -(context-coloring-define-dispatch - 'emacs-lisp - :modes '(emacs-lisp-mode) - :colorizer 'context-coloring-emacs-lisp-colorize) - -(defun context-coloring-dispatch (&optional callback) - "Determine the optimal track for scopification / coloring of -the current buffer, then execute it. - -Invoke CALLBACK when complete. It is invoked synchronously for -elisp tracks, and asynchronously for shell command tracks." - (let ((dispatch (gethash major-mode context-coloring-mode-hash-table)) -colorizer -scopifier -command) -(cond - ((setq colorizer (plist-get dispatch :colorizer)) - (funcall colorizer) - (when callback (funcall callback))) - ((setq scopifier (plist-get dispatch :scopifier)) - (context-coloring-apply-tokens (funcall scopifier)) - (when callback (funcall callback))) - ((setq command (plist-get dispatch :command)) - (context-coloring-scopify-and-colorize command callback) - ;;; Colorization @@ -1316,7 +1273,7 @@ precedence, i.e. the car of `custom-enabled-themes'." "#dca3a3")) -;;; Minor mode +;;; Change detection (defvar-local context-coloring-colorize-idle-timer nil "The currently-running idle timer.") @@ -1340,6 +1297,64 @@ Supported modes: `js-mode', `js3-mode'" t 'context-coloring-maybe-colorize))) + +;;; Built-in dispatches + +(context-coloring-define-dispatch + 'javascript-node + :modes '(js-mode js3-mode) + :executable "scopifier" + :command "scopifier" + :version "v1.1.1") + +(context-coloring-define-dispatch + 'javascript-js2 + :modes '(js2-mode) + :colorizer 'context-coloring-js2-colorize + :setup + (lambda () + (add-hook 'js2-post-parse-callbacks 'context-coloring-colorize nil t)) + :teardown + (lambda () + (remove-hook 'js2-post-parse-callbacks 'context-coloring-colorize t))) + +(context-coloring-define-dispatch + 'emacs-lisp + :modes '(emacs-lisp-mode) + :colorizer 'context-coloring-emacs-lisp-colorize + :setup + (lambda () + (context-coloring-setup-idle-change-detection)) + :teardown + (lambda () + (when context-coloring-colorize-idle-timer + (cancel-timer context-coloring-colorize-idle-timer)) + (remove-hook +'after-change-functions 'context-coloring-change-function t))) + +(defun context-coloring-dispatch (&optional callback) + "Determine the optimal track for scopification / coloring of +the current buffer, then execute it. + +Invoke CALLBACK when complete. It is invoked synchronously for +elisp tracks, and asynchronously for shell command tracks." + (let ((dispatch (gethash major-mode context-coloring-mode-hash-table)) +colorizer +scopifier +command) +(cond + ((setq colorizer (plist-get dispatch :colorizer)) + (funcall colorizer) + (when callback (funcall callback))) + ((setq scopifier (plist-get dispatch :scopifier)) + (context-coloring-apply-tokens (funcall scopifier)) + (when callback (funcall callback))) + ((setq command (plist-get dispatch :command)) + (context-coloring-scopify-and-colorize command callback) + + +;;; Minor mode + ;;;###autoload (define-minor-mode context-coloring-mode "Context-based code coloring, inspired by Douglas Crockford."
[elpa] master bd9c147 20/47: Ignore the dot.
branch: master commit bd9c14741615469cc19aebaa659124117bf78169 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Ignore the dot. --- context-coloring.el |6 +++--- test/context-coloring-test.el |4 ++-- test/fixtures/ignored.el |2 ++ test/fixtures/unbindable.el |2 -- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 4a37389..6f161c6 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -407,8 +407,8 @@ generated by `js2-mode'." (defconst context-coloring-arglist-arg-regexp "\\`[^&:]") -(defconst context-coloring-unbindable-constant-regexp - "\\`[-+]?[0-9]\\|\\`t\\'\\|\\`nil\\'") +(defconst context-coloring-ignored-word-regexp + "\\`[-+]?[0-9]\\|\\`t\\'\\|\\`nil\\'\\|\\`\\.\\'") (defconst context-coloring-COMMA-CHAR 44) (defconst context-coloring-BACKTICK-CHAR 96) @@ -630,7 +630,7 @@ generated by `js2-mode'." (cond ;; Ignore constants such as numbers, keywords, t, nil. These can't ;; be rebound, so they should be treated like syntax. - ((string-match-p context-coloring-unbindable-constant-regexp variable-string)) + ((string-match-p context-coloring-ignored-word-regexp variable-string)) ((keywordp (read variable-string))) (t (setq variable (intern variable-string)) diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el index 234084c..9573119 100644 --- a/test/context-coloring-test.el +++ b/test/context-coloring-test.el @@ -1130,11 +1130,11 @@ see that function." :setup (lambda () (setq context-coloring-syntactic-strings t))) -(context-coloring-test-deftest-emacs-lisp-mode unbindable +(context-coloring-test-deftest-emacs-lisp-mode ignored (lambda () (context-coloring-test-assert-coloring " (x x () - (x x 1 11 11 111 11 1 111))"))) + (x x 1 11 11 111 11 1 111 (1 1 1)))"))) (context-coloring-test-deftest-emacs-lisp-mode let (lambda () diff --git a/test/fixtures/ignored.el b/test/fixtures/ignored.el new file mode 100644 index 000..776a846 --- /dev/null +++ b/test/fixtures/ignored.el @@ -0,0 +1,2 @@ +(defun a () + (+ a 1 +1 -1 1.0 :a t nil (0 . 0))) diff --git a/test/fixtures/unbindable.el b/test/fixtures/unbindable.el deleted file mode 100644 index d5bb47f..000 --- a/test/fixtures/unbindable.el +++ /dev/null @@ -1,2 +0,0 @@ -(defun a () - (+ a 1 +1 -1 1.0 :a t nil))
[elpa] master d9d901f 03/47: Add basic elisp defun coloring.
branch: master commit d9d901f2f60ec3f95fe6d6b5e6342cb5583918ac Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Add basic elisp defun coloring. --- context-coloring.el | 186 + test/context-coloring-test.el | 29 +++ test/fixtures/defun.el|4 + 3 files changed, 219 insertions(+), 0 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index c5c7d3f..7787cb5 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -294,6 +294,187 @@ generated by `js2-mode'." (context-coloring-maybe-colorize-comments-and-strings))) +;;; Emacs Lisp colorization + +(defun context-coloring-make-scope (depth level) + (list + :depth depth + :level level + :variables (make-hash-table))) + +(defun context-coloring-scope-get-depth (scope) + (plist-get scope :depth)) + +(defun context-coloring-scope-get-level (scope) + (plist-get scope :level)) + +(defun context-coloring-scope-add-variable (scope variable) + (puthash variable t (plist-get scope :variables))) + +(defun context-coloring-scope-get-variable (scope variable) + (gethash variable (plist-get scope :variables))) + +(defun context-coloring-get-variable-level (scope-stack variable) + (let* (scope + level) +(while (and scope-stack (not level)) + (setq scope (car scope-stack)) + (cond + ((context-coloring-scope-get-variable scope variable) +(setq level (context-coloring-scope-get-level scope))) + (t +(setq scope-stack (cdr scope-stack) +;; Assume global +(or level 0))) + +(defun context-coloring-emacs-lisp-identifier-syntax-p (syntax-code) + (or (= 2 syntax-code) + (= 3 syntax-code))) + +(defun context-coloring-emacs-lisp-colorize () + "Color the current buffer by parsing emacs lisp sexps." + (with-silent-modifications +(save-excursion + ;; TODO: Can probably make this lazy to the nearest defun + (goto-char (point-min)) + (let* ((inhibit-point-motion-hooks t) + (end (point-max)) + (last-ppss-pos (point)) + (ppss (syntax-ppss)) + (scope-stack `(,(context-coloring-make-scope -1 0))) ; -1 never matches a depth + one-word-found-p + in-defun-p + function-call-p + defun-arglist + defun-arg + variable + variable-end + variable-string + variable-scope-level + token-pos + token-syntax + token-syntax-code + child-0-pos + child-0-end + child-0-syntax + child-0-syntax-code + child-0-string + child-1-pos + child-1-end + child-1-syntax + child-1-syntax-code + child-2-end) +(while (> end (progn (skip-syntax-forward "^()w_" end) + (point))) + (setq token-pos (point)) + (setq token-syntax (syntax-after token-pos)) + (setq ppss (parse-partial-sexp last-ppss-pos token-pos nil nil ppss)) + (setq last-ppss-pos token-pos) + ;; `skip-syntax-forward' leaves the point at the delimiter, move past + ;; it. + (setq token-syntax-code (logand #x (car token-syntax))) + (cond + ;; Opening delimiter + ((= 4 token-syntax-code) +(forward-char) +;; Lookahead for scopes / function calls +(skip-syntax-forward " " end) +(setq child-0-pos (point)) +(setq child-0-syntax (syntax-after child-0-pos)) +(setq child-0-syntax-code (logand #x (car child-0-syntax))) +(cond + ;; Word + ((context-coloring-emacs-lisp-identifier-syntax-p child-0-syntax-code) + (setq one-word-found-p t) + (setq child-0-end (scan-sexps child-0-pos 1)) + (setq child-0-string (buffer-substring-no-properties child-0-pos child-0-end)) + (cond + ((string-match-p "defun\\|defmacro" child-0-string) +(setq in-defun-p t) +(setq scope-stack (cons (context-coloring-make-scope + (nth 0 ppss) + (1+ (context-coloring-scope-get-level + (car scope-stack +scope-stack))) + ;; Assume a global function call + (t +(setq function-call-p t) +;; TODO: Probably redundant and wasteful +(context-coloring-colorize-region token-pos + (scan-sexps token-pos 1) + (context-coloring-scope-get-level + (car scope-stack))) +(when function-call-p +
[elpa] master dd8d491 12/47: Also color defsubst.
branch: master commit dd8d4916a2ebbd6f0b15912434280948eba5c70c Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Also color defsubst. --- context-coloring.el |4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 0f65b57..a84a1b4 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -466,7 +466,9 @@ generated by `js2-mode'." (setq child-0-end (scan-sexps child-0-pos 1)) (setq child-0-string (buffer-substring-no-properties child-0-pos child-0-end)) (cond - ((string-match-p "\\`defun\\'\\|\\`defmacro\\'" child-0-string) + ((string-match-p + "\\`defun\\'\\|\\`defmacro\\'\\|\\`defsubst\\'" + child-0-string) (setq in-defun-p t)) ((string-match-p "\\`lambda\\'" child-0-string) (setq in-lambda-p t))
[elpa] master 58b7474 11/47: Don't color function calls as level 0.
branch: master commit 58b7474f6d6e80a3b91c782c23453d173588f878 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Don't color function calls as level 0. --- context-coloring.el |9 + test/context-coloring-test.el | 14 +++--- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index 3a57b3f..0f65b57 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -376,7 +376,6 @@ generated by `js2-mode'." in-defun-p in-lambda-p in-let*-p - function-call-p defun-arglist defun-arg let-varlist @@ -472,10 +471,7 @@ generated by `js2-mode'." ((string-match-p "\\`lambda\\'" child-0-string) (setq in-lambda-p t)) ((string-match-p "\\`let\\*\\'" child-0-string) -(setq in-let*-p t)) - ;; Assume a global function call - (t -(setq function-call-p t) +(setq in-let*-p t) (when (or in-defun-p in-lambda-p in-let*-p) @@ -489,9 +485,6 @@ generated by `js2-mode'." (scan-sexps token-pos 1) (context-coloring-scope-get-level (car scope-stack))) -(when function-call-p - (context-coloring-colorize-region child-0-pos child-0-end 0) - (setq function-call-p nil)) (cond ((or in-defun-p in-lambda-p) diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el index 148ddac..c8a3532 100644 --- a/test/context-coloring-test.el +++ b/test/context-coloring-test.el @@ -1090,7 +1090,7 @@ see that function." (lambda () (context-coloring-test-assert-coloring " 11 000 111 1 - 10 111 111 111 11 + 11 111 111 111 11 0 0 00 @@ -1101,16 +1101,16 @@ see that function." (lambda () (context-coloring-test-assert-coloring " 111 - 1000 11 222 - 200 22 12 2221 111 0 00"))) + 11 222 + 222 22 12 2221 111 0 00"))) (context-coloring-test-deftest-emacs-lisp-mode quote (lambda () (context-coloring-test-assert-coloring " (x x (x) (xx (xx x 111 - 10 1 111 111 - 10 1 00 11 111 1 110 1 1 1 11 1 1 1"))) + 11 1 111 111 + 11 1 11 11 111 1 111 1 1 1 11 1 1 1"))) (context-coloring-test-deftest-emacs-lisp-mode comment (lambda () @@ -1118,7 +1118,7 @@ see that function." (context-coloring-test-assert-coloring " (x x () (xx (x x- xx) ;; - (0 x- xx))) ;;")) + 11 0- 11))) ;;")) :setup (lambda () (setq context-coloring-syntactic-comments t))) @@ -1134,7 +1134,7 @@ see that function." (lambda () (context-coloring-test-assert-coloring " (x x () - (0 0 1 11 11 111 11 1 111))"))) + (x x 1 11 11 111 11 1 111))"))) (context-coloring-test-deftest-emacs-lisp-mode let* (lambda ()
[elpa] master 5e34bec 04/47: Cover malformed defun cases.
branch: master commit 5e34bec7fcfaaaf9c7bd34bd718ea52d2f991dfe Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton 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 #x (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 #x (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 ())
[elpa] master 3fc5b20 27/47: Make dispatches fully redefinable.
branch: master commit 3fc5b201808b57efcab2e4f61e7afdc3cd3009ca Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Make dispatches fully redefinable. --- context-coloring.el |3 +-- 1 files changed, 1 insertions(+), 2 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index a513947..d1c2d52 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -864,8 +864,7 @@ interrupted (for synchronous strategies like `:colorizer' and (error "No colorizer, scopifier or command defined for dispatch")) (puthash symbol properties context-coloring-dispatch-hash-table) (dolist (mode modes) - (when (null (gethash mode context-coloring-mode-hash-table)) -(puthash mode properties context-coloring-mode-hash-table) + (puthash mode properties context-coloring-mode-hash-table ;;; Colorization
[elpa] master 438cb33 36/47: Fix incorrect last fontified position.
branch: master commit 438cb336604d867478a941d3814eaf820817bf3e Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Fix incorrect last fontified position. --- context-coloring.el |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/context-coloring.el b/context-coloring.el index ead1a79..585f325 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -492,7 +492,7 @@ provide visually \"instant\" updates at ~60 frames per second.") (context-coloring-maybe-colorize-comments-and-strings last-fontified-position end-of-current-defun) -(setq last-fontified-position end-of-current-defun) +(setq last-fontified-position (point)) (when (and context-coloring-parse-interruptable-p (input-pending-p)) (throw 'interrupted t)))
[elpa] master b525e2d 47/47: Merge commit '3bf805df83fe6f110f3e7e8ce2dc37e0cf6c14cb' from context-coloring
branch: master commit b525e2d04fd260fb6ccebb3355583329edde24f3 Merge: e42b97b 3bf805d Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Merge commit '3bf805df83fe6f110f3e7e8ce2dc37e0cf6c14cb' from context-coloring --- packages/context-coloring/README.md| 46 +- packages/context-coloring/context-coloring.el | 751 .../context-coloring/test/context-coloring-test.el | 275 +++- packages/context-coloring/test/fixtures/comment.el |3 + packages/context-coloring/test/fixtures/defun.el |7 + packages/context-coloring/test/fixtures/ignored.el |2 + .../context-coloring/test/fixtures/iteration.el|2 + packages/context-coloring/test/fixtures/lambda.el |3 + packages/context-coloring/test/fixtures/let*.el| 11 + packages/context-coloring/test/fixtures/let.el |8 + packages/context-coloring/test/fixtures/quote.el |4 + packages/context-coloring/test/fixtures/string.el |2 + 12 files changed, 947 insertions(+), 167 deletions(-) diff --git a/packages/context-coloring/README.md b/packages/context-coloring/README.md index 6c895de..39c15cf 100644 --- a/packages/context-coloring/README.md +++ b/packages/context-coloring/README.md @@ -13,9 +13,12 @@ By default, comments and strings are still highlighted syntactically. ## Features -- Supported languages: JavaScript - Light and dark (customizable) color schemes. -- Very fast for files under 1000 lines. +- JavaScript support: + - Very fast for files under 1000 lines. + - Script, function and block scopes (and even `catch` block scopes). +- Emacs Lisp support: + - `defun`, `lambda`, `let`, `let*`, quotes, backticks, commas. ## Installation @@ -51,7 +54,7 @@ make compile (require 'context-coloring) ``` -### scopifier (for non-js2-mode users) +### Dependencies (js-mode) ```bash npm install -g scopifier @@ -62,12 +65,15 @@ npm install -g scopifier Add the following to your init file: ```lisp -;; non-js2-mode users: +;; js-mode: (add-hook 'js-mode-hook 'context-coloring-mode) -;; js2-mode users: +;; js2-mode: (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode)) (add-hook 'js2-mode-hook 'context-coloring-mode) + +;; emacs-lisp-mode: +(add-hook 'emacs-lisp-mode-hook 'context-coloring-mode) ``` ## Customizing @@ -79,7 +85,8 @@ Add the following to your init file: - `context-coloring-syntactic-strings` (default: `t`): If non-nil, also color strings using `font-lock`. - `context-coloring-delay` (default: `0.25`; supported modes: `js-mode`, - `js3-mode`): Delay between a buffer update and colorization. + `js3-mode`, `emacs-lisp-mode`): Delay between a buffer update and + colorization. - `context-coloring-js-block-scopes` (default: `nil`; supported modes: `js2-mode`): If non-nil, also color block scopes in the scope hierarchy in JavaScript. @@ -96,17 +103,17 @@ You can define your own theme colors too: ```lisp (context-coloring-define-theme 'zenburn - :colors '("#DCDCCC" - "#93E0E3" - "#BFEBBF" - "#F0DFAF" - "#DFAF8F" - "#CC9393" - "#DC8CC3" - "#94BFF3" - "#9FC59F" - "#D0BF8F" - "#DCA3A3")) + :colors '("#dcdccc" + "#93e0e3" + "#bfebbf" + "#f0dfaf" + "#dfaf8f" + "#cc9393" + "#dc8cc3" + "#94bff3" + "#9fc59f" + "#d0bf8f" + "#dca3a3")) ``` See `C-h f context-coloring-define-theme` for more info on theme parameters. @@ -170,6 +177,11 @@ When a `--version` argument is passed, a scopifier should print its version number and exit. This allows context-coloring to determine if an update is required. +Alternatively, you could implement a "colorizer" in Emacs Lisp. A colorizer +also handles the job of calling `context-coloring-colorize-region` to apply +colors to a buffer. A colorizer may have better performance than a scopifier +when parsing and coloring can be performed in the same pass. + [js2-mode]: https://github.com/mooz/js2-mode [node]: http://nodejs.org/download/ [scopifier]: https://github.com/jacksonrayhamilton/scopifier diff --git a/packages/context-coloring/context-coloring.el b/packages/context-coloring/context-coloring.el index d73773a..cb74ee7 100644 --- a/packages/context-coloring/context-coloring.el +++ b/packages/context-coloring/context-coloring.el @@ -3,10 +3,10 @@ ;; Copyright (C) 2014-2015 Free Software Foundation, Inc. ;; Author: Jackson Ray Hamilton -;; Version: 6.2.1 +;; Version: 6.3.0 ;; Keywords: convenience faces tools -;; Homepage: https://github.com/jacksonrayhamilton/context-coloring ;; Package-Requires: ((emacs "24") (js2-mode "20150126")) +;; URL: https://github.com/jacksonrayhamilton/context-coloring ;; This file is part of GNU Emacs. @@ -32,27 +32,11 @@ ;; By default, comments and strings are still highlighted syntactically. -;; To use with js2-mode, add the fol
[elpa] master c6e173b 45/47: Merge branch 'elisp'
branch: master commit c6e173b4d603cdc54080569bbc78038473921a97 Merge: eb429df 3b6a391 Author: Jackson Ray Hamilton Commit: Jackson Ray Hamilton Merge branch 'elisp' --- README.md | 24 ++- context-coloring.el | 657 - test/context-coloring-test.el | 275 - test/fixtures/comment.el |3 + test/fixtures/defun.el|7 + test/fixtures/ignored.el |2 + test/fixtures/iteration.el|2 + test/fixtures/lambda.el |3 + test/fixtures/let*.el | 11 + test/fixtures/let.el |8 + test/fixtures/quote.el|4 + test/fixtures/string.el |2 + 12 files changed, 894 insertions(+), 104 deletions(-) diff --git a/README.md b/README.md index bc21b62..39c15cf 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,12 @@ By default, comments and strings are still highlighted syntactically. ## Features -- Supported languages: JavaScript - Light and dark (customizable) color schemes. -- Very fast for files under 1000 lines. +- JavaScript support: + - Very fast for files under 1000 lines. + - Script, function and block scopes (and even `catch` block scopes). +- Emacs Lisp support: + - `defun`, `lambda`, `let`, `let*`, quotes, backticks, commas. ## Installation @@ -51,7 +54,7 @@ make compile (require 'context-coloring) ``` -### scopifier (for non-js2-mode users) +### Dependencies (js-mode) ```bash npm install -g scopifier @@ -62,12 +65,15 @@ npm install -g scopifier Add the following to your init file: ```lisp -;; non-js2-mode users: +;; js-mode: (add-hook 'js-mode-hook 'context-coloring-mode) -;; js2-mode users: +;; js2-mode: (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode)) (add-hook 'js2-mode-hook 'context-coloring-mode) + +;; emacs-lisp-mode: +(add-hook 'emacs-lisp-mode-hook 'context-coloring-mode) ``` ## Customizing @@ -79,7 +85,8 @@ Add the following to your init file: - `context-coloring-syntactic-strings` (default: `t`): If non-nil, also color strings using `font-lock`. - `context-coloring-delay` (default: `0.25`; supported modes: `js-mode`, - `js3-mode`): Delay between a buffer update and colorization. + `js3-mode`, `emacs-lisp-mode`): Delay between a buffer update and + colorization. - `context-coloring-js-block-scopes` (default: `nil`; supported modes: `js2-mode`): If non-nil, also color block scopes in the scope hierarchy in JavaScript. @@ -170,6 +177,11 @@ When a `--version` argument is passed, a scopifier should print its version number and exit. This allows context-coloring to determine if an update is required. +Alternatively, you could implement a "colorizer" in Emacs Lisp. A colorizer +also handles the job of calling `context-coloring-colorize-region` to apply +colors to a buffer. A colorizer may have better performance than a scopifier +when parsing and coloring can be performed in the same pass. + [js2-mode]: https://github.com/mooz/js2-mode [node]: http://nodejs.org/download/ [scopifier]: https://github.com/jacksonrayhamilton/scopifier diff --git a/context-coloring.el b/context-coloring.el index c5c7d3f..5c3b76f 100644 --- a/context-coloring.el +++ b/context-coloring.el @@ -47,12 +47,6 @@ (require 'js2-mode) -;;; Local variables - -(defvar-local context-coloring-buffer nil - "Reference to this buffer (for timers).") - - ;;; Utilities (defun context-coloring-join (strings delimiter) @@ -172,29 +166,29 @@ the END point (exclusive) with the face corresponding to LEVEL." "Tell `font-lock' to color a string but not a comment." (if (nth 3 state) font-lock-string-face nil)) -(defsubst context-coloring-maybe-colorize-comments-and-strings () +(defsubst context-coloring-maybe-colorize-comments-and-strings (&optional min max) "Color the current buffer's comments and strings if `context-coloring-comments-and-strings' is non-nil." (when (or context-coloring-comments-and-strings context-coloring-syntactic-comments context-coloring-syntactic-strings) -(let ((old-function font-lock-syntactic-face-function) - saved-function-p) - (cond - ((and context-coloring-syntactic-comments - (not context-coloring-syntactic-strings)) -(setq font-lock-syntactic-face-function - 'context-coloring-font-lock-syntactic-comment-function) -(setq saved-function-p t)) - ((and context-coloring-syntactic-strings - (not context-coloring-syntactic-comments)) -(setq font-lock-syntactic-face-function - 'context-coloring-font-lock-syntactic-string-function) -(setq saved-function-p t))) +(let ((min (or min (point-min))) + (max (or max (point-max))) + (font-lock-syntactic-face-function + (cond +((and context-coloring-syntactic-comments + (not context-coloring-syntactic-strings)) + 'con