Refactor FindInParent from haxe.vim to be a util function

This commit is contained in:
Thomas Holmes 2013-07-05 17:12:06 -04:00
parent 6ba8e651cb
commit 2d537305f6
2 changed files with 23 additions and 23 deletions

View File

@ -119,6 +119,28 @@ function! syntastic#util#bufIsActive(buffer)
return 0
endfunction
" 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)
let here = fnamemodify(a:where, ':p')
while !empty(here)
let p = split(globpath(here, a:what), '\n')
if !empty(p)
return fnamemodify(p[0], ':p')
elseif here == '/'
break
endif
" we use ':h:h' rather than ':h' since ':p' adds a trailing '/'
" if 'here' is a directory
let here = fnamemodify(here, ':p:h:h')
endwhile
return ''
endfunction
" Returns unique elements in a list
function! syntastic#util#unique(list)
let seen = {}

View File

@ -19,35 +19,13 @@ function! SyntaxCheckers_haxe_haxe_IsAvailable()
return executable('haxe')
endfunction
" 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! s:FindInParent(what, where)
let here = fnamemodify(a:where, ':p')
while !empty(here)
let p = split(globpath(here, a:what), '\n')
if !empty(p)
return fnamemodify(p[0], ':p')
elseif here == '/'
break
endif
" we use ':h:h' rather than ':h' since ':p' adds a trailing '/'
" if 'here' is a directory
let here = fnamemodify(here, ':p:h:h')
endwhile
return ''
endfunction
function! SyntaxCheckers_haxe_haxe_GetLocList()
if exists('b:vaxe_hxml')
let hxml = b:vaxe_hxml
elseif exists('g:vaxe_hxml')
let hxml = g:vaxe_hxml
else
let hxml = s:FindInParent('*.hxml', expand('%:p:h'))
let hxml = syntastic#util#findInParent('*.hxml', expand('%:p:h'))
endif
let hxml = fnamemodify(hxml, ':p')