Skip to content

Commit

Permalink
Open qf or loc only when results found fixes (mileszs#225)
Browse files Browse the repository at this point in the history
Ack opens quickfix also when no results found mileszs#225.
When not used with Dispatch, we check if location list or quick fix list were populated with valid results before opening them.
  • Loading branch information
mboughaba committed Dec 9, 2017
1 parent a16a9b6 commit 201ba55
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 12 additions & 1 deletion autoload/ack.vim
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ endfunction "}}}

function! ack#ShowResults() "{{{
let l:handler = s:UsingLocList() ? g:ack_lhandler : g:ack_qhandler
execute l:handler
" 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
else
echo "No results found."
endif
call s:ApplyMappings()
redraw!
endfunction "}}}
Expand All @@ -105,6 +111,11 @@ 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

0 comments on commit 201ba55

Please sign in to comment.