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

Restore previous window(s) with lwindow/cwindow #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
35 changes: 35 additions & 0 deletions autoload/qf.vim
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,56 @@ function! qf#GetEntryPath(line) abort
return substitute(a:line, '|.*$', '', '')
endfunction

let s:prev_windows = []
function! s:save_prev_windows() abort
let aw = winnr('#')
let pw = winnr()
if exists('*win_getid')
let aw_id = win_getid(aw)
let pw_id = win_getid(pw)
else
let aw_id = 0
let pw_id = 0
endif
call add(s:prev_windows, [aw, pw, aw_id, pw_id])
endfunction

function! s:restore_prev_windows() abort
let [aw, pw, aw_id, pw_id] = remove(s:prev_windows, 0)
if winnr() != pw
" Go back, maintaining the '#' window (CTRL-W_p).
if pw_id
let aw = win_id2win(aw_id)
let pw = win_id2win(pw_id)
endif
if pw
if aw
exec aw . 'wincmd w'
endif
exec pw . 'wincmd w'
endif
endif
endfunction

" open the quickfix window if there are valid errors
function! qf#OpenQuickfix()
if get(g:, 'qf_auto_open_quickfix', 1)
call s:save_prev_windows()
" get user-defined maximum height
let max_height = get(g:, 'qf_max_height', 10) < 1 ? 10 : get(g:, 'qf_max_height', 10)
execute get(g:, "qf_auto_resize", 1) ? 'cclose|' . min([ max_height, len(getqflist()) ]) . 'cwindow' : 'cwindow'
call s:restore_prev_windows()
endif
endfunction

" open a location window if there are valid locations
function! qf#OpenLoclist()
if get(g:, 'qf_auto_open_loclist', 1)
call s:save_prev_windows()
" get user-defined maximum height
let max_height = get(g:, 'qf_max_height', 10) < 1 ? 10 : get(g:, 'qf_max_height', 10)
execute get(g:, "qf_auto_resize", 1) ? 'lclose|' . min([ max_height, len(getloclist(0)) ]) . 'lwindow' : 'lwindow'
call s:restore_prev_windows()
endif
endfunction

Expand Down