1
0
mirror of https://github.com/gryf/tagbar.git synced 2025-12-17 11:30:28 +01:00

Update tags on CursorHold after writing

Currently the tags will always get updated immediately when writing a
file. However, for large files that can slow down the writing process
noticeably, leading to annoying pauses. This commit instead defers the
updating process to the first CursorHold/CursorHoldI event after writing
a file, which should make the process much less noticeable.

Closes #289
Closes #381
References SpaceVim/SpaceVim#129
This commit is contained in:
Jan Larres
2017-02-05 18:51:28 +13:00
parent 72a7ef378f
commit 68eebbb50c

View File

@@ -76,6 +76,8 @@ let s:window_pos = {
\ 'post' : { 'x' : 0, 'y' : 0 }
\}
let s:delayed_update_files = []
" Script-local variable needed since compare functions can't
" take extra arguments
let s:compare_typeinfo = {}
@@ -1082,8 +1084,9 @@ function! s:CreateAutocommands() abort
\ call s:ShrinkIfExpanded() |
\ endif
autocmd BufWritePost * call
\ s:AutoUpdate(fnamemodify(expand('<afile>'), ':p'), 1)
autocmd BufWritePost *
\ call s:HandleBufWrite(fnamemodify(expand('<afile>'), ':p'))
autocmd CursorHold,CursorHoldI * call s:do_delayed_update()
" BufReadPost is needed for reloading the current buffer if the file
" was changed by an external command; see commit 17d199f
autocmd BufReadPost,BufEnter,CursorHold,FileType * call
@@ -3578,9 +3581,13 @@ endfunction
" Helper functions {{{1
" s:AutoUpdate() {{{2
function! s:AutoUpdate(fname, force) abort
function! s:AutoUpdate(fname, force, ...) abort
call s:debug('AutoUpdate called [' . a:fname . ']')
" Whether we want to skip actually displaying the tags in Tagbar and only
" update the fileinfo
let no_display = a:0 > 0 ? a:1 : 0
" This file is being loaded due to a quickfix command like vimgrep, so
" don't process it
if exists('s:tagbar_qf_active')
@@ -3641,6 +3648,10 @@ function! s:AutoUpdate(fname, force) abort
let updated = 1
endif
if no_display
return
endif
let fileinfo = s:known_files.get(a:fname)
" If we don't have an entry for the file by now something must have gone
@@ -4250,6 +4261,29 @@ function! s:HandleBufDelete(bufname, bufnr) abort
endif
endfunction
" s:HandleBufWrite() {{{2
function! s:HandleBufWrite(fname) abort
if index(s:delayed_update_files, a:fname) == -1
call add(s:delayed_update_files, a:fname)
endif
endfunction
" s:do_delayed_update() {{{2
function! s:do_delayed_update() abort
let curfile = s:TagbarState().getCurrent(0)
if empty(curfile)
let curfname = ''
else
let curfname = curfile.fpath
endif
while !empty(s:delayed_update_files)
let fname = remove(s:delayed_update_files, 0)
let no_display = curfname !=# fname
call s:AutoUpdate(fname, 1, no_display)
endwhile
endfunction
" s:ReopenWindow() {{{2
function! s:ReopenWindow(delbufname) abort
if expand('<amatch>') == a:delbufname