diff --git a/autoload/ack.vim b/autoload/ack.vim index 82d3de65..a58995e4 100644 --- a/autoload/ack.vim +++ b/autoload/ack.vim @@ -11,7 +11,7 @@ endif " Public API "----------------------------------------------------------------------------- -function! ack#Ack(cmd, args) "{{{ +function! ack#Ack(cmd, args, paths) "{{{ call s:Init(a:cmd) redraw @@ -37,6 +37,11 @@ function! ack#Ack(cmd, args) "{{{ " If no pattern is provided, search for the word under the cursor let l:grepargs = empty(a:args) ? expand("") : a:args . join(a:000, ' ') + " Add paths to search in + if len(a:paths) > 0 + let l:grepargs .= ' '.join(a:paths, ' ') + endif + "Bypass search if cursor is on blank string if l:grepargs == "" echo "No regular expression found." @@ -65,12 +70,11 @@ function! ack#AckFromSearch(cmd, args) "{{{ let search = getreg('/') " translate vim regular expression to perl regular expression. let search = substitute(search, '\(\\<\|\\>\)', '\\b', 'g') - call ack#Ack(a:cmd, '"' . search . '" ' . a:args) + call ack#Ack(a:cmd, '"' . search . '" ' . a:args, []) endfunction "}}} function! ack#AckHelp(cmd, args) "{{{ - let args = a:args . ' ' . s:GetDocLocations() - call ack#Ack(a:cmd, args) + call ack#Ack(a:cmd, a:args, s:GetDocPaths()) endfunction "}}} function! ack#AckWindow(cmd, args) "{{{ @@ -85,9 +89,8 @@ function! ack#AckWindow(cmd, args) "{{{ " expand to full path (avoid problems with cd/lcd in au QuickFixCmdPre) let files = map(files, "shellescape(fnamemodify(v:val, ':p'))") - let args = a:args . ' ' . join(files) - call ack#Ack(a:cmd, args) + call ack#Ack(a:cmd, a:args, files) endfunction "}}} function! ack#ShowResults() "{{{ @@ -133,12 +136,12 @@ function! s:ApplyMappings() "{{{ endif endfunction "}}} -function! s:GetDocLocations() "{{{ - let dp = '' +function! s:GetDocPaths() "{{{ + let dp = [] for p in split(&rtp, ',') let p = p . '/doc/' if isdirectory(p) - let dp = p . '*.txt ' . dp + call insert(dp, p . '*.txt') endif endfor diff --git a/plugin/ack.vim b/plugin/ack.vim index 2be8197d..06df2103 100644 --- a/plugin/ack.vim +++ b/plugin/ack.vim @@ -67,12 +67,12 @@ if !exists("g:ack_use_cword_for_empty_search") let g:ack_use_cword_for_empty_search = 1 endif -command! -bang -nargs=* -complete=file Ack call ack#Ack('grep', ) -command! -bang -nargs=* -complete=file AckAdd call ack#Ack('grepadd', ) +command! -bang -nargs=* -complete=file Ack call ack#Ack('grep', , []) +command! -bang -nargs=* -complete=file AckAdd call ack#Ack('grepadd', , []) command! -bang -nargs=* -complete=file AckFromSearch call ack#AckFromSearch('grep', ) -command! -bang -nargs=* -complete=file LAck call ack#Ack('lgrep', ) -command! -bang -nargs=* -complete=file LAckAdd call ack#Ack('lgrepadd', ) -command! -bang -nargs=* -complete=file AckFile call ack#Ack('grep -g', ) +command! -bang -nargs=* -complete=file LAck call ack#Ack('lgrep', , []) +command! -bang -nargs=* -complete=file LAckAdd call ack#Ack('lgrepadd', , []) +command! -bang -nargs=* -complete=file AckFile call ack#Ack('grep -g', , []) command! -bang -nargs=* -complete=help AckHelp call ack#AckHelp('grep', ) command! -bang -nargs=* -complete=help LAckHelp call ack#AckHelp('lgrep', ) command! -bang -nargs=* AckWindow call ack#AckWindow('grep', )