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

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

[elpa] master 615ce2c 004/271: Wow, actually works.


From: Jackson Ray Hamilton
Subject: [elpa] master 615ce2c 004/271: Wow, actually works.
Date: Thu, 05 Feb 2015 18:29:21 +0000

branch: master
commit 615ce2c80ac50c14780da4f7ad00a9e21e7ce6fe
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>

    Wow, actually works.
---
 context-coloring.el |  115 +++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 97 insertions(+), 18 deletions(-)

diff --git a/context-coloring.el b/context-coloring.el
index 16e5157..29eb00e 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -48,21 +48,100 @@
 ;; goto-line, move-to-column: Finding ranges to apply colors to.
 ;; with-silent-modifications: The colorization itself.
 
-;; Probably useful, here's the rainbow-blocks colorizer.
-(defsubst rainbow-blocks-propertize-delimiter (loc depth)
-  "Highlight a single delimiter at LOC according to DEPTH.
-LOC is the location of the character to add text properties to.
-DEPTH is the nested depth at LOC, which determines the face to use.
-Sets text properties:
-`font-lock-face' to the appropriate delimiter face.
-`rear-nonsticky' to prevent color from bleeding into subsequent characters 
typed by the user."
-  (with-silent-modifications
-    (let* ((delim-face (if (<= depth 0)
-                           'rainbow-blocks-unmatched-face
-                         (rainbow-blocks-depth-face depth)))
-           (end-pos    (save-excursion (goto-char loc)
-                                       (forward-sexp)
-                                       (point))))
-      (add-text-properties loc end-pos
-                           `(font-lock-face ,delim-face
-                                            rear-nonsticky t)))))
+(require 'json)
+
+;; Faces for highlighting blocks by nested level:
+
+(defface context-coloring-depth-0-face
+  '((((background light)) (:foreground "#ffffff"))
+    (((background dark)) (:foreground "#ffffff")))
+  "Nested blocks face, depth 0 - outermost set."
+  :tag "Rainbow Blocks Depth 0 Face -- OUTERMOST"
+  :group 'context-coloring-faces)
+
+(defface context-coloring-depth-1-face
+  '((((background light)) (:foreground "#ffff80"))
+    (((background dark)) (:foreground "#ffff80")))
+  "Nested blocks face, depth 1."
+  :group 'context-coloring-faces)
+
+(defface context-coloring-depth-2-face
+  '((((background light)) (:foreground "#cdfacd"))
+    (((background dark)) (:foreground "#cdfacd")))
+  "Nested blocks face, depth 2."
+  :group 'context-coloring-faces)
+
+(defface context-coloring-depth-3-face
+  '((((background light)) (:foreground "#d8d8ff"))
+    (((background dark)) (:foreground "#d8d8ff")))
+  "Nested blocks face, depth 3."
+  :group 'context-coloring-faces)
+
+(defface context-coloring-depth-4-face
+  '((((background light)) (:foreground "#e7c7ff"))
+    (((background dark)) (:foreground "#e7c7ff")))
+  "Nested blocks face, depth 4."
+  :group 'context-coloring-faces)
+
+(defface context-coloring-depth-5-face
+  '((((background light)) (:foreground "#ffcdcd"))
+    (((background dark)) (:foreground "#ffcdcd")))
+  "Nested blocks face, depth 5."
+  :group 'context-coloring-faces)
+
+(defface context-coloring-depth-6-face
+  '((((background light)) (:foreground "#ffe390"))
+    (((background dark)) (:foreground "#ffe390")))
+  "Nested blocks face, depth 6."
+  :group 'context-coloring-faces)
+
+(defface context-coloring-depth-7-face
+  '((((background light)) (:foreground "#cdcdcd"))
+    (((background dark)) (:foreground "#cdcdcd")))
+  "Nested blocks face, depth 7."
+  :group 'context-coloring-faces)
+
+(defconst context-coloring-face-count 8
+  "Number of faces defined for highlighting delimiter levels.
+Determines depth at which to cycle through faces again.")
+
+;;; Face utility functions
+
+(defun context-coloring-depth-face (depth)
+  "Return face-name for DEPTH as a string 'context-coloring-depth-DEPTH-face'.
+For example: 'context-coloring-depth-1-face'."
+  (intern-soft
+   (concat "context-coloring-depth-"
+           (number-to-string (mod depth context-coloring-face-count))
+           "-face")))
+
+(defconst context-coloring-path
+  (file-name-directory (or load-file-name buffer-file-name)))
+
+(defun context-coloring-get-point (line column)
+  (save-excursion
+    (goto-line line)
+    (move-to-column column)
+    (point)))
+
+(defun context-coloring ()
+  (interactive)
+  (let* ((json (shell-command-to-string
+                 (format "echo '%s' | %s"
+                         (buffer-substring-no-properties
+                          (point-min)
+                          (point-max))
+                         (expand-file-name "./tokenizer/tokenizer" 
context-coloring-path))))
+         (tokens (let ((json-array-type 'list))
+                   (json-read-from-string json))))
+    (with-silent-modifications
+      (dolist (token tokens)
+        (let* ((line (cdr (assoc 'line token)))
+               (from (cdr (assoc 'from token)))
+               (thru (cdr (assoc 'thru token)))
+               (level (cdr (assoc 'level token)))
+               (start (context-coloring-get-point line (- from 1)))
+               (end (context-coloring-get-point line (- thru 1)))
+               (face (context-coloring-depth-face level)))
+          (message "from %s to %s, use face %s" start end face)
+          (add-text-properties start end `(font-lock-face ,face rear-nonsticky 
t)))))))



reply via email to

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