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

Fix :AckWindow for word-under-cursor searches #181

Open
wants to merge 2 commits 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
21 changes: 12 additions & 9 deletions autoload/ack.vim
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ endif
" Public API
"-----------------------------------------------------------------------------

function! ack#Ack(cmd, args) "{{{
function! ack#Ack(cmd, args, paths) "{{{
call s:Init(a:cmd)
redraw

Expand All @@ -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("<cword>") : 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."
Expand Down Expand Up @@ -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) "{{{
Expand All @@ -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() "{{{
Expand Down Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions plugin/ack.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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<bang>', <q-args>)
command! -bang -nargs=* -complete=file AckAdd call ack#Ack('grepadd<bang>', <q-args>)
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>)
command! -bang -nargs=* -complete=file LAck call ack#Ack('lgrep<bang>', <q-args>)
command! -bang -nargs=* -complete=file LAckAdd call ack#Ack('lgrepadd<bang>', <q-args>)
command! -bang -nargs=* -complete=file AckFile call ack#Ack('grep<bang> -g', <q-args>)
command! -bang -nargs=* -complete=file LAck call ack#Ack('lgrep<bang>', <q-args>, [])
command! -bang -nargs=* -complete=file LAckAdd call ack#Ack('lgrepadd<bang>', <q-args>, [])
command! -bang -nargs=* -complete=file AckFile call ack#Ack('grep<bang> -g', <q-args>, [])
command! -bang -nargs=* -complete=help AckHelp call ack#AckHelp('grep<bang>', <q-args>)
command! -bang -nargs=* -complete=help LAckHelp call ack#AckHelp('lgrep<bang>', <q-args>)
command! -bang -nargs=* AckWindow call ack#AckWindow('grep<bang>', <q-args>)
Expand Down