From 5b00d54cd6e8921a99fc253157428812e0bb5ec5 Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Sat, 2 Jul 2016 09:40:04 +0200 Subject: [PATCH 1/3] If window is too small, shorten branch name --- autoload/airline/extensions/branch.vim | 3 +++ 1 file changed, 3 insertions(+) diff --git a/autoload/airline/extensions/branch.vim b/autoload/airline/extensions/branch.vim index 422a65ce..83763fd1 100644 --- a/autoload/airline/extensions/branch.vim +++ b/autoload/airline/extensions/branch.vim @@ -162,6 +162,9 @@ function! airline#extensions#branch#head() if empty(b:airline_head) || !found_fugitive_head && !s:check_in_path() let b:airline_head = '' endif + if winwidth(0) < 120 && len(split(b:airline_head, '\zs')) > 9 + let b:airline_head = matchstr(b:airline_head, '^.\{9\}').'…' + endif return b:airline_head endfunction From 409e8b0cbd91285cabbac72a58b258b1beb73da5 Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Sat, 2 Jul 2016 09:49:05 +0200 Subject: [PATCH 2/3] refactor shortening code --- autoload/airline/extensions/branch.vim | 4 +--- autoload/airline/extensions/whitespace.vim | 7 +------ autoload/airline/util.vim | 8 ++++++++ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/autoload/airline/extensions/branch.vim b/autoload/airline/extensions/branch.vim index 83763fd1..d34cd239 100644 --- a/autoload/airline/extensions/branch.vim +++ b/autoload/airline/extensions/branch.vim @@ -162,9 +162,7 @@ function! airline#extensions#branch#head() if empty(b:airline_head) || !found_fugitive_head && !s:check_in_path() let b:airline_head = '' endif - if winwidth(0) < 120 && len(split(b:airline_head, '\zs')) > 9 - let b:airline_head = matchstr(b:airline_head, '^.\{9\}').'…' - endif + let b:airline_head = airline#util#shorten(b:airline_head, 120, 9) return b:airline_head endfunction diff --git a/autoload/airline/extensions/whitespace.vim b/autoload/airline/extensions/whitespace.vim index 825ee50b..15460797 100644 --- a/autoload/airline/extensions/whitespace.vim +++ b/autoload/airline/extensions/whitespace.vim @@ -106,12 +106,7 @@ function! airline#extensions#whitespace#check() endif endif endif - if winwidth(0) < 120 && len(split(b:airline_whitespace_check, '\zs')) > 9 - return matchstr(b:airline_whitespace_check, '^.\{9\}').'…' - else - return b:airline_whitespace_check - endif - + return airline#util#shorten(b:airline_whitespace_check, 120, 9) endfunction function! airline#extensions#whitespace#toggle() diff --git a/autoload/airline/util.vim b/autoload/airline/util.vim index f4525516..157060f0 100644 --- a/autoload/airline/util.vim +++ b/autoload/airline/util.vim @@ -4,6 +4,14 @@ call airline#init#bootstrap() let s:spc = g:airline_symbols.space +function! airline#util#shorten(text, winwidth, minwidth) + if winwidth(0) < a:winwidth && len(split(a:text, '\zs')) > a:minwidth + return matchstr(a:text, '^.\{'.a:minwidth.'}').'…' + else + return a:text + endif +endfunction + function! airline#util#wrap(text, minwidth) if a:minwidth > 0 && winwidth(0) < a:minwidth return '' From e715bce77be1d5bc2aa7dccb38e97d17c94c727c Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Sat, 2 Jul 2016 09:56:05 +0200 Subject: [PATCH 3/3] Shorten section z in small windows --- autoload/airline/init.vim | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/autoload/airline/init.vim b/autoload/airline/init.vim index 2b6e09f6..1e824c65 100644 --- a/autoload/airline/init.vim +++ b/autoload/airline/init.vim @@ -131,7 +131,11 @@ function! airline#init#sections() let g:airline_section_y = airline#section#create_right(['ffenc']) endif if !exists('g:airline_section_z') - let g:airline_section_z = airline#section#create(['windowswap', 'obsession', '%3p%%'.spc, 'linenr', 'maxlinenr', spc.':%3v']) + if winwidth(0) > 80 + let g:airline_section_z = airline#section#create(['windowswap', 'obsession', '%3p%%'.spc, 'linenr', 'maxlinenr', spc.':%3v']) + else + let g:airline_section_z = airline#section#create(['%3p%%'.spc, 'linenr', ':%3v']) + endif endif if !exists('g:airline_section_error') let g:airline_section_error = airline#section#create(['ycm_error_count', 'syntastic', 'eclim'])