Optimize fugitive#foldtext
Only really relevant when using `set cursorline` [1], but good in general after all. 1: https://github.com/vim/vim/issues/2773
This commit is contained in:
parent
3e0bd86b99
commit
409b098c93
@ -3085,38 +3085,42 @@ augroup END
|
|||||||
function! fugitive#foldtext() abort
|
function! fugitive#foldtext() abort
|
||||||
if &foldmethod !=# 'syntax'
|
if &foldmethod !=# 'syntax'
|
||||||
return foldtext()
|
return foldtext()
|
||||||
elseif getline(v:foldstart) =~# '^diff '
|
endif
|
||||||
|
|
||||||
|
let line_foldstart = getline(v:foldstart)
|
||||||
|
if line_foldstart =~# '^diff '
|
||||||
let [add, remove] = [-1, -1]
|
let [add, remove] = [-1, -1]
|
||||||
let filename = ''
|
let filename = ''
|
||||||
for lnum in range(v:foldstart, v:foldend)
|
for lnum in range(v:foldstart, v:foldend)
|
||||||
if filename ==# '' && getline(lnum) =~# '^[+-]\{3\} [abciow12]/'
|
let line = getline(lnum)
|
||||||
let filename = getline(lnum)[6:-1]
|
if filename ==# '' && line =~# '^[+-]\{3\} [abciow12]/'
|
||||||
|
let filename = line[6:-1]
|
||||||
endif
|
endif
|
||||||
if getline(lnum) =~# '^+'
|
if line =~# '^+'
|
||||||
let add += 1
|
let add += 1
|
||||||
elseif getline(lnum) =~# '^-'
|
elseif line =~# '^-'
|
||||||
let remove += 1
|
let remove += 1
|
||||||
elseif getline(lnum) =~# '^Binary '
|
elseif line =~# '^Binary '
|
||||||
let binary = 1
|
let binary = 1
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
if filename ==# ''
|
if filename ==# ''
|
||||||
let filename = matchstr(getline(v:foldstart), '^diff .\{-\} [abciow12]/\zs.*\ze [abciow12]/')
|
let filename = matchstr(line_foldstart, '^diff .\{-\} [abciow12]/\zs.*\ze [abciow12]/')
|
||||||
endif
|
endif
|
||||||
if filename ==# ''
|
if filename ==# ''
|
||||||
let filename = getline(v:foldstart)[5:-1]
|
let filename = line_foldstart[5:-1]
|
||||||
endif
|
endif
|
||||||
if exists('binary')
|
if exists('binary')
|
||||||
return 'Binary: '.filename
|
return 'Binary: '.filename
|
||||||
else
|
else
|
||||||
return (add<10&&remove<100?' ':'') . add . '+ ' . (remove<10&&add<100?' ':'') . remove . '- ' . filename
|
return (add<10&&remove<100?' ':'') . add . '+ ' . (remove<10&&add<100?' ':'') . remove . '- ' . filename
|
||||||
endif
|
endif
|
||||||
elseif getline(v:foldstart) =~# '^# .*:$'
|
elseif line_foldstart =~# '^# .*:$'
|
||||||
let lines = getline(v:foldstart, v:foldend)
|
let lines = getline(v:foldstart, v:foldend)
|
||||||
call filter(lines, 'v:val =~# "^#\t"')
|
call filter(lines, 'v:val =~# "^#\t"')
|
||||||
cal map(lines,'s:sub(v:val, "^#\t%(modified: +|renamed: +)=", "")')
|
cal map(lines, "s:sub(v:val, '^#\t%(modified: +|renamed: +)=', '')")
|
||||||
cal map(lines,'s:sub(v:val, "^([[:alpha:] ]+): +(.*)", "\\2 (\\1)")')
|
cal map(lines, "s:sub(v:val, '^([[:alpha:] ]+): +(.*)', '\\2 (\\1)')")
|
||||||
return getline(v:foldstart).' '.join(lines, ', ')
|
return line_foldstart.' '.join(lines, ', ')
|
||||||
endif
|
endif
|
||||||
return foldtext()
|
return foldtext()
|
||||||
endfunction
|
endfunction
|
||||||
|
Loading…
x
Reference in New Issue
Block a user