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

No way to disable syntax in hunk header🐛 #1032

Closed
washtubs opened this issue Apr 2, 2022 · 10 comments · Fixed by #1568
Closed

No way to disable syntax in hunk header🐛 #1032

washtubs opened this issue Apr 2, 2022 · 10 comments · Fixed by #1568

Comments

@washtubs
Copy link

washtubs commented Apr 2, 2022

The help menu seems to suggest that I can adjust this

    --hunk-header-style <STYLE>
        Style string for the hunk-header.
        
        See STYLES section. Special attributes 'file' and 'line-number' can be used to include the file path, and number of first hunk line, in the hunk header. The style 'omit' can be used to remove the hunk header section from the output.
        
        [default: "line-number syntax"]

However if I use --hunk-header-style "line-number" without specifying syntax I still see the syntax. I would think since I didn't specify syntax it wouldn't show that. I understand changing this might be considered "breaking". Is there any other way to keep the hunk header but not show the syntax? Maybe a new nosyntax option? Personally I like having the hunk headers clearly visible, but I find the syntax to just be distracting for the files I'm comparing.

@deanhouseholder
Copy link

+1 - I'm also annoyed by this as the syntax is often not helpful.

@dandavison
Copy link
Owner

Hey @washtubs, @deanhouseholder. I agree that it should let you do this! Are you sure it isn't working already though? A quick test:

git show | delta --no-gitconfig

image

git show | delta --no-gitconfig --hunk-header-style line-number

image

I'm also able to reproduce that using gitconfig

[delta]
   hunk-header-style = line-number

@washtubs
Copy link
Author

Oh I don't mean the coloring, I was thinking in your second example, it should just be a box with "21:". That was my understanding of what syntax referred to unless I'm missing something?

@dandavison
Copy link
Owner

Ah, right! No, syntax says "I want syntax highlighting colors on this piece of text (assuming it can be interpreted as code in some programming language)"

We don't currently have a way to say "please hide the hunk header code fragment entirely".

However, you could set its foreground color to be equal to your background :)

E.g. --hunk-header-style 'line-number #000000' if you're on a black background.

I have a white background currently:

 git show | delta --no-gitconfig --hunk-header-style 'line-number #FFFFFF'

image

Of course, that leaves a large box... you could play with hunk-header-decoration-style:

--hunk-header-style 'line-number #FFFFFF' --hunk-header-decoration-style ul

image

Does anything along those lines achieve what you're looking for, at least as a workaround?

@washtubs
Copy link
Author

washtubs commented Apr 15, 2022

It is a workaround for sure! I'm not too keen on the invisible text method as it's still gonna be there and still be selectable, not to mention I'm not confident I would be able to programmatically pick the right background color depending on the environment.

I did experiment with another setting, because I don't necessarily even need the line number, I tried --hunk-header-style=omit. This would have done it for me, however the problem with this one is because the boundary between hunks is just a blank line, there is no way to distinguish a boundary between two hunks vs a blank line within a hunk.

For example this is with a hunk header.

With hunk header

This is without a hunk header. Note that after - checkout there's no way for me to tell if that is the end of a hunk or just a continuation.

Without hunk header

@deanhouseholder
Copy link

In case it helps, this is exactly the problem I'm having and hoping for a solution to. @washtubs nailed it.

@CodexHere
Copy link

CodexHere commented Jun 24, 2023

Adding another "+1" to the list here, I struggled fighting the settings to try and get things working but to no avail.

Another thing I noticed with hunk-header settings is only hunk-header-style is outputting when asking to show the config (filed here: #1458)

image

@zmc
Copy link
Contributor

zmc commented Nov 20, 2023

I ran into this today and decided to work on a patch to make it configurable. I have not filed a PR yet but you can view/try the branch at my fork (diff view).

My one hesitation is that while it technically won't change delta's default behavior, existing "themes" will drop the code fragment unless they are updated. This could be worked around by e.g. using no-code-fragment and inverting its logic, but I would like to hear what @dandavison thinks first if he's got a minute.

@dandavison
Copy link
Owner

dandavison commented Nov 20, 2023

#Hi @zmc, I think your design is how it should have been initially. However, I'm not sure it's worth the breaking change today. We do already use the word "omit" with special meaning:

The style 'omit' can be used to remove the hunk header section from the output.

The attribute 'omit' is supported by commit-style, file-style, and hunk-header-style, meaning to remove the element entirely from the output.

So perhaps we should just call this omit-code-fragment? It's not beautiful, I agree.

Internally, I'd be happy for your implementation to use the non-inverted names that you are currently, i.e. HunkHeaderIncludeCodeFragment

zmc added a commit to zmc/delta that referenced this issue Nov 21, 2023
zmc added a commit to zmc/delta that referenced this issue Nov 21, 2023
@zmc
Copy link
Contributor

zmc commented Nov 21, 2023

#Hi @zmc, I think your design is how it should have been initially. However, I'm not sure it's worth the breaking change today

Agreed - I don't like the idea of breaking anyone's existing configuration.

So perhaps we should just call this omit-code-fragment? It's not beautiful, I agree.

Internally, I'd be happy for your implementation to use the non-inverted names that you are currently, i.e. HunkHeaderIncludeCodeFragment

Ended up doing exactly this :)

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.

5 participants