Skip to content
This repository was archived by the owner on Oct 21, 2022. It is now read-only.

Commit a2b5c40

Browse files
committed
Move lighttable from node_modules to core/
Signed-off-by: Pratik Karki <pratik@prertik.com>
1 parent 98907c7 commit a2b5c40

File tree

10 files changed

+1840
-3
lines changed

10 files changed

+1840
-3
lines changed

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
//deploy/core/node_modules/*
2-
!/deploy/core/node_modules/lighttabledeploy/core/node_modules/lighttable/cljs/
1+
/deploy/core/node_modules/*
32
/deploy/core/node_modules/clojurescript/cljsDeps/
43
/target/
54
/deploy/plugins/
65
.DS_Store
7-
/deploy/core/node_modules/lighttable/bootstrap.js*
86
.lein-deps-sum
97
.lein-env
108
.lein-plugins/
@@ -13,3 +11,6 @@
1311
.idea
1412
*.iml
1513
/lsp
14+
/deploy/core/lighttable/bootstrap.js
15+
/deploy/core/lighttable/bootstrap.js.map
16+
/deploy/core/lighttable/cljs/
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
var opposites = {
2+
"(": ")",
3+
"[": "]",
4+
"{": "}",
5+
")": "(",
6+
"]": "[",
7+
"}": "{"
8+
};
9+
10+
var chars = /[^\s\)\]\}]/;
11+
12+
//{:+ {:app [:foo (:blah "asdf" {:foo 234}) :zomg]}}
13+
//var example = "{:+ {:app [(:lt.objs.style/set-skin \"dark\")\n (:lt.plugins.vim/map-keys {\"-\" \"$\",\n \"0\" \"^\",\n \"<BS>\" \"<PageUp>\",\n \"<Space>\" \"<PageDown>\",\n \"j\" \"gj\",\n \"k\" \"gk\"})\n :lt.objs.intro/show-new-file \n ],\n\n :editor [:lt.plugins.vim/activate-vim\n :lt.objs.editor/no-wrap\n :lt.plugins.rainbow-parens/rainbow-parens\n :lt.plugins.auto-complete/auto-show-on-input\n (:lt.objs.style/set-theme \"ibdknox\")],\n\n :editor.behaviors [:lt.plugins.rainbow-parens/rainbow-parens],\n\n :editor.clj [:lt.plugins.rainbow-parens/rainbow-parens],\n\n :editor.clj.instarepl [:lt.plugins.rainbow-parens/rainbow-parens\n (:lt.objs.langs.clj/print-length 1000)],\n\n :editor.cljs [:lt.plugins.rainbow-parens/rainbow-parens],\n\n :editor.javascript [(:lt.plugins.jshint/jshint-options {:maxparams false})\n :lt.plugins.jshint/on-save],\n\n :editor.keymap [:lt.plugins.rainbow-parens/rainbow-parens],\n\n :editor.markdown [:lt.objs.editor/wrap],\n\n :editor.plaintext [:lt.objs.editor/wrap],\n\n :editor.python [(:lt.objs.style/set-theme \"tomorrow-night\")],\n\n :files [(:lt.objs.files/file-types [{:exts [:wisp],\n :mime \"text/x-clojurescript\",\n :name \"Wisp\",\n :tags [:editor.wisp]}])]},\n\n :- {:app [:lt.objs.intro/show-intro]}}\n";
14+
15+
16+
//{:+ {:app {"a" [:foo]}}}
17+
18+
// parseFlat(new CodeMirror.StringStream("[[:app :foo :bar] [:zomg :baz 234 \"hi how are you?\"]]"));
19+
function parseFlat(stream) {
20+
21+
var state = { level: 0, stack: []};
22+
var errors = [];
23+
var entries = [];
24+
var curEntry;
25+
26+
stream.eatSpace();
27+
while(stream.peek()) {
28+
var ch = stream.next();
29+
30+
if (ch == "\"") {
31+
stream.start = stream.pos - 1;
32+
state.mode = "string";
33+
var pos = stream.pos;
34+
var next, escaped = false;
35+
while ((next = stream.next()) != null) {
36+
if (next == "\"" && !escaped) {
37+
38+
state.mode = false;
39+
break;
40+
}
41+
escaped = !escaped && next == "\\";
42+
}
43+
44+
if(state.level === 2) {
45+
curEntry.tokens.push({start: stream.start, end: stream.pos, value: stream.current(), type: "string"});
46+
}
47+
48+
} else if (ch == ";") { // comment
49+
stream.skipTo("\n"); // rest of the line is a comment
50+
51+
} else if (ch == "(" || ch == "[" || ch == "{") {
52+
state.stack.push({type: ch, pos: stream.pos});
53+
state.level++;
54+
if(state.level === 2) {
55+
curEntry = {start: stream.pos - 1,
56+
tokens: []};
57+
entries.push(curEntry);
58+
} else if(state.level === 3) {
59+
curEntry.tokens.push({start: stream.pos - 1,
60+
type: "collection",
61+
tokens: []});
62+
} else if(state.level === 4) {
63+
var lastToken = curEntry.tokens[curEntry.tokens.length - 1];
64+
lastToken.tokens.push({start: stream.pos - 1,
65+
type: "collection",
66+
tokens: []});
67+
}
68+
69+
} else if (ch == ")" || ch == "]" || ch == "}") {
70+
if(state.stack.length && state.stack[state.stack.length - 1].type == opposites[ch]) {
71+
state.stack.pop();
72+
state.level--;
73+
74+
if(state.level === 1) {
75+
curEntry.end = stream.pos;
76+
} else if(state.level === 2) {
77+
curEntry.tokens[curEntry.tokens.length - 1].end = stream.pos;
78+
stream.start = stream.pos;
79+
} else if(state.level === 3) {
80+
var lastToken = curEntry.tokens[curEntry.tokens.length - 1];
81+
lastToken.tokens[lastToken.tokens.length - 1].end = stream.pos;
82+
stream.start = stream.pos;
83+
}
84+
85+
} else {
86+
var expected = "the end of the file";
87+
if(state.stack[state.stack.length - 1]) {
88+
var expected = opposites[state.stack[state.stack.length - 1].type];
89+
}
90+
errors.push({error: "Unmatched delimiter " + ch + " expected to see " + expected + "", from: stream.start, to: stream.pos});
91+
}
92+
93+
94+
} else if ( ch == ":" ) {
95+
stream.start = stream.pos - 1;
96+
stream.eatWhile(chars);
97+
if(state.level === 2) {
98+
curEntry.tokens.push({start: stream.start, end: stream.pos, value: stream.current(), type: "keyword"});
99+
} else if(state.level === 3) {
100+
var lastToken = curEntry.tokens[curEntry.tokens.length - 1];
101+
lastToken.tokens.push({start: stream.start, end: stream.pos, value: stream.current(), type: "keyword"});
102+
}
103+
stream.start = stream.pos;
104+
} else if(ch.match(chars)) {
105+
stream.start = stream.pos - 1;
106+
var pos = stream.pos;
107+
stream.eatWhile(chars);
108+
if(state.level === 2) {
109+
curEntry.tokens.push({start: stream.start, end: stream.pos, value: stream.current(), type: "atom"});
110+
} else if(state.level === 3) {
111+
var lastToken = curEntry.tokens[curEntry.tokens.length - 1];
112+
lastToken.tokens.push({start: stream.start, end: stream.pos, value: stream.current(), type: "keyword"});
113+
}
114+
stream.start = stream.pos;
115+
}
116+
}
117+
118+
return {errors: errors, entries: entries};
119+
}
120+
121+
exports.parseFlat = parseFlat;
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
var fs = require("fs");
2+
var funcs = {};
3+
var ltpath = "";
4+
5+
var _send = function(obj, msg, res, format) {
6+
format = format || "json";
7+
process.send({msg: cljs.core.name(msg), res: res, obj:obj, format: format});
8+
};
9+
10+
var argsArray = function(args) {
11+
var final = [];
12+
for(var i = 0; i < args.length; i++) {
13+
final.push(args[i]);
14+
}
15+
return final;
16+
};
17+
18+
var lttools = {
19+
watch: function(exp, meta) {
20+
_send(meta.obj, cljs.core.keyword(meta.ev), cljs.core.pr_str(cljs.core.js__GT_clj({result: exp, meta: meta}, cljs.core.keyword("keywordize-keys"), true)), "clj");
21+
}
22+
};
23+
24+
process.on("message", function(m) {
25+
try {
26+
switch(m.msg) {
27+
case "init":
28+
ltpath = m.ltpath;
29+
global.eval(fs.readFileSync(ltpath + "/core/node_modules/clojurescript/cljsDeps.js").toString());
30+
cljs.core._STAR_print_fn_STAR_ = function(x) {
31+
var final = clojure.string.trim(x);
32+
if(x != "\n") {
33+
console.log(final);
34+
}
35+
};
36+
_send(m.obj, "connect");
37+
break;
38+
case "register":
39+
eval("funcs['" + m.name + "'] = " + m.func);
40+
break;
41+
case "call":
42+
m.params.unshift(m);
43+
funcs[m.name].apply(null, m.params);
44+
break;
45+
}
46+
} catch (e) {
47+
console.error(e.stack);
48+
}
49+
});
50+
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
var fs = require('fs');
2+
var _path = require('path');
3+
4+
var curtime = function() {
5+
return (new Date()).getTime();
6+
}
7+
8+
var walk = function(path,options){
9+
10+
var start = curtime();
11+
var allPaths = [];
12+
if(path.push) {
13+
var queue = path;
14+
} else {
15+
var queue = [path];
16+
}
17+
var stat = null;
18+
var children = null;
19+
var child = null;
20+
var isDir = null;
21+
var filter = options.filter;
22+
var limit = options.limit;
23+
var cur = null;
24+
var limited = false;
25+
var basename = null;
26+
27+
while(cur = queue.shift()) {
28+
29+
try {
30+
children = fs.readdirSync(cur);
31+
} catch(e) {
32+
console.error("Couldn't read dir " + cur);
33+
continue;
34+
}
35+
36+
for(var i = 0; i < children.length; i++) {
37+
basename = children[i];
38+
child = _path.join(cur, basename);
39+
try {
40+
stat = fs.statSync(child);
41+
} catch(e) {
42+
try {
43+
stat = fs.lstatSync(child);
44+
} catch(e) {
45+
continue;
46+
}
47+
}
48+
isDir = stat.isDirectory();
49+
50+
if(isDir) {
51+
basename += _path.sep;
52+
}
53+
54+
if(!filter || !basename.match(filter)) {
55+
if(isDir) {
56+
queue.push(child);
57+
} else if(!limit || allPaths.length <= limit) {
58+
allPaths.push(child);
59+
} else {
60+
queue = [];
61+
limited = true;
62+
break;
63+
}
64+
}
65+
}
66+
}
67+
68+
return {time: curtime() - start,
69+
paths: allPaths,
70+
total: allPaths.length,
71+
limited: limited};
72+
73+
}
74+
75+
module.exports = walk;
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
(function(window) {
2+
3+
const { ipcMain, ipcRenderer } = require('electron');
4+
5+
function toArray(arrayLike) {
6+
var final = [];
7+
for(var i = 0, len = arrayLike.length; i < len; i++) {
8+
final.push(arrayLike.item(i));
9+
}
10+
return final;
11+
}
12+
13+
ipcMain.on("editor.eval.css", function(args) {
14+
var nodeName = args.name.replace(/\./, "-");
15+
var code = args.code;
16+
var styleElem = document.createElement("style");
17+
styleElem.type = "text/css"
18+
styleElem.id = nodeName;
19+
styleElem.innerHTML = code;
20+
var prev = document.getElementById(nodeName);
21+
if(prev) {
22+
prev.parentNode.removeChild(prev);
23+
} else {
24+
var link = toArray(document.head.querySelectorAll("link")).filter(function(cur) {
25+
return cur.href.indexOf(args.name) > -1;
26+
});
27+
if(link[0]) {
28+
link[0].parentNode.removeChild(link[0]);
29+
}
30+
}
31+
document.head.appendChild(styleElem);
32+
});
33+
34+
35+
ipcMain.on("editor.eval.cljs.exec", function(args) {
36+
for(var i = 0; i < args.results.length; i++) {
37+
var data = args.results[i];
38+
var meta = args.results[i].meta;
39+
meta.verbatim = true;
40+
try {
41+
var res = eval.call(window, args.results[i].code);
42+
if(window.cljs) {
43+
ipcRenderer.sendToHost("browser-raise", [args.client, "editor.eval.cljs.result", {result: cljs.core.pr_str(res), meta: meta}]);
44+
} else {
45+
ipcRenderer.sendToHost("browser-raise", [args.client, "editor.eval.cljs.result", {result: safeStringify(res), meta: meta}]);
46+
}
47+
} catch (e) {
48+
var exdata = cljs.core.ex_data(e);
49+
var error = "";
50+
if (exdata) {
51+
error = e.message + ": " + cljs.core.pr_str(exdata);
52+
} else {
53+
error = cljs.core.pr_str(e);
54+
}
55+
56+
if(e.stack) {
57+
error += "\n" + e.stack;
58+
}
59+
ipcRenderer.sendToHost("browser-raise", [args.client, "editor.eval.cljs.exception", {ex: error, meta: meta}]);
60+
}
61+
}
62+
});
63+
64+
window.addEventListener("hashchange", function(e) {
65+
ipcRenderer.sendToHost("browser-event", ["hashchange", {href: window.location.href, hash: window.location.hash}]);
66+
});
67+
68+
function replacer(key, value) {
69+
if(window.jQuery && value instanceof jQuery) {
70+
return "[jQuery $(" + value.selector + ")]";
71+
}
72+
if(value instanceof Element) {
73+
return "[Element " + value.tagName.toLowerCase() + (value.id != "" ? "#" : "") + value.id + "]";
74+
}
75+
if(value instanceof Array) {
76+
return value;
77+
}
78+
if(typeof(value) == "object") {
79+
if(cache.indexOf(value) > -1) {
80+
return "circular";
81+
}
82+
cache.push(value);
83+
return value;
84+
}
85+
if(typeof value == "function") {
86+
return "[function]";
87+
}
88+
return value;
89+
}
90+
91+
function safeStringify(res) {
92+
cache = [];
93+
return JSON.stringify(res, replacer);
94+
}
95+
96+
window.lttools = {
97+
watch: function(exp, meta) {
98+
if(meta.ev == "editor.eval.cljs.watch") {
99+
var final = cljs.core.pr_str(exp);
100+
} else {
101+
meta["no-inspect"] = true;
102+
var final = safeStringify(exp);
103+
}
104+
ipcRenderer.sendToHost("browser-raise", [meta.obj, meta.ev, {result: final, meta: meta}]);
105+
return exp;
106+
}
107+
}
108+
109+
110+
})(window);

0 commit comments

Comments
 (0)