From 2ad1fe1e3c4a76d68dae5c0fc9ff629065b976b2 Mon Sep 17 00:00:00 2001 From: Aasif Versi Date: Thu, 12 Nov 2020 21:44:41 -0500 Subject: [PATCH] Add ability to search all open buffers Closes #189 --- autoload/ack.vim | 22 ++++++++++++++++++++++ doc/ack.txt | 10 ++++++++++ plugin/ack.vim | 3 +++ 3 files changed, 35 insertions(+) diff --git a/autoload/ack.vim b/autoload/ack.vim index b6afdba4..c8edcd12 100644 --- a/autoload/ack.vim +++ b/autoload/ack.vim @@ -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') @@ -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 diff --git a/doc/ack.txt b/doc/ack.txt index 22e884bc..554261db 100644 --- a/doc/ack.txt +++ b/doc/ack.txt @@ -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 diff --git a/plugin/ack.vim b/plugin/ack.vim index 202ae2ea..829a0c9e 100644 --- a/plugin/ack.vim +++ b/plugin/ack.vim @@ -72,12 +72,15 @@ 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=* AckBuffers call ack#AckBuffers('grep', ) +command! -bang -nargs=* LAckBuffers call ack#AckBuffers('lgrep', ) 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', ) command! -bang -nargs=* LAckWindow call ack#AckWindow('lgrep', ) + let g:loaded_ack = 1 " vim:set et sw=2 ts=2 tw=78 fdm=marker