Re: [PATCH] git-gui: highlight trailing whitespace in diff view

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Oct 20, 2010 at 12:59 AM, Pat Thoyts
<patthoyts@xxxxxxxxxxxxxxxxxxxxx> wrote:
> Highlight any trailing whitespace in the diff view using a red background
> as is done in the terminal when color is enabled.
>
> Suggested-by: Tor Arvid Lund <torarvid@xxxxxxxxx>
> Signed-off-by: Pat Thoyts <patthoyts@xxxxxxxxxxxxxxxxxxxxx>

Hey, Pat, and thanks for this. It solves my initial question. But in
the time since I asked that question, I started thinking that it
probably should honor the core.whitespace settings, and also work for,
say, 'space-before-tab'. (You seem to say the same thing in your
commit msg, I see)

I tried hacking it for a bit, but my Tcl knowledge is Absolute Zero,
so it got frustrating pretty fast :)

> ---
>
> Tor Arvid Lund <torarvid@xxxxxxxxx> writes:
>>Hi, all! When doing "git diff", whitespaces before EOL, for instance,
>>are marked with red background in my terminal.
>>
>>Is it possible to see this coloring in git gui too?
>>
>>-Tor Arvid-
>
> This patch should do the job. It probably should get some configuration
> item to control this though.
>
> Âgit-gui.sh  |  Â1 +
> Âlib/diff.tcl | Â Â9 ++++++++-
> Â2 files changed, 9 insertions(+), 1 deletions(-)
>
> diff --git a/git-gui.sh b/git-gui.sh
> index 25229a4..8d652f0 100755
> --- a/git-gui.sh
> +++ b/git-gui.sh
> @@ -3314,6 +3314,7 @@ pack .vpane.lower.diff.header -side top -fill x
> Âpack .vpane.lower.diff.body -side bottom -fill both -expand 1
>
> Â$ui_diff tag conf d_cr -elide true
> +$ui_diff tag conf ws -background red
> Â$ui_diff tag conf d_@ -foreground blue -font font_diffbold
> Â$ui_diff tag conf d_+ -foreground {#00a000}
> Â$ui_diff tag conf d_- -foreground red
> diff --git a/lib/diff.tcl b/lib/diff.tcl
> index c628750..83e3f6d 100644
> --- a/lib/diff.tcl
> +++ b/lib/diff.tcl
> @@ -434,7 +434,14 @@ proc read_diff {fd cont_info} {
> Â Â Â Â Â Â Â Â Â Â Â Â}
> Â Â Â Â Â Â Â Â Â Â Â Â}
> Â Â Â Â Â Â Â Â}
> - Â Â Â Â Â Â Â $ui_diff insert end $line $tags
> + Â Â Â Â Â Â Â if {[regexp -indices {^.*\S(\s+)$} $line -> ndx]} {
> + Â Â Â Â Â Â Â Â Â set ndx [expr {[lindex $ndx 0] - 1}]
> + Â Â Â Â Â Â Â Â Â Â Â set nonws [string range $line 0 $ndx]
> + Â Â Â Â Â Â Â Â Â Â Â $ui_diff insert end $nonws $tags \
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â [string range $line [incr ndx] end] [concat $tags ws]
> + Â Â Â Â Â Â Â } else {
> + Â Â Â Â Â Â Â Â Â Â Â $ui_diff insert end $line $tags
> + Â Â Â Â Â Â Â }
<snip>

So - what I tried to do was expand on this (to include a
'space-before-tab' filter). I can't make a simple "elseif" for regexp
"( +)\t" (or whatever the right regexp may be).

I mean that currently you can only match one ws-filter per line. So a
line with both space-before-tab and blank-at-eol would not be printed
correctly.

What I wanted to do, in pseudo-code, was:

read git config core.whitespace
for each diff-line #diff-line is any line starting with '+' or '-'
  set temp-ui-line to $line $tags
  if option_enabled core.whitespace.space-before-tab
    if regexp_match space-before-tab-pattern -> indices
      temp-ui-line.replace(indices[0], indices[1]) with-red-bg
  if option_enabled core.whitespace.blank-at-eol
    ...
  ..
end for

#and then
$ui_diff insert end $temp-ui-line
------------------

Maybe this is the easiest thing in the world to do in Tcl, but I don't
have more time to fiddle with it today :)

Thanks for the patch anyways.

-Tor Arvid-
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]