From 93eb0389b91c610a8e371d7548f6d4b70fe72ff7 Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Fri, 30 Aug 2013 21:56:12 +0000 Subject: [PATCH] move init code into new file, add section. --- autoload/airline/init.vim | 87 ++++++++++++++++++++++++++++++++++++ autoload/airline/section.vim | 47 +++++++++++++++++++ plugin/airline.vim | 82 +-------------------------------- 3 files changed, 135 insertions(+), 81 deletions(-) create mode 100644 autoload/airline/init.vim create mode 100644 autoload/airline/section.vim diff --git a/autoload/airline/init.vim b/autoload/airline/init.vim new file mode 100644 index 00000000..cb53f5ed --- /dev/null +++ b/autoload/airline/init.vim @@ -0,0 +1,87 @@ +" MIT License. Copyright (c) 2013 Bailey Ling. +" vim: et ts=2 sts=2 sw=2 + +function! s:check_defined(variable, default) + if !exists(a:variable) + let {a:variable} = a:default + endif +endfunction + +function! airline#init#bootstrap() + call s:check_defined('g:airline_left_sep', get(g:, 'airline_powerline_fonts', 0)?"":">") + call s:check_defined('g:airline_left_alt_sep', get(g:, 'airline_powerline_fonts', 0)?"":">") + call s:check_defined('g:airline_right_sep', get(g:, 'airline_powerline_fonts', 0)?"":"<") + call s:check_defined('g:airline_right_alt_sep', get(g:, 'airline_powerline_fonts', 0)?"":"<") + call s:check_defined('g:airline_detect_modified', 1) + call s:check_defined('g:airline_detect_paste', 1) + call s:check_defined('g:airline_detect_iminsert', 0) + call s:check_defined('g:airline_inactive_collapse', 1) + call s:check_defined('g:airline_exclude_filenames', ['DebuggerWatch','DebuggerStack','DebuggerStatus']) + call s:check_defined('g:airline_exclude_filetypes', []) + call s:check_defined('g:airline_exclude_preview', 0) + + call s:check_defined('g:airline_symbols', {}) + call extend(g:airline_symbols, { + \ 'paste': get(g:, 'airline_paste_symbol', 'PASTE'), + \ 'readonly': get(g:, 'airline_readonly_symbol', get(g:, 'airline_powerline_fonts', 0) ? '' : 'RO'), + \ 'whitespace': get(g:, 'airline_powerline_fonts', 0) ? '✹' : '!', + \ 'linenr': get(g:, 'airline_linecolumn_prefix', get(g:, 'airline_powerline_fonts', 0) ? '' : ':' ), + \ 'branch': get(g:, 'airline_branch_prefix', get(g:, 'airline_powerline_fonts', 0) ? '' : ''), + \ }, 'keep') + + call airline#parts#define_function('mode', 'airline#parts#mode') + call airline#parts#define_function('iminsert', 'airline#parts#iminsert') + call airline#parts#define_function('paste', 'airline#parts#paste') + call airline#parts#define('readonly', { + \ 'function': 'airline#parts#readonly', + \ 'highlight': 'airline_file', + \ }) + call airline#parts#define_raw('file', '%f%m') + + call s:check_defined('g:airline_parts', {}) + call extend(g:airline_parts, { + \ 'ffenc': '%{printf("%s%s",&fenc,strlen(&ff)>0?"[".&ff."]":"")}', + \ 'tagbar': 'airline#parts#empty', + \ 'syntastic': 'airline#parts#empty', + \ 'whitespace': 'airline#parts#empty', + \ }, 'keep') + + call s:check_defined('g:airline_mode_map', {}) + call extend(g:airline_mode_map, { + \ '__' : '------', + \ 'n' : 'NORMAL', + \ 'i' : 'INSERT', + \ 'R' : 'REPLACE', + \ 'v' : 'VISUAL', + \ 'V' : 'V-LINE', + \ 'c' : 'COMMAND', + \ '' : 'V-BLOCK', + \ 's' : 'SELECT', + \ 'S' : 'S-LINE', + \ '' : 'S-BLOCK', + \ }, 'keep') + + call s:check_defined('g:airline_theme_map', {}) + call extend(g:airline_theme_map, { + \ 'Tomorrow.*': 'tomorrow', + \ 'mo[l|n]okai': 'molokai', + \ 'wombat.*': 'wombat', + \ '.*solarized.*': 'solarized', + \ }, 'keep') + + call airline#extensions#load() + + if !exists('g:airline_section_a') + let g:airline_section_a = airline#section#create_left(['mode', 'paste', 'iminsert']) + endif + if !exists('g:airline_section_b') + let g:airline_section_b = airline#section#create(['hunks', 'branch']) + endif + let g:airline_section_c = airline#section#create(['%<', 'file']) + let g:airline_section_gutter = airline#section#create([' ', 'readonly', '%=']) + let g:airline_section_x = airline#section#create(['tagbar', '%{&filetype}']) + let g:airline_section_y = airline#section#create(['ffenc']) + let g:airline_section_z = airline#section#create(['%3p%% %{g:airline_symbols.linenr} %3l:%3c ']) + let g:airline_section_warning = airline#section#create(['syntastic', 'whitespace']) +endfunction + diff --git a/autoload/airline/section.vim b/autoload/airline/section.vim new file mode 100644 index 00000000..788b443b --- /dev/null +++ b/autoload/airline/section.vim @@ -0,0 +1,47 @@ +" MIT License. Copyright (c) 2013 Bailey Ling. +" vim: et ts=2 sts=2 sw=2 + +function! s:get_val(key, append) + let val = '' + let part = airline#parts#get(a:key) + if exists('part.function') + let func = (part.function).'()' + elseif exists('part.text') + let func = '"'.(part.text).'"' + elseif exists('part.raw') + return part.raw + else + return a:key + endif + + if a:append > 0 + let val .= '%{airline#util#append('.func.')}' + elseif a:append < 0 + return '%{airline#util#prepend('.func.')}' + else + return '%{'.func.'}' + endif + return val +endfunction + +function! airline#section#create(parts) + return join(map(a:parts, 's:get_val(v:val, 0)'), '') +endfunction + +function! airline#section#create_left(parts) + let _ = s:get_val(a:parts[0], 0) + for i in range(1, len(a:parts) - 1) + let _ .= s:get_val(a:parts[i], 1) + endfor + return _ +endfunction + +function! airline#section#create_right(parts) + let _ = '' + for i in range(0, len(a:parts) - 2) + let _ .= s:get_val(a:parts[i], -1) + endfor + let _ .= s:get_val(a:parts[-1], 0) + return _ +endfunction + diff --git a/plugin/airline.vim b/plugin/airline.vim index b54ae3c1..f1164da7 100644 --- a/plugin/airline.vim +++ b/plugin/airline.vim @@ -8,93 +8,13 @@ let g:loaded_airline = 1 " autocmd VimEnter * call airline#deprecation#check() -function! s:check_defined(variable, default) - if !exists(a:variable) - let {a:variable} = a:default - endif -endfunction - let s:airline_initialized = 0 let s:airline_theme_defined = 0 function! s:init() if !s:airline_initialized let s:airline_initialized = 1 - call s:check_defined('g:airline_left_sep', get(g:, 'airline_powerline_fonts', 0)?"":">") - call s:check_defined('g:airline_left_alt_sep', get(g:, 'airline_powerline_fonts', 0)?"":">") - call s:check_defined('g:airline_right_sep', get(g:, 'airline_powerline_fonts', 0)?"":"<") - call s:check_defined('g:airline_right_alt_sep', get(g:, 'airline_powerline_fonts', 0)?"":"<") - call s:check_defined('g:airline_detect_modified', 1) - call s:check_defined('g:airline_detect_paste', 1) - call s:check_defined('g:airline_detect_iminsert', 0) - call s:check_defined('g:airline_inactive_collapse', 1) - call s:check_defined('g:airline_exclude_filenames', ['DebuggerWatch','DebuggerStack','DebuggerStatus']) - call s:check_defined('g:airline_exclude_filetypes', []) - call s:check_defined('g:airline_exclude_preview', 0) - - call s:check_defined('g:airline_symbols', {}) - call extend(g:airline_symbols, { - \ 'paste': get(g:, 'airline_paste_symbol', 'PASTE'), - \ 'readonly': get(g:, 'airline_readonly_symbol', get(g:, 'airline_powerline_fonts', 0) ? '' : 'RO'), - \ 'whitespace': get(g:, 'airline_powerline_fonts', 0) ? '✹' : '!', - \ 'linenr': get(g:, 'airline_linecolumn_prefix', get(g:, 'airline_powerline_fonts', 0) ? '' : ':' ), - \ 'branch': get(g:, 'airline_branch_prefix', get(g:, 'airline_powerline_fonts', 0) ? '' : ''), - \ }, 'keep') - - call airline#parts#define_function('mode', 'airline#parts#mode') - call airline#parts#define_function('iminsert', 'airline#parts#iminsert') - call airline#parts#define_function('paste', 'airline#parts#paste') - call airline#parts#define('readonly', { - \ 'function': 'airline#parts#readonly', - \ 'highlight': 'airline_file', - \ }) - call airline#parts#define_raw('file', '%f%m') - - call s:check_defined('g:airline_parts', {}) - call extend(g:airline_parts, { - \ 'ffenc': '%{printf("%s%s",&fenc,strlen(&ff)>0?"[".&ff."]":"")}', - \ 'tagbar': 'airline#parts#empty', - \ 'syntastic': 'airline#parts#empty', - \ 'whitespace': 'airline#parts#empty', - \ }, 'keep') - - call s:check_defined('g:airline_mode_map', {}) - call extend(g:airline_mode_map, { - \ '__' : '------', - \ 'n' : 'NORMAL', - \ 'i' : 'INSERT', - \ 'R' : 'REPLACE', - \ 'v' : 'VISUAL', - \ 'V' : 'V-LINE', - \ 'c' : 'COMMAND', - \ '' : 'V-BLOCK', - \ 's' : 'SELECT', - \ 'S' : 'S-LINE', - \ '' : 'S-BLOCK', - \ }, 'keep') - - call s:check_defined('g:airline_theme_map', {}) - call extend(g:airline_theme_map, { - \ 'Tomorrow.*': 'tomorrow', - \ 'mo[l|n]okai': 'molokai', - \ 'wombat.*': 'wombat', - \ '.*solarized.*': 'solarized', - \ }, 'keep') - - call airline#extensions#load() - - if !exists('g:airline_section_a') - let g:airline_section_a = airline#section#create_left(['mode', 'paste', 'iminsert']) - endif - if !exists('g:airline_section_b') - let g:airline_section_b = airline#section#create(['hunks', 'branch']) - endif - let g:airline_section_c = airline#section#create(['%<', 'file']) - let g:airline_section_gutter = airline#section#create([' ', 'readonly', '%=']) - let g:airline_section_x = airline#section#create(['tagbar', '%{&filetype}']) - let g:airline_section_y = airline#section#create(['ffenc']) - let g:airline_section_z = airline#section#create(['%3p%% %{g:airline_symbols.linenr} %3l:%3c ']) - let g:airline_section_warning = airline#section#create(['syntastic', 'whitespace']) + call airline#init#bootstrap() let s:airline_theme_defined = exists('g:airline_theme') if s:airline_theme_defined || !airline#switch_matching_theme()