2013-08-16 14:04:03 -04:00
|
|
|
" MIT License. Copyright (c) 2013 Bailey Ling.
|
2013-08-21 11:14:12 -04:00
|
|
|
" vim: et ts=2 sts=2 sw=2
|
2013-08-16 14:04:03 -04:00
|
|
|
|
|
|
|
" Extension specific variables can be defined the usual fashion.
|
|
|
|
if !exists('g:airline#extensions#example#number_of_cats')
|
|
|
|
let g:airline#extensions#example#number_of_cats = 42
|
|
|
|
endif
|
|
|
|
|
2013-08-27 22:36:12 -04:00
|
|
|
" First we define an init function that will be invoked from extensions.vim
|
2013-08-25 11:39:11 -04:00
|
|
|
function! airline#extensions#example#init(ext)
|
|
|
|
|
2013-08-27 22:36:12 -04:00
|
|
|
" Here we define a new part for the plugin. This allows users to place this
|
|
|
|
" extension in arbitrary locations.
|
2013-08-30 18:07:45 -04:00
|
|
|
call airline#parts#define_raw('cats', '%{airline#extensions#example#get_cats()}')
|
2013-08-27 22:36:12 -04:00
|
|
|
|
|
|
|
" Next up we add a funcref so that we can run some code prior to the
|
|
|
|
" statusline getting modifed.
|
2013-08-23 17:22:20 -04:00
|
|
|
call a:ext.add_statusline_func('airline#extensions#example#apply')
|
2013-08-16 14:04:03 -04:00
|
|
|
|
2013-08-27 22:36:12 -04:00
|
|
|
" You can also add a funcref for inactive statuslines.
|
2013-08-25 11:39:11 -04:00
|
|
|
" call a:ext.add_inactive_statusline_func('airline#extensions#example#unapply')
|
2013-08-16 14:04:03 -04:00
|
|
|
endfunction
|
|
|
|
|
2013-08-25 11:39:11 -04:00
|
|
|
" This function will be invoked just prior to the statusline getting modified.
|
2013-08-21 11:14:12 -04:00
|
|
|
function! airline#extensions#example#apply(...)
|
2013-08-25 11:39:11 -04:00
|
|
|
" First we check for the filetype.
|
2013-08-16 14:04:03 -04:00
|
|
|
if &filetype == "nyancat"
|
2013-08-25 11:39:11 -04:00
|
|
|
" 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.
|
2013-08-30 18:07:45 -04:00
|
|
|
call airline#extensions#prepend_to_section('x', airline#parts#get('cats').raw)
|
2013-08-16 14:04:03 -04:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Finally, this function will be invoked from the statusline.
|
|
|
|
function! airline#extensions#example#get_cats()
|
|
|
|
let cats = ''
|
|
|
|
for i in range(1, g:airline#extensions#example#number_of_cats)
|
|
|
|
let cats .= ' (,,,)=(^.^)=(,,,) '
|
|
|
|
endfor
|
|
|
|
return cats
|
|
|
|
endfunction
|
|
|
|
|