From 8662779debf47125dffd390dc7db9e1c40efb3b5 Mon Sep 17 00:00:00 2001 From: Jan Larres Date: Wed, 25 May 2011 15:18:26 +1200 Subject: [PATCH] Properly restore Tagbar after a session got loaded --- plugin/tagbar.vim | 74 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 56 insertions(+), 18 deletions(-) diff --git a/plugin/tagbar.vim b/plugin/tagbar.vim index 6c35b8e..29e7841 100644 --- a/plugin/tagbar.vim +++ b/plugin/tagbar.vim @@ -136,6 +136,8 @@ let s:access_symbols = { \ 'private' : '-' \ } +autocmd SessionLoadPost * nested call s:RestoreSession() + " s:InitTypes() {{{2 function! s:InitTypes() let s:known_types = {} @@ -831,6 +833,42 @@ function! s:GetUserTypeDefs() return defdict endfunction +" s:RestoreSession() {{{2 +" Properly restore Tagbar after a session got loaded +function! s:RestoreSession() + let tagbarwinnr = bufwinnr('__Tagbar__') + if tagbarwinnr == -1 + " Tagbar wasn't open in the saved session, nothing to do + return + else + let in_tagbar = 1 + if winnr() != tagbarwinnr + execute tagbarwinnr . 'wincmd w' + let in_tagbar = 0 + endif + endif + + if !s:type_init_done + call s:InitTypes() + endif + + if !s:checked_ctags + if !s:CheckForExCtags() + return + endif + endif + + call s:InitWindow(g:tagbar_autoclose) + + " Leave the Tagbar window and come back so the update event gets triggered + execute 'wincmd p' + execute tagbarwinnr . 'wincmd w' + + if !in_tagbar + execute 'wincmd p' + endif +endfunction + " s:MapKeys() {{{2 function! s:MapKeys() nnoremap