mirror of
https://github.com/amix/vimrc
synced 2025-08-16 20:55:00 +08:00
Updated vim plugins
This commit is contained in:
@ -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() " {{{2
|
||||
function! syntastic#c#NullOutput() abort " {{{2
|
||||
let known_os = has('unix') || has('mac') || syntastic#util#isRunningWindows()
|
||||
return known_os ? '-o ' . syntastic#util#DevNull() : ''
|
||||
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) " {{{2
|
||||
function! syntastic#c#ReadConfig(file) abort " {{{2
|
||||
call syntastic#log#debug(g:_SYNTASTIC_DEBUG_CHECKERS, 'ReadConfig: looking for', a:file)
|
||||
|
||||
" search upwards from the current file's directory
|
||||
@ -69,7 +69,7 @@ function! syntastic#c#ReadConfig(file) " {{{2
|
||||
endfunction " }}}2
|
||||
|
||||
" GetLocList() for C-like compilers
|
||||
function! syntastic#c#GetLocList(filetype, subchecker, options) " {{{2
|
||||
function! syntastic#c#GetLocList(filetype, subchecker, options) abort " {{{2
|
||||
try
|
||||
let flags = s:_get_cflags(a:filetype, a:subchecker, a:options)
|
||||
catch /\m\C^Syntastic: skip checks$/
|
||||
@ -96,7 +96,7 @@ endfunction " }}}2
|
||||
" Private functions {{{1
|
||||
|
||||
" initialize c/cpp syntax checker handlers
|
||||
function! s:_init() " {{{2
|
||||
function! s:_init() abort " {{{2
|
||||
let s:handlers = []
|
||||
let s:cflags = {}
|
||||
|
||||
@ -118,7 +118,7 @@ function! s:_init() " {{{2
|
||||
endfunction " }}}2
|
||||
|
||||
" register a handler dictionary object
|
||||
function! s:_registerHandler(regex, function, args) " {{{2
|
||||
function! s:_registerHandler(regex, function, args) abort " {{{2
|
||||
let handler = {}
|
||||
let handler["regex"] = a:regex
|
||||
let handler["func"] = function(a:function)
|
||||
@ -129,7 +129,7 @@ endfunction " }}}2
|
||||
" try to find library with 'pkg-config'
|
||||
" search possible libraries from first to last given
|
||||
" argument until one is found
|
||||
function! s:_checkPackage(name, ...) " {{{2
|
||||
function! s:_checkPackage(name, ...) abort " {{{2
|
||||
if executable('pkg-config')
|
||||
if !has_key(s:cflags, a:name)
|
||||
for pkg in a:000
|
||||
@ -150,7 +150,7 @@ function! s:_checkPackage(name, ...) " {{{2
|
||||
endfunction " }}}2
|
||||
|
||||
" try to find PHP includes with 'php-config'
|
||||
function! s:_checkPhp() " {{{2
|
||||
function! s:_checkPhp() abort " {{{2
|
||||
if executable('php-config')
|
||||
if !has_key(s:cflags, 'php')
|
||||
let s:cflags['php'] = system('php-config --includes')
|
||||
@ -162,7 +162,7 @@ function! s:_checkPhp() " {{{2
|
||||
endfunction " }}}2
|
||||
|
||||
" try to find the python headers with distutils
|
||||
function! s:_checkPython() " {{{2
|
||||
function! s:_checkPython() abort " {{{2
|
||||
if executable('python')
|
||||
if !has_key(s:cflags, 'python')
|
||||
let s:cflags['python'] = system('python -c ''from distutils import ' .
|
||||
@ -176,7 +176,7 @@ function! s:_checkPython() " {{{2
|
||||
endfunction " }}}2
|
||||
|
||||
" try to find the ruby headers with 'rbconfig'
|
||||
function! s:_checkRuby() " {{{2
|
||||
function! s:_checkRuby() abort " {{{2
|
||||
if executable('ruby')
|
||||
if !has_key(s:cflags, 'ruby')
|
||||
let s:cflags['ruby'] = system('ruby -r rbconfig -e ' .
|
||||
@ -194,7 +194,7 @@ endfunction " }}}2
|
||||
" Utilities {{{1
|
||||
|
||||
" resolve checker-related user variables
|
||||
function! s:_get_checker_var(scope, filetype, subchecker, name, default) " {{{2
|
||||
function! s:_get_checker_var(scope, filetype, subchecker, name, default) abort " {{{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}
|
||||
@ -206,7 +206,7 @@ function! s:_get_checker_var(scope, filetype, subchecker, name, default) " {{{2
|
||||
endfunction " }}}2
|
||||
|
||||
" resolve user CFLAGS
|
||||
function! s:_get_cflags(ft, ck, opts) " {{{2
|
||||
function! s:_get_cflags(ft, ck, opts) abort " {{{2
|
||||
" determine whether to parse header files as well
|
||||
if has_key(a:opts, 'header_names') && expand('%', 1) =~? a:opts['header_names']
|
||||
if s:_get_checker_var('g', a:ft, a:ck, 'check_header', 0)
|
||||
@ -253,7 +253,7 @@ 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:_get_include_dirs(filetype) " {{{2
|
||||
function! s:_get_include_dirs(filetype) abort " {{{2
|
||||
let include_dirs = []
|
||||
|
||||
if a:filetype =~# '\v^%(c|cpp|objc|objcpp)$' &&
|
||||
@ -271,7 +271,7 @@ endfunction " }}}2
|
||||
|
||||
" search the first 100 lines for include statements that are
|
||||
" given in the handlers dictionary
|
||||
function! s:_search_headers() " {{{2
|
||||
function! s:_search_headers() abort " {{{2
|
||||
let includes = ''
|
||||
let files = []
|
||||
let found = []
|
||||
|
@ -10,24 +10,24 @@ let s:one_time_notices_issued = []
|
||||
|
||||
" Public functions {{{1
|
||||
|
||||
function! syntastic#log#info(msg) " {{{2
|
||||
function! syntastic#log#info(msg) abort " {{{2
|
||||
echomsg "syntastic: info: " . a:msg
|
||||
endfunction " }}}2
|
||||
|
||||
function! syntastic#log#warn(msg) " {{{2
|
||||
function! syntastic#log#warn(msg) abort " {{{2
|
||||
echohl WarningMsg
|
||||
echomsg "syntastic: warning: " . a:msg
|
||||
echohl None
|
||||
endfunction " }}}2
|
||||
|
||||
function! syntastic#log#error(msg) " {{{2
|
||||
function! syntastic#log#error(msg) abort " {{{2
|
||||
execute "normal \<Esc>"
|
||||
echohl ErrorMsg
|
||||
echomsg "syntastic: error: " . a:msg
|
||||
echohl None
|
||||
endfunction " }}}2
|
||||
|
||||
function! syntastic#log#oneTimeWarn(msg) " {{{2
|
||||
function! syntastic#log#oneTimeWarn(msg) abort " {{{2
|
||||
if index(s:one_time_notices_issued, a:msg) >= 0
|
||||
return
|
||||
endif
|
||||
@ -37,7 +37,7 @@ function! syntastic#log#oneTimeWarn(msg) " {{{2
|
||||
endfunction " }}}2
|
||||
|
||||
" @vimlint(EVL102, 1, l:OLD_VAR)
|
||||
function! syntastic#log#deprecationWarn(old, new, ...) " {{{2
|
||||
function! syntastic#log#deprecationWarn(old, new, ...) abort " {{{2
|
||||
if exists('g:syntastic_' . a:old) && !exists('g:syntastic_' . a:new)
|
||||
let msg = 'variable g:syntastic_' . a:old . ' is deprecated, please use '
|
||||
|
||||
@ -60,7 +60,7 @@ function! syntastic#log#deprecationWarn(old, new, ...) " {{{2
|
||||
endfunction " }}}2
|
||||
" @vimlint(EVL102, 0, l:OLD_VAR)
|
||||
|
||||
function! syntastic#log#debug(level, msg, ...) " {{{2
|
||||
function! syntastic#log#debug(level, msg, ...) abort " {{{2
|
||||
if !s:_isDebugEnabled(a:level)
|
||||
return
|
||||
endif
|
||||
@ -80,7 +80,7 @@ function! syntastic#log#debug(level, msg, ...) " {{{2
|
||||
call s:_logRedirect(0)
|
||||
endfunction " }}}2
|
||||
|
||||
function! syntastic#log#debugShowOptions(level, names) " {{{2
|
||||
function! syntastic#log#debugShowOptions(level, names) abort " {{{2
|
||||
if !s:_isDebugEnabled(a:level)
|
||||
return
|
||||
endif
|
||||
@ -96,7 +96,7 @@ function! syntastic#log#debugShowOptions(level, names) " {{{2
|
||||
call s:_logRedirect(0)
|
||||
endfunction " }}}2
|
||||
|
||||
function! syntastic#log#debugShowVariables(level, names) " {{{2
|
||||
function! syntastic#log#debugShowVariables(level, names) abort " {{{2
|
||||
if !s:_isDebugEnabled(a:level)
|
||||
return
|
||||
endif
|
||||
@ -115,7 +115,7 @@ function! syntastic#log#debugShowVariables(level, names) " {{{2
|
||||
call s:_logRedirect(0)
|
||||
endfunction " }}}2
|
||||
|
||||
function! syntastic#log#debugDump(level) " {{{2
|
||||
function! syntastic#log#debugDump(level) abort " {{{2
|
||||
if !s:_isDebugEnabled(a:level)
|
||||
return
|
||||
endif
|
||||
@ -127,11 +127,11 @@ endfunction " }}}2
|
||||
|
||||
" Private functions {{{1
|
||||
|
||||
function! s:_isDebugEnabled_smart(level) " {{{2
|
||||
function! s:_isDebugEnabled_smart(level) abort " {{{2
|
||||
return and(g:syntastic_debug, a:level)
|
||||
endfunction " }}}2
|
||||
|
||||
function! s:_isDebugEnabled_dumb(level) " {{{2
|
||||
function! s:_isDebugEnabled_dumb(level) abort " {{{2
|
||||
" poor man's bit test for bit N, assuming a:level == 2**N
|
||||
return (g:syntastic_debug / a:level) % 2
|
||||
endfunction " }}}2
|
||||
@ -139,7 +139,7 @@ endfunction " }}}2
|
||||
let s:_isDebugEnabled = function(exists('*and') ? 's:_isDebugEnabled_smart' : 's:_isDebugEnabled_dumb')
|
||||
lockvar s:_isDebugEnabled
|
||||
|
||||
function! s:_logRedirect(on) " {{{2
|
||||
function! s:_logRedirect(on) abort " {{{2
|
||||
if exists("g:syntastic_debug_file")
|
||||
if a:on
|
||||
try
|
||||
@ -158,11 +158,11 @@ endfunction " }}}2
|
||||
|
||||
" Utilities {{{1
|
||||
|
||||
function! s:_log_timestamp() " {{{2
|
||||
function! s:_log_timestamp() abort " {{{2
|
||||
return 'syntastic: ' . split(reltimestr(reltime(g:_SYNTASTIC_START)))[0] . ': '
|
||||
endfunction " }}}2
|
||||
|
||||
function! s:_format_variable(name) " {{{2
|
||||
function! s:_format_variable(name) abort " {{{2
|
||||
let vals = []
|
||||
if exists('g:syntastic_' . a:name)
|
||||
call add(vals, 'g:syntastic_' . a:name . ' = ' . strtrans(string(g:syntastic_{a:name})))
|
||||
|
@ -9,7 +9,7 @@ set cpo&vim
|
||||
" Public functions {{{1
|
||||
|
||||
" merge consecutive blanks
|
||||
function! syntastic#postprocess#compressWhitespace(errors) " {{{2
|
||||
function! syntastic#postprocess#compressWhitespace(errors) abort " {{{2
|
||||
for e in a:errors
|
||||
let e['text'] = substitute(e['text'], "\001", '', 'g')
|
||||
let e['text'] = substitute(e['text'], '\n', ' ', 'g')
|
||||
@ -22,7 +22,7 @@ function! syntastic#postprocess#compressWhitespace(errors) " {{{2
|
||||
endfunction " }}}2
|
||||
|
||||
" remove spurious CR under Cygwin
|
||||
function! syntastic#postprocess#cygwinRemoveCR(errors) " {{{2
|
||||
function! syntastic#postprocess#cygwinRemoveCR(errors) abort " {{{2
|
||||
if has('win32unix')
|
||||
for e in a:errors
|
||||
let e['text'] = substitute(e['text'], '\r', '', 'g')
|
||||
@ -33,7 +33,7 @@ function! syntastic#postprocess#cygwinRemoveCR(errors) " {{{2
|
||||
endfunction " }}}2
|
||||
|
||||
" decode XML entities
|
||||
function! syntastic#postprocess#decodeXMLEntities(errors) " {{{2
|
||||
function! syntastic#postprocess#decodeXMLEntities(errors) abort " {{{2
|
||||
for e in a:errors
|
||||
let e['text'] = syntastic#util#decodeXMLEntities(e['text'])
|
||||
endfor
|
||||
@ -42,13 +42,13 @@ function! syntastic#postprocess#decodeXMLEntities(errors) " {{{2
|
||||
endfunction " }}}2
|
||||
|
||||
" filter out errors referencing other files
|
||||
function! syntastic#postprocess#filterForeignErrors(errors) " {{{2
|
||||
function! syntastic#postprocess#filterForeignErrors(errors) abort " {{{2
|
||||
return filter(copy(a:errors), 'get(v:val, "bufnr") == ' . bufnr(''))
|
||||
endfunction " }}}2
|
||||
|
||||
" make sure line numbers are not past end of buffers
|
||||
" XXX: this loads all referenced buffers in memory
|
||||
function! syntastic#postprocess#guards(errors) " {{{2
|
||||
function! syntastic#postprocess#guards(errors) abort " {{{2
|
||||
let buffers = syntastic#util#unique(map(filter(copy(a:errors), 'v:val["valid"]'), 'str2nr(v:val["bufnr"])'))
|
||||
|
||||
let guards = {}
|
||||
|
@ -8,7 +8,7 @@ set cpo&vim
|
||||
|
||||
" Public functions {{{1
|
||||
|
||||
function! syntastic#preprocess#cabal(errors) " {{{2
|
||||
function! syntastic#preprocess#cabal(errors) abort " {{{2
|
||||
let out = []
|
||||
let star = 0
|
||||
for err in a:errors
|
||||
@ -28,7 +28,7 @@ function! syntastic#preprocess#cabal(errors) " {{{2
|
||||
return out
|
||||
endfunction " }}}2
|
||||
|
||||
function! syntastic#preprocess#checkstyle(errors) " {{{2
|
||||
function! syntastic#preprocess#checkstyle(errors) abort " {{{2
|
||||
let out = []
|
||||
let fname = expand('%', 1)
|
||||
for err in a:errors
|
||||
@ -55,14 +55,14 @@ function! syntastic#preprocess#checkstyle(errors) " {{{2
|
||||
return out
|
||||
endfunction " }}}2
|
||||
|
||||
function! syntastic#preprocess#cppcheck(errors) " {{{2
|
||||
function! syntastic#preprocess#cppcheck(errors) abort " {{{2
|
||||
return map(copy(a:errors), 'substitute(v:val, ''\v^\[[^]]+\]\zs( -\> \[[^]]+\])+\ze:'', "", "")')
|
||||
endfunction " }}}2
|
||||
|
||||
" @vimlint(EVL102, 1, l:true)
|
||||
" @vimlint(EVL102, 1, l:false)
|
||||
" @vimlint(EVL102, 1, l:null)
|
||||
function! syntastic#preprocess#flow(errors) " {{{2
|
||||
function! syntastic#preprocess#flow(errors) abort " {{{2
|
||||
" JSON artifacts
|
||||
let true = 1
|
||||
let false = 0
|
||||
@ -123,11 +123,11 @@ endfunction " }}}2
|
||||
" @vimlint(EVL102, 0, l:false)
|
||||
" @vimlint(EVL102, 0, l:null)
|
||||
|
||||
function! syntastic#preprocess#killEmpty(errors) " {{{2
|
||||
function! syntastic#preprocess#killEmpty(errors) abort " {{{2
|
||||
return filter(copy(a:errors), 'v:val != ""')
|
||||
endfunction " }}}2
|
||||
|
||||
function! syntastic#preprocess#perl(errors) " {{{2
|
||||
function! syntastic#preprocess#perl(errors) abort " {{{2
|
||||
let out = []
|
||||
|
||||
for e in a:errors
|
||||
@ -143,7 +143,7 @@ endfunction " }}}2
|
||||
" @vimlint(EVL102, 1, l:true)
|
||||
" @vimlint(EVL102, 1, l:false)
|
||||
" @vimlint(EVL102, 1, l:null)
|
||||
function! syntastic#preprocess#prospector(errors) " {{{2
|
||||
function! syntastic#preprocess#prospector(errors) abort " {{{2
|
||||
" JSON artifacts
|
||||
let true = 1
|
||||
let false = 0
|
||||
@ -158,36 +158,38 @@ function! syntastic#preprocess#prospector(errors) " {{{2
|
||||
endtry
|
||||
|
||||
let out = []
|
||||
if type(errs) == type({}) && has_key(errs, 'messages') && type(errs['messages']) == type([])
|
||||
for e in errs['messages']
|
||||
if type(e) == type({})
|
||||
try
|
||||
if e['source'] ==# 'pylint'
|
||||
let e['location']['character'] += 1
|
||||
endif
|
||||
if type(errs) == type({}) && has_key(errs, 'messages')
|
||||
if type(errs['messages']) == type([])
|
||||
for e in errs['messages']
|
||||
if type(e) == type({})
|
||||
try
|
||||
if e['source'] ==# 'pylint'
|
||||
let e['location']['character'] += 1
|
||||
endif
|
||||
|
||||
let msg =
|
||||
\ e['location']['path'] . ':' .
|
||||
\ e['location']['line'] . ':' .
|
||||
\ e['location']['character'] . ': ' .
|
||||
\ e['code'] . ' ' .
|
||||
\ e['message'] . ' ' .
|
||||
\ '[' . e['source'] . ']'
|
||||
let msg =
|
||||
\ e['location']['path'] . ':' .
|
||||
\ e['location']['line'] . ':' .
|
||||
\ e['location']['character'] . ': ' .
|
||||
\ e['code'] . ' ' .
|
||||
\ e['message'] . ' ' .
|
||||
\ '[' . e['source'] . ']'
|
||||
|
||||
call add(out, msg)
|
||||
catch /\m^Vim\%((\a\+)\)\=:E716/
|
||||
call add(out, msg)
|
||||
catch /\m^Vim\%((\a\+)\)\=:E716/
|
||||
call syntastic#log#warn('checker python/prospector: unknown error format')
|
||||
let out = []
|
||||
break
|
||||
endtry
|
||||
else
|
||||
call syntastic#log#warn('checker python/prospector: unknown error format')
|
||||
let out = []
|
||||
break
|
||||
endtry
|
||||
else
|
||||
call syntastic#log#warn('checker python/prospector: unknown error format')
|
||||
let out = []
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
else
|
||||
call syntastic#log#warn('checker python/prospector: unknown error format')
|
||||
endif
|
||||
endfor
|
||||
else
|
||||
call syntastic#log#warn('checker python/prospector: unknown error format')
|
||||
endif
|
||||
endif
|
||||
|
||||
return out
|
||||
@ -196,7 +198,7 @@ endfunction " }}}2
|
||||
" @vimlint(EVL102, 0, l:false)
|
||||
" @vimlint(EVL102, 0, l:null)
|
||||
|
||||
function! syntastic#preprocess#rparse(errors) " {{{2
|
||||
function! syntastic#preprocess#rparse(errors) abort " {{{2
|
||||
let errlist = copy(a:errors)
|
||||
|
||||
" remove uninteresting lines and handle continuations
|
||||
@ -205,7 +207,7 @@ function! syntastic#preprocess#rparse(errors) " {{{2
|
||||
if i > 0 && errlist[i][:1] == ' ' && errlist[i] !~ '\m\s\+\^$'
|
||||
let errlist[i-1] .= errlist[i][1:]
|
||||
call remove(errlist, i)
|
||||
elseif errlist[i] !~ '\m^\(Lint:\|Lint checking:\|Error in\) '
|
||||
elseif errlist[i] !~# '\m^\(Lint:\|Lint checking:\|Error in\) '
|
||||
call remove(errlist, i)
|
||||
else
|
||||
let i += 1
|
||||
@ -235,11 +237,11 @@ function! syntastic#preprocess#rparse(errors) " {{{2
|
||||
return out
|
||||
endfunction " }}}2
|
||||
|
||||
function! syntastic#preprocess#tslint(errors) " {{{2
|
||||
function! syntastic#preprocess#tslint(errors) abort " {{{2
|
||||
return map(copy(a:errors), 'substitute(v:val, ''\m^\(([^)]\+)\)\s\(.\+\)$'', ''\2 \1'', "")')
|
||||
endfunction " }}}2
|
||||
|
||||
function! syntastic#preprocess#validator(errors) " {{{2
|
||||
function! syntastic#preprocess#validator(errors) abort " {{{2
|
||||
let out = []
|
||||
for e in a:errors
|
||||
let parts = matchlist(e, '\v^"([^"]+)"(.+)')
|
||||
@ -254,6 +256,58 @@ function! syntastic#preprocess#validator(errors) " {{{2
|
||||
return out
|
||||
endfunction " }}}2
|
||||
|
||||
" @vimlint(EVL102, 1, l:true)
|
||||
" @vimlint(EVL102, 1, l:false)
|
||||
" @vimlint(EVL102, 1, l:null)
|
||||
function! syntastic#preprocess#vint(errors) abort " {{{2
|
||||
" JSON artifacts
|
||||
let true = 1
|
||||
let false = 0
|
||||
let null = ''
|
||||
|
||||
" A hat tip to Marc Weber for this trick
|
||||
" http://stackoverflow.com/questions/17751186/iterating-over-a-string-in-vimscript-or-parse-a-json-file/19105763#19105763
|
||||
try
|
||||
let errs = eval(join(a:errors, ''))
|
||||
catch
|
||||
let errs = []
|
||||
endtry
|
||||
|
||||
let out = []
|
||||
if type(errs) == type([])
|
||||
for e in errs
|
||||
if type(e) == type({})
|
||||
try
|
||||
let msg =
|
||||
\ e['file_path'] . ':' .
|
||||
\ e['line_number'] . ':' .
|
||||
\ e['column_number'] . ':' .
|
||||
\ e['severity'][0] . ': ' .
|
||||
\ e['description'] . ' (' .
|
||||
\ e['policy_name'] . ')'
|
||||
|
||||
call add(out, msg)
|
||||
catch /\m^Vim\%((\a\+)\)\=:E716/
|
||||
call syntastic#log#warn('checker vim/vint: unknown error format')
|
||||
let out = []
|
||||
break
|
||||
endtry
|
||||
else
|
||||
call syntastic#log#warn('checker vim/vint: unknown error format')
|
||||
let out = []
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
else
|
||||
call syntastic#log#warn('checker vim/vint: unknown error format')
|
||||
endif
|
||||
|
||||
return out
|
||||
endfunction " }}}2
|
||||
" @vimlint(EVL102, 0, l:true)
|
||||
" @vimlint(EVL102, 0, l:false)
|
||||
" @vimlint(EVL102, 0, l:null)
|
||||
|
||||
" }}}1
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
|
@ -8,11 +8,11 @@ set cpo&vim
|
||||
|
||||
" Public functions {{{1
|
||||
|
||||
function! syntastic#util#isRunningWindows() " {{{2
|
||||
function! syntastic#util#isRunningWindows() abort " {{{2
|
||||
return has('win16') || has('win32') || has('win64')
|
||||
endfunction " }}}2
|
||||
|
||||
function! syntastic#util#DevNull() " {{{2
|
||||
function! syntastic#util#DevNull() abort " {{{2
|
||||
if syntastic#util#isRunningWindows()
|
||||
return 'NUL'
|
||||
endif
|
||||
@ -24,8 +24,12 @@ function! syntastic#util#Slash() abort " {{{2
|
||||
return (!exists("+shellslash") || &shellslash) ? '/' : '\'
|
||||
endfunction " }}}2
|
||||
|
||||
function! syntastic#util#CygwinPath(path) abort " {{{2
|
||||
return substitute(system('cygpath -m ' . syntastic#util#shescape(a:path)), "\n", '', 'g')
|
||||
endfunction " }}}2
|
||||
|
||||
" Create a temporary directory
|
||||
function! syntastic#util#tmpdir() " {{{2
|
||||
function! syntastic#util#tmpdir() abort " {{{2
|
||||
let tempdir = ''
|
||||
|
||||
if (has('unix') || has('mac')) && executable('mktemp')
|
||||
@ -41,7 +45,7 @@ function! syntastic#util#tmpdir() " {{{2
|
||||
if has('win32') || has('win64')
|
||||
let tempdir = $TEMP . syntastic#util#Slash() . 'vim-syntastic-' . getpid()
|
||||
elseif has('win32unix')
|
||||
let tempdir = s:CygwinPath('/tmp/vim-syntastic-' . getpid())
|
||||
let tempdir = syntastic#util#CygwinPath('/tmp/vim-syntastic-' . getpid())
|
||||
elseif $TMPDIR != ''
|
||||
let tempdir = $TMPDIR . '/vim-syntastic-' . getpid()
|
||||
else
|
||||
@ -60,7 +64,7 @@ function! syntastic#util#tmpdir() " {{{2
|
||||
endfunction " }}}2
|
||||
|
||||
" Recursively remove a directory
|
||||
function! syntastic#util#rmrf(what) " {{{2
|
||||
function! syntastic#util#rmrf(what) abort " {{{2
|
||||
" try to make sure we don't delete directories we didn't create
|
||||
if a:what !~? 'vim-syntastic-'
|
||||
return
|
||||
@ -94,7 +98,7 @@ endfunction " }}}2
|
||||
"returns
|
||||
"
|
||||
"{'exe': '/usr/bin/perl', 'args': ['-f', '-bar']}
|
||||
function! syntastic#util#parseShebang() " {{{2
|
||||
function! syntastic#util#parseShebang() abort " {{{2
|
||||
for lnum in range(1, 5)
|
||||
let line = getline(lnum)
|
||||
if line =~ '^#!'
|
||||
@ -109,7 +113,7 @@ function! syntastic#util#parseShebang() " {{{2
|
||||
endfunction " }}}2
|
||||
|
||||
" Get the value of a variable. Allow local variables to override global ones.
|
||||
function! syntastic#util#var(name, ...) " {{{2
|
||||
function! syntastic#util#var(name, ...) abort " {{{2
|
||||
return
|
||||
\ exists('b:syntastic_' . a:name) ? b:syntastic_{a:name} :
|
||||
\ exists('g:syntastic_' . a:name) ? g:syntastic_{a:name} :
|
||||
@ -117,7 +121,7 @@ function! syntastic#util#var(name, ...) " {{{2
|
||||
endfunction " }}}2
|
||||
|
||||
" Parse a version string. Return an array of version components.
|
||||
function! syntastic#util#parseVersion(version) " {{{2
|
||||
function! syntastic#util#parseVersion(version) abort " {{{2
|
||||
return map(split(matchstr( a:version, '\v^\D*\zs\d+(\.\d+)+\ze' ), '\m\.'), 'str2nr(v:val)')
|
||||
endfunction " }}}2
|
||||
|
||||
@ -127,13 +131,13 @@ endfunction " }}}2
|
||||
" 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) " {{{2
|
||||
function! syntastic#util#versionIsAtLeast(installed, required) abort " {{{2
|
||||
return syntastic#util#compareLexi(a:installed, a:required) >= 0
|
||||
endfunction " }}}2
|
||||
|
||||
" Almost lexicographic comparison of two lists of integers. :) If lists
|
||||
" have different lengths, the "missing" elements are assumed to be 0.
|
||||
function! syntastic#util#compareLexi(a, b) " {{{2
|
||||
function! syntastic#util#compareLexi(a, b) abort " {{{2
|
||||
for idx in range(max([len(a:a), len(a:b)]))
|
||||
let a_element = str2nr(get(a:a, idx, 0))
|
||||
let b_element = str2nr(get(a:b, idx, 0))
|
||||
@ -150,7 +154,7 @@ endfunction " }}}2
|
||||
let s:_width = function(exists('*strwidth') ? 'strwidth' : 'strlen')
|
||||
lockvar s:_width
|
||||
|
||||
function! syntastic#util#screenWidth(str, tabstop) " {{{2
|
||||
function! syntastic#util#screenWidth(str, tabstop) abort " {{{2
|
||||
let chunks = split(a:str, "\t", 1)
|
||||
let width = s:_width(chunks[-1])
|
||||
for c in chunks[:-2]
|
||||
@ -161,7 +165,7 @@ function! syntastic#util#screenWidth(str, tabstop) " {{{2
|
||||
endfunction " }}}2
|
||||
|
||||
"print as much of a:msg as possible without "Press Enter" prompt appearing
|
||||
function! syntastic#util#wideMsg(msg) " {{{2
|
||||
function! syntastic#util#wideMsg(msg) abort " {{{2
|
||||
let old_ruler = &ruler
|
||||
let old_showcmd = &showcmd
|
||||
|
||||
@ -185,7 +189,7 @@ function! syntastic#util#wideMsg(msg) " {{{2
|
||||
endfunction " }}}2
|
||||
|
||||
" Check whether a buffer is loaded, listed, and not hidden
|
||||
function! syntastic#util#bufIsActive(buffer) " {{{2
|
||||
function! syntastic#util#bufIsActive(buffer) abort " {{{2
|
||||
" convert to number, or hell breaks loose
|
||||
let buf = str2nr(a:buffer)
|
||||
|
||||
@ -205,7 +209,7 @@ 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) " {{{2
|
||||
function! syntastic#util#findInParent(what, where) abort " {{{2
|
||||
let here = fnamemodify(a:where, ':p')
|
||||
|
||||
let root = syntastic#util#Slash()
|
||||
@ -237,7 +241,7 @@ function! syntastic#util#findInParent(what, where) " {{{2
|
||||
endfunction " }}}2
|
||||
|
||||
" Returns unique elements in a list
|
||||
function! syntastic#util#unique(list) " {{{2
|
||||
function! syntastic#util#unique(list) abort " {{{2
|
||||
let seen = {}
|
||||
let uniques = []
|
||||
for e in a:list
|
||||
@ -250,17 +254,17 @@ function! syntastic#util#unique(list) " {{{2
|
||||
endfunction " }}}2
|
||||
|
||||
" A less noisy shellescape()
|
||||
function! syntastic#util#shescape(string) " {{{2
|
||||
return a:string =~ '\m^[A-Za-z0-9_/.-]\+$' ? a:string : shellescape(a:string)
|
||||
function! syntastic#util#shescape(string) abort " {{{2
|
||||
return a:string =~# '\m^[A-Za-z0-9_/.-]\+$' ? a:string : shellescape(a:string)
|
||||
endfunction " }}}2
|
||||
|
||||
" A less noisy shellescape(expand())
|
||||
function! syntastic#util#shexpand(string, ...) " {{{2
|
||||
function! syntastic#util#shexpand(string, ...) abort " {{{2
|
||||
return syntastic#util#shescape(a:0 ? expand(a:string, a:1) : expand(a:string, 1))
|
||||
endfunction " }}}2
|
||||
|
||||
" Escape arguments
|
||||
function! syntastic#util#argsescape(opt) " {{{2
|
||||
function! syntastic#util#argsescape(opt) abort " {{{2
|
||||
if type(a:opt) == type('') && a:opt != ''
|
||||
return [a:opt]
|
||||
elseif type(a:opt) == type([])
|
||||
@ -271,7 +275,7 @@ function! syntastic#util#argsescape(opt) " {{{2
|
||||
endfunction " }}}2
|
||||
|
||||
" decode XML entities
|
||||
function! syntastic#util#decodeXMLEntities(string) " {{{2
|
||||
function! syntastic#util#decodeXMLEntities(string) abort " {{{2
|
||||
let str = a:string
|
||||
let str = substitute(str, '\m<', '<', 'g')
|
||||
let str = substitute(str, '\m>', '>', 'g')
|
||||
@ -281,7 +285,7 @@ function! syntastic#util#decodeXMLEntities(string) " {{{2
|
||||
return str
|
||||
endfunction " }}}2
|
||||
|
||||
function! syntastic#util#redraw(full) " {{{2
|
||||
function! syntastic#util#redraw(full) abort " {{{2
|
||||
if a:full
|
||||
redraw!
|
||||
else
|
||||
@ -289,7 +293,7 @@ function! syntastic#util#redraw(full) " {{{2
|
||||
endif
|
||||
endfunction " }}}2
|
||||
|
||||
function! syntastic#util#dictFilter(errors, filter) " {{{2
|
||||
function! syntastic#util#dictFilter(errors, filter) abort " {{{2
|
||||
let rules = s:_translateFilter(a:filter)
|
||||
" call syntastic#log#debug(g:_SYNTASTIC_DEBUG_TRACE, "applying filter:", rules)
|
||||
try
|
||||
@ -303,7 +307,7 @@ endfunction " }}}2
|
||||
" Return a [high, low] list of integers, representing the time
|
||||
" (hopefully high resolution) since program start
|
||||
" TODO: This assumes reltime() returns a list of integers.
|
||||
function! syntastic#util#stamp() " {{{2
|
||||
function! syntastic#util#stamp() abort " {{{2
|
||||
return reltime(g:_SYNTASTIC_START)
|
||||
endfunction " }}}2
|
||||
|
||||
@ -311,7 +315,7 @@ endfunction " }}}2
|
||||
|
||||
" Private functions {{{1
|
||||
|
||||
function! s:_translateFilter(filters) " {{{2
|
||||
function! s:_translateFilter(filters) abort " {{{2
|
||||
let conditions = []
|
||||
for k in keys(a:filters)
|
||||
if type(a:filters[k]) == type([])
|
||||
@ -327,7 +331,7 @@ function! s:_translateFilter(filters) " {{{2
|
||||
return len(conditions) == 1 ? conditions[0] : join(map(conditions, '"(" . v:val . ")"'), ' && ')
|
||||
endfunction " }}}2
|
||||
|
||||
function! s:_translateElement(key, term) " {{{2
|
||||
function! s:_translateElement(key, term) abort " {{{2
|
||||
let fkey = a:key
|
||||
if fkey[0] == '!'
|
||||
let fkey = fkey[1:]
|
||||
@ -365,7 +369,7 @@ function! s:_translateElement(key, term) " {{{2
|
||||
return ret
|
||||
endfunction " }}}2
|
||||
|
||||
function! s:_rmrf(what) " {{{2
|
||||
function! s:_rmrf(what) abort " {{{2
|
||||
if !exists('s:rmdir')
|
||||
let s:rmdir = syntastic#util#shescape(get(g:, 'netrw_localrmdir', 'rmdir'))
|
||||
endif
|
||||
|
Reference in New Issue
Block a user