From 8fda614d0de7e624eef8564ac34893ad3f160f79 Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Sun, 3 Jul 2016 20:44:05 +0200 Subject: [PATCH 1/2] Cache hunk values, shorten for small windows Cache the hunk values. In case of short windows, shorten the hunk string a little bit and make the branch extension take the hunk value into account when deciding how much to shorten it. --- autoload/airline/extensions/branch.vim | 3 ++- autoload/airline/extensions/hunks.vim | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/autoload/airline/extensions/branch.vim b/autoload/airline/extensions/branch.vim index 2789036b..0618a447 100644 --- a/autoload/airline/extensions/branch.vim +++ b/autoload/airline/extensions/branch.vim @@ -166,7 +166,8 @@ function! airline#extensions#branch#head() if empty(b:airline_head) || !found_fugitive_head && !s:check_in_path() let b:airline_head = '' endif - let b:airline_head = airline#util#shorten(b:airline_head, 120, 9) + let minwidth = empty(get(b:, 'airline_hunks', '')) ? 14 : 7 + let b:airline_head = airline#util#shorten(b:airline_head, 120, minwidth) return b:airline_head endfunction diff --git a/autoload/airline/extensions/hunks.vim b/autoload/airline/extensions/hunks.vim index 86d86557..3044ec1c 100644 --- a/autoload/airline/extensions/hunks.vim +++ b/autoload/airline/extensions/hunks.vim @@ -65,19 +65,27 @@ function! airline#extensions#hunks#get_hunks() if !get(w:, 'airline_active', 0) return '' endif + " Cache vavlues, so that it isn't called too often + if exists("b:airline_hunks") && + \ get(b:, 'airline_changenr', 0) == changenr() && + \ winwidth(0) == get(s:, 'airline_winwidth', 0) + return b:airline_hunks + endif let hunks = s:get_hunks() let string = '' if !empty(hunks) for i in [0, 1, 2] - if s:non_zero_only == 0 || hunks[i] > 0 + if (s:non_zero_only == 0 && winwidth(0) > 100) || hunks[i] > 0 let string .= printf('%s%s ', s:hunk_symbols[i], hunks[i]) endif endfor endif + let b:airline_hunks = string + let b:airline_changenr = changenr() + let s:airline_winwidth = winwidth(0) return string endfunction function! airline#extensions#hunks#init(ext) call airline#parts#define_function('hunks', 'airline#extensions#hunks#get_hunks') endfunction - From fdd29caef43e67812297b03d55b0d4da38bf94b1 Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Sun, 3 Jul 2016 21:32:33 +0200 Subject: [PATCH 2/2] shorten filetype for smaller screens --- autoload/airline/parts.vim | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/autoload/airline/parts.vim b/autoload/airline/parts.vim index 0c1fd668..c5ab94a1 100644 --- a/autoload/airline/parts.vim +++ b/autoload/airline/parts.vim @@ -82,10 +82,9 @@ function! airline#parts#readonly() endfunction function! airline#parts#filetype() - return &filetype + return winwidth(0) < 100 && strlen(&filetype) > 3 ? matchstr(&filetype, '...'). '…' : &filetype endfunction function! airline#parts#ffenc() return printf('%s%s%s', &fenc, &l:bomb ? '[BOM]' : '', strlen(&ff) > 0 ? '['.&ff.']' : '') endfunction -