1
0
mirror of https://github.com/amix/vimrc synced 2025-07-09 10:45:00 +08:00

Added vim-commentary and updarted the plugins.

commentary:
Comment stuff out.  Use `gcc` to comment out a line (takes a count),
`gc` to comment out the target of a motion (for example, `gcap` to
comment out a paragraph), and `gc` in visual mode to comment out the
selection.  That's it.
This commit is contained in:
amix
2014-03-02 14:35:00 +00:00
parent 8c9210dca4
commit 0d8e7370bd
56 changed files with 1330 additions and 873 deletions

View File

@ -1,4 +1,4 @@
if exists("g:loaded_syntastic_c_autoload")
if exists("g:loaded_syntastic_c_autoload") || !exists("g:loaded_syntastic_plugin")
finish
endif
let g:loaded_syntastic_c_autoload = 1
@ -10,14 +10,14 @@ set cpo&vim
" convenience function to determine the 'null device' parameter
" based on the current operating system
function! syntastic#c#NullOutput()
function! syntastic#c#NullOutput() " {{{2
let known_os = has('unix') || has('mac') || syntastic#util#isRunningWindows()
return known_os ? '-o ' . syntastic#util#DevNull() : ''
endfunction
endfunction " }}}2
" read additional compiler flags from the given configuration file
" the file format and its parsing mechanism is inspired by clang_complete
function! syntastic#c#ReadConfig(file)
function! syntastic#c#ReadConfig(file) " {{{2
" search in the current file's directory upwards
let config = findfile(a:file, '.;')
if config == '' || !filereadable(config)
@ -30,7 +30,7 @@ function! syntastic#c#ReadConfig(file)
" try to read config file
try
let lines = readfile(config)
catch /^Vim\%((\a\+)\)\=:E48[45]/
catch /\m^Vim\%((\a\+)\)\=:E48[45]/
return ''
endtry
@ -57,12 +57,12 @@ function! syntastic#c#ReadConfig(file)
endfor
return join(map(parameters, 'syntastic#util#shescape(v:val)'))
endfunction
endfunction " }}}2
" GetLocList() for C-like compilers
function! syntastic#c#GetLocList(filetype, subchecker, options)
function! syntastic#c#GetLocList(filetype, subchecker, options) " {{{2
try
let flags = s:GetCflags(a:filetype, a:subchecker, a:options)
let flags = s:getCflags(a:filetype, a:subchecker, a:options)
catch /\m\C^Syntastic: skip checks$/
return []
endtry
@ -70,9 +70,9 @@ function! syntastic#c#GetLocList(filetype, subchecker, options)
let makeprg = syntastic#util#shexpand(g:syntastic_{a:filetype}_compiler) .
\ ' ' . flags . ' ' . syntastic#util#shexpand('%')
let errorformat = s:GetCheckerVar('g', a:filetype, a:subchecker, 'errorformat', a:options['errorformat'])
let errorformat = s:getCheckerVar('g', a:filetype, a:subchecker, 'errorformat', a:options['errorformat'])
let postprocess = s:GetCheckerVar('g', a:filetype, a:subchecker, 'remove_include_errors', 0) ?
let postprocess = s:getCheckerVar('g', a:filetype, a:subchecker, 'remove_include_errors', 0) ?
\ ['filterForeignErrors'] : []
" process makeprg
@ -80,34 +80,45 @@ function! syntastic#c#GetLocList(filetype, subchecker, options)
\ 'makeprg': makeprg,
\ 'errorformat': errorformat,
\ 'postprocess': postprocess })
endfunction
endfunction " }}}2
" }}}1
" Private functions {{{1
" initialize c/cpp syntax checker handlers
function! s:Init()
function! s:init() " {{{2
let s:handlers = []
let s:cflags = {}
call s:RegHandler('\m\<cairo', 'syntastic#c#CheckPKG', ['cairo', 'cairo'])
call s:RegHandler('\m\<freetype', 'syntastic#c#CheckPKG', ['freetype', 'freetype2', 'freetype'])
call s:RegHandler('\m\<glade', 'syntastic#c#CheckPKG', ['glade', 'libglade-2.0', 'libglade'])
call s:RegHandler('\m\<glib', 'syntastic#c#CheckPKG', ['glib', 'glib-2.0', 'glib'])
call s:RegHandler('\m\<gtk', 'syntastic#c#CheckPKG', ['gtk', 'gtk+-2.0', 'gtk+', 'glib-2.0', 'glib'])
call s:RegHandler('\m\<libsoup', 'syntastic#c#CheckPKG', ['libsoup', 'libsoup-2.4', 'libsoup-2.2'])
call s:RegHandler('\m\<libxml', 'syntastic#c#CheckPKG', ['libxml', 'libxml-2.0', 'libxml'])
call s:RegHandler('\m\<pango', 'syntastic#c#CheckPKG', ['pango', 'pango'])
call s:RegHandler('\m\<SDL', 'syntastic#c#CheckPKG', ['sdl', 'sdl'])
call s:RegHandler('\m\<opengl', 'syntastic#c#CheckPKG', ['opengl', 'gl'])
call s:RegHandler('\m\<webkit', 'syntastic#c#CheckPKG', ['webkit', 'webkit-1.0'])
call s:regHandler('\m\<cairo', 'syntastic#c#checkPKG', ['cairo', 'cairo'])
call s:regHandler('\m\<freetype', 'syntastic#c#checkPKG', ['freetype', 'freetype2', 'freetype'])
call s:regHandler('\m\<glade', 'syntastic#c#checkPKG', ['glade', 'libglade-2.0', 'libglade'])
call s:regHandler('\m\<glib', 'syntastic#c#checkPKG', ['glib', 'glib-2.0', 'glib'])
call s:regHandler('\m\<gtk', 'syntastic#c#checkPKG', ['gtk', 'gtk+-2.0', 'gtk+', 'glib-2.0', 'glib'])
call s:regHandler('\m\<libsoup', 'syntastic#c#checkPKG', ['libsoup', 'libsoup-2.4', 'libsoup-2.2'])
call s:regHandler('\m\<libxml', 'syntastic#c#checkPKG', ['libxml', 'libxml-2.0', 'libxml'])
call s:regHandler('\m\<pango', 'syntastic#c#checkPKG', ['pango', 'pango'])
call s:regHandler('\m\<SDL', 'syntastic#c#checkPKG', ['sdl', 'sdl'])
call s:regHandler('\m\<opengl', 'syntastic#c#checkPKG', ['opengl', 'gl'])
call s:regHandler('\m\<webkit', 'syntastic#c#checkPKG', ['webkit', 'webkit-1.0'])
call s:RegHandler('\m\<php\.h\>', 'syntastic#c#CheckPhp', [])
call s:RegHandler('\m\<Python\.h\>', 'syntastic#c#CheckPython', [])
call s:RegHandler('\m\<ruby', 'syntastic#c#CheckRuby', [])
endfunction
call s:regHandler('\m\<php\.h\>', 'syntastic#c#checkPHP', [])
call s:regHandler('\m\<Python\.h\>', 'syntastic#c#checkPython', [])
call s:regHandler('\m\<ruby', 'syntastic#c#checkRuby', [])
endfunction " }}}2
" return a handler dictionary object
function! s:regHandler(regex, function, args) " {{{2
let handler = {}
let handler["regex"] = a:regex
let handler["func"] = function(a:function)
let handler["args"] = a:args
call add(s:handlers, handler)
endfunction " }}}2
" resolve checker-related user variables
function! s:GetCheckerVar(scope, filetype, subchecker, name, default)
function! s:getCheckerVar(scope, filetype, subchecker, name, default) " {{{2
let prefix = a:scope . ':' . 'syntastic_'
if exists(prefix . a:filetype . '_' . a:subchecker . '_' . a:name)
return {a:scope}:syntastic_{a:filetype}_{a:subchecker}_{a:name}
@ -116,13 +127,13 @@ function! s:GetCheckerVar(scope, filetype, subchecker, name, default)
else
return a:default
endif
endfunction
endfunction " }}}2
" resolve user CFLAGS
function! s:GetCflags(ft, ck, opts)
function! s:getCflags(ft, ck, opts) " {{{2
" determine whether to parse header files as well
if has_key(a:opts, 'header_names') && expand('%') =~? a:opts['header_names']
if s:GetCheckerVar('g', a:ft, a:ck, 'check_header', 0)
if s:getCheckerVar('g', a:ft, a:ck, 'check_header', 0)
let flags = get(a:opts, 'header_flags', '') . ' -c ' . syntastic#c#NullOutput()
else
" checking headers when check_header is unset: bail out
@ -132,21 +143,21 @@ function! s:GetCflags(ft, ck, opts)
let flags = get(a:opts, 'main_flags', '')
endif
let flags .= ' ' . s:GetCheckerVar('g', a:ft, a:ck, 'compiler_options', '') . ' ' . s:GetIncludeDirs(a:ft)
let flags .= ' ' . s:getCheckerVar('g', a:ft, a:ck, 'compiler_options', '') . ' ' . s:getIncludeDirs(a:ft)
" check if the user manually set some cflags
let b_cflags = s:GetCheckerVar('b', a:ft, a:ck, 'cflags', '')
let b_cflags = s:getCheckerVar('b', a:ft, a:ck, 'cflags', '')
if b_cflags == ''
" check whether to search for include files at all
if !s:GetCheckerVar('g', a:ft, a:ck, 'no_include_search', 0)
if !s:getCheckerVar('g', a:ft, a:ck, 'no_include_search', 0)
if a:ft ==# 'c' || a:ft ==# 'cpp'
" refresh the include file search if desired
if s:GetCheckerVar('g', a:ft, a:ck, 'auto_refresh_includes', 0)
let flags .= ' ' . s:SearchHeaders()
if s:getCheckerVar('g', a:ft, a:ck, 'auto_refresh_includes', 0)
let flags .= ' ' . s:searchHeaders()
else
" search for header includes if not cached already
if !exists('b:syntastic_' . a:ft . '_includes')
let b:syntastic_{a:ft}_includes = s:SearchHeaders()
let b:syntastic_{a:ft}_includes = s:searchHeaders()
endif
let flags .= ' ' . b:syntastic_{a:ft}_includes
endif
@ -158,15 +169,15 @@ function! s:GetCflags(ft, ck, opts)
endif
" add optional config file parameters
let config_file = s:GetCheckerVar('g', a:ft, a:ck, 'config_file', '.syntastic_' . a:ft . '_config')
let config_file = s:getCheckerVar('g', a:ft, a:ck, 'config_file', '.syntastic_' . a:ft . '_config')
let flags .= ' ' . syntastic#c#ReadConfig(config_file)
return flags
endfunction
endfunction " }}}2
" get the gcc include directory argument depending on the default
" includes and the optional user-defined 'g:syntastic_c_include_dirs'
function! s:GetIncludeDirs(filetype)
function! s:getIncludeDirs(filetype) " {{{2
let include_dirs = []
if a:filetype =~# '\v^%(c|cpp|d|objc|objcpp)$' &&
@ -180,11 +191,11 @@ function! s:GetIncludeDirs(filetype)
endif
return join(map(syntastic#util#unique(include_dirs), 'syntastic#util#shescape("-I" . v:val)'))
endfunction
endfunction " }}}2
" search the first 100 lines for include statements that are
" given in the handlers dictionary
function! s:SearchHeaders()
function! s:searchHeaders() " {{{2
let includes = ''
let files = []
let found = []
@ -214,7 +225,7 @@ function! s:SearchHeaders()
try
let lines = readfile(filename, '', 100)
catch /^Vim\%((\a\+)\)\=:E484/
catch /\m^Vim\%((\a\+)\)\=:E484/
continue
endtry
@ -237,12 +248,12 @@ function! s:SearchHeaders()
endfor
return includes
endfunction
endfunction " }}}2
" try to find library with 'pkg-config'
" search possible libraries from first to last given
" argument until one is found
function! syntastic#c#CheckPKG(name, ...)
function! syntastic#c#checkPKG(name, ...) " {{{2
if executable('pkg-config')
if !has_key(s:cflags, a:name)
for pkg in a:000
@ -260,10 +271,10 @@ function! syntastic#c#CheckPKG(name, ...)
endif
endif
return ''
endfunction
endfunction " }}}2
" try to find PHP includes with 'php-config'
function! syntastic#c#CheckPhp()
function! syntastic#c#checkPHP() " {{{2
if executable('php-config')
if !has_key(s:cflags, 'php')
let s:cflags['php'] = system('php-config --includes')
@ -272,10 +283,10 @@ function! syntastic#c#CheckPhp()
return s:cflags['php']
endif
return ''
endfunction
endfunction " }}}2
" try to find the ruby headers with 'rbconfig'
function! syntastic#c#CheckRuby()
function! syntastic#c#checkRuby() " {{{2
if executable('ruby')
if !has_key(s:cflags, 'ruby')
let s:cflags['ruby'] = system('ruby -r rbconfig -e ' .
@ -286,10 +297,10 @@ function! syntastic#c#CheckRuby()
return s:cflags['ruby']
endif
return ''
endfunction
endfunction " }}}2
" try to find the python headers with distutils
function! syntastic#c#CheckPython()
function! syntastic#c#checkPython() " {{{2
if executable('python')
if !has_key(s:cflags, 'python')
let s:cflags['python'] = system('python -c ''from distutils import ' .
@ -300,16 +311,7 @@ function! syntastic#c#CheckPython()
return s:cflags['python']
endif
return ''
endfunction
" return a handler dictionary object
function! s:RegHandler(regex, function, args)
let handler = {}
let handler["regex"] = a:regex
let handler["func"] = function(a:function)
let handler["args"] = a:args
call add(s:handlers, handler)
endfunction
endfunction " }}}2
" }}}1
@ -322,9 +324,9 @@ let s:default_includes = [
\ '..' . syntastic#util#Slash() . 'include',
\ '..' . syntastic#util#Slash() . 'includes' ]
call s:Init()
call s:init()
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: set et sts=4 sw=4 fdm=marker:
" vim: set sw=4 sts=4 et fdm=marker:

View File

@ -1,4 +1,4 @@
if exists("g:loaded_syntastic_log_autoload")
if exists("g:loaded_syntastic_log_autoload") || !exists("g:loaded_syntastic_plugin")
finish
endif
let g:loaded_syntastic_log_autoload = 1
@ -6,67 +6,37 @@ let g:loaded_syntastic_log_autoload = 1
let s:save_cpo = &cpo
set cpo&vim
if !exists("g:syntastic_debug")
let g:syntastic_debug = 0
endif
let s:global_options = [
\ 'syntastic_aggregate_errors',
\ 'syntastic_always_populate_loc_list',
\ 'syntastic_auto_jump',
\ 'syntastic_auto_loc_list',
\ 'syntastic_check_on_open',
\ 'syntastic_check_on_wq',
\ 'syntastic_debug',
\ 'syntastic_echo_current_error',
\ 'syntastic_enable_balloons',
\ 'syntastic_enable_highlighting',
\ 'syntastic_enable_signs',
\ 'syntastic_error_symbol',
\ 'syntastic_filetype_map',
\ 'syntastic_full_redraws',
\ 'syntastic_id_checkers',
\ 'syntastic_ignore_files',
\ 'syntastic_loc_list_height',
\ 'syntastic_mode_map',
\ 'syntastic_quiet_messages',
\ 'syntastic_reuse_loc_lists',
\ 'syntastic_stl_format',
\ 'syntastic_style_error_symbol',
\ 'syntastic_style_warning_symbol',
\ 'syntastic_warning_symbol' ]
let s:deprecation_notices_issued = []
" Public functions {{{1
function! syntastic#log#info(msg)
function! syntastic#log#info(msg) " {{{2
echomsg "syntastic: info: " . a:msg
endfunction
endfunction " }}}2
function! syntastic#log#warn(msg)
function! syntastic#log#warn(msg) " {{{2
echohl WarningMsg
echomsg "syntastic: warning: " . a:msg
echohl None
endfunction
endfunction " }}}2
function! syntastic#log#error(msg)
function! syntastic#log#error(msg) " {{{2
execute "normal \<Esc>"
echohl ErrorMsg
echomsg "syntastic: error: " . a:msg
echohl None
endfunction
endfunction " }}}2
function! syntastic#log#deprecationWarn(msg)
function! syntastic#log#deprecationWarn(msg) " {{{2
if index(s:deprecation_notices_issued, a:msg) >= 0
return
endif
call add(s:deprecation_notices_issued, a:msg)
call syntastic#log#warn(a:msg)
endfunction
endfunction " }}}2
function! syntastic#log#debug(level, msg, ...)
function! syntastic#log#debug(level, msg, ...) " {{{2
if !s:isDebugEnabled(a:level)
return
endif
@ -84,9 +54,9 @@ function! syntastic#log#debug(level, msg, ...)
endif
call s:logRedirect(0)
endfunction
endfunction " }}}2
function! syntastic#log#debugShowOptions(level, names)
function! syntastic#log#debugShowOptions(level, names) " {{{2
if !s:isDebugEnabled(a:level)
return
endif
@ -94,15 +64,15 @@ function! syntastic#log#debugShowOptions(level, names)
let leader = s:logTimestamp()
call s:logRedirect(1)
let vlist = type(a:names) == type("") ? [a:names] : a:names
let vlist = copy(type(a:names) == type("") ? [a:names] : a:names)
if !empty(vlist)
call map(copy(vlist), "'&' . v:val . ' = ' . strtrans(string(eval('&' . v:val)))")
call map(vlist, "'&' . v:val . ' = ' . strtrans(string(eval('&' . v:val)))")
echomsg leader . join(vlist, ', ')
endif
call s:logRedirect(0)
endfunction
endfunction " }}}2
function! syntastic#log#debugShowVariables(level, names)
function! syntastic#log#debugShowVariables(level, names) " {{{2
if !s:isDebugEnabled(a:level)
return
endif
@ -112,39 +82,44 @@ function! syntastic#log#debugShowVariables(level, names)
let vlist = type(a:names) == type("") ? [a:names] : a:names
for name in vlist
echomsg leader . s:formatVariable(name)
let msg = s:formatVariable(name)
if msg != ''
echomsg leader . msg
endif
endfor
call s:logRedirect(0)
endfunction
endfunction " }}}2
function! syntastic#log#debugDump(level)
function! syntastic#log#debugDump(level) " {{{2
if !s:isDebugEnabled(a:level)
return
endif
call syntastic#log#debugShowVariables(a:level, s:global_options)
endfunction
call syntastic#log#debugShowVariables( a:level, sort(keys(g:syntastic_defaults)) )
endfunction " }}}2
" }}}1
" Private functions {{{1
function! s:isDebugEnabled_smart(level)
function! s:isDebugEnabled_smart(level) " {{{2
return and(g:syntastic_debug, a:level)
endfunction
endfunction " }}}2
function! s:isDebugEnabled_dumb(level)
function! s:isDebugEnabled_dumb(level) " {{{2
" poor man's bit test for bit N, assuming a:level == 2**N
return (g:syntastic_debug / a:level) % 2
endfunction
endfunction " }}}2
let s:isDebugEnabled = function(exists('*and') ? 's:isDebugEnabled_smart' : 's:isDebugEnabled_dumb')
function! s:logRedirect(on)
function! s:logRedirect(on) " {{{2
if exists("g:syntastic_debug_file")
if a:on
try
execute 'redir >> ' . fnameescape(expand(g:syntastic_debug_file))
catch /^Vim\%((\a\+)\)\=:/
catch /\m^Vim\%((\a\+)\)\=:/
silent! redir END
unlet g:syntastic_debug_file
endtry
@ -152,30 +127,33 @@ function! s:logRedirect(on)
silent! redir END
endif
endif
endfunction
endfunction " }}}2
function! s:logTimestamp_smart()
function! s:logTimestamp_smart() " {{{2
return 'syntastic: ' . split(reltimestr(reltime(g:syntastic_start)))[0] . ': '
endfunction
endfunction " }}}2
function! s:logTimestamp_dumb()
function! s:logTimestamp_dumb() " {{{2
return 'syntastic: debug: '
endfunction
endfunction " }}}2
let s:logTimestamp = function(has('reltime') ? 's:logTimestamp_smart' : 's:logTimestamp_dumb')
function! s:formatVariable(name)
function! s:formatVariable(name) " {{{2
let vals = []
if exists('g:' . a:name)
call add(vals, 'g:' . a:name . ' = ' . strtrans(string(g:{a:name})))
if exists('g:syntastic_' . a:name)
call add(vals, 'g:syntastic_' . a:name . ' = ' . strtrans(string(g:syntastic_{a:name})))
endif
if exists('b:' . a:name)
call add(vals, 'b:' . a:name . ' = ' . strtrans(string(b:{a:name})))
if exists('b:syntastic_' . a:name)
call add(vals, 'b:syntastic_' . a:name . ' = ' . strtrans(string(b:syntastic_{a:name})))
endif
return join(vals, ', ')
endfunction
endfunction " }}}2
" }}}1
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: set et sts=4 sw=4 fdm=marker:
" vim: set sw=4 sts=4 et fdm=marker:

View File

@ -1,4 +1,4 @@
if exists("g:loaded_syntastic_postprocess_autoload")
if exists("g:loaded_syntastic_postprocess_autoload") || !exists("g:loaded_syntastic_plugin")
finish
endif
let g:loaded_syntastic_postprocess_autoload = 1
@ -6,7 +6,9 @@ let g:loaded_syntastic_postprocess_autoload = 1
let s:save_cpo = &cpo
set cpo&vim
function! s:compareErrorItems(a, b)
" Public functions {{{1
function! s:compareErrorItems(a, b) " {{{2
if a:a['bufnr'] != a:b['bufnr']
" group by files
return a:a['bufnr'] - a:b['bufnr']
@ -18,15 +20,15 @@ function! s:compareErrorItems(a, b)
else
return get(a:a, 'col', 0) - get(a:b, 'col', 0)
endif
endfunction
endfunction " }}}2
" natural sort
function! syntastic#postprocess#sort(errors)
function! syntastic#postprocess#sort(errors) " {{{2
return sort(copy(a:errors), 's:compareErrorItems')
endfunction
endfunction " }}}2
" merge consecutive blanks
function! syntastic#postprocess#compressWhitespace(errors)
function! syntastic#postprocess#compressWhitespace(errors) " {{{2
for e in a:errors
let e['text'] = substitute(e['text'], "\001", '', 'g')
let e['text'] = substitute(e['text'], '\n', ' ', 'g')
@ -34,10 +36,10 @@ function! syntastic#postprocess#compressWhitespace(errors)
endfor
return a:errors
endfunction
endfunction " }}}2
" remove spurious CR under Cygwin
function! syntastic#postprocess#cygwinRemoveCR(errors)
function! syntastic#postprocess#cygwinRemoveCR(errors) " {{{2
if has('win32unix')
for e in a:errors
let e['text'] = substitute(e['text'], '\r', '', 'g')
@ -45,23 +47,25 @@ function! syntastic#postprocess#cygwinRemoveCR(errors)
endif
return a:errors
endfunction
endfunction " }}}2
" decode XML entities
function! syntastic#postprocess#decodeXMLEntities(errors)
function! syntastic#postprocess#decodeXMLEntities(errors) " {{{2
for e in a:errors
let e['text'] = syntastic#util#decodeXMLEntities(e['text'])
endfor
return a:errors
endfunction
endfunction " }}}2
" filter out errors referencing other files
function! syntastic#postprocess#filterForeignErrors(errors)
function! syntastic#postprocess#filterForeignErrors(errors) " {{{2
return filter(copy(a:errors), 'get(v:val, "bufnr") == ' . bufnr(''))
endfunction
endfunction " }}}2
" }}}1
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: set et sts=4 sw=4:
" vim: set sw=4 sts=4 et fdm=marker:

View File

@ -0,0 +1,79 @@
if exists("g:loaded_syntastic_preprocess_autoload") || !exists("g:loaded_syntastic_plugin")
finish
endif
let g:loaded_syntastic_preprocess_autoload = 1
let s:save_cpo = &cpo
set cpo&vim
" Public functions {{{1
function! syntastic#preprocess#checkstyle(errors) " {{{2
let out = []
let fname = expand('%')
for err in a:errors
if match(err, '\m<error\>') > -1
let line = str2nr(matchstr(err, '\m\<line="\zs\d\+\ze"'))
if line == 0
continue
endif
let col = str2nr(matchstr(err, '\m\<column="\zs\d\+\ze"'))
let type = matchstr(err, '\m\<severity="\zs.\ze')
if type !~? '^[EW]'
let type = 'E'
endif
let message = syntastic#util#decodeXMLEntities(matchstr(err, '\m\<message="\zs[^"]\+\ze"'))
call add(out, join([fname, type, line, col, message], ':'))
elseif match(err, '\m<file name="') > -1
let fname = syntastic#util#decodeXMLEntities(matchstr(err, '\v\<file name\="\zs[^"]+\ze"'))
endif
endfor
return out
endfunction " }}}2
function! syntastic#preprocess#cppcheck(errors) " {{{2
return map(copy(a:errors), 'substitute(v:val, ''\v^\[[^]]+\]\zs( -\> \[[^]]+\])+\ze:'', "", "")')
endfunction " }}}2
function! syntastic#preprocess#killEmpty(errors) " {{{2
return filter(copy(a:errors), 'v:val != ""')
endfunction " }}}2
function! syntastic#preprocess#perl(errors) " {{{2
let out = []
for e in a:errors
let parts = matchlist(e, '\v^(.*)\sat\s(.*)\sline\s(\d+)(.*)$')
if !empty(parts)
call add(out, parts[2] . ':' . parts[3] . ':' . parts[1] . parts[4])
endif
endfor
return syntastic#util#unique(out)
endfunction " }}}2
function! syntastic#preprocess#validator(errors) " {{{2
let out = []
for e in a:errors
let parts = matchlist(e, '\v^"([^"]+)"(.+)')
if len(parts) >= 3
" URL decode, except leave alone any "+"
let parts[1] = substitute(parts[1], '\m%\(\x\x\)', '\=nr2char("0x".submatch(1))', 'g')
let parts[1] = substitute(parts[1], '\m\\"', '"', 'g')
let parts[1] = substitute(parts[1], '\m\\\\', '\\', 'g')
call add(out, '"' . parts[1] . '"' . parts[2])
endif
endfor
return out
endfunction " }}}2
" }}}1
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: set sw=4 sts=4 et fdm=marker:

View File

@ -1,4 +1,4 @@
if exists('g:loaded_syntastic_util_autoload')
if exists('g:loaded_syntastic_util_autoload') || !exists("g:loaded_syntastic_plugin")
finish
endif
let g:loaded_syntastic_util_autoload = 1
@ -6,27 +6,23 @@ let g:loaded_syntastic_util_autoload = 1
let s:save_cpo = &cpo
set cpo&vim
" strwidth() was added in Vim 7.3; if it doesn't exist, we use strlen()
" and hope for the best :)
let s:width = function(exists('*strwidth') ? 'strwidth' : 'strlen')
" Public functions {{{1
function! syntastic#util#isRunningWindows()
function! syntastic#util#isRunningWindows() " {{{2
return has('win16') || has('win32') || has('win64')
endfunction
endfunction " }}}2
function! syntastic#util#DevNull()
function! syntastic#util#DevNull() " {{{2
if syntastic#util#isRunningWindows()
return 'NUL'
endif
return '/dev/null'
endfunction
endfunction " }}}2
" Get directory separator
function! syntastic#util#Slash() abort
function! syntastic#util#Slash() abort " {{{2
return (!exists("+shellslash") || &shellslash) ? '/' : '\'
endfunction
endfunction " }}}2
"search the first 5 lines of the file for a magic number and return a map
"containing the args and the executable
@ -38,7 +34,7 @@ endfunction
"returns
"
"{'exe': '/usr/bin/perl', 'args': ['-f', '-bar']}
function! syntastic#util#parseShebang()
function! syntastic#util#parseShebang() " {{{2
for lnum in range(1,5)
let line = getline(lnum)
@ -50,25 +46,26 @@ function! syntastic#util#parseShebang()
endfor
return { 'exe': '', 'args': [] }
endfunction
endfunction " }}}2
" Get the value of a variable. Allow local variables to override global ones.
function! syntastic#util#var(name)
function! syntastic#util#var(name, ...) " {{{2
return
\ exists('b:syntastic_' . a:name) ? b:syntastic_{a:name} :
\ exists('g:syntastic_' . a:name) ? g:syntastic_{a:name} : ''
endfunction
\ exists('g:syntastic_' . a:name) ? g:syntastic_{a:name} :
\ a:0 > 0 ? a:1 : ''
endfunction " }}}2
" Parse a version string. Return an array of version components.
function! syntastic#util#parseVersion(version)
function! syntastic#util#parseVersion(version) " {{{2
return split(matchstr( a:version, '\v^\D*\zs\d+(\.\d+)+\ze' ), '\m\.')
endfunction
endfunction " }}}2
" Run 'command' in a shell and parse output as a version string.
" Returns an array of version components.
function! syntastic#util#getVersion(command)
function! syntastic#util#getVersion(command) " {{{2
return syntastic#util#parseVersion(system(a:command))
endfunction
endfunction " }}}2
" Verify that the 'installed' version is at least the 'required' version.
"
@ -76,7 +73,7 @@ endfunction
" the "missing" elements 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) " {{{2
for idx in range(max([len(a:installed), len(a:required)]))
let installed_element = get(a:installed, idx, 0)
let required_element = get(a:required, idx, 0)
@ -86,10 +83,14 @@ function! syntastic#util#versionIsAtLeast(installed, required)
endfor
" Everything matched, so it is at least the required version.
return 1
endfunction
endfunction " }}}2
" strwidth() was added in Vim 7.3; if it doesn't exist, we use strlen()
" and hope for the best :)
let s:width = function(exists('*strwidth') ? 'strwidth' : 'strlen')
"print as much of a:msg as possible without "Press Enter" prompt appearing
function! syntastic#util#wideMsg(msg)
function! syntastic#util#wideMsg(msg) " {{{2
let old_ruler = &ruler
let old_showcmd = &showcmd
@ -101,7 +102,7 @@ function! syntastic#util#wideMsg(msg)
"width as the proper amount of characters
let chunks = split(msg, "\t", 1)
let msg = join(map(chunks[:-2], 'v:val . repeat(" ", &ts - s:width(v:val) % &ts)'), '') . chunks[-1]
let msg = strpart(msg, 0, winwidth(0) - 1)
let msg = strpart(msg, 0, &columns - 1)
set noruler noshowcmd
call syntastic#util#redraw(0)
@ -110,10 +111,10 @@ function! syntastic#util#wideMsg(msg)
let &ruler = old_ruler
let &showcmd = old_showcmd
endfunction
endfunction " }}}2
" Check whether a buffer is loaded, listed, and not hidden
function! syntastic#util#bufIsActive(buffer)
function! syntastic#util#bufIsActive(buffer) " {{{2
" convert to number, or hell breaks loose
let buf = str2nr(a:buffer)
@ -129,11 +130,11 @@ function! syntastic#util#bufIsActive(buffer)
endfor
return 0
endfunction
endfunction " }}}2
" start in directory a:where and walk up the parent folders until it
" finds a file matching a:what; return path to that file
function! syntastic#util#findInParent(what, where)
function! syntastic#util#findInParent(what, where) " {{{2
let here = fnamemodify(a:where, ':p')
let root = syntastic#util#Slash()
@ -162,10 +163,10 @@ function! syntastic#util#findInParent(what, where)
endwhile
return ''
endfunction
endfunction " }}}2
" Returns unique elements in a list
function! syntastic#util#unique(list)
function! syntastic#util#unique(list) " {{{2
let seen = {}
let uniques = []
for e in a:list
@ -175,20 +176,20 @@ function! syntastic#util#unique(list)
endif
endfor
return uniques
endfunction
endfunction " }}}2
" A less noisy shellescape()
function! syntastic#util#shescape(string)
function! syntastic#util#shescape(string) " {{{2
return a:string =~ '\m^[A-Za-z0-9_/.-]\+$' ? a:string : shellescape(a:string)
endfunction
endfunction " }}}2
" A less noisy shellescape(expand())
function! syntastic#util#shexpand(string)
function! syntastic#util#shexpand(string) " {{{2
return syntastic#util#shescape(expand(a:string))
endfunction
endfunction " }}}2
" decode XML entities
function! syntastic#util#decodeXMLEntities(string)
function! syntastic#util#decodeXMLEntities(string) " {{{2
let str = a:string
let str = substitute(str, '\m&lt;', '<', 'g')
let str = substitute(str, '\m&gt;', '>', 'g')
@ -196,17 +197,17 @@ function! syntastic#util#decodeXMLEntities(string)
let str = substitute(str, '\m&apos;', "'", 'g')
let str = substitute(str, '\m&amp;', '\&', 'g')
return str
endfunction
endfunction " }}}2
function! syntastic#util#redraw(full)
function! syntastic#util#redraw(full) " {{{2
if a:full
redraw!
else
redraw
endif
endfunction
endfunction " }}}2
function! syntastic#util#dictFilter(errors, filter)
function! syntastic#util#dictFilter(errors, filter) " {{{2
let rules = s:translateFilter(a:filter)
" call syntastic#log#debug(g:SyntasticDebugFilters, "applying filter:", rules)
try
@ -215,11 +216,13 @@ function! syntastic#util#dictFilter(errors, filter)
let msg = matchstr(v:exception, '\m^Vim\%((\a\+)\)\=:\zs.*')
call syntastic#log#error('quiet_messages: ' . msg)
endtry
endfunction
endfunction " }}}2
" }}}1
" Private functions {{{1
function! s:translateFilter(filters)
function! s:translateFilter(filters) " {{{2
let conditions = []
for k in keys(a:filters)
if type(a:filters[k]) == type([])
@ -228,10 +231,14 @@ function! s:translateFilter(filters)
call add(conditions, s:translateElement(k, a:filters[k]))
endif
endfor
return len(conditions) == 1 ? conditions[0] : join(map(conditions, '"(" . v:val . ")"'), ' && ')
endfunction
function! s:translateElement(key, term)
if conditions == []
let conditions = ["1"]
endif
return len(conditions) == 1 ? conditions[0] : join(map(conditions, '"(" . v:val . ")"'), ' && ')
endfunction " }}}2
function! s:translateElement(key, term) " {{{2
if a:key ==? 'level'
let ret = 'v:val["type"] !=? ' . string(a:term[0])
elseif a:key ==? 'type'
@ -241,11 +248,15 @@ function! s:translateElement(key, term)
elseif a:key ==? 'file'
let ret = 'bufname(str2nr(v:val["bufnr"])) !~# ' . string(a:term)
else
call syntastic#log#warn('quiet_messages: ignoring invalid key ' . strtrans(string(a:key)))
let ret = "1"
endif
return ret
endfunction
endfunction " }}}2
" }}}1
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: set et sts=4 sw=4 fdm=marker:
" vim: set sw=4 sts=4 et fdm=marker: