Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support windows type builds in the guessprojectroot function #112

Closed
wants to merge 10 commits into from
21 changes: 14 additions & 7 deletions autoload/ag.vim
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ if !exists("g:ag_mapping_message")
endif

if !exists("g:ag_working_path_mode")
let g:ag_working_path_mode = 'c'
let g:ag_working_path_mode = 'c'
endif

function! ag#AgBuffer(cmd, args)
Expand Down Expand Up @@ -216,17 +216,24 @@ function! ag#AgHelp(cmd,args)
endfunction

function! s:guessProjectRoot()
let l:splitsearchdir = split(getcwd(), "/")
let l:startdir = getcwd()
if has('win16') || has('win32')
let l:startdir = substitute(l:startdir, '\', '/', 'g')
endif
let l:searchdirs = split(l:startdir, '/', 1)

while len(l:splitsearchdir) > 2
let l:searchdir = '/'.join(l:splitsearchdir, '/').'/'
while len(l:searchdirs) > 0
" the forward slash works as a dirsep on Windows too.
let l:searchdir = join(l:searchdirs, '/') . '/'
for l:marker in ['.rootdir', '.git', '.hg', '.svn', 'bzr', '_darcs', 'build.xml']
" found it! Return the dir
if filereadable(l:searchdir.l:marker) || isdirectory(l:searchdir.l:marker)
let l:item = l:searchdir . l:marker
if filereadable(l:item) || isdirectory(l:item)
" found it! Return the dir
return l:searchdir
endif
endfor
let l:splitsearchdir = l:splitsearchdir[0:-2] " Splice the list to get rid of the tail directory
" pop the last dir off the list
let l:searchdirs = l:searchdirs[:-2]
endwhile

" Nothing found, fallback to current working dir
Expand Down