vim/bundle/ooze/plugin/ooze.vim @ a87221e612e6
Start ooze
author |
Steve Losh <steve@stevelosh.com> |
date |
Wed, 09 Dec 2015 12:14:39 +0000 |
parents |
(none) |
children |
83aac563abc9 |
function! s:IsString(a)
return type(a:a) == 1
endfunction
function! s:HandleMessage(msg)
let stdout = get(a:msg, 'stdout')
if s:IsString(stdout)
echo stdout
endif
let stderr = get(a:msg, 'stderr')
if s:IsString(stderr)
echo stderr
endif
let value = get(a:msg, 'value')
if s:IsString(value)
echo value
endif
endfunction
function! s:HandleData(data)
for msg in bencode#BdecodeAll(a:data)
call s:HandleMessage(msg)
endfor
endfunction
silent! function s:JobHandler(job_id, data, event)
if a:event == 'stdout'
call s:HandleData(join(a:data, "\n"))
elseif a:event == 'stderr'
1
else
1
endif
endfunction
let s:callbacks = {
\ 'on_stdout': function('s:JobHandler'),
\ 'on_stderr': function('s:JobHandler'),
\ 'on_exit': function('s:JobHandler')
\ }
if !exists("g:ooze_connection")
let g:ooze_connection = 0
endif
function! OozeDisconnect()
if g:ooze_connection
call jobstop(g:ooze_connection)
let g:ooze_connection = 0
endif
endfunction
function! OozeConnect()
if g:ooze_connection
call OozeDisconnect()
endif
let g:ooze_connection = jobstart(['nc', 'localhost', '8675'], s:callbacks)
endfunction
function! OozeEval(code)
if !g:ooze_connection
throw "Not connected!"
endif
let msg = {"op": "eval", "code": a:code}
call jobsend(g:ooze_connection, bencode#Bencode(msg))
endfunction
function! OozeEvalSelection()
let z = @z
normal! gv"zy
call OozeEval(@z)
let @z = z
endfunction
function! OozeMapKeys()
nnoremap <buffer> <localleader>C :call OozeConnect()<cr>
nnoremap <buffer> <localleader>K :call OozeDisconnect()<cr>
nnoremap <buffer> <localleader>E :call OozeEval(input("? "))<cr>
vnoremap <buffer> <localleader>e :<c-u>call OozeEvalSelection()<cr>
nnoremap <buffer> <localleader>e mz:silent normal! l<cr>:call PareditFindDefunBck()<cr>vab:<c-u>call OozeEvalSelection()<cr>`z
endfunction
augroup ooze_dev
au!
autocmd BufWritePost ooze.vim source %
augroup END