From c869665b1648b3e596606975323514ab75d1fb98 Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Wed, 25 Sep 2013 00:25:20 -0400 Subject: [PATCH 1/3] guard against attempting to load invalid themes. --- autoload/airline.vim | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/autoload/airline.vim b/autoload/airline.vim index 501e537..2373668 100644 --- a/autoload/airline.vim +++ b/autoload/airline.vim @@ -31,8 +31,18 @@ function! airline#load_theme() endfunction function! airline#switch_theme(name) - let g:airline_theme = a:name - let palette = g:airline#themes#{g:airline_theme}#palette "also lazy loads the theme + try + let palette = g:airline#themes#{a:name}#palette "also lazy loads the theme + let g:airline_theme = a:name + catch + echohl WarningMsg | echo 'The specified theme cannot be found.' | echohl NONE + if exists('g:airline_theme') + return + else + let g:airline_theme = 'dark' + let palette = g:airline#themes#dark#palette + endif + endtry call airline#themes#patch(palette) if exists('g:airline_theme_patch_func') From e507f481a259a97d3a4e3dd0ff71d7122aca9de9 Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Wed, 25 Sep 2013 18:48:18 +0000 Subject: [PATCH 2/3] allow parts to be defined in the vimrc as overrides. resolves #284. --- autoload/airline/init.vim | 8 ++++++-- autoload/airline/parts.vim | 6 +++++- t/init.vim | 13 +++++++++++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/autoload/airline/init.vim b/autoload/airline/init.vim index 37ac856..aa93e1e 100644 --- a/autoload/airline/init.vim +++ b/autoload/airline/init.vim @@ -61,6 +61,10 @@ function! airline#init#bootstrap() \ 'modified': '+', \ 'space': ' ', \ }, 'keep') +endfunction + +function! airline#init#sections() + let g:airline#init#initializing_sections = 1 call airline#parts#define('mode', { \ 'function': 'airline#parts#mode', @@ -77,9 +81,7 @@ function! airline#init#bootstrap() call airline#parts#define_raw('linenr', (g:airline_symbols.linenr).'%#__accent_bold#%4l%#__restore__#') call airline#parts#define_function('ffenc', 'airline#parts#ffenc') call airline#parts#define_empty(['hunks', 'branch', 'tagbar', 'syntastic', 'whitespace']) -endfunction -function! airline#init#sections() let spc = g:airline_symbols.space if !exists('g:airline_section_a') let g:airline_section_a = airline#section#create_left(['mode', 'paste', 'iminsert']) @@ -105,5 +107,7 @@ function! airline#init#sections() if !exists('g:airline_section_warning') let g:airline_section_warning = airline#section#create(['syntastic', 'whitespace']) endif + + unlet g:airline#init#initializing_sections endfunction diff --git a/autoload/airline/parts.vim b/autoload/airline/parts.vim index e5cbd38..0a43b97 100644 --- a/autoload/airline/parts.vim +++ b/autoload/airline/parts.vim @@ -7,7 +7,11 @@ let s:parts = {} function! airline#parts#define(key, config) let s:parts[a:key] = get(s:parts, a:key, {}) - call extend(s:parts[a:key], a:config) + if exists('g:airline#init#initializing_sections') + call extend(s:parts[a:key], a:config, 'keep') + else + call extend(s:parts[a:key], a:config, 'force') + endif endfunction function! airline#parts#define_function(key, name) diff --git a/t/init.vim b/t/init.vim index 9891c2d..e6e3eb6 100644 --- a/t/init.vim +++ b/t/init.vim @@ -6,10 +6,11 @@ function! s:clear() endfor endfunction -describe 'init' +call airline#init#bootstrap() + +describe 'init sections' before call s:clear() - call airline#init#bootstrap() call airline#init#sections() end @@ -65,3 +66,11 @@ describe 'init' end end +describe 'init parts' + it 'should not redefine parts already defined' + call airline#parts#define_raw('linenr', 'bar') + call airline#init#sections() + Expect g:airline_section_z =~ 'bar' + end +end + From 4d706c5f4ad4a0ffa7c89af3b45e296d906d0fd6 Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Wed, 25 Sep 2013 19:26:25 +0000 Subject: [PATCH 3/3] use columns instead of winwidth (#222). --- autoload/airline/extensions/tabline.vim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/autoload/airline/extensions/tabline.vim b/autoload/airline/extensions/tabline.vim index 2c3e5fa..6b85b4b 100644 --- a/autoload/airline/extensions/tabline.vim +++ b/autoload/airline/extensions/tabline.vim @@ -124,12 +124,13 @@ function! s:get_visible_buffers() " only show current and surrounding buffers if there are too many buffers let position = index(buffers, cur) - if total_width > winwidth(0) && position > -1 + let vimwidth = &columns + if total_width > vimwidth && position > -1 let buf_count = len(buffers) " determine how many buffers to show based on the longest buffer width, " use one on the right side and put the rest on the left - let buf_max = winwidth(0) / max_width + let buf_max = vimwidth / max_width let buf_right = 1 let buf_left = max([0, buf_max - buf_right])