Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add live preview mode #279

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 45 additions & 4 deletions autoload/ack.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
"-----------------------------------------------------------------------------
Expand All @@ -110,9 +147,8 @@ function! s:ApplyMappings() "{{{
return
endif

let l:wintype = s:UsingLocList() ? 'l' : 'c'
let l:closemap = ':' . l:wintype . 'close<CR>'
let g:ack_mappings.q = l:closemap
let close = ":call ack#close(0)<CR>"
let g:ack_mappings.q = ":call ack#close(1)<CR>"

nnoremap <buffer> <silent> ? :call <SID>QuickHelp()<CR>

Expand All @@ -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 <buffer> <silent> j j<CR><C-W><C-P>
nnoremap <buffer> <silent> k k<CR><C-W><C-P>
nmap <buffer> <silent> <Down> j
nmap <buffer> <silent> <Up> k
elseif g:ackpreview == 2
nnoremap <buffer> <silent> j :call ack#preview()<CR>j
nnoremap <buffer> <silent> k :call ack#preview()<CR>k
nmap <buffer> <silent> <Down> j
nmap <buffer> <silent> <Up> k
endif
endfunction "}}}

Expand Down
7 changes: 6 additions & 1 deletion doc/ack.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions plugin/ack.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down