Move strchars into util.vim

This commit is contained in:
mrmr1993 2018-03-19 14:58:50 +00:00
parent 5b7b9cf656
commit 51bb8dd7e0
2 changed files with 16 additions and 16 deletions

View File

@ -16,7 +16,7 @@ endfunction
function! s:prototype.try_insert_title(index, group, pos, sep_size, force) dict function! s:prototype.try_insert_title(index, group, pos, sep_size, force) dict
let title = self.get_title(a:index) let title = self.get_title(a:index)
let self._remaining_space -= s:strchars(s:evaluate_tabline(title)) + a:sep_size let self._remaining_space -= airline#util#strchars(s:evaluate_tabline(title)) + a:sep_size
if a:force || self._remaining_space >= 0 if a:force || self._remaining_space >= 0
let pos = a:pos let pos = a:pos
if has_key(self, "get_pretitle") if has_key(self, "get_pretitle")
@ -37,7 +37,7 @@ function! s:prototype.try_insert_title(index, group, pos, sep_size, force) dict
return 1 return 1
else else
let self._remaining_space += s:strchars(s:evaluate_tabline(title)) + a:sep_size let self._remaining_space += airline#util#strchars(s:evaluate_tabline(title)) + a:sep_size
endif endif
return 0 return 0
endfunction endfunction
@ -58,15 +58,15 @@ endfunction
function! s:prototype.build() dict function! s:prototype.build() dict
if has_key(self, '_left_position') if has_key(self, '_left_position')
let self._remaining_space = &columns - s:strchars(s:evaluate_tabline(self._build())) let self._remaining_space = &columns - airline#util#strchars(s:evaluate_tabline(self._build()))
let center_active = get(g:, 'airline#extensions#tabline#center_active', 0) let center_active = get(g:, 'airline#extensions#tabline#center_active', 0)
let sep_size = s:strchars(s:evaluate_tabline(self._context.left_sep)) let sep_size = airline#util#strchars(s:evaluate_tabline(self._context.left_sep))
let alt_sep_size = s:strchars(s:evaluate_tabline(self._context.left_alt_sep)) let alt_sep_size = airline#util#strchars(s:evaluate_tabline(self._context.left_alt_sep))
let overflow_marker = get(g:, 'airline#extensions#tabline#overflow_marker', g:airline_symbols.ellipsis) let overflow_marker = get(g:, 'airline#extensions#tabline#overflow_marker', g:airline_symbols.ellipsis)
let overflow_marker_size = s:strchars(s:evaluate_tabline(overflow_marker)) let overflow_marker_size = airline#util#strchars(s:evaluate_tabline(overflow_marker))
" Allow space for the markers before we begin filling in titles. " Allow space for the markers before we begin filling in titles.
let self._remaining_space -= 2 * overflow_marker_size let self._remaining_space -= 2 * overflow_marker_size
@ -153,16 +153,6 @@ function! s:evaluate_tabline(tabline)
return tabline return tabline
endfunction endfunction
" Compatibility wrapper for strchars, in case this vim version does not
" have it natively
function! s:strchars(str)
if exists('*strchars')
return strchars(a:str)
else
return strlen(substitute(a:str, '.', 'a', 'g'))
endif
endfunction
function! airline#extensions#tabline#builder#new(context) function! airline#extensions#tabline#builder#new(context)
let builder = airline#builder#new(a:context) let builder = airline#builder#new(a:context)
let builder._build = builder.build let builder._build = builder.build

View File

@ -86,3 +86,13 @@ else
return 0 return 0
endfunction endfunction
endif endif
" Compatibility wrapper for strchars, in case this vim version does not
" have it natively
function! airline#util#strchars(str)
if exists('*strchars')
return strchars(a:str)
else
return strlen(substitute(a:str, '.', 'a', 'g'))
endif
endfunction