From f28a706020cfeb0992d15ac7aad74c96f24d88bd Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Mon, 29 Feb 2016 22:38:39 +0100 Subject: [PATCH] Enable po.vim integration fixes #1070 --- autoload/airline/extensions.vim | 4 ++++ autoload/airline/extensions/po.vim | 36 ++++++++++++++++++++++++++++++ doc/airline.txt | 9 ++++++++ 3 files changed, 49 insertions(+) create mode 100644 autoload/airline/extensions/po.vim diff --git a/autoload/airline/extensions.vim b/autoload/airline/extensions.vim index 0ce64252..2970dc8e 100644 --- a/autoload/airline/extensions.vim +++ b/autoload/airline/extensions.vim @@ -210,6 +210,10 @@ function! airline#extensions#load() call airline#extensions#whitespace#init(s:ext) endif + if get(g:, 'airline#extensions#po#enabled', 1) && executable('msgfmt') + call airline#extensions#po#init(s:ext) + endif + if get(g:, 'airline#extensions#wordcount#enabled', 1) call airline#extensions#wordcount#init(s:ext) endif diff --git a/autoload/airline/extensions/po.vim b/autoload/airline/extensions/po.vim new file mode 100644 index 00000000..6e5b6bca --- /dev/null +++ b/autoload/airline/extensions/po.vim @@ -0,0 +1,36 @@ +" MIT License. Copyright (c) 2013-2016 Bailey Ling. +" vim: et ts=2 sts=2 sw=2 + +function! airline#extensions#po#apply(...) + if &ft ==# 'po' + call airline#extensions#prepend_to_section('z', '%{airline#extensions#po#stats()}') + autocmd airline BufWritePost * unlet! b:airline_po_stats + endif +endfunction + +function! airline#extensions#po#stats() + if exists('b:airline_po_stats') && !empty(b:airline_po_stats) + return b:airline_po_stats + endif + + let airline_po_stats = system('msgfmt --statistics -o /dev/null -- '. expand('%:p')) + if v:shell_error + return '' + endif + try + let b:airline_po_stats = '['. split(airline_po_stats, '\n')[0]. ']' + catch + let b:airline_po_stats = '' + endtry + if exists("g:airline#extensions#po#displayed_limit") + let w:displayed_po_limit = g:airline#extensions#po#displayed_limit + if len(b:airline_po_stats) > w:displayed_po_limit - 1 + let b:airline_po_stats = b:airline_po_stats[0:(w:displayed_po_limit - 1)].(&encoding==?'utf-8' ? '…' : '.') + endif + endif + return b:airline_po_stats +endfunction + +function! airline#extensions#po#init(ext) + call a:ext.add_statusline_func('airline#extensions#po#apply') +endfunction diff --git a/doc/airline.txt b/doc/airline.txt index d123858d..fcf285b1 100644 --- a/doc/airline.txt +++ b/doc/airline.txt @@ -721,6 +721,15 @@ Shows number of errors and warnings in the current file detected by YCM. * set warning count prefix > let g:airline#extensions#ycm#warning_symbol = 'W:' < +------------------------------------- *airline-po* +po.vim + +* enable/disable po integration > + let g:airline#extensions#po#enabled = 1 +< +* truncate width names to a fixed length > + let g:airline#extensions#po#displayed_limit = 0 +< ============================================================================== ADVANCED CUSTOMIZATION *airline-advanced-customization*