# HG changeset patch # User Steve Losh # Date 1449683342 0 # Node ID 83aac563abc9d0116894ac61db2c63c9a05f72be # Parent 3d47932040eff915693dfcc6363f8be93b56e797 More work on Ooze diff -r 3d47932040ef -r 83aac563abc9 vim/bundle/ooze/plugin/ooze.vim --- a/vim/bundle/ooze/plugin/ooze.vim Wed Dec 09 14:40:25 2015 +0000 +++ b/vim/bundle/ooze/plugin/ooze.vim Wed Dec 09 17:49:02 2015 +0000 @@ -1,21 +1,56 @@ +" vim: set foldmethod=indent + 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 +function! s:GetString(msg, key, extra) + let val = get(a:msg, a:key) + if s:IsString(val) + return val . a:extra + else + return '' + endif +endfunction + +let g:ooze_scratch_buffer_name = '__OozeScratch__' +function! s:OpenOozeScratch(contents) + echom "test" + echom bufname('%') + if bufname('%') != g:ooze_scratch_buffer_name + wincmd s + execute "edit " . g:ooze_scratch_buffer_name endif - let stderr = get(a:msg, 'stderr') - if s:IsString(stderr) - echo stderr + set filetype=lisp + setlocal foldlevel=99 + setlocal buftype=nofile + setlocal bufhidden=hide + setlocal noswapfile + setlocal buflisted + + setlocal noreadonly + normal! ggdG + call append(0, a:contents) + setlocal readonly +endfunction + +function! s:HandleMessage(msg) + let moutput = s:GetString(a:msg, 'macroexpand-1', "") + if moutput != '' + call s:OpenOozeScratch(split(moutput, "\n")) + return endif - let value = get(a:msg, 'value') - if s:IsString(value) - echo value + let output = '' + let output .= s:GetString(a:msg, 'stdout', "") + let output .= s:GetString(a:msg, 'stdout', "") + let output .= s:GetString(a:msg, 'stderr', "") + let output .= s:GetString(a:msg, 'value', "") + let output .= s:GetString(a:msg, 'function-arglist', "\n\n") + let output .= s:GetString(a:msg, 'function-docstring', "\n") + if output != '' + echo output endif endfunction @@ -59,6 +94,36 @@ let g:ooze_connection = jobstart(['nc', 'localhost', '8675'], s:callbacks) endfunction +function! OozeMacroexpand(form) + if !g:ooze_connection + throw "Not connected!" + endif + let msg = {"op": "macroexpand", "form": a:form} + call jobsend(g:ooze_connection, bencode#Bencode(msg)) +endfunction + +function! OozeMacroexpandSelection() + let z = @z + normal! gv"zy + call OozeMacroexpand(@z) + let @z = z +endfunction + +function! OozeDocument(symbol) + if !g:ooze_connection + throw "Not connected!" + endif + let msg = {"op": "documentation", "symbol": a:symbol} + call jobsend(g:ooze_connection, bencode#Bencode(msg)) +endfunction + +function! OozeDocumentSelection() + let z = @z + normal! gv"zy + call OozeDocument(@z) + let @z = z +endfunction + function! OozeEval(code) if !g:ooze_connection throw "Not connected!" @@ -74,6 +139,18 @@ let @z = z endfunction +function! OozeLoad(path) + if !g:ooze_connection + throw "Not connected!" + endif + let msg = {"op": "load-file", "path": a:path} + call jobsend(g:ooze_connection, bencode#Bencode(msg)) +endfunction + +function! OozeLoadCurrent() + call OozeLoad(expand('%:p')) +endfunction + function! OozeMapKeys() nnoremap C :call OozeConnect() nnoremap K :call OozeDisconnect() @@ -81,6 +158,16 @@ nnoremap E :call OozeEval(input("? ")) vnoremap e :call OozeEvalSelection() nnoremap e mz:silent normal! l:call PareditFindDefunBck()vab:call OozeEvalSelection()`z + nnoremap f mzvab:call OozeEvalSelection()`z + + nnoremap D :call OozeDocument(input("? ")) + nnoremap d mzviw:call OozeDocumentSelection()`z + inoremap mzbviw:call OozeDocumentSelection()`za + + nnoremap M :call OozeMacroexpand(input("? ")) + nnoremap m mzvab:call OozeMacroexpandSelection()`z + + nnoremap r :call OozeLoadCurrent() endfunction augroup ooze_dev