Skip to content

Commit

Permalink
Merge pull request vim-airline#1877 from maxnordlund/resepct-minwidth…
Browse files Browse the repository at this point in the history
…-for-vcs

Respect minwidth for hunks and branch parts
  • Loading branch information
chrisbra authored Feb 22, 2019
2 parents 7b88d9d + f5f963d commit baa2713
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
5 changes: 3 additions & 2 deletions autoload/airline/extensions/branch.vim
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,14 @@ function! airline#extensions#branch#head()
endif
endif

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

function! airline#extensions#branch#get_head()
let head = airline#extensions#branch#head()
let winwidth = get(airline#parts#get('branch'), 'minwidth', 120)
let minwidth = empty(get(b:, 'airline_hunks', '')) ? 14 : 7
let head = airline#util#shorten(head, winwidth, minwidth)
let empty_message = get(g:, 'airline#extensions#branch#empty_message', '')
let symbol = get(g:, 'airline#extensions#branch#symbol', g:airline_symbols.branch)
return empty(head)
Expand Down
7 changes: 4 additions & 3 deletions autoload/airline/extensions/hunks.vim
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function! s:get_hunks_empty()
return ''
endfunction

function! s:get_hunks()
function! airline#extensions#hunks#get_raw_hunks()
if !exists('b:source_func') || get(b:, 'source_func', '') is# 's:get_hunks_empty'
if get(g:, 'loaded_signify') && sy#buffer_is_active()
let b:source_func = 's:get_hunks_signify'
Expand Down Expand Up @@ -73,11 +73,12 @@ function! airline#extensions#hunks#get_hunks()
\ get(b:, 'source_func', '') isnot# 's:get_hunks_changes'
return b:airline_hunks
endif
let hunks = s:get_hunks()
let hunks = airline#extensions#hunks#get_raw_hunks()
let string = ''
let winwidth = get(airline#parts#get('hunks'), 'minwidth', 100)
if !empty(hunks)
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])
endif
endfor
Expand Down
10 changes: 8 additions & 2 deletions autoload/airline/init.vim
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,14 @@ function! airline#init#bootstrap()
\ 'raw': '/%L%{g:airline_symbols.maxlinenr}',
\ 'accent': 'bold'})
call airline#parts#define_function('ffenc', 'airline#parts#ffenc')
call airline#parts#define_empty(['hunks', 'branch', 'obsession', 'tagbar',
\ 'syntastic-warn', 'syntastic-err', 'eclim', 'whitespace','windowswap',
call airline#parts#define('hunks', {
\ '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',
\ 'neomake_warning_count', 'ale_error_count', 'ale_warning_count',
\ 'languageclient_error_count', 'languageclient_warning_count'])
Expand Down
12 changes: 8 additions & 4 deletions doc/airline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ values):
let g:airline_inactive_collapse=1
<
* Use alternative seperators for the statusline of inactive windows >
let g:airline_inactive_alt_sep=1
let g:airline_inactive_alt_sep=1
<
* themes are automatically selected based on the matching colorscheme. this
can be overridden by defining a value. >
Expand Down Expand Up @@ -233,7 +233,7 @@ values):
<
* Display the statusline in the tabline (first top line): >
let g:airline_statusline_ontop = 1
<
<
Setting this option, allows to use the statusline option to be used by
a custom function or another plugin, since airline won't change it.

Expand Down Expand Up @@ -632,6 +632,10 @@ vim-signify <https://github.com/mhinz/vim-signify>
changesPlugin <https://github.com/chrisbra/changesPlugin>
quickfixsigns <https://github.com/tomtom/quickfixsigns_vim>

You can use `airline#extensions#hunks#get_raw_hunks()` to get the full hunks,
without shortening. This allows for advanced customization, or a quick way of
querying how many changes you got. It will return something like '+4 ~2 -1'.

* enable/disable showing a summary of changed hunks under source control. >
let g:airline#extensions#hunks#enabled = 1
<
Expand Down Expand Up @@ -824,7 +828,7 @@ with the middle mouse button to delete that buffer.
Note: last option can be used to specify a different formatter for
displaying the numbers. By default tabline/formatter/tabnr.vim is used
The argument of that setting should either be a filename that exists
The argument of that setting should either be a filename that exists
autoload/airline/extensions/tabline/formatter/ (without .vim extension)
and needs to provide a format() function. Alternatively you can use a
custom function name, that is defined e.g. in your .vimrc file. In any
Expand Down Expand Up @@ -1157,7 +1161,7 @@ virtualenv <https://github.com/jmcantrell/vim-virtualenv>
" (see above at g:airline#extensions#whitespace#checks)
" To disable mixed-indent-file for go files use:
let g:airline#extensions#whitespace#skip_indent_check_ft = {'go': ['mixed-indent-file']}
<
<
------------------------------------- *airline-windowswap*
vim-windowswap <https://github.com/wesQ3/vim-windowswap>

Expand Down

0 comments on commit baa2713

Please sign in to comment.