Extract classpath.vim to a separate plugin

Keeping it in the repository, for now.  Disable it with

	let g:no_foreplay_classpath = 1

This eliminates the startup delay at the cost of requiring a REPL to
evaluate code.

References #3.
This commit is contained in:
Tim Pope 2013-01-06 17:59:40 -05:00
parent 113bc5487f
commit fe8277b42f
3 changed files with 109 additions and 20 deletions

View File

@ -1,4 +1,4 @@
" classpath.vim - Manipulate the Java class path
" autoload/classpath.vim
" Maintainer: Tim Pope <http://tpo.pe>
if exists("g:autoloaded_classpath")

23
plugin/classpath.vim Normal file
View File

@ -0,0 +1,23 @@
" classpath.vim - Set 'path' from the Java class path
" Maintainer: Tim Pope <http://tpo.pe/>
if exists('g:no_foreplay_classpath') || exists("g:loaded_classpath") || v:version < 700 || &cp
finish
endif
let g:loaded_classpath = 1
if &viminfo !~# '!'
set viminfo+=!
endif
augroup classpath
autocmd!
autocmd FileType clojure
\ if expand('%:p') =~# '^zipfile:' |
\ let &l:path = getbufvar('#', '&path') |
\ else |
\ let &l:path = classpath#detect() |
\ endif
augroup END
" vim:set et sw=2:

View File

@ -11,16 +11,8 @@ let g:loaded_foreplay = 1
augroup foreplay_file_type
autocmd!
autocmd BufNewFile,BufReadPost *.clj setfiletype clojure
autocmd FileType clojure
\ if expand('%:p') !~# '^zipfile:' |
\ let &l:path = classpath#detect() |
\ endif
augroup END
if &viminfo !~# '!'
set viminfo+=!
endif
" }}}1
" Escaping {{{1
@ -366,8 +358,11 @@ function! foreplay#local_client(...)
return repl
endif
endfor
if exists('*classpath#from_vim')
let cp = classpath#from_vim(getbufvar(buf, '&path'))
return extend({'classpath': cp}, s:oneoff)
endif
throw ':Connect to a REPL or install classpath.vim to evaluate code'
endfunction
function! s:output_response(response) abort
@ -393,9 +388,63 @@ function! s:eval(expr, ...) abort
return client.eval(a:expr, options)
endfunction
function! s:temp_response(response) abort
let output = []
if get(a:response, 'out', '') !=# ''
let output = map(split(a:response.out, "\n"), '";".v:val')
endif
if has_key(a:response, 'value')
let output += [a:response.value]
endif
let temp = tempname().'.clj'
call writefile(output, temp)
return temp
endfunction
if !exists('s:history')
let s:history = []
endif
if !exists('s:qffiles')
let s:qffiles = {}
endif
function! s:qfentry(entry) abort
if !has_key(a:entry, 'tempfile')
let a:entry.tempfile = s:temp_response(a:entry.response)
endif
let s:qffiles[a:entry.tempfile] = a:entry
return {'filename': a:entry.tempfile, 'text': a:entry.code}
endfunction
function! s:qfhistory() abort
let list = []
for entry in s:history
if !has_key(entry, 'tempfile')
let entry.tempfile = s:temp_response(entry.response)
endif
call extend(list, [s:qfentry(entry)])
endfor
return list
endfunction
function! s:previewwindow()
for nr in range(1, winnr('$'))
if getwinvar(nr, '&previewwindow')
return nr
endif
endfor
endfunction
function! foreplay#eval(expr) abort
let response = s:eval(a:expr, {'session': 1})
call extend(s:history, [{'buffer': bufnr(''), 'code': a:expr, 'ns': foreplay#ns(), 'response': response}])
let pwin = s:previewwindow()
if pwin && has_key(s:qffiles, bufname(winbufnr(pwin)))
call setloclist(pwin, [s:qfentry(s:history[-1])], 'a')
endif
call s:output_response(response)
if get(response, 'ex', '') !=# ''
@ -409,10 +458,25 @@ function! foreplay#eval(expr) abort
endfunction
function! foreplay#evalprint(expr) abort
let pwin = s:previewwindow()
if s:previewwindow()
try
silent call foreplay#eval(a:expr)
catch /^Clojure:/
endtry
let nr = winnr()
wincmd p
wincmd P
call setloclist(pwin, s:qfhistory())
llast
wincmd p
exe nr.'wincmd w'
else
try
echo foreplay#eval(a:expr)
catch /^Clojure:/
endtry
endif
return ''
endfunction
@ -817,11 +881,13 @@ function! s:buffer_path(...) abort
return ''
endif
let path = substitute(fnamemodify(bufname(buffer), ':p'), '\C^zipfile:\(.*\)::', '\1/', '')
if exists('*classpath#from_vim')
for dir in classpath#split(classpath#from_vim(getbufvar(buffer, '&path')))
if dir !=# '' && path[0 : strlen(dir)-1] ==# dir
return path[strlen(dir)+1:-1]
endif
endfor
endif
return ''
endfunction