From 46bfc1021c9cecf3209c6f58428f73c5c2bc3b25 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 7 Apr 2018 23:27:55 +0200 Subject: s:FilterTabPageElements(): Filter empty "Tab page X" elements This function now works the way I want it to, removing the "Tab page X" headers with no files under them from the `:tabs` list. We do this by building a list of indexes of those "Tab page X" elements and then removing them from the original list. The removal happens in reverse so we don't mess up the indexes by removing from left to right. --- plugin/tabs_grep.vim | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/plugin/tabs_grep.vim b/plugin/tabs_grep.vim index 70e7bce..2c8df4c 100644 --- a/plugin/tabs_grep.vim +++ b/plugin/tabs_grep.vim @@ -10,7 +10,7 @@ function! TabsGrep(search) call filter(tabs, function('s:MatchString', [a:search])) echo tabs - call s:FilterTabPageElements(tabs) + echo s:FilterTabPageElements(tabs) " let filtered_tabs = system( " \ 'echo ' @@ -57,17 +57,23 @@ function! s:FilterTabPageElements(list) " if last l == len l - 1 " delete last l - let filtered_tab_page_indexes = copy(tab_page_indexes) + let tab_page_indexes_to_remove = [] for i in range(1, len(tab_page_indexes) - 1) if tab_page_indexes[i - 1] == tab_page_indexes[i] - 1 - call remove(filtered_tab_page_indexes, i - 1) + call add(tab_page_indexes_to_remove, tab_page_indexes[i - 1]) endif endfor - if filtered_tab_page_indexes[-1] == len(a:list) - 1 - call remove(filtered_tab_page_indexes, -1) + if tab_page_indexes[-1] == len(a:list) - 1 + call add(tab_page_indexes_to_remove, tab_page_indexes[-1]) endif + + for i in reverse(tab_page_indexes_to_remove) + call remove(a:list, i) + endfor + + return a:list endfunction command! -nargs=1 TabsGrep :call TabsGrep() -- cgit v1.2.3