Give each tab its own tagbar instance data

This commit is contained in:
Martin Vuille 2016-09-24 17:49:35 -04:00
parent 7c56066685
commit 1e5b704e09

View File

@ -1574,7 +1574,7 @@ endfunction
" s:KindheaderTag.toggleFold() {{{3
function! s:KindheaderTag.toggleFold() abort dict
let fileinfo = s:state.getCurrent(0)
let fileinfo = s:TagbarState().getCurrent(0)
let fileinfo.kindfolds[self.short] = !fileinfo.kindfolds[self.short]
endfunction
@ -1704,12 +1704,17 @@ function! s:FileInfo.closeKindFold(kind) abort dict
let self.kindfolds[a:kind.short] = 1
endfunction
" Per-tagbar instance state {{{2
" Per-tagbar instance state prototype {{{2
let s:state = {
\ '_current' : {},
\ '_paused' : {},
\ }
" s:state.New() {{{3
function! s:state.New() abort dict
return deepcopy(self)
endfunction
" s:state.getCurrent() {{{3
function! s:state.getCurrent(forcecurrent) abort dict
if !s:paused || a:forcecurrent
@ -1940,7 +1945,7 @@ function! s:CloseWindow() abort
if winbufnr(2) != -1
" Other windows are open, only close the tagbar one
let curfile = s:state.getCurrent(0)
let curfile = s:TagbarState().getCurrent(0)
close
@ -2042,7 +2047,7 @@ endfunction
" the current file after startup.
function! s:CorrectFocusOnStartup() abort
if bufwinnr(s:TagbarBufName()) != -1 && !g:tagbar_autofocus && !s:last_autofocus
let curfile = s:state.getCurrent(1)
let curfile = s:TagbarState().getCurrent(1)
if !empty(curfile) && curfile.fpath != fnamemodify(bufname('%'), ':p')
let winnr = bufwinnr(curfile.fpath)
if winnr != -1
@ -2639,7 +2644,7 @@ endfunction
" s:ToggleSort() {{{2
function! s:ToggleSort() abort
let fileinfo = s:state.getCurrent(0)
let fileinfo = s:TagbarState().getCurrent(0)
if empty(fileinfo)
return
endif
@ -2681,7 +2686,7 @@ function! s:RenderContent(...) abort
if a:0 == 1
let fileinfo = a:1
else
let fileinfo = s:state.getCurrent(0)
let fileinfo = s:TagbarState().getCurrent(0)
endif
if empty(fileinfo)
@ -2706,8 +2711,8 @@ function! s:RenderContent(...) abort
call s:goto_win(tagbarwinnr, 1)
endif
if !empty(s:state.getCurrent(0)) &&
\ fileinfo.fpath ==# s:state.getCurrent(0).fpath
if !empty(s:TagbarState().getCurrent(0)) &&
\ fileinfo.fpath ==# s:TagbarState().getCurrent(0).fpath
" We're redisplaying the same file, so save the view
call s:debug('Redisplaying file [' . fileinfo.fpath . ']')
let saveline = line('.')
@ -2751,8 +2756,8 @@ function! s:RenderContent(...) abort
setlocal nomodifiable
if !empty(s:state.getCurrent(0)) &&
\ fileinfo.fpath ==# s:state.getCurrent(0).fpath
if !empty(s:TagbarState().getCurrent(0)) &&
\ fileinfo.fpath ==# s:TagbarState().getCurrent(0).fpath
let scrolloff_save = &scrolloff
set scrolloff=0
@ -3252,7 +3257,7 @@ endfunction
" Folding {{{1
" s:OpenFold() {{{2
function! s:OpenFold() abort
let fileinfo = s:state.getCurrent(0)
let fileinfo = s:TagbarState().getCurrent(0)
if empty(fileinfo)
return
endif
@ -3271,7 +3276,7 @@ endfunction
" s:CloseFold() {{{2
function! s:CloseFold() abort
let fileinfo = s:state.getCurrent(0)
let fileinfo = s:TagbarState().getCurrent(0)
if empty(fileinfo)
return
endif
@ -3292,7 +3297,7 @@ endfunction
" s:ToggleFold() {{{2
function! s:ToggleFold() abort
let fileinfo = s:state.getCurrent(0)
let fileinfo = s:TagbarState().getCurrent(0)
if empty(fileinfo)
return
endif
@ -3328,7 +3333,7 @@ function! s:SetFoldLevel(level, force) abort
return
endif
let fileinfo = s:state.getCurrent(0)
let fileinfo = s:TagbarState().getCurrent(0)
if empty(fileinfo)
return
endif
@ -3524,8 +3529,8 @@ function! s:AutoUpdate(fname, force) abort
" file is being displayed
if bufwinnr(s:TagbarBufName()) != -1 && !s:paused &&
\ (s:new_window || updated ||
\ (!empty(s:state.getCurrent(0)) &&
\ a:fname != s:state.getCurrent(0).fpath))
\ (!empty(s:TagbarState().getCurrent(0)) &&
\ a:fname != s:TagbarState().getCurrent(0).fpath))
call s:RenderContent(fileinfo)
endif
@ -3533,7 +3538,7 @@ function! s:AutoUpdate(fname, force) abort
" same file is being redisplayed
if !empty(fileinfo)
call s:debug('Setting current file [' . a:fname . ']')
call s:state.setCurrent(fileinfo)
call s:TagbarState().setCurrent(fileinfo)
let s:nearby_disabled = 0
endif
@ -3749,7 +3754,7 @@ function! s:GetNearbyTag(all, forcecurrent, ...) abort
return {}
endif
let fileinfo = s:state.getCurrent(a:forcecurrent)
let fileinfo = s:TagbarState().getCurrent(a:forcecurrent)
if empty(fileinfo)
return {}
endif
@ -3785,7 +3790,7 @@ endfunction
" does not contain a valid tag (for example because it is empty or only
" contains a pseudo-tag) return an empty dictionary.
function! s:GetTagInfo(linenr, ignorepseudo) abort
let fileinfo = s:state.getCurrent(0)
let fileinfo = s:TagbarState().getCurrent(0)
if empty(fileinfo)
return {}
@ -3871,7 +3876,7 @@ endfunction
" s:ToggleHideNonPublicTags() {{{2
function! s:ToggleHideNonPublicTags() abort
let fileinfo = s:state.getCurrent(0)
let fileinfo = s:TagbarState().getCurrent(0)
if empty(fileinfo)
return
endif
@ -3897,7 +3902,7 @@ endfunction
" s:ToggleCaseInsensitive() {{{2
function! s:ToggleCaseInsensitive() abort
let fileinfo = s:state.getCurrent(0)
let fileinfo = s:TagbarState().getCurrent(0)
if empty(fileinfo)
return
endif
@ -3984,8 +3989,8 @@ function! s:SetStatusLine()
let sort = g:tagbar_sort ? 'Name' : 'Order'
if !empty(s:state.getCurrent(0))
let fname = fnamemodify(s:state.getCurrent(0).fpath, ':t')
if !empty(s:TagbarState().getCurrent(0))
let fname = fnamemodify(s:TagbarState().getCurrent(0).fpath, ':t')
else
let fname = ''
endif
@ -4084,6 +4089,7 @@ function! s:NextNormalWindow() abort
return -1
endfunction
" s:TagbarBufName() {{{2
function! s:TagbarBufName() abort
if !exists('t:tagbar_buf_name')
let s:buffer_seqno += 1
@ -4093,6 +4099,15 @@ function! s:TagbarBufName() abort
return t:tagbar_buf_name
endfunction
" s:TagbarState() {{{2
function! s:TagbarState() abort
if !exists('t:tagbar_state')
let t:tagbar_state = s:state.New()
endif
return t:tagbar_state
endfunction
" s:goto_win() {{{2
function! s:goto_win(winnr, ...) abort
let cmd = type(a:winnr) == type(0) ? a:winnr . 'wincmd w'
@ -4251,7 +4266,7 @@ function! tagbar#toggle_pause() abort
let s:paused = !s:paused
if s:paused
call s:state.setPaused()
call s:TagbarState().setPaused()
else
call s:AutoUpdate(fnamemodify(expand('%'), ':p'), 1)
endif
@ -4332,8 +4347,8 @@ endfunction
function! tagbar#currentfile() abort
let filename = ''
if !empty(s:state.getCurrent(1))
let filename = fnamemodify(s:state.getCurrent(1).fpath, ':t')
if !empty(s:TagbarState().getCurrent(1))
let filename = fnamemodify(s:TagbarState().getCurrent(1).fpath, ':t')
endif
return filename