Allow non-interactive :Connect

Closes #46.
This commit is contained in:
Tim Pope 2013-02-14 00:12:45 -05:00
parent 8d253a9fdf
commit 5b57f37802
2 changed files with 9 additions and 8 deletions

View File

@ -30,8 +30,9 @@ file is found, an nREPL connection will be established automatically.
CONNECTING TO A REPL *foreplay-connect*
*foreplay-:Connect*
:Connect {proto}://{host}:{port}
Connect to a REPL server.
:Connect {proto}://{host}:{port} {path}
Connect to a REPL server. The path is the root of the
project that the REPL applies to.
:Connect Interactively prompt for the options to connect to a
REPL server.

View File

@ -170,7 +170,7 @@ endfunction
" }}}1
" :Connect {{{1
command! -bar -complete=customlist,s:connect_complete -nargs=? ForeplayConnect :exe s:Connect(<q-args>)
command! -bar -complete=customlist,s:connect_complete -nargs=* ForeplayConnect :exe s:Connect(<f-args>)
function! foreplay#input_host_port()
let arg = input('Host> ', 'localhost')
@ -209,7 +209,7 @@ function! s:connect_complete(A, L, P)
return options
endfunction
function! s:Connect(arg)
function! s:Connect(arg, ...)
if a:arg =~# '^\w\+://'
let [proto, arg] = split(a:arg, '://')
elseif a:arg !=# ''
@ -239,16 +239,16 @@ function! s:Connect(arg)
let client = s:register_connection(connection)
echo 'Connected to '.proto.'://'.arg
let path = fnamemodify(exists('b:java_root') ? b:java_root : fnamemodify(expand('%'), ':p:s?.*\zs[\/]src[\/].*??'), ':~')
let root = input('Scope connection to: ', path, 'dir')
if root !=# ''
let s:repl_paths[fnamemodify(root, ':p:s?[\/]$??')] = client
let root = a:0 ? expand(a:1) : input('Scope connection to: ', path, 'dir')
if root !=# '' && root !=# '-'
let s:repl_paths[fnamemodify(root, ':p:s?.\zs[\/]$??')] = client
endif
return ''
endfunction
augroup foreplay_connect
autocmd!
autocmd FileType clojure command! -bar -complete=customlist,s:connect_complete -nargs=? Connect :ForeplayConnect <args>
autocmd FileType clojure command! -bar -complete=customlist,s:connect_complete -nargs=* Connect :ForeplayConnect <args>
augroup END
" }}}1