diff --git a/autoload/sy/repo.vim b/autoload/sy/repo.vim index 7b3ff90f..c83d0c95 100644 --- a/autoload/sy/repo.vim +++ b/autoload/sy/repo.vim @@ -234,6 +234,27 @@ function! sy#repo#get_stats(...) abort return empty(sy) ? [-1, -1, -1] : sy.stats endfunction +" #get_stats_decorated {{{1 +function! sy#repo#get_stats_decorated(...) + let bufnr = a:0 ? a:1 : bufnr('') + let [added, modified, removed] = sy#repo#get_stats(bufnr) + let symbols = ['+', '-', '~'] + let stats = [added, removed, modified] " reorder + let statline = '' + + for i in range(3) + if stats[i] > 0 + let statline .= printf('%s%s ', symbols[i], stats[i]) + endif + endfor + + if !empty(statline) + let statline = printf('[%s]', statline[:-2]) + endif + + return statline +endfunction + " #debug_detection {{{1 function! sy#repo#debug_detection() if !exists('b:sy') diff --git a/doc/signify.txt b/doc/signify.txt index cdbadcd5..b6d2f9d2 100644 --- a/doc/signify.txt +++ b/doc/signify.txt @@ -563,37 +563,60 @@ color for |hl-Normal| but for |hl-SignColumn|. To avoid that visible difference: ============================================================================== FAQ *signify-faq* - |signify-faq-01| What about vim-flagship support? + |signify-faq-01| How to display changes in the statusline? |signify-faq-02| The plugin is slow! |signify-faq-03| Line highlighting without showing signs? ------------------------------------------------------------------------------ *signify-faq-01* -What about vim-flagship support?~ +How to display changes in the statusline?~ -sy#repo#get_stats() returns a list with 3 integers for added, modified and -removed lines. Create a wrapper function around it and return a string: +Use either of the following two functions. Both take an optional buffer number +and default to the current one. + + - sy#repo#get_stats(...)~ + + Returns a list with the number of added, modified, and removed lines. + + - sy#repo#get_stats_decorated(...)~ + + Similar to sy#repo#get_stats(), but with added decorations. + Example: "[+3 -8 ~5]" + +Using 'statusline': +> + function! MyStatusline() + return ' %f '. sy#repo#get_stats_decorated() + endfunction + + set statusline=%!MyStatusline() +< +The above is the short form of: > function! s:sy_stats_wrapper() - let symbols = ['+', '-', '~'] let [added, modified, removed] = sy#repo#get_stats() + let symbols = ['+', '-', '~'] let stats = [added, removed, modified] " reorder - let hunkline = '' + let statline = '' for i in range(3) if stats[i] > 0 - let hunkline .= printf('%s%s ', symbols[i], stats[i]) + let statline .= printf('%s%s ', symbols[i], stats[i]) endif endfor - if !empty(hunkline) - let hunkline = printf('[%s]', hunkline[:-2]) + if !empty(statline) + let statline = printf('[%s]', statline[:-2]) endif - return hunkline + return statline + endfunction + + function! MyStatusline() + return ' %f '. s:sy_stats_wrapper() endfunction - autocmd User Flags call Hoist('buffer', function('s:sy_stats_wrapper')) + set statusline=%!MyStatusline() < ------------------------------------------------------------------------------ *signify-faq-02*