Merge branch 'dev'

Implements #204.

Conflicts:
	README.md
This commit is contained in:
Bailey Ling
2013-08-31 15:02:01 +00:00
25 changed files with 536 additions and 127 deletions

View File

@@ -27,10 +27,12 @@ function! airline#extensions#branch#get_head()
endif
endif
return empty(head) ? s:empty_message : s:symbol.' '.head
return empty(head)
\ ? s:empty_message
\ : printf('%s%s', empty(s:symbol) ? '' : s:symbol.' ', head)
endfunction
function! airline#extensions#branch#init(ext)
let g:airline_parts.branch = '%{airline#extensions#branch#get_head()}'
call airline#parts#define_function('branch', 'airline#extensions#branch#get_head')
endfunction

View File

@@ -14,5 +14,6 @@ function! airline#extensions#bufferline#init(ext)
let g:bufferline_separator = ' '
endif
let g:airline_parts.file = '%{bufferline#refresh_status()}'.bufferline#get_status_string()
call airline#parts#define_raw('file', '%{bufferline#refresh_status()}'.bufferline#get_status_string())
endfunction

View File

@@ -11,7 +11,7 @@ function! airline#extensions#example#init(ext)
" Here we define a new part for the plugin. This allows users to place this
" extension in arbitrary locations.
let g:airline_parts.cats = '%{airline#extensions#example#get_cats()}'
call airline#parts#define_raw('cats', '%{airline#extensions#example#get_cats()}')
" Next up we add a funcref so that we can run some code prior to the
" statusline getting modifed.
@@ -28,7 +28,7 @@ function! airline#extensions#example#apply(...)
" Let's use a helper function. It will take care of ensuring that the
" window-local override exists (and create one based on the global
" airline_section if not), and prepend to it.
call airline#extensions#prepend_to_section('x', g:airline_parts.cats)
call airline#extensions#prepend_to_section('x', airline#parts#get('cats').raw)
endif
endfunction

View File

@@ -54,6 +54,6 @@ function! airline#extensions#hunks#get_hunks()
endfunction
function! airline#extensions#hunks#init(ext)
let g:airline_parts.hunks = '%{airline#extensions#hunks#get_hunks()}'
call airline#parts#define_function('hunks', 'airline#extensions#hunks#get_hunks')
endfunction

View File

@@ -10,6 +10,6 @@ function! airline#extensions#syntastic#get_warnings()
endfunction
function! airline#extensions#syntastic#init(ext)
let g:airline_parts.syntastic = '%{airline#extensions#syntastic#get_warnings()}'
call airline#parts#define_function('syntastic', 'airline#extensions#syntastic#get_warnings')
endfunction

View File

@@ -16,11 +16,17 @@ function! airline#extensions#tagbar#inactive_apply(...)
endif
endfunction
function! airline#extensions#tagbar#currenttag()
if get(w:, 'airline_active', 0)
return tagbar#currenttag('%s', '')
endif
return ''
endfunction
function! airline#extensions#tagbar#init(ext)
call a:ext.add_inactive_statusline_func('airline#extensions#tagbar#inactive_apply')
let g:tagbar_status_func = 'airline#extensions#tagbar#get_status'
let g:airline_parts.tagbar = '%(%{get(w:,"airline_active",0) ? tagbar#currenttag("%s","") : ""} '
\ .g:airline_right_alt_sep.' %)'
call airline#parts#define_function('tagbar', 'airline#extensions#tagbar#currenttag')
endfunction

View File

@@ -56,6 +56,7 @@ endfunction!
function! airline#extensions#whitespace#toggle()
if s:enabled
autocmd! airline_whitespace CursorHold,BufWritePost
augroup! airline_whitespace
let s:enabled = 0
else
call airline#extensions#whitespace#init()
@@ -65,7 +66,7 @@ function! airline#extensions#whitespace#toggle()
endfunction
function! airline#extensions#whitespace#init(...)
let g:airline_parts.whitespace = '%{airline#extensions#whitespace#check()}'
call airline#parts#define_function('whitespace', 'airline#extensions#whitespace#check')
unlet! b:airline_whitespace_check
augroup airline_whitespace

94
autoload/airline/init.vim Normal file
View File

@@ -0,0 +1,94 @@
" 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_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 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 airline#parts#define_raw('ffenc', '%{printf("%s%s",&fenc,strlen(&ff)>0?"[".&ff."]":"")}')
call airline#parts#define_empty(['hunks', 'branch', 'tagbar', 'syntastic'])
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
if !exists('g:airline_section_c')
let g:airline_section_c = airline#section#create(['%<', 'file'])
endif
if !exists('g:airline_section_gutter')
let g:airline_section_gutter = airline#section#create([' ', 'readonly', '%='])
endif
if !exists('g:airline_section_x')
let g:airline_section_x = airline#section#create_right(['tagbar', '%{&filetype}'])
endif
if !exists('g:airline_section_y')
let g:airline_section_y = airline#section#create_right(['ffenc'])
endif
if !exists('g:airline_section_z')
let g:airline_section_z = airline#section#create_right(['%3p%% %{g:airline_symbols.linenr} %3l:%3c '])
endif
if !exists('g:airline_section_warning')
let g:airline_section_warning = airline#section#create(['syntastic', 'whitespace'])
endif
endfunction

View File

@@ -1,13 +1,46 @@
" MIT License. Copyright (c) 2013 Bailey Ling.
" vim: et ts=2 sts=2 sw=2
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)
endfunction
function! airline#parts#define_function(key, name)
call airline#parts#define(a:key, { 'function': a:name })
endfunction
function! airline#parts#define_text(key, text)
call airline#parts#define(a:key, { 'text': a:text })
endfunction
function! airline#parts#define_raw(key, raw)
call airline#parts#define(a:key, { 'raw': a:raw })
endfunction
function! airline#parts#define_empty(keys)
for key in a:keys
call airline#parts#define_raw(key, '')
endfor
endfunction
function! airline#parts#get(key)
return get(s:parts, a:key, {})
endfunction
function! airline#parts#mode()
return get(w:, 'airline_current_mode', '')
endfunction
function! airline#parts#paste()
return g:airline_detect_paste && &paste ? ' '.g:airline_symbols.paste : ''
return g:airline_detect_paste && &paste ? g:airline_symbols.paste : ''
endfunction
function! airline#parts#iminsert()
if g:airline_detect_iminsert && &iminsert && exists('b:keymap_name')
return ' '.g:airline_left_alt_sep.' '.toupper(b:keymap_name)
return toupper(b:keymap_name)
endif
return ''
endfunction

View File

@@ -0,0 +1,52 @@
" MIT License. Copyright (c) 2013 Bailey Ling.
" vim: et ts=2 sts=2 sw=2
function! s:get_val(key, append)
let part = airline#parts#get(a:key)
let val = ''
if exists('part.highlight')
let val .= '%#'.(part.highlight).'#'
endif
if exists('part.function')
let func = (part.function).'()'
elseif exists('part.text')
let func = '"'.(part.text).'"'
elseif exists('part.raw')
return val.(part.raw)
else
return a:key
endif
if a:append > 0
let val .= '%{airline#util#append('.func.')}'
elseif a:append < 0
let val .= '%{airline#util#prepend('.func.')}'
else
let val .= '%{'.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

View File

@@ -1,6 +1,14 @@
" MIT License. Copyright (c) 2013 Bailey Ling.
" vim: et ts=2 sts=2 sw=2
function! airline#util#append(text)
return empty(a:text) ? '' : ' '.g:airline_left_alt_sep.' '.a:text
endfunction
function! airline#util#prepend(text)
return empty(a:text) ? '' : a:text.' '.g:airline_right_alt_sep.' '
endfunction
if v:version >= 704
function! airline#util#getwinvar(winnr, key, def)
return getwinvar(a:winnr, a:key, a:def)