[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 98df7db 010/271: Optimize cli a little bit.
From: |
Jackson Ray Hamilton |
Subject: |
[elpa] master 98df7db 010/271: Optimize cli a little bit. |
Date: |
Thu, 05 Feb 2015 18:29:24 +0000 |
branch: master
commit 98df7dbd758c76161955988acd006629357415a9
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>
Optimize cli a little bit.
---
context-coloring.el | 18 +++-------------
tokenizer/cli.js | 54 ++++++++++++++++++++++++++++++++++++++------------
2 files changed, 45 insertions(+), 27 deletions(-)
diff --git a/context-coloring.el b/context-coloring.el
index 47952bb..bef584d 100644
--- a/context-coloring.el
+++ b/context-coloring.el
@@ -57,7 +57,7 @@ Determines depth at which to cycle through faces again.")
;;; Face utility functions
-(defsubst context-coloring-depth-face (depth)
+(defsubst context-coloring-level-face (depth)
"Return face-name for DEPTH as a string 'context-coloring-depth-DEPTH-face'.
For example: 'context-coloring-depth-1-face'."
(intern-soft
@@ -74,12 +74,6 @@ For example: 'context-coloring-depth-1-face'."
(- context-coloring-face-count 1)))))
"-face")))
-(defsubst context-coloring-get-point (line column)
- (save-excursion
- (goto-line line)
- (move-to-column column)
- (point)))
-
(defun context-coloring-save-buffer-to-temp ()
"Save buffer to temp file.
Return the name of the temporary file."
@@ -105,13 +99,9 @@ Return the name of the temporary file."
(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)))
+ (let ((start (cdr (assoc 's token)))
+ (end (cdr (assoc 'e token)))
+ (face (context-coloring-level-face (cdr (assoc 'l token)))))
(add-text-properties start end `(font-lock-face ,face rear-nonsticky
t)))))
(delete-file temp-file)))
diff --git a/tokenizer/cli.js b/tokenizer/cli.js
index 9ac8262..0e799d1 100644
--- a/tokenizer/cli.js
+++ b/tokenizer/cli.js
@@ -4,7 +4,25 @@ var JSLINT = require('./jslint'),
util = require('util'),
// Accumulated input.
- whole = '';
+ whole = '',
+
+ // Acquires the number of accumulated characters after the end of each
line.
+ getTotals = function (file) {
+ var lines = file.split('\n'),
+ total = 0,
+ totals = {
+ 0: total
+ },
+ i = 0,
+ length = lines.length;
+ while (i < length) {
+ total += lines[i].length + 1;
+ totals[i + 1] = total;
+ i += 1;
+ }
+ totals[i + 1] = total + 1;
+ return totals;
+ };
process.stdin.setEncoding('utf8');
@@ -16,16 +34,24 @@ process.stdin.on('readable', function () {
});
process.stdin.on('end', function () {
- var data, tokens;
+ var data, totals, out, i, tokens, length, token, origin, level, total;
// Generate a syntax tree for the input.
JSLINT(whole);
data = JSLINT.data();
+ totals = getTotals(whole);
+
// Minimize an otherwise-circular structure.
- tokens = data.tokens.map(function (token) {
- var origin = token,
- level;
+ out = [];
+ i = 0;
+ tokens = data.tokens;
+ length = tokens.length;
+
+ while (i < length) {
+ token = tokens[i];
+
+ origin = token;
// We always consider the function keyword to be "part" of the scope it
// creates, even if the name leaks in the case of function statements.
@@ -43,14 +69,16 @@ process.stdin.on('end', function () {
} else {
level = origin.function.level;
}
+ total = totals[token.line - 1];
+
+ out.push({
+ l: level,
+ s: total + token.from,
+ e: total + token.thru
+ });
- return {
- from: token.from,
- level: level,
- line: token.line,
- thru: token.thru
- };
- });
+ i += 1;
+ }
- console.log(JSON.stringify(tokens));
+ console.log(JSON.stringify(out));
});
- [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 <=
- [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, 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