From a04d7c277a5e7bc99de282f070246edc32e13867 Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Tue, 20 Aug 2013 15:43:26 +0000 Subject: [PATCH] support vim-signify as a hunk source. --- README.md | 3 ++- autoload/airline/extensions.vim | 2 +- autoload/airline/extensions/hunks.vim | 31 +++++++++++++++++++++++---- doc/airline.txt | 3 ++- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 8ca436d8..2cf5b059 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Lean & mean statusline for vim that's light as air. # Features * tiny core written with extensibility in mind ([open/closed principle][8]). -* integrates with a variety of plugins, including: [vim-bufferline][6], [fugitive][4], [unite][9], [ctrlp][10], [minibufexpl][15], [gundo][16], [undotree][17], [nerdtree][18], [tagbar][19], [vim-gitgutter][29], [syntastic][5] and [lawrencium][21]. +* integrates with a variety of plugins, including: [vim-bufferline][6], [fugitive][4], [unite][9], [ctrlp][10], [minibufexpl][15], [gundo][16], [undotree][17], [nerdtree][18], [tagbar][19], [vim-gitgutter][29], [vim-signify][30], [syntastic][5] and [lawrencium][21]. * looks good with regular fonts and provides configuration points so you can use unicode or powerline symbols. * optimized for speed; it loads in under a millisecond. * fully customizable; if you know a little `statusline` syntax you can tweak it to your needs. @@ -136,3 +136,4 @@ MIT license. Copyright (c) 2013 Bailey Ling. [27]: https://github.com/bling/vim-airline/wiki/FAQ [28]: https://github.com/chrisbra/csv.vim [29]: https://github.com/airblade/vim-gitgutter +[30]: https://github.com/mhinz/vim-signify diff --git a/autoload/airline/extensions.vim b/autoload/airline/extensions.vim index e778af46..97640865 100644 --- a/autoload/airline/extensions.vim +++ b/autoload/airline/extensions.vim @@ -129,7 +129,7 @@ function! airline#extensions#load() endif if (get(g:, 'airline#extensions#hunks#enabled', 1) && get(g:, 'airline_enable_hunks', 1)) - \ && exists('*GitGutterGetHunkSummary') + \ && (exists('g:loaded_signify') || exists('g:loaded_gitgutter')) call airline#extensions#hunks#init(s:ext) endif diff --git a/autoload/airline/extensions/hunks.vim b/autoload/airline/extensions/hunks.vim index 8057097d..076b241c 100644 --- a/autoload/airline/extensions/hunks.vim +++ b/autoload/airline/extensions/hunks.vim @@ -4,11 +4,34 @@ let s:non_zero_only = get(g:, 'airline#extensions#hunks#non_zero_only', 0) let s:hunk_symbols = get(g:, 'airline#extensions#hunks#hunk_symbols', ['+', '~', '-']) -function! airline#extensions#hunks#get_hunks() - if get(g:, 'gitgutter_enabled', 0) == 0 - return '' +let s:initialized = 0 +function! s:init() + if !s:initialized + let s:initialized = 1 + if exists('*sy#repo#get_stats') + function! s:get_hunks() + let hunks = sy#repo#get_stats() + return hunks + endfunction + elseif exists('*GitGutterGetHunkSummary') + function! s:get_hunks() + if !get(g:, 'gitgutter_enabled', 0) + return '' + endif + return GitGutterGetHunkSummary() + endfunction + else + let s:non_zero_only = 1 + function! s:get_hunks() + return [0, 0, 0] + endfunction + endif endif - let hunks = GitGutterGetHunkSummary() +endfunction + +function! airline#extensions#hunks#get_hunks() + call init() + let hunks = s:get_hunks() let string = '' for i in [0, 1, 2] if s:non_zero_only == 0 || hunks[i] > 0 diff --git a/doc/airline.txt b/doc/airline.txt index 650ee91c..11319fb8 100644 --- a/doc/airline.txt +++ b/doc/airline.txt @@ -203,8 +203,9 @@ csv.vim < *airline-hunks* vim-gitgutter +vim-signify -* enable/disable detecting changed hunks under source control. > +* enable/disable showing a summary of changed hunks under source control. let g:airline#extensions#hunks#enabled = 1 < * enable/disable showing only non-zero hunks. >