1
0
mirror of https://github.com/amix/vimrc synced 2025-07-06 16:05:01 +08:00

prefinal close

This commit is contained in:
bood
2013-08-18 08:59:23 +02:00
parent 42f32196d3
commit b0798e23f8
144 changed files with 10091 additions and 121 deletions

View File

@ -0,0 +1,456 @@
"============================================================================
"File: syntastic.vim
"Description: Vim plugin for on the fly syntax checking.
"Version: 3.0.0
"Released On: 13 April, 2013
"License: This program is free software. It comes without any warranty,
" to the extent permitted by applicable law. You can redistribute
" it and/or modify it under the terms of the Do What The Fuck You
" Want To Public License, Version 2, as published by Sam Hocevar.
" See http://sam.zoy.org/wtfpl/COPYING for more details.
"
"============================================================================
if exists("g:loaded_syntastic_plugin")
finish
endif
let g:loaded_syntastic_plugin = 1
runtime! plugin/syntastic/*.vim
let s:running_windows = has("win16") || has("win32")
if !exists("g:syntastic_always_populate_loc_list")
let g:syntastic_always_populate_loc_list = 0
endif
if !exists("g:syntastic_auto_jump")
let g:syntastic_auto_jump = 0
endif
if !exists("g:syntastic_quiet_warnings")
let g:syntastic_quiet_warnings = 0
endif
if !exists("g:syntastic_stl_format")
let g:syntastic_stl_format = '[Syntax: line:%F (%t)]'
endif
if !exists("g:syntastic_check_on_open")
let g:syntastic_check_on_open = 0
endif
if !exists("g:syntastic_check_on_wq")
let g:syntastic_check_on_wq = 1
endif
if !exists("g:syntastic_aggregate_errors")
let g:syntastic_aggregate_errors = 0
endif
if !exists("g:syntastic_loc_list_height")
let g:syntastic_loc_list_height = 10
endif
if !exists("g:syntastic_ignore_files")
let g:syntastic_ignore_files = []
endif
if !exists("g:syntastic_filetype_map")
let g:syntastic_filetype_map = {}
endif
if !exists("g:syntastic_full_redraws")
let g:syntastic_full_redraws = !( has('gui_running') || has('gui_macvim'))
endif
" TODO: not documented
if !exists("g:syntastic_reuse_loc_lists")
" a relevant bug has been fixed in one of the pre-releases of Vim 7.4
let g:syntastic_reuse_loc_lists = (v:version >= 704)
endif
let s:registry = g:SyntasticRegistry.Instance()
let s:notifiers = g:SyntasticNotifiers.Instance()
let s:modemap = g:SyntasticModeMap.Instance()
function! s:CompleteCheckerName(argLead, cmdLine, cursorPos)
let checker_names = []
for ft in s:CurrentFiletypes()
for checker in s:registry.availableCheckersFor(ft)
call add(checker_names, checker.getName())
endfor
endfor
return join(checker_names, "\n")
endfunction
command! SyntasticToggleMode call s:ToggleMode()
command! -nargs=? -complete=custom,s:CompleteCheckerName SyntasticCheck call s:UpdateErrors(0, <f-args>) <bar> call s:Redraw()
command! Errors call s:ShowLocList()
command! SyntasticInfo call s:registry.echoInfoFor(s:CurrentFiletypes())
command! SyntasticReset call s:ClearCache() | call s:notifiers.refresh(g:SyntasticLoclist.New([]))
highlight link SyntasticError SpellBad
highlight link SyntasticWarning SpellCap
augroup syntastic
autocmd BufReadPost * if g:syntastic_check_on_open | call s:UpdateErrors(1) | endif
autocmd BufWritePost * call s:UpdateErrors(1)
autocmd BufWinEnter * call s:BufWinEnterHook()
" 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:BufEnterHook()
augroup END
if v:version > 703 || (v:version == 703 && has('patch544'))
" QuitPre was added in Vim 7.3.544
augroup syntastic
autocmd QuitPre * call s:QuitPreHook()
augroup END
endif
function! s:BufWinEnterHook()
if empty(&bt)
let loclist = g:SyntasticLoclist.current()
call s:notifiers.refresh(loclist)
endif
endfunction
function! s:BufEnterHook()
" 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
function! s:QuitPreHook()
let b:syntastic_skip_checks = !g:syntastic_check_on_wq
call g:SyntasticLoclistHide()
endfunction
"refresh and redraw all the error info for this buf when saving or reading
function! s:UpdateErrors(auto_invoked, ...)
if s:SkipFile()
return
endif
let run_checks = !a:auto_invoked || s:modemap.allowsAutoChecking(&filetype)
if run_checks
if a:0 >= 1
call s:CacheErrors(a:1)
else
call s:CacheErrors()
endif
end
let loclist = g:SyntasticLoclist.current()
let w:syntastic_loclist_set = 0
if g:syntastic_always_populate_loc_list || g:syntastic_auto_jump
call setloclist(0, loclist.filteredRaw())
let w:syntastic_loclist_set = 1
if run_checks && g:syntastic_auto_jump && loclist.hasErrorsOrWarningsToDisplay()
silent! lrewind
endif
endif
call s:notifiers.refresh(loclist)
endfunction
"clear the loc list for the buffer
function! s:ClearCache()
call s:notifiers.reset(g:SyntasticLoclist.current())
unlet! b:syntastic_loclist
endfunction
function! s:CurrentFiletypes()
return split(&filetype, '\.')
endfunction
"detect and cache all syntax errors in this buffer
function! s:CacheErrors(...)
call s:ClearCache()
let newLoclist = g:SyntasticLoclist.New([])
if !s:SkipFile()
let active_checkers = 0
let names = []
call syntastic#util#debug("CacheErrors: g:syntastic_aggregate_errors = " . g:syntastic_aggregate_errors)
if exists('b:syntastic_aggregate_errors')
call syntastic#util#debug("CacheErrors: b:syntastic_aggregate_errors = " . b:syntastic_aggregate_errors)
endif
for ft in s:CurrentFiletypes()
if a:0
let checker = s:registry.getChecker(ft, a:1)
let checkers = !empty(checker) ? [checker] : []
else
let checkers = s:registry.getActiveCheckers(ft)
endif
for checker in checkers
let active_checkers += 1
call syntastic#util#debug("CacheErrors: Invoking checker: " . checker.getName())
let loclist = checker.getLocList()
if !loclist.isEmpty()
let newLoclist = newLoclist.extend(loclist)
call add(names, [checker.getName(), checker.getFiletype()])
if !(exists('b:syntastic_aggregate_errors') ? b:syntastic_aggregate_errors : g:syntastic_aggregate_errors)
break
endif
endif
endfor
endfor
if !empty(names)
if len(syntastic#util#unique(map(copy(names), 'v:val[1]'))) == 1
let type = names[0][1]
let name = join(map(names, 'v:val[0]'), ', ')
call newLoclist.setName( name . ' ('. type . ')' )
else
" checkers from mixed types
call newLoclist.setName(join(map(names, 'v:val[1] . "/" . v:val[0]'), ', '))
endif
endif
if !active_checkers
if a:0
call syntastic#util#warn('checker ' . a:1 . ' is not active for filetype ' . &filetype)
else
call syntastic#util#debug('no active checkers for filetype ' . &filetype)
endif
endif
endif
let b:syntastic_loclist = newLoclist
endfunction
function! s:ToggleMode()
call s:modemap.toggleMode()
call s:ClearCache()
call s:UpdateErrors(1)
call s:modemap.echoMode()
endfunction
"display the cached errors for this buf in the location list
function! s:ShowLocList()
let loclist = g:SyntasticLoclist.current()
call loclist.show()
endfunction
"the script changes &shellredir and &shell to stop the screen flicking when
"shelling out to syntax checkers. Not all OSs support the hacks though
function! s:OSSupportsShellredirHack()
return !s:running_windows && executable('/bin/bash') && (s:uname() !~ "FreeBSD") && (s:uname() !~ "OpenBSD")
endfunction
function! s:IsRedrawRequiredAfterMake()
return !s:running_windows && (s:uname() =~ "FreeBSD" || s:uname() =~ "OpenBSD")
endfunction
"Redraw in a way that doesnt make the screen flicker or leave anomalies behind.
"
"Some terminal versions of vim require `redraw!` - otherwise there can be
"random anomalies left behind.
"
"However, on some versions of gvim using `redraw!` causes the screen to
"flicker - so use redraw.
function! s:Redraw()
if g:syntastic_full_redraws
redraw!
else
redraw
endif
endfunction
function! s:IgnoreFile(filename)
let fname = fnamemodify(a:filename, ':p')
for p in g:syntastic_ignore_files
if fname =~# p
return 1
endif
endfor
return 0
endfunction
" Skip running in special buffers
function! s:SkipFile()
let force_skip = exists('b:syntastic_skip_checks') ? b:syntastic_skip_checks : 0
let fname = expand('%')
return force_skip || !empty(&buftype) || !filereadable(fname) || getwinvar(0, '&diff') || s:IgnoreFile(fname)
endfunction
function! s:uname()
if !exists('s:uname')
let s:uname = system('uname')
endif
return s:uname
endfunction
"return a string representing the state of buffer according to
"g:syntastic_stl_format
"
"return '' if no errors are cached for the buffer
function! SyntasticStatuslineFlag()
let loclist = g:SyntasticLoclist.current()
let issues = loclist.filteredRaw()
let num_issues = loclist.getLength()
if loclist.hasErrorsOrWarningsToDisplay()
let errors = loclist.errors()
let warnings = loclist.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{\([^}]*\)}', num_errors ? '\1' : '' , 'g')
"hide stuff wrapped in %W(...) unless there are warnings
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{\([^}]*\)}', (num_warnings && num_errors) ? '\1' : '' , 'g')
"sub in the total errors/warnings/both
let output = substitute(output, '\C%w', num_warnings, 'g')
let output = substitute(output, '\C%e', num_errors, 'g')
let output = substitute(output, '\C%t', num_issues, 'g')
"first error/warning line num
let output = substitute(output, '\C%F', num_issues ? issues[0]['lnum'] : '', 'g')
"first error line num
let output = substitute(output, '\C%fe', num_errors ? errors[0]['lnum'] : '', 'g')
"first warning line num
let output = substitute(output, '\C%fw', num_warnings ? warnings[0]['lnum'] : '', 'g')
return output
else
return ''
endif
endfunction
"Emulates the :lmake command. Sets up the make environment according to the
"options given, runs make, resets the environment, returns the location list
"
"a:options can contain the following keys:
" 'makeprg'
" 'errorformat'
"
"The corresponding options are set for the duration of the function call. They
"are set with :let, so dont escape spaces.
"
"a:options may also contain:
" 'defaults' - a dict containing default values for the returned errors
" 'subtype' - all errors will be assigned the given subtype
" 'preprocess' - a function to be applied to the error file before parsing errors
" 'postprocess' - a list of functions to be applied to the error list
" 'cwd' - change directory to the given path before running the checker
" 'returns' - a list of valid exit codes for the checker
function! SyntasticMake(options)
call syntastic#util#debug('SyntasticMake: called with options: '. string(a:options))
let old_shell = &shell
let old_shellredir = &shellredir
let old_errorformat = &errorformat
let old_cwd = getcwd()
let old_lc_messages = $LC_MESSAGES
let old_lc_all = $LC_ALL
if s:OSSupportsShellredirHack()
"this is a hack to stop the screen needing to be ':redraw'n when
"when :lmake is run. Otherwise the screen flickers annoyingly
let &shellredir = '&>'
let &shell = '/bin/bash'
endif
if has_key(a:options, 'errorformat')
let &errorformat = a:options['errorformat']
endif
if has_key(a:options, 'cwd')
exec 'lcd ' . fnameescape(a:options['cwd'])
endif
let $LC_MESSAGES = 'C'
let $LC_ALL = ''
let err_lines = split(system(a:options['makeprg']), "\n", 1)
let $LC_ALL = old_lc_all
let $LC_MESSAGES = old_lc_messages
if has_key(a:options, 'preprocess')
let err_lines = call(a:options['preprocess'], [err_lines])
endif
lgetexpr err_lines
let errors = copy(getloclist(0))
if has_key(a:options, 'cwd')
exec 'lcd ' . fnameescape(old_cwd)
endif
silent! lolder
let &errorformat = old_errorformat
let &shellredir = old_shellredir
let &shell=old_shell
if s:IsRedrawRequiredAfterMake()
call s:Redraw()
endif
if has_key(a:options, 'returns') && index(a:options['returns'], v:shell_error) == -1
throw 'Syntastic: checker error'
endif
if has_key(a:options, 'defaults')
call SyntasticAddToErrors(errors, a:options['defaults'])
endif
" Apply ignore patterns
let ignore = {}
for buf in syntastic#util#unique(map(copy(errors), 'v:val["bufnr"]'))
let ignore[buf] = s:IgnoreFile(bufname(str2nr(buf)))
endfor
call filter(errors, '!ignore[v:val["bufnr"]]')
" Add subtype info if present.
if has_key(a:options, 'subtype')
call SyntasticAddToErrors(errors, {'subtype': a:options['subtype']})
endif
if has_key(a:options, 'postprocess') && !empty(a:options['postprocess'])
for rule in a:options['postprocess']
let errors = call('syntastic#postprocess#' . rule, [errors])
endfor
endif
return errors
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)
for key in keys(a:options)
if !has_key(a:errors[i], key) || empty(a:errors[i][key])
let a:errors[i][key] = a:options[key]
endif
endfor
endfor
return a:errors
endfunction
" vim: set et sts=4 sw=4:

View File

@ -0,0 +1,38 @@
if exists("g:loaded_syntastic_notifier_autoloclist")
finish
endif
let g:loaded_syntastic_notifier_autoloclist = 1
if !exists("g:syntastic_auto_loc_list")
let g:syntastic_auto_loc_list = 2
endif
let g:SyntasticAutoloclistNotifier = {}
" Public methods {{{1
"
function! g:SyntasticAutoloclistNotifier.New()
let newObj = copy(self)
return newObj
endfunction
function! g:SyntasticAutoloclistNotifier.refresh(loclist)
call g:SyntasticAutoloclistNotifier.AutoToggle(a:loclist)
endfunction
function! g:SyntasticAutoloclistNotifier.AutoToggle(loclist)
if a:loclist.hasErrorsOrWarningsToDisplay()
if g:syntastic_auto_loc_list == 1
call a:loclist.show()
endif
else
if g:syntastic_auto_loc_list > 0
"TODO: this will close the loc list window if one was opened by
"something other than syntastic
lclose
endif
endif
endfunction
" vim: set sw=4 sts=4 et fdm=marker:

View File

@ -0,0 +1,64 @@
if exists("g:loaded_syntastic_notifier_balloons")
finish
endif
let g:loaded_syntastic_notifier_balloons = 1
if !exists("g:syntastic_enable_balloons")
let g:syntastic_enable_balloons = 1
endif
if !has('balloon_eval')
let g:syntastic_enable_balloons = 0
endif
let g:SyntasticBalloonsNotifier = {}
" Public methods {{{1
function! g:SyntasticBalloonsNotifier.New()
let newObj = copy(self)
return newObj
endfunction
function! g:SyntasticBalloonsNotifier.enabled()
return
\ has('balloon_eval') &&
\ (exists('b:syntastic_enable_balloons') ? b:syntastic_enable_balloons : g:syntastic_enable_balloons)
endfunction
" Update the error balloons
function! g:SyntasticBalloonsNotifier.refresh(loclist)
let b:syntastic_balloons = {}
if self.enabled() && a:loclist.hasErrorsOrWarningsToDisplay()
let buf = bufnr('')
let issues = filter(a:loclist.filteredRaw(), 'v:val["bufnr"] == buf')
if !empty(issues)
for i in issues
if has_key(b:syntastic_balloons, i['lnum'])
let b:syntastic_balloons[i['lnum']] .= "\n" . i['text']
else
let b:syntastic_balloons[i['lnum']] = i['text']
endif
endfor
set beval bexpr=SyntasticBalloonsExprNotifier()
endif
endif
endfunction
" Reset the error balloons
function! g:SyntasticBalloonsNotifier.reset(loclist)
if has('balloon_eval')
set nobeval
endif
endfunction
" Private functions {{{1
function! SyntasticBalloonsExprNotifier()
if !exists('b:syntastic_balloons')
return ''
endif
return get(b:syntastic_balloons, v:beval_lnum, '')
endfunction
" vim: set sw=4 sts=4 et fdm=marker:

View File

@ -0,0 +1,79 @@
if exists("g:loaded_syntastic_checker")
finish
endif
let g:loaded_syntastic_checker = 1
let g:SyntasticChecker = {}
" Public methods {{{1
function! g:SyntasticChecker.New(args)
let newObj = copy(self)
let newObj._filetype = a:args['filetype']
let newObj._name = a:args['name']
let prefix = 'SyntaxCheckers_' . newObj._filetype . '_' . newObj._name . '_'
let newObj._locListFunc = function(prefix . 'GetLocList')
let newObj._isAvailableFunc = function(prefix . 'IsAvailable')
if exists('*' . prefix . 'GetHighlightRegex')
let newObj._highlightRegexFunc = function(prefix. 'GetHighlightRegex')
else
let newObj._highlightRegexFunc = ''
endif
return newObj
endfunction
function! g:SyntasticChecker.getFiletype()
return self._filetype
endfunction
function! g:SyntasticChecker.getName()
return self._name
endfunction
function! g:SyntasticChecker.getLocList()
try
let list = self._locListFunc()
call syntastic#util#debug('getLocList: checker ' . self._filetype . '/' . self._name . ' returned ' . v:shell_error)
catch /\m\C^Syntastic: checker error$/
let list = []
call syntastic#util#error('checker ' . self._filetype . '/' . self._name . ' returned abnormal status ' . v:shell_error)
endtry
call self._populateHighlightRegexes(list)
return g:SyntasticLoclist.New(list)
endfunction
function! g:SyntasticChecker.getHighlightRegexFor(error)
if empty(self._highlightRegexFunc)
return []
endif
return self._highlightRegexFunc(error)
endfunction
function! g:SyntasticChecker.isAvailable()
return self._isAvailableFunc()
endfunction
" Private methods {{{1
function! g:SyntasticChecker._populateHighlightRegexes(list)
let list = a:list
if !empty(self._highlightRegexFunc)
for i in range(0, len(list)-1)
if list[i]['valid']
let term = self._highlightRegexFunc(list[i])
if len(term) > 0
let list[i]['hl'] = term
endif
endif
endfor
endif
return list
endfunction
" vim: set sw=4 sts=4 et fdm=marker:

View File

@ -0,0 +1,63 @@
if exists("g:loaded_syntastic_notifier_cursor")
finish
endif
let g:loaded_syntastic_notifier_cursor = 1
if !exists('g:syntastic_echo_current_error')
let g:syntastic_echo_current_error = 1
endif
let g:SyntasticCursorNotifier = {}
" Public methods {{{1
function! g:SyntasticCursorNotifier.New()
let newObj = copy(self)
return newObj
endfunction
function! g:SyntasticCursorNotifier.enabled()
return exists('b:syntastic_echo_current_error') ? b:syntastic_echo_current_error : g:syntastic_echo_current_error
endfunction
function! g:SyntasticCursorNotifier.refresh(loclist)
if self.enabled() && a:loclist.hasErrorsOrWarningsToDisplay()
let b:syntastic_messages = copy(a:loclist.messages(bufnr('')))
let b:oldLine = -1
autocmd! syntastic CursorMoved
autocmd syntastic CursorMoved * call g:SyntasticRefreshCursor()
endif
endfunction
function! g:SyntasticCursorNotifier.reset(loclist)
autocmd! syntastic CursorMoved
unlet! b:syntastic_messages
let b:oldLine = -1
endfunction
" Private methods {{{1
" The following defensive nonsense is needed because of the nature of autocmd
function! g:SyntasticRefreshCursor()
if !exists('b:syntastic_messages') || empty(b:syntastic_messages)
" file not checked
return
endif
if !exists('b:oldLine')
let b:oldLine = -1
endif
let l = line('.')
if l == b:oldLine
return
endif
let b:oldLine = l
if has_key(b:syntastic_messages, l)
call syntastic#util#wideMsg(b:syntastic_messages[l])
else
echo
endif
endfunction
" vim: set sw=4 sts=4 et fdm=marker:

View File

@ -0,0 +1,66 @@
if exists("g:loaded_syntastic_notifier_highlighting")
finish
endif
let g:loaded_syntastic_notifier_highlighting = 1
" Highlighting requires getmatches introduced in 7.1.040
let s:has_highlighting = v:version > 701 || (v:version == 701 && has('patch040'))
if !exists("g:syntastic_enable_highlighting")
let g:syntastic_enable_highlighting = 1
endif
let g:SyntasticHighlightingNotifier = {}
" Public methods {{{1
function! g:SyntasticHighlightingNotifier.New()
let newObj = copy(self)
return newObj
endfunction
function! g:SyntasticHighlightingNotifier.enabled()
return
\ s:has_highlighting &&
\ (exists('b:syntastic_enable_highlighting') ? b:syntastic_enable_highlighting : g:syntastic_enable_highlighting)
endfunction
" Sets error highlights in the cuirrent window
function! g:SyntasticHighlightingNotifier.refresh(loclist)
if self.enabled()
call self.reset(a:loclist)
let buf = bufnr('')
let issues = filter(a:loclist.filteredRaw(), 'v:val["bufnr"] == buf')
for item in issues
let group = item['type'] == 'E' ? 'SyntasticError' : 'SyntasticWarning'
" The function `Syntastic_{filetype}_{checker}_GetHighlightRegex` is
" used to override default highlighting.
if has_key(item, 'hl')
call matchadd(group, '\%' . item['lnum'] . 'l' . item['hl'])
elseif get(item, 'col')
let lastcol = col([item['lnum'], '$'])
let lcol = min([lastcol, item['col']])
" a bug in vim can sometimes cause there to be no 'vcol' key,
" so check for its existence
let coltype = has_key(item, 'vcol') && item['vcol'] ? 'v' : 'c'
call matchadd(group, '\%' . item['lnum'] . 'l\%' . lcol . coltype)
endif
endfor
endif
endfunction
" Remove all error highlights from the window
function! g:SyntasticHighlightingNotifier.reset(loclist)
if s:has_highlighting
for match in getmatches()
if stridx(match['group'], 'Syntastic') == 0
call matchdelete(match['id'])
endif
endfor
endif
endfunction
" vim: set sw=4 sts=4 et fdm=marker:

View File

@ -0,0 +1,184 @@
if exists("g:loaded_syntastic_loclist")
finish
endif
let g:loaded_syntastic_loclist = 1
let g:SyntasticLoclist = {}
" Public methods {{{1
function! g:SyntasticLoclist.New(rawLoclist)
let newObj = copy(self)
let newObj._quietWarnings = g:syntastic_quiet_warnings
let llist = copy(a:rawLoclist)
let llist = filter(llist, 'v:val["valid"] == 1')
for e in llist
if empty(e['type'])
let e['type'] = 'E'
endif
endfor
let newObj._rawLoclist = llist
let newObj._hasErrorsOrWarningsToDisplay = -1
let newObj._name = ''
return newObj
endfunction
function! g:SyntasticLoclist.current()
if !exists("b:syntastic_loclist")
let b:syntastic_loclist = g:SyntasticLoclist.New([])
endif
return b:syntastic_loclist
endfunction
function! g:SyntasticLoclist.extend(other)
let list = self.toRaw()
call extend(list, a:other.toRaw())
return g:SyntasticLoclist.New(list)
endfunction
function! g:SyntasticLoclist.toRaw()
return copy(self._rawLoclist)
endfunction
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
function! g:SyntasticLoclist.getLength()
return len(self._rawLoclist)
endfunction
function! g:SyntasticLoclist.getName()
return len(self._name)
endfunction
function! g:SyntasticLoclist.setName(name)
let self._name = a:name
endfunction
function! g:SyntasticLoclist.hasErrorsOrWarningsToDisplay()
if self._hasErrorsOrWarningsToDisplay >= 0
return self._hasErrorsOrWarningsToDisplay
endif
let self._hasErrorsOrWarningsToDisplay = empty(self._rawLoclist) ? 0 : (!self._quietWarnings || len(self.errors()))
return self._hasErrorsOrWarningsToDisplay
endfunction
function! g:SyntasticLoclist.errors()
if !exists("self._cachedErrors")
let self._cachedErrors = self.filter({'type': "E"})
endif
return self._cachedErrors
endfunction
function! g:SyntasticLoclist.warnings()
if !exists("self._cachedWarnings")
let self._cachedWarnings = self.filter({'type': "W"})
endif
return self._cachedWarnings
endfunction
" cache used by EchoCurrentError()
function! g:SyntasticLoclist.messages(buf)
if !exists("self._cachedMessages")
let self._cachedMessages = {}
let errors = self.errors() + (self._quietWarnings ? [] : self.warnings())
for e in errors
let b = e['bufnr']
let l = e['lnum']
if !has_key(self._cachedMessages, b)
let self._cachedMessages[b] = {}
endif
if !has_key(self._cachedMessages[b], l)
let self._cachedMessages[b][l] = e['text']
endif
endfor
endif
return get(self._cachedMessages, a:buf, {})
endfunction
"Filter the list and return new native loclist
"e.g.
" .filter({'bufnr': 10, 'type': 'e'})
"
"would return all errors for buffer 10.
"
"Note that all comparisons are done with ==?
function! g:SyntasticLoclist.filter(filters)
let rv = []
for error in self._rawLoclist
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
"display the cached errors for this buf in the location list
function! g:SyntasticLoclist.show()
if !exists('w:syntastic_loclist_set')
let w:syntastic_loclist_set = 0
endif
call setloclist(0, self.filteredRaw(), g:syntastic_reuse_loc_lists && w:syntastic_loclist_set ? 'r' : ' ')
let w:syntastic_loclist_set = 1
if self.hasErrorsOrWarningsToDisplay()
let num = winnr()
exec "lopen " . g:syntastic_loc_list_height
if num != winnr()
wincmd p
endif
" try to find the loclist window and set w:quickfix_title
let errors = getloclist(0)
for buf in tabpagebuflist()
if buflisted(buf) && bufloaded(buf) && getbufvar(buf, '&buftype') ==# 'quickfix'
let win = bufwinnr(buf)
let title = getwinvar(win, 'quickfix_title')
" TODO: try to make sure we actually own this window; sadly,
" errors == getloclist(0) is the only somewhat safe way to
" achieve that
if strpart(title, 0, 16) ==# ':SyntasticCheck ' ||
\ ( (title == '' || title ==# ':setloclist()') && errors == getloclist(0) )
call setwinvar(win, 'quickfix_title', ':SyntasticCheck ' . self._name)
endif
endif
endfor
endif
endfunction
" Non-method functions {{{1
function! g:SyntasticLoclistHide()
silent! lclose
endfunction
" vim: set sw=4 sts=4 et fdm=marker:

View File

@ -0,0 +1,72 @@
if exists("g:loaded_syntastic_makeprg_builder")
finish
endif
let g:loaded_syntastic_makeprg_builder = 1
let g:SyntasticMakeprgBuilder = {}
" Public methods {{{1
function! g:SyntasticMakeprgBuilder.New(exe, args, fname, post_args, tail, filetype, subchecker)
let newObj = copy(self)
let newObj._exe = a:exe
let newObj._args = a:args
let newObj._fname = a:fname
let newObj._post_args = a:post_args
let newObj._tail = a:tail
let newObj._filetype = empty(a:filetype) ? &filetype : a:filetype
let newObj._subchecker = a:subchecker
return newObj
endfunction
function! g:SyntasticMakeprgBuilder.makeprg()
return join([self.exe(), self.args(), self.fname(), self.post_args(), self.tail()])
endfunction
function! g:SyntasticMakeprgBuilder.exe()
return self._getOpt('exe')
endfunction
function! g:SyntasticMakeprgBuilder.args()
return self._getOpt('args')
endfunction
function! g:SyntasticMakeprgBuilder.fname()
if empty(self._fname)
return syntastic#util#shexpand('%')
else
return self._fname
endif
endfunction
function! g:SyntasticMakeprgBuilder.post_args()
return self._getOpt('post_args')
endfunction
function! g:SyntasticMakeprgBuilder.tail()
return self._getOpt('tail')
endfunction
" Private methods {{{1
function g:SyntasticMakeprgBuilder._getOpt(name)
if self._optExists(a:name)
return {self._optName(a:name)}
endif
return self['_' . a:name]
endfunction
function! g:SyntasticMakeprgBuilder._optExists(name)
return exists(self._optName(a:name))
endfunction
function! g:SyntasticMakeprgBuilder._optName(name)
let setting = "g:syntastic_" . self._filetype
if !empty(self._subchecker)
let setting .= '_' . self._subchecker
endif
return setting . '_' . a:name
endfunction
" vim: set sw=4 sts=4 et fdm=marker:

View File

@ -0,0 +1,67 @@
if exists("g:loaded_syntastic_modemap")
finish
endif
let g:loaded_syntastic_modemap = 1
let g:SyntasticModeMap = {}
" Public methods {{{1
function! g:SyntasticModeMap.Instance()
if !exists('s:SyntasticModeMapInstance')
let s:SyntasticModeMapInstance = copy(self)
call s:SyntasticModeMapInstance._initModeMapFromGlobalOpts()
endif
return s:SyntasticModeMapInstance
endfunction
function! g:SyntasticModeMap.allowsAutoChecking(filetype)
let fts = split(a:filetype, '\.')
if self.isPassive()
return self._isOneFiletypeActive(fts)
else
return self._noFiletypesArePassive(fts)
endif
endfunction
function! g:SyntasticModeMap.isPassive()
return self._mode == "passive"
endfunction
function! g:SyntasticModeMap.toggleMode()
if self._mode == "active"
let self._mode = "passive"
else
let self._mode = "active"
endif
endfunction
function! g:SyntasticModeMap.echoMode()
echo "Syntastic: " . self._mode . " mode enabled"
endfunction
" Private methods {{{1
function! g:SyntasticModeMap._initModeMapFromGlobalOpts()
let self._mode = "active"
let self._activeFiletypes = []
let self._passiveFiletypes = []
if exists("g:syntastic_mode_map")
let self._mode = get(g:syntastic_mode_map, 'mode', self._mode)
let self._activeFiletypes = get(g:syntastic_mode_map, 'active_filetypes', self._activeFiletypes)
let self._passiveFiletypes = get(g:syntastic_mode_map, 'passive_filetypes', self._passiveFiletypes)
endif
endfunction
function! g:SyntasticModeMap._isOneFiletypeActive(filetypes)
return !empty(filter(a:filetypes, 'index(self._activeFiletypes, v:val) != -1'))
endfunction
function! g:SyntasticModeMap._noFiletypesArePassive(filetypes)
return empty(filter(a:filetypes, 'index(self._passiveFiletypes, v:val) != -1'))
endfunction
" vim: set sw=4 sts=4 et fdm=marker:

View File

@ -0,0 +1,55 @@
if exists("g:loaded_syntastic_notifiers")
finish
endif
let g:loaded_syntastic_notifiers = 1
let g:SyntasticNotifiers = {}
let s:notifier_types = ['signs', 'balloons', 'highlighting', 'cursor', 'autoloclist']
" Public methods {{{1
function! g:SyntasticNotifiers.Instance()
if !exists('s:SyntasticNotifiersInstance')
let s:SyntasticNotifiersInstance = copy(self)
call s:SyntasticNotifiersInstance._initNotifiers()
endif
return s:SyntasticNotifiersInstance
endfunction
function! g:SyntasticNotifiers.refresh(loclist)
for type in self._enabled_types
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
endfunction
function! g:SyntasticNotifiers.reset(loclist)
for type in self._enabled_types
let class = substitute(type, '.*', 'Syntastic\u&Notifier', '')
" reset notifiers regardless if they are enabled or not, since
" the user might have disabled them since the last refresh();
" notifiers MUST be prepared to deal with reset() when disabled
if has_key(g:{class}, 'reset')
call self._notifier[type].reset(a:loclist)
endif
endfor
endfunction
" Private methods {{{1
function! g:SyntasticNotifiers._initNotifiers()
let self._notifier = {}
for type in s:notifier_types
let class = substitute(type, '.*', 'Syntastic\u&Notifier', '')
let self._notifier[type] = g:{class}.New()
endfor
let self._enabled_types = copy(s:notifier_types)
endfunction
" vim: set sw=4 sts=4 et fdm=marker:

View File

@ -0,0 +1,213 @@
if exists("g:loaded_syntastic_registry")
finish
endif
let g:loaded_syntastic_registry = 1
let s:defaultCheckers = {
\ 'c': ['gcc'],
\ 'coffee': ['coffee', 'coffeelint'],
\ 'cpp': ['gcc'],
\ 'css': ['csslint', 'phpcs'],
\ 'go': ['go'],
\ 'html': ['tidy'],
\ 'java': ['javac'],
\ 'javascript': ['jshint', 'jslint'],
\ 'json': ['jsonlint', 'jsonval'],
\ 'objc': ['gcc'],
\ 'objcpp': ['gcc'],
\ 'perl': ['perl', 'perlcritic'],
\ 'php': ['php', 'phpcs', 'phpmd'],
\ 'puppet': ['puppet', 'puppetlint'],
\ 'python': ['python', 'flake8', 'pylint'],
\ 'ruby': ['mri'],
\ 'sh': ['sh'],
\ 'tex': ['lacheck']
\ }
let s:defaultFiletypeMap = {
\ 'gentoo-metadata': 'xml',
\ 'lhaskell': 'haskell'
\ }
let g:SyntasticRegistry = {}
" TODO: Handling of filetype aliases: all public methods take aliases as
" parameters, all private methods take normalized filetypes. Public methods
" are thus supposed to normalize filetypes before calling private methods.
" Public methods {{{1
function! g:SyntasticRegistry.Instance()
if !exists('s:SyntasticRegistryInstance')
let s:SyntasticRegistryInstance = copy(self)
let s:SyntasticRegistryInstance._checkerMap = {}
endif
return s:SyntasticRegistryInstance
endfunction
function! g:SyntasticRegistry.CreateAndRegisterChecker(args)
let checker = g:SyntasticChecker.New(a:args)
let registry = g:SyntasticRegistry.Instance()
call registry.registerChecker(checker)
endfunction
function! g:SyntasticRegistry.registerChecker(checker) abort
let ft = a:checker.getFiletype()
if !has_key(self._checkerMap, ft)
let self._checkerMap[ft] = []
endif
call self._validateUniqueName(a:checker)
call add(self._checkerMap[ft], a:checker)
endfunction
function! g:SyntasticRegistry.checkable(ftalias)
return !empty(self.getActiveCheckers(a:ftalias))
endfunction
function! g:SyntasticRegistry.getActiveCheckers(ftalias)
let filetype = s:SyntasticRegistryNormaliseFiletype(a:ftalias)
let checkers = self.availableCheckersFor(a:ftalias)
if self._userHasFiletypeSettings(filetype)
return self._filterCheckersByUserSettings(checkers, filetype)
endif
if has_key(s:defaultCheckers, filetype)
return self._filterCheckersByDefaultSettings(checkers, filetype)
endif
let checkers = self.availableCheckersFor(filetype)
if !empty(checkers)
return [checkers[0]]
endif
return []
endfunction
function! g:SyntasticRegistry.getChecker(ftalias, name)
for checker in self.availableCheckersFor(a:ftalias)
if checker.getName() == a:name
return checker
endif
endfor
return {}
endfunction
function! g:SyntasticRegistry.availableCheckersFor(ftalias)
let filetype = s:SyntasticRegistryNormaliseFiletype(a:ftalias)
let checkers = copy(self._allCheckersFor(filetype))
return self._filterCheckersByAvailability(checkers)
endfunction
function! g:SyntasticRegistry.echoInfoFor(ftalias_list)
echomsg "Syntastic info for filetype: " . join(a:ftalias_list, '.')
let available = []
let active = []
for ftalias in a:ftalias_list
call extend(available, self.availableCheckersFor(ftalias))
call extend(active, self.getActiveCheckers(ftalias))
endfor
echomsg "Available checkers: " . join(syntastic#util#unique(map(available, "v:val.getName()")))
echomsg "Currently active checker(s): " . join(syntastic#util#unique(map(active, "v:val.getName()")))
endfunction
" Private methods {{{1
function! g:SyntasticRegistry._allCheckersFor(filetype)
call self._loadCheckers(a:filetype)
if empty(self._checkerMap[a:filetype])
return []
endif
return self._checkerMap[a:filetype]
endfunction
function! g:SyntasticRegistry._filterCheckersByDefaultSettings(checkers, filetype)
if has_key(s:defaultCheckers, a:filetype)
return self._filterCheckersByName(a:checkers, s:defaultCheckers[a:filetype])
endif
return a:checkers
endfunction
function! g:SyntasticRegistry._filterCheckersByUserSettings(checkers, filetype)
if exists("b:syntastic_checkers")
let whitelist = b:syntastic_checkers
else
let whitelist = g:syntastic_{a:filetype}_checkers
endif
return self._filterCheckersByName(a:checkers, whitelist)
endfunction
function! g:SyntasticRegistry._filterCheckersByName(checkers, list)
let checkers_by_name = {}
for c in a:checkers
let checkers_by_name[c.getName()] = c
endfor
let filtered = []
for name in a:list
if has_key(checkers_by_name, name)
call add(filtered, checkers_by_name[name])
endif
endfor
return filtered
endfunction
function! g:SyntasticRegistry._filterCheckersByAvailability(checkers)
return filter(copy(a:checkers), "v:val.isAvailable()")
endfunction
function! g:SyntasticRegistry._loadCheckers(filetype)
if self._haveLoadedCheckers(a:filetype)
return
endif
exec "runtime! syntax_checkers/" . a:filetype . "/*.vim"
if !has_key(self._checkerMap, a:filetype)
let self._checkerMap[a:filetype] = []
endif
endfunction
function! g:SyntasticRegistry._haveLoadedCheckers(filetype)
return has_key(self._checkerMap, a: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]
call syntastic#util#deprecationWarn("variable g:syntastic_" . a:filetype . "_checker is deprecated")
endif
return exists("b:syntastic_checkers") || exists("g:syntastic_" . a:filetype . "_checkers")
endfunction
function! g:SyntasticRegistry._validateUniqueName(checker) abort
for checker in self._allCheckersFor(a:checker.getFiletype())
if checker.getName() == a:checker.getName()
throw "Syntastic: Duplicate syntax checker name for: " . a:checker.getName()
endif
endfor
endfunction
" Private functions {{{1
"resolve filetype aliases, and replace - with _ otherwise we cant name
"syntax checker functions legally for filetypes like "gentoo-metadata"
function! s:SyntasticRegistryNormaliseFiletype(ftalias)
let ft = get(s:defaultFiletypeMap, a:ftalias, a:ftalias)
let ft = get(g:syntastic_filetype_map, ft, ft)
let ft = substitute(ft, '-', '_', 'g')
return ft
endfunction
" vim: set sw=4 sts=4 et fdm=marker:

View File

@ -0,0 +1,149 @@
if exists("g:loaded_syntastic_notifier_signs")
finish
endif
let g:loaded_syntastic_notifier_signs = 1
if !exists("g:syntastic_enable_signs")
let g:syntastic_enable_signs = 1
endif
if !exists("g:syntastic_error_symbol")
let g:syntastic_error_symbol = '>>'
endif
if !exists("g:syntastic_warning_symbol")
let g:syntastic_warning_symbol = '>>'
endif
if !exists("g:syntastic_style_error_symbol")
let g:syntastic_style_error_symbol = 'S>'
endif
if !exists("g:syntastic_style_warning_symbol")
let g:syntastic_style_warning_symbol = 'S>'
endif
" start counting sign ids at 5000, start here to hopefully avoid conflicting
" with any other code that places signs (not sure if this precaution is
" actually needed)
let s:first_sign_id = 5000
let s:next_sign_id = s:first_sign_id
let g:SyntasticSignsNotifier = {}
let s:setup_done = 0
" Public methods {{{1
function! g:SyntasticSignsNotifier.New()
let newObj = copy(self)
if !s:setup_done
call self._setup()
let s:setup_done = 1
endif
return newObj
endfunction
function! g:SyntasticSignsNotifier.enabled()
return
\ has('signs') &&
\ exists('b:syntastic_enable_signs') ? b:syntastic_enable_signs : g:syntastic_enable_signs
endfunction
function! g:SyntasticSignsNotifier.refresh(loclist)
let old_signs = copy(self._bufSignIds())
if self.enabled()
call self._signErrors(a:loclist)
endif
call self._removeSigns(old_signs)
let s:first_sign_id = s:next_sign_id
endfunction
" Private methods {{{1
" One time setup: define our own sign types and highlighting
function! g:SyntasticSignsNotifier._setup()
if has('signs')
if !hlexists('SyntasticErrorSign')
highlight link SyntasticErrorSign error
endif
if !hlexists('SyntasticWarningSign')
highlight link SyntasticWarningSign todo
endif
if !hlexists('SyntasticStyleErrorSign')
highlight link SyntasticStyleErrorSign SyntasticErrorSign
endif
if !hlexists('SyntasticStyleWarningSign')
highlight link SyntasticStyleWarningSign SyntasticWarningSign
endif
if !hlexists('SyntasticStyleErrorLine')
highlight link SyntasticStyleErrorLine SyntasticErrorLine
endif
if !hlexists('SyntasticStyleWarningLine')
highlight link SyntasticStyleWarningLine SyntasticWarningLine
endif
" define the signs used to display syntax and style errors/warns
exe 'sign define SyntasticError text=' . g:syntastic_error_symbol .
\ ' texthl=SyntasticErrorSign linehl=SyntasticErrorLine'
exe 'sign define SyntasticWarning text=' . g:syntastic_warning_symbol .
\ ' texthl=SyntasticWarningSign linehl=SyntasticWarningLine'
exe 'sign define SyntasticStyleError text=' . g:syntastic_style_error_symbol .
\ ' texthl=SyntasticStyleErrorSign linehl=SyntasticStyleErrorLine'
exe 'sign define SyntasticStyleWarning text=' . g:syntastic_style_warning_symbol .
\ ' texthl=SyntasticStyleWarningSign linehl=SyntasticStyleWarningLine'
endif
endfunction
" Place signs by all syntax errors in the buffer
function! g:SyntasticSignsNotifier._signErrors(loclist)
let loclist = a:loclist
if loclist.hasErrorsOrWarningsToDisplay()
" errors some first, so that they are not masked by warnings
let buf = bufnr('')
let issues = copy(loclist.errors())
if !loclist.quietWarnings()
call extend(issues, loclist.warnings())
endif
call filter(issues, 'v:val["bufnr"] == buf')
let seen = {}
for i in issues
if !has_key(seen, i['lnum'])
let seen[i['lnum']] = 1
let sign_severity = i['type'] ==? 'W' ? 'Warning' : 'Error'
let sign_subtype = get(i, 'subtype', '')
let sign_type = 'Syntastic' . sign_subtype . sign_severity
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
endfor
endif
endfunction
" Remove the signs with the given ids from this buffer
function! g:SyntasticSignsNotifier._removeSigns(ids)
if has('signs')
for i in a:ids
exec "sign unplace " . i
call remove(self._bufSignIds(), index(self._bufSignIds(), i))
endfor
endif
endfunction
" Get all the ids of the SyntaxError signs in the buffer
function! g:SyntasticSignsNotifier._bufSignIds()
if !exists("b:syntastic_sign_ids")
let b:syntastic_sign_ids = []
endif
return b:syntastic_sign_ids
endfunction
" vim: set sw=4 sts=4 et fdm=marker: