make s:FilterLocList() work on s:LocList() by default

This commit is contained in:
Martin Grenfell 2011-12-16 16:57:06 +00:00
parent ec3ac50f76
commit 2385a0b581

View File

@ -247,7 +247,7 @@ function! s:BufHasErrorsOrWarningsToDisplay()
endfunction endfunction
function! s:ErrorsForType(type) function! s:ErrorsForType(type)
return s:FilterLocList(s:LocList(), {'type': a:type}) return s:FilterLocList({'type': a:type})
endfunction endfunction
function! s:Errors() function! s:Errors()
@ -258,16 +258,18 @@ function! s:Warnings()
return s:ErrorsForType("W") return s:ErrorsForType("W")
endfunction endfunction
"Filter a:llist by a:filters "Filter a loc list (defaults to s:LocList()) by a:filters
"e.g. "e.g.
" s:FilterLocList(list, {'bufnr': 10, 'type': 'e'}) " s:FilterLocList({'bufnr': 10, 'type': 'e'})
" "
"would return all errors for buffer 10. "would return all errors in s:LocList() for buffer 10.
" "
"Note that all comparisons are done with ==? "Note that all comparisons are done with ==?
function! s:FilterLocList(llist, filters) function! s:FilterLocList(filters, ...)
let rv = deepcopy(a:llist) let llist = a:0 ? a:1 : s:LocList()
for error in a:llist
let rv = deepcopy(llist)
for error in llist
for key in keys(a:filters) for key in keys(a:filters)
let rhs = a:filters[key] let rhs = a:filters[key]
if type(rhs) == 1 "string if type(rhs) == 1 "string
@ -296,7 +298,7 @@ let s:next_sign_id = s:first_sign_id
function! s:SignErrors() function! s:SignErrors()
if s:BufHasErrorsOrWarningsToDisplay() if s:BufHasErrorsOrWarningsToDisplay()
let errors = s:FilterLocList(s:LocList(), {'bufnr': bufnr('') }) let errors = s:FilterLocList({'bufnr': bufnr('')})
for i in errors for i in errors
let sign_type = 'SyntasticError' let sign_type = 'SyntasticError'
if i['type'] ==? 'W' if i['type'] ==? 'W'
@ -319,7 +321,7 @@ function! s:WarningMasksError(error, llist)
return 0 return 0
endif endif
return len(s:FilterLocList(a:llist, { 'type': "E", 'lnum': a:error['lnum'] })) > 0 return len(s:FilterLocList({ 'type': "E", 'lnum': a:error['lnum'] }, a:llist)) > 0
endfunction endfunction
"remove the signs with the given ids from this buffer "remove the signs with the given ids from this buffer
@ -412,8 +414,8 @@ endfunction
"echo out the first error we find for the current line in the cmd window "echo out the first error we find for the current line in the cmd window
function! s:EchoCurrentError() function! s:EchoCurrentError()
"If we have an error or warning at the current line, show it "If we have an error or warning at the current line, show it
let errors = s:FilterLocList(s:LocList(), {'lnum': line("."), "type": 'e'}) let errors = s:FilterLocList({'lnum': line("."), "type": 'e'})
let warnings = s:FilterLocList(s:LocList(), {'lnum': line("."), "type": 'w'}) let warnings = s:FilterLocList({'lnum': line("."), "type": 'w'})
let b:syntastic_echoing_error = len(errors) || len(warnings) let b:syntastic_echoing_error = len(errors) || len(warnings)
if len(errors) if len(errors)