git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Pat Thoyts <patthoyts@users.sourceforge.net>
Date
Oct 19, 2010, 22:59 UTC
Message-ID
<87hbgh7paf.fsf@fox.patthoyts.tk>
In-Reply-To
<AANLkTikttRVeE+PVUJGiLERC=qdoxSH1oyXa5HLXoW0N@mail.gmail.com>

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@gmail.com>
Signed-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>
---
Tor Arvid Lund <torarvid@gmail.com> writes:
Show 6 quoted lines
>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
+		}
 		if {[string index $line end] eq "\r"} {
 			$ui_diff tag add d_cr {end - 2c}
 		}
-- 
1.7.3.1.msysgit.0
Previous: Tor Arvid LundNext: Tor Arvid Lund
Message 2 of 14 in “Colored whitespace in git gui”
  1. Tor Arvid LundOct 18, 2010
  2. git-gui: highlight trailing whitespace in diff viewPat Thoyts, Oct 19, 2010
  3. Tor Arvid LundOct 20, 2010
  4. git-gui: support core.whitespace rules in diff viewPat Thoyts, Oct 20, 2010
  5. Junio C HamanoOct 20, 2010
  6. Tor Arvid LundOct 21, 2010
  7. Pat ThoytsOct 21, 2010
  8. Tor Arvid LundOct 22, 2010
  9. Pat ThoytsOct 22, 2010
  10. git-gui: apply color information from git diffPat Thoyts, Oct 21, 2010
  11. Kevin BallardOct 21, 2010
  12. Pat ThoytsOct 21, 2010
  13. git-gui: apply color information from git diff outputPat Thoyts, Oct 22, 2010
  14. Tor Arvid LundOct 22, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.