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

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
This commit is contained in:
raven42
2021-01-12 07:41:38 -06:00
committed by GitHub
parent 2a36ad79a7
commit e6e6582739
3 changed files with 60 additions and 33 deletions

View File

@@ -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('<amatch>') !~ '__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('<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
\ s:AutoUpdate(fnamemodify(expand('<afile>'), ':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('<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
\ s:AutoUpdate(fnamemodify(expand('<afile>'), ':p'), 0)
if g:tagbar_highlight_follow_insert
autocmd CursorHoldI * call
\ s:AutoUpdate(fnamemodify(expand('<afile>'), ':p'), 0)
endif
autocmd BufDelete,BufWipeout *
\ nested call s:HandleBufDelete(expand('<afile>'), expand('<abuf>'))
" 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('<afile>'), expand('<abuf>'))
" 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

View File

@@ -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~

View File

@@ -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', {}],