[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)))))))
- [elpa] master updated (c8087b9 -> dc9644e), Jackson Ray Hamilton, 2015/02/05
- [elpa] master e3fc05a 011/271: Create bin and scripts directories., Jackson Ray Hamilton, 2015/02/05
- [elpa] master aaf199e 006/271: Fix global wraparound., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 809d48b 020/271: Minor tweaks., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 98df7db 010/271: Optimize cli a little bit., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 5fd312b 002/271: More planning and research., Jackson Ray Hamilton, 2015/02/05
- [elpa] master ebc0b99 013/271: Add rollover font lock optimization., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 615ce2c 004/271: Wow, actually works.,
Jackson Ray Hamilton <=
- [elpa] master 6d79b91 024/271: Idly colorizing after changes working. Cancelling seemingly not working., Jackson Ray Hamilton, 2015/02/05
- [elpa] master fd4b629 007/271: Add mode., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 6e991c4 014/271: Fix off-by-one error., Jackson Ray Hamilton, 2015/02/05
- [elpa] master b35380b 019/271: Vastly improve idle timer strategy., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 7ac8db6 012/271: Fix a bug where strings were matched., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 806398e 016/271: Use asynchronous command execution strategy., Jackson Ray Hamilton, 2015/02/05
- [elpa] master d0f5470 022/271: Successfully lexically bind buffer., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 397ef04 005/271: Detect globals., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 409a05b 017/271: Enable font lock again., Jackson Ray Hamilton, 2015/02/05
- [elpa] master a72314c 008/271: Write temp files., Jackson Ray Hamilton, 2015/02/05