From b978d9f0bebc2e50a68beafd80675c50253d0eca Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Thu, 5 Apr 2012 12:25:24 -0400 Subject: [PATCH] :Glgrep and :Gllog --- doc/fugitive.txt | 10 +++++++++- plugin/fugitive.vim | 18 ++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/doc/fugitive.txt b/doc/fugitive.txt index 2fd7793..3d95f65 100644 --- a/doc/fugitive.txt +++ b/doc/fugitive.txt @@ -69,12 +69,20 @@ that are part of Git repositories). *fugitive-:Ggrep* :Ggrep [args] |:grep| with git-grep as 'grepprg'. + *fugitive-:Glgrep* +:Glgrep [args] |:lgrep| with git-grep as 'grepprg'. + *fugitive-:Glog* :Glog [args] Load all previous revisions of the current file into the quickfix list. Additional git-log arguments can be given (for example, --reverse). If "--" appears as an argument, no file specific filtering is done, and - commits are loaded into the quickfix list. + previous commits rather than previous file revisions + are loaded. + + *fugitive-:Gllog* +:Gllog [args] Like |:Glog|, but use the location list instead of the + quickfix list. *fugitive-:Gedit* *fugitive-:Ge* :Gedit [revision] |:edit| a |fugitive-revision|. diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim index 1aeac25..174ca03 100644 --- a/plugin/fugitive.vim +++ b/plugin/fugitive.vim @@ -914,10 +914,12 @@ if !exists('g:fugitive_summary_format') let g:fugitive_summary_format = '%s' endif -call s:command("-bang -nargs=? -complete=customlist,s:EditComplete Ggrep :execute s:Grep(0,)") +call s:command("-bang -nargs=? -complete=customlist,s:EditComplete Ggrep :execute s:Grep('grep',0,)") +call s:command("-bang -nargs=? -complete=customlist,s:EditComplete Glgrep :execute s:Grep('lgrep',0,)") call s:command("-bar -bang -nargs=* -complete=customlist,s:EditComplete Glog :execute s:Log('grep',)") +call s:command("-bar -bang -nargs=* -complete=customlist,s:EditComplete Gllog :execute s:Log('lgrep',)") -function! s:Grep(bang,arg) abort +function! s:Grep(cmd,bang,arg) abort let grepprg = &grepprg let grepformat = &grepformat let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd ' @@ -926,8 +928,8 @@ 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! '.escape(matchstr(a:arg,'\v\C.{-}%($|[''" ]\@=\|)@='),'|') - let list = getqflist() + exe a:cmd.'! '.escape(matchstr(a:arg,'\v\C.{-}%($|[''" ]\@=\|)@='),'|') + let list = a:cmd =~# '^l' ? getloclist(0) : getqflist() for entry in list if bufname(entry.bufnr) =~ ':' let entry.filename = s:repo().translate(bufname(entry.bufnr)) @@ -937,9 +939,13 @@ function! s:Grep(bang,arg) abort unlet! entry.bufnr endif endfor - call setqflist(list,'r') + if a:cmd =~# '^l' + call setloclist(0, list, 'r') + else + setqflist(list, 'r') + endif if !a:bang && !empty(list) - return 'cfirst'.matchstr(a:arg,'\v\C[''" ]\zs\|.*') + return (a:cmd =~# '^l' ? 'l' : 'c').'first'.matchstr(a:arg,'\v\C[''" ]\zs\|.*') else return matchstr(a:arg,'\v\C[''" ]\|\zs.*') endif