mirror of
https://github.com/vim-airline/vim-airline.git
synced 2024-11-22 09:17:56 +08:00
prefer function name instead of funcref.
This commit is contained in:
parent
95a46cc106
commit
e8d0d24163
|
@ -1,9 +1,26 @@
|
|||
" MIT License. Copyright (c) 2013 Bailey Ling.
|
||||
" vim: et ts=2 sts=2 sw=2
|
||||
|
||||
let g:airline_statusline_funcrefs = get(g:, 'airline_statusline_funcrefs', [])
|
||||
|
||||
let s:sections = ['a','b','c','gutter','x','y','z','warning']
|
||||
let s:highlighter = airline#highlighter#new()
|
||||
|
||||
function! airline#add_statusline_func(name)
|
||||
call airline#add_statusline_funcref(function(a:name))
|
||||
endfunction
|
||||
|
||||
function! airline#add_statusline_funcref(function)
|
||||
call add(g:airline_statusline_funcrefs, a:function)
|
||||
endfunction
|
||||
|
||||
function! airline#remove_statusline_func(name)
|
||||
let i = index(g:airline_statusline_funcrefs, function(a:name))
|
||||
if i > -1
|
||||
call remove(g:airline_statusline_funcrefs, i)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! airline#load_theme()
|
||||
call s:highlighter.load_theme()
|
||||
call airline#extensions#load_theme()
|
||||
|
|
|
@ -2,8 +2,11 @@
|
|||
" vim: et ts=2 sts=2 sw=2
|
||||
|
||||
let s:ext = {}
|
||||
function! s:ext.add_statusline_funcref(funcref) dict
|
||||
call add(g:airline_statusline_funcrefs, a:funcref)
|
||||
function! s:ext.add_statusline_func(name) dict
|
||||
call airline#add_statusline_func(a:name)
|
||||
endfunction
|
||||
function! s:ext.add_statusline_funcref(function) dict
|
||||
call airline#add_statusline_funcref(a:function)
|
||||
endfunction
|
||||
|
||||
let s:script_path = expand('<sfile>:p:h')
|
||||
|
@ -104,7 +107,7 @@ function! airline#extensions#load()
|
|||
autocmd CursorMoved * call <sid>sync_active_winnr()
|
||||
|
||||
" load core funcrefs
|
||||
call add(g:airline_statusline_funcrefs, function('airline#extensions#update_statusline'))
|
||||
call airline#add_statusline_func('airline#extensions#update_statusline')
|
||||
|
||||
if get(g:, 'loaded_unite', 0)
|
||||
let g:unite_force_overwrite_statusline = 0
|
||||
|
|
|
@ -26,6 +26,6 @@ function! airline#extensions#bufferline#init(ext)
|
|||
let g:bufferline_separator = ' '
|
||||
|
||||
if g:airline_section_c == '%f%m'
|
||||
call a:ext.add_statusline_funcref(function('airline#extensions#bufferline#apply'))
|
||||
call a:ext.add_statusline_func('airline#extensions#bufferline#apply')
|
||||
endif
|
||||
endfunction
|
||||
|
|
|
@ -8,5 +8,5 @@ function! airline#extensions#commandt#apply(...)
|
|||
endfunction
|
||||
|
||||
function! airline#extensions#commandt#init(ext)
|
||||
call a:ext.add_statusline_funcref(function('airline#extensions#commandt#apply'))
|
||||
call a:ext.add_statusline_func('airline#extensions#commandt#apply')
|
||||
endfunction
|
||||
|
|
|
@ -27,6 +27,6 @@ function! airline#extensions#csv#apply(...)
|
|||
endfunction
|
||||
|
||||
function! airline#extensions#csv#init(ext)
|
||||
call a:ext.add_statusline_funcref(function('airline#extensions#csv#apply'))
|
||||
call a:ext.add_statusline_func('airline#extensions#csv#apply')
|
||||
endfunction
|
||||
|
||||
|
|
|
@ -59,6 +59,6 @@ function! airline#extensions#ctrlp#init(ext)
|
|||
\ 'main': 'airline#extensions#ctrlp#ctrlp_airline',
|
||||
\ 'prog': 'airline#extensions#ctrlp#ctrlp_airline_status',
|
||||
\ }
|
||||
call a:ext.add_statusline_funcref(function('airline#extensions#ctrlp#apply'))
|
||||
call a:ext.add_statusline_func('airline#extensions#ctrlp#apply')
|
||||
endfunction
|
||||
|
||||
|
|
|
@ -9,13 +9,13 @@ endif
|
|||
" First you should follow the convention and define an 'init' function.
|
||||
" It takes a single argument, which is the 'ext'ension manager of sorts,
|
||||
" which you can invoke certain functions. The most important one is
|
||||
" 'add_statusline_funcref', which as the name implies, adds a funcref to
|
||||
" 'add_statusline_func', which as the name implies, adds a function to
|
||||
" the collection such that it will be invoked prior to changes being made
|
||||
" to the statusline. Finally, invoke this init function in the
|
||||
" 'extensions.vim' file after a check to a non-autoloaded variable,
|
||||
" command, or function.
|
||||
function! airline#extensions#example#init(ext)
|
||||
call a:ext.add_statusline_funcref(function('airline#extensions#example#apply'))
|
||||
call a:ext.add_statusline_func('airline#extensions#example#apply')
|
||||
|
||||
" Alternatively, you can also modify the default global section by
|
||||
" appending or prepending to it. But read on to see why using the funcref
|
||||
|
|
|
@ -7,6 +7,6 @@ function! airline#extensions#syntastic#apply(...)
|
|||
endfunction
|
||||
|
||||
function! airline#extensions#syntastic#init(ext)
|
||||
call a:ext.add_statusline_funcref(function('airline#extensions#syntastic#apply'))
|
||||
call a:ext.add_statusline_func('airline#extensions#syntastic#apply')
|
||||
endfunction
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ function! s:check_statusline()
|
|||
endfunction
|
||||
|
||||
function! airline#extensions#tagbar#init(ext)
|
||||
call a:ext.add_statusline_funcref(function('airline#extensions#tagbar#apply'))
|
||||
call a:ext.add_statusline_func('airline#extensions#tagbar#apply')
|
||||
|
||||
let g:airline_section_x = '%(%{get(w:,"airline_active",0) ? tagbar#currenttag("%s","") : ""} '
|
||||
\ .g:airline_right_alt_sep.' %)'.g:airline_section_x
|
||||
|
|
|
@ -16,6 +16,6 @@ function! airline#extensions#undotree#apply(...)
|
|||
endfunction
|
||||
|
||||
function! airline#extensions#undotree#init(ext)
|
||||
call a:ext.add_statusline_funcref(function('airline#extensions#undotree#apply'))
|
||||
call a:ext.add_statusline_func('airline#extensions#undotree#apply')
|
||||
endfunction
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ endfunction
|
|||
function! airline#extensions#whitespace#init(...)
|
||||
if !s:initialized
|
||||
let s:initialized = 1
|
||||
call add(g:airline_statusline_funcrefs, function('airline#extensions#whitespace#apply'))
|
||||
call airline#add_statusline_func('airline#extensions#whitespace#apply')
|
||||
endif
|
||||
|
||||
unlet! b:airline_whitespace_check
|
||||
|
|
|
@ -255,11 +255,9 @@ FUNCREFS *airline-funcrefs*
|
|||
vim-airline internally uses funcrefs to integrate with third party plugins,
|
||||
and you can tap into this functionality to extend it for you needs.
|
||||
|
||||
*g:airline_statusline_funcrefs*
|
||||
The g:airline_statusline_funcrefs variable is an array of funcrefs that get
|
||||
invoked before the statusline gets overwritten for each window. The following
|
||||
is an example of how you can extend vim-airline to support a new plugin.
|
||||
>
|
||||
*add_statusline_func*
|
||||
The following is an example of how you can extend vim-airline to support a
|
||||
new plugin. >
|
||||
function! MyPlugin(...)
|
||||
if &filetype == 'MyPluginFileType'
|
||||
let w:airline_section_a = 'MyPlugin'
|
||||
|
@ -268,8 +266,14 @@ is an example of how you can extend vim-airline to support a new plugin.
|
|||
let g:airline_variable_referenced_in_statusline = 'foo'
|
||||
endif
|
||||
endfunction
|
||||
call add(g:airline_statusline_funcrefs, function('MyPlugin'))
|
||||
call airline#add_statusline_func('MyPlugin')
|
||||
<
|
||||
*remove_statusline_func*
|
||||
You can also remove a function as well, if you only need to have something
|
||||
activated temporarily. >
|
||||
call airline#remove_statusline_func('MyPlugin')
|
||||
<
|
||||
|
||||
==============================================================================
|
||||
PIPELINE *airline-pipeline*
|
||||
|
||||
|
@ -307,7 +311,7 @@ For each section that the algorithm encounters, it will first check to see if
|
|||
there is a window-local variable of the section. If it exists, the value will
|
||||
be used, otherwise, the global variable of the section will be used. This
|
||||
means it is possible to override only one or two sections of the statusline.
|
||||
See |g:airline_statusline_funcrefs| for an example of a simple extension.
|
||||
See |add_statusline_func| for an example of a simple extension.
|
||||
|
||||
For contributions into the plugin, here are the following guidelines:
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ 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_statusline_funcrefs', [])
|
||||
|
||||
call s:check_defined('g:airline_mode_map', {
|
||||
\ '__' : '------',
|
||||
|
@ -108,9 +107,9 @@ function! s:airline_toggle()
|
|||
autocmd!
|
||||
|
||||
autocmd CmdwinEnter *
|
||||
\ call add(g:airline_statusline_funcrefs, function('airline#cmdwinenter'))
|
||||
\ call airline#add_statusline_func('airline#cmdwinenter')
|
||||
\ | call <sid>on_window_changed()
|
||||
autocmd CmdwinLeave * call remove(g:airline_statusline_funcrefs, -1)
|
||||
autocmd CmdwinLeave * call airline#remove_statusline_func('airline#cmdwinenter')
|
||||
|
||||
autocmd ColorScheme * call <sid>on_colorscheme_changed()
|
||||
autocmd WinEnter,BufWinEnter,FileType,BufUnload,ShellCmdPost *
|
||||
|
|
Loading…
Reference in New Issue
Block a user