From 8a588134f16190abbdad542cfedaaa342fa01e24 Mon Sep 17 00:00:00 2001 From: LCD 47 Date: Sat, 1 Feb 2014 18:44:04 +0200 Subject: [PATCH] Cleanup: minor optimisations, formatting. --- autoload/syntastic/c.vim | 28 +++++++++++++------------- autoload/syntastic/postprocess.vim | 2 +- autoload/syntastic/util.vim | 30 ++++++++++++---------------- plugin/syntastic.vim | 32 +++++++++++++----------------- 4 files changed, 42 insertions(+), 50 deletions(-) diff --git a/autoload/syntastic/c.vim b/autoload/syntastic/c.vim index 78fe9128..e89a4d22 100644 --- a/autoload/syntastic/c.vim +++ b/autoload/syntastic/c.vim @@ -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\', 'syntastic#c#CheckPhp', []) + call s:RegHandler('\m\', 'syntastic#c#CheckPython', []) + call s:RegHandler('\m\ 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 diff --git a/plugin/syntastic.vim b/plugin/syntastic.vim index 586c72bd..de27f57a 100644 --- a/plugin/syntastic.vim +++ b/plugin/syntastic.vim @@ -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