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

Highlight diffs when there is unrecognised initial content #121

Closed
dandavison opened this issue Apr 10, 2020 · 4 comments · Fixed by #123
Closed

Highlight diffs when there is unrecognised initial content #121

dandavison opened this issue Apr 10, 2020 · 4 comments · Fixed by #123

Comments

@dandavison
Copy link
Owner

dandavison commented Apr 10, 2020

cc @m-lima @gibfahn Currently, if delta doesn't recognize the type of diff from the first line, it gives up on parsing. I'm aware of two situations where this is too strict:

  1. Magit makes calls like git show -p --cc --format= --numstat --stat. This results in the numstat and stat output appearing before the diff, and the diff is not highlighted as a result. (I'm making it possible to use delta as a diff rendering plugin for magit.)

  2. In Support git stash show --stat --patch #100 delta does not render git stash show --stat --patch correctly for the same reason.

@m-lima
Copy link
Contributor

m-lima commented Apr 10, 2020

I suppose the crux here is to extend detect_source to detect a source based on multiple lines (without consuming them)?

@dandavison
Copy link
Owner Author

dandavison commented Apr 12, 2020

I suppose the crux here is to extend detect_source to detect a source based on multiple lines (without consuming them)?

I was hoping to be able to more flexible and not care what the initial content is until we get to recognizable content. If you would like to, any thoughts you have on #123 would be appreciated!

@gibfahn
Copy link

gibfahn commented Apr 12, 2020

I was hoping to be able to more flexible and not care what the initial content is until we get to recognizable content. If you would like to, any thoughts you have on #123 would be appreciated!

Yeah this sounds really useful, it means we could use delta in places where there is arbitrary text before the diff.

Would this also handle unrecognised text after the diff as well, or is that not possible?

@dandavison
Copy link
Owner Author

Would this also handle unrecognised text after the diff as well, or is that not possible?

Yes, unrecognised text after the diff is printed out. However, currently, the state machine will still be in HUNK mode (see screenshot below, in particular the way that the initial junk is not syntax highlighted but when it occurs further down after a hunk it is.) This can be improved: basically, when in a diff hunk, the first character in each line must be one of {'+', '-', ' '}. However, the current code in #123 doesn't enforce that (I'll put a comment in the code to show why). Thanks, that was a helpful question -- the behaviour below should be fixed either in #123 or perhaps in a subsequent PR.

(
    echo xxxxxxx
    echo "((;;);$~(()"
    git diff --stat --numstat --patch
    echo xxxxxxx
    echo "((;;);$~(()"
    git diff --stat --numstat --patch
    echo xxxxxxx
    echo "((;;);$~(()"
) | delta
image

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

Successfully merging a pull request may close this issue.

3 participants