Skip to content

Commit 9ea3a09

Browse files
committed
WIP - update names, docstrings
1 parent 0227b5c commit 9ea3a09

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

socket-repl-plugin/TODO

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
TODO
2-
[_] Move this TODO to socket-repl-plugin
3-
[_] Move all of the socket repl stuff to a plugin project
2+
[X] Move all of the socket repl stuff to a plugin project
43
[X] Make buffer-get-text-async work, just test it at the repl
54
[X] Get "eval-code" working
65
[_] Figure out how to accumulate / display results in vim
@@ -13,6 +12,7 @@ TODO
1312
make it autoread
1413
[_] Name vim functions correctly
1514
[_] Pass host, port in connect
15+
[_] Shut down the plugin if no input received for one minute
1616

1717
Goals
1818
-Not a proper nRepl plugin, primary use is as an thought exercise

socket-repl-plugin/plugin/socketrepl.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function! StartIfNotRunning()
1313
endif
1414
endfunction
1515

16-
function! EvalConnect()
16+
function! Connect()
1717
"call StartIfNotRunning()
1818
let res = rpcrequest(1, 'connect', [])
1919
return res

socket-repl-plugin/src/socket_repl/socket_repl_plugin.clj

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
(java.net Socket)
1010
(java.io PrintStream)))
1111

12+
(def current-connection (atom nil))
13+
1214
(defn connection
15+
"Create a connection to a socket repl."
1316
[host port]
1417
(let [socket (java.net.Socket. "localhost" 5555)]
1518
{:host host
@@ -19,14 +22,18 @@
1922
PrintStream.)
2023
:in (io/reader socket)}))
2124

22-
(defn eval*
25+
(defn write-code
26+
"Writes a string of code to the socket repl connection."
2327
[{:keys [:out]} code-string]
2428
(.println out code-string)
2529
(.flush out))
2630

27-
(def current-connection (atom nil))
28-
2931
(defn connect!
32+
"Connect to a socket repl. Adds the connection to the `current-connection`
33+
atom. Creates `go-loop`s to delegate input from the socket to `handler` one
34+
line at a time.
35+
36+
`handler` is a function which accepts one string argument."
3037
[host port handler]
3138
(let [conn (connection host port)
3239
chan (async/chan 10)]
@@ -47,9 +54,10 @@
4754
(recur))))
4855
"success")
4956

50-
(defn eval*!
57+
(defn write-code!
58+
"Like `write-code`, but uses the current socket repl connection."
5159
[code-string]
52-
(eval* @current-connection code-string))
60+
(write-code @current-connection code-string))
5361

5462
(defn -main
5563
[& args]
@@ -81,9 +89,10 @@
8189
;; TODO: send code being executed
8290
;; back to vim, to show what actually
8391
;; happened in the repl buffer
84-
(eval*! x)))))
92+
(write-code! x)))))
8593

86-
;; TODO: When do we disconnect?
94+
;; TODO: Rather than an arbitrary timeout, the plugin should shut down
95+
;; when it has received no input for some time.
8796
(comment
8897
(dotimes [n 60]
8998
(if (= 0 (mod n 10))

0 commit comments

Comments
 (0)