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

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

[elpa] master 5402f35 21/21: Merge commit '1b30a28857727202d1f6a027f83ad


From: Jackson Ray Hamilton
Subject: [elpa] master 5402f35 21/21: Merge commit '1b30a28857727202d1f6a027f83ad66151fb1e92' from context-coloring
Date: Fri, 23 Dec 2016 20:27:52 +0000 (UTC)

branch: master
commit 5402f3573c0b5b4535e65fa5008c47754a43defc
Merge: 580a1b6 1b30a28
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>

    Merge commit '1b30a28857727202d1f6a027f83ad66151fb1e92' from 
context-coloring
---
 packages/context-coloring/.travis.yml              |    1 +
 packages/context-coloring/Makefile                 |    4 +-
 packages/context-coloring/README.md                |    4 +-
 .../context-coloring/context-coloring-benchmark.el |    2 +-
 .../context-coloring/context-coloring-coverage.el  |    2 +-
 .../context-coloring-javascript.el                 |   23 ++++---
 packages/context-coloring/context-coloring-test.el |   55 ++++++++++++++---
 packages/context-coloring/context-coloring.el      |   65 +++++++++++++++++---
 .../context-coloring/fixtures/test/block-scopes.js |    9 ---
 .../fixtures/test/narrow-to-region.js              |    3 +
 .../fixtures/test/prettify-symbols.el              |    1 +
 11 files changed, 127 insertions(+), 42 deletions(-)

diff --git a/packages/context-coloring/.travis.yml 
b/packages/context-coloring/.travis.yml
index ba959a9..70d1f6d 100644
--- a/packages/context-coloring/.travis.yml
+++ b/packages/context-coloring/.travis.yml
@@ -6,6 +6,7 @@ env:
   - EVM_EMACS=emacs-24.3-travis
   - EVM_EMACS=emacs-24.4-travis
   - EVM_EMACS=emacs-24.5-travis
+  - EVM_EMACS=emacs-25.1-travis
 
 before_install:
   - export PATH="/home/travis/.evm/bin:$PATH"
diff --git a/packages/context-coloring/Makefile 
b/packages/context-coloring/Makefile
index 4519b70..9763be1 100644
--- a/packages/context-coloring/Makefile
+++ b/packages/context-coloring/Makefile
@@ -1,5 +1,5 @@
-EMACS = emacs
-CASK = EMACS=${EMACS} cask
+EMACS ?= emacs
+CASK ?= EMACS=${EMACS} cask
 DEPENDENCIES = .cask/
 SOURCE_FILES = \
        context-coloring.el \
diff --git a/packages/context-coloring/README.md 
b/packages/context-coloring/README.md
index 21f1eb5..bfbb4fb 100644
--- a/packages/context-coloring/README.md
+++ b/packages/context-coloring/README.md
@@ -25,7 +25,9 @@ By default, comments and strings are still highlighted 
syntactically.
 ## Installation
 
 Requires Emacs 24.3+.  JavaScript language support requires
-[js2-mode](https://github.com/mooz/js2-mode).
+[js2-mode](https://github.com/mooz/js2-mode) (or, if you use
+[Tern](http://ternjs.net/), you may be interested in
+[tern-context-coloring](https://github.com/jacksonrayhamilton/tern-context-coloring)).
 
 To install, run the command `M-x package-install RET context-coloring RET`, and
 then add the following to your init file:
diff --git a/packages/context-coloring/context-coloring-benchmark.el 
b/packages/context-coloring/context-coloring-benchmark.el
index 0c38e85..dafc959 100644
--- a/packages/context-coloring/context-coloring-benchmark.el
+++ b/packages/context-coloring/context-coloring-benchmark.el
@@ -1,4 +1,4 @@
-;;; context-coloring-benchmark.el --- Benchmarks for context coloring  -*- 
lexical-binding: t; no-byte-compile: t; -*-
+;;; context-coloring-benchmark.el --- Benchmarks for context coloring  -*- 
lexical-binding: t; -*-
 
 ;; Copyright (C) 2014-2016  Free Software Foundation, Inc.
 
diff --git a/packages/context-coloring/context-coloring-coverage.el 
b/packages/context-coloring/context-coloring-coverage.el
index c63dc6b..fe990d9 100644
--- a/packages/context-coloring/context-coloring-coverage.el
+++ b/packages/context-coloring/context-coloring-coverage.el
@@ -1,4 +1,4 @@
-;;; context-coloring-coverage.el --- Test coverage for context coloring  -*- 
lexical-binding: t; no-byte-compile: t; -*-
+;;; context-coloring-coverage.el --- Test coverage for context coloring  -*- 
lexical-binding: t; -*-
 
 ;; Copyright (C) 2014-2016  Free Software Foundation, Inc.
 
diff --git a/packages/context-coloring/context-coloring-javascript.el 
b/packages/context-coloring/context-coloring-javascript.el
index d145184..29bafb8 100644
--- a/packages/context-coloring/context-coloring-javascript.el
+++ b/packages/context-coloring/context-coloring-javascript.el
@@ -73,26 +73,33 @@ this for ES6 code; disable it elsewhere."
                        ;; `js2-prop-get-node', so this always works.
                        (eq node (js2-prop-get-node-right parent))))))))
 
+(defvar-local context-coloring-point-min nil
+  "Cached value of `point-min'.")
+
 (defvar-local context-coloring-point-max nil
   "Cached value of `point-max'.")
 
+(defsubst context-coloring-js2-bounded-point (point)
+  "Make POINT safe to set text properties.
+POINT may be unsafe if a JS2 node extends beyond the end of the
+buffer (in the case of an unterminated multiline comment).  The
+region could also be narrowed and the node thus obscured."
+  (min (max point context-coloring-point-min) context-coloring-point-max))
+
 (defsubst context-coloring-js2-colorize-node (node level)
   "Color NODE with the color for LEVEL."
-  (let ((start (js2-node-abs-pos node)))
+  (let* ((start (js2-node-abs-pos node))
+         (end (+ start (js2-node-len node))))
     (context-coloring-colorize-region
-     start
-     (min
-      ;; End
-      (+ start (js2-node-len node))
-      ;; Somes nodes (like the ast when there is an unterminated multiline
-      ;; comment) will stretch to the value of `point-max'.
-      context-coloring-point-max)
+     (context-coloring-js2-bounded-point start)
+     (context-coloring-js2-bounded-point end)
      level)))
 
 (defun context-coloring-js2-colorize-ast ()
   "Color the buffer using the `js2-mode' abstract syntax tree."
   ;; Reset the hash table; the old one could be obsolete.
   (setq context-coloring-js2-scope-level-hash-table (make-hash-table :test 
#'eq))
+  (setq context-coloring-point-min (point-min))
   (setq context-coloring-point-max (point-max))
   (with-silent-modifications
     (js2-visit-ast
diff --git a/packages/context-coloring/context-coloring-test.el 
b/packages/context-coloring/context-coloring-test.el
index 1655496..fabf55b 100644
--- a/packages/context-coloring/context-coloring-test.el
+++ b/packages/context-coloring/context-coloring-test.el
@@ -1,4 +1,4 @@
-;;; context-coloring-test.el --- Tests for context coloring  -*- 
lexical-binding: t; no-byte-compile: t; -*-
+;;; context-coloring-test.el --- Tests for context coloring  -*- 
lexical-binding: t; -*-
 
 ;; Copyright (C) 2014-2016  Free Software Foundation, Inc.
 
@@ -344,6 +344,41 @@ signaled."
             '(context-coloring-level-0-face nil))
            (disable-theme 'context-coloring-test-custom-theme)))
 
+(when (fboundp 'prettify-symbols-mode)
+
+  (defun context-coloring-test-assert-prettify-symbols-coloring ()
+    (context-coloring-test-assert-coloring "
+(111111 () (222222 ()))"))
+
+  (defun context-coloring-test-assert-prettify-symbols-text-properties ()
+    (unless (cond
+             ((version< emacs-version "25.0")
+              (get-text-property 2 'composition))
+             (t
+              (and (get-text-property 2 'prettify-symbols-start)
+                   (get-text-property 2 'prettify-symbols-end))))
+      (ert-fail "Expected buffer to have it's symbols prettified, but it 
didn't.")))
+
+  (context-coloring-test-deftest prettify-symbols-enabled-before
+                                 (lambda ()
+                                   (context-coloring-test-with-fixture
+                                    "./fixtures/test/prettify-symbols.el"
+                                    (emacs-lisp-mode)
+                                    (prettify-symbols-mode)
+                                    (context-coloring-mode)
+                                    
(context-coloring-test-assert-prettify-symbols-text-properties)
+                                    
(context-coloring-test-assert-prettify-symbols-coloring))))
+
+  (context-coloring-test-deftest prettify-symbols-enabled-after
+                                 (lambda ()
+                                   (context-coloring-test-with-fixture
+                                    "./fixtures/test/prettify-symbols.el"
+                                    (emacs-lisp-mode)
+                                    (context-coloring-mode)
+                                    (prettify-symbols-mode)
+                                    
(context-coloring-test-assert-prettify-symbols-text-properties)
+                                    
(context-coloring-test-assert-prettify-symbols-coloring)))))
+
 
 ;;; Coloring tests
 
@@ -485,15 +520,6 @@ other non-letters are guaranteed to always be discarded."
     11 111 2
         222 12
         222 22
-        22222 12
-    2
-}());
-
-(xxxxxxxx () {
-    'xxx xxxxxx';
-    11 111 2
-        222 12
-        222 22
         22222 22
     2
 }());"))
@@ -637,6 +663,15 @@ ssssssssssss0"))
         (context-coloring-test-assert-javascript-global-level))))
   :fixture "initial-level.js")
 
+(context-coloring-test-deftest-javascript narrow-to-region
+  (lambda ()
+    (context-coloring-test-assert-coloring "
+1111111 0 11 11
+11111111 0 11 11
+11111111 0 11 1"))
+  :before (lambda ()
+            (narrow-to-region (+ (point-min) 1) (- (point-max) 2))))
+
 (context-coloring-test-deftest-emacs-lisp defun
   (lambda ()
     (context-coloring-test-assert-coloring "
diff --git a/packages/context-coloring/context-coloring.el 
b/packages/context-coloring/context-coloring.el
index 06830fd..ac24364 100644
--- a/packages/context-coloring/context-coloring.el
+++ b/packages/context-coloring/context-coloring.el
@@ -3,7 +3,7 @@
 ;; Copyright (C) 2014-2016  Free Software Foundation, Inc.
 
 ;; Author: Jackson Ray Hamilton <address@hidden>
-;; Version: 8.0.1
+;; Version: 8.1.0
 ;; Keywords: convenience faces tools
 ;; Package-Requires: ((emacs "24.3"))
 ;; URL: https://github.com/jacksonrayhamilton/context-coloring
@@ -41,6 +41,14 @@
   "Join a list of STRINGS with the string DELIMITER."
   (mapconcat #'identity strings delimiter))
 
+(defun context-coloring-check-predicates (predicates)
+  "Call PREDICATES until one returns t, otherwise return nil."
+  (let ((satisfied-p nil))
+    (while (and predicates
+                (not satisfied-p))
+      (setq satisfied-p (funcall (pop predicates))))
+    satisfied-p))
+
 
 ;;; Faces
 
@@ -311,7 +319,11 @@ override `context-coloring-default-delay'.
 `context-coloring-mode' is enabled.
 
 `:teardown' - Arbitrary code to tear down this dispatch when
-`context-coloring-mode' is disabled.")
+`context-coloring-mode' is disabled.
+
+`:async-p' - Hint that code will be colorized asynchronously.
+Please call `context-coloring-after-colorize' when colorization
+completes.")
 
 (defun context-coloring-find-dispatch (predicate)
   "Find the first dispatch satisfying PREDICATE."
@@ -345,18 +357,46 @@ override `context-coloring-default-delay'.
   "Set up environment for colorization."
   (context-coloring-update-maximum-face))
 
+(defvar context-coloring-after-colorize-hook nil
+  "Functions to run after colorizing.")
+
+(defun context-coloring-after-colorize ()
+  "Do final business after colorization."
+  (run-hooks 'context-coloring-after-colorize-hook))
+
 (defun context-coloring-dispatch ()
   "Determine how to color the current buffer, and color it."
   (let* ((dispatch (context-coloring-get-current-dispatch))
-         (colorizer (plist-get dispatch :colorizer)))
+         (colorizer (plist-get dispatch :colorizer))
+         (async-p (plist-get dispatch :async-p)))
     (context-coloring-before-colorize)
     (when colorizer
       (catch 'interrupted
-        (funcall colorizer)))))
+        (funcall colorizer)))
+    (unless async-p
+      (context-coloring-after-colorize))))
 
 
 ;;; Colorization
 
+(defvar context-coloring-fontify-keywords-predicates
+  (list
+   (lambda () (and (boundp 'prettify-symbols-mode) prettify-symbols-mode)))
+  "Cases where the whole buffer should have keywords fontified.
+Necessary in cases where a mode relies on fontifications in
+regions where Context Coloring doesn't happen to touch.")
+
+(defun context-coloring-maybe-fontify-keywords ()
+  "Determine if the buffer ought to have keywords fontified."
+  (when (context-coloring-check-predicates
+         context-coloring-fontify-keywords-predicates)
+    (with-silent-modifications
+      (save-excursion
+        (font-lock-fontify-keywords-region (point-min) (point-max))))))
+
+(add-hook 'context-coloring-after-colorize-hook
+          #'context-coloring-maybe-fontify-keywords)
+
 (defun context-coloring-colorize ()
   "Color the current buffer by function context."
   (interactive)
@@ -381,12 +421,8 @@ permissible.")
 
 (defun context-coloring-ignore-unavailable-message-p ()
   "Determine if the unavailable message should be silenced."
-  (let ((predicates context-coloring-ignore-unavailable-predicates)
-        (ignore-p nil))
-    (while (and predicates
-                (not ignore-p))
-      (setq ignore-p (funcall (pop predicates))))
-    ignore-p))
+  (context-coloring-check-predicates
+   context-coloring-ignore-unavailable-predicates))
 
 (defvar context-coloring-interruptable-p t
   "When non-nil, coloring may be interrupted by user input.")
@@ -428,6 +464,14 @@ Feature inspired by Douglas Crockford."
         (font-lock-set-defaults)
         ;; Safely change the value of this function as necessary.
         (make-local-variable 'font-lock-syntactic-face-function)
+        ;; Improve integration with `prettify-symbols-mode'.  It relies on Font
+        ;; Lock's automatic fontification to apply it's changes on mode change,
+        ;; so Context Coloring has to make those changes manually.
+        (add-hook 'prettify-symbols-mode-hook 
#'context-coloring-maybe-fontify-keywords nil t)
+        ;; Furthermore, on Emacs < 25.0, `prettify-symbols-mode' calls
+        ;; `font-lock-fontify-buffer-function' which would overwrite context
+        ;; coloring, so make it a no-op.
+        (set (make-local-variable 'font-lock-fontify-buffer-function) (lambda 
()))
         (let ((setup (plist-get dispatch :setup)))
           (when setup
             (funcall setup))
@@ -442,6 +486,7 @@ Feature inspired by Douglas Crockford."
         (let ((teardown (plist-get dispatch :teardown)))
           (when teardown
             (funcall teardown)))))
+    (remove-hook 'prettify-symbols-mode-hook 
#'context-coloring-maybe-fontify-keywords t)
     (turn-on-font-lock-if-desired))))
 
 (provide 'context-coloring)
diff --git a/packages/context-coloring/fixtures/test/block-scopes.js 
b/packages/context-coloring/fixtures/test/block-scopes.js
index 86e4a13..34a40ba 100644
--- a/packages/context-coloring/fixtures/test/block-scopes.js
+++ b/packages/context-coloring/fixtures/test/block-scopes.js
@@ -5,12 +5,3 @@
         const c;
     }
 }());
-
-(function () {
-    'use strict';
-    if (1) {
-        var a;
-        let b;
-        const c;
-    }
-}());
diff --git a/packages/context-coloring/fixtures/test/narrow-to-region.js 
b/packages/context-coloring/fixtures/test/narrow-to-region.js
new file mode 100644
index 0000000..29f9aef
--- /dev/null
+++ b/packages/context-coloring/fixtures/test/narrow-to-region.js
@@ -0,0 +1,3 @@
+function a () {}
+function b () {}
+function c () {}
diff --git a/packages/context-coloring/fixtures/test/prettify-symbols.el 
b/packages/context-coloring/fixtures/test/prettify-symbols.el
new file mode 100644
index 0000000..0863230
--- /dev/null
+++ b/packages/context-coloring/fixtures/test/prettify-symbols.el
@@ -0,0 +1 @@
+(lambda () (lambda ()))



reply via email to

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