From e6e658273961aa80d746757beabc2ede1f973193 Mon Sep 17 00:00:00 2001 From: raven42 Date: Tue, 12 Jan 2021 07:41:38 -0600 Subject: [PATCH] Add `g:tagbar_no_autocmds` option to disable almost all autocmds (#688) * Closed #578 - Add `g:tagbar_no_autocmds` option to disable almost all autocommands * Rework to be more streamlined --- autoload/tagbar.vim | 77 ++++++++++++++++++++++++++------------------- doc/tagbar.txt | 15 +++++++++ plugin/tagbar.vim | 1 + 3 files changed, 60 insertions(+), 33 deletions(-) diff --git a/autoload/tagbar.vim b/autoload/tagbar.vim index 2582999..08fd238 100644 --- a/autoload/tagbar.vim +++ b/autoload/tagbar.vim @@ -548,16 +548,6 @@ function! s:CreateAutocommands() abort augroup TagbarAutoCmds autocmd! - if !g:tagbar_silent - autocmd CursorHold __Tagbar__.* call s:ShowPrototype(1) - endif - autocmd WinEnter __Tagbar__.* call s:SetStatusLine() - autocmd WinLeave __Tagbar__.* call s:SetStatusLine() - - if g:tagbar_autopreview - autocmd CursorMoved __Tagbar__.* nested call s:ShowInPreviewWin() - endif - autocmd BufEnter * if expand('') !~ '__Tagbar__.*' | \ let s:last_alt_bufnr = bufnr('#') | \ endif @@ -565,32 +555,45 @@ function! s:CreateAutocommands() abort autocmd QuitPre * let s:vim_quitting = 1 endif autocmd WinEnter * nested call s:HandleOnlyWindow() - autocmd WinEnter * if bufwinnr(s:TagbarBufName()) == -1 | - \ call s:ShrinkIfExpanded() | - \ endif - autocmd BufWritePost * - \ call s:HandleBufWrite(fnamemodify(expand(''), ':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 - \ s:AutoUpdate(fnamemodify(expand(''), ':p'), 0) - if g:tagbar_highlight_follow_insert - autocmd CursorHoldI * call + if !g:tagbar_no_autocmds + if !g:tagbar_silent + autocmd CursorHold __Tagbar__.* call s:ShowPrototype(1) + endif + autocmd WinEnter __Tagbar__.* call s:SetStatusLine() + autocmd WinLeave __Tagbar__.* call s:SetStatusLine() + + if g:tagbar_autopreview + autocmd CursorMoved __Tagbar__.* nested call s:ShowInPreviewWin() + endif + + autocmd WinEnter * if bufwinnr(s:TagbarBufName()) == -1 | + \ call s:ShrinkIfExpanded() | + \ endif + + autocmd BufWritePost * + \ call s:HandleBufWrite(fnamemodify(expand(''), ':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 \ s:AutoUpdate(fnamemodify(expand(''), ':p'), 0) + if g:tagbar_highlight_follow_insert + 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 + autocmd QuickFixCmdPre *grep* let s:tagbar_qf_active = 1 + autocmd QuickFixCmdPost *grep* if exists('s:tagbar_qf_active') | + \ unlet s:tagbar_qf_active | + \ endif + + autocmd VimEnter * call s:CorrectFocusOnStartup() 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 - autocmd QuickFixCmdPre *grep* let s:tagbar_qf_active = 1 - autocmd QuickFixCmdPost *grep* if exists('s:tagbar_qf_active') | - \ unlet s:tagbar_qf_active | - \ endif - - autocmd VimEnter * call s:CorrectFocusOnStartup() augroup END let s:autocommands_done = 1 @@ -2209,6 +2212,14 @@ endfunction " User actions {{{1 " s:HighlightTag() {{{2 function! s:HighlightTag(openfolds, ...) abort + + if g:tagbar_no_autocmds + " If no autocmds are enabled, then it doesn't make sense to highlight + " anything as the cursor can move around and any highlighting would be + " inaccurate + return + endif + let tagline = 0 let force = a:0 > 0 ? a:1 : 0 diff --git a/doc/tagbar.txt b/doc/tagbar.txt index 47cbd49..fe3e3ae 100644 --- a/doc/tagbar.txt +++ b/doc/tagbar.txt @@ -1055,6 +1055,21 @@ wrap intentation to function. Example: > let g:tagbar_wrap = 1 +< + *g:tagbar_no_autocmds* +g:tagbar_no_autocmds~ +Default: 0 + +If set to non-zero, tagbar will not enable any autocmds. Note: This greatly +limits what tagbar can do. When activated, it will generate the tags once and +display the contents once. You can use |:TagbarForceUpdate| to manually update +the tagbar window if this is activated. There will only be two autocmds +created in the tagbar autocmd group to handle closing the tagbar window +automatically on the QuitPre event. + +Example: +> + let g:tagbar_no_autocmds = 1 < *g:tagbar_scrolloff* g:tagbar_scrolloff~ diff --git a/plugin/tagbar.vim b/plugin/tagbar.vim index c93077d..fce4a0b 100644 --- a/plugin/tagbar.vim +++ b/plugin/tagbar.vim @@ -103,6 +103,7 @@ function! s:setup_options() abort \ ['highlight_follow_insert', 0], \ ['highlight_method', 'nearest-stl'], \ ['ignore_anonymous', 0], + \ ['no_autocmds', 0], \ ['position', default_pos], \ ['previewwin_pos', previewwin_pos], \ ['scopestrs', {}],