Make the wordcount ext more flexible for the def. filetypes

This allows the user to further adjust the
g:airline#extensions#wordcount#filetypes configuration variable even
after Vim has started up.
This commit is contained in:
Christian Brabandt 2016-12-13 21:27:53 +01:00
parent 5e2ef0cd83
commit a0ea8db1fc
1 changed files with 4 additions and 3 deletions

View File

@ -3,12 +3,13 @@
scriptencoding utf-8 scriptencoding utf-8
let s:filetypes = get(g:, 'airline#extensions#wordcount#filetypes', '\vhelp|markdown|rst|org|text|asciidoc|tex|mail')
let s:format = get(g:, 'airline#extensions#wordcount#format', '%d words') let s:format = get(g:, 'airline#extensions#wordcount#format', '%d words')
let s:formatter = get(g:, 'airline#extensions#wordcount#formatter', 'default') let s:formatter = get(g:, 'airline#extensions#wordcount#formatter', 'default')
let g:airline#extensions#wordcount#filetypes = get(g:, 'airline#extensions#wordcount#filetypes',
\ '\vhelp|markdown|rst|org|text|asciidoc|tex|mail')
function! s:update() function! s:update()
if match(&ft, s:filetypes) > -1 if match(&ft, get(g:, 'airline#extensions#wordcount#filetypes')) > -1
let l:mode = mode() let l:mode = mode()
if l:mode ==# 'v' || l:mode ==# 'V' || l:mode ==# 's' || l:mode ==# 'S' if l:mode ==# 'v' || l:mode ==# 'V' || l:mode ==# 's' || l:mode ==# 'S'
let b:airline_wordcount = airline#extensions#wordcount#formatters#{s:formatter}#format() let b:airline_wordcount = airline#extensions#wordcount#formatters#{s:formatter}#format()
@ -27,7 +28,7 @@ function! s:update()
endfunction endfunction
function! airline#extensions#wordcount#apply(...) function! airline#extensions#wordcount#apply(...)
if &ft =~ s:filetypes if match(&ft, get(g:, 'airline#extensions#wordcount#filetypes')) > -1
call airline#extensions#prepend_to_section('z', '%{get(b:, "airline_wordcount", "")}') call airline#extensions#prepend_to_section('z', '%{get(b:, "airline_wordcount", "")}')
endif endif
endfunction endfunction