From dfba6a17f6c88f9c81576fc6cc9dd477cd3e749e Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Sun, 20 Nov 2011 15:32:32 -0500 Subject: [PATCH] Provide custom 'foldtext' autocmd FileType git,gitcommit setlocal foldmethod=syntax --- plugin/fugitive.vim | 47 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim index 0a61f88..a3ec3cf 100644 --- a/plugin/fugitive.vim +++ b/plugin/fugitive.vim @@ -2382,6 +2382,53 @@ function! fugitive#statusline(...) endif 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: