diff --git a/autoload/ack.vim b/autoload/ack.vim index dbf84572..1cf5d7b8 100644 --- a/autoload/ack.vim +++ b/autoload/ack.vim @@ -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 diff --git a/doc/ack.txt b/doc/ack.txt index 22e884bc..0c3bc6bc 100644 --- a/doc/ack.txt +++ b/doc/ack.txt @@ -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. 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.