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

Open qf or loc only when results found fixes (#225) #230

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
17 changes: 14 additions & 3 deletions autoload/ack.vim
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,26 @@ endfunction "}}}

function! ack#ShowResults() "{{{
let l:handler = s:UsingLocList() ? g:ack_lhandler : g:ack_qhandler
execute l:handler
call s:ApplyMappings()
redraw!
" Dispatch has no callback mechanism currently, we just have to display the
" list window early and wait for it to populate :-/
if g:ack_use_dispatch || s:HasResults()
execute l:handler
call s:ApplyMappings()
redraw!
else
echo "No results found."
endif
endfunction "}}}

"-----------------------------------------------------------------------------
" Private API
"-----------------------------------------------------------------------------

function! s:HasResults() "{{{
let l:win_filtered_results = s:UsingLocList() ? len(filter(getloclist(0), 'v:val.valid')) : len(filter(getqflist(), 'v:val.valid'))
return l:win_filtered_results
endfunction "}}}

function! s:ApplyMappings() "{{{
if !s:UsingListMappings() || &filetype != 'qf'
return
Expand Down
3 changes: 3 additions & 0 deletions doc/ack.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ Files containing the search term will be listed in the split window, along
with the line number of the occurrence, once for each occurrence. <Enter> on
a line in this window will open the file, and place the cursor on the matching
line.
When no results are found, the location list or quick fix window won't be
displayed. Instead message "No results found." will be printed. Note, this doesn't
apply when using Dispatch.

Note that if you are using Dispatch.vim with |g:ack_use_dispatch|, location
lists are not supported, because Dispatch does not support them at this time.
Expand Down