motiejus/dotfiles

Unnamed repository; edit this file 'description' to name the repository.
git clone https://git.jakstys.lt/motiejus/dotfiles.git
Log | Tree | Refs | README | LICENSE

commit 56b8ad786b7cb0e49a7bcea76bedd8535caa1146 (tree)
parent 6b55a997a93cadc441dfe848d2b978f8779ef6cc
Author: Tim Pope <code@tpope.net>
Date:   Fri, 19 Mar 2010 19:59:08 -0400

Allow double quotes in :Git and :Ggrep arguments

:Git and :Ggrep were defined with the -bar flag, which enables chaining
(`:Ggrep foo | copen`) but also comments (`:Ggrep foo " find foo).  The
former is useful but the latter prevents one from using double quotes
with commands.  Instead, let's disable -bar and fake it in the
implementation.

:Git implements chaining in a way that's hopefully the same as the way
Vim itself chains.  :Ggrep is a little different; it only chains after a
quote or a space so that `:Ggrep -e 'foo|bar'|copen` works as one would
expect.

Diffstat:
Mplugin/fugitive.vim | 14++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim @@ -448,7 +448,7 @@ call s:add_methods('buffer',['getvar','setvar','getline','repo','type','name','c " }}}1 " Git {{{1 -call s:command("-bar -bang -nargs=? -complete=customlist,s:GitComplete Git :call s:Git(<bang>0,<q-args>)") +call s:command("-bang -nargs=? -complete=customlist,s:GitComplete Git :execute s:Git(<bang>0,<q-args>)") function! s:ExecuteInTree(cmd) abort let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd ' @@ -466,8 +466,10 @@ function! s:Git(bang,cmd) abort if has('gui_running') && !has('win32') let git .= ' --no-pager' endif - call s:ExecuteInTree('!'.git.' '.a:cmd) + let cmd = matchstr(a:cmd,'\v\C.{-}%($|\\@<!%(\\\\)*\|)@=') + call s:ExecuteInTree('!'.git.' '.cmd) call fugitive#reload_status() + return matchstr(a:cmd,'\v\C\\@<!%(\\\\)*\|\zs.*') endfunction function! s:GitComplete(A,L,P) abort @@ -738,7 +740,7 @@ if !exists('g:fugitive_summary_format') let g:fugitive_summary_format = '%s' endif -call s:command("-bar -bang -nargs=? -complete=customlist,s:EditComplete Ggrep :execute s:Grep(<bang>0,<q-args>)") +call s:command("-bang -nargs=? -complete=customlist,s:EditComplete Ggrep :execute s:Grep(<bang>0,<q-args>)") call s:command("-bar -bang -nargs=* -complete=customlist,s:EditComplete Glog :execute s:Log('grep<bang>',<f-args>)") function! s:Grep(bang,arg) abort @@ -750,7 +752,7 @@ function! s:Grep(bang,arg) abort execute cd.'`=s:repo().tree()`' let &grepprg = s:repo().git_command('--no-pager', 'grep', '-n') let &grepformat = '%f:%l:%m' - exe 'grep! '.a:arg + exe 'grep! '.escape(matchstr(a:arg,'\v\C.{-}%($|[''" ]\@=\|)@='),'|') let list = getqflist() for entry in list if bufname(entry.bufnr) =~ ':' @@ -763,9 +765,9 @@ function! s:Grep(bang,arg) abort endfor call setqflist(list,'r') if !a:bang && !empty(list) - return 'cfirst' + return 'cfirst'.matchstr(a:arg,'\v\C[''" ]\zs\|.*') else - return '' + return matchstr(a:arg,'\v\C[''" ]\|\zs.*') endif finally let &grepprg = grepprg