Skip to content

Commit

Permalink
Refactor function.
Browse files Browse the repository at this point in the history
  • Loading branch information
kaethorn committed Mar 27, 2018
1 parent ff37de5 commit 589a5f4
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions plugin/side-search.vim
Original file line number Diff line number Diff line change
Expand Up @@ -152,24 +152,21 @@ function! SideSearchWinnr()
endfunction

function! s:guessProjectRoot()
let l:splitsearchdir = split(getcwd(), "/")
let l:cwd = getcwd()
let l:maxdistance = len(split(l:cwd, '/')) - 2
let l:searchdir = ''

while len(l:splitsearchdir) > 2
while len(split(l:searchdir, '/')) < l:maxdistance
for l:marker in ['.rootdir', '.git', '.hg', '.svn', 'bzr', '_darcs', 'build.xml']
let l:dir = l:searchdir.l:marker
" found it! Return the dir
if filereadable(l:dir) || isdirectory(l:dir)
return l:searchdir
endif
endfor
" Splice the list to get rid of the tail directory
let l:splitsearchdir = l:splitsearchdir[0:-2]
let l:searchdir = '../'.l:searchdir
endwhile

" Nothing found, fallback to current working dir
return getcwd()
return l:cwd
endfunction

" The public facing function.
Expand Down

0 comments on commit 589a5f4

Please sign in to comment.