Skip to content

Commit

Permalink
Provide custom 'foldtext'
Browse files Browse the repository at this point in the history
    autocmd FileType git,gitcommit setlocal foldmethod=syntax
  • Loading branch information
tpope committed Apr 8, 2012
1 parent 859f7ea commit dfba6a1
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions plugin/fugitive.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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:

0 comments on commit dfba6a1

Please sign in to comment.