Skip to content

Commit

Permalink
Add ability to search all open buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
versi786 committed Nov 13, 2020
1 parent 36e40f9 commit 2ad1fe1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
22 changes: 22 additions & 0 deletions autoload/ack.vim
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ endfunction "}}}

function! ack#AckWindow(cmd, args) "{{{
let files = tabpagebuflist()
echom string(files)

" remove duplicated filenames (files appearing in more than one window)
let files = filter(copy(sort(files)), 'index(files,v:val,v:key+1)==-1')
Expand All @@ -94,6 +95,27 @@ function! ack#AckWindow(cmd, args) "{{{
call ack#Ack(a:cmd, args)
endfunction "}}}

function! ack#AckBuffers(cmd, args) "{{{
echom "test"
echom string(getbufinfo())
let files = map(filter(copy(getbufinfo()), 'v:val.listed'), 'v:val.bufnr')
echom string(files)

" remove duplicated filenames (files appearing in more than one window)
let files = filter(copy(sort(files)), 'index(files,v:val,v:key+1)==-1')
call map(files, "bufname(v:val)")

" remove unnamed buffers as quickfix (empty strings before shellescape)
call filter(files, 'v:val != ""')

" 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)
endfunction "}}}


function! ack#ShowResults() "{{{
let l:handler = s:UsingLocList() ? g:ack_lhandler : g:ack_qhandler
execute l:handler
Expand Down
10 changes: 10 additions & 0 deletions doc/ack.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ shows the results in a split window.
Just like |:AckAdd| but instead of the |quickfix| list, matches are added
to the current |location-list|

:AckBuffers[!] [options] {pattern} *:AckBuffers*

Search all buffers visible in the screen (current tab page only) files for
the {pattern}.

:LAckBuffers [options] {pattern} *:LAckBuffers*

Just like |:AckBuffers| but instead of the |quickfix| list, matches are
placed in the current |location-list|.

:AckFile [options] {pattern} [{directory}] *:AckFile*

Search recursively in {directory} (which defaults to the current
Expand Down
3 changes: 3 additions & 0 deletions plugin/ack.vim
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,15 @@ command! -bang -nargs=* -complete=file AckAdd call ack#Ack('grepadd<bang>
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=* AckBuffers call ack#AckBuffers('grep<bang>', <q-args>)
command! -bang -nargs=* LAckBuffers call ack#AckBuffers('lgrep<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>)
command! -bang -nargs=* LAckWindow call ack#AckWindow('lgrep<bang>', <q-args>)


let g:loaded_ack = 1

" vim:set et sw=2 ts=2 tw=78 fdm=marker

0 comments on commit 2ad1fe1

Please sign in to comment.