Skip to content

Commit 4dae3cd

Browse files
committed
Add Eval command
The Eval command in this implements a version of the quasi-REPL of vim-fireplace. I chose to rename EvalCode to EvalForm in the process, because I needed a naming scheme that supports Eval as the "base" case, and EvalCode sounds too much like something taking user input. EvalForm on the other hand feels more natural for the functionality it provides; send form under cursor to be evaluated.
1 parent 21899b9 commit 4dae3cd

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-8
lines changed

plugin/socketrepl.vim

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,38 @@ function! ReadyEvalBuffer()
5050
endfunction
5151
command! EvalBuffer call ReadyEvalBuffer()
5252

53-
function! EvalCode()
53+
function! EvalForm()
5454
ReplLog
55-
let res = rpcnotify(g:nvim_tcp_plugin_channel, 'eval-code', [])
55+
let res = rpcnotify(g:nvim_tcp_plugin_channel, 'eval-form', [])
5656
return res
5757
endfunction
5858

59-
function! ReadyEvalCode()
59+
function! ReadyEvalForm()
6060
if g:socket_repl_plugin_ready == 1
61-
call EvalCode()
61+
call EvalForm()
6262
else
6363
echo s:not_ready
6464
endif
6565
endfunction
66-
command! EvalCode call ReadyEvalCode()
66+
command! EvalForm call ReadyEvalForm()
67+
68+
function! Eval()
69+
ReplLog
70+
call inputsave()
71+
let form = input('=> ')
72+
call inputrestore()
73+
let res = rpcnotify(g:nvim_tcp_plugin_channel, 'eval', [form])
74+
return res
75+
endfunction
76+
77+
function! ReadyEval()
78+
if g:socket_repl_plugin_ready == 1
79+
call Eval()
80+
else
81+
echo s:not_ready
82+
endif
83+
endfunction
84+
command! Eval call ReadyEval()
6785

6886
function! ReplLog(buffer_cmd)
6987
let res = rpcnotify(g:nvim_tcp_plugin_channel, 'show-log', a:buffer_cmd)
@@ -109,8 +127,9 @@ endfunction
109127
command! Doc call ReadyDoc()
110128

111129
if !exists('g:disable_socket_repl_mappings')
130+
nnoremap <leader>e :Eval<cr>
112131
nnoremap <leader>eb :EvalBuffer<cr>
113-
nnoremap <leader>ef :EvalCode<cr>
132+
nnoremap <leader>ef :EvalForm<cr>
114133
nnoremap <leader>doc :Doc<cr>
115134
nnoremap <leader>rlog :ReplLog<cr>
116135
nnoremap <leader>drlog :DismissReplLog<cr>

src/socket_repl/socket_repl_plugin.clj

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
(str "\n##### PLUGIN ERR #####\n"
2626
(.getMessage throwable) "\n"
2727
(string/join "\n" (map str (.getStackTrace throwable)))
28-
\n"######################\n")))
28+
"\n######################\n")))
2929

3030
(defn run-command
3131
[{:keys [nvim nrepl socket-repl]} f]
@@ -111,7 +111,23 @@
111111

112112
(nvim/register-method!
113113
nvim
114-
"eval-code"
114+
"eval"
115+
(run-command
116+
plugin
117+
(fn [msg]
118+
(try
119+
(async/>!! code-channel (parser/read-next
120+
(-> msg
121+
message/params
122+
ffirst)
123+
0 0))
124+
(catch Throwable t
125+
(log/error t "Error evaluating form")
126+
(write-error repl-log t))))))
127+
128+
(nvim/register-method!
129+
nvim
130+
"eval-form"
115131
(run-command
116132
plugin
117133
(fn [msg]

0 commit comments

Comments
 (0)