Created
November 17, 2015 20:25
-
-
Save davidosomething/d2e061dbd7c290966328 to your computer and use it in GitHub Desktop.
Try to fix loclist associations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let t:dko_fixing = 0 | |
let t:dko_moving = 0 | |
let t:dko_correcting = 0 | |
let t:dko_last_window = winnr() | |
" Remember what window you came from when you leave a normal buffer | |
function! s:DKO_Remember_Window() | |
if &buftype != '' | return | endif | |
let t:dko_last_window = winnr() | |
endfunction | |
function! s:DKO_Correct_Quickfix_On_WinLeave() | |
" coming from quickfix, go up to its parent | |
if &buftype == 'quickfix' | |
let t:dko_correcting = 1 | |
return | |
endif | |
let t:dko_moving = 1 | |
endfunction | |
" Empty loclist of previous buffer when you enter a normal buffer | |
function! s:DKO_Correct_Quickfix_On_WinEnter() | |
if t:dko_fixing == 1 | |
return | |
endif | |
if t:dko_moving == 1 | |
let t:dko_moving = 0 | |
" moving to a quickfix window intentionally | |
if &buftype == 'quickfix' | |
return | |
endif | |
endif | |
" should be in a normal buffer now | |
" go to previous normal window and fix its loclist | |
let t:dko_fixing = 1 | |
let t:dko_this_window = winnr() | |
call input('going to last') | |
execute t:dko_last_window . 'wincmd w' | |
call input('closing l') | |
lclose | |
call input('reopening l') | |
if len(getloclist(0)) | |
execute 'lopen ' . g:dko_loc_list_height | |
endif | |
" return to the intended new window | |
call input('back to intended') | |
execute t:dko_this_window . 'wincmd w' | |
let t:dko_fixing = 0 | |
endfunction | |
" Remember last window when you switch | |
autocmd vimrc WinEnter * call s:DKO_Correct_Quickfix_On_WinEnter() | |
autocmd vimrc WinLeave * call s:DKO_Correct_Quickfix_On_WinLeave() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment