Cleanup: minor optimisations, formatting.

This commit is contained in:
LCD 47 2014-02-01 18:44:04 +02:00
parent 147bd7cca3
commit 8a588134f1
4 changed files with 42 additions and 50 deletions

View File

@ -88,21 +88,21 @@ function! s:Init()
let s:handlers = []
let s:cflags = {}
call s:RegHandler('cairo', 'syntastic#c#CheckPKG', ['cairo', 'cairo'])
call s:RegHandler('freetype', 'syntastic#c#CheckPKG', ['freetype', 'freetype2', 'freetype'])
call s:RegHandler('glade', 'syntastic#c#CheckPKG', ['glade', 'libglade-2.0', 'libglade'])
call s:RegHandler('glib', 'syntastic#c#CheckPKG', ['glib', 'glib-2.0', 'glib'])
call s:RegHandler('gtk', 'syntastic#c#CheckPKG', ['gtk', 'gtk+-2.0', 'gtk+', 'glib-2.0', 'glib'])
call s:RegHandler('libsoup', 'syntastic#c#CheckPKG', ['libsoup', 'libsoup-2.4', 'libsoup-2.2'])
call s:RegHandler('libxml', 'syntastic#c#CheckPKG', ['libxml', 'libxml-2.0', 'libxml'])
call s:RegHandler('pango', 'syntastic#c#CheckPKG', ['pango', 'pango'])
call s:RegHandler('SDL', 'syntastic#c#CheckPKG', ['sdl', 'sdl'])
call s:RegHandler('opengl', 'syntastic#c#CheckPKG', ['opengl', 'gl'])
call s:RegHandler('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('php\.h', 'syntastic#c#CheckPhp', [])
call s:RegHandler('Python\.h', 'syntastic#c#CheckPython', [])
call s:RegHandler('ruby', 'syntastic#c#CheckRuby', [])
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
" resolve checker-related user variables

View File

@ -16,7 +16,7 @@ function! s:compareErrorItems(a, b)
" errors take precedence over warnings
return a:a['type'] ==? 'e' ? -1 : 1
else
return get(a:a, 'col') - get(a:b, 'col')
return get(a:a, 'col', 0) - get(a:b, 'col', 0)
endif
endfunction

View File

@ -25,7 +25,7 @@ endfunction
" Get directory separator
function! syntastic#util#Slash() abort
return !exists("+shellslash") || &shellslash ? '/' : '\'
return (!exists("+shellslash") || &shellslash) ? '/' : '\'
endfunction
"search the first 5 lines of the file for a magic number and return a map
@ -45,11 +45,11 @@ function! syntastic#util#parseShebang()
if line =~ '^#!'
let exe = matchstr(line, '\m^#!\s*\zs[^ \t]*')
let args = split(matchstr(line, '\m^#!\s*[^ \t]*\zs.*'))
return {'exe': exe, 'args': args}
return { 'exe': exe, 'args': args }
endif
endfor
return {'exe': '', 'args': []}
return { 'exe': '', 'args': [] }
endfunction
" Parse a version string. Return an array of version components.
@ -70,17 +70,9 @@ endfunction
"
" See http://semver.org for info about version numbers.
function! syntastic#util#versionIsAtLeast(installed, required)
for index in range(max([len(a:installed), len(a:required)]))
if len(a:installed) <= index
let installed_element = 0
else
let installed_element = a:installed[index]
endif
if len(a:required) <= index
let required_element = 0
else
let required_element = a:required[index]
endif
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)
if installed_element != required_element
return installed_element > required_element
endif
@ -145,15 +137,18 @@ function! syntastic#util#findInParent(what, where)
let root = here[0] . root[1:]
endif
while !empty(here)
let old = ''
while here != ''
let p = split(globpath(here, a:what), '\n')
if !empty(p)
return fnamemodify(p[0], ':p')
elseif here ==? root
elseif here ==? root || here ==? old
break
endif
let old = here
" we use ':h:h' rather than ':h' since ':p' adds a trailing '/'
" if 'here' is a directory
let here = fnamemodify(here, ':p:h:h')
@ -230,7 +225,6 @@ function! s:translateFilter(filters)
endfunction
function! s:translateElement(key, term)
let ret = "1"
if a:key ==? 'level'
let ret = 'v:val["type"] !=? ' . string(a:term[0])
elseif a:key ==? 'type'
@ -239,6 +233,8 @@ function! s:translateElement(key, term)
let ret = 'v:val["text"] !~? ' . string(a:term)
elseif a:key ==? 'file'
let ret = 'bufname(str2nr(v:val["bufnr"])) !~# ' . string(a:term)
else
let ret = "1"
endif
return ret
endfunction

View File

@ -123,7 +123,7 @@ let s:modemap = g:SyntasticModeMap.Instance()
" @vimlint(EVL103, 1, a:argLead)
function! s:CompleteCheckerName(argLead, cmdLine, cursorPos)
let checker_names = []
for ft in s:CurrentFiletypes()
for ft in s:ResolveFiletypes()
for checker in s:registry.availableCheckersFor(ft)
call add(checker_names, checker.getName())
endfor
@ -197,8 +197,7 @@ function! s:BufWinEnterHook()
\ 'autocmd: BufWinEnter, buffer ' . bufnr("") . ' = ' . string(bufname(str2nr(bufnr("")))) .
\ ', &buftype = ' . string(&buftype))
if &buftype == ''
let loclist = g:SyntasticLoclist.current()
call s:notifiers.refresh(loclist)
call s:notifiers.refresh(g:SyntasticLoclist.current())
endif
endfunction
@ -275,10 +274,6 @@ function! s:ResolveFiletypes(...)
return split( get(g:syntastic_filetype_map, type, type), '\m\.' )
endfunction
function! s:CurrentFiletypes()
return s:ResolveFiletypes(&filetype)
endfunction
"detect and cache all syntax errors in this buffer
function! s:CacheErrors(checkers)
call s:ClearCache()
@ -294,12 +289,13 @@ function! s:CacheErrors(checkers)
call syntastic#log#debugDump(g:SyntasticDebugVariables)
call syntastic#log#debugShowVariables(g:SyntasticDebugTrace, 'syntastic_aggregate_errors')
let filetypes = s:ResolveFiletypes()
let aggregate_errors =
\ exists('b:syntastic_aggregate_errors') ? b:syntastic_aggregate_errors : g:syntastic_aggregate_errors
let decorate_errors = (aggregate_errors || len(s:CurrentFiletypes()) > 1) &&
let decorate_errors = (aggregate_errors || len(filetypes) > 1) &&
\ (exists('b:syntastic_id_checkers') ? b:syntastic_id_checkers : g:syntastic_id_checkers)
for ft in s:CurrentFiletypes()
for ft in filetypes
let clist = empty(a:checkers) ? s:registry.getActiveCheckers(ft) : s:registry.getCheckers(ft, a:checkers)
for checker in clist
@ -366,8 +362,7 @@ endfunction
"display the cached errors for this buf in the location list
function! s:ShowLocList()
let loclist = g:SyntasticLoclist.current()
call loclist.show()
call g:SyntasticLoclist.current().show()
endfunction
"the script changes &shellredir and &shell to stop the screen flicking when
@ -382,8 +377,8 @@ endfunction
function! s:IgnoreFile(filename)
let fname = fnamemodify(a:filename, ':p')
for p in g:syntastic_ignore_files
if fname =~# p
for pattern in g:syntastic_ignore_files
if fname =~# pattern
return 1
endif
endfor
@ -479,7 +474,7 @@ function! SyntasticMake(options)
let &errorformat = old_errorformat
let &l:errorformat = old_local_errorformat
let &shellredir = old_shellredir
let &shell=old_shell
let &shell = old_shell
if s:IsRedrawRequiredAfterMake()
call syntastic#util#redraw(g:syntastic_full_redraws)
@ -497,7 +492,7 @@ function! SyntasticMake(options)
" Add subtype info if present.
if has_key(a:options, 'subtype')
call SyntasticAddToErrors(errors, {'subtype': a:options['subtype']})
call SyntasticAddToErrors(errors, { 'subtype': a:options['subtype'] })
endif
if has_key(a:options, 'postprocess') && !empty(a:options['postprocess'])
@ -512,13 +507,14 @@ 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 err in a:errors
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]
if !has_key(err, key) || empty(err[key])
let err[key] = a:options[key]
endif
endfor
endfor
return a:errors
endfunction