-
Notifications
You must be signed in to change notification settings - Fork 395
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
🚀 make whitespace changes visible as such #522
Comments
Hi @Kr1ss-XD can I just check -- passing |
Yes, that's correct. I would like to be able to see whitespace changes, but also to distinguish them from other differences on a glance. |
I see. It almost feels like there could be a git option for rendering tabs as visible characters doesn't it? But there doesn't seem to be one. Just playing around with possibilities, this seems quite nice: [core]
pager = sed 's/\t/├──┤/g' | delta So is this as simple as allowing the user to supply a string to substitute tabs? Here's a quick branch implementing that, do you want to try it out? #523 E.g.
|
Nice, I guess that's exactly what I was looking for. I'll check out that branch and build it. Thanks a lot ! |
It's working fine @dandavison 👍 |
Great. One question is do we consider the breaking change of getting rid of the |
I'd say there are - at least - two ways to handle this.
That's my understanding, too. Though I'd say it's preferable to prevent breaking changes if possible. |
Speaking of tabs, when replacing them
Also maybe use a more muted color than white, e.g. gray or blue as |
If possible, I think it would be great to make clearer that lines that contains only whitespace change don’t introduce other modifications. In this example, it doesn’t seems like the first line is really an addition, because of the whitespace changes on the next lines. I think the easiest change would be to use the light green background for lines that are entirely new. The same logic can be used for lines that where completely removed. |
@robinmoussu also see PR #13 which among other things discusses that single changed words are emphasized more than an entire added or removed line. |
@robinmoussu, @th1000s putting aside temporarily the question of what the defaults should be, what I would like to be true is that delta's style configuration options can achieve any of these desired highlighting styles. (Seeing as there are so many options, it seems like it must be a bug for things like this to be non-achievable!) I believe that the example above can be achieved by making which gives this diff: So now if we make it looks like this I also haven't forgotten about @nkouevda's PR #13, which dates from before delta gained its |
IMHO, the Also, I would suggest using a vim-style configuration for this, where you can set the characters replacing the space and the beginning, end, and middle of a tab. What vim doesn't do (and I would like) is to configure what you use for a tab expanding to a single column, and maybe also for two columns. Also, should all tabs and spaces be replaced with these characters, only those on lines that have changed, or only those that have actually changed? (And should this be configurable?) I have a very crude change on top of #752, but as you can see, it still needs some work: |
Just for reference: Git also has an option to show invisible or non-printable characters via |
I would really appreciate something like Since I also think having a "show all invisible characters" option, rather than something specific to just tabs, would map a lot better to user expectations, since it's found in so many IDEs/editors/tools - many devs are familiar with it, and already have trained up their minds to visually parse those kinds of visual cues for invisible characters. For example, when I first ran into the problem of |
Hi @mentalisttraceur, this isn't true, but I'm curious where you got that idea from, since I see it said quite a bit! |
@dandavison I think the strongest reason was the quote (emphasis added) " All together, that gave me the impression that there was significant code reuse, and my first thought would be to try to reuse it for any heavy lifting needed to syntax-highlight the text inside the diff markers. |
Right, it's funny, I added those sentences to try to dispel the belief that delta used code from bat for syntax highlighting, but I can see it's confusing especially if people come with a prior belief that it does. Delta uses bat code for things like launching the pager process, and it uses the color themes and language definitions that bat uses. But the low-level details of syntax highlighting are implemented independently in bat and delta, both using the same underlying library (syntect). |
Gotcha, thanks for clarifying! If I think of any better wording or place for more precisely/unambiguously mitigating that misunderstanding I'll let you know! In any case, I would love a |
@mentalisttraceur, I agree, I use I haven't thought too hard about how helpful this is but FWIW here's a conversation with GPT4 about this issue.
The git-delta issue #522 discusses the need for a feature to make whitespace changes visible and distinguishable from other changes in a diff. The main problem raised is that when viewing a diff, indented lines are highlighted as differences, even though the code is not changed, but only indented with spaces or tabs. The proposed solution is to have an option to display whitespace characters using user-defined glyphs and/or applying specific delta styles to whitespace changes. Throughout the conversation, there are various suggestions and implementations shared. The initial idea is to allow the user to supply a string to substitute tabs. However, it evolves to include discussions about how to handle the deprecated delta.tabs in favor of delta.tab-string and whether to break backward compatibility. The conversation also covers topics such as:
Next steps:
Apologies for any confusion in my previous response. The idea of the
Delta could use a combination of colors and symbols to indicate the differences in whitespace characters. For example, it could use different colors for changed spaces and tabs, and a separate color for unchanged whitespace characters. Here is an ASCII representation of how it could look:
In this example:
Please note that this is a text-based representation, and the actual implementation in delta would involve colors and custom symbols to create a more visually appealing and informative display. |
Sounds like I convinced ChatGPT4 😄. I appreciate that you publicly shared that - I hadn't thought to use AI as a thinking aid like that, seems useful! I basically agree with its recommendations - obviously to be precise, we probably don't want a full tab represented by just one single-width character (I'm tempted to say "that's what it meant", in the sense that if a human said this, I'd suppose that's probably what they meant). As for coloring, I imagine the coloring of the whitespace characters to be like syntax highlighting now: if style includes |
As someone who prefers using tabs in code I'd also be happy to see an option for rendering a tab to just a sequence of spaces and rendering spaces as some kind of a middle dot or a fancy underscore or something (should I open a PR for that?) |
Hi, at first glance I couldn't find any open or closed issues on this topic. Please excuse me if I missed one.
Recently, while viewing a particular diff, I noticed that every indented line was highlighted as a difference, even though the code itself was not changed, other than being indented by spaces vs. tabs. (PKGBUILD's are interpreted by bash, so indentation doesn't matter).
Therefore, I think it might be useful to have an option which allows displaying whitespace characters using one or more user-defined glyphs, and/or applying the
delta.{plus,minus}-emph-style
settings to whitespace changes.In the case that the characters to display tabs were be defined as
'‣·'
and tab size as4
, I would imagine something like :The text was updated successfully, but these errors were encountered: