diff --git a/autoload/grepper.vim b/autoload/grepper.vim index 16b9891..5e3ce65 100644 --- a/autoload/grepper.vim +++ b/autoload/grepper.vim @@ -437,6 +437,16 @@ function! s:finish_up(flags) abort let qf = a:flags.quickfix let size = len(qf ? getqflist() : getloclist(0)) + let title = s:cmdline . ' [grepper]' + try + if qf + call setqflist(getqflist(), 'r', title) + else + call setloclist(0, getloclist(0), 'r', title) + endif + catch /E118/ + endtry + if size == 0 execute (qf ? 'cclose' : 'lclose') echo 'No matches found.' @@ -449,18 +459,10 @@ function! s:finish_up(flags) abort if a:flags.open execute (qf ? 'botright copen' : 'lopen') (size > 10 ? 10 : size) - let w:quickfix_title = s:cmdline - setlocal nowrap - - nnoremap zv - nnoremap o zv - nnoremap O zvp - nnoremap s :call open_entry('split', 1) - nnoremap S :call open_entry('split', 0) - nnoremap v :call open_entry('vsplit', 1) - nnoremap V :call open_entry('vsplit', 0) - nnoremap t gFzv - nmap T tgT + if get(w:, 'quickfix_title', '') != title + let w:quickfix_title = title + call grepper#on_qf(1) + endif if !a:flags.switch call feedkeys("\p", 'n') @@ -477,6 +479,26 @@ function! s:finish_up(flags) abort silent doautocmd User Grepper endfunction + +function! grepper#on_qf(...) + let force = a:0 ? a:1 : 0 + if !force && get(w:, 'quickfix_title', '') !~# '\m \[grepper\]$' + return + endif + + setlocal nowrap + + nnoremap zv + nnoremap o zv + nnoremap O zvp + nnoremap s :call open_entry('split', 1) + nnoremap S :call open_entry('split', 0) + nnoremap v :call open_entry('vsplit', 1) + nnoremap V :call open_entry('vsplit', 0) + nnoremap t gFzv + nmap T tgT +endfunction + " s:open_entry() {{{1 function! s:open_entry(cmd, jump) let swb = &switchbuf diff --git a/plugin/grepper.vim b/plugin/grepper.vim index 4db56aa..4aacbf8 100644 --- a/plugin/grepper.vim +++ b/plugin/grepper.vim @@ -23,3 +23,8 @@ for [cmd, tool] in cmds \ 'Grepper -noprompt -tool' tool '-query ' endif endfor + +augroup grepper + au! + autocmd FileType qf call grepper#on_qf() +augroup END diff --git a/test/feature/flags.vader b/test/feature/flags.vader index b5070a5..0e4e9d8 100644 --- a/test/feature/flags.vader +++ b/test/feature/flags.vader @@ -6,7 +6,7 @@ Execute (:Grepper -noprompt -tool ag -grepprg ag --column --nogroup -s Foo inclu Grepper -noprompt -tool ag -grepprg ag --column --nogroup -s Foo include AssertEqual len(getqflist()), 1 AssertEqual winnr('$'), 2 - AssertEqual w:quickfix_title, 'ag --column --nogroup -s Foo include ' + AssertEqual w:quickfix_title, 'ag --column --nogroup -s Foo include [grepper]' AssertEqual getline('.')[:6], 'include' Execute (:Grepper -noprompt -noswitch -tool ag -grepprg ag --column --nogroup -s Foo include):