From 6154582b68190e632922bb667e627a17f087a2ab Mon Sep 17 00:00:00 2001 From: Tiago Matias Date: Sat, 28 Oct 2017 14:37:19 -0200 Subject: [PATCH 1/3] check group in when toggling same ids --- autoload/go/guru.vim | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/autoload/go/guru.vim b/autoload/go/guru.vim index 6182a88758..69c652c242 100644 --- a/autoload/go/guru.vim +++ b/autoload/go/guru.vim @@ -548,11 +548,14 @@ function! go#guru#ClearSameIds() abort endfunction function! go#guru#ToggleSameIds() abort - if len(getmatches()) != 0 - call go#guru#ClearSameIds() - else - call go#guru#SameIds() - endif + let m = getmatches() + for item in m + if item['group'] == 'goSameId' + call go#guru#ClearSameIds() + return + endif + endfor + call go#guru#SameIds() endfunction function! go#guru#AutoToogleSameIds() abort From 216da44d1afc0d5f4212f0efaa0055caddb341ea Mon Sep 17 00:00:00 2001 From: Tiago Matias Date: Sat, 28 Oct 2017 17:47:48 -0200 Subject: [PATCH 2/3] let ClearSameIds return whether it cleared so we don't need to replicate its group check logic inside ToogleSameIds --- autoload/go/guru.vim | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/autoload/go/guru.vim b/autoload/go/guru.vim index 69c652c242..b698baa954 100644 --- a/autoload/go/guru.vim +++ b/autoload/go/guru.vim @@ -534,10 +534,13 @@ function! s:same_ids_highlight(exit_val, output) abort endfunction function! go#guru#ClearSameIds() abort + let l:cleared = 0 + let m = getmatches() for item in m if item['group'] == 'goSameId' call matchdelete(item['id']) + let l:cleared = 1 endif endfor @@ -545,17 +548,14 @@ function! go#guru#ClearSameIds() abort if exists("#BufWinEnter#") autocmd! BufWinEnter endif + + return cleared endfunction function! go#guru#ToggleSameIds() abort - let m = getmatches() - for item in m - if item['group'] == 'goSameId' - call go#guru#ClearSameIds() - return - endif - endfor - call go#guru#SameIds() + if !go#guru#ClearSameIds() + call go#guru#SameIds() + endif endfunction function! go#guru#AutoToogleSameIds() abort From 4f7091a516d7a10ba6942a856cbff23d4cbc03f5 Mon Sep 17 00:00:00 2001 From: Tiago Matias Date: Sat, 28 Oct 2017 18:32:57 -0200 Subject: [PATCH 3/3] return early with a negative value if didnt clear --- autoload/go/guru.vim | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/autoload/go/guru.vim b/autoload/go/guru.vim index b698baa954..10c8692472 100644 --- a/autoload/go/guru.vim +++ b/autoload/go/guru.vim @@ -534,26 +534,30 @@ function! s:same_ids_highlight(exit_val, output) abort endfunction function! go#guru#ClearSameIds() abort - let l:cleared = 0 + let l:cleared = -1 let m = getmatches() for item in m if item['group'] == 'goSameId' call matchdelete(item['id']) - let l:cleared = 1 + let l:cleared = 0 endif endfor + if l:cleared != 0 + return -1 + endif + " remove the autocmds we defined if exists("#BufWinEnter#") autocmd! BufWinEnter endif - return cleared + return 0 endfunction function! go#guru#ToggleSameIds() abort - if !go#guru#ClearSameIds() + if go#guru#ClearSameIds() != 0 call go#guru#SameIds() endif endfunction