File tree Expand file tree Collapse file tree 4 files changed +71
-8
lines changed Expand file tree Collapse file tree 4 files changed +71
-8
lines changed Original file line number Diff line number Diff line change 2
2
[X] Move all of the socket repl stuff to a plugin project
3
3
[X] Make buffer-get-text-async work, just test it at the repl
4
4
[X] Get "eval-code" working
5
- [_ ] Figure out how to accumulate / display results in vim
5
+ [X ] Figure out how to accumulate / display results in vim
6
6
[X] append it all to a file
7
7
[X] preferably a temp file (could be a lot of data)
8
- [_ ] `:ShowRepl`
8
+ [X ] `:ShowRepl`
9
9
no vimscript, invoke a plugin function
10
10
show the contents of the temp file in the current buffer
11
11
make it autoread
12
12
[X] Name vim functions correctly
13
+ [_] Rather than explicit repl output logging, can we intercept
14
+ channel
15
+ stream implementation
16
+ [_] tmux dev env script
13
17
[_] Pass host, port in connect
14
18
[_] Shut down the plugin if no input received for one minute
19
+ [X] evaluate form under cursor
15
20
16
21
Goals
17
22
-Not a proper nRepl plugin, primary use is as an thought exercise
32
37
Forces you to explicity connect
33
38
One connection only `:call ConnectClojurePlugin(host, port)`
34
39
Accessible from vim buffer `:call ShowClojurePluginRepl()`
40
+ -Not a way of life
41
+ Does not include paredit, syntax highlight, etc
35
42
36
43
Questions
37
44
Figwheel cljs-repl support
Original file line number Diff line number Diff line change @@ -29,7 +29,8 @@ command! EvalBuffer call EvalBuffer()
29
29
30
30
function ! EvalCode ()
31
31
" call StartIfNotRunning()
32
- let res = rpcrequest (g: channel , ' eval-code' , [])
32
+ " let res = rpcrequest(g:channel, 'eval-code', [])
33
+ let res = rpcrequest (1 , ' eval-code' , [])
33
34
return res
34
35
endfunction
35
36
command ! EvalCode call EvalCode ()
Original file line number Diff line number Diff line change 4
4
(:require
5
5
[clojure.java.io :as io]
6
6
[clojure.core.async :as async :refer [go go-loop >! <!]]
7
+ [clojure.string :as string]
7
8
[neovim-client.nvim :as nvim])
8
9
(:import
9
10
(java.net Socket)
10
11
(java.io PrintStream File)))
11
12
12
13
(def current-connection (atom nil ))
13
14
15
+ (defn position
16
+ " Find the position in a code string given line and column."
17
+ [code-str [y x]]
18
+ (->> code-str
19
+ string/split-lines
20
+ (take (dec y))
21
+ (string/join " \n " )
22
+ count
23
+ (+ (inc x))))
24
+
25
+ (defn get-form-at
26
+ " Returns the enclosing form from a string a code using [row col]
27
+ coordinates."
28
+ [code-str coords]
29
+ (let [pos (position code-str coords)]
30
+ (read-string
31
+ ; ; Start at the last index of paren on or before `pos`, read a form.
32
+ (subs code-str (if (= \( (.charAt code-str pos))
33
+ pos
34
+ (.lastIndexOf (subs code-str 0 pos) " (" ))))))
35
+
14
36
(defn output-file
15
37
[]
16
38
(File/createTempFile " socket-repl" " .txt" ))
96
118
(nvim/register-method!
97
119
" eval-code"
98
120
(fn [msg]
99
- ; ; TODO: Get the cursor location, find current form
100
- ))
121
+ (nvim/get-cursor-location-async
122
+ (fn [coords]
123
+ (nvim/get-current-buffer-text-async
124
+ (fn [x]
125
+ (try
126
+ (let [form (get-form-at x coords)]
127
+ (write-output! (str form " \n " ))
128
+ (write-code! form))
129
+ (catch Throwable t
130
+ ; ; TODO: Use more general plugin-level ereror handling
131
+ (write-output!
132
+ (str " \n ##### PLUGIN ERR #####\n "
133
+ (.getMessage t) " \n "
134
+ (string/join " \n " (map str (.getStackTrace t)))
135
+ \n" ######################\n " ))))))))))
101
136
102
137
(nvim/register-method!
103
138
" eval-buffer"
138
173
; ; Let nvim know we're shutting down.
139
174
(nvim/run-command! " :let g:is_running=0" )
140
175
(nvim/run-command! " :echo 'plugin stopping.'" )))
141
-
Original file line number Diff line number Diff line change 22
22
23
23
(defn get-api-info [] (send-message! " vim_get_api_info" ))
24
24
25
+ ; ; ***** Cursor *****
26
+
27
+ (declare get-current-window-async )
28
+ (defn get-cursor-location-async
29
+ " Gets the cursor's current position as a tuple (row, col) asynchronously."
30
+ [f]
31
+ (get-current-window-async
32
+ (fn [window]
33
+ (rpc/send-message-async!
34
+ (->request-msg " window_get_cursor" [window]) f))))
35
+
36
+ ; ; ***** Lines *****
37
+
25
38
(defn get-current-line [] (send-message! " vim_get_current_line" ))
26
39
27
40
(defn set-current-line! [line] (send-message! " vim_set_current_line" line))
28
41
42
+ ; ; ***** Windows *****
43
+
44
+ (defn get-current-window-async
45
+ " Gets a reference to the current window asynchronously."
46
+ [f]
47
+ (rpc/send-message-async! (->request-msg " vim_get_current_window" []) f))
48
+
49
+ ; ; ***** Buffers *****
50
+
29
51
(defn get-current-buffer
30
- ; ; TODO: fix comment
31
- " Returns ??? (object, map, ?) representing the current buffer."
52
+ " Returns a reference to the current buffer."
32
53
[]
33
54
(send-message! " vim_get_current_buffer" ))
34
55
You can’t perform that action at this time.
0 commit comments