From 201ba55003ce9014bf7bb732b2b29e83547e09bb Mon Sep 17 00:00:00 2001 From: mboughaba Date: Sat, 9 Dec 2017 10:42:40 +0100 Subject: [PATCH 1/3] Open qf or loc only when results found fixes (#225) Ack opens quickfix also when no results found #225. When not used with Dispatch, we check if location list or quick fix list were populated with valid results before opening them. --- autoload/ack.vim | 13 ++++++++++++- doc/ack.txt | 3 +++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/autoload/ack.vim b/autoload/ack.vim index dbf84572..876292f4 100644 --- a/autoload/ack.vim +++ b/autoload/ack.vim @@ -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 "}}} @@ -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 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. From f718c42614a4429b1e72d9b9ad0c49d8c8f2dc20 Mon Sep 17 00:00:00 2001 From: mboughaba Date: Sat, 9 Dec 2017 10:51:20 +0100 Subject: [PATCH 2/3] Redraw only when results found --- autoload/ack.vim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/autoload/ack.vim b/autoload/ack.vim index 876292f4..b5a8d75e 100644 --- a/autoload/ack.vim +++ b/autoload/ack.vim @@ -104,7 +104,10 @@ function! ack#ShowResults() "{{{ echo "No results found." endif call s:ApplyMappings() - redraw! + " Redraw not needed when quickfix or locationlist were not opened. + if g:ack_use_dispatch || s:HasResults() + redraw! + endif endfunction "}}} "----------------------------------------------------------------------------- From fe9b22cd2b9f1ce1fa8dd9a17a55f1f0ee115473 Mon Sep 17 00:00:00 2001 From: mboughaba Date: Sat, 9 Dec 2017 10:54:22 +0100 Subject: [PATCH 3/3] Apply mappings only when results found --- autoload/ack.vim | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/autoload/ack.vim b/autoload/ack.vim index b5a8d75e..1cf5d7b8 100644 --- a/autoload/ack.vim +++ b/autoload/ack.vim @@ -100,14 +100,11 @@ function! ack#ShowResults() "{{{ " 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 - call s:ApplyMappings() - " Redraw not needed when quickfix or locationlist were not opened. - if g:ack_use_dispatch || s:HasResults() - redraw! - endif endfunction "}}} "-----------------------------------------------------------------------------