File autoload/libui/tabs.vim changed (mode: 100644) (index 5b6a6e0..521950a) |
|
1 |
|
" This implementation formats textual tabs trying to keep tip of the current tab |
|
2 |
|
" visible at all times and providing indication of how many tab tips were |
|
3 |
|
" hidden. It looks like this: |
|
4 |
|
" |
|
5 |
|
" [+2][3:~/r/v/s/u/str.h] [4:~/r/v/s/u/str.c] [5:~/r/v/s/c/os.h][+4] X |
|
6 |
|
|
1 |
7 |
" formats tab line |
" formats tab line |
2 |
8 |
function! libui#tabs#TabLine() |
function! libui#tabs#TabLine() |
3 |
|
let s = '' |
|
4 |
|
for i in range(tabpagenr('$')) |
|
5 |
|
" select the highlighting |
|
6 |
|
if i + 1 == tabpagenr() |
|
7 |
|
let s .= '%#TabLineSel#' |
|
8 |
|
else |
|
9 |
|
let s .= '%#TabLine#' |
|
|
9 |
|
let ctab = tabpagenr() - 1 |
|
10 |
|
let ntabs = tabpagenr('$') |
|
11 |
|
|
|
12 |
|
let labels = [] |
|
13 |
|
for i in range(ntabs) |
|
14 |
|
call add(labels, s:TabLabel(i + 1)) |
|
15 |
|
endfor |
|
16 |
|
|
|
17 |
|
let s = s:WrapTabLabel(labels[ctab], 1, ctab) |
|
18 |
|
let left = &columns - len(s) - 1 |
|
19 |
|
let l = ctab - 1 |
|
20 |
|
let r = ctab + 1 |
|
21 |
|
while left > 0 && (l >= 0 || r < ntabs) |
|
22 |
|
let oldl = l |
|
23 |
|
let oldr = r |
|
24 |
|
|
|
25 |
|
if l >= 0 && left >= len(labels[l]) |
|
26 |
|
let s = s:WrapTabLabel(labels[l], 0, l) . ' ' . s |
|
27 |
|
let left -= len(labels[l]) |
|
28 |
|
let l -= 1 |
|
29 |
|
endif |
|
30 |
|
if r < ntabs && left >= len(labels[r]) |
|
31 |
|
let s .= '%* ' . s:WrapTabLabel(labels[r], 0, r) |
|
32 |
|
let left -= len(labels[r]) |
|
33 |
|
let r += 1 |
10 |
34 |
endif |
endif |
11 |
35 |
|
|
12 |
|
" set the tab page $1 (for mouse clicks) |
|
13 |
|
let s .= '%' . (i + 1) . 'T' |
|
|
36 |
|
if oldl == l && oldr == r |
|
37 |
|
break |
|
38 |
|
endif |
|
39 |
|
endwhile |
14 |
40 |
|
|
15 |
|
" the label is made by TabLabel() |
|
16 |
|
let s .= '%{libui#tabs#TabLabel(' . (i + 1) . ')} ' |
|
17 |
|
endfor |
|
|
41 |
|
if l >= 0 |
|
42 |
|
let s = '[+' . (l + 1) . ']' . s |
|
43 |
|
endif |
|
44 |
|
if r < ntabs |
|
45 |
|
let s .= '%*[+' . (ntabs - r) . ']' |
|
46 |
|
endif |
18 |
47 |
|
|
19 |
48 |
" after the last tab fill with TabLineFill and reset tab page nr |
" after the last tab fill with TabLineFill and reset tab page nr |
20 |
49 |
let s .= '%#TabLineFill#%T' |
let s .= '%#TabLineFill#%T' |
21 |
50 |
|
|
22 |
51 |
" right-align the label to close the current tab page |
" right-align the label to close the current tab page |
23 |
|
if tabpagenr('$') > 1 |
|
|
52 |
|
if ntabs > 1 |
24 |
53 |
let s .= '%=%#TabLine#%999XX' |
let s .= '%=%#TabLine#%999XX' |
25 |
54 |
endif |
endif |
26 |
55 |
|
|
27 |
56 |
return s |
return s |
28 |
57 |
endfunction |
endfunction |
29 |
58 |
|
|
|
59 |
|
" adds macros around the label |
|
60 |
|
function! s:WrapTabLabel(lbl, iscurrent, idx) |
|
61 |
|
" select the highlighting |
|
62 |
|
let hl = a:iscurrent ? '%#TabLineSel#' : '%#TabLine#' |
|
63 |
|
|
|
64 |
|
" set the tab page id (for mouse clicks) |
|
65 |
|
return hl . '%' . (a:idx + 1) . 'T' . a:lbl |
|
66 |
|
endfunction |
|
67 |
|
|
30 |
68 |
" formats tab label |
" formats tab label |
31 |
|
function! libui#tabs#TabLabel(n) |
|
|
69 |
|
function! s:TabLabel(n) |
32 |
70 |
let buflist = tabpagebuflist(a:n) |
let buflist = tabpagebuflist(a:n) |
33 |
71 |
let winnr = tabpagewinnr(a:n) |
let winnr = tabpagewinnr(a:n) |
34 |
72 |
let l = pathshorten(expand('#'.buflist[winnr - 1].':p:~')) |
let l = pathshorten(expand('#'.buflist[winnr - 1].':p:~')) |