Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/notifiers'
Browse files Browse the repository at this point in the history
Conflicts:
	autoload/syntastic/util.vim
  • Loading branch information
scrooloose committed Apr 13, 2013
2 parents fbbb302 + 3083df5 commit a9938e0
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 34 deletions.
30 changes: 29 additions & 1 deletion autoload/syntastic/util.vim
Expand Up @@ -47,7 +47,7 @@ endfunction
" will be assumed to be '0' for the purposes of checking.
"
" See http://semver.org for info about version numbers.
function syntastic#util#versionIsAtLeast(installed, required)
function! syntastic#util#versionIsAtLeast(installed, required)
for index in [0,1,2]
if len(a:installed) <= index
let installed_element = 0
Expand Down Expand Up @@ -102,6 +102,34 @@ function! syntastic#util#debug(msg)
endif
endfunction

" Check whether a buffer is loaded, listed, and not hidden
function! syntastic#util#bufIsActive(buffer)
" convert to number, or hell breaks loose
let buf = str2nr(a:buffer)

if !bufloaded(buf) || !buflisted(buf)
return 0
endif

" get rid of hidden buffers
for tab in range(1, tabpagenr('$'))
if index(tabpagebuflist(tab), buf) >= 0
return 1
endif
endfor

return 0
endfunction

" List of buffers referenced by the location list
function! syntastic#util#unique(list)
let seen = {}
for e in a:list
let seen[e] = 1
endfor
return keys(seen)
endfunction

let &cpo = s:save_cpo
unlet s:save_cpo
" vim: set et sts=4 sw=4:
26 changes: 18 additions & 8 deletions plugin/syntastic.vim
Expand Up @@ -70,10 +70,22 @@ augroup syntastic
autocmd BufWritePost * call s:UpdateErrors(1)

autocmd BufWinEnter * if empty(&bt) | call g:SyntasticAutoloclistNotifier.AutoToggle(g:SyntasticLoclist.Current()) | endif
autocmd BufEnter * if &bt=='quickfix' && !empty(getloclist(0)) && !bufloaded(getloclist(0)[0].bufnr) | call g:SyntasticLoclist.Hide() | endif

" TODO: the next autocmd should be "autocmd BufWinLeave * if empty(&bt) | lclose | endif"
" but in recent versions of Vim lclose can no longer be called from BufWinLeave
autocmd BufEnter * call s:BufWinLeaveCleanup()
augroup END


function! s:BufWinLeaveCleanup()
" TODO: at this point there is no b:syntastic_loclist
let loclist = filter(getloclist(0), 'v:val["valid"] == 1')
let buffers = syntastic#util#unique(map( loclist, 'v:val["bufnr"]' ))
if &bt=='quickfix' && !empty(loclist) && empty(filter( buffers, 'syntastic#util#bufIsActive(v:val)' ))
call g:SyntasticLoclistHide()
endif
endfunction

"refresh and redraw all the error info for this buf when saving or reading
function! s:UpdateErrors(auto_invoked, ...)
if s:SkipFile()
Expand All @@ -88,16 +100,14 @@ function! s:UpdateErrors(auto_invoked, ...)
endif
end

call s:notifiers.refresh(g:SyntasticLoclist.Current())

let loclist = g:SyntasticLoclist.Current()
if g:syntastic_always_populate_loc_list && loclist.hasErrorsOrWarningsToDisplay()
call setloclist(0, loclist.filteredRaw())
endif
call s:notifiers.refresh(loclist)

if g:syntastic_auto_jump && loclist.hasErrorsOrWarningsToDisplay()
if (g:syntastic_always_populate_loc_list || g:syntastic_auto_jump) && loclist.hasErrorsOrWarningsToDisplay()
call setloclist(0, loclist.filteredRaw())
silent! ll
if g:syntastic_auto_jump
silent! ll
endif
endif
endfunction

Expand Down
4 changes: 0 additions & 4 deletions plugin/syntastic/autoloclist.vim
Expand Up @@ -16,10 +16,6 @@ function! g:SyntasticAutoloclistNotifier.New()
return newObj
endfunction

function! g:SyntasticAutoloclistNotifier.enabled()
return 1
endfunction

function! g:SyntasticAutoloclistNotifier.refresh(loclist)
call g:SyntasticAutoloclistNotifier.AutoToggle(a:loclist)
endfunction
Expand Down
5 changes: 1 addition & 4 deletions plugin/syntastic/cursor.vim
Expand Up @@ -17,10 +17,6 @@ function! g:SyntasticCursorNotifier.New()
return newObj
endfunction

function! g:SyntasticCursorNotifier.enabled()
return 1
endfunction

function! g:SyntasticCursorNotifier.refresh(loclist)
autocmd! syntastic CursorMoved
let enabled = exists('b:syntastic_echo_current_error') ? b:syntastic_echo_current_error : g:syntastic_echo_current_error
Expand All @@ -31,6 +27,7 @@ function! g:SyntasticCursorNotifier.refresh(loclist)
endfunction

function! g:SyntasticCursorNotifier.reset(loclist)
unlet! b:syntastic_messages
let b:oldLine = -1
endfunction

Expand Down
10 changes: 8 additions & 2 deletions plugin/syntastic/loclist.vim
Expand Up @@ -47,6 +47,10 @@ function! g:SyntasticLoclist.filteredRaw()
return copy(self._quietWarnings ? self.errors() : self._rawLoclist)
endfunction

function! g:SyntasticLoclist.quietWarnings()
return self._quietWarnings
endfunction

function! g:SyntasticLoclist.isEmpty()
return empty(self._rawLoclist)
endfunction
Expand Down Expand Up @@ -139,8 +143,10 @@ function! g:SyntasticLoclist.show()
endif
endfunction

function! g:SyntasticLoclist.Hide()
if len(filter( range(1,bufnr('$')), 'buflisted(v:val) && bufloaded(v:val)' )) == 1
" Non-method functions {{{1

function! g:SyntasticLoclistHide()
if len(filter( range(1, bufnr('$')), 'syntastic#util#bufIsActive(v:val)' )) == 1
quit
else
lclose
Expand Down
3 changes: 2 additions & 1 deletion plugin/syntastic/notifiers.vim
Expand Up @@ -25,7 +25,8 @@ endfunction

function! g:SyntasticNotifiers.refresh(loclist)
for type in self._enabled_types
if self._notifier[type].enabled()
let class = substitute(type, '.*', 'Syntastic\u&Notifier', '')
if !has_key(g:{class}, 'enabled') || self._notifier[type].enabled()
call self._notifier[type].refresh(a:loclist)
endif
endfor
Expand Down
4 changes: 4 additions & 0 deletions plugin/syntastic/registry.vim
Expand Up @@ -139,6 +139,10 @@ function! g:SyntasticRegistry._haveLoadedCheckers(filetype)
endfunction

function! g:SyntasticRegistry._userHasFiletypeSettings(filetype)
if exists("g:syntastic_" . a:filetype . "_checker") && !exists("g:syntastic_" . a:filetype . "_checkers")
let g:syntastic_{a:filetype}_checkers = [g:syntastic_{a:filetype}_checker]
echomsg "syntastic: warning: variable g:syntastic_" . a:filetype . "_checker is deprecated"
endif
return exists("b:syntastic_checkers") || exists("g:syntastic_" . a:filetype . "_checkers")
endfunction

Expand Down
22 changes: 8 additions & 14 deletions plugin/syntastic/signer.vim → plugin/syntastic/signs.vim
Expand Up @@ -103,24 +103,18 @@ function! g:SyntasticSignsNotifier._signErrors(loclist)
let loclist = a:loclist
if loclist.hasErrorsOrWarningsToDisplay()

let lfilter = {'bufnr': bufnr('')}
if g:syntastic_quiet_warnings
let lfilter['type'] = 'E'
endif
let errors = loclist.filter(lfilter)
let buf = bufnr('')
let errors = loclist.quietWarnings() ? [] : loclist.warnings()
call extend(errors, loclist.errors())
call filter(errors, 'v:val["bufnr"] == buf')

for i in errors
let sign_severity = 'Error'
let sign_subtype = ''
if has_key(i,'subtype')
let sign_subtype = i['subtype']
endif
if i['type'] ==? 'w'
let sign_severity = 'Warning'
endif
let sign_severity = i['type'] ==? 'w' ? 'Warning' : 'Error'
let sign_subtype = has_key(i,'subtype') ? i['subtype'] : ''
let sign_type = 'Syntastic' . sign_subtype . sign_severity

if !self._warningMasksError(i, errors)
exec "sign place ". s:next_sign_id ." line=". i['lnum'] ." name=". sign_type ." file=". expand("%:p")
exec "sign place " . s:next_sign_id . " line=" . i['lnum'] . " name=" . sign_type . " buffer=" . i['bufnr']
call add(self._bufSignIds(), s:next_sign_id)
let s:next_sign_id += 1
endif
Expand Down

0 comments on commit a9938e0

Please sign in to comment.