Skip to content

Commit 0912bb9

Browse files
committed
Make NS switching command configurable
It is not always desirable to eval the entire NS declaration, so this commit makes it configurable whether to use `in-ns` or eval it entirely.
1 parent 5102acf commit 0912bb9

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

Diff for: plugin/socketrepl.vim

+14
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ let s:p_dir = expand('<sfile>:p:h')
22
let g:is_running = 0
33
let g:socket_repl_plugin_ready = 0
44
let g:nvim_tcp_plugin_channel = 0
5+
let g:eval_entire_ns_decl = 0 " 0 = SwitchBufferNS uses `in-ns`. 1 = SwitchBufferNS evals entire ns declaration
56

67
let s:not_ready = "SocketREPL plugin not ready (starting)"
78

@@ -177,6 +178,19 @@ function! ReadyCursorSource()
177178
endfunction
178179
command! SourceCursor call ReadyCursorSource()
179180

181+
function! SwitchBufferNS()
182+
call rpcnotify(g:nvim_tcp_plugin_channel, 'switch-buffer-ns', [])
183+
endfunction
184+
185+
function! ReadySwitchBufferNS()
186+
if g:socket_repl_plugin_ready == 1
187+
call SwitchBufferNS()
188+
else
189+
echo s:not_ready
190+
endif
191+
endfunction
192+
command! SwitchBufferNS call ReadySwitchBufferNS()
193+
180194
if !exists('g:disable_socket_repl_mappings')
181195
nnoremap K :DocCursor<cr>
182196
nnoremap [d :SourceCursor<cr>

Diff for: src/socket_repl/socket_repl_plugin.clj

+7-3
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,19 @@
234234

235235
(nvim/register-method!
236236
nvim
237-
"eval-buffer-ns"
237+
"switch-buffer-ns"
238238
(run-command
239239
plugin
240240
(fn [msg]
241241
(let [buffer-name (api/get-current-buf nvim)
242242
file-name (api.buffer/get-name nvim buffer-name)
243243
file (io/file file-name)
244-
namespace-declarations (namespace.find/find-ns-decls-in-dir file)]
245-
(async/>!! (socket-repl/input-channel socket-repl) (first namespace-declarations))))))
244+
namespace-declaration (first (namespace.find/find-ns-decls-in-dir file))
245+
eval-entire-declaration? (= 1 (api/get-var nvim "eval_entire_ns_decl"))
246+
code-form (if eval-entire-declaration?
247+
namespace-declaration
248+
`(clojure.core/in-ns '~(second namespace-declaration)))]
249+
(async/>!! (socket-repl/input-channel socket-repl) code-form)))))
246250

247251
(nvim/register-method!
248252
nvim

0 commit comments

Comments
 (0)