refactor shortening code

This commit is contained in:
Christian Brabandt 2016-07-02 09:49:05 +02:00
parent 5b00d54cd6
commit 409e8b0cbd
3 changed files with 10 additions and 9 deletions

View File

@ -162,9 +162,7 @@ function! airline#extensions#branch#head()
if empty(b:airline_head) || !found_fugitive_head && !s:check_in_path() if empty(b:airline_head) || !found_fugitive_head && !s:check_in_path()
let b:airline_head = '' let b:airline_head = ''
endif endif
if winwidth(0) < 120 && len(split(b:airline_head, '\zs')) > 9 let b:airline_head = airline#util#shorten(b:airline_head, 120, 9)
let b:airline_head = matchstr(b:airline_head, '^.\{9\}').'…'
endif
return b:airline_head return b:airline_head
endfunction endfunction

View File

@ -106,12 +106,7 @@ function! airline#extensions#whitespace#check()
endif endif
endif endif
endif endif
if winwidth(0) < 120 && len(split(b:airline_whitespace_check, '\zs')) > 9 return airline#util#shorten(b:airline_whitespace_check, 120, 9)
return matchstr(b:airline_whitespace_check, '^.\{9\}').'…'
else
return b:airline_whitespace_check
endif
endfunction endfunction
function! airline#extensions#whitespace#toggle() function! airline#extensions#whitespace#toggle()

View File

@ -4,6 +4,14 @@
call airline#init#bootstrap() call airline#init#bootstrap()
let s:spc = g:airline_symbols.space 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) function! airline#util#wrap(text, minwidth)
if a:minwidth > 0 && winwidth(0) < a:minwidth if a:minwidth > 0 && winwidth(0) < a:minwidth
return '' return ''