Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: fold the body of the commit under the cursor #118

Open
gh-liu opened this issue Jan 20, 2024 · 6 comments
Open

FR: fold the body of the commit under the cursor #118

gh-liu opened this issue Jan 20, 2024 · 6 comments

Comments

@gh-liu
Copy link

gh-liu commented Jan 20, 2024

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.

@rbong
Copy link
Owner

rbong commented Jan 20, 2024

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?

@gh-liu
Copy link
Author

gh-liu commented Jan 21, 2024

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?

  1. Select a line of file by V, then run the :'<,'>Flog command
  2. The gloggraph buffer will list commits and each commit fllowed by a diff
  3. Open the diff in a flod-side-window and run :set foldmethod=syntax command then the diff in a flod-side-window is foldable
  4. What I would like is the diff in the step2 could be folded like in the step3
Screenshot 2024-01-21 at 08 35 20

@rbong
Copy link
Owner

rbong commented Jan 21, 2024

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.

@gh-liu
Copy link
Author

gh-liu commented Jan 24, 2024

This is part of why folding only works manually now.

Using foldexpr may work.

@rbong
Copy link
Owner

rbong commented Jan 24, 2024

You're right, still I will probably leave this up to a PR.

@gh-liu
Copy link
Author

gh-liu commented Jan 26, 2024

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()
Snipaste_2024-01-26_11-41-41 Snipaste_2024-01-26_13-18-33

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants