diff --git a/autoload/airline.vim b/autoload/airline.vim index 9e6b3a34..fb82d110 100644 --- a/autoload/airline.vim +++ b/autoload/airline.vim @@ -1,28 +1,16 @@ " MIT License. Copyright (c) 2013 Bailey Ling. -" vim: ts=2 sts=2 sw=2 fdm=indent +" vim: et ts=2 sts=2 sw=2 fdm=indent -let s:is_win32term = (has('win32') || has('win64')) && !has('gui_running') let s:sections = ['a','b','c','gutter','x','y','z','warning'] +let s:highlighter = airline#highlighter#new() -function! airline#exec_highlight(group, colors) - let colors = a:colors - if s:is_win32term - let colors = map(a:colors, 'v:val != "" && v:val > 128 ? v:val - 128 : v:val') - endif - exec printf('hi %s %s %s %s %s %s %s %s', - \ a:group, - \ colors[0] != '' ? 'guifg='.colors[0] : '', - \ colors[1] != '' ? 'guibg='.colors[1] : '', - \ colors[2] != '' ? 'ctermfg='.colors[2] : '', - \ colors[3] != '' ? 'ctermbg='.colors[3] : '', - \ len(colors) > 4 && colors[4] != '' ? 'gui='.colors[4] : '', - \ len(colors) > 4 && colors[4] != '' ? 'cterm='.colors[4] : '', - \ len(colors) > 4 && colors[4] != '' ? 'term='.colors[4] : '') +function! airline#get_highlighter() + return s:highlighter endfunction function! airline#reload_highlight() - call s:highlight(['inactive']) - call s:highlight(['normal']) + call s:highlighter.highlight(['inactive']) + call s:highlighter.highlight(['normal']) call airline#extensions#load_theme() endfunction @@ -35,22 +23,6 @@ function! airline#load_theme(name) call airline#check_mode() endfunction -function! s:highlight(modes) - " draw the base mode, followed by any overrides - let mapped = map(a:modes, 'v:val == a:modes[0] ? v:val : a:modes[0]."_".v:val') - for mode in mapped - if exists('g:airline#themes#{g:airline_theme}#{mode}') - for key in keys(g:airline#themes#{g:airline_theme}#{mode}) - let colors = g:airline#themes#{g:airline_theme}#{mode}[key] - let suffix = a:modes[0] == 'inactive' ? '_inactive' : '' - call airline#exec_highlight(key.suffix, colors) - endfor - endif - endfor - for sep in w:airline_current_info.separator_groups - call airline#themes#exec_highlight_separator(sep[0], sep[1]) - endfor -endfunction function! s:get_section(winnr, key, ...) let text = airline#util#getwinvar(a:winnr, 'airline_section_'.a:key, g:airline_section_{a:key}) @@ -59,7 +31,7 @@ function! s:get_section(winnr, key, ...) endfunction function! airline#get_statusline(winnr, active) - let builder = airline#builder#new(a:active) + let builder = airline#builder#new(a:active, s:highlighter) if airline#util#getwinvar(a:winnr, 'airline_render_left', a:active || (!a:active && !g:airline_inactive_collapse)) call builder.add_section('a', s:get_section(a:winnr, 'a').'%{g:airline_detect_paste && &paste ? g:airline_paste_symbol." " : ""}') @@ -68,7 +40,9 @@ function! airline#get_statusline(winnr, active) else call builder.add_section('c', '%f%m') endif + call builder.split(s:get_section(a:winnr, 'gutter', '', '')) + if airline#util#getwinvar(a:winnr, 'airline_render_right', 1) call builder.add_section('c', s:get_section(a:winnr, 'x')) call builder.add_section('b', s:get_section(a:winnr, 'y')) @@ -126,12 +100,16 @@ function! airline#check_mode() let w:airline_current_mode = get(g:airline_mode_map, '__') endif - if g:airline_detect_modified && &modified | call add(l:mode, 'modified') | endif - if g:airline_detect_paste && &paste | call add(l:mode, 'paste') | endif + if g:airline_detect_modified && &modified + call add(l:mode, 'modified') + endif + if g:airline_detect_paste && &paste + call add(l:mode, 'paste') + endif let mode_string = join(l:mode) if get(w:, 'airline_lastmode', '') != mode_string - call s:highlight(l:mode) + call s:highlighter.highlight(l:mode) let w:airline_lastmode = mode_string endif return '' diff --git a/autoload/airline/builder.vim b/autoload/airline/builder.vim index d461d3c5..db590d8a 100644 --- a/autoload/airline/builder.vim +++ b/autoload/airline/builder.vim @@ -1,10 +1,11 @@ " MIT license. Copyright (c) 2013 Bailey Ling. -" vim: ts=2 sts=2 sw=2 fdm=indent +" vim: et ts=2 sts=2 sw=2 fdm=indent -function! airline#builder#new(active) +function! airline#builder#new(active, highlighter) let builder = {} let builder._sections = [] let builder._active = a:active + let builder._highlighter = a:highlighter function! builder.split(gutter) call add(self._sections, ['|', a:gutter]) @@ -18,14 +19,8 @@ function! airline#builder#new(active) call add(self._sections, ['_', a:text]) endfunction - function! builder.refresh_separator_highlights() - for sep in self._separator_groups - call airline#themes#exec_highlight_separator(sep[0], sep[1]) - endfor - endfunction - function! builder._group(group) - return '%#' . (self._active ? a:group : a:group.'_inactive') . '#' + return self._active ? a:group : a:group.'_inactive' endfunction function! builder.build() @@ -46,17 +41,19 @@ function! airline#builder#new(active) endif if prev_group != '' - let sep = side == 0 ? [section[0], prev_group] : [prev_group, section[0]] + let sep = side == 0 + \ ? [self._group(section[0]), self._group(prev_group)] + \ : [self._group(prev_group), self._group(section[0])] call add(separator_groups, sep) let line .= side == 0 - \ ? self._group(section[0].'_to_'.prev_group) - \ : self._group(prev_group.'_to_'.section[0]) + \ ? '%#'.self._group(section[0].'_to_'.prev_group).'#' + \ : '%#'.self._group(prev_group.'_to_'.section[0]).'#' let line .= side == 0 \ ? self._active ? g:airline_left_sep : g:airline_left_alt_sep \ : self._active ? g:airline_right_sep : g:airline_right_alt_sep endif - let line .= self._group(section[0]).section[1] + let line .= '%#'.self._group(section[0]).'#'.section[1] let prev_group = section[0] endfor diff --git a/autoload/airline/extensions/ctrlp.vim b/autoload/airline/extensions/ctrlp.vim index 3b388b31..738faff0 100644 --- a/autoload/airline/extensions/ctrlp.vim +++ b/autoload/airline/extensions/ctrlp.vim @@ -22,7 +22,7 @@ function! airline#extensions#ctrlp#load_theme() \ g:airline#themes#{g:airline_theme}#insert['airline_a']) endif for key in keys(theme) - call airline#exec_highlight(key, theme[key]) + call airline#highlighter#exec(key, theme[key]) endfor endfunction diff --git a/autoload/airline/highlighter.vim b/autoload/airline/highlighter.vim new file mode 100644 index 00000000..284ab511 --- /dev/null +++ b/autoload/airline/highlighter.vim @@ -0,0 +1,56 @@ +" MIT license. Copyright (c) 2013 Bailey Ling. +" vim: et ts=2 sts=2 sw=2 fdm=indent + +let s:is_win32term = (has('win32') || has('win64')) && !has('gui_running') + +function! airline#highlighter#exec(group, colors) + let colors = a:colors + if s:is_win32term + let colors = map(a:colors, 'v:val != "" && v:val > 128 ? v:val - 128 : v:val') + endif + exec printf('hi %s %s %s %s %s %s %s %s', + \ a:group, + \ colors[0] != '' ? 'guifg='.colors[0] : '', + \ colors[1] != '' ? 'guibg='.colors[1] : '', + \ colors[2] != '' ? 'ctermfg='.colors[2] : '', + \ colors[3] != '' ? 'ctermbg='.colors[3] : '', + \ len(colors) > 4 && colors[4] != '' ? 'gui='.colors[4] : '', + \ len(colors) > 4 && colors[4] != '' ? 'cterm='.colors[4] : '', + \ len(colors) > 4 && colors[4] != '' ? 'term='.colors[4] : '') +endfunction + +function! airline#highlighter#exec_separator(from, to) + if a:from == a:to + return a:from + endif + let l:from = airline#themes#get_highlight(a:from) + let l:to = airline#themes#get_highlight(a:to) + let group = a:from.'_to_'.a:to + call airline#highlighter#exec(group, [ l:to[1], l:from[1], l:to[3], l:from[3] ]) + return group +endfunction + + +function! airline#highlighter#new() + let highlighter = {} + + function! highlighter.highlight(modes) + " draw the base mode, followed by any overrides + let mapped = map(a:modes, 'v:val == a:modes[0] ? v:val : a:modes[0]."_".v:val') + let suffix = a:modes[0] == 'inactive' ? '_inactive' : '' + for mode in mapped + if exists('g:airline#themes#{g:airline_theme}#{mode}') + for key in keys(g:airline#themes#{g:airline_theme}#{mode}) + let colors = g:airline#themes#{g:airline_theme}#{mode}[key] + call airline#highlighter#exec(key.suffix, colors) + endfor + endif + endfor + for sep in w:airline_current_info.separator_groups + call airline#highlighter#exec_separator(sep[0].suffix, sep[1].suffix) + endfor + endfunction + + return highlighter +endfunction + diff --git a/autoload/airline/themes.vim b/autoload/airline/themes.vim index 5cfa777c..9f385d9d 100644 --- a/autoload/airline/themes.vim +++ b/autoload/airline/themes.vim @@ -54,13 +54,3 @@ function! airline#themes#get_highlight2(fg, bg, ...) return s:get_array(fg, bg, a:000) endfunction -function! airline#themes#exec_highlight_separator(from, to) - if a:from == a:to - return a:from - endif - let l:from = airline#themes#get_highlight(a:from) - let l:to = airline#themes#get_highlight(a:to) - let group = a:from.'_to_'.a:to - call airline#exec_highlight(group, [ l:to[1], l:from[1], l:to[3], l:from[3] ]) - return group -endfunction diff --git a/plugin/airline.vim b/plugin/airline.vim index 6b5965c0..a9eda5ac 100644 --- a/plugin/airline.vim +++ b/plugin/airline.vim @@ -1,5 +1,5 @@ " MIT License. Copyright (c) 2013 Bailey Ling. -" vim: ts=2 sts=2 sw=2 fdm=indent +" vim: et ts=2 sts=2 sw=2 fdm=indent if &cp || v:version < 702 || (exists('g:loaded_airline') && g:loaded_airline) finish