1
0
mirror of https://github.com/gryf/.vim.git synced 2025-12-18 03:50:30 +01:00

Plugins update

This commit is contained in:
2012-03-12 17:00:46 +01:00
parent c2500d764e
commit 7cbe6dca6d
37 changed files with 977 additions and 589 deletions

View File

@@ -127,6 +127,10 @@ function! s:UpdateErrors(auto_invoked)
call s:RefreshSigns()
endif
if g:syntastic_enable_highlighting
call s:HightlightErrors()
endif
if g:syntastic_auto_jump && s:BufHasErrorsOrWarningsToDisplay()
silent! ll
endif
@@ -160,8 +164,10 @@ function! s:LocList()
endfunction
"clear the loc list for the buffer
function! s:ClearLocList()
function! s:ClearCache()
let b:syntastic_loclist = []
unlet! b:syntastic_errors
unlet! b:syntastic_warnings
endfunction
"detect and cache all syntax errors in this buffer
@@ -169,7 +175,7 @@ endfunction
"depends on a function called SyntaxCheckers_{&ft}_GetLocList() existing
"elsewhere
function! s:CacheErrors()
call s:ClearLocList()
call s:ClearCache()
if filereadable(expand("%"))
@@ -195,7 +201,7 @@ function! s:ToggleMode()
let g:syntastic_mode_map['mode'] = "active"
endif
call s:ClearLocList()
call s:ClearCache()
call s:UpdateErrors(1)
echo "Syntastic: " . g:syntastic_mode_map['mode'] . " mode enabled"
@@ -217,30 +223,22 @@ function! s:ModeMapAllowsAutoChecking()
endif
endfunction
"return true if there are cached errors/warnings for this buf
function! s:BufHasErrorsOrWarnings()
return !empty(s:LocList())
endfunction
"return true if there are cached errors for this buf
function! s:BufHasErrors()
return len(s:ErrorsForType('E')) > 0
endfunction
function! s:BufHasErrorsOrWarningsToDisplay()
return s:BufHasErrors() || (!g:syntastic_quiet_warnings && s:BufHasErrorsOrWarnings())
endfunction
function! s:ErrorsForType(type)
return s:FilterLocList({'type': a:type})
return len(s:Errors()) || (!g:syntastic_quiet_warnings && !empty(s:LocList()))
endfunction
function! s:Errors()
return s:ErrorsForType("E")
if !exists("b:syntastic_errors")
let b:syntastic_errors = s:FilterLocList({'type': "E"})
endif
return b:syntastic_errors
endfunction
function! s:Warnings()
return s:ErrorsForType("W")
if !exists("b:syntastic_warnings")
let b:syntastic_warnings = s:FilterLocList({'type': "W"})
endif
return b:syntastic_warnings
endfunction
"Filter a loc list (defaults to s:LocList()) by a:filters
@@ -253,16 +251,21 @@ endfunction
function! s:FilterLocList(filters, ...)
let llist = a:0 ? a:1 : s:LocList()
let rv = deepcopy(llist)
for error in llist
for key in keys(a:filters)
let rhs = a:filters[key]
if type(rhs) == 1 "string
let rhs = '"' . rhs . '"'
endif
let rv = []
call filter(rv, "v:val['".key."'] ==? " . rhs)
for error in llist
let passes_filters = 1
for key in keys(a:filters)
if error[key] !=? a:filters[key]
let passes_filters = 0
break
endif
endfor
if passes_filters
call add(rv, error)
endif
endfor
return rv
endfunction
@@ -351,6 +354,43 @@ function! s:ShowLocList()
endif
endfunction
"highlight the current errors using matchadd()
"
"The function `Syntastic_{&ft}_GetHighlightRegex` is used to get the regex to
"highlight errors that do not have a 'col' key (and hence cant be done
"automatically). This function must take one arg (an error item) and return a
"regex to match that item in the buffer.
"
"If the 'force_highlight_callback' key is set for an error item, then invoke
"the callback even if it can be highlighted automatically.
function! s:HightlightErrors()
call s:ClearErrorHighlights()
let fts = substitute(&ft, '-', '_', 'g')
for ft in split(fts, '\.')
for item in s:LocList()
let force_callback = has_key(item, 'force_highlight_callback') && item['force_highlight_callback']
let group = item['type'] == 'E' ? 'SyntasticError' : 'SyntasticWarning'
if item['col'] && !force_callback
let lastcol = col([item['lnum'], '$'])
let lcol = min([lastcol, item['col']])
call matchadd(group, '\%'.item['lnum'].'l\%'.lcol.'c')
else
if exists("*SyntaxCheckers_". ft ."_GetHighlightRegex")
let term = SyntaxCheckers_{ft}_GetHighlightRegex(item)
if len(term) > 0
call matchadd(group, '\%' . item['lnum'] . 'l' . term)
endif
endif
endif
endfor
endfor
endfunction
"remove all error highlights from the window
function! s:ClearErrorHighlights()
for match in getmatches()
@@ -439,30 +479,33 @@ function! SyntasticStatuslineFlag()
let errors = s:Errors()
let warnings = s:Warnings()
let num_errors = len(errors)
let num_warnings = len(warnings)
let output = g:syntastic_stl_format
"hide stuff wrapped in %E(...) unless there are errors
let output = substitute(output, '\C%E{\([^}]*\)}', len(errors) ? '\1' : '' , 'g')
let output = substitute(output, '\C%E{\([^}]*\)}', num_errors ? '\1' : '' , 'g')
"hide stuff wrapped in %W(...) unless there are warnings
let output = substitute(output, '\C%W{\([^}]*\)}', len(warnings) ? '\1' : '' , 'g')
let output = substitute(output, '\C%W{\([^}]*\)}', num_warnings ? '\1' : '' , 'g')
"hide stuff wrapped in %B(...) unless there are both errors and warnings
let output = substitute(output, '\C%B{\([^}]*\)}', (len(warnings) && len(errors)) ? '\1' : '' , 'g')
let output = substitute(output, '\C%B{\([^}]*\)}', (num_warnings && num_errors) ? '\1' : '' , 'g')
"sub in the total errors/warnings/both
let output = substitute(output, '\C%w', len(warnings), 'g')
let output = substitute(output, '\C%e', len(errors), 'g')
let output = substitute(output, '\C%w', num_warnings, 'g')
let output = substitute(output, '\C%e', num_errors, 'g')
let output = substitute(output, '\C%t', len(s:LocList()), 'g')
"first error/warning line num
let output = substitute(output, '\C%F', s:LocList()[0]['lnum'], 'g')
"first error line num
let output = substitute(output, '\C%fe', len(errors) ? errors[0]['lnum'] : '', 'g')
let output = substitute(output, '\C%fe', num_errors ? errors[0]['lnum'] : '', 'g')
"first warning line num
let output = substitute(output, '\C%fw', len(warnings) ? warnings[0]['lnum'] : '', 'g')
let output = substitute(output, '\C%fw', num_warnings ? warnings[0]['lnum'] : '', 'g')
return output
else
@@ -539,37 +582,6 @@ function! SyntasticErrorBalloonExpr()
return get(b:syntastic_balloons, v:beval_lnum, '')
endfunction
"highlight the list of errors (a:errors) using matchadd()
"
"a:termfunc is provided to highlight errors that do not have a 'col' key (and
"hence cant be done automatically). This function must take one arg (an error
"item) and return a regex to match that item in the buffer.
"
"an optional boolean third argument can be provided to force a:termfunc to be
"used regardless of whether a 'col' key is present for the error
function! SyntasticHighlightErrors(errors, termfunc, ...)
if !g:syntastic_enable_highlighting
return
endif
call s:ClearErrorHighlights()
let force_callback = a:0 && a:1
for item in a:errors
let group = item['type'] == 'E' ? 'SyntasticError' : 'SyntasticWarning'
if item['col'] && !force_callback
let lastcol = col([item['lnum'], '$'])
let lcol = min([lastcol, item['col']])
call matchadd(group, '\%'.item['lnum'].'l\%'.lcol.'c')
else
let term = a:termfunc(item)
if len(term) > 0
call matchadd(group, '\%' . item['lnum'] . 'l' . term)
endif
endif
endfor
endfunction
"take a list of errors and add default values to them from a:options
function! SyntasticAddToErrors(errors, options)
for i in range(0, len(a:errors)-1)