From e90aa61ca65e582c921c468f829a9f9d6fef05c0 Mon Sep 17 00:00:00 2001 From: Martin Grenfell Date: Fri, 16 Dec 2011 13:28:49 +0000 Subject: [PATCH] add Lclose() and use it when closing the loc list Lclose() acts as :lclose except that it checks the content of the location list and calls :lclose if it only contains syntastic data --- plugin/syntastic.vim | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/plugin/syntastic.vim b/plugin/syntastic.vim index b9c90bac..d8b7bb7f 100644 --- a/plugin/syntastic.vim +++ b/plugin/syntastic.vim @@ -91,7 +91,7 @@ augroup syntastic autocmd BufReadPost,BufWritePost * call s:UpdateErrors(1) autocmd BufWinEnter * if empty(&bt) | call s:AutoToggleLocList() | endif - autocmd BufWinLeave * if empty(&bt) | lclose | endif + autocmd BufWinLeave * if empty(&bt) | call s:Lclose() | endif augroup END @@ -123,20 +123,44 @@ function s:AutoToggleLocList() silent! ll endif elseif g:syntastic_auto_loc_list == 2 - lclose + call s:Lclose() endif if g:syntastic_auto_loc_list == 1 if s:BufHasErrorsOrWarningsToDisplay() call s:ShowLocList() else - "TODO: this will close the loc list window if one was opened by - "something other than syntastic - lclose + call s:Lclose() endif endif endfunction +"close the current loc list if it contains only syntastic data +" +"Note that we cant just compare the 2 lists since calling setloclist() adds +"some extra default data to the loclist +function! s:Lclose() + if !exists("b:syntastic_loclist") + return + endif + + let llist = getloclist(0) + + if len(llist) != len(b:syntastic_loclist) + return + endif + + "make sure the line number and message is the same for all elements" + for i in range(0,len(llist)-1) + if llist[i]['lnum'] != b:syntastic_loclist[i]['lnum'] || llist[i]['text'] != b:syntastic_loclist[i]['text'] + return + endif + endfor + + lclose +endfunction + + "detect and cache all syntax errors in this buffer " "depends on a function called SyntaxCheckers_{&ft}_GetLocList() existing