From 993c0067681a5eb58e4d20c43d30e57f3adfc09b Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Sat, 30 Apr 2016 11:30:09 +0300 Subject: [PATCH 1/2] Fix :AckWindow for word-under-cursor searches If an argument was not given, the command didn't take the word under the cursor, since the locations that were given to the ack#Ack() function worked as an "args" argument. Separating "args" and "locations" fixes the issue. --- autoload/ack.vim | 19 +++++++++++-------- plugin/ack.vim | 10 +++++----- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/autoload/ack.vim b/autoload/ack.vim index 82d3de65..41fb1de3 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, locations) "{{{ 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 locations to search in + if len(a:locations) > 0 + let l:grepargs .= ' '.join(a:locations, ' ') + 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:GetDocLocations()) 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() "{{{ @@ -134,11 +137,11 @@ function! s:ApplyMappings() "{{{ endfunction "}}} function! s:GetDocLocations() "{{{ - let dp = '' + 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', ) From 91d398b4cb885215f2b1bf5338228947ba2b891e Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Tue, 3 May 2016 21:36:26 +0300 Subject: [PATCH 2/2] Rename "locations" to "paths" --- autoload/ack.vim | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/autoload/ack.vim b/autoload/ack.vim index 41fb1de3..a58995e4 100644 --- a/autoload/ack.vim +++ b/autoload/ack.vim @@ -11,7 +11,7 @@ endif " Public API "----------------------------------------------------------------------------- -function! ack#Ack(cmd, args, locations) "{{{ +function! ack#Ack(cmd, args, paths) "{{{ call s:Init(a:cmd) redraw @@ -37,9 +37,9 @@ function! ack#Ack(cmd, args, locations) "{{{ " 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 locations to search in - if len(a:locations) > 0 - let l:grepargs .= ' '.join(a:locations, ' ') + " 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 @@ -74,7 +74,7 @@ function! ack#AckFromSearch(cmd, args) "{{{ endfunction "}}} function! ack#AckHelp(cmd, args) "{{{ - call ack#Ack(a:cmd, a:args, s:GetDocLocations()) + call ack#Ack(a:cmd, a:args, s:GetDocPaths()) endfunction "}}} function! ack#AckWindow(cmd, args) "{{{ @@ -136,7 +136,7 @@ function! s:ApplyMappings() "{{{ endif endfunction "}}} -function! s:GetDocLocations() "{{{ +function! s:GetDocPaths() "{{{ let dp = [] for p in split(&rtp, ',') let p = p . '/doc/'