Skip to content

Commit 410e921

Browse files
committed
Use guessProjectRoot from rking/ag.vim.
1 parent be8a43a commit 410e921

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

plugin/side-search.vim

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,24 @@ function! SideSearchWinnr()
151151
return s:my_buffer_winnr()
152152
endfunction
153153

154+
function! s:guessProjectRoot()
155+
let l:splitsearchdir = split(getcwd(), "/")
156+
157+
while len(l:splitsearchdir) > 2
158+
let l:searchdir = '/'.join(l:splitsearchdir, '/').'/'
159+
for l:marker in ['.rootdir', '.git', '.hg', '.svn', 'bzr', '_darcs', 'build.xml']
160+
" found it! Return the dir
161+
if filereadable(l:searchdir.l:marker) || isdirectory(l:searchdir.l:marker)
162+
return l:searchdir
163+
endif
164+
endfor
165+
let l:splitsearchdir = l:splitsearchdir[0:-2] " Splice the list to get rid of the tail directory
166+
endwhile
167+
168+
" Nothing found, fallback to current working dir
169+
return getcwd()
170+
endfunction
171+
154172
" The public facing function.
155173
" Accept 1 or 2 arguments which basically get passed directly
156174
" to the `ag` command.
@@ -173,8 +191,10 @@ function! SideSearch(args) abort
173191

174192
call s:append_guide()
175193

194+
" determine root directory
195+
let l:cwd = s:guessProjectRoot()
176196
" execute showing summary of stuff read (without silent)
177-
let b:cmd = g:side_search_prg . ' ' . a:args
197+
let b:cmd = g:side_search_prg . ' ' . a:args . ' ' . l:cwd
178198
" Thanks: https://github.com/rking/ag.vim/blob/master/autoload/ag.vim#L154
179199
let query = matchstr(a:args, "\\v(-)\@<!(\<)\@<=\\w+|['\"]\\zs.{-}\\ze['\"]")
180200
let b:escaped_query = shellescape(query)

0 commit comments

Comments
 (0)