vim-flog
vim-flog copied to clipboard
FR: fold the body of the commit under the cursor
Provide the fold
way to collapse the body of the commit under the cursor, like the git file does.
The doc says using <
>
=
can collapse the body of the commit under the cursor, but fold may be another intuitional way.
Sorry, I'm not quite sure what you mean, can you provide a step-by-step description of how you would like this to work?
Sorry, I'm not quite sure what you mean, can you provide a step-by-step description of how you would like this to work?
- Select a line of file by
V
, then run the:'<,'>Flog
command - The
gloggraph
buffer will list commits and each commit fllowed by a diff - Open the diff in a
flod-side-window
and run:set foldmethod=syntax
command then the diff in aflod-side-window
is foldable - What I would like is the diff in the step2 could be folded like in the step3
I see what you mean. Thanks for the suggestion!
Unfortunately this may be technically impossible in every case because there's no way syntactically to determine the end of a commit with -no-graph
enabled. There may be no way to draw a distinction between the first first line of a new commit and a line in the diff (unless if all diffs never contains a newline - which I think they do). This is part of why folding only works manually now.
Even if it's implemented partially, the Flog syntax groups are quite complex, so it's not so easy to implement, and I'm guessing the Fugitive fold groups are complex as well. I'm not against the idea but I will probably leave this up to a PR.
This is part of why folding only works manually now.
Using foldexpr may work.
You're right, still I will probably leave this up to a PR.
I do not know if the code below is the best way, but there is a issue that the foldtext can not be highlighted. Do you have any thoughts?
" vim-flog/autoload/flog/floggraph/fold.vim
function! flog#floggraph#fold#foldexpr() abort
let l:cur_line = v:lnum
let l:commit = flog#floggraph#commit#GetAtLine(l:cur_line)
if empty(l:commit)
return 0
endif
if l:cur_line == l:commit.line
return 0
endif
return 1
endfunction
function! flog#floggraph#fold#foldtext() abort
let l:commit = flog#floggraph#commit#GetAtLine(v:foldstart)
if empty(l:commit)
return getline(v:foldstart)
endif
return l:commit.collapsed_body
endfunction
setlocal foldmethod=expr
setlocal foldexpr=flog#floggraph#fold#foldexpr()
setlocal foldtext=flog#floggraph#fold#foldtext()