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

add auto set search directory #285

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions autoload/ack.vim
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ endif
" Public API
"-----------------------------------------------------------------------------

function! s:FindProjectRoot()
let current_dir = expand('%:p:h')
while current_dir != '/'
for marker in g:ack_root_markers
let marker_path = current_dir . '/' . marker
if isdirectory(marker_path) || filereadable(marker_path)
return current_dir
endif
endfor
let current_dir = fnamemodify(current_dir, ':h')
endwhile
return ''
endfunction

function! ack#Ack(cmd, args) "{{{
call s:Init(a:cmd)
redraw
Expand Down Expand Up @@ -50,13 +64,14 @@ function! ack#Ack(cmd, args) "{{{
" NOTE: we escape special chars, but not everything using shellescape to
" allow for passing arguments etc
let l:escaped_args = escape(l:grepargs, '|#%')
let l:final_args = l:escaped_args.' '.s:FindProjectRoot()

echo "Searching ..."

if g:ack_use_dispatch
call s:SearchWithDispatch(l:grepprg, l:escaped_args, l:grepformat)
call s:SearchWithDispatch(l:grepprg, l:final_args, l:grepformat)
else
call s:SearchWithGrep(a:cmd, l:grepprg, l:escaped_args, l:grepformat)
call s:SearchWithGrep(a:cmd, l:grepprg, l:final_args, l:grepformat)
endif

" Dispatch has no callback mechanism currently, we just have to display the
Expand Down
13 changes: 13 additions & 0 deletions doc/ack.txt
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,19 @@ Example:
>
let g:ack_use_cword_for_empty_search = 0
<

g:ack_root_markers
Default: ['']

Use this option to enable auto set search directory which contains ack_root_markers,
otherwise the search directory will be current directory.

Example:
>
let g:ack_root_markers = ['.git', '.svn', '.hg']
<


==============================================================================
MAPPINGS *ack-mappings*

Expand Down
4 changes: 4 additions & 0 deletions plugin/ack.vim
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ if !exists("g:ack_use_cword_for_empty_search")
let g:ack_use_cword_for_empty_search = 1
endif

if !exists("g:ack_root_markers")
let g:ack_root_markers = ['']
endif

command! -bang -nargs=* -complete=file Ack call ack#Ack('grep<bang>', <q-args>)
command! -bang -nargs=* -complete=file AckAdd call ack#Ack('grepadd<bang>', <q-args>)
command! -bang -nargs=* -complete=file AckFromSearch call ack#AckFromSearch('grep<bang>', <q-args>)
Expand Down