Generate tabs directly in tabline/builder.build
This commit is contained in:
parent
3f87d28abb
commit
349d01ba39
@ -5,78 +5,88 @@ scriptencoding utf-8
|
|||||||
|
|
||||||
let s:prototype = {}
|
let s:prototype = {}
|
||||||
|
|
||||||
function! s:prototype.insert_tabs(tabs_position, curtab) dict
|
function! s:prototype.insert_tabs(curtab) dict
|
||||||
let tab_nr_type = get(g:, 'airline#extensions#tabline#tab_nr_type', 0)
|
let self._tabs_position = self.get_position()
|
||||||
let num_tabs = tabpagenr('$')
|
let self._curtab = a:curtab
|
||||||
let left_tab = a:curtab - 1
|
endfunction
|
||||||
let right_tab = a:curtab + 1
|
|
||||||
let left_position = a:tabs_position
|
|
||||||
let right_position = a:tabs_position + 1
|
|
||||||
let remaining_space = &columns - s:strchars(s:evaluate_tabline(self.build()))
|
|
||||||
|
|
||||||
let left_sep_size = s:strchars(s:evaluate_tabline(self._context.left_sep))
|
function! s:prototype.build() dict
|
||||||
let left_alt_sep_size = s:strchars(s:evaluate_tabline(self._context.left_alt_sep))
|
if has_key(self, "_tabs_position")
|
||||||
|
let tab_nr_type = get(g:, 'airline#extensions#tabline#tab_nr_type', 0)
|
||||||
|
let num_tabs = tabpagenr('$')
|
||||||
|
let curtab = self._curtab
|
||||||
|
let left_tab = curtab - 1
|
||||||
|
let right_tab = curtab + 1
|
||||||
|
let left_position = self._tabs_position
|
||||||
|
let right_position = self._tabs_position + 1
|
||||||
|
let remaining_space = &columns - s:strchars(s:evaluate_tabline(self._build()))
|
||||||
|
|
||||||
let skipped_tabs_marker = get(g:, 'airline#extensions#tabline#overflow_marker', g:airline_symbols.ellipsis)
|
let left_sep_size = s:strchars(s:evaluate_tabline(self._context.left_sep))
|
||||||
let skipped_tabs_marker_size = s:strchars(s:evaluate_tabline(skipped_tabs_marker))
|
let left_alt_sep_size = s:strchars(s:evaluate_tabline(self._context.left_alt_sep))
|
||||||
" The left marker will have left_alt_sep, and the right will have left_sep.
|
|
||||||
let remaining_space -= 2 * skipped_tabs_marker_size + left_sep_size + left_alt_sep_size
|
|
||||||
|
|
||||||
" Add the current tab
|
let skipped_tabs_marker = get(g:, 'airline#extensions#tabline#overflow_marker', g:airline_symbols.ellipsis)
|
||||||
let tab_title = self.get_title(tab_nr_type, a:curtab)
|
let skipped_tabs_marker_size = s:strchars(s:evaluate_tabline(skipped_tabs_marker))
|
||||||
let remaining_space -= s:strchars(s:evaluate_tabline(tab_title))
|
" The left marker will have left_alt_sep, and the right will have left_sep.
|
||||||
" There are always two left_seps (either side of the selected tab) and all
|
let remaining_space -= 2 * skipped_tabs_marker_size + left_sep_size + left_alt_sep_size
|
||||||
" other seperators are left_alt_seps.
|
|
||||||
let remaining_space -= 2 * left_sep_size - left_alt_sep_size
|
|
||||||
call self.insert_section(self.get_group(a:curtab), tab_title, left_position)
|
|
||||||
|
|
||||||
if get(g:, 'airline#extensions#tabline#current_first', 0)
|
" Add the current tab
|
||||||
" always have current tabpage first
|
let tab_title = self.get_title(tab_nr_type, curtab)
|
||||||
let left_position += 1
|
let remaining_space -= s:strchars(s:evaluate_tabline(tab_title))
|
||||||
endif
|
" There are always two left_seps (either side of the selected tab) and all
|
||||||
|
" other seperators are left_alt_seps.
|
||||||
|
let remaining_space -= 2 * left_sep_size - left_alt_sep_size
|
||||||
|
call self.insert_section(self.get_group(curtab), tab_title, left_position)
|
||||||
|
|
||||||
" Add the tab to the right
|
if get(g:, 'airline#extensions#tabline#current_first', 0)
|
||||||
if right_tab <= num_tabs
|
" always have current tabpage first
|
||||||
let tab_title = self.get_title(tab_nr_type, right_tab)
|
let left_position += 1
|
||||||
let remaining_space -= s:strchars(s:evaluate_tabline(tab_title)) + left_alt_sep_size
|
endif
|
||||||
call self.insert_section(self.get_group(right_tab), tab_title, right_position)
|
|
||||||
let right_position += 1
|
|
||||||
let right_tab += 1
|
|
||||||
endif
|
|
||||||
|
|
||||||
while remaining_space > 0
|
" Add the tab to the right
|
||||||
if left_tab > 0
|
if right_tab <= num_tabs
|
||||||
let tab_title = self.get_title(tab_nr_type, left_tab)
|
|
||||||
let remaining_space -= s:strchars(s:evaluate_tabline(tab_title)) + left_alt_sep_size
|
|
||||||
if remaining_space >= 0
|
|
||||||
call self.insert_section(self.get_group(left_tab), tab_title, left_position)
|
|
||||||
let right_position += 1
|
|
||||||
let left_tab -= 1
|
|
||||||
endif
|
|
||||||
elseif right_tab <= num_tabs
|
|
||||||
let tab_title = self.get_title(tab_nr_type, right_tab)
|
let tab_title = self.get_title(tab_nr_type, right_tab)
|
||||||
let remaining_space -= s:strchars(s:evaluate_tabline(tab_title)) + left_alt_sep_size
|
let remaining_space -= s:strchars(s:evaluate_tabline(tab_title)) + left_alt_sep_size
|
||||||
if remaining_space >= 0
|
call self.insert_section(self.get_group(right_tab), tab_title, right_position)
|
||||||
call self.insert_section(self.get_group(right_tab), tab_title, right_position)
|
let right_position += 1
|
||||||
let right_position += 1
|
let right_tab += 1
|
||||||
let right_tab += 1
|
endif
|
||||||
|
|
||||||
|
while remaining_space > 0
|
||||||
|
if left_tab > 0
|
||||||
|
let tab_title = self.get_title(tab_nr_type, left_tab)
|
||||||
|
let remaining_space -= s:strchars(s:evaluate_tabline(tab_title)) + left_alt_sep_size
|
||||||
|
if remaining_space >= 0
|
||||||
|
call self.insert_section(self.get_group(left_tab), tab_title, left_position)
|
||||||
|
let right_position += 1
|
||||||
|
let left_tab -= 1
|
||||||
|
endif
|
||||||
|
elseif right_tab <= num_tabs
|
||||||
|
let tab_title = self.get_title(tab_nr_type, right_tab)
|
||||||
|
let remaining_space -= s:strchars(s:evaluate_tabline(tab_title)) + left_alt_sep_size
|
||||||
|
if remaining_space >= 0
|
||||||
|
call self.insert_section(self.get_group(right_tab), tab_title, right_position)
|
||||||
|
let right_position += 1
|
||||||
|
let right_tab += 1
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
break
|
||||||
endif
|
endif
|
||||||
else
|
endwhile
|
||||||
break
|
|
||||||
endif
|
|
||||||
endwhile
|
|
||||||
|
|
||||||
if left_tab > 0
|
if left_tab > 0
|
||||||
if get(g:, 'airline#extensions#tabline#current_first', 0)
|
if get(g:, 'airline#extensions#tabline#current_first', 0)
|
||||||
let left_position -= 1
|
let left_position -= 1
|
||||||
|
endif
|
||||||
|
call self.insert_raw('%#airline_tab#'.skipped_tabs_marker, left_position)
|
||||||
|
let right_position += 1
|
||||||
|
endif
|
||||||
|
|
||||||
|
if right_tab <= num_tabs
|
||||||
|
call self.insert_raw('%#airline_tab#'.skipped_tabs_marker, right_position)
|
||||||
endif
|
endif
|
||||||
call self.insert_raw('%#airline_tab#'.skipped_tabs_marker, left_position)
|
|
||||||
let right_position += 1
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if right_tab <= num_tabs
|
return self._build()
|
||||||
call self.insert_raw('%#airline_tab#'.skipped_tabs_marker, right_position)
|
|
||||||
endif
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:evaluate_tabline(tabline)
|
function! s:evaluate_tabline(tabline)
|
||||||
@ -102,6 +112,7 @@ 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
|
||||||
call extend(builder, s:prototype, 'force')
|
call extend(builder, s:prototype, 'force')
|
||||||
return builder
|
return builder
|
||||||
endfunction
|
endfunction
|
||||||
|
@ -43,26 +43,6 @@ function! airline#extensions#tabline#tabs#get()
|
|||||||
|
|
||||||
call airline#extensions#tabline#add_label(b, 'tabs')
|
call airline#extensions#tabline#add_label(b, 'tabs')
|
||||||
|
|
||||||
let tabs_position = b.get_position()
|
|
||||||
|
|
||||||
call b.add_section('airline_tabfill', '')
|
|
||||||
call b.split()
|
|
||||||
call b.add_section('airline_tabfill', '')
|
|
||||||
|
|
||||||
if get(g:, 'airline#extensions#tabline#show_close_button', 1)
|
|
||||||
call b.add_section('airline_tab_right', ' %999X'.
|
|
||||||
\ get(g:, 'airline#extensions#tabline#close_symbol', 'X').' ')
|
|
||||||
endif
|
|
||||||
|
|
||||||
if get(g:, 'airline#extensions#tabline#show_splits', 1) == 1
|
|
||||||
let buffers = tabpagebuflist(curtab)
|
|
||||||
for nr in buffers
|
|
||||||
let group = airline#extensions#tabline#group_of_bufnr(buffers, nr) . "_right"
|
|
||||||
call b.add_section_spaced(group, '%(%{airline#extensions#tabline#get_buffer_name('.nr.')}%)')
|
|
||||||
endfor
|
|
||||||
call airline#extensions#tabline#add_label(b, 'buffers')
|
|
||||||
endif
|
|
||||||
|
|
||||||
function! b.get_group(i) dict
|
function! b.get_group(i) dict
|
||||||
let curtab = tabpagenr()
|
let curtab = tabpagenr()
|
||||||
let group = 'airline_tab'
|
let group = 'airline_tab'
|
||||||
@ -90,7 +70,25 @@ function! airline#extensions#tabline#tabs#get()
|
|||||||
return val.'%'.a:i.'T %{airline#extensions#tabline#title('.a:i.')} %)'
|
return val.'%'.a:i.'T %{airline#extensions#tabline#title('.a:i.')} %)'
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
call b.insert_tabs(tabs_position, curtab)
|
call b.insert_tabs(curtab)
|
||||||
|
|
||||||
|
call b.add_section('airline_tabfill', '')
|
||||||
|
call b.split()
|
||||||
|
call b.add_section('airline_tabfill', '')
|
||||||
|
|
||||||
|
if get(g:, 'airline#extensions#tabline#show_close_button', 1)
|
||||||
|
call b.add_section('airline_tab_right', ' %999X'.
|
||||||
|
\ get(g:, 'airline#extensions#tabline#close_symbol', 'X').' ')
|
||||||
|
endif
|
||||||
|
|
||||||
|
if get(g:, 'airline#extensions#tabline#show_splits', 1) == 1
|
||||||
|
let buffers = tabpagebuflist(curtab)
|
||||||
|
for nr in buffers
|
||||||
|
let group = airline#extensions#tabline#group_of_bufnr(buffers, nr) . "_right"
|
||||||
|
call b.add_section_spaced(group, '%(%{airline#extensions#tabline#get_buffer_name('.nr.')}%)')
|
||||||
|
endfor
|
||||||
|
call airline#extensions#tabline#add_label(b, 'buffers')
|
||||||
|
endif
|
||||||
|
|
||||||
let s:current_bufnr = curbuf
|
let s:current_bufnr = curbuf
|
||||||
let s:current_tabnr = curtab
|
let s:current_tabnr = curtab
|
||||||
|
Loading…
Reference in New Issue
Block a user