diff --git a/autoload/ack.vim b/autoload/ack.vim index b6afdba4..84be95b9 100644 --- a/autoload/ack.vim +++ b/autoload/ack.vim @@ -101,6 +101,43 @@ function! ack#ShowResults() "{{{ redraw! endfunction "}}} +function! ack#preview() + let idqf = line('.') - 1 + let pos = getqflist()[idqf] + let lnn = pos.lnum + + if lnn < 1 + let lnn = 1 + endif + + let fname = pos.bufnr + + if type(fname) == type(0) + let fname = bufname(fname) + endif + if fname == '%' + let fname = bufname('%') + endif + + if fname == '' + return + endif + + exec 'topleft pedit +' . lnn fname +endfunction + + +function! ack#close(q) + if g:ack_autoclose || a:q + let l:wintype = s:UsingLocList() ? 'l' : 'c' + let l:closemap = ':' . l:wintype . 'close' + execute l:closemap + endif + + if g:ackpreview == 2 + pclose + endif +endfunction "----------------------------------------------------------------------------- " Private API "----------------------------------------------------------------------------- @@ -110,9 +147,8 @@ function! s:ApplyMappings() "{{{ return endif - let l:wintype = s:UsingLocList() ? 'l' : 'c' - let l:closemap = ':' . l:wintype . 'close' - let g:ack_mappings.q = l:closemap + let close = ":call ack#close(0)" + let g:ack_mappings.q = ":call ack#close(1)" nnoremap ? :call QuickHelp() @@ -129,11 +165,16 @@ function! s:ApplyMappings() "{{{ endfor endif - if exists("g:ackpreview") " if auto preview in on, remap j and k keys + if g:ackpreview == 1 " if auto preview in on, remap j and k keys nnoremap j j nnoremap k k nmap j nmap k + elseif g:ackpreview == 2 + nnoremap j :call ack#preview()j + nnoremap k :call ack#preview()k + nmap j + nmap k endif endfunction "}}} diff --git a/doc/ack.txt b/doc/ack.txt index 22e884bc..3f3be6b8 100644 --- a/doc/ack.txt +++ b/doc/ack.txt @@ -199,11 +199,16 @@ Example: g:ackpreview Default: 0 -Use this option to automagically open the file with 'j' or 'k'. +Use this option to automagically open the file with 'j' or 'k'. By setting it +to 1, it will show it in the main window. If you set it to 2, it will show in +a +preview window. Example: > let g:ackpreview = 1 + " or + let g:ackpreview = 2 < *g:ack_use_dispatch* g:ack_use_dispatch diff --git a/plugin/ack.vim b/plugin/ack.vim index 202ae2ea..e02957c7 100644 --- a/plugin/ack.vim +++ b/plugin/ack.vim @@ -59,6 +59,10 @@ if !exists("g:ack_autoclose") let g:ack_autoclose = 0 endif +if !exists("g:ackpreview") + let g:ackpreview = 0 +endif + if !exists("g:ack_autofold_results") let g:ack_autofold_results = 0 endif