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 endfunction
function! s:ale_refresh() function! s:ale_refresh()
if !exists('#airline')
" airline disabled
return
endif
if get(g:, 'airline_skip_empty_sections', 0) if get(g:, 'airline_skip_empty_sections', 0)
exe ':AirlineRefresh!' exe ':AirlineRefresh!'
endif endif

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -43,6 +43,10 @@ function! airline#extensions#po#shorten()
endfunction endfunction
function! airline#extensions#po#on_winenter() function! airline#extensions#po#on_winenter()
if !exists('#airline')
" airline disabled
return
endif
" only reset cache, if the window size changed " only reset cache, if the window size changed
if get(b:, 'airline_winwidth', 0) != airline#util#winwidth() if get(b:, 'airline_winwidth', 0) != airline#util#winwidth()
let b:airline_winwidth = airline#util#winwidth() let b:airline_winwidth = airline#util#winwidth()
@ -51,11 +55,17 @@ function! airline#extensions#po#on_winenter()
endif endif
endfunction endfunction
function! s:autocmd_handler()
if exists('#airline')
unlet! b:airline_po_stats
endif
endfunction
function! airline#extensions#po#apply(...) function! airline#extensions#po#apply(...)
if &ft ==# 'po' if &ft ==# 'po'
call airline#extensions#prepend_to_section('z', '%{airline#extensions#po#stats()}') 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 " 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() autocmd airline WinEnter * call airline#extensions#po#on_winenter()
endif endif
endfunction endfunction

View File

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

View File

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

View File

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

View File

@ -24,8 +24,10 @@ function! airline#extensions#tabline#tabws#on()
endfunction endfunction
function! airline#extensions#tabline#tabws#invalidate() function! airline#extensions#tabline#tabws#invalidate()
if exists('#airline')
let s:current_bufnr = -1 let s:current_bufnr = -1
let s:current_tabnr = -1 let s:current_tabnr = -1
endif
endfunction endfunction
function! airline#extensions#tabline#tabws#add_buffer_section(builder, cur_tab, cur_buf, pull_right) 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 TabLeave * call s:Do('leave')
autocmd TabClosed * call s:Do('close') 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() autocmd BufAdd,BufDelete,BufWrite * call airline#extensions#tabline#xtabline#filter_buffers()
augroup END augroup END
@ -180,6 +180,10 @@ function! airline#extensions#tabline#xtabline#filter_buffers()
" 'accepted' is a list of buffer numbers, for quick access. " '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. " '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 if !s:xtabline_filtering | return | endif
let g:airline#extensions#tabline#exclude_buffers = [] let g:airline#extensions#tabline#exclude_buffers = []
@ -351,6 +355,10 @@ endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! s:Do(action) function! s:Do(action)
if !exists('#airline')
" airline disabled
return
endif
let arg = a:action let arg = a:action
if !s:state | call s:InitCwds() | return | endif if !s:state | call s:InitCwds() | return | endif

View File

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

View File

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

View File

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