-
Notifications
You must be signed in to change notification settings - Fork 393
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
🚀 empty line handling and getting rid of the space leftover from -/+ #179
Comments
Hi @andrei-pavel, thanks for this. This has been bothering me too. I think you're right, that we should get rid of them. By default, I think. We have |
If you drop the space in the first column it is impossible to tell the difference between empty context lines, insertions or deletions as you lose the coloring because the line is empty. I stopped using diff-so-fancy because of this. On a related note git also marks trailing newlines by coloring background of the |
GNU diff also has that space: $ cat a.txt
line 1
line 3
$ cat b.txt
line 1
line 3.1
$ diff --unified a.txt b.txt
--- a.txt 2020-06-11 19:53:19.000000000 -0700
+++ b.txt 2020-06-11 19:53:27.000000000 -0700
@@ -1,3 +1,3 @@
line 1
-line 3
+line 3.1 I think this is the convention of most patch files, so I would recommend to keep the space by default, based on the principle of least surprise. |
@philipwood, @andrei-pavel, @FranklinYu, @mk12 thanks very much for your input on this subject. I'm working on this and trying to reach a clear understanding. Let me try to summarize. If you happen to have time to add any further thoughts on the options and default behavior delta should provide that would be really useful and appreciated! There are two cases:
The next release of delta (current master) will take configuration from
@philipwood what's your opinion about diff-so-fancy's solution to this? (
Injecting an artificial space and styling it appropriately is a possible solution there too, and is what dsf does.
@FranklinYu apologies if I'm misunderstanding your argument. GNU diff -u has leading spaces in the first column (in unchanged lines) because it is using the first column for -/+ markers (in changed lines). However, here I have in mind what delta's behavior should be when it is not emitting -/+ markers. (In which case it can never be a valid patch: to get a patch from delta one would use An alternative to the inject-an-artificial-space-and-style-it solution might be to force a background color across the entire line, even though the user doesn't have background colors configured. I'm not saying that's a great solution, just the only other solution that has occurred to me so far. The downside of injecting a real space is that the user might copy it and commit trailing whitespace and it would be delta's fault. But I'm not yet aware of a suitable way to get a terminal emulator to visually highlight these things other than forcing background color across the full line, or injecting a hard space. |
For my diff-so-fancy-ish setup, I think I'd be happy with entire blank lines using the emph style (because those are the ones that have a background color). Or you could leave it up to the user with a |
Are you reading the file with Git, or parse them yourself? Just making sure that you are aware of multiple possible configuration files. I’m using |
I'm not sure there is anything todo to style any whitespace changes in this case. If the first character (
As I said above I think using background coloring solves this in delta, I'm not in favor of adding extra spaces as
Is there a way to do that without injecting a fake space? Maybe there could be a distinct background color to show an added empty line at the end of a file.
I think you can color just the first character by doing something like To style the first character differently to the rest of the line without adding a fake space you can do |
It's using libgit2 so should be fine and hopefully handle all the complexities of conditional includes and worktree config file. |
@phillipwood thanks very much for your extremely helpful post above. I'll move forwards with trying to style the things we're discussing appropriately without introducing fake characters, using the terminal emulator techniques you point out. |
And, without any leading space: genuine code to start in the first column. Please correct me if this is wrong but my reading of the conversation so far is that we don't have reasons to keep that, and we do have a good reason to get rid of it (copying code from the diff). |
Yes I agree |
Thanks very much everyone for the help here. I believe that everything here is addressed in master. If you are able to build and try out master, that is of course very useful. Copying the PR description from #225:
See git documentation: https://git-scm.com/docs/git-config#Documentation/git-config.txt-corewhitespace |
Hi, I use delta as part of git in the terminal. I find it really useful to be able to copy chunks of deleted or added code and paste them in my IDE. Problem is there is always one space before each row. So I have to copy, paste and then remove that space for each line. Is it possible to get rid of this one-character column altogether in order to streamline the copy&paste? As default behavior or as an option?
The text was updated successfully, but these errors were encountered: