Added REPL support

Closes #9
Closes #12
This commit is contained in:
baabelfish 2016-02-07 18:03:56 +02:00
commit fd587228d0
5 changed files with 90 additions and 1 deletions

View file

@ -0,0 +1,67 @@
if exists("s:loaded")
finish
endif
let s:loaded = 1
let s:repl_pid = -1
let s:repl_window = -1
function! s:Window()
return winbufnr(s:repl_window)
endfunction
function! s:IsOpen()
return winbufnr(s:Window()) > 0
endfunction
function! s:Focus()
if s:IsOpen()
exec ":" . s:Window() . "wincmd w"
endif
endfunction
function! features#repl#start()
if s:IsOpen()
call s:Focus()
else
if g:nvim_nim_repl_vsplit
vnew
wincmd L
wincmd L
wincmd L
else
new
wincmd J
wincmd J
wincmd J
endif
let s:repl_window = winnr()
let s:repl_pid = termopen("sh -c \"nim secret\"")
endif
endfunction
function! features#repl#send(lines)
if !s:IsOpen()
call features#repl#start()
sleep 100m
endif
for line in a:lines
call jobsend(s:repl_pid, line . "\r")
sleep 20m
endfor
call jobsend(s:repl_pid, "\r")
sleep 20m
norm! i
endfunction
function! features#repl#stop()
if s:repl_pid > 0
call jobstop(s:repl_pid)
call s:Focus()
exec ":bd!"
else
echom "No REPL running"
endif
endfunction

View file

@ -262,3 +262,15 @@ function! util#SelectNimProc(inner)
normal! h
endif
endfunction
call operator#user#define('nimrepl_send', 'NimReplSend')
function! NimReplSend(motion_wiseness)
let start = getpos("'[")
let stop = getpos("']")
let start_line = start[1]
let stop_line = stop[1]
let str = join(getline(start_line, stop_line), "\n")
echom str
call features#repl#send(str)
endfunction