From 25e384f2360ec3cdb584344cc2ea0d19f103d263 Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Mon, 4 Feb 2019 08:25:45 +0100 Subject: [PATCH] wordcount: move User autocommand to plugin Do not scatter the autocommands around, but rather move the auto command to the main plugin file. The function that handles the auto command will be created in the autoload script. Also add a call to force updating the tabline, if g:airline_statusline_ontop is defined. In addition, the wordcount() extension did not correctly notice block-wise visual mode, so while creating the airline#mode_changed() function, make the mode also detect blockwise visual mode correctly. --- autoload/airline.vim | 8 ++++++++ autoload/airline/extensions/wordcount.vim | 7 +------ plugin/airline.vim | 1 + 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/autoload/airline.vim b/autoload/airline.vim index a7b4fe85..a684e475 100644 --- a/autoload/airline.vim +++ b/autoload/airline.vim @@ -271,3 +271,11 @@ function! airline#update_tabline() call airline#extensions#tabline#redraw() endif endfunction + +function! airline#mode_changed() + " airline#visual_active + " Boolean: for when to get visual wordcount + " needed for the wordcount extension + let g:airline#visual_active = (mode() =~? '[vs]') + call airline#update_tabline() +endfunction diff --git a/autoload/airline/extensions/wordcount.vim b/autoload/airline/extensions/wordcount.vim index a9b9aace..fc290113 100644 --- a/autoload/airline/extensions/wordcount.vim +++ b/autoload/airline/extensions/wordcount.vim @@ -68,9 +68,8 @@ function! s:update_wordcount(force_update) endif endfunction -let s:visual_active = 0 " Boolean: for when to get visual wordcount function airline#extensions#wordcount#get() - if s:visual_active + if get(g:, 'airline#visual_active', 0) return s:format_wordcount(s:get_wordcount(1)) else if get(b:, 'airline_changedtick', 0) != b:changedtick @@ -109,9 +108,5 @@ function! airline#extensions#wordcount#apply(...) endfunction function! airline#extensions#wordcount#init(ext) - augroup airline_wordcount - autocmd! User AirlineModeChanged nested - \ let s:visual_active = (mode() ==? 'v' || mode() ==? 's') - augroup END call a:ext.add_statusline_func('airline#extensions#wordcount#apply') endfunction diff --git a/plugin/airline.vim b/plugin/airline.vim index cc45d51f..e4c10e08 100644 --- a/plugin/airline.vim +++ b/plugin/airline.vim @@ -145,6 +145,7 @@ function! s:airline_toggle() autocmd BufWritePost */autoload/airline/themes/*.vim \ exec 'source '.split(globpath(&rtp, 'autoload/airline/themes/'.g:airline_theme.'.vim', 1), "\n")[0] \ | call airline#load_theme() + autocmd User AirlineModeChanged nested call airline#mode_changed() if get(g:, 'airline_statusline_ontop', 0) " Force update of tabline more often