# HG changeset patch # User Steve Losh # Date 1448973331 0 # Node ID d1d3411ab22eaec51533b36238273f710bac3c09 # Parent e7931486f06bc13ad3116dc2bc44732c14529251 Fireplace hackery for cl-nrepl diff -r e7931486f06b -r d1d3411ab22e .hgsubstate --- a/.hgsubstate Tue Dec 01 00:46:35 2015 +0000 +++ b/.hgsubstate Tue Dec 01 12:35:31 2015 +0000 @@ -12,7 +12,7 @@ c1646e3c28d75bcc834af4836f4c6e12296ba891 vim/bundle/ctrlp 38487bbec8ba50834e257940b357de03991fa8f9 vim/bundle/delimitmate ffbd5eb50c9daf67657b87fd767d1801ac9a15a7 vim/bundle/dispatch -86e03d6b632426399b666ec994307d7e07e91961 vim/bundle/fireplace +1c75b56ceb96a6e7fb6708ae96ab63b3023bab2f vim/bundle/fireplace 935a2cccd3065b1322fb2235285d42728600afdf vim/bundle/fugitive 6e9f52a160e3d15060848a8f453bd1b5bfa70db2 vim/bundle/gnupg 0d57b080f9fae8573c688b6679b31eb1666edc4c vim/bundle/gnuplot diff -r e7931486f06b -r d1d3411ab22e vim/after/plugin/fireplace-cl-nrepl.vim --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vim/after/plugin/fireplace-cl-nrepl.vim Tue Dec 01 12:35:31 2015 +0000 @@ -0,0 +1,133 @@ +" janky workaround from https://github.com/hylang/vim-hy/blob/master/after/plugin/fireplace.vim + +augroup fireplace_connect + autocmd FileType lisp command! -buffer -bar -nargs=* + \ Connect FireplaceConnect +augroup END + +function! s:set_up_eval() abort + command! -buffer -bang -range=0 -nargs=? Eval :exe s:Eval(0, , , , ) + command! -buffer -bar -nargs=1 -complete=customlist,fireplace#eval_complete Doc :exe s:Doc() + + nmap cp FireplacePrint + nmap cpp FireplaceCountPrint + + nmap cm FireplaceMacroExpand + nmap cmm FireplaceCountMacroExpand + + nmap cqp FireplacePrompt + + map! ( FireplaceRecall + + nmap K FireplaceK +endfunction + +if !exists('s:qffiles') + let s:qffiles = {} +endif + +function! s:buf() abort + if exists('s:input') + return s:input + elseif has_key(s:qffiles, expand('%:p')) + return s:qffiles[expand('%:p')].buffer + else + return '%' + endif +endfunction + +function! s:buffer_path(...) abort + let buffer = a:0 ? a:1 : s:buf() + if getbufvar(buffer, '&buftype') =~# '^no' + return '' + endif + let path = substitute(fnamemodify(bufname(buffer), ':p'), '\C^zipfile:\(.*\)::', '\1/', '') + for dir in fireplace#path(buffer) + if dir !=# '' && path[0 : strlen(dir)-1] ==# dir && path[strlen(dir)] =~# '[\/]' + return path[strlen(dir)+1:-1] + endif + endfor + return '' +endfunction + +function! s:Eval(bang, line1, line2, count, args) abort + let options = {} + if a:args !=# '' + let expr = a:args + else + if a:count ==# 0 + let open = '[[{(]' + let close = '[]})]' + let [line1, col1] = searchpairpos(open, '', close, 'bcrn', g:fireplace#skip) + let [line2, col2] = searchpairpos(open, '', close, 'rn', g:fireplace#skip) + if !line1 && !line2 + let [line1, col1] = searchpairpos(open, '', close, 'brn', g:fireplace#skip) + let [line2, col2] = searchpairpos(open, '', close, 'crn', g:fireplace#skip) + endif + while col1 > 1 && getline(line1)[col1-2] =~# '[#''`~@]' + let col1 -= 1 + endwhile + else + let line1 = a:line1 + let line2 = a:line2 + let col1 = 1 + let col2 = strlen(getline(line2)) + endif + if !line1 || !line2 + return '' + endif + let options.file_path = s:buffer_path() + let expr = repeat("\n", line1-1).repeat(" ", col1-1) + if line1 == line2 + let expr .= getline(line1)[col1-1 : col2-1] + else + let expr .= getline(line1)[col1-1 : -1] . "\n" + \ . join(map(getline(line1+1, line2-1), 'v:val . "\n"')) + \ . getline(line2)[0 : col2-1] + endif + if a:bang + exe line1.','.line2.'delete _' + endif + endif + if a:bang + try + let result = fireplace#session_eval(expr, options) + if a:args !=# '' + call append(a:line1, result) + exe a:line1 + else + call append(a:line1-1, result) + exe a:line1-1 + endif + catch /^Clojure:/ + endtry + else + call fireplace#echo_session_eval(expr, options) + endif + return '' +endfunction + +augroup fireplace_bindings + autocmd FileType lisp call s:set_up_eval() +augroup END + +function! s:Doc(symbol) abort + let info = fireplace#info(a:symbol) + if has_key(info, 'ns') && has_key(info, 'name') + echo info.ns . ' ' . info.name + elseif has_key(info, "name") + echo info.name + endif + if get(info, 'arglists-str', 'nil') !=# 'nil' + echo info['arglists-str'] + endif + if !empty(get(info, 'doc', '')) + echo "\n" . info.doc + endif + return '' +endfunction + +function! s:K() abort + let word = expand('') + return 'Doc '.word +endfunction