emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 1d1af16 11/11: Merge commit 'f062d5a55496e22cf89f2ef9778a2


From: Jackson Ray Hamilton
Subject: [elpa] master 1d1af16 11/11: Merge commit 'f062d5a55496e22cf89f2ef9778a24a840a5a68e' from context-coloring
Date: Sat, 14 Mar 2015 20:21:45 +0000

branch: master
commit 1d1af16fbd945715c320d093a437767037efb2e3
Merge: b36c4b4 f062d5a
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>

    Merge commit 'f062d5a55496e22cf89f2ef9778a24a840a5a68e' from 
context-coloring
---
 packages/context-coloring/Makefile                 |    3 +-
 packages/context-coloring/README.md                |   20 ++-
 .../benchmark/context-coloring-benchmark.el        |    2 +
 packages/context-coloring/context-coloring.el      |   56 ++++++-
 packages/context-coloring/scripts/dependencies     |    2 +
 .../scripts/download-dependencies.el               |   51 ++++---
 .../context-coloring/test/context-coloring-test.el |  173 +++++++++++++-------
 .../test/fixtures/comments-and-strings.js          |    1 +
 8 files changed, 213 insertions(+), 95 deletions(-)

diff --git a/packages/context-coloring/Makefile 
b/packages/context-coloring/Makefile
index c265382..3a6a0be 100644
--- a/packages/context-coloring/Makefile
+++ b/packages/context-coloring/Makefile
@@ -25,7 +25,8 @@ clean: uncompile
 
 ${DEPENDENCIES}:
        ${EMACS} -Q -batch \
-       -l scripts/download-dependencies.el
+       -l scripts/download-dependencies.el \
+       -f download-dependencies
 
 test: ${DEPENDENCIES}
        ${EMACS} -Q -batch \
diff --git a/packages/context-coloring/README.md 
b/packages/context-coloring/README.md
index ff305c1..7eeacf7 100644
--- a/packages/context-coloring/README.md
+++ b/packages/context-coloring/README.md
@@ -89,6 +89,20 @@ Add the following to your `~/.emacs` file:
 
 ## Customizing
 
+### Options
+
+- `context-coloring-syntactic-comments` (default: `t`): If non-nil, also color
+  comments using `font-lock`.
+- `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.
+- `context-coloring-js-block-scopes` (default: `nil`; supported modes:
+  `js2-mode`): If non-nil, also color block scopes in the scope hierarchy in
+  JavaScript.
+
+### Color Schemes
+
 Color schemes for custom themes are automatically applied when those themes are
 active. Built-in theme support is available for: `ample`, `anti-zenburn`,
 `grandshell`, `leuven`, `monokai`, `solarized`, `spacegray`, `tango` and
@@ -124,13 +138,13 @@ more info on dispatch strategies.)
 A "scopifier" is a CLI program that reads a buffer's contents from stdin and
 writes a JSON array of numbers to stdout. Every three numbers in the array
 represent a range of color. For instance, if I fed the following string of
-JavaScript code to a scopifier,
+JavaScript code to a scopifier:
 
 ```js
 var a = function () {};
 ```
 
-then the scopifier would produce the following array:
+Then the scopifier would produce the following array:
 
 ```js
 [1,24,0,9,23,1]
@@ -175,7 +189,7 @@ required.
 
 [linter]: http://jshint.com/about/
 [flycheck]: http://www.flycheck.org/
-[point]: http://www.gnu.org/software/emacs/manual/html_node/elisp/Point.html
 [js2-mode]: https://github.com/mooz/js2-mode
 [node]: http://nodejs.org/download/
 [scopifier]: https://github.com/jacksonrayhamilton/scopifier
+[point]: http://www.gnu.org/software/emacs/manual/html_node/elisp/Point.html
diff --git a/packages/context-coloring/benchmark/context-coloring-benchmark.el 
b/packages/context-coloring/benchmark/context-coloring-benchmark.el
index 3da8d79..2de5646 100644
--- a/packages/context-coloring/benchmark/context-coloring-benchmark.el
+++ b/packages/context-coloring/benchmark/context-coloring-benchmark.el
@@ -28,8 +28,10 @@
 
 ;;; Code:
 
+(require 'context-coloring)
 (require 'js2-mode)
 
+
 (defconst context-coloring-benchmark-path
   (file-name-directory (or load-file-name buffer-file-name))
   "This file's directory.")
diff --git a/packages/context-coloring/context-coloring.el 
b/packages/context-coloring/context-coloring.el
index 849d392..02537c6 100644
--- a/packages/context-coloring/context-coloring.el
+++ b/packages/context-coloring/context-coloring.el
@@ -5,7 +5,7 @@
 ;; Author: Jackson Ray Hamilton <address@hidden>
 ;; URL: https://github.com/jacksonrayhamilton/context-coloring
 ;; Keywords: context coloring syntax highlighting
-;; Version: 6.0.0
+;; Version: 6.1.0
 ;; Package-Requires: ((emacs "24") (js2-mode "20150126"))
 
 ;; This file is part of GNU Emacs.
@@ -132,16 +132,55 @@ the END point (exclusive) with the face corresponding to 
LEVEL."
    end
    `(face ,(context-coloring-bounded-level-face level))))
 
-(defcustom context-coloring-comments-and-strings t
+(defcustom context-coloring-comments-and-strings nil
   "If non-nil, also color comments and strings using `font-lock'."
   :group 'context-coloring)
 
+(make-obsolete-variable
+ 'context-coloring-comments-and-strings
+ "use `context-coloring-syntactic-comments' and
+ `context-coloring-syntactic-strings' instead."
+ "6.1.0")
+
+(defcustom context-coloring-syntactic-comments t
+  "If non-nil, also color comments using `font-lock'."
+  :group 'context-coloring)
+
+(defcustom context-coloring-syntactic-strings t
+  "If non-nil, also color strings using `font-lock'."
+  :group 'context-coloring)
+
+(defun context-coloring-font-lock-syntactic-comment-function (state)
+  "Tell `font-lock' to color a comment but not a string."
+  (if (nth 3 state) nil font-lock-comment-face))
+
+(defun context-coloring-font-lock-syntactic-string-function (state)
+  "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 ()
   "Color the current buffer's comments and strings if
 `context-coloring-comments-and-strings' is non-nil."
-  (when context-coloring-comments-and-strings
-    (save-excursion
-      (font-lock-fontify-syntactically-region (point-min) (point-max)))))
+  (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)))
+      (save-excursion
+        (font-lock-fontify-syntactically-region (point-min) (point-max)))
+      (when saved-function-p
+        (setq font-lock-syntactic-face-function old-function)))))
 
 
 ;;; js2-mode colorization
@@ -678,7 +717,7 @@ precedence, i.e. the car of `custom-enabled-themes'."
            "#401440"
            "#0f2050"
            "#205070"
-           "#437c7c"
+           "#336c6c"
            "#23733c"
            "#6b400c"
            "#603a60"
@@ -785,7 +824,7 @@ precedence, i.e. the car of `custom-enabled-themes'."
            "#BFEBBF"
            "#F0DFAF"
            "#DFAF8F"
-           "#BC8383"
+           "#CC9393"
            "#DC8CC3"
            "#94BFF3"
            "#9FC59F"
@@ -835,6 +874,9 @@ Supported modes: `js-mode', `js3-mode'"
     (font-lock-mode 0)
     (jit-lock-mode nil)
 
+    ;; Safely change the valye of this function as necessary.
+    (make-local-variable 'font-lock-syntactic-face-function)
+
     (let ((dispatch (gethash major-mode context-coloring-mode-hash-table)))
       (when dispatch
         (let ((command (plist-get dispatch :command))
diff --git a/packages/context-coloring/scripts/dependencies 
b/packages/context-coloring/scripts/dependencies
new file mode 100644
index 0000000..c2a9107
--- /dev/null
+++ b/packages/context-coloring/scripts/dependencies
@@ -0,0 +1,2 @@
+https://raw.githubusercontent.com/mooz/js2-mode/master/js2-mode.el
+https://raw.githubusercontent.com/rejeep/ert-async.el/master/ert-async.el
diff --git a/packages/context-coloring/scripts/download-dependencies.el 
b/packages/context-coloring/scripts/download-dependencies.el
index 54211cc..2ab24e2 100644
--- a/packages/context-coloring/scripts/download-dependencies.el
+++ b/packages/context-coloring/scripts/download-dependencies.el
@@ -17,36 +17,45 @@
 ;; You should have received a copy of the GNU General Public License
 ;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-;; This script downloads some dependencies for development so they don't need 
to
-;; be version-controlled.
+;; Download dependencies for development.
+
+;; Dependencies don't need to be version-controlled. They are also
+;; bleeding-edge, which is good because that is what most MELPA users are 
using.
 
 ;;; Code:
 
-(defconst directory (file-name-directory (or load-file-name buffer-file-name))
+(defconst download-dependencies-directory
+  (file-name-directory (or load-file-name buffer-file-name))
   "This file's directory.")
 
-(defun resolve-path (path)
+(defun download-dependencies-resolve-path (path)
   "Resolve a path relative to this file's directory."
-  (expand-file-name path directory))
+  (expand-file-name path download-dependencies-directory))
 
-(defun strip-headers ()
+(defun download-dependencies-strip-headers ()
   "Remove the http headers included in the output of
 `url-retrieve-synchronously'."
   (goto-char 1)
-  (kill-paragraph 1) ; The headers are 1 paragraph. I hope.
-  (kill-line)        ; A line separates the headers from the file's content.
-  )
-
-;; Download any missing dependencies.
-(let ((files 
'("https://raw.githubusercontent.com/mooz/js2-mode/master/js2-mode.el";
-               
"https://raw.githubusercontent.com/rejeep/ert-async.el/master/ert-async.el";)))
-  (make-directory (resolve-path "../libraries") t)
-  (dolist (file files)
-    (let* ((basename (file-name-nondirectory file))
-           (destination (resolve-path (concat "../libraries/" basename))))
-      (when (null (file-exists-p destination))
-        (with-current-buffer (url-retrieve-synchronously file)
-          (strip-headers)
-          (write-file destination))))))
+  (kill-paragraph 1) ; The headers are 1 paragraph.  I hope.
+  (kill-line))       ; A line separates the headers from the file's content.
+
+(defun download-dependencies-get-dependencies ()
+  "Read the `dependencies' file as a list of URLs."
+  (with-temp-buffer
+    (insert-file-contents (download-dependencies-resolve-path 
"./dependencies"))
+    (split-string (buffer-substring-no-properties (point-min) (point-max)))))
+
+(defun download-dependencies ()
+  "Download dependencies for development."
+  (let ((files (download-dependencies-get-dependencies)))
+    (make-directory (download-dependencies-resolve-path "../libraries") t)
+    (dolist (file files)
+      (let* ((basename (file-name-nondirectory file))
+             (destination (download-dependencies-resolve-path
+                           (concat "../libraries/" basename))))
+        (unless (file-exists-p destination)
+          (with-current-buffer (url-retrieve-synchronously file)
+            (download-dependencies-strip-headers)
+            (write-file destination)))))))
 
 ;;; download-dependencies.el ends here
diff --git a/packages/context-coloring/test/context-coloring-test.el 
b/packages/context-coloring/test/context-coloring-test.el
index 88a7158..903da68 100644
--- a/packages/context-coloring/test/context-coloring-test.el
+++ b/packages/context-coloring/test/context-coloring-test.el
@@ -28,7 +28,9 @@
 
 ;;; Code:
 
+(require 'context-coloring)
 (require 'ert-async)
+(require 'js2-mode)
 
 
 ;;; Test running utilities
@@ -50,7 +52,8 @@
 (defun context-coloring-test-cleanup ()
   "Cleanup after all tests."
   (setq context-coloring-comments-and-strings t)
-  (setq context-coloring-after-colorize-hook nil)
+  (setq context-coloring-syntactic-comments nil)
+  (setq context-coloring-syntactic-strings nil)
   (setq context-coloring-js-block-scopes nil))
 
 (defmacro context-coloring-test-with-fixture (fixture &rest body)
@@ -68,16 +71,15 @@ buffer."
   "Create a temporary buffer, and evaluate CALLBACK there.  A
 teardown callback is passed to CALLBACK for it to invoke when it
 is done."
-  (let ((temp-buffer (make-symbol "temp-buffer")))
-    (let ((previous-buffer (current-buffer))
-          (temp-buffer (generate-new-buffer " *temp*")))
-      (set-buffer temp-buffer)
-      (funcall
-       callback
-       (lambda ()
-         (and (buffer-name temp-buffer)
-              (kill-buffer temp-buffer))
-         (set-buffer previous-buffer))))))
+  (let ((previous-buffer (current-buffer))
+        (temp-buffer (generate-new-buffer " *temp*")))
+    (set-buffer temp-buffer)
+    (funcall
+     callback
+     (lambda ()
+       (and (buffer-name temp-buffer)
+            (kill-buffer temp-buffer))
+       (set-buffer previous-buffer)))))
 
 (defun context-coloring-test-with-fixture-async
     (fixture callback &optional setup)
@@ -113,7 +115,7 @@ instantiated in SETUP."
         (funcall callback done-with-test))))
    setup))
 
-(defmacro context-coloring-test-js2-mode (fixture &rest body)
+(defmacro context-coloring-test-js2-mode (fixture setup &rest body)
   "Use FIXTURE as the subject matter for test logic in BODY."
   `(context-coloring-test-with-fixture
     ,fixture
@@ -121,16 +123,20 @@ instantiated in SETUP."
     (setq js2-mode-show-parse-errors nil)
     (setq js2-mode-show-strict-warnings nil)
     (js2-mode)
+    (when ,setup (funcall ,setup))
     (context-coloring-mode)
     ,@body))
 
-(defmacro context-coloring-test-deftest-js-mode (name)
+(cl-defmacro context-coloring-test-deftest-js-mode (name &key fixture-name)
   "Define an asynchronous test for `js-mode' with the name NAME
 in the typical format."
+  (declare (indent defun))
   (let ((test-name (intern (format "context-coloring-test-js-mode-%s" name)))
-        (fixture (format "./fixtures/%s.js" name))
+        (fixture (format "./fixtures/%s.js" (or fixture-name name)))
         (function-name (intern-soft
-                        (format "context-coloring-test-js-%s" name))))
+                        (format "context-coloring-test-js-%s" name)))
+        (setup-function-name (intern-soft
+                              (format "context-coloring-test-js-%s-setup" 
name))))
     `(ert-deftest-async ,test-name (done)
                         (context-coloring-test-js-mode
                          ,fixture
@@ -138,18 +144,23 @@ in the typical format."
                            (unwind-protect
                                (,function-name)
                              (funcall teardown))
-                           (funcall done))))))
+                           (funcall done))
+                         ',setup-function-name))))
 
-(defmacro context-coloring-test-deftest-js2-mode (name)
+(cl-defmacro context-coloring-test-deftest-js2-mode (name &key fixture-name)
   "Define a test for `js2-mode' with the name NAME in the typical
 format."
+  (declare (indent defun))
   (let ((test-name (intern (format "context-coloring-test-js2-mode-%s" name)))
-        (fixture (format "./fixtures/%s.js" name))
+        (fixture (format "./fixtures/%s.js" (or fixture-name name)))
         (function-name (intern-soft
-                        (format "context-coloring-test-js-%s" name))))
+                        (format "context-coloring-test-js-%s" name)))
+        (setup-function-name (intern-soft
+                              (format "context-coloring-test-js-%s-setup" 
name))))
     `(ert-deftest ,test-name ()
        (context-coloring-test-js2-mode
         ,fixture
+        ',setup-function-name
         (,function-name)))))
 
 
@@ -163,8 +174,7 @@ Provides the free variables `i', `length', `point', `face' 
and
          (length (- end start)))
      (while (< i length)
        (let* ((point (+ i start))
-              (face (get-text-property point 'face))
-              actual-level)
+              (face (get-text-property point 'face)))
          ,@body)
        (setq i (+ i 1)))))
 
@@ -172,23 +182,24 @@ Provides the free variables `i', `length', `point', 
`face' and
   "Assert that all points in the range [START, END) are of level
 LEVEL."
   (context-coloring-test-assert-region
-   (when (not (when 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 in region [%s, %s), "
-                               "which is \"%s\", to be %s; "
-                               "but at point %s, it was %s")
-                       start end
-                       (buffer-substring-no-properties start end) level
-                       point actual-level)))))
+   (let (actual-level)
+     (when (not (when 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 in region [%s, %s), "
+                                 "which is \"%s\", to be %s; "
+                                 "but at point %s, it was %s")
+                         start end
+                         (buffer-substring-no-properties start end) level
+                         point actual-level))))))
 
 (defun context-coloring-test-assert-region-face (start end expected-face)
   "Assert that all points in the range [START, END) have the face
@@ -690,32 +701,68 @@ see that function."
 (context-coloring-test-deftest-js-mode key-values)
 (context-coloring-test-deftest-js2-mode key-values)
 
-(defun context-coloring-test-js-comments-and-strings ()
-  "Test fixtures/comments-and-strings.js."
-  (context-coloring-test-assert-region-comment-delimiter 1 4)
-  (context-coloring-test-assert-region-comment 4 8)
+(defun context-coloring-test-js-syntactic-comments-and-strings ()
+  "Test comments and strings."
+  (context-coloring-test-assert-region-level 1 8 0)
   (context-coloring-test-assert-region-comment-delimiter 9 12)
-  (context-coloring-test-assert-region-comment 12 19)
-  (context-coloring-test-assert-region-string 20 32)
-  (context-coloring-test-assert-region-level 32 33 0))
-
-(ert-deftest-async context-coloring-test-js-mode-comments-and-strings (done)
-  (context-coloring-test-js-mode
-   "./fixtures/comments-and-strings.js"
-   (lambda (teardown)
-     (unwind-protect
-         (context-coloring-test-js-comments-and-strings)
-       (funcall teardown))
-     (funcall done))
-   (lambda ()
-     (setq context-coloring-comments-and-strings t))))
-
-(ert-deftest context-coloring-test-js2-mode-comments-and-strings ()
-  (context-coloring-test-js2-mode
-   "./fixtures/comments-and-strings.js"
-   (setq context-coloring-comments-and-strings t)
-   (context-coloring-colorize)
-   (context-coloring-test-js-comments-and-strings)))
+  (context-coloring-test-assert-region-comment 12 16)
+  (context-coloring-test-assert-region-comment-delimiter 17 20)
+  (context-coloring-test-assert-region-comment 20 27)
+  (context-coloring-test-assert-region-string 28 40)
+  (context-coloring-test-assert-region-level 40 41 0))
+
+(defun context-coloring-test-js-syntactic-comments-and-strings-setup ()
+  (setq context-coloring-syntactic-comments t)
+  (setq context-coloring-syntactic-strings t))
+
+(context-coloring-test-deftest-js-mode syntactic-comments-and-strings
+  :fixture-name comments-and-strings)
+(context-coloring-test-deftest-js2-mode syntactic-comments-and-strings
+  :fixture-name comments-and-strings)
+
+(defalias 'context-coloring-test-js-comments-and-strings
+  'context-coloring-test-js-syntactic-comments-and-strings
+  "Test comments and strings.  Deprecated.")
+
+(defun context-coloring-test-js-comments-and-strings-setup ()
+  "Setup comments and strings.  Deprecated."
+  (setq context-coloring-comments-and-strings t))
+
+(context-coloring-test-deftest-js-mode comments-and-strings)
+(context-coloring-test-deftest-js2-mode comments-and-strings)
+
+(defun context-coloring-test-js-syntactic-comments ()
+  "Test syntactic comments."
+  (context-coloring-test-assert-region-level 1 8 0)
+  (context-coloring-test-assert-region-comment-delimiter 9 12)
+  (context-coloring-test-assert-region-comment 12 16)
+  (context-coloring-test-assert-region-comment-delimiter 17 20)
+  (context-coloring-test-assert-region-comment 20 27)
+  (context-coloring-test-assert-region-level 28 41 0))
+
+(defun context-coloring-test-js-syntactic-comments-setup ()
+  "Setup syntactic comments."
+  (setq context-coloring-syntactic-comments t))
+
+(context-coloring-test-deftest-js-mode syntactic-comments
+  :fixture-name comments-and-strings)
+(context-coloring-test-deftest-js2-mode syntactic-comments
+  :fixture-name comments-and-strings)
+
+(defun context-coloring-test-js-syntactic-strings ()
+  "Test syntactic strings."
+  (context-coloring-test-assert-region-level 1 28 0)
+  (context-coloring-test-assert-region-string 28 40)
+  (context-coloring-test-assert-region-level 40 41 0))
+
+(defun context-coloring-test-js-syntactic-strings-setup ()
+  "Setup syntactic strings."
+  (setq context-coloring-syntactic-strings t))
+
+(context-coloring-test-deftest-js-mode syntactic-strings
+  :fixture-name comments-and-strings)
+(context-coloring-test-deftest-js2-mode syntactic-strings
+  :fixture-name comments-and-strings)
 
 (provide 'context-coloring-test)
 
diff --git a/packages/context-coloring/test/fixtures/comments-and-strings.js 
b/packages/context-coloring/test/fixtures/comments-and-strings.js
index 9910b02..4297011 100644
--- a/packages/context-coloring/test/fixtures/comments-and-strings.js
+++ b/packages/context-coloring/test/fixtures/comments-and-strings.js
@@ -1,3 +1,4 @@
+void 0;
 // Foo.
 /* Bar. */
 'use strict';



reply via email to

[Prev in Thread] Current Thread [Next in Thread]