Provide custom 'foldtext'
autocmd FileType git,gitcommit setlocal foldmethod=syntax
This commit is contained in:
parent
859f7eaa70
commit
dfba6a17f6
@ -2382,6 +2382,53 @@ function! fugitive#statusline(...)
|
|||||||
endif
|
endif
|
||||||
endfunction
|
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
|
" }}}1
|
||||||
|
|
||||||
" vim:set et sw=2:
|
" vim:set et sw=2:
|
||||||
|
Loading…
Reference in New Issue
Block a user