Skip to content

Commit 4ad01ac

Browse files
committed
First commit
0 parents  commit 4ad01ac

File tree

7 files changed

+419
-0
lines changed

7 files changed

+419
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.nrepl-port
2+
target

lt_cljs_playground.behaviors

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[
2+
[:app :lt.objs.plugins/load-js "lt_cljs_playground_compiled.js"]
3+
[:lt-cljs-playground.hello :lt.plugins.lt-cljs-playground/on-close-destroy]
4+
]

lt_cljs_playground_compiled.js

Lines changed: 266 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lt_cljs_playground_compiled.js.map

Lines changed: 57 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugin.edn

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{:name "lt_cljs_playground"
2+
:version "0.0.1"
3+
:author ""
4+
:source ""
5+
:desc ""
6+
:behaviors "lt_cljs_playground.behaviors"}

project.clj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
(defproject lt-cljs-playground "0.0.1"
2+
:dependencies [[org.clojure/clojure "1.5.1"]])
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
(ns lt.plugins.lt-cljs-playground
2+
(:require [lt.object :as object]
3+
[lt.objs.tabs :as tabs]
4+
[lt.objs.command :as cmd]
5+
[lt.objs.editor :as editor]
6+
[lt.objs.editor.pool :as editor-pool]
7+
[cljs.reader :refer [read-string] :as rdr])
8+
(:require-macros [lt.macros :refer [defui behavior]]))
9+
10+
(defui hello-panel [this]
11+
[:h1 "Hello from lt-cljs-playground"])
12+
13+
(object/object* ::lt-cljs-playground.hello
14+
:tags [:lt-cljs-playground.hello]
15+
:behaviors [::on-close-destroy]
16+
:name "lt-cljs-playground"
17+
:init (fn [this]
18+
(hello-panel this)))
19+
20+
(behavior ::on-close-destroy
21+
:triggers #{:close}
22+
:desc "lt-cljs-playground: Close tab and tabset as well if last tab"
23+
:reaction (fn [this]
24+
(when-let [ts (:lt.objs.tabs/tabset @this)]
25+
(when (= (count (:objs @ts)) 1)
26+
(tabs/rem-tabset ts)))
27+
(object/raise this :destroy)))
28+
29+
(def hello (object/create ::lt-cljs-playground.hello))
30+
31+
(defrecord EditorPushbackReader [ed state]
32+
rdr/PushbackReader
33+
(read-char [_]
34+
(println @state)
35+
(if (seq (:buffer @state))
36+
(let [popped (last (:buffer @state))]
37+
(swap! state update-in [:buffer] pop)
38+
popped)
39+
(let [{:keys [line-contents line col]} @state]
40+
(if (<= (count line-contents) col)
41+
(loop [line-contents (editor/line ed (inc line))
42+
line (inc line)]
43+
(cond
44+
(nil? line-contents) (do (swap! state assoc :eof? true) nil)
45+
(clojure.string/blank? line-contents) (recur (editor/line ed (inc line)) (inc line))
46+
:else (do
47+
(println ">>>>" line line-contents)
48+
(swap! state assoc :line line :col 0 :line-contents line-contents)
49+
(aget line-contents 0))))
50+
(do
51+
(swap! state update-in [:col] inc)
52+
(aget line-contents col))))))
53+
(unread [_ ch] (swap! state update-in [:buffer] conj ch)))
54+
55+
(defn- default-reader-state
56+
[ed start-line start-col]
57+
{:line start-line
58+
:col start-col
59+
:buffer []
60+
:line-contents (editor/line ed start-line)})
61+
62+
(defn editor-pushback-reader
63+
[ed]
64+
(EditorPushbackReader. ed (atom (default-reader-state ed 0 0))))
65+
66+
(defn read-all-forms-in-editor
67+
[ed]
68+
(loop [forms []
69+
r (editor-pushback-reader ed)]
70+
(if-not (:eof? @(:state r))
71+
(let [form (rdr/read r false nil true)
72+
state @(:state r)]
73+
(recur (conj forms form)
74+
(assoc r :state (atom (default-reader-state ed (:line state) (inc (:col state)))))))
75+
forms)))
76+
77+
(cmd/command {:command ::run-dis
78+
:desc "Idiocheck: Run dis"
79+
:exec (fn []
80+
(when-let [ed (editor-pool/last-active)]
81+
(println (read-all-forms-in-editor ed))))})
82+

0 commit comments

Comments
 (0)