Merge pull request #1749 from flemingfleming/autocmd-improvements

Autocmds: Move CursorMoved autocmd into the main augroup.
This commit is contained in:
Christian Brabandt 2018-06-18 08:39:17 +02:00 committed by GitHub
commit c3a814dbae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 12 deletions

View File

@ -56,9 +56,7 @@ function! airline#extensions#apply_left_override(section1, section2)
let w:airline_render_right = 0 let w:airline_render_right = 0
endfunction endfunction
let s:active_winnr = -1
function! airline#extensions#apply(...) function! airline#extensions#apply(...)
let s:active_winnr = winnr()
if s:is_excluded_window() if s:is_excluded_window()
return -1 return -1
@ -113,16 +111,8 @@ function! airline#extensions#load_theme()
call airline#util#exec_funcrefs(s:ext._theme_funcrefs, g:airline#themes#{g:airline_theme}#palette) call airline#util#exec_funcrefs(s:ext._theme_funcrefs, g:airline#themes#{g:airline_theme}#palette)
endfunction endfunction
function! s:sync_active_winnr()
if exists('#airline') && winnr() != s:active_winnr
call airline#update_statusline()
endif
endfunction
function! airline#extensions#load() function! airline#extensions#load()
let loaded_ext = [] let loaded_ext = []
" non-trivial number of external plugins use eventignore=all, so we need to account for that
autocmd CursorMoved * call <sid>sync_active_winnr()
if exists('g:airline_extensions') if exists('g:airline_extensions')
for ext in g:airline_extensions for ext in g:airline_extensions

View File

@ -35,15 +35,18 @@ function! s:init()
silent doautocmd User AirlineAfterInit silent doautocmd User AirlineAfterInit
endfunction endfunction
let s:active_winnr = -1
function! s:on_window_changed() function! s:on_window_changed()
let s:active_winnr = winnr()
if pumvisible() && (!&previewwindow || g:airline_exclude_preview) if pumvisible() && (!&previewwindow || g:airline_exclude_preview)
return return
endif endif
" Handle each window only once, since we might come here several times for " Handle each window only once, since we might come here several times for
" different autocommands. " different autocommands.
let l:key = [bufnr('%'), winnr(), winnr('$'), tabpagenr(), &ft] let l:key = [bufnr('%'), s:active_winnr, winnr('$'), tabpagenr(), &ft]
if get(g:, 'airline_last_window_changed', []) == l:key if get(g:, 'airline_last_window_changed', []) == l:key
\ && &stl is# '%!airline#statusline('.winnr().')' \ && &stl is# '%!airline#statusline('.s:active_winnr.')'
\ && &ft !~? 'gitcommit' \ && &ft !~? 'gitcommit'
" fugitive is special, it changes names and filetypes several times, " fugitive is special, it changes names and filetypes several times,
" make sure the caching does not get into its way " make sure the caching does not get into its way
@ -110,6 +113,11 @@ function! s:airline_toggle()
if exists('##CompleteDone') if exists('##CompleteDone')
autocmd CompleteDone * call <sid>on_window_changed() autocmd CompleteDone * call <sid>on_window_changed()
endif endif
" non-trivial number of external plugins use eventignore=all, so we need to account for that
autocmd CursorMoved *
\ if winnr() != s:active_winnr
\ | call <sid>on_window_changed()
\ | endif
autocmd VimResized * unlet! w:airline_lastmode | :call <sid>airline_refresh() autocmd VimResized * unlet! w:airline_lastmode | :call <sid>airline_refresh()
autocmd TabEnter * :unlet! w:airline_lastmode | let w:airline_active=1 autocmd TabEnter * :unlet! w:airline_lastmode | let w:airline_active=1