2018-03-14 21:23:43 -04:00
|
|
|
" MIT License. Copyright (c) 2013-2018 Bailey Ling et al.
|
|
|
|
" vim: et ts=2 sts=2 sw=2
|
|
|
|
|
|
|
|
scriptencoding utf-8
|
|
|
|
|
|
|
|
let s:prototype = {}
|
|
|
|
|
2018-03-19 10:34:38 -04:00
|
|
|
function! s:prototype.insert_titles(current, first, last) dict
|
|
|
|
let self._first_title = a:first
|
|
|
|
let self._last_title = a:last
|
|
|
|
let self._left_title = a:current
|
|
|
|
let self._right_title = a:current + 1
|
2018-03-15 13:46:33 -04:00
|
|
|
let self._left_position = self.get_position()
|
|
|
|
let self._right_position = self._left_position
|
2018-03-15 13:10:49 -04:00
|
|
|
endfunction
|
2018-03-15 13:05:58 -04:00
|
|
|
|
2018-03-19 10:34:38 -04:00
|
|
|
function! s:prototype.try_insert_title(index, group, pos, sep_size, force) dict
|
|
|
|
let title = self.get_title(a:index)
|
2018-03-19 10:58:50 -04:00
|
|
|
let self._remaining_space -= airline#util#strchars(s:evaluate_tabline(title)) + a:sep_size
|
2018-03-15 14:09:18 -04:00
|
|
|
if a:force || self._remaining_space >= 0
|
2018-03-15 15:41:58 -04:00
|
|
|
let pos = a:pos
|
|
|
|
if has_key(self, "get_pretitle")
|
2018-03-19 10:34:38 -04:00
|
|
|
call self.insert_raw(self.get_pretitle(a:index), pos)
|
2018-03-15 15:41:58 -04:00
|
|
|
let self._right_position += 1
|
|
|
|
let pos += 1
|
|
|
|
endif
|
|
|
|
|
2018-03-19 10:34:38 -04:00
|
|
|
call self.insert_section(a:group, title, pos)
|
2018-03-15 14:09:18 -04:00
|
|
|
let self._right_position += 1
|
2018-03-15 15:41:58 -04:00
|
|
|
let pos += 1
|
|
|
|
|
|
|
|
if has_key(self, "get_posttitle")
|
2018-03-19 10:34:38 -04:00
|
|
|
call self.insert_raw(self.get_posttitle(a:index), pos)
|
2018-03-15 15:41:58 -04:00
|
|
|
let self._right_position += 1
|
|
|
|
let pos += 1
|
|
|
|
endif
|
|
|
|
|
2018-03-15 14:09:18 -04:00
|
|
|
return 1
|
2018-03-17 15:59:47 -04:00
|
|
|
else
|
2018-03-19 10:58:50 -04:00
|
|
|
let self._remaining_space += airline#util#strchars(s:evaluate_tabline(title)) + a:sep_size
|
2018-03-15 14:09:18 -04:00
|
|
|
endif
|
|
|
|
return 0
|
|
|
|
endfunction
|
|
|
|
|
2018-03-17 20:15:29 -04:00
|
|
|
function! s:get_separator_change(new_group, old_group, end_group, sep_size, alt_sep_size)
|
|
|
|
let sep_change = 0
|
|
|
|
if !empty(a:end_group)
|
|
|
|
let sep_change += airline#builder#should_change_group(a:new_group, a:end_group) ? a:sep_size : a:alt_sep_size
|
|
|
|
endif
|
|
|
|
if !empty(a:old_group)
|
|
|
|
let sep_change += airline#builder#should_change_group(a:new_group, a:old_group) ? a:sep_size : a:alt_sep_size
|
|
|
|
if !empty(a:end_group)
|
|
|
|
let sep_change -= airline#builder#should_change_group(a:old_group, a:end_group) ? a:sep_size : a:alt_sep_size
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
return sep_change
|
|
|
|
endfunction
|
|
|
|
|
2018-03-15 13:10:49 -04:00
|
|
|
function! s:prototype.build() dict
|
2018-03-15 13:46:33 -04:00
|
|
|
if has_key(self, '_left_position')
|
2018-03-19 10:58:50 -04:00
|
|
|
let self._remaining_space = &columns - airline#util#strchars(s:evaluate_tabline(self._build()))
|
2018-03-15 13:05:58 -04:00
|
|
|
|
2018-03-15 16:07:44 -04:00
|
|
|
let center_active = get(g:, 'airline#extensions#tabline#center_active', 0)
|
|
|
|
|
2018-03-19 10:58:50 -04:00
|
|
|
let sep_size = airline#util#strchars(s:evaluate_tabline(self._context.left_sep))
|
|
|
|
let alt_sep_size = airline#util#strchars(s:evaluate_tabline(self._context.left_alt_sep))
|
2018-03-15 13:10:49 -04:00
|
|
|
|
2018-03-17 21:17:53 -04:00
|
|
|
let overflow_marker = get(g:, 'airline#extensions#tabline#overflow_marker', g:airline_symbols.ellipsis)
|
2018-03-19 10:58:50 -04:00
|
|
|
let overflow_marker_size = airline#util#strchars(s:evaluate_tabline(overflow_marker))
|
2018-03-17 20:15:29 -04:00
|
|
|
" Allow space for the markers before we begin filling in titles.
|
2018-03-17 21:17:53 -04:00
|
|
|
let self._remaining_space -= 2 * overflow_marker_size
|
2018-03-17 20:15:29 -04:00
|
|
|
|
|
|
|
let outer_left_group = airline#builder#get_prev_group(self._sections, self._left_position)
|
|
|
|
let outer_right_group = airline#builder#get_next_group(self._sections, self._right_position)
|
2018-03-15 14:09:18 -04:00
|
|
|
|
2018-03-19 10:34:38 -04:00
|
|
|
" Add the current title
|
|
|
|
let group = self.get_group(self._left_title)
|
2018-03-17 20:15:29 -04:00
|
|
|
let sep_change =
|
2018-03-17 21:13:30 -04:00
|
|
|
\ s:get_separator_change(group, "", outer_left_group, sep_size, alt_sep_size) +
|
|
|
|
\ s:get_separator_change(group, "", outer_right_group, sep_size, alt_sep_size)
|
2018-03-17 21:15:11 -04:00
|
|
|
let left_group = group
|
|
|
|
let right_group = group
|
2018-03-19 10:34:38 -04:00
|
|
|
let self._left_title -=
|
|
|
|
\ self.try_insert_title(self._left_title, group, self._left_position, sep_change, 1)
|
2018-03-15 13:10:49 -04:00
|
|
|
|
|
|
|
if get(g:, 'airline#extensions#tabline#current_first', 0)
|
2018-03-19 10:34:38 -04:00
|
|
|
" always have current title first
|
2018-03-15 13:41:08 -04:00
|
|
|
let self._left_position += 1
|
2018-03-15 13:10:49 -04:00
|
|
|
endif
|
|
|
|
|
2018-03-19 10:34:38 -04:00
|
|
|
" Add the title to the right
|
|
|
|
if !center_active && self._right_title <= self._last_title
|
|
|
|
let group = self.get_group(self._right_title)
|
2018-03-17 20:15:29 -04:00
|
|
|
let sep_change =
|
2018-03-17 21:15:11 -04:00
|
|
|
\ s:get_separator_change(group, right_group, outer_right_group, sep_size, alt_sep_size)
|
|
|
|
let right_group = group
|
2018-03-19 10:34:38 -04:00
|
|
|
let self._right_title +=
|
|
|
|
\ self.try_insert_title(self._right_title, group, self._right_position, sep_change, 1)
|
2018-03-15 13:10:49 -04:00
|
|
|
endif
|
|
|
|
|
2018-03-15 14:01:39 -04:00
|
|
|
while self._remaining_space > 0
|
2018-03-15 16:07:44 -04:00
|
|
|
let done = 0
|
2018-03-19 10:34:38 -04:00
|
|
|
if self._left_title >= self._first_title
|
|
|
|
let group = self.get_group(self._left_title)
|
2018-03-17 20:15:29 -04:00
|
|
|
let sep_change =
|
2018-03-17 21:15:11 -04:00
|
|
|
\ s:get_separator_change(group, left_group, outer_left_group, sep_size, alt_sep_size)
|
|
|
|
let left_group = group
|
2018-03-19 10:34:38 -04:00
|
|
|
let done = self.try_insert_title(self._left_title, group, self._left_position, sep_change, 0)
|
|
|
|
let self._left_title -= done
|
2018-03-15 16:07:44 -04:00
|
|
|
endif
|
2018-03-19 10:34:38 -04:00
|
|
|
if self._right_title <= self._last_title && (center_active || !done)
|
|
|
|
let group = self.get_group(self._right_title)
|
2018-03-17 20:15:29 -04:00
|
|
|
let sep_change =
|
2018-03-17 21:15:11 -04:00
|
|
|
\ s:get_separator_change(group, right_group, outer_right_group, sep_size, alt_sep_size)
|
|
|
|
let right_group = group
|
2018-03-19 10:34:38 -04:00
|
|
|
let done = self.try_insert_title(self._right_title, group, self._right_position, sep_change, 0)
|
|
|
|
let self._right_title += done
|
2018-03-15 16:07:44 -04:00
|
|
|
endif
|
|
|
|
if !done
|
2018-03-15 13:10:49 -04:00
|
|
|
break
|
2018-03-15 13:05:58 -04:00
|
|
|
endif
|
2018-03-15 13:10:49 -04:00
|
|
|
endwhile
|
|
|
|
|
2018-03-19 10:34:38 -04:00
|
|
|
if self._left_title >= self._first_title
|
2018-03-15 13:10:49 -04:00
|
|
|
if get(g:, 'airline#extensions#tabline#current_first', 0)
|
2018-03-15 13:41:08 -04:00
|
|
|
let self._left_position -= 1
|
2018-03-15 13:10:49 -04:00
|
|
|
endif
|
2018-03-17 21:17:53 -04:00
|
|
|
call self.insert_raw('%#'.self.overflow_group.'#'.overflow_marker, self._left_position)
|
2018-03-15 13:41:08 -04:00
|
|
|
let self._right_position += 1
|
2018-03-15 13:05:58 -04:00
|
|
|
endif
|
|
|
|
|
2018-03-19 10:34:38 -04:00
|
|
|
if self._right_title <= self._last_title
|
2018-03-17 21:17:53 -04:00
|
|
|
call self.insert_raw('%#'.self.overflow_group.'#'.overflow_marker, self._right_position)
|
2018-03-15 13:05:58 -04:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2018-03-15 13:10:49 -04:00
|
|
|
return self._build()
|
2018-03-15 13:05:58 -04:00
|
|
|
endfunction
|
|
|
|
|
2018-03-15 15:36:30 -04:00
|
|
|
let s:prototype.overflow_group = 'airline_tab'
|
|
|
|
|
2018-03-15 13:05:58 -04:00
|
|
|
function! s:evaluate_tabline(tabline)
|
|
|
|
let tabline = a:tabline
|
|
|
|
let tabline = substitute(tabline, '%{\([^}]\+\)}', '\=eval(submatch(1))', 'g')
|
|
|
|
let tabline = substitute(tabline, '%#[^#]\+#', '', 'g')
|
|
|
|
let tabline = substitute(tabline, '%(\([^)]\+\)%)', '\1', 'g')
|
|
|
|
let tabline = substitute(tabline, '%\d\+[TX]', '', 'g')
|
|
|
|
let tabline = substitute(tabline, '%=', '', 'g')
|
|
|
|
let tabline = substitute(tabline, '%\d*\*', '', 'g')
|
2018-03-15 15:21:15 -04:00
|
|
|
if has('tablineat')
|
|
|
|
let tabline = substitute(tabline, '%@[^@]\+@', '', 'g')
|
|
|
|
endif
|
2018-03-15 13:05:58 -04:00
|
|
|
return tabline
|
|
|
|
endfunction
|
|
|
|
|
2018-03-14 21:23:43 -04:00
|
|
|
function! airline#extensions#tabline#builder#new(context)
|
|
|
|
let builder = airline#builder#new(a:context)
|
2018-03-15 13:10:49 -04:00
|
|
|
let builder._build = builder.build
|
2018-03-14 21:23:43 -04:00
|
|
|
call extend(builder, s:prototype, 'force')
|
|
|
|
return builder
|
|
|
|
endfunction
|