From 8d7c2ad8305fe258340e973a48a66d7b1bb09f24 Mon Sep 17 00:00:00 2001 From: zdm Date: Sun, 22 Dec 2013 02:27:42 +0200 Subject: [PATCH 1/8] uniq_tail improved formatter added --- autoload/airline/extensions/tabline.vim | 5 +- .../airline/extensions/tabline/formatters.vim | 82 ++++++++++++++++++- 2 files changed, 84 insertions(+), 3 deletions(-) diff --git a/autoload/airline/extensions/tabline.vim b/autoload/airline/extensions/tabline.vim index 2936c0e3..79154246 100644 --- a/autoload/airline/extensions/tabline.vim +++ b/autoload/airline/extensions/tabline.vim @@ -5,6 +5,7 @@ let s:formatter = get(g:, 'airline#extensions#tabline#formatter', 'default') let s:excludes = get(g:, 'airline#extensions#tabline#excludes', []) let s:tab_nr_type = get(g:, 'airline#extensions#tabline#tab_nr_type', 0) let s:show_buffers = get(g:, 'airline#extensions#tabline#show_buffers', 1) +let s:show_tab_nr = get(g:, 'airline#extensions#tabline#show_tab_nr', 1) let s:builder_context = { \ 'active' : 1, @@ -103,7 +104,7 @@ function! airline#extensions#tabline#title(n) endfunction function! airline#extensions#tabline#get_buffer_name(nr) - return airline#extensions#tabline#formatters#{s:formatter}(a:nr, get(s:, 'current_buffer_list', [])) + return airline#extensions#tabline#formatters#{s:formatter}(a:nr, get(s:, 'current_buffer_list', s:get_buffer_list())) endfunction function! s:get_buffer_list() @@ -245,8 +246,10 @@ function! s:get_tabs() if s:tab_nr_type == 0 let val .= ' %{len(tabpagebuflist('.i.'))}' else + if s:show_tab_nr let val .= (g:airline_symbols.space).i endif + endif call b.add_section(group, val.'%'.i.'T %{airline#extensions#tabline#title('.i.')} %)') endfor diff --git a/autoload/airline/extensions/tabline/formatters.vim b/autoload/airline/extensions/tabline/formatters.vim index 656ba225..ffb9a64b 100644 --- a/autoload/airline/extensions/tabline/formatters.vim +++ b/autoload/airline/extensions/tabline/formatters.vim @@ -49,12 +49,90 @@ function! airline#extensions#tabline#formatters#unique_tail(bufnr, buffers) return map[a:bufnr] endfunction +function! airline#extensions#tabline#formatters#unique_tail_improved(bufnr, buffers) + if len(a:buffers) <= 1 " don't need to compare bufnames if has less than one buffer opened + return airline#extensions#tabline#formatters#default(a:bufnr, a:buffers) + endif + + let curbuf_tail = fnamemodify(bufname(a:bufnr), ':t') + let do_deduplicate = 0 + let path_tokens = {} + + for nr in a:buffers + let name = bufname(nr) + if !empty(name) && nr != a:bufnr && fnamemodify(name, ':t') == curbuf_tail + let do_deduplicate = 1 + let tokens = reverse(split(substitute(fnamemodify(name, ':p:.:h'), '\\', '/', 'g'), '/')) + let token_index = 0 + for token in tokens + if token == '.' | break | endif + if !has_key(path_tokens, token_index) + let path_tokens[token_index] = {} + endif + let path_tokens[token_index][token] = 1 + let token_index += 1 + endfor + endif + endfor + + if do_deduplicate == 1 + let path = [] + let token_index = 0 + for token in reverse(split(fnamemodify(bufname(a:bufnr), ':p:.:h'), '\')) + if token == '.' | break | endif + let duplicated = 0 + let uniq = 1 + let single = 1 + if has_key(path_tokens, token_index) + let duplicated = 1 + if len(keys(path_tokens[token_index])) > 1 | let single = 0 | endif + if has_key(path_tokens[token_index], token) | let uniq = 0 | endif + endif + call insert(path, {'token': token, 'duplicated': duplicated, 'uniq': uniq, 'single': single}) + let token_index += 1 + endfor + + let buf_name = [curbuf_tail] + let has_uniq = 0 + let has_skipped = 0 + let skip_symbol = '…' + for token1 in reverse(path) + if !token1['duplicated'] && len(buf_name) > 1 + call insert(buf_name, skip_symbol) + break + endif + + if has_uniq == 1 + call insert(buf_name, skip_symbol) + break + endif + + if token1['uniq'] == 0 && token1['single'] == 1 + let has_skipped = 1 + else + if has_skipped == 1 + call insert(buf_name, skip_symbol) + let has_skipped = 0 + endif + call insert(buf_name, token1['token']) + endif + + if token1['uniq'] == 1 + let has_uniq = 1 + endif + endfor + return s:wrap_name(a:bufnr, join(buf_name, '/')) + else + return airline#extensions#tabline#formatters#default(a:bufnr, a:buffers) + endif +endfunction + function! s:wrap_name(bufnr, buffer_name) let _ = s:buf_nr_show ? printf(s:buf_nr_format, a:bufnr) : '' - let _ .= a:buffer_name + let _ .= substitute(a:buffer_name, '\\', '/', 'g') + if getbufvar(a:bufnr, '&modified') == 1 let _ .= s:buf_modified_symbol endif return _ endfunction - From 43c1636e365f5f29a692909139336c75c43f4317 Mon Sep 17 00:00:00 2001 From: zdm Date: Sun, 22 Dec 2013 03:49:30 +0200 Subject: [PATCH 2/8] windows path replaced --- autoload/airline/extensions/tabline/formatters.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/airline/extensions/tabline/formatters.vim b/autoload/airline/extensions/tabline/formatters.vim index ffb9a64b..4b4caeee 100644 --- a/autoload/airline/extensions/tabline/formatters.vim +++ b/autoload/airline/extensions/tabline/formatters.vim @@ -78,7 +78,7 @@ function! airline#extensions#tabline#formatters#unique_tail_improved(bufnr, buff if do_deduplicate == 1 let path = [] let token_index = 0 - for token in reverse(split(fnamemodify(bufname(a:bufnr), ':p:.:h'), '\')) + for token in reverse(split(fnamemodify(bufname(a:bufnr), ':p:.:h'), '/')) if token == '.' | break | endif let duplicated = 0 let uniq = 1 From f6133e4fa144fcaaa5792e9c96d57a9b45cc3d06 Mon Sep 17 00:00:00 2001 From: zdm Date: Sun, 22 Dec 2013 04:03:07 +0200 Subject: [PATCH 3/8] dos path fixed --- autoload/airline/extensions/tabline/formatters.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/airline/extensions/tabline/formatters.vim b/autoload/airline/extensions/tabline/formatters.vim index 4b4caeee..573fb2e3 100644 --- a/autoload/airline/extensions/tabline/formatters.vim +++ b/autoload/airline/extensions/tabline/formatters.vim @@ -78,7 +78,7 @@ function! airline#extensions#tabline#formatters#unique_tail_improved(bufnr, buff if do_deduplicate == 1 let path = [] let token_index = 0 - for token in reverse(split(fnamemodify(bufname(a:bufnr), ':p:.:h'), '/')) + for token in reverse(split(substitute(fnamemodify(bufname(a:bufnr), ':p:.:h'), '\\', '/', 'g'), '/')) if token == '.' | break | endif let duplicated = 0 let uniq = 1 From 0714c3554700889c3064314e8ad657da0661a4bc Mon Sep 17 00:00:00 2001 From: zdm Date: Sun, 22 Dec 2013 05:17:01 +0200 Subject: [PATCH 4/8] add skipped symbol fix --- autoload/airline/extensions/tabline/formatters.vim | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/autoload/airline/extensions/tabline/formatters.vim b/autoload/airline/extensions/tabline/formatters.vim index 573fb2e3..2b506b8d 100644 --- a/autoload/airline/extensions/tabline/formatters.vim +++ b/autoload/airline/extensions/tabline/formatters.vim @@ -99,11 +99,13 @@ function! airline#extensions#tabline#formatters#unique_tail_improved(bufnr, buff for token1 in reverse(path) if !token1['duplicated'] && len(buf_name) > 1 call insert(buf_name, skip_symbol) + let has_skipped = 0 break endif if has_uniq == 1 call insert(buf_name, skip_symbol) + let has_skipped = 0 break endif @@ -121,6 +123,11 @@ function! airline#extensions#tabline#formatters#unique_tail_improved(bufnr, buff let has_uniq = 1 endif endfor + + if has_skipped == 1 + call insert(buf_name, skip_symbol) + endif + return s:wrap_name(a:bufnr, join(buf_name, '/')) else return airline#extensions#tabline#formatters#default(a:bufnr, a:buffers) From 6c79004aaa61de1ecc630b6433cbda400df3af87 Mon Sep 17 00:00:00 2001 From: zdm Date: Sun, 22 Dec 2013 05:32:06 +0200 Subject: [PATCH 5/8] show tab nr condition moved to right place --- autoload/airline/extensions/tabline.vim | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/autoload/airline/extensions/tabline.vim b/autoload/airline/extensions/tabline.vim index 79154246..0294e879 100644 --- a/autoload/airline/extensions/tabline.vim +++ b/autoload/airline/extensions/tabline.vim @@ -243,12 +243,12 @@ function! s:get_tabs() let group = 'airline_tab' endif let val = '%(' - if s:tab_nr_type == 0 - let val .= ' %{len(tabpagebuflist('.i.'))}' - else - if s:show_tab_nr - let val .= (g:airline_symbols.space).i - endif + if s:show_tab_nr + if s:tab_nr_type == 0 + let val .= ' %{len(tabpagebuflist('.i.'))}' + else + let val .= (g:airline_symbols.space).i + endif endif call b.add_section(group, val.'%'.i.'T %{airline#extensions#tabline#title('.i.')} %)') endfor @@ -264,4 +264,3 @@ function! s:get_tabs() let s:current_tabline = b.build() return s:current_tabline endfunction - From 50fd649110893d38d2c6dd8b3e19cbb2caa0b63b Mon Sep 17 00:00:00 2001 From: zdm Date: Mon, 23 Dec 2013 07:41:24 +0200 Subject: [PATCH 6/8] docs updated, formatters moved to separate filenames --- autoload/airline/extensions/tabline.vim | 2 +- .../airline/extensions/tabline/default.vim | 35 +++++++++ .../extensions/tabline/unique_tail.vim | 27 +++++++ ...ormatters.vim => unique_tail_improved.vim} | 75 +++---------------- doc/airline.txt | 9 ++- 5 files changed, 80 insertions(+), 68 deletions(-) create mode 100644 autoload/airline/extensions/tabline/default.vim create mode 100644 autoload/airline/extensions/tabline/unique_tail.vim rename autoload/airline/extensions/tabline/{formatters.vim => unique_tail_improved.vim} (50%) diff --git a/autoload/airline/extensions/tabline.vim b/autoload/airline/extensions/tabline.vim index 0294e879..cf3d7df2 100644 --- a/autoload/airline/extensions/tabline.vim +++ b/autoload/airline/extensions/tabline.vim @@ -104,7 +104,7 @@ function! airline#extensions#tabline#title(n) endfunction function! airline#extensions#tabline#get_buffer_name(nr) - return airline#extensions#tabline#formatters#{s:formatter}(a:nr, get(s:, 'current_buffer_list', s:get_buffer_list())) + return airline#extensions#tabline#{s:formatter}#format(a:nr, get(s:, 'current_buffer_list', s:get_buffer_list())) endfunction function! s:get_buffer_list() diff --git a/autoload/airline/extensions/tabline/default.vim b/autoload/airline/extensions/tabline/default.vim new file mode 100644 index 00000000..f1c87e4f --- /dev/null +++ b/autoload/airline/extensions/tabline/default.vim @@ -0,0 +1,35 @@ +" MIT License. Copyright (c) 2013 Bailey Ling. +" vim: et ts=2 sts=2 sw=2 + +let s:fmod = get(g:, 'airline#extensions#tabline#fnamemod', ':~:.') +let s:fnamecollapse = get(g:, 'airline#extensions#tabline#fnamecollapse', 1) +let s:buf_nr_format = get(g:, 'airline#extensions#tabline#buffer_nr_format', '%s: ') +let s:buf_nr_show = get(g:, 'airline#extensions#tabline#buffer_nr_show', 0) +let s:buf_modified_symbol = g:airline_symbols.modified + +function! airline#extensions#tabline#default#format(bufnr, buffers) + let _ = '' + + let name = bufname(a:bufnr) + if empty(name) + let _ .= '[No Name]' + else + if s:fnamecollapse + let _ .= substitute(fnamemodify(name, s:fmod), '\v\w\zs.{-}\ze(\\|/)', '', 'g') + else + let _ .= fnamemodify(name, s:fmod) + endif + endif + + return airline#extensions#tabline#default#wrap_name(a:bufnr, _) +endfunction + +function! airline#extensions#tabline#default#wrap_name(bufnr, buffer_name) + let _ = s:buf_nr_show ? printf(s:buf_nr_format, a:bufnr) : '' + let _ .= substitute(a:buffer_name, '\\', '/', 'g') + + if getbufvar(a:bufnr, '&modified') == 1 + let _ .= s:buf_modified_symbol + endif + return _ +endfunction diff --git a/autoload/airline/extensions/tabline/unique_tail.vim b/autoload/airline/extensions/tabline/unique_tail.vim new file mode 100644 index 00000000..eb622f5e --- /dev/null +++ b/autoload/airline/extensions/tabline/unique_tail.vim @@ -0,0 +1,27 @@ +" MIT License. Copyright (c) 2013 Bailey Ling. +" vim: et ts=2 sts=2 sw=2 + +function! airline#extensions#tabline#unique_tail#format(bufnr, buffers) + let duplicates = {} + let tails = {} + let map = {} + for nr in a:buffers + let name = bufname(nr) + if empty(name) + let map[nr] = '[No Name]' + else + let tail = fnamemodify(name, ':t') + if has_key(tails, tail) + let duplicates[nr] = nr + endif + let tails[tail] = 1 + let map[nr] = airline#extensions#tabline#default#wrap_name(nr, tail) + endif + endfor + + for nr in values(duplicates) + let map[nr] = airline#extensions#tabline#default#wrap_name(nr, fnamemodify(bufname(nr), ':p:.')) + endfor + + return map[a:bufnr] +endfunction diff --git a/autoload/airline/extensions/tabline/formatters.vim b/autoload/airline/extensions/tabline/unique_tail_improved.vim similarity index 50% rename from autoload/airline/extensions/tabline/formatters.vim rename to autoload/airline/extensions/tabline/unique_tail_improved.vim index 2b506b8d..12b28ae6 100644 --- a/autoload/airline/extensions/tabline/formatters.vim +++ b/autoload/airline/extensions/tabline/unique_tail_improved.vim @@ -1,57 +1,11 @@ " MIT License. Copyright (c) 2013 Bailey Ling. " vim: et ts=2 sts=2 sw=2 -let s:fmod = get(g:, 'airline#extensions#tabline#fnamemod', ':~:.') -let s:fnamecollapse = get(g:, 'airline#extensions#tabline#fnamecollapse', 1) -let s:buf_nr_format = get(g:, 'airline#extensions#tabline#buffer_nr_format', '%s: ') -let s:buf_nr_show = get(g:, 'airline#extensions#tabline#buffer_nr_show', 0) -let s:buf_modified_symbol = g:airline_symbols.modified +let s:skip_symbol = '…' -function! airline#extensions#tabline#formatters#default(bufnr, buffers) - let _ = '' - - let name = bufname(a:bufnr) - if empty(name) - let _ .= '[No Name]' - else - if s:fnamecollapse - let _ .= substitute(fnamemodify(name, s:fmod), '\v\w\zs.{-}\ze(\\|/)', '', 'g') - else - let _ .= fnamemodify(name, s:fmod) - endif - endif - - return s:wrap_name(a:bufnr, _) -endfunction - -function! airline#extensions#tabline#formatters#unique_tail(bufnr, buffers) - let duplicates = {} - let tails = {} - let map = {} - for nr in a:buffers - let name = bufname(nr) - if empty(name) - let map[nr] = '[No Name]' - else - let tail = fnamemodify(name, ':t') - if has_key(tails, tail) - let duplicates[nr] = nr - endif - let tails[tail] = 1 - let map[nr] = s:wrap_name(nr, tail) - endif - endfor - - for nr in values(duplicates) - let map[nr] = s:wrap_name(nr, fnamemodify(bufname(nr), ':p:.')) - endfor - - return map[a:bufnr] -endfunction - -function! airline#extensions#tabline#formatters#unique_tail_improved(bufnr, buffers) +function! airline#extensions#tabline#unique_tail_improved#format(bufnr, buffers) if len(a:buffers) <= 1 " don't need to compare bufnames if has less than one buffer opened - return airline#extensions#tabline#formatters#default(a:bufnr, a:buffers) + return airline#extensions#tabline#default#format(a:bufnr, a:buffers) endif let curbuf_tail = fnamemodify(bufname(a:bufnr), ':t') @@ -95,16 +49,15 @@ function! airline#extensions#tabline#formatters#unique_tail_improved(bufnr, buff let buf_name = [curbuf_tail] let has_uniq = 0 let has_skipped = 0 - let skip_symbol = '…' for token1 in reverse(path) if !token1['duplicated'] && len(buf_name) > 1 - call insert(buf_name, skip_symbol) + call insert(buf_name, s:skip_symbol) let has_skipped = 0 break endif if has_uniq == 1 - call insert(buf_name, skip_symbol) + call insert(buf_name, s:skip_symbol) let has_skipped = 0 break endif @@ -113,7 +66,7 @@ function! airline#extensions#tabline#formatters#unique_tail_improved(bufnr, buff let has_skipped = 1 else if has_skipped == 1 - call insert(buf_name, skip_symbol) + call insert(buf_name, s:skip_symbol) let has_skipped = 0 endif call insert(buf_name, token1['token']) @@ -125,21 +78,11 @@ function! airline#extensions#tabline#formatters#unique_tail_improved(bufnr, buff endfor if has_skipped == 1 - call insert(buf_name, skip_symbol) + call insert(buf_name, s:skip_symbol) endif - return s:wrap_name(a:bufnr, join(buf_name, '/')) + return airline#extensions#tabline#default#wrap_name(a:bufnr, join(buf_name, '/')) else - return airline#extensions#tabline#formatters#default(a:bufnr, a:buffers) + return airline#extensions#tabline#default#format(a:bufnr, a:buffers) endif endfunction - -function! s:wrap_name(bufnr, buffer_name) - let _ = s:buf_nr_show ? printf(s:buf_nr_format, a:bufnr) : '' - let _ .= substitute(a:buffer_name, '\\', '/', 'g') - - if getbufvar(a:bufnr, '&modified') == 1 - let _ .= s:buf_modified_symbol - endif - return _ -endfunction diff --git a/doc/airline.txt b/doc/airline.txt index e8e83cad..76e3fabd 100644 --- a/doc/airline.txt +++ b/doc/airline.txt @@ -379,11 +379,14 @@ eclim let g:airline#extensions#tabline#tab_nr_type = 0 " # of splits (default) let g:airline#extensions#tabline#tab_nr_type = 1 " tab number < +* enable/disable displaying tab number in tabs mode. > + let g:airline#extensions#tabline#show_tab_nr = 1 + * defines the name of a formatter for how buffer names are displayed. > let g:airline#extensions#tabline#formatter = 'default' " here is how you can define a 'foo' formatter: - function! airline#extensions#tabline#formatters#foo(bufnr, buffers) + function! airline#extensions#tabline#foo#format(bufnr, buffers) return fnamemodify(bufname(a:bufnr), ':t') endfunction let g:airline#extensions#tabline#formatter = 'foo' @@ -406,6 +409,10 @@ eclim " there is another file of the same name, in which it will display it along " with the containing parent directory. let g:airline#extensions#tabline#formatter = 'unique_tail' + + The `unique_tail_improved` - another algorithm, that will smartly uniqualise + buffers names with similar filename, suppressing common parts of paths. + let g:airline#extensions#tabline#formatter = 'unique_tail_improved' < * configure the minimum number of buffers needed to show the tabline. > let g:airline#extensions#tabline#buffer_min_count = 0 From 19861d051400cda26bd25faf7d6a8224708e7b53 Mon Sep 17 00:00:00 2001 From: zdm Date: Mon, 23 Dec 2013 07:58:24 +0200 Subject: [PATCH 7/8] docs updated --- doc/airline.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/airline.txt b/doc/airline.txt index 76e3fabd..8c40d995 100644 --- a/doc/airline.txt +++ b/doc/airline.txt @@ -410,8 +410,8 @@ eclim " with the containing parent directory. let g:airline#extensions#tabline#formatter = 'unique_tail' - The `unique_tail_improved` - another algorithm, that will smartly uniqualise - buffers names with similar filename, suppressing common parts of paths. + " The `unique_tail_improved` - another algorithm, that will smartly uniqualise + " buffers names with similar filename, suppressing common parts of paths. let g:airline#extensions#tabline#formatter = 'unique_tail_improved' < * configure the minimum number of buffers needed to show the tabline. > From 225098475afcd6f17c764154e51c2d35ec872d33 Mon Sep 17 00:00:00 2001 From: zdm Date: Thu, 26 Dec 2013 08:16:30 +0200 Subject: [PATCH 8/8] docs updated --- doc/airline.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/airline.txt b/doc/airline.txt index 8c40d995..bfe7cb3f 100644 --- a/doc/airline.txt +++ b/doc/airline.txt @@ -410,7 +410,7 @@ eclim " with the containing parent directory. let g:airline#extensions#tabline#formatter = 'unique_tail' - " The `unique_tail_improved` - another algorithm, that will smartly uniqualise + " The `unique_tail_improved` - another algorithm, that will smartly uniquify " buffers names with similar filename, suppressing common parts of paths. let g:airline#extensions#tabline#formatter = 'unique_tail_improved' <