2018-01-05 17:37:59 +08:00
|
|
|
" MIT License. Copyright (c) 2013-2018 Bailey Ling et al.
|
2013-08-21 23:14:12 +08:00
|
|
|
" vim: et ts=2 sts=2 sw=2
|
2013-08-17 02:04:03 +08:00
|
|
|
|
2016-09-24 08:16:30 +08:00
|
|
|
scriptencoding utf-8
|
|
|
|
|
2013-09-10 23:37:25 +08:00
|
|
|
" we don't actually want this loaded :P
|
|
|
|
finish
|
|
|
|
|
2013-09-22 23:29:27 +08:00
|
|
|
" Due to some potential rendering issues, the use of the `space` variable is
|
|
|
|
" recommended.
|
|
|
|
let s:spc = g:airline_symbols.space
|
|
|
|
|
2013-08-17 02:04:03 +08: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-28 10:36:12 +08:00
|
|
|
" First we define an init function that will be invoked from extensions.vim
|
2013-08-25 23:39:11 +08:00
|
|
|
function! airline#extensions#example#init(ext)
|
|
|
|
|
2013-08-28 10:36:12 +08:00
|
|
|
" Here we define a new part for the plugin. This allows users to place this
|
|
|
|
" extension in arbitrary locations.
|
2013-08-31 06:07:45 +08:00
|
|
|
call airline#parts#define_raw('cats', '%{airline#extensions#example#get_cats()}')
|
2013-08-28 10:36:12 +08:00
|
|
|
|
|
|
|
" Next up we add a funcref so that we can run some code prior to the
|
|
|
|
" statusline getting modifed.
|
2013-08-24 05:22:20 +08:00
|
|
|
call a:ext.add_statusline_func('airline#extensions#example#apply')
|
2013-08-17 02:04:03 +08:00
|
|
|
|
2013-08-28 10:36:12 +08:00
|
|
|
" You can also add a funcref for inactive statuslines.
|
2013-08-25 23:39:11 +08:00
|
|
|
" call a:ext.add_inactive_statusline_func('airline#extensions#example#unapply')
|
2013-08-17 02:04:03 +08:00
|
|
|
endfunction
|
|
|
|
|
2013-08-25 23:39:11 +08:00
|
|
|
" This function will be invoked just prior to the statusline getting modified.
|
2013-08-21 23:14:12 +08:00
|
|
|
function! airline#extensions#example#apply(...)
|
2013-08-25 23:39:11 +08:00
|
|
|
" First we check for the filetype.
|
2013-08-17 02:04:03 +08:00
|
|
|
if &filetype == "nyancat"
|
2013-08-31 23:29:04 +08:00
|
|
|
|
|
|
|
" Let's say we want to append to section_c, first we check if there's
|
|
|
|
" already a window-local override, and if not, create it off of the global
|
|
|
|
" section_c.
|
|
|
|
let w:airline_section_c = get(w:, 'airline_section_c', g:airline_section_c)
|
|
|
|
|
|
|
|
" Then we just append this extenion to it, optionally using separators.
|
2013-09-22 23:29:27 +08:00
|
|
|
let w:airline_section_c .= s:spc.g:airline_left_alt_sep.s:spc.'%{airline#extensions#example#get_cats()}'
|
2013-08-17 02:04:03 +08: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
|