autocommands: check for existence of airline highlight group

Several extensions trigger custom actions. Make sure, those actions are
only performed, if airline is actually active and not temporarily
disabled using e.g. :AirlineToggle
This commit is contained in:
Christian Brabandt 2021-04-30 13:25:26 +02:00
parent 06134df810
commit 2e9df43962
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09
15 changed files with 79 additions and 10 deletions

View File

@ -128,6 +128,10 @@ function! airline#extensions#ale#init(ext)
endfunction
function! s:ale_refresh()
if !exists('#airline')
" airline disabled
return
endif
if get(g:, 'airline_skip_empty_sections', 0)
exe ':AirlineRefresh!'
endif

View File

@ -325,6 +325,10 @@ endfunction
function! s:reset_untracked_cache(shellcmdpost)
" shellcmdpost - whether function was called as a result of ShellCmdPost hook
if !exists('#airline')
" airline disabled
return
endif
if !g:airline#init#vim_async && !has('nvim')
if a:shellcmdpost
" Clear cache only if there was no error or the script uses an
@ -346,11 +350,17 @@ function! s:reset_untracked_cache(shellcmdpost)
endfor
endfunction
function! s:sh_autocmd_handler()
if exists('#airline')
unlet! b:airline_head b:airline_do_mq_check
endif
endfunction
function! airline#extensions#branch#init(ext)
call airline#parts#define_function('branch', 'airline#extensions#branch#get_head')
autocmd ShellCmdPost,CmdwinLeave * unlet! b:airline_head b:airline_do_mq_check
autocmd User AirlineBeforeRefresh unlet! b:airline_head b:airline_do_mq_check
autocmd ShellCmdPost,CmdwinLeave * call s:sh_autocmd_handler()
autocmd User AirlineBeforeRefresh call s:sh_autocmd_handler()
autocmd BufWritePost * call s:reset_untracked_cache(0)
autocmd ShellCmdPost * call s:reset_untracked_cache(1)
endfunction

View File

@ -107,6 +107,10 @@ augroup airline#extensions#cursormode
augroup END
function! airline#extensions#cursormode#activate()
if !exists('#airline')
" airline disabled
return
endif
let s:color_map = s:get_color_map()
call airline#extensions#cursormode#set()
endfunction

View File

@ -43,6 +43,12 @@ function! airline#extensions#fugitiveline#bufname()
endif
endfunction
function! s:sh_autocmd_handler()
if exists('#airline')
unlet! b:fugitive_name
endif
endfunction
function! airline#extensions#fugitiveline#init(ext)
if exists("+autochdir") && &autochdir
" if 'acd' is set, vim-airline uses the path section, so we need to redefine this here as well
@ -50,6 +56,6 @@ function! airline#extensions#fugitiveline#init(ext)
else
call airline#parts#define_raw('file', '%<%{airline#extensions#fugitiveline#bufname()}%m')
endif
autocmd ShellCmdPost,CmdwinLeave * unlet! b:fugitive_name
autocmd User AirlineBeforeRefresh unlet! b:fugitive_name
autocmd ShellCmdPost,CmdwinLeave * call s:sh_autocmd_handler()
autocmd User AirlineBeforeRefresh call s:sh_autocmd_handler()
endfunction

View File

@ -35,6 +35,10 @@ function! s:record_diagnostics(state)
endfunction
function! s:get_diagnostics()
if !exists('#airline')
" airline disabled
return
endif
call LanguageClient#getState(function("s:record_diagnostics"))
endfunction

View File

@ -88,6 +88,10 @@ endfunction
let s:timer = 0
let s:ignore_time = 0
function! airline#extensions#lsp#update() abort
if !exists('#airline')
" airline disabled
return
endif
if reltimefloat(reltime()) - s:ignore_time >=
\ get(g:, 'airline#extensions#lsp#progress_skip_time', 0.3)
\ || len(s:lsp_progress) == 0

View File

@ -43,6 +43,10 @@ function! airline#extensions#po#shorten()
endfunction
function! airline#extensions#po#on_winenter()
if !exists('#airline')
" airline disabled
return
endif
" only reset cache, if the window size changed
if get(b:, 'airline_winwidth', 0) != airline#util#winwidth()
let b:airline_winwidth = airline#util#winwidth()
@ -51,11 +55,17 @@ function! airline#extensions#po#on_winenter()
endif
endfunction
function! s:autocmd_handler()
if exists('#airline')
unlet! b:airline_po_stats
endif
endfunction
function! airline#extensions#po#apply(...)
if &ft ==# 'po'
call airline#extensions#prepend_to_section('z', '%{airline#extensions#po#stats()}')
" Also reset the cache variable, if a window has been split, e.g. the winwidth changed
autocmd airline BufWritePost * unlet! b:airline_po_stats
autocmd airline BufWritePost * call s:autocmd_handler()
autocmd airline WinEnter * call airline#extensions#po#on_winenter()
endif
endfunction

View File

@ -8,6 +8,10 @@ function! airline#extensions#tabline#buflist#invalidate()
endfunction
function! airline#extensions#tabline#buflist#clean()
if !exists('#airline')
" airline disabled
return
endif
call airline#extensions#tabline#buflist#invalidate()
call airline#extensions#tabline#buffers#invalidate()
endfunction

View File

@ -24,6 +24,9 @@ function! airline#extensions#tabline#ctrlspace#on()
endfunction
function! airline#extensions#tabline#ctrlspace#invalidate()
if !exists('#airline')
return
endif
let s:current_bufnr = -1
let s:current_tabnr = -1
endfunction

View File

@ -22,7 +22,9 @@ function! airline#extensions#tabline#tabs#on()
endfunction
function! airline#extensions#tabline#tabs#invalidate()
let s:current_bufnr = -1
if exists('#airline')
let s:current_bufnr = -1
endif
endfunction
function! airline#extensions#tabline#tabs#get()

View File

@ -24,8 +24,10 @@ function! airline#extensions#tabline#tabws#on()
endfunction
function! airline#extensions#tabline#tabws#invalidate()
let s:current_bufnr = -1
let s:current_tabnr = -1
if exists('#airline')
let s:current_bufnr = -1
let s:current_tabnr = -1
endif
endfunction
function! airline#extensions#tabline#tabws#add_buffer_section(builder, cur_tab, cur_buf, pull_right)

View File

@ -44,7 +44,7 @@ function! airline#extensions#tabline#xtabline#init()
autocmd TabLeave * call s:Do('leave')
autocmd TabClosed * call s:Do('close')
autocmd BufEnter * let g:xtabline_changing_buffer = 0
autocmd BufEnter * if exists('#airline') | let g:xtabline_changing_buffer = 0 | endif
autocmd BufAdd,BufDelete,BufWrite * call airline#extensions#tabline#xtabline#filter_buffers()
augroup END
@ -180,6 +180,10 @@ function! airline#extensions#tabline#xtabline#filter_buffers()
" 'accepted' is a list of buffer numbers, for quick access.
" 'excluded' is a list of buffer numbers, it will be used by Airline to hide buffers.
if !exists('#airline')
" airline disabled
return
endif
if !s:xtabline_filtering | return | endif
let g:airline#extensions#tabline#exclude_buffers = []
@ -351,6 +355,10 @@ endfunction
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! s:Do(action)
if !exists('#airline')
" airline disabled
return
endif
let arg = a:action
if !s:state | call s:InitCwds() | return | endif

View File

@ -183,6 +183,10 @@ function! airline#extensions#whitespace#init(...)
endfunction
function! s:ws_refresh()
if !exists('#airline')
" airline disabled
return
endif
if get(b:, 'airline_ws_changedtick', 0) == b:changedtick
return
endif

View File

@ -174,6 +174,10 @@ function! airline#util#has_custom_scm()
endfunction
function! airline#util#doautocmd(event)
if !exists('#airline')
" airline disabled
return
endif
exe printf("silent doautocmd %s User %s", s:nomodeline, a:event)
endfunction

View File

@ -230,7 +230,7 @@ function! s:airline_refresh(...)
endfunction
function! s:FocusGainedHandler(timer)
if exists("s:timer") && a:timer == s:timer
if exists("s:timer") && a:timer == s:timer && exists('#airline')
augroup airline
au FocusGained * call s:on_focus_gained()
augroup END