From 5b57f378029753c084ba217eb73c3aa9d42b9f23 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Thu, 14 Feb 2013 00:12:45 -0500 Subject: [PATCH] Allow non-interactive :Connect Closes #46. --- doc/foreplay.txt | 5 +++-- plugin/foreplay.vim | 12 ++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/doc/foreplay.txt b/doc/foreplay.txt index 85f4283..c1f8bda 100644 --- a/doc/foreplay.txt +++ b/doc/foreplay.txt @@ -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. diff --git a/plugin/foreplay.vim b/plugin/foreplay.vim index b144d4d..c1de88c 100644 --- a/plugin/foreplay.vim +++ b/plugin/foreplay.vim @@ -170,7 +170,7 @@ endfunction " }}}1 " :Connect {{{1 -command! -bar -complete=customlist,s:connect_complete -nargs=? ForeplayConnect :exe s:Connect() +command! -bar -complete=customlist,s:connect_complete -nargs=* ForeplayConnect :exe s:Connect() 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 + autocmd FileType clojure command! -bar -complete=customlist,s:connect_complete -nargs=* Connect :ForeplayConnect augroup END " }}}1