Honor minwidth for hunks and branch parts

This removes the hardcoded minwidth limits for both the `hunks` and
`branch` parts. It replaces these with safe accesses to the `minwidth`
setting as done by `airline#parts#define_minwidth`.
This commit is contained in:
Max Nordlund gmail 2019-02-20 12:24:22 +01:00
parent 448aa43ec4
commit 45ff435378
No known key found for this signature in database
GPG Key ID: 995D5074B7F9E79F
3 changed files with 12 additions and 4 deletions

View File

@ -266,8 +266,9 @@ function! airline#extensions#branch#head()
endif endif
endif endif
let winwidth = get(airline#parts#get('branch'), 'minwidth', 120)
let minwidth = empty(get(b:, 'airline_hunks', '')) ? 14 : 7 let minwidth = empty(get(b:, 'airline_hunks', '')) ? 14 : 7
let b:airline_head = airline#util#shorten(b:airline_head, 120, minwidth) let b:airline_head = airline#util#shorten(b:airline_head, winwidth, minwidth)
return b:airline_head return b:airline_head
endfunction endfunction

View File

@ -75,9 +75,10 @@ function! airline#extensions#hunks#get_hunks()
endif endif
let hunks = s:get_hunks() let hunks = s:get_hunks()
let string = '' let string = ''
let winwidth = get(airline#parts#get('hunks'), 'minwidth', 100)
if !empty(hunks) if !empty(hunks)
for i in [0, 1, 2] for i in [0, 1, 2]
if (s:non_zero_only == 0 && airline#util#winwidth() > 100) || hunks[i] > 0 if (s:non_zero_only == 0 && airline#util#winwidth() > winwidth) || hunks[i] > 0
let string .= printf('%s%s ', s:hunk_symbols[i], hunks[i]) let string .= printf('%s%s ', s:hunk_symbols[i], hunks[i])
endif endif
endfor endfor

View File

@ -151,8 +151,14 @@ function! airline#init#bootstrap()
\ 'raw': '/%L%{g:airline_symbols.maxlinenr}', \ 'raw': '/%L%{g:airline_symbols.maxlinenr}',
\ 'accent': 'bold'}) \ 'accent': 'bold'})
call airline#parts#define_function('ffenc', 'airline#parts#ffenc') call airline#parts#define_function('ffenc', 'airline#parts#ffenc')
call airline#parts#define_empty(['hunks', 'branch', 'obsession', 'tagbar', call airline#parts#define('hunks', {
\ 'syntastic-warn', 'syntastic-err', 'eclim', 'whitespace','windowswap', \ 'raw': '',
\ 'minwidth': 100})
call airline#parts#define('branch', {
\ 'raw': '',
\ 'minwidth': 120})
call airline#parts#define_empty(['obsession', 'tagbar', 'syntastic-warn',
\ 'syntastic-err', 'eclim', 'whitespace','windowswap',
\ 'ycm_error_count', 'ycm_warning_count', 'neomake_error_count', \ 'ycm_error_count', 'ycm_warning_count', 'neomake_error_count',
\ 'neomake_warning_count', 'ale_error_count', 'ale_warning_count', \ 'neomake_warning_count', 'ale_error_count', 'ale_warning_count',
\ 'languageclient_error_count', 'languageclient_warning_count']) \ 'languageclient_error_count', 'languageclient_warning_count'])