From 68cfe6513ba9432d69d534a90bd2761f80b40ce8 Mon Sep 17 00:00:00 2001 From: LCD 47 Date: Mon, 13 May 2013 16:37:16 +0300 Subject: [PATCH] Cleanup. --- autoload/syntastic/postprocess.vim | 16 ++++ syntax_checkers/java/checkstyle.vim | 39 +++------- syntax_checkers/java/javac.vim | 111 ++++++++++++++-------------- syntax_checkers/sass/sass.vim | 18 +++-- 4 files changed, 93 insertions(+), 91 deletions(-) diff --git a/autoload/syntastic/postprocess.vim b/autoload/syntastic/postprocess.vim index 1342980a..1491c738 100644 --- a/autoload/syntastic/postprocess.vim +++ b/autoload/syntastic/postprocess.vim @@ -36,6 +36,22 @@ function syntastic#postprocess#compressWhitespace(errors) return llist endfunction +" remove spurious CR under Cygwin +function! syntastic#postprocess#cygwinRemoveCR(errors) + if has('win32unix') + let llist = [] + + for e in a:errors + let e['text'] = substitute(e['text'], '\r', '', 'g') + call add(llist, e) + endfor + else + let llist = a:errors + endif + + return llist +endfunction + let &cpo = s:save_cpo unlet s:save_cpo " vim: set et sts=4 sw=4: diff --git a/syntax_checkers/java/checkstyle.vim b/syntax_checkers/java/checkstyle.vim index e03df5d3..c86136f0 100644 --- a/syntax_checkers/java/checkstyle.vim +++ b/syntax_checkers/java/checkstyle.vim @@ -27,47 +27,28 @@ function! SyntaxCheckers_java_checkstyle_IsAvailable() return executable('java') endfunction -function! s:CygwinPath(path) - return substitute(system("cygpath -m ".a:path), '\%x00', '', 'g') -endfunction - -function! s:RemoveCarriageReturn(line) - return substitute(a:line, '\r', '', 'g') -endfunction - -function! s:RemoveCarriageReturns(errors) - for error in a:errors - let error['text'] = s:RemoveCarriageReturn(error['text']) - endfor -endfunction - function! SyntaxCheckers_java_checkstyle_GetLocList() - let fname = fnameescape(expand ( '%:p:h' ) . '/' . expand ( '%:t' )) + let fname = fnameescape( expand('%:p:h') . '/' . expand('%:t') ) - if has('win32unix') - let fname = s:CygwinPath(fname) - endif + if has('win32unix') + let fname = substitute(system('cygpath -m ' . fname), '\%x00', '', 'g') + endif let makeprg = syntastic#makeprg#build({ - \ 'exe': 'java', - \ 'args': '-cp ' . g:syntastic_java_checkstyle_classpath . ' com.puppycrawl.tools.checkstyle.Main -c ' . g:syntastic_java_checkstyle_conf_file, - \ 'fname': fname, - \ 'tail': '2>&1', - \ 'subchecker': 'checkstyle' }) + \ 'exe': 'java', + \ 'args': '-cp ' . g:syntastic_java_checkstyle_classpath . + \ ' com.puppycrawl.tools.checkstyle.Main -c ' . g:syntastic_java_checkstyle_conf_file, + \ 'fname': fname, + \ 'subchecker': 'checkstyle' }) " check style format let errorformat = '%f:%l:%c:\ %m,%f:%l:\ %m' - let errors = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) - if has('win32unix') - call s:RemoveCarriageReturns(errors) - endif + return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'postprocess': ['cygwinRemoveCR'] }) - return errors endfunction call g:SyntasticRegistry.CreateAndRegisterChecker({ \ 'filetype': 'java', \ 'name': 'checkstyle'}) - diff --git a/syntax_checkers/java/javac.vim b/syntax_checkers/java/javac.vim index cc1b03f6..db3c2d47 100644 --- a/syntax_checkers/java/javac.vim +++ b/syntax_checkers/java/javac.vim @@ -37,15 +37,15 @@ if !exists("g:syntastic_java_javac_delete_output") let g:syntastic_java_javac_delete_output = 1 endif -function! s:CygwinPath(path) +function! s:CygwinPath(path) return substitute(system("cygpath -m ".a:path), '\%x00', '', 'g') endfunction if !exists("g:syntastic_java_javac_temp_dir") if has('win32') || has('win64') let g:syntastic_java_javac_temp_dir = $TEMP."\\vim-syntastic-javac" - elseif has('win32unix') - let g:syntastic_java_javac_temp_dir=s:CygwinPath('/tmp/vim-syntastic-javac') + elseif has('win32unix') + let g:syntastic_java_javac_temp_dir = s:CygwinPath('/tmp/vim-syntastic-javac') else let g:syntastic_java_javac_temp_dir = '/tmp/vim-syntastic-javac' endif @@ -77,22 +77,16 @@ if !exists("g:syntastic_java_javac_maven_pom_classpath") endif function! s:RemoveCarriageReturn(line) - return substitute(a:line, '\r', '', 'g') -endfunction - -function! s:RemoveCarriageReturns(errors) - for error in a:errors - let error['text'] = s:RemoveCarriageReturn(error['text']) - endfor + return substitute(a:line, '\r', '', 'g') endfunction " recursively remove directory and all it's sub-directories function! s:RemoveDir(dir) if isdirectory(a:dir) - for f in split(globpath(a:dir,'*'),"\n") + for f in split(globpath(a:dir, '*'), "\n") call s:RemoveDir(f) endfor - silent! call system('rmdir '.a:dir) + silent! call system('rmdir ' . a:dir) else silent! call delete(a:dir) endif @@ -119,7 +113,7 @@ function! s:LoadClasspathFromConfigFile() let lines = readfile(g:syntastic_java_javac_config_file) for l in lines if l != '' - let path .= l."\n" + let path .= l . "\n" endif endfor return path @@ -130,14 +124,14 @@ endfunction function! s:SaveClasspath() let path = '' - let lines = getline(1,line('$')) + let lines = getline(1, line('$')) " save classpath to config file if g:syntastic_java_javac_config_file_enabled call writefile(lines,g:syntastic_java_javac_config_file) endif for l in lines if l != '' - let path .= l."\n" + let path .= l . "\n" endif endfor let g:syntastic_java_javac_classpath = path @@ -149,10 +143,16 @@ function! s:EditClasspath() let winnr = bufwinnr('^' . command . '$') if winnr < 0 let pathlist = split(g:syntastic_java_javac_classpath,"\n") - execute (len(pathlist)+5) . 'sp ' . fnameescape(command) - au BufWriteCmd call s:SaveClasspath() | bwipeout + execute (len(pathlist) + 5) . 'sp ' . fnameescape(command) + + augroup syntastic + autocmd BufWriteCmd call s:SaveClasspath() | bwipeout + augroup END + setlocal buftype=acwrite bufhidden=wipe nobuflisted noswapfile nowrap number - for p in pathlist | call append(line('$')-1,p) | endfor + for p in pathlist + call append(line('$') - 1, p) + endfor else execute winnr . 'wincmd w' endif @@ -162,8 +162,9 @@ command! SyntasticJavacEditClasspath call s:EditClasspath() function! s:GetMavenClasspath() if filereadable('pom.xml') if g:syntastic_java_javac_maven_pom_ftime != getftime('pom.xml') || g:syntastic_java_javac_maven_pom_cwd != getcwd() - let mvn_classpath_output = split(system(g:syntastic_java_maven_executable.' dependency:build-classpath'),"\n") + let mvn_classpath_output = split(system(g:syntastic_java_maven_executable . ' dependency:build-classpath'), "\n") let class_path_next = 0 + for line in mvn_classpath_output if class_path_next == 1 let mvn_classpath = s:RemoveCarriageReturn(line) @@ -173,8 +174,10 @@ function! s:GetMavenClasspath() let class_path_next = 1 endif endfor - let mvn_classpath = s:AddToClasspath(mvn_classpath,'target/classes') - let mvn_classpath = s:AddToClasspath(mvn_classpath,'target/test-classes') + + let mvn_classpath = s:AddToClasspath(mvn_classpath, 'target/classes') + let mvn_classpath = s:AddToClasspath(mvn_classpath, 'target/test-classes') + let g:syntastic_java_javac_maven_pom_cwd = getcwd() let g:syntastic_java_javac_maven_pom_ftime = getftime('pom.xml') let g:syntastic_java_javac_maven_pom_classpath = mvn_classpath @@ -190,28 +193,28 @@ endfunction function! s:MavenOutputDirectory() if filereadable('pom.xml') - let output_dir = getcwd() - if match(expand( '%:p:h' ), "src.main.java") >= 0 - let output_dir .= '/target/classes' - endif - if match(expand( '%:p:h' ), "src.test.java") >= 0 - let output_dir .= '/target/test-classes' - endif + let output_dir = getcwd() + if match(expand( '%:p:h' ), "src.main.java") >= 0 + let output_dir .= '/target/classes' + endif + if match(expand( '%:p:h' ), "src.test.java") >= 0 + let output_dir .= '/target/test-classes' + endif - if has('win32unix') - let output_dir=s:CygwinPath(output_dir) - endif - return output_dir + if has('win32unix') + let output_dir=s:CygwinPath(output_dir) + endif + return output_dir endif endfunction function! SyntaxCheckers_java_javac_GetLocList() - let javac_opts = g:syntastic_java_javac_options + let javac_opts = g:syntastic_java_javac_options if g:syntastic_java_javac_delete_output - let output_dir = g:syntastic_java_javac_temp_dir - let javac_opts .= ' -d ' .output_dir + let output_dir = g:syntastic_java_javac_temp_dir + let javac_opts .= ' -d ' . output_dir endif " load classpath from config file @@ -234,7 +237,9 @@ function! SyntaxCheckers_java_javac_GetLocList() endtry if type(ps) == type([]) for p in ps - if p != '' | let javac_classpath = s:AddToClasspath(javac_classpath,p) | endif + if p != '' + let javac_classpath = s:AddToClasspath(javac_classpath,p) + endif endfor else let javac_classpath = s:AddToClasspath(javac_classpath,ps) @@ -243,10 +248,10 @@ function! SyntaxCheckers_java_javac_GetLocList() endfor if g:syntastic_java_javac_autoload_maven_classpath - if !g:syntastic_java_javac_delete_output - let maven_output_dir = s:MavenOutputDirectory() - let javac_opts .= ' -d ' . maven_output_dir - endif + if !g:syntastic_java_javac_delete_output + let maven_output_dir = s:MavenOutputDirectory() + let javac_opts .= ' -d ' . maven_output_dir + endif let maven_classpath = s:GetMavenClasspath() let javac_classpath = s:AddToClasspath(javac_classpath,maven_classpath) endif @@ -257,23 +262,23 @@ function! SyntaxCheckers_java_javac_GetLocList() " path seperator if has('win32') || has('win32unix') || has('win64') - let sep = "\\" + let sep = "\\" else let sep = '/' endif - let fname = fnameescape(expand ( '%:p:h' ) . sep . expand ( '%:t' )) + let fname = fnameescape(expand ( '%:p:h' ) . sep . expand ( '%:t' )) - if has('win32unix') - let fname = s:CygwinPath(fname) - endif + if has('win32unix') + let fname = s:CygwinPath(fname) + endif let makeprg = syntastic#makeprg#build({ - \ 'exe': g:syntastic_java_javac_executable, - \ 'args': javac_opts, - \ 'fname': fname, - \ 'tail': '2>&1', - \ 'subchecker': 'javac' }) + \ 'exe': g:syntastic_java_javac_executable, + \ 'args': javac_opts, + \ 'fname': fname, + \ 'tail': '2>&1', + \ 'subchecker': 'javac' }) " unashamedly stolen from *errorformat-javac* (quickfix.txt) and modified to include error types let errorformat = '%E%f:%l:\ error:\ %m,%W%f:%l:\ warning:\ %m,%A%f:%l:\ %m,%+Z%p^,%+C%.%#,%-G%.%#' @@ -281,11 +286,7 @@ function! SyntaxCheckers_java_javac_GetLocList() if g:syntastic_java_javac_delete_output silent! call mkdir(output_dir,'p') endif - let errors = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) - - if has('win32unix') - call s:RemoveCarriageReturns(errors) - endif + let errors = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'postprocess': ['cygwinRemoveCR'] }) if g:syntastic_java_javac_delete_output call s:RemoveDir(output_dir) diff --git a/syntax_checkers/sass/sass.vim b/syntax_checkers/sass/sass.vim index ae796e94..de99c617 100644 --- a/syntax_checkers/sass/sass.vim +++ b/syntax_checkers/sass/sass.vim @@ -39,14 +39,18 @@ function! SyntaxCheckers_sass_sass_GetLocList() return [] end let makeprg = syntastic#makeprg#build({ - \ 'exe': 'sass', - \ 'args': '--cache-location ' . s:sass_cache_location . ' ' . s:imports . ' --check', - \ 'subchecker': 'sass' }) - let errorformat = '%ESyntax %trror:%m,%C on line %l of %f,%Z%.%#' - let errorformat .= ',%Wwarning on line %l:,%Z%m,Syntax %trror on line %l: %m' - let loclist = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) + \ 'exe': 'sass', + \ 'args': '--cache-location ' . s:sass_cache_location . ' ' . s:imports . ' --check', + \ 'subchecker': 'sass' }) + let errorformat = + \ '%ESyntax %trror:%m,' . + \ '%C on line %l of %f,' . + \ '%Z%.%#,' . + \ '%Wwarning on line %l:,' . + \ '%Z%m,' . + \ 'Syntax %trror on line %l: %m' - return loclist + return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) endfunction call g:SyntasticRegistry.CreateAndRegisterChecker({