From c2541dd9a958a687581420061d1526b771ca34f2 Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Thu, 4 Jul 2013 11:39:49 -0400 Subject: [PATCH] implement almost full customization support. resolves #3 --- autoload/airline/themes/default.vim | 2 +- doc/airline.txt | 19 +++++++- plugin/airline.vim | 71 +++++++++++++++++------------ 3 files changed, 60 insertions(+), 32 deletions(-) diff --git a/autoload/airline/themes/default.vim b/autoload/airline/themes/default.vim index 5e43e99c..459aa58d 100644 --- a/autoload/airline/themes/default.vim +++ b/autoload/airline/themes/default.vim @@ -11,7 +11,7 @@ let g:airline#themes#default#normal = { \ 'inactive': [ '#4e4e4e' , '#1c1c1c' , 239 , 234 , '' ] , \ } let g:airline#themes#default#normal_modified = copy(g:airline#themes#default#normal) -let g:airline#themes#default#normal_modified.info_separator = [ '#444444' , '#5f005f' , s:N2[3] , 53 , '' ] +let g:airline#themes#default#normal_modified.info_separator = [ '#444444' , '#5f005f' , 238 , 53 , '' ] let g:airline#themes#default#normal_modified.statusline = [ '#ffffff' , '#5f005f' , 255 , 53 , '' ] let s:I1 = [ '#00005f' , '#00dfff' , 17 , 45 ] diff --git a/doc/airline.txt b/doc/airline.txt index d7889914..03a7fb91 100644 --- a/doc/airline.txt +++ b/doc/airline.txt @@ -65,6 +65,11 @@ values): let g:airline_powerline_fonts=0 < +* define the set of text to display for each mode. +> + let g:airline_mode_map = {} " see source for current list +< + * define the set of filename match queries which excludes a window from having its statusline modified > @@ -98,11 +103,23 @@ well as the powerline font glyths let g:airline_left_sep = '' let g:airline_right_sep = '' let g:airline_right_sep = '' - let g:airline_fugitive_prefix = '  ' + let g:airline_fugitive_prefix = ' ' let g:airline_readonly_symbol = '' let g:airline_linecolumn_prefix = ' ' < +for more intricate customizations, you can replace the predefined sections +with the usual *statusline* syntax. + +> + let g:airline_section_a (the mode indicator) + let g:airline_section_b (the fugitive branch indicator) + let g:airline_section_c (bufferline or filename) + let g:airline_section_x (filetype) + let g:airline_section_y (fileencoding, fileformat) + let g:airline_section_z (percentage, line number, column number) +< + ============================================================================== CONTRIBUTIONS *airline-contributions* diff --git a/plugin/airline.vim b/plugin/airline.vim index 0e249bab..433c4a2c 100644 --- a/plugin/airline.vim +++ b/plugin/airline.vim @@ -1,4 +1,4 @@ -" vim: ts=2 sts=2 sw=2 +" vim: ts=2 sts=2 sw=2 fdm=indent if &cp || v:version < 702 || (exists('g:loaded_airline') && g:loaded_airline) finish endif @@ -16,7 +16,7 @@ call s:check_defined('g:airline_right_sep', exists('g:airline_powerline_fonts')? call s:check_defined('g:airline_enable_bufferline', 1) call s:check_defined('g:airline_enable_fugitive', 1) call s:check_defined('g:airline_enable_syntastic', 1) -call s:check_defined('g:airline_fugitive_prefix', exists('g:airline_powerline_fonts')?'  ':' ') +call s:check_defined('g:airline_fugitive_prefix', exists('g:airline_powerline_fonts')?' ':'') call s:check_defined('g:airline_readonly_symbol', exists('g:airline_powerline_fonts')?'':'RO') call s:check_defined('g:airline_linecolumn_prefix', exists('g:airline_powerline_fonts')?' ':':') call s:check_defined('g:airline_theme', 'default') @@ -27,15 +27,15 @@ call s:check_defined('g:airline_exclude_filetypes', ['qf','netrw','diff','undotr let s:is_win32term = (has('win32') || has('win64')) && !has('gui_running') let s:load_the_theme = g:airline#themes#{g:airline_theme}#normal -let s:airline_mode_map = { - \ 'n' : ' NORMAL ', - \ 'i' : ' INSERT ', - \ 'R' : ' RPLACE ', - \ 'v' : ' VISUAL ', - \ 'V' : ' V-LINE ', - \ 'c' : ' CMD ', - \ '' : ' V-BLCK ', - \ } +call s:check_defined('g:airline_mode_map', { + \ 'n' : 'NORMAL', + \ 'i' : 'INSERT', + \ 'R' : 'RPLACE', + \ 'v' : 'VISUAL', + \ 'V' : 'V-LINE', + \ 'c' : 'CMD ', + \ '' : 'V-BLCK', + \ }) let s:airline_highlight_map = { \ 'mode' : 'User2', \ 'mode_separator' : 'User3', @@ -82,10 +82,19 @@ function! s:is_excluded_window() endfunction function! s:update_externals() - let g:airline_externals_bufferline = g:airline_enable_bufferline && exists('g:bufferline_loaded') ? bufferline#generate_string() : "%f%m" - let g:airline_externals_fugitive = g:airline_enable_fugitive && exists('g:loaded_fugitive') ? g:airline_fugitive_prefix.fugitive#head() : '' + let g:airline_externals_bufferline = g:airline_enable_bufferline && exists('g:bufferline_loaded') ? '%{bufferline#generate_string()}' : "%f%m" let g:airline_externals_syntastic = g:airline_enable_syntastic && exists('g:loaded_syntastic_plugin') ? '%{SyntasticStatuslineFlag()}' : '' + let g:airline_externals_fugitive = g:airline_enable_fugitive && exists('g:loaded_fugitive') && strlen(fugitive#head()) > 0 + \ ? g:airline_fugitive_prefix.fugitive#head() : '' endfunction +call s:update_externals() + +call s:check_defined('g:airline_section_a', '%{g:airline_current_mode_text}') +call s:check_defined('g:airline_section_b', '%{g:airline_externals_fugitive}') +call s:check_defined('g:airline_section_c', g:airline_externals_bufferline) +call s:check_defined('g:airline_section_x', "%{strlen(&filetype)>0?&filetype:''}") +call s:check_defined('g:airline_section_y', "%{strlen(&fenc)>0?&fenc:''}%{strlen(&ff)>0?'['.&ff.']':''}") +call s:check_defined('g:airline_section_z', '%3p%% '.g:airline_linecolumn_prefix.'%3l:%3c') function! s:update_statusline(active) if s:is_excluded_window() @@ -100,30 +109,34 @@ function! s:update_statusline(active) let l:status_color = a:active ? "%6*" : "%9*" let l:file_flag_color = a:active ? "%8*" : "%9*" - let sl = a:active ? l:mode_color."%{AirlineModePrefix()}".l:mode_sep_color : l:mode_color." NORMAL %9*" - let sl.="%{g:airline_left_sep}".l:info_color - let sl.=g:airline_externals_fugitive - let sl.=' '.l:info_sep_color."%{g:airline_left_sep}" + let sl = l:mode_color + let sl.= a:active + \ ? '%{AirlineUpdateHighlight()} '.g:airline_section_a.' '.l:mode_sep_color + \ : ' %9*' + let sl.='%{g:airline_left_sep}'.l:info_color + let sl.=' '.g:airline_section_b.' ' + let sl.=l:info_sep_color.g:airline_left_sep if a:active - let sl.=l:status_color.' '.g:airline_externals_bufferline.' ' + let sl.=l:status_color.' '.g:airline_section_c.' ' else let sl.=" ".bufname(winbufnr(winnr())) endif let sl.="%#warningmsg#" let sl.=g:airline_externals_syntastic - let sl.=l:status_color."%<%=".l:file_flag_color."%{&ro? g:airline_readonly_symbol :''}" + let sl.=l:status_color."%<%=".l:file_flag_color."%{&ro ? g:airline_readonly_symbol : ''}" let sl.="%q%{&previewwindow?'[preview]':''}" - let sl.=l:status_color."\ %{strlen(&filetype)>0?&filetype:''}\ " - let sl.=l:info_sep_color."%{g:airline_right_sep}".l:info_color."\ " - let sl.="%{strlen(&fileencoding)>0?&fileencoding:''}" - let sl.="%{strlen(&fileformat)>0?'['.&fileformat.']':''}" - let sl.="\ ".l:mode_sep_color."%{g:airline_right_sep}" - let sl.=l:mode_color."\ %3p%%\ ".g:airline_linecolumn_prefix."%3l:%3c\ " + let sl.=l:status_color + let sl.=' '.g:airline_section_x.' ' + let sl.=l:info_sep_color.g:airline_right_sep.l:info_color + let sl.=' '.g:airline_section_y.' ' + let sl.=l:mode_sep_color.g:airline_right_sep.l:mode_color + let sl.=' '.g:airline_section_z.' ' call setwinvar(winnr(), '&statusline', sl) endfunction let s:lastmode = '' -function! AirlineModePrefix() +let g:airline_current_mode_text = '' +function! AirlineUpdateHighlight() let l:m = mode() let l:mode = 'normal' if l:m ==# "i" || l:m ==# "R" @@ -141,10 +154,8 @@ function! AirlineModePrefix() let s:lastmode = l:mode endif - if has_key(s:airline_mode_map, l:m) - return s:airline_mode_map[l:m] - endif - return l:mode + let g:airline_current_mode_text = get(g:airline_mode_map, l:m, l:m) + return '' endfunction augroup airline