[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master fd4b629 007/271: Add mode.
From: |
Jackson Ray Hamilton |
Subject: |
[elpa] master fd4b629 007/271: Add mode. |
Date: |
Thu, 05 Feb 2015 18:29:22 +0000 |
branch: master
commit fd4b62933fc8d20b602f1499770311ab2d018ca1
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>
Add mode.
---
context-coloring.el | 102 ++++++++++++++++++-----------------------------
test/fixtures/depth.js | 88 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 127 insertions(+), 63 deletions(-)
diff --git a/context-coloring.el b/context-coloring.el
index 6fc2545..7674faa 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -1,56 +1,6 @@
-;; Musings:
-
-;; Each time a function statement/expression is encountered, a new scope is
-;; created. New scopes use the next unique color. Multiple scopes within the
-;; same scope have the same color.
-
-;; function statement syntax:
-;;
-;; function name([param1[, param2[, ..., paramN]]]) { [statements] }
-
-;; A function statement's name is added to the previous scope and is colored in
-;; the previous scope's color. The rest of the function is part of the new
-;; scope.
-
-;; function expression syntax:
-;;
-;; function [name]([param1[, param2[, ..., paramN]]]) { [statements] }
-
-;; A function expression's name, if it has one, is part of the new scope
created
-;; by the expression.
-
-
-;; JSLINT strategy:
-
-;; Colors for levels:
-
-;; white
-;; #ffff80
-;; #cdfacd
-;; #d8d8ff
-;; #e7c7ff
-;; #ffcdcd
-;; #ffe390
-;; #cdcdcd
-
-;; - Obtain the buffer's contents, pipe them to a JSLint server.
-;; - Run code through JSLINT.
-;; - Pipe `JSLINT.data().tokens` back to emacs.
-;; - Iterate through the tokens.
-;; - On line `line`, from `from` through `thru` inclusive, color the area
-;; according to `function.level`
-;; - ...
-;; - Profit.
-
-;; elisp functions that may come in handy:
-
-;; save-excursion: Wrap the whole body in this.
-;; goto-line, move-to-column: Finding ranges to apply colors to.
-;; with-silent-modifications: The colorization itself.
-
(require 'json)
-;; Faces for highlighting blocks by nested level:
+;;; Faces
(defface context-coloring-depth-0-face
'((((background light)) (:foreground "#ffffff"))
@@ -107,7 +57,7 @@ Determines depth at which to cycle through faces again.")
;;; Face utility functions
-(defun context-coloring-depth-face (depth)
+(defsubst 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
@@ -124,23 +74,25 @@ For example: 'context-coloring-depth-1-face'."
(- context-coloring-face-count 1)))))
"-face")))
-(defconst context-coloring-path
- (file-name-directory (or load-file-name buffer-file-name)))
-
-(defun context-coloring-get-point (line column)
+(defsubst context-coloring-get-point (line column)
(save-excursion
(goto-line line)
(move-to-column column)
(point)))
-(defun context-coloring ()
+;;; The coloring.
+
+(defconst context-coloring-path
+ (file-name-directory (or load-file-name buffer-file-name)))
+
+(defun context-coloring-propertize-region (start end)
(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))))
+ (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
@@ -152,5 +104,29 @@ For example: 'context-coloring-depth-1-face'."
(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)))))))
+
+;;; Minor mode:
+
+;;;###autoload
+(define-minor-mode context-coloring-mode
+ "Context-based code coloring for JavaScript, inspired by Douglas Crockford."
+ nil " Context" nil
+ (if (not context-coloring-mode)
+ (progn
+ (jit-lock-unregister 'context-coloring-propertize-region))
+ (jit-lock-register 'context-coloring-propertize-region)))
+
+;;;###autoload
+(defun context-coloring-mode-enable ()
+ (context-coloring-mode 1))
+
+;;;###autoload
+(defun context-coloring-mode-disable ()
+ (context-coloring-mode 0))
+
+;;;###autoload
+(define-globalized-minor-mode global-context-coloring-mode
+ context-coloring-mode context-coloring-mode-enable)
+
+(provide 'context-coloring)
diff --git a/test/fixtures/depth.js b/test/fixtures/depth.js
index 107d8ca..1d75fd1 100644
--- a/test/fixtures/depth.js
+++ b/test/fixtures/depth.js
@@ -9,6 +9,50 @@ function a() {
function i() {
function j() {
function k() {
+function a() {
+ function b() {
+ function c() {
+ function d() {
+ function e() {
+ function f() {
+ function g() {
+ function h() {
+ function i() {
+ function j() {
+ function k() {
+function a() {
+ function b() {
+ function c() {
+ function d() {
+ function e() {
+ function f() {
+ function g() {
+ function h() {
+ function i() {
+ function j() {
+ function k() {
+function a() {
+ function b() {
+ function c() {
+ function d() {
+ function e() {
+ function f() {
+ function g() {
+ function h() {
+ function i() {
+ function j() {
+ function k() {
+function a() {
+ function b() {
+ function c() {
+ function d() {
+ function e() {
+ function f() {
+ function g() {
+ function h() {
+ function i() {
+ function j() {
+ function k() {
}
}
@@ -21,3 +65,47 @@ function a() {
}
}
}
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
- [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, 2015/02/05
- [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 <=
- [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
- [elpa] master 6a2a7df 018/271: Use idle timers instead of font lock., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 0a4248b 009/271: Update chunk size., Jackson Ray Hamilton, 2015/02/05