From 225e6530c2b083e37744b23bac74ae40d7639d68 Mon Sep 17 00:00:00 2001 From: David Hegland Date: Thu, 27 May 2021 09:33:59 -0500 Subject: [PATCH] Fix for #750 to cleanup files once tagbar window closed (#769) Fixes #750 Once the tagbar window is opened and a file is registered, that file stays in memory even if the tagbar window is closed. This allows tagbar to cache the info so if the tagbar window is opened again, it doesn't have to rescan the file and rerun ctags on the file. However if this buffer is wiped out using `:bwipe `, then the buffer is completely unloaded from vim memory and also needs to be unloaded from tagbar memory. This works if the tagbar window is open, but in the event the tagbar window is closed, all autocmds are unregistered, so tagbar never gets the BufWipeout notification. This results in tagbar leaving the buffer in active memory even though the buffer doesn't exist anymore. This fix will leave the BufWipeout and BufDelete autocmds active even if the tagbar window is closed. This allows the buffer cleanup to occur on a `:bwipe` command even if the tagbar window is closed. --- autoload/tagbar.vim | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/autoload/tagbar.vim b/autoload/tagbar.vim index 09b6888..1da6055 100644 --- a/autoload/tagbar.vim +++ b/autoload/tagbar.vim @@ -582,8 +582,6 @@ function! s:CreateAutocommands() abort autocmd CursorHoldI * call \ s:AutoUpdate(fnamemodify(expand(''), ':p'), 0) endif - autocmd BufDelete,BufWipeout * - \ nested call s:HandleBufDelete(expand(''), expand('')) " Suspend Tagbar while grep commands are running, since we don't want " to process files that only get loaded temporarily to search them @@ -596,6 +594,15 @@ function! s:CreateAutocommands() abort endif augroup END + " Separate these autocmds out from the others as we want to always perform + " these actions even if the tagbar window closes. + augroup TagbarCleanupAutoCmds + if !g:tagbar_no_autocmds + autocmd BufDelete,BufWipeout * + \ nested call s:HandleBufDelete(expand(''), expand('')) + endif + augroup END + let s:autocommands_done = 1 endfunction