diff options
author | Teddy Wing | 2018-04-07 23:27:55 +0200 |
---|---|---|
committer | Teddy Wing | 2018-04-07 23:27:55 +0200 |
commit | 46bfc1021c9cecf3209c6f58428f73c5c2bc3b25 (patch) | |
tree | 021adef7707391042adeab3648f3faef0c391696 | |
parent | db6e5083d9f975c3b63ed8506dcedb0c900309b1 (diff) | |
download | vim-tabs-grep-46bfc1021c9cecf3209c6f58428f73c5c2bc3b25.tar.bz2 |
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.
-rw-r--r-- | plugin/tabs_grep.vim | 16 |
1 files 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(<f-args>) |