Skip to content

Commit ec57a86

Browse files
committed
Add sy#repo#get_stats_decorated()
It's a common request, so here is the beefed up version of sy#repo#get_stats().
1 parent 25f3d4b commit ec57a86

File tree

2 files changed

+55
-11
lines changed

2 files changed

+55
-11
lines changed

autoload/sy/repo.vim

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,27 @@ function! sy#repo#get_stats(...) abort
234234
return empty(sy) ? [-1, -1, -1] : sy.stats
235235
endfunction
236236

237+
" #get_stats_decorated {{{1
238+
function! sy#repo#get_stats_decorated(...)
239+
let bufnr = a:0 ? a:1 : bufnr('')
240+
let [added, modified, removed] = sy#repo#get_stats(bufnr)
241+
let symbols = ['+', '-', '~']
242+
let stats = [added, removed, modified] " reorder
243+
let statline = ''
244+
245+
for i in range(3)
246+
if stats[i] > 0
247+
let statline .= printf('%s%s ', symbols[i], stats[i])
248+
endif
249+
endfor
250+
251+
if !empty(statline)
252+
let statline = printf('[%s]', statline[:-2])
253+
endif
254+
255+
return statline
256+
endfunction
257+
237258
" #debug_detection {{{1
238259
function! sy#repo#debug_detection()
239260
if !exists('b:sy')

doc/signify.txt

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -563,37 +563,60 @@ color for |hl-Normal| but for |hl-SignColumn|. To avoid that visible difference:
563563
==============================================================================
564564
FAQ *signify-faq*
565565

566-
|signify-faq-01| What about vim-flagship support?
566+
|signify-faq-01| How to display changes in the statusline?
567567
|signify-faq-02| The plugin is slow!
568568
|signify-faq-03| Line highlighting without showing signs?
569569

570570
------------------------------------------------------------------------------
571571
*signify-faq-01*
572-
What about vim-flagship support?~
572+
How to display changes in the statusline?~
573573

574-
sy#repo#get_stats() returns a list with 3 integers for added, modified and
575-
removed lines. Create a wrapper function around it and return a string:
574+
Use either of the following two functions. Both take an optional buffer number
575+
and default to the current one.
576+
577+
- sy#repo#get_stats(...)~
578+
579+
Returns a list with the number of added, modified, and removed lines.
580+
581+
- sy#repo#get_stats_decorated(...)~
582+
583+
Similar to sy#repo#get_stats(), but with added decorations.
584+
Example: "[+3 -8 ~5]"
585+
586+
Using 'statusline':
587+
>
588+
function! MyStatusline()
589+
return ' %f '. sy#repo#get_stats_decorated()
590+
endfunction
591+
592+
set statusline=%!MyStatusline()
593+
<
594+
The above is the short form of:
576595
>
577596
function! s:sy_stats_wrapper()
578-
let symbols = ['+', '-', '~']
579597
let [added, modified, removed] = sy#repo#get_stats()
598+
let symbols = ['+', '-', '~']
580599
let stats = [added, removed, modified] " reorder
581-
let hunkline = ''
600+
let statline = ''
582601

583602
for i in range(3)
584603
if stats[i] > 0
585-
let hunkline .= printf('%s%s ', symbols[i], stats[i])
604+
let statline .= printf('%s%s ', symbols[i], stats[i])
586605
endif
587606
endfor
588607

589-
if !empty(hunkline)
590-
let hunkline = printf('[%s]', hunkline[:-2])
608+
if !empty(statline)
609+
let statline = printf('[%s]', statline[:-2])
591610
endif
592611

593-
return hunkline
612+
return statline
613+
endfunction
614+
615+
function! MyStatusline()
616+
return ' %f '. s:sy_stats_wrapper()
594617
endfunction
595618

596-
autocmd User Flags call Hoist('buffer', function('s:sy_stats_wrapper'))
619+
set statusline=%!MyStatusline()
597620
<
598621
------------------------------------------------------------------------------
599622
*signify-faq-02*

0 commit comments

Comments
 (0)