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

@ -23,12 +23,15 @@ DON'T INSTALL YET, STILL UNDER VERY HEAVY DEVELOPMENT.
- Jump to documentation in web
- Refactoring
- Rename symbol in file or project
- REPL
- Open repl
- Send current buffer
- Send selection
![something](https://raw.githubusercontent.com/baabelfish/nvim-nim/master/other/pic1.png)
## Planned features
- REPL support
- Debugger support
- Autocomplete modules
- All features will work asynchronously

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

View file

@ -36,6 +36,10 @@ command! NimEdbIgonore :call features#debugger#ignore()
command! NimEdbContinue :call features#debugger#continue()
command! NimEdbToggleBP :call features#debugger#togglebp()
command! NimREPL :call features#repl#start()
command! NimREPLEvalFile :call features#repl#send(getline(0, line("$")))
command! -range NimREPLEval :call features#repl#send(getline(getpos("'<")[1], getpos("'>")[1]))
nnoremap <buffer> <c-]> :NimDefinition<cr>
nnoremap <buffer> gd :NimDefinition<cr>
nnoremap <buffer> gt :NimInfo<cr>

View file

@ -44,4 +44,7 @@ let g:nvim_nim_highlight_use_unite = 0
let g:nvim_nim_outline_buffer = 1
let g:nvim_nim_outline_buffer_width = 30
let g:nvim_nim_repl_height = 14
let g:nvim_nim_repl_vsplit = 0
let g:nvim_nim_highlighter_semantics = ["skConst", "skForVar", "skGlobalVar", "skGlobalLet", "skLet", "skModule", "skParam", "skTemp", "skVar"]