From 248c9b0e29db2127f15867af3691b55d0a10c4a3 Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Mon, 23 Sep 2013 15:45:44 +0000 Subject: [PATCH] restore highlight group with accents for all types of parts. resolves #272. --- autoload/airline/section.vim | 20 ++++++++++---------- t/section.vim | 11 +++++++++-- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/autoload/airline/section.vim b/autoload/airline/section.vim index 6d7d476..aba88a0 100644 --- a/autoload/airline/section.vim +++ b/autoload/airline/section.vim @@ -4,15 +4,18 @@ call airline#init#bootstrap() let s:spc = g:airline_symbols.space +function! s:wrap_accent(part, value) + if exists('a:part.accent') + return '%#__accent_'.(a:part.accent).'#'.a:value.'%#__restore__#' + endif + return a:value +endfunction + function! s:create(parts, append) let _ = '' for idx in range(len(a:parts)) let part = airline#parts#get(a:parts[idx]) - let val = '' - if exists('part.accent') - let val .= '%#__accent_'.(part.accent).'#' - endif if exists('part.function') let func = (part.function).'()' @@ -26,10 +29,10 @@ function! s:create(parts, append) let val = s:spc.g:airline_right_alt_sep.s:spc.val endif if exists('part.raw') - let _ .= val.(part.raw) + let _ .= s:wrap_accent(part, val.(part.raw)) continue else - let _ .= val.a:parts[idx] + let _ .= s:wrap_accent(part, val.a:parts[idx]) continue endif endif @@ -49,10 +52,7 @@ function! s:create(parts, append) let partval = substitute(partval, '}', ' : ""}', '') endif - let val .= partval - if exists('part.accent') - let val .= '%#__restore__#' - endif + let val .= s:wrap_accent(part, partval) let _ .= val endfor return _ diff --git a/t/section.vim b/t/section.vim index 400ca0d..d36fe5c 100644 --- a/t/section.vim +++ b/t/section.vim @@ -26,13 +26,20 @@ describe 'section' Expect s == '%{airline#util#prepend("text",0)}%{airline#util#wrap("text",0)}' end - it 'should prefix with accent group if provided' + it 'should prefix with accent group if provided and restore afterwards' call airline#parts#define('hi', { \ 'raw': 'hello', \ 'accent': 'red', \ }) let s = airline#section#create(['hi']) - Expect s == '%#__accent_red#hello' + Expect s == '%#__accent_red#hello%#__restore__#' + end + + it 'should accent functions' + call airline#parts#define_function('hi', 'Hello') + call airline#parts#define_accent('hi', 'bold') + let s = airline#section#create(['hi']) + Expect s == '%#__accent_bold#%{airline#util#wrap(Hello(),0)}%#__restore__#' end it 'should parse out a section from the distro'