From e8d0d24163b05c0cafb01f34f65a389d763c3e89 Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Fri, 23 Aug 2013 21:22:20 +0000 Subject: [PATCH] prefer function name instead of funcref. --- autoload/airline.vim | 17 +++++++++++++++++ autoload/airline/extensions.vim | 9 ++++++--- autoload/airline/extensions/bufferline.vim | 2 +- autoload/airline/extensions/commandt.vim | 2 +- autoload/airline/extensions/csv.vim | 2 +- autoload/airline/extensions/ctrlp.vim | 2 +- autoload/airline/extensions/example.vim | 4 ++-- autoload/airline/extensions/syntastic.vim | 2 +- autoload/airline/extensions/tagbar.vim | 2 +- autoload/airline/extensions/undotree.vim | 2 +- autoload/airline/extensions/whitespace.vim | 2 +- doc/airline.txt | 18 +++++++++++------- plugin/airline.vim | 5 ++--- 13 files changed, 46 insertions(+), 23 deletions(-) diff --git a/autoload/airline.vim b/autoload/airline.vim index 69eb4c0b..12bb33d4 100644 --- a/autoload/airline.vim +++ b/autoload/airline.vim @@ -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() diff --git a/autoload/airline/extensions.vim b/autoload/airline/extensions.vim index c9185456..a4a639df 100644 --- a/autoload/airline/extensions.vim +++ b/autoload/airline/extensions.vim @@ -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(':p:h') @@ -104,7 +107,7 @@ function! airline#extensions#load() autocmd CursorMoved * call 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 diff --git a/autoload/airline/extensions/bufferline.vim b/autoload/airline/extensions/bufferline.vim index a6b9848f..55462364 100644 --- a/autoload/airline/extensions/bufferline.vim +++ b/autoload/airline/extensions/bufferline.vim @@ -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 diff --git a/autoload/airline/extensions/commandt.vim b/autoload/airline/extensions/commandt.vim index 644cc66b..c1e78902 100644 --- a/autoload/airline/extensions/commandt.vim +++ b/autoload/airline/extensions/commandt.vim @@ -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 diff --git a/autoload/airline/extensions/csv.vim b/autoload/airline/extensions/csv.vim index d669be84..4130d1e3 100644 --- a/autoload/airline/extensions/csv.vim +++ b/autoload/airline/extensions/csv.vim @@ -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 diff --git a/autoload/airline/extensions/ctrlp.vim b/autoload/airline/extensions/ctrlp.vim index fe70a896..ec882f19 100644 --- a/autoload/airline/extensions/ctrlp.vim +++ b/autoload/airline/extensions/ctrlp.vim @@ -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 diff --git a/autoload/airline/extensions/example.vim b/autoload/airline/extensions/example.vim index 637f83da..ae1e7646 100644 --- a/autoload/airline/extensions/example.vim +++ b/autoload/airline/extensions/example.vim @@ -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 diff --git a/autoload/airline/extensions/syntastic.vim b/autoload/airline/extensions/syntastic.vim index 21ec0d83..288cdd17 100644 --- a/autoload/airline/extensions/syntastic.vim +++ b/autoload/airline/extensions/syntastic.vim @@ -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 diff --git a/autoload/airline/extensions/tagbar.vim b/autoload/airline/extensions/tagbar.vim index 3326e493..bb957bc4 100644 --- a/autoload/airline/extensions/tagbar.vim +++ b/autoload/airline/extensions/tagbar.vim @@ -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 diff --git a/autoload/airline/extensions/undotree.vim b/autoload/airline/extensions/undotree.vim index f869d0c9..1f1e3acf 100644 --- a/autoload/airline/extensions/undotree.vim +++ b/autoload/airline/extensions/undotree.vim @@ -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 diff --git a/autoload/airline/extensions/whitespace.vim b/autoload/airline/extensions/whitespace.vim index 17f9c087..8f2fd1a7 100644 --- a/autoload/airline/extensions/whitespace.vim +++ b/autoload/airline/extensions/whitespace.vim @@ -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 diff --git a/doc/airline.txt b/doc/airline.txt index 7f1feeb8..10cb8238 100644 --- a/doc/airline.txt +++ b/doc/airline.txt @@ -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: diff --git a/plugin/airline.vim b/plugin/airline.vim index 4a1b87db..022d8fbf 100644 --- a/plugin/airline.vim +++ b/plugin/airline.vim @@ -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 on_window_changed() - autocmd CmdwinLeave * call remove(g:airline_statusline_funcrefs, -1) + autocmd CmdwinLeave * call airline#remove_statusline_func('airline#cmdwinenter') autocmd ColorScheme * call on_colorscheme_changed() autocmd WinEnter,BufWinEnter,FileType,BufUnload,ShellCmdPost *