commit dfba6a17f6c88f9c81576fc6cc9dd477cd3e749e (tree)
parent 859f7eaa709401b384c36d2e6c2ee2e3043dd7a1
Author: Tim Pope <code@tpope.net>
Date: Sun, 20 Nov 2011 15:32:32 -0500
Provide custom 'foldtext'
autocmd FileType git,gitcommit setlocal foldmethod=syntax
Diffstat:
1 file changed, 47 insertions(+), 0 deletions(-)
diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim
@@ -2383,5 +2383,52 @@ function! fugitive#statusline(...)
endfunction
" }}}1
+" Folding {{{1
+
+function! fugitive#foldtext() abort
+ if &foldmethod !=# 'syntax'
+ return foldtext()
+ elseif getline(v:foldstart) =~# '^diff '
+ let [add, remove] = [-1, -1]
+ let filename = ''
+ for lnum in range(v:foldstart, v:foldend)
+ if filename ==# '' && getline(lnum) =~# '^[+-]\{3\} [ab]/'
+ let filename = getline(lnum)[6:-1]
+ endif
+ if getline(lnum) =~# '^+'
+ let add += 1
+ elseif getline(lnum) =~# '^-'
+ let remove += 1
+ elseif getline(lnum) =~# '^Binary '
+ let binary = 1
+ endif
+ endfor
+ if filename ==# ''
+ let filename = matchstr(getline(v:foldstart), '^diff .\{-\} a/\zs.*\ze b/')
+ endif
+ if exists('binary')
+ return 'Binary: '.filename
+ else
+ return (add<10&&remove<100?' ':'') . add . '+ ' . (remove<10&&add<100?' ':'') . remove . '- ' . filename
+ endif
+ elseif getline(v:foldstart) =~# '^# .*:$'
+ let lines = getline(v:foldstart, v:foldend)
+ call filter(lines, 'v:val =~# "^#\t"')
+ cal map(lines,'s:sub(v:val, "^#\t%(modified: +|renamed: +)=", "")')
+ cal map(lines,'s:sub(v:val, "^([[:alpha:] ]+): +(.*)", "\\2 (\\1)")')
+ return getline(v:foldstart).' '.join(lines, ', ')
+ endif
+ return foldtext()
+endfunction
+
+augroup fugitive_foldtext
+ autocmd!
+ autocmd User Fugitive
+ \ if &filetype =~# '^git\%(commit\)\=$' && &foldtext ==# 'foldtext()' |
+ \ set foldtext=fugitive#foldtext() |
+ \ endif
+augroup END
+
+" }}}1
" vim:set et sw=2: