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:
parent
113bc5487f
commit
fe8277b42f
@ -1,4 +1,4 @@
|
|||||||
" classpath.vim - Manipulate the Java class path
|
" autoload/classpath.vim
|
||||||
" Maintainer: Tim Pope <http://tpo.pe>
|
" Maintainer: Tim Pope <http://tpo.pe>
|
||||||
|
|
||||||
if exists("g:autoloaded_classpath")
|
if exists("g:autoloaded_classpath")
|
||||||
|
23
plugin/classpath.vim
Normal file
23
plugin/classpath.vim
Normal 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:
|
@ -11,16 +11,8 @@ let g:loaded_foreplay = 1
|
|||||||
augroup foreplay_file_type
|
augroup foreplay_file_type
|
||||||
autocmd!
|
autocmd!
|
||||||
autocmd BufNewFile,BufReadPost *.clj setfiletype clojure
|
autocmd BufNewFile,BufReadPost *.clj setfiletype clojure
|
||||||
autocmd FileType clojure
|
|
||||||
\ if expand('%:p') !~# '^zipfile:' |
|
|
||||||
\ let &l:path = classpath#detect() |
|
|
||||||
\ endif
|
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
if &viminfo !~# '!'
|
|
||||||
set viminfo+=!
|
|
||||||
endif
|
|
||||||
|
|
||||||
" }}}1
|
" }}}1
|
||||||
" Escaping {{{1
|
" Escaping {{{1
|
||||||
|
|
||||||
@ -366,8 +358,11 @@ function! foreplay#local_client(...)
|
|||||||
return repl
|
return repl
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
let cp = classpath#from_vim(getbufvar(buf, '&path'))
|
if exists('*classpath#from_vim')
|
||||||
return extend({'classpath': cp}, s:oneoff)
|
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
|
endfunction
|
||||||
|
|
||||||
function! s:output_response(response) abort
|
function! s:output_response(response) abort
|
||||||
@ -393,9 +388,63 @@ function! s:eval(expr, ...) abort
|
|||||||
return client.eval(a:expr, options)
|
return client.eval(a:expr, options)
|
||||||
endfunction
|
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
|
function! foreplay#eval(expr) abort
|
||||||
let response = s:eval(a:expr, {'session': 1})
|
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)
|
call s:output_response(response)
|
||||||
|
|
||||||
if get(response, 'ex', '') !=# ''
|
if get(response, 'ex', '') !=# ''
|
||||||
@ -409,10 +458,25 @@ function! foreplay#eval(expr) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! foreplay#evalprint(expr) abort
|
function! foreplay#evalprint(expr) abort
|
||||||
try
|
let pwin = s:previewwindow()
|
||||||
echo foreplay#eval(a:expr)
|
if s:previewwindow()
|
||||||
catch /^Clojure:/
|
try
|
||||||
endtry
|
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 ''
|
return ''
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@ -817,11 +881,13 @@ function! s:buffer_path(...) abort
|
|||||||
return ''
|
return ''
|
||||||
endif
|
endif
|
||||||
let path = substitute(fnamemodify(bufname(buffer), ':p'), '\C^zipfile:\(.*\)::', '\1/', '')
|
let path = substitute(fnamemodify(bufname(buffer), ':p'), '\C^zipfile:\(.*\)::', '\1/', '')
|
||||||
for dir in classpath#split(classpath#from_vim(getbufvar(buffer, '&path')))
|
if exists('*classpath#from_vim')
|
||||||
if dir !=# '' && path[0 : strlen(dir)-1] ==# dir
|
for dir in classpath#split(classpath#from_vim(getbufvar(buffer, '&path')))
|
||||||
return path[strlen(dir)+1:-1]
|
if dir !=# '' && path[0 : strlen(dir)-1] ==# dir
|
||||||
endif
|
return path[strlen(dir)+1:-1]
|
||||||
endfor
|
endif
|
||||||
|
endfor
|
||||||
|
endif
|
||||||
return ''
|
return ''
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user