Separate shared and per-tagbar instance data

This commit is contained in:
Martin Vuille 2016-09-24 17:45:07 -04:00
parent 2955f71856
commit 7e35a40715

View File

@ -1572,7 +1572,7 @@ endfunction
" s:KindheaderTag.toggleFold() {{{3
function! s:KindheaderTag.toggleFold() abort dict
let fileinfo = s:known_files.getCurrent(0)
let fileinfo = s:state.getCurrent(0)
let fileinfo.kindfolds[self.short] = !fileinfo.kindfolds[self.short]
endfunction
@ -1702,15 +1702,14 @@ function! s:FileInfo.closeKindFold(kind) abort dict
let self.kindfolds[a:kind.short] = 1
endfunction
" Known files {{{2
let s:known_files = {
" Per-tagbar instance state {{{2
let s:state = {
\ '_current' : {},
\ '_paused' : {},
\ '_files' : {}
\ }
" s:known_files.getCurrent() {{{3
function! s:known_files.getCurrent(forcecurrent) abort dict
" s:state.getCurrent() {{{3
function! s:state.getCurrent(forcecurrent) abort dict
if !s:paused || a:forcecurrent
return self._current
else
@ -1718,16 +1717,21 @@ function! s:known_files.getCurrent(forcecurrent) abort dict
endif
endfunction
" s:known_files.setCurrent() {{{3
function! s:known_files.setCurrent(fileinfo) abort dict
" s:state.setCurrent() {{{3
function! s:state.setCurrent(fileinfo) abort dict
let self._current = a:fileinfo
endfunction
" s:known_files.setPaused() {{{3
function! s:known_files.setPaused() abort dict
" s:state.setPaused() {{{3
function! s:state.setPaused() abort dict
let self._paused = self._current
endfunction
" Known files {{{2
let s:known_files = {
\ '_files' : {}
\ }
" s:known_files.get() {{{3
function! s:known_files.get(fname) abort dict
return get(self._files, a:fname, {})
@ -1934,7 +1938,7 @@ function! s:CloseWindow() abort
if winbufnr(2) != -1
" Other windows are open, only close the tagbar one
let curfile = s:known_files.getCurrent(0)
let curfile = s:state.getCurrent(0)
close
@ -2036,7 +2040,7 @@ endfunction
" the current file after startup.
function! s:CorrectFocusOnStartup() abort
if bufwinnr('__Tagbar__') != -1 && !g:tagbar_autofocus && !s:last_autofocus
let curfile = s:known_files.getCurrent(1)
let curfile = s:state.getCurrent(1)
if !empty(curfile) && curfile.fpath != fnamemodify(bufname('%'), ':p')
let winnr = bufwinnr(curfile.fpath)
if winnr != -1
@ -2633,7 +2637,7 @@ endfunction
" s:ToggleSort() {{{2
function! s:ToggleSort() abort
let fileinfo = s:known_files.getCurrent(0)
let fileinfo = s:state.getCurrent(0)
if empty(fileinfo)
return
endif
@ -2675,7 +2679,7 @@ function! s:RenderContent(...) abort
if a:0 == 1
let fileinfo = a:1
else
let fileinfo = s:known_files.getCurrent(0)
let fileinfo = s:state.getCurrent(0)
endif
if empty(fileinfo)
@ -2700,8 +2704,8 @@ function! s:RenderContent(...) abort
call s:goto_win(tagbarwinnr, 1)
endif
if !empty(s:known_files.getCurrent(0)) &&
\ fileinfo.fpath ==# s:known_files.getCurrent(0).fpath
if !empty(s:state.getCurrent(0)) &&
\ fileinfo.fpath ==# s:state.getCurrent(0).fpath
" We're redisplaying the same file, so save the view
call s:debug('Redisplaying file [' . fileinfo.fpath . ']')
let saveline = line('.')
@ -2745,8 +2749,8 @@ function! s:RenderContent(...) abort
setlocal nomodifiable
if !empty(s:known_files.getCurrent(0)) &&
\ fileinfo.fpath ==# s:known_files.getCurrent(0).fpath
if !empty(s:state.getCurrent(0)) &&
\ fileinfo.fpath ==# s:state.getCurrent(0).fpath
let scrolloff_save = &scrolloff
set scrolloff=0
@ -3246,7 +3250,7 @@ endfunction
" Folding {{{1
" s:OpenFold() {{{2
function! s:OpenFold() abort
let fileinfo = s:known_files.getCurrent(0)
let fileinfo = s:state.getCurrent(0)
if empty(fileinfo)
return
endif
@ -3265,7 +3269,7 @@ endfunction
" s:CloseFold() {{{2
function! s:CloseFold() abort
let fileinfo = s:known_files.getCurrent(0)
let fileinfo = s:state.getCurrent(0)
if empty(fileinfo)
return
endif
@ -3286,7 +3290,7 @@ endfunction
" s:ToggleFold() {{{2
function! s:ToggleFold() abort
let fileinfo = s:known_files.getCurrent(0)
let fileinfo = s:state.getCurrent(0)
if empty(fileinfo)
return
endif
@ -3322,7 +3326,7 @@ function! s:SetFoldLevel(level, force) abort
return
endif
let fileinfo = s:known_files.getCurrent(0)
let fileinfo = s:state.getCurrent(0)
if empty(fileinfo)
return
endif
@ -3518,8 +3522,8 @@ function! s:AutoUpdate(fname, force) abort
" file is being displayed
if bufwinnr('__Tagbar__') != -1 && !s:paused &&
\ (s:new_window || updated ||
\ (!empty(s:known_files.getCurrent(0)) &&
\ a:fname != s:known_files.getCurrent(0).fpath))
\ (!empty(s:state.getCurrent(0)) &&
\ a:fname != s:state.getCurrent(0).fpath))
call s:RenderContent(fileinfo)
endif
@ -3527,7 +3531,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:known_files.setCurrent(fileinfo)
call s:state.setCurrent(fileinfo)
let s:nearby_disabled = 0
endif
@ -3743,7 +3747,7 @@ function! s:GetNearbyTag(all, forcecurrent, ...) abort
return {}
endif
let fileinfo = s:known_files.getCurrent(a:forcecurrent)
let fileinfo = s:state.getCurrent(a:forcecurrent)
if empty(fileinfo)
return {}
endif
@ -3779,7 +3783,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:known_files.getCurrent(0)
let fileinfo = s:state.getCurrent(0)
if empty(fileinfo)
return {}
@ -3865,7 +3869,7 @@ endfunction
" s:ToggleHideNonPublicTags() {{{2
function! s:ToggleHideNonPublicTags() abort
let fileinfo = s:known_files.getCurrent(0)
let fileinfo = s:state.getCurrent(0)
if empty(fileinfo)
return
endif
@ -3891,7 +3895,7 @@ endfunction
" s:ToggleCaseInsensitive() {{{2
function! s:ToggleCaseInsensitive() abort
let fileinfo = s:known_files.getCurrent(0)
let fileinfo = s:state.getCurrent(0)
if empty(fileinfo)
return
endif
@ -3978,8 +3982,8 @@ function! s:SetStatusLine()
let sort = g:tagbar_sort ? 'Name' : 'Order'
if !empty(s:known_files.getCurrent(0))
let fname = fnamemodify(s:known_files.getCurrent(0).fpath, ':t')
if !empty(s:state.getCurrent(0))
let fname = fnamemodify(s:state.getCurrent(0).fpath, ':t')
else
let fname = ''
endif
@ -4236,7 +4240,7 @@ function! tagbar#toggle_pause() abort
let s:paused = !s:paused
if s:paused
call s:known_files.setPaused()
call s:state.setPaused()
else
call s:AutoUpdate(fnamemodify(expand('%'), ':p'), 1)
endif
@ -4317,8 +4321,8 @@ endfunction
function! tagbar#currentfile() abort
let filename = ''
if !empty(s:known_files.getCurrent(1))
let filename = fnamemodify(s:known_files.getCurrent(1).fpath, ':t')
if !empty(s:state.getCurrent(1))
let filename = fnamemodify(s:state.getCurrent(1).fpath, ':t')
endif
return filename