From d03d035ac6e5f962c12834b99d0d09fa9dd97357 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 | 20 ++++++++++++++++++++ doc/ack.txt | 9 +++++++++ plugin/ack.vim | 2 ++ 3 files changed, 31 insertions(+) diff --git a/autoload/ack.vim b/autoload/ack.vim index b6afdba4..425b6517 100644 --- a/autoload/ack.vim +++ b/autoload/ack.vim @@ -94,6 +94,26 @@ function! ack#AckWindow(cmd, args) "{{{ call ack#Ack(a:cmd, args) endfunction "}}} +function! ack#AckBuffers(cmd, args) "{{{ + let files = map(filter(copy(getbufinfo()), 'v:val.listed'), 'v:val.bufnr') + + " 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 != ""') + + " remove directories + call filter(files, {idx, val -> !isdirectory(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..f39da86b 100644 --- a/doc/ack.txt +++ b/doc/ack.txt @@ -41,6 +41,15 @@ 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 listed buffers 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..f1625196 100644 --- a/plugin/ack.vim +++ b/plugin/ack.vim @@ -72,6 +72,8 @@ 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', )