Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved quickfix handling with title #44

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 34 additions & 12 deletions autoload/grepper.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand All @@ -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 <silent><buffer> <cr> <cr>zv
nnoremap <silent><buffer> o <cr>zv
nnoremap <silent><buffer> O <cr>zv<c-w>p
nnoremap <silent><buffer> s :call <sid>open_entry('split', 1)<cr>
nnoremap <silent><buffer> S :call <sid>open_entry('split', 0)<cr>
nnoremap <silent><buffer> v :call <sid>open_entry('vsplit', 1)<cr>
nnoremap <silent><buffer> V :call <sid>open_entry('vsplit', 0)<cr>
nnoremap <silent><buffer> t <c-w>gFzv
nmap <silent><buffer> 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("\<c-w>p", 'n')
Expand All @@ -477,6 +479,26 @@ function! s:finish_up(flags) abort
silent doautocmd <nomodeline> 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 <silent><buffer> <cr> <cr>zv
nnoremap <silent><buffer> o <cr>zv
nnoremap <silent><buffer> O <cr>zv<c-w>p
nnoremap <silent><buffer> s :call <sid>open_entry('split', 1)<cr>
nnoremap <silent><buffer> S :call <sid>open_entry('split', 0)<cr>
nnoremap <silent><buffer> v :call <sid>open_entry('vsplit', 1)<cr>
nnoremap <silent><buffer> V :call <sid>open_entry('vsplit', 0)<cr>
nnoremap <silent><buffer> t <c-w>gFzv
nmap <silent><buffer> T tgT
endfunction

" s:open_entry() {{{1
function! s:open_entry(cmd, jump)
let swb = &switchbuf
Expand Down
5 changes: 5 additions & 0 deletions plugin/grepper.vim
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ for [cmd, tool] in cmds
\ 'Grepper -noprompt -tool' tool '-query <args>'
endif
endfor

augroup grepper
au!
autocmd FileType qf call grepper#on_qf()
augroup END
2 changes: 1 addition & 1 deletion test/feature/flags.vader
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down