{"thread":{"id":"25475","subject":"Colored whitespace in git gui","startedAt":"2010-10-18T23:00:34Z","lastAt":"2010-10-22T15:18:06Z","messageCount":14,"participants":["Tor Arvid Lund","Pat Thoyts","Junio C Hamano","Kevin Ballard"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"153755","messageId":"AANLkTikttRVeE+PVUJGiLERC=qdoxSH1oyXa5HLXoW0N@mail.gmail.com","threadId":"25475","inReplyTo":null,"subject":"Colored whitespace in git gui","fromName":"Tor Arvid Lund","fromEmail":"torarvid@gmail.com","sentAt":"2010-10-18T23:00:34Z","receivedAt":"2010-10-18T23:00:34Z","isPatch":false,"sender":{"key":"torarvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/439758?v=4"},"body":"Hi, all! When doing \"git diff\", whitespaces before EOL, for instance,\nare marked with red background in my terminal.\n\nIs it possible to see this coloring in git gui too?\n\n-Tor Arvid-\n"},{"id":"153836","messageId":"87hbgh7paf.fsf@fox.patthoyts.tk","threadId":"25475","inReplyTo":"AANLkTikttRVeE+PVUJGiLERC=qdoxSH1oyXa5HLXoW0N@mail.gmail.com","subject":"[PATCH] git-gui: highlight trailing whitespace in diff view","fromName":"Pat Thoyts","fromEmail":"patthoyts@users.sourceforge.net","sentAt":"2010-10-19T22:59:23Z","receivedAt":"2010-10-19T22:59:23Z","isPatch":true,"sender":{"key":"patthoyts@users.sourceforge.net","avatar":"https://avatars.githubusercontent.com/u/30739?v=4"},"body":"Highlight any trailing whitespace in the diff view using a red background\nas is done in the terminal when color is enabled.\n\nSuggested-by: Tor Arvid Lund <torarvid@gmail.com>\nSigned-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>\n---\n\nTor Arvid Lund <torarvid@gmail.com> writes:\n>Hi, all! When doing \"git diff\", whitespaces before EOL, for instance,\n>are marked with red background in my terminal.\n>\n>Is it possible to see this coloring in git gui too?\n>\n>-Tor Arvid-\n\nThis patch should do the job. It probably should get some configuration\nitem to control this though.\n\n git-gui.sh   |    1 +\n lib/diff.tcl |    9 ++++++++-\n 2 files changed, 9 insertions(+), 1 deletions(-)\n\ndiff --git a/git-gui.sh b/git-gui.sh\nindex 25229a4..8d652f0 100755\n--- a/git-gui.sh\n+++ b/git-gui.sh\n@@ -3314,6 +3314,7 @@ pack .vpane.lower.diff.header -side top -fill x\n pack .vpane.lower.diff.body -side bottom -fill both -expand 1\n \n $ui_diff tag conf d_cr -elide true\n+$ui_diff tag conf ws -background red\n $ui_diff tag conf d_@ -foreground blue -font font_diffbold\n $ui_diff tag conf d_+ -foreground {#00a000}\n $ui_diff tag conf d_- -foreground red\ndiff --git a/lib/diff.tcl b/lib/diff.tcl\nindex c628750..83e3f6d 100644\n--- a/lib/diff.tcl\n+++ b/lib/diff.tcl\n@@ -434,7 +434,14 @@ proc read_diff {fd cont_info} {\n \t\t\t}\n \t\t\t}\n \t\t}\n-\t\t$ui_diff insert end $line $tags\n+\t\tif {[regexp -indices {^.*\\S(\\s+)$} $line -> ndx]} {\n+\t\t    set ndx [expr {[lindex $ndx 0] - 1}]\n+\t\t\tset nonws [string range $line 0 $ndx]\n+\t\t\t$ui_diff insert end $nonws $tags \\\n+\t\t\t\t[string range $line [incr ndx] end] [concat $tags ws]\n+\t\t} else {\n+\t\t\t$ui_diff insert end $line $tags\n+\t\t}\n \t\tif {[string index $line end] eq \"\\r\"} {\n \t\t\t$ui_diff tag add d_cr {end - 2c}\n \t\t}\n-- \n1.7.3.1.msysgit.0\n"},{"id":"153871","messageId":"AANLkTimrrxbKSYib7g0O5TXXwt5yDTdkt_bycs69mKT7@mail.gmail.com","threadId":"25475","inReplyTo":"87hbgh7paf.fsf@fox.patthoyts.tk","subject":"Re: [PATCH] git-gui: highlight trailing whitespace in diff view","fromName":"Tor Arvid Lund","fromEmail":"torarvid@gmail.com","sentAt":"2010-10-20T15:30:26Z","receivedAt":"2010-10-20T15:30:26Z","isPatch":true,"sender":{"key":"torarvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/439758?v=4"},"body":"On Wed, Oct 20, 2010 at 12:59 AM, Pat Thoyts\n<patthoyts@users.sourceforge.net> wrote:\n> Highlight any trailing whitespace in the diff view using a red background\n> as is done in the terminal when color is enabled.\n>\n> Suggested-by: Tor Arvid Lund <torarvid@gmail.com>\n> Signed-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>\n\nHey, Pat, and thanks for this. It solves my initial question. But in\nthe time since I asked that question, I started thinking that it\nprobably should honor the core.whitespace settings, and also work for,\nsay, 'space-before-tab'. (You seem to say the same thing in your\ncommit msg, I see)\n\nI tried hacking it for a bit, but my Tcl knowledge is Absolute Zero,\nso it got frustrating pretty fast :)\n\n> ---\n>\n> Tor Arvid Lund <torarvid@gmail.com> writes:\n>>Hi, all! When doing \"git diff\", whitespaces before EOL, for instance,\n>>are marked with red background in my terminal.\n>>\n>>Is it possible to see this coloring in git gui too?\n>>\n>>-Tor Arvid-\n>\n> This patch should do the job. It probably should get some configuration\n> item to control this though.\n>\n>  git-gui.sh   |    1 +\n>  lib/diff.tcl |    9 ++++++++-\n>  2 files changed, 9 insertions(+), 1 deletions(-)\n>\n> diff --git a/git-gui.sh b/git-gui.sh\n> index 25229a4..8d652f0 100755\n> --- a/git-gui.sh\n> +++ b/git-gui.sh\n> @@ -3314,6 +3314,7 @@ pack .vpane.lower.diff.header -side top -fill x\n>  pack .vpane.lower.diff.body -side bottom -fill both -expand 1\n>\n>  $ui_diff tag conf d_cr -elide true\n> +$ui_diff tag conf ws -background red\n>  $ui_diff tag conf d_@ -foreground blue -font font_diffbold\n>  $ui_diff tag conf d_+ -foreground {#00a000}\n>  $ui_diff tag conf d_- -foreground red\n> diff --git a/lib/diff.tcl b/lib/diff.tcl\n> index c628750..83e3f6d 100644\n> --- a/lib/diff.tcl\n> +++ b/lib/diff.tcl\n> @@ -434,7 +434,14 @@ proc read_diff {fd cont_info} {\n>                        }\n>                        }\n>                }\n> -               $ui_diff insert end $line $tags\n> +               if {[regexp -indices {^.*\\S(\\s+)$} $line -> ndx]} {\n> +                   set ndx [expr {[lindex $ndx 0] - 1}]\n> +                       set nonws [string range $line 0 $ndx]\n> +                       $ui_diff insert end $nonws $tags \\\n> +                               [string range $line [incr ndx] end] [concat $tags ws]\n> +               } else {\n> +                       $ui_diff insert end $line $tags\n> +               }\n<snip>\n\nSo - what I tried to do was expand on this (to include a\n'space-before-tab' filter). I can't make a simple \"elseif\" for regexp\n\"( +)\\t\" (or whatever the right regexp may be).\n\nI mean that currently you can only match one ws-filter per line. So a\nline with both space-before-tab and blank-at-eol would not be printed\ncorrectly.\n\nWhat I wanted to do, in pseudo-code, was:\n\nread git config core.whitespace\nfor each diff-line #diff-line is any line starting with '+' or '-'\n  set temp-ui-line to $line $tags\n  if option_enabled core.whitespace.space-before-tab\n    if regexp_match space-before-tab-pattern -> indices\n      temp-ui-line.replace(indices[0], indices[1]) with-red-bg\n  if option_enabled core.whitespace.blank-at-eol\n    ...\n  ..\nend for\n\n#and then\n$ui_diff insert end $temp-ui-line\n------------------\n\nMaybe this is the easiest thing in the world to do in Tcl, but I don't\nhave more time to fiddle with it today :)\n\nThanks for the patch anyways.\n\n-Tor Arvid-\n"},{"id":"153901","messageId":"87pqv4fqqz.fsf_-_@fox.patthoyts.tk","threadId":"25475","inReplyTo":"AANLkTimrrxbKSYib7g0O5TXXwt5yDTdkt_bycs69mKT7@mail.gmail.com","subject":"[PATCH] git-gui: support core.whitespace rules in diff view","fromName":"Pat Thoyts","fromEmail":"patthoyts@users.sourceforge.net","sentAt":"2010-10-20T22:05:43Z","receivedAt":"2010-10-20T22:05:43Z","isPatch":true,"sender":{"key":"patthoyts@users.sourceforge.net","avatar":"https://avatars.githubusercontent.com/u/30739?v=4"},"body":"This is a rather more complete implementation of whitespace highlighting\naccording to the core.whitespace setting. The diff view whitespace\nhighlights should match what you see with 'git diff' when color is\nenabled for all the whitespace rules except cr-at-eol where there is\ncurrently a rule to hide these.\n\nSuggested-by: Tor Arvid Lund <torarvid@gmail.com>\nSigned-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>\n---\n\n git-gui.sh   |   27 +++++++++++++++++++++++++++\n lib/diff.tcl |   58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--\n 2 files changed, 83 insertions(+), 2 deletions(-)\n\ndiff --git a/git-gui.sh b/git-gui.sh\nindex 5e8378f..134afba 100755\n--- a/git-gui.sh\n+++ b/git-gui.sh\n@@ -806,6 +806,7 @@ proc apply_config {} {\n }\n \n set default_config(branch.autosetupmerge) true\n+set default_config(core.whitespace) \"\"\n set default_config(merge.tool) {}\n set default_config(mergetool.keepbackup) true\n set default_config(merge.diffstat) true\n@@ -836,6 +837,13 @@ set font_descs {\n \t{fontdiff font_diff {mc \"Diff/Console Font\"}}\n }\n \n+set whitespace_config(blank-at-eol) 1\n+set whitespace_config(space-before-tab) 1\n+set whitespace_config(indent-with-non-tab) 0\n+set whitespace_config(tab-in-indent) 0\n+set whitespace_config(blank-at-eof) 1\n+set whitespace_config(cr-at-eol) 0\n+\n ######################################################################\n ##\n ## find git\n@@ -1060,6 +1068,7 @@ git-version proc _parse_config {arr_name args} {\n \n proc load_config {include_global} {\n \tglobal repo_config global_config system_config default_config\n+\tglobal whitespace_config\n \n \tif {$include_global} {\n \t\t_parse_config system_config --system\n@@ -1080,6 +1089,23 @@ proc load_config {include_global} {\n \t\t\tset repo_config($name) $system_config($name)\n \t\t}\n \t}\n+\tset whitespace \"\"\n+\tforeach cf {default_config system_config global_config repo_config} {\n+\t\tupvar #0 $cf config\n+\t\tif {[info exists config(core.whitespace)]} {\n+\t\t\tset whitespace $config(core.whitespace)\n+\t\t}\n+\t}\n+\tforeach var [split $whitespace ,] {\n+\t\tset state [expr {![string match -* $var]}]\n+\t\tset var [string trimleft $var -]\n+\t\tif {[string match \"trailing-space\" $var]} {\n+\t\t\tset whitespace_config(blank-at-eol) $state\n+\t\t\tset whitespace_config(blank-at-eof) $state\n+\t\t} else {\n+\t\t\tset whitespace_config($var) $state\n+\t\t}\n+\t}\n }\n \n ######################################################################\n@@ -3323,6 +3349,7 @@ pack .vpane.lower.diff.header -side top -fill x\n pack .vpane.lower.diff.body -side bottom -fill both -expand 1\n \n $ui_diff tag conf d_cr -elide true\n+$ui_diff tag conf ws -background red\n $ui_diff tag conf d_@ -foreground blue -font font_diffbold\n $ui_diff tag conf d_+ -foreground {#00a000}\n $ui_diff tag conf d_- -foreground red\ndiff --git a/lib/diff.tcl b/lib/diff.tcl\nindex c628750..e174faf 100644\n--- a/lib/diff.tcl\n+++ b/lib/diff.tcl\n@@ -332,11 +332,17 @@ proc start_show_diff {cont_info {add_opts {}}} {\n \tfileevent $fd readable [list read_diff $fd $cont_info]\n }\n \n+proc add_tag {w tag pos ndx} {\n+\tset begin \"$pos + [lindex $ndx 0] chars\"\n+\tset end \"$pos + [expr {[lindex $ndx 1] + 1}] chars\"\n+\t$w tag add $tag $begin $end\n+}\n+\n proc read_diff {fd cont_info} {\n \tglobal ui_diff diff_active is_submodule_diff\n \tglobal is_3way_diff is_conflict_diff current_diff_header\n \tglobal current_diff_queue\n-\tglobal diff_empty_count\n+\tglobal diff_empty_count whitespace_config\n \n \t$ui_diff conf -state normal\n \twhile {[gets $fd line] >= 0} {\n@@ -434,7 +440,38 @@ proc read_diff {fd cont_info} {\n \t\t\t}\n \t\t\t}\n \t\t}\n-\t\t$ui_diff insert end $line $tags\n+\t\tset insertion [list $line $tags]\n+\t\tif {$whitespace_config(blank-at-eol)} {\n+\t\t\tif {[regexp -indices {^[+-](?:.*\\S)?(\\s+)$} $line -> ndx]} {\n+\t\t\t\tset ndx [expr {[lindex $ndx 0] - 1}]\n+\t\t\t\tset insertion [list [string range $line 0 $ndx] $tags\\\n+\t\t\t\t\t\t\t\t   [string range $line [incr ndx] end]\\\n+\t\t\t\t\t\t\t\t   [concat $tags ws]]\n+\t\t\t}\n+\t\t}\n+\t\tset pos [$ui_diff index \"end - 1 line linestart\"]\n+\t\teval [linsert $insertion 0 $ui_diff insert end]\n+\t\tif {[regexp {^[+-](\\s*)\\S} [lindex $insertion 0] -> initial]} {\n+\t\t\tif {$whitespace_config(indent-with-non-tab)} {\n+\t\t\t\tif {[regexp -indices {^x( {8,})} x$initial -> ndx]} {\n+\t\t\t\t\tadd_tag $ui_diff ws $pos $ndx\n+\t\t\t\t}\n+\t\t\t}\n+\t\t\tif {$whitespace_config(space-before-tab)} {\n+\t\t\t\tset start 0\n+\t\t\t\twhile {[regexp -indices -start $start {( +)\\t} x$initial -> ndx]} {\n+\t\t\t\t\tadd_tag $ui_diff ws $pos $ndx\n+\t\t\t\t\tset start [expr {[lindex $ndx 1] + 1}]\n+\t\t\t\t}\n+\t\t\t}\n+\t\t\tif {$whitespace_config(tab-in-indent)} {\n+\t\t\t\tset start 0\n+\t\t\t\twhile {[regexp -indices -start $start {\\t} x$initial ndx]} {\n+\t\t\t\t\tadd_tag $ui_diff ws $pos $ndx\n+\t\t\t\t\tset start [expr {[lindex $ndx 1] + 1}]\n+\t\t\t\t}\n+\t\t\t}\n+\t\t}\n \t\tif {[string index $line end] eq \"\\r\"} {\n \t\t\t$ui_diff tag add d_cr {end - 2c}\n \t\t}\n@@ -450,6 +487,16 @@ proc read_diff {fd cont_info} {\n \t\t\treturn\n \t\t}\n \n+\t\tif {$whitespace_config(blank-at-eof)} {\n+\t\t\tset n 2\n+\t\t\t$ui_diff configure -state normal\n+\t\t\twhile {[regexp {^[+-]$} [$ui_diff get \"end - $n line linestart\" \"end - $n line lineend\"]]} {\n+\t\t\t\t$ui_diff tag add ws \"end - $n line linestart\" \"end - $n line lineend\"\n+\t\t\t\tincr n\n+\t\t\t}\n+\t\t\t$ui_diff configure -state disabled\n+\t\t}\n+\n \t\tset diff_active 0\n \t\tunlock_index\n \t\tset scroll_pos [lindex $cont_info 0]\n@@ -731,3 +778,10 @@ proc apply_range_or_line {x y} {\n \n \tunlock_index\n }\n+\n+# Local variables:\n+# mode: tcl\n+# indent-tabs-mode: t\n+# tcl-indent-level: 4\n+# tab-width: 4\n+# End:\n-- \n1.7.3.1.msysgit.0\n"},{"id":"153909","messageId":"7vy69stop2.fsf@alter.siamese.dyndns.org","threadId":"25475","inReplyTo":"87pqv4fqqz.fsf_-_@fox.patthoyts.tk","subject":"Re: [PATCH] git-gui: support core.whitespace rules in diff view","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-10-20T23:43:53Z","receivedAt":"2010-10-20T23:43:53Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Pat Thoyts <patthoyts@users.sourceforge.net> writes:\n\n> This is a rather more complete implementation of whitespace highlighting\n> according to the core.whitespace setting. The diff view whitespace\n> highlights should match what you see with 'git diff' when color is\n> enabled for all the whitespace rules except cr-at-eol where there is\n> currently a rule to hide these.\n>\n> Suggested-by: Tor Arvid Lund <torarvid@gmail.com>\n> Signed-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>\n> ---\n\nThis might be a very stupid question, but isn't it an easier-to-maintain\noption to let underlying \"git diff\" color its output and convert the ANSI\ncoloring to whatever Tcl wants to use, especially in the long run, instead\nof trying to replicate the logic to check whitespace breakages here?\n"},{"id":"153953","messageId":"AANLkTikG0_9+Gjnhehf8436Kw089Zd-XaSdSOP-J6_yD@mail.gmail.com","threadId":"25475","inReplyTo":"7vy69stop2.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] git-gui: support core.whitespace rules in diff view","fromName":"Tor Arvid Lund","fromEmail":"torarvid@gmail.com","sentAt":"2010-10-21T12:36:36Z","receivedAt":"2010-10-21T12:36:36Z","isPatch":true,"sender":{"key":"torarvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/439758?v=4"},"body":"On Thu, Oct 21, 2010 at 1:43 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> Pat Thoyts <patthoyts@users.sourceforge.net> writes:\n>\n>> This is a rather more complete implementation of whitespace highlighting\n>> according to the core.whitespace setting. The diff view whitespace\n>> highlights should match what you see with 'git diff' when color is\n>> enabled for all the whitespace rules except cr-at-eol where there is\n>> currently a rule to hide these.\n>>\n>> Suggested-by: Tor Arvid Lund <torarvid@gmail.com>\n>> Signed-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>\n>> ---\n>\n> This might be a very stupid question, but isn't it an easier-to-maintain\n> option to let underlying \"git diff\" color its output and convert the ANSI\n> coloring to whatever Tcl wants to use, especially in the long run, instead\n> of trying to replicate the logic to check whitespace breakages here?\n\nHi Pat, and thanks again for doing the Tcl hacking :)\n\nI did a quick test (with core.whitespace unset, so the defaults should\nbe used). I wonder if there is a little bug somewhere else in git-gui.\nIf I have committed a line like this:\n\n............Hello world\n\nand change it to:\n\n........*Hello world\n\nI used '.' to indicate Space, and '*' to indicate Tab, so I changed 4\nspaces to one tab character. As I understand space-before-tab, this\nshould render 8 red spaces, 1 white Tab, and then \"Hello world\". But\ninstead I get 9 white spaces... So the tab gets converted to a space\n(I verified that it was not my editor that converted it - it really is\n8 SP and 1 TAB).\n\nIf I change it to\n***Hello world\nso that there are no leading spaces, then the Tabs do not get converted.\n\nCan you reproduce this? I have applied your patch on top of Junio's\nmaster and build on msysgit on Vista 64 (if that matters).\n\n\nBtw, I almost feel bad saying this after you implemented my\nsuggestion, but Junio's suggestion to parse the ANSI escapes seems\nquite clever, doesn't it?\n\nHave a good day.\n\n-Tor Arvid-\n"},{"id":"153994","messageId":"87eibje5zs.fsf_-_@fox.patthoyts.tk","threadId":"25475","inReplyTo":"7vy69stop2.fsf@alter.siamese.dyndns.org","subject":"[PATCH] git-gui: apply color information from git diff","fromName":"Pat Thoyts","fromEmail":"patthoyts@users.sourceforge.net","sentAt":"2010-10-21T15:22:40Z","receivedAt":"2010-10-21T15:22:40Z","isPatch":true,"sender":{"key":"patthoyts@users.sourceforge.net","avatar":"https://avatars.githubusercontent.com/u/30739?v=4"},"body":"This patch extracts the ansi color sequences from git diff output and\napplies these to the diff view window. This ensures that the gui view\nmakes use of the current git configuration for whitespace display.\n\nSuggested-by: Tor Arvid Lund <torarvid@gmail.com>\nSuggested-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>\n---\n\nJunio C Hamano <gitster@pobox.com> writes:\n>Pat Thoyts <patthoyts@users.sourceforge.net> writes:\n>\n>> This is a rather more complete implementation of whitespace highlighting\n>> according to the core.whitespace setting. The diff view whitespace\n>> highlights should match what you see with 'git diff' when color is\n>> enabled for all the whitespace rules except cr-at-eol where there is\n>> currently a rule to hide these.\n>>\n>> Suggested-by: Tor Arvid Lund <torarvid@gmail.com>\n>> Signed-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>\n>> ---\n>\n>This might be a very stupid question, but isn't it an easier-to-maintain\n>option to let underlying \"git diff\" color its output and convert the ANSI\n>coloring to whatever Tcl wants to use, especially in the long run, instead\n>of trying to replicate the logic to check whitespace breakages here?\n\nSeems like a fine plan. Here is an implementation to try out.\n\n git-gui.sh   |    7 ++++++-\n lib/diff.tcl |   27 ++++++++++++++++++++++++++-\n 2 files changed, 32 insertions(+), 2 deletions(-)\n\ndiff --git a/git-gui.sh b/git-gui.sh\nindex 5e8378f..8fba57c 100755\n--- a/git-gui.sh\n+++ b/git-gui.sh\n@@ -3322,8 +3322,13 @@ pack $ui_diff -side left -fill both -expand 1\n pack .vpane.lower.diff.header -side top -fill x\n pack .vpane.lower.diff.body -side bottom -fill both -expand 1\n \n+foreach {n c} {0 black 1 red4 2 green4 3 yellow4 4 blue4 5 magenta4 6 cyan4 7 grey60} {\n+\t$ui_diff tag configure clr4$n -background $c\n+\t$ui_diff tag configure clr3$n -foreground $c\n+}\n+\n $ui_diff tag conf d_cr -elide true\n-$ui_diff tag conf d_@ -foreground blue -font font_diffbold\n+$ui_diff tag conf d_@ -font font_diffbold\n $ui_diff tag conf d_+ -foreground {#00a000}\n $ui_diff tag conf d_- -foreground red\n \ndiff --git a/lib/diff.tcl b/lib/diff.tcl\nindex c628750..7625cb8 100644\n--- a/lib/diff.tcl\n+++ b/lib/diff.tcl\n@@ -294,7 +294,7 @@ proc start_show_diff {cont_info {add_opts {}}} {\n \t}\n \n \tlappend cmd -p\n-\tlappend cmd --no-color\n+\tlappend cmd --color\n \tif {$repo_config(gui.diffcontext) >= 1} {\n \t\tlappend cmd \"-U$repo_config(gui.diffcontext)\"\n \t}\n@@ -332,6 +332,21 @@ proc start_show_diff {cont_info {add_opts {}}} {\n \tfileevent $fd readable [list read_diff $fd $cont_info]\n }\n \n+proc parse_color_line {line} {\n+\tset start 0\n+\tset result \"\"\n+\tset markup [list]\n+\twhile {[regexp -indices -start $start \"\\033\\\\\\[(\\\\d+)?m\" $line match code]} {\n+\t\tforeach {begin end} $match break\n+\t\tappend result [string range $line $start [expr {$begin - 1}]]\n+\t\tlappend markup [string length $result] [eval [linsert $code 0 string range $line]]\n+\t\tset start [incr end]\n+\t}\n+\tappend result [string range $line $start end]\n+\tif {[llength $markup] < 4} {set markup {}}\n+\treturn [list $result $markup]\n+}\n+\n proc read_diff {fd cont_info} {\n \tglobal ui_diff diff_active is_submodule_diff\n \tglobal is_3way_diff is_conflict_diff current_diff_header\n@@ -340,6 +355,9 @@ proc read_diff {fd cont_info} {\n \n \t$ui_diff conf -state normal\n \twhile {[gets $fd line] >= 0} {\n+\t\tforeach {line markup} [parse_color_line $line] break\n+\t\tset line [string map {\\033 ^} $line]\n+\n \t\t# -- Cleanup uninteresting diff header lines.\n \t\t#\n \t\tif {$::current_diff_inheader} {\n@@ -434,11 +452,18 @@ proc read_diff {fd cont_info} {\n \t\t\t}\n \t\t\t}\n \t\t}\n+\t\tset mark [$ui_diff index \"end - 1 line linestart\"]\n \t\t$ui_diff insert end $line $tags\n \t\tif {[string index $line end] eq \"\\r\"} {\n \t\t\t$ui_diff tag add d_cr {end - 2c}\n \t\t}\n \t\t$ui_diff insert end \"\\n\" $tags\n+\n+\t\tforeach {posbegin colbegin posend colend} $markup {\n+\t\t\tset a \"$mark linestart + $posbegin chars\"\n+\t\t\tset b \"$mark linestart + $posend chars\"\n+\t\t\tcatch {$ui_diff tag add clr$colbegin $a $b}\n+\t\t}\n \t}\n \t$ui_diff conf -state disabled\n \n-- \n1.7.3.1.msysgit.0\n"},{"id":"153996","messageId":"8762wve5k2.fsf@fox.patthoyts.tk","threadId":"25475","inReplyTo":"AANLkTikG0_9+Gjnhehf8436Kw089Zd-XaSdSOP-J6_yD@mail.gmail.com","subject":"Re: [PATCH] git-gui: support core.whitespace rules in diff view","fromName":"Pat Thoyts","fromEmail":"patthoyts@users.sourceforge.net","sentAt":"2010-10-21T18:58:37Z","receivedAt":"2010-10-21T18:58:37Z","isPatch":true,"sender":{"key":"patthoyts@users.sourceforge.net","avatar":"https://avatars.githubusercontent.com/u/30739?v=4"},"body":"Tor Arvid Lund <torarvid@gmail.com> writes:\n\n>On Thu, Oct 21, 2010 at 1:43 AM, Junio C Hamano <gitster@pobox.com> wrote:\n>> Pat Thoyts <patthoyts@users.sourceforge.net> writes:\n>>\n>>> This is a rather more complete implementation of whitespace highlighting\n>>> according to the core.whitespace setting. The diff view whitespace\n>>> highlights should match what you see with 'git diff' when color is\n>>> enabled for all the whitespace rules except cr-at-eol where there is\n>>> currently a rule to hide these.\n>>>\n>>> Suggested-by: Tor Arvid Lund <torarvid@gmail.com>\n>>> Signed-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>\n>>> ---\n>>\n>> This might be a very stupid question, but isn't it an easier-to-maintain\n>> option to let underlying \"git diff\" color its output and convert the ANSI\n>> coloring to whatever Tcl wants to use, especially in the long run, instead\n>> of trying to replicate the logic to check whitespace breakages here?\n>\n>Hi Pat, and thanks again for doing the Tcl hacking :)\n>\n>I did a quick test (with core.whitespace unset, so the defaults should\n>be used). I wonder if there is a little bug somewhere else in git-gui.\n>If I have committed a line like this:\n>\n>............Hello world\n>\n>and change it to:\n>\n>........*Hello world\n>\n>I used '.' to indicate Space, and '*' to indicate Tab, so I changed 4\n>spaces to one tab character. As I understand space-before-tab, this\n>should render 8 red spaces, 1 white Tab, and then \"Hello world\". But\n>instead I get 9 white spaces... So the tab gets converted to a space\n>(I verified that it was not my editor that converted it - it really is\n>8 SP and 1 TAB).\n\nThis is caused by the tabstyle being defaulted to 'tabular'. This means\nthe first tab on a line extends to the first tab position and if that\nlies to the left then the width of a single space is added. Looks like\nthis widget should be using -tabstyle wordprocessor which would do what\nyou expect and move to the next tab position.\n\nIt is still a tab - just the display width looks wrong.\n\n>\n>If I change it to\n>***Hello world\n>so that there are no leading spaces, then the Tabs do not get converted.\n>Can you reproduce this? I have applied your patch on top of Junio's\n>master and build on msysgit on Vista 64 (if that matters).\n>\n>\n>Btw, I almost feel bad saying this after you implemented my\n>suggestion, but Junio's suggestion to parse the ANSI escapes seems\n>quite clever, doesn't it?\n\nIndeed - see my other post for an implementation.\n\n-- \nPat Thoyts                            http://www.patthoyts.tk/\nPGP fingerprint 2C 6E 98 07 2C 59 C8 97  10 CE 11 E6 04 E0 B9 DD\n"},{"id":"154027","messageId":"FB63A238-C5FD-4A00-9EAD-E99512C9D38B@sb.org","threadId":"25475","inReplyTo":"87eibje5zs.fsf_-_@fox.patthoyts.tk","subject":"Re: [PATCH] git-gui: apply color information from git diff","fromName":"Kevin Ballard","fromEmail":"kevin@sb.org","sentAt":"2010-10-21T20:59:44Z","receivedAt":"2010-10-21T20:59:44Z","isPatch":true,"sender":{"key":"kevin@sb.org","avatar":"https://avatars.githubusercontent.com/u/714?v=4"},"body":"On Oct 21, 2010, at 8:22 AM, Pat Thoyts wrote:\n\n> +\twhile {[regexp -indices -start $start \"\\033\\\\\\[(\\\\d+)?m\" $line match code]} {\n\nGit currently doesn't emit combined escapes (e.g. \\e[0;31m to reset and then turn on red text), but I can imagine it being enhanced to do this in the future. I would recommend handling it here if you can.\n\n-Kevin Ballard"},{"id":"154048","messageId":"8739rzf6yr.fsf@fox.patthoyts.tk","threadId":"25475","inReplyTo":"FB63A238-C5FD-4A00-9EAD-E99512C9D38B@sb.org","subject":"Re: [PATCH] git-gui: apply color information from git diff","fromName":"Pat Thoyts","fromEmail":"patthoyts@users.sourceforge.net","sentAt":"2010-10-21T23:42:52Z","receivedAt":"2010-10-21T23:42:52Z","isPatch":true,"sender":{"key":"patthoyts@users.sourceforge.net","avatar":"https://avatars.githubusercontent.com/u/30739?v=4"},"body":"Kevin Ballard <kevin@sb.org> writes:\n\n>On Oct 21, 2010, at 8:22 AM, Pat Thoyts wrote:\n>\n>> +\twhile {[regexp -indices -start $start \"\\033\\\\\\[(\\\\d+)?m\" $line match code]} {\n>\n>Git currently doesn't emit combined escapes (e.g. \\e[0;31m to reset and then turn on red text), but I can imagine it being enhanced to do this in the future. I would recommend handling it here if you can.\n\nIn fact that can be configured even now:\n % git config color.diff.whitespace \"bold white bold cyan\"\n % git diff --color | cat.exe --show-all\n ^[[1;37;46m+^[[m$\nso thanks for the warning.\n-- \nPat Thoyts                            http://www.patthoyts.tk/\nPGP fingerprint 2C 6E 98 07 2C 59 C8 97  10 CE 11 E6 04 E0 B9 DD\n"},{"id":"154132","messageId":"87pqv2ttjx.fsf_-_@fox.patthoyts.tk","threadId":"25475","inReplyTo":"FB63A238-C5FD-4A00-9EAD-E99512C9D38B@sb.org","subject":"[PATCH] git-gui: apply color information from git diff output","fromName":"Pat Thoyts","fromEmail":"patthoyts@users.sourceforge.net","sentAt":"2010-10-22T10:10:48Z","receivedAt":"2010-10-22T10:10:48Z","isPatch":true,"sender":{"key":"patthoyts@users.sourceforge.net","avatar":"https://avatars.githubusercontent.com/u/30739?v=4"},"body":"This patch extracts the ANSI color sequences from git diff output and\napplies these to the diff view window. This ensures that the gui view\nmakes use of the current git configuration for whitespace display.\n\nANSI codes may include attributes, foreground and background in a single\nsequence. Handle this and support bold and reverse attributes. Ignore\nall other attributes.\n\nSuggested-by: Tor Arvid Lund <torarvid@gmail.com>\nSuggested-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>\n---\n\nKevin Ballard <kevin@sb.org> writes:\n\n>On Oct 21, 2010, at 8:22 AM, Pat Thoyts wrote:\n>\n>> +\twhile {[regexp -indices -start $start \"\\033\\\\\\[(\\\\d+)?m\" $line match code]} {\n>\n>Git currently doesn't emit combined escapes (e.g. \\e[0;31m to reset and then turn on red text), but I can imagine it being enhanced to do this in the future. I would recommend handling it here if you can.\n>\n>-Kevin Ballard\n\nIt turns out that such sequences will be generated by git if the user\nconfigures the color.diff.whitespace (eg: bold cyan magenta). This patch\nhandles these cases. I don't see any point trying to handle blink. I\ncould add underline but I don't see that being so appropriate for a\nGUI. It seems more like something that is configured for a monochrome\nterminal.\n\n git-gui.sh   |   10 +++++++++-\n lib/diff.tcl |   34 +++++++++++++++++++++++++++++++++-\n 2 files changed, 42 insertions(+), 2 deletions(-)\n\ndiff --git a/git-gui.sh b/git-gui.sh\nindex 1ccaba1..1fb0254 100755\n--- a/git-gui.sh\n+++ b/git-gui.sh\n@@ -3322,8 +3322,16 @@ pack $ui_diff -side left -fill both -expand 1\n pack .vpane.lower.diff.header -side top -fill x\n pack .vpane.lower.diff.body -side bottom -fill both -expand 1\n \n+foreach {n c} {0 black 1 red4 2 green4 3 yellow4 4 blue4 5 magenta4 6 cyan4 7 grey60} {\n+\t$ui_diff tag configure clr4$n -background $c\n+\t$ui_diff tag configure clri4$n -foreground $c\n+\t$ui_diff tag configure clr3$n -foreground $c\n+\t$ui_diff tag configure clri3$n -background $c\n+}\n+$ui_diff tag configure clr1 -font font_diffbold\n+\n $ui_diff tag conf d_cr -elide true\n-$ui_diff tag conf d_@ -foreground blue -font font_diffbold\n+$ui_diff tag conf d_@ -font font_diffbold\n $ui_diff tag conf d_+ -foreground {#00a000}\n $ui_diff tag conf d_- -foreground red\n \ndiff --git a/lib/diff.tcl b/lib/diff.tcl\nindex c628750..dcf0711 100644\n--- a/lib/diff.tcl\n+++ b/lib/diff.tcl\n@@ -294,7 +294,7 @@ proc start_show_diff {cont_info {add_opts {}}} {\n \t}\n \n \tlappend cmd -p\n-\tlappend cmd --no-color\n+\tlappend cmd --color\n \tif {$repo_config(gui.diffcontext) >= 1} {\n \t\tlappend cmd \"-U$repo_config(gui.diffcontext)\"\n \t}\n@@ -332,6 +332,23 @@ proc start_show_diff {cont_info {add_opts {}}} {\n \tfileevent $fd readable [list read_diff $fd $cont_info]\n }\n \n+proc parse_color_line {line} {\n+\tset start 0\n+\tset result \"\"\n+\tset markup [list]\n+\tset regexp {\\033\\[((?:\\d+;)*\\d+)?m}\n+\twhile {[regexp -indices -start $start $regexp $line match code]} {\n+\t\tforeach {begin end} $match break\n+\t\tappend result [string range $line $start [expr {$begin - 1}]]\n+\t\tlappend markup [string length $result] \\\n+\t\t\t[eval [linsert $code 0 string range $line]]\n+\t\tset start [incr end]\n+\t}\n+\tappend result [string range $line $start end]\n+\tif {[llength $markup] < 4} {set markup {}}\n+\treturn [list $result $markup]\n+}\n+\n proc read_diff {fd cont_info} {\n \tglobal ui_diff diff_active is_submodule_diff\n \tglobal is_3way_diff is_conflict_diff current_diff_header\n@@ -340,6 +357,9 @@ proc read_diff {fd cont_info} {\n \n \t$ui_diff conf -state normal\n \twhile {[gets $fd line] >= 0} {\n+\t\tforeach {line markup} [parse_color_line $line] break\n+\t\tset line [string map {\\033 ^} $line]\n+\n \t\t# -- Cleanup uninteresting diff header lines.\n \t\t#\n \t\tif {$::current_diff_inheader} {\n@@ -434,11 +454,23 @@ proc read_diff {fd cont_info} {\n \t\t\t}\n \t\t\t}\n \t\t}\n+\t\tset mark [$ui_diff index \"end - 1 line linestart\"]\n \t\t$ui_diff insert end $line $tags\n \t\tif {[string index $line end] eq \"\\r\"} {\n \t\t\t$ui_diff tag add d_cr {end - 2c}\n \t\t}\n \t\t$ui_diff insert end \"\\n\" $tags\n+\n+\t\tforeach {posbegin colbegin posend colend} $markup {\n+\t\t\tset prefix clr\n+\t\t\tforeach style [split $colbegin \";\"] {\n+\t\t\t\tif {$style eq \"7\"} {append prefix i; continue}\n+\t\t\t\tif {$style < 30 || $style > 47} {continue}\n+\t\t\t\tset a \"$mark linestart + $posbegin chars\"\n+\t\t\t\tset b \"$mark linestart + $posend chars\"\n+\t\t\t\tcatch {$ui_diff tag add $prefix$style $a $b}\n+\t\t\t}\n+\t\t}\n \t}\n \t$ui_diff conf -state disabled\n \n-- \n1.7.3.1.msysgit.0\n"},{"id":"154140","messageId":"AANLkTimSrQ07pPKJ=4H+JL=TpGd7vJD63eea=waATiru@mail.gmail.com","threadId":"25475","inReplyTo":"8762wve5k2.fsf@fox.patthoyts.tk","subject":"Re: [PATCH] git-gui: support core.whitespace rules in diff view","fromName":"Tor Arvid Lund","fromEmail":"torarvid@gmail.com","sentAt":"2010-10-22T12:00:22Z","receivedAt":"2010-10-22T12:00:22Z","isPatch":true,"sender":{"key":"torarvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/439758?v=4"},"body":"On Thu, Oct 21, 2010 at 8:58 PM, Pat Thoyts\n<patthoyts@users.sourceforge.net> wrote:\n> Tor Arvid Lund <torarvid@gmail.com> writes:\n<snip>\n>>I did a quick test (with core.whitespace unset, so the defaults should\n>>be used). I wonder if there is a little bug somewhere else in git-gui.\n>>If I have committed a line like this:\n>>\n>>............Hello world\n>>\n>>and change it to:\n>>\n>>........*Hello world\n>>\n>>I used '.' to indicate Space, and '*' to indicate Tab, so I changed 4\n>>spaces to one tab character. As I understand space-before-tab, this\n>>should render 8 red spaces, 1 white Tab, and then \"Hello world\". But\n>>instead I get 9 white spaces... So the tab gets converted to a space\n>>(I verified that it was not my editor that converted it - it really is\n>>8 SP and 1 TAB).\n>\n> This is caused by the tabstyle being defaulted to 'tabular'. This means\n> the first tab on a line extends to the first tab position and if that\n> lies to the left then the width of a single space is added. Looks like\n> this widget should be using -tabstyle wordprocessor which would do what\n> you expect and move to the next tab position.\n>\n> It is still a tab - just the display width looks wrong.\n<snap>\n\nOk. I tried this, which seems to make it better:\n\ndiff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh\nindex 31ca47d..65d5f2a 100755\n--- a/git-gui/git-gui.sh\n+++ b/git-gui/git-gui.sh\n@@ -3283,6 +3283,7 @@ text $ui_diff -background white -foreground black \\\n        -borderwidth 0 \\\n        -width 80 -height 5 -wrap none \\\n        -font font_diff \\\n+       -tabstyle wordprocessor \\\n        -xscrollcommand {.vpane.lower.diff.body.sbx set} \\\n        -yscrollcommand {.vpane.lower.diff.body.sby set} \\\n        -state disabled\n\n(this goes on top of your most recent patch from an hour ago)\n\n-Tor Arvid-\n"},{"id":"154148","messageId":"AANLkTikiRsrQtv65RBAe6HBfssYoDEuK5xp5t5eZQ2_E@mail.gmail.com","threadId":"25475","inReplyTo":"87pqv2ttjx.fsf_-_@fox.patthoyts.tk","subject":"Re: [PATCH] git-gui: apply color information from git diff output","fromName":"Tor Arvid Lund","fromEmail":"torarvid@gmail.com","sentAt":"2010-10-22T14:40:38Z","receivedAt":"2010-10-22T14:40:38Z","isPatch":true,"sender":{"key":"torarvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/439758?v=4"},"body":"On Fri, Oct 22, 2010 at 12:10 PM, Pat Thoyts\n<patthoyts@users.sourceforge.net> wrote:\n> This patch extracts the ANSI color sequences from git diff output and\n> applies these to the diff view window. This ensures that the gui view\n> makes use of the current git configuration for whitespace display.\n>\n> ANSI codes may include attributes, foreground and background in a single\n> sequence. Handle this and support bold and reverse attributes. Ignore\n> all other attributes.\n>\n> Suggested-by: Tor Arvid Lund <torarvid@gmail.com>\n> Suggested-by: Junio C Hamano <gitster@pobox.com>\n> Signed-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>\n> ---\n\nTested-by: Tor Arvid Lund <torarvid@gmail.com>\n\nIt seems to work well for me. I'm just using the default (unset)\ncore.whitespace settings, so space-before-tab and blank-at-eol both\nshow up with red background, just like in the console.\n\n-Tor Arvid-\n\n> Kevin Ballard <kevin@sb.org> writes:\n>\n>>On Oct 21, 2010, at 8:22 AM, Pat Thoyts wrote:\n>>\n>>> +    while {[regexp -indices -start $start \"\\033\\\\\\[(\\\\d+)?m\" $line match code]} {\n>>\n>>Git currently doesn't emit combined escapes (e.g. \\e[0;31m to reset and then turn on red text), but I can imagine it being enhanced to do this in the future. I would recommend handling it here if you can.\n>>\n>>-Kevin Ballard\n>\n> It turns out that such sequences will be generated by git if the user\n> configures the color.diff.whitespace (eg: bold cyan magenta). This patch\n> handles these cases. I don't see any point trying to handle blink. I\n> could add underline but I don't see that being so appropriate for a\n> GUI. It seems more like something that is configured for a monochrome\n> terminal.\n>\n>  git-gui.sh   |   10 +++++++++-\n>  lib/diff.tcl |   34 +++++++++++++++++++++++++++++++++-\n>  2 files changed, 42 insertions(+), 2 deletions(-)\n>\n> diff --git a/git-gui.sh b/git-gui.sh\n> index 1ccaba1..1fb0254 100755\n> --- a/git-gui.sh\n> +++ b/git-gui.sh\n> @@ -3322,8 +3322,16 @@ pack $ui_diff -side left -fill both -expand 1\n>  pack .vpane.lower.diff.header -side top -fill x\n>  pack .vpane.lower.diff.body -side bottom -fill both -expand 1\n>\n> +foreach {n c} {0 black 1 red4 2 green4 3 yellow4 4 blue4 5 magenta4 6 cyan4 7 grey60} {\n> +       $ui_diff tag configure clr4$n -background $c\n> +       $ui_diff tag configure clri4$n -foreground $c\n> +       $ui_diff tag configure clr3$n -foreground $c\n> +       $ui_diff tag configure clri3$n -background $c\n> +}\n> +$ui_diff tag configure clr1 -font font_diffbold\n> +\n>  $ui_diff tag conf d_cr -elide true\n> -$ui_diff tag conf d_@ -foreground blue -font font_diffbold\n> +$ui_diff tag conf d_@ -font font_diffbold\n>  $ui_diff tag conf d_+ -foreground {#00a000}\n>  $ui_diff tag conf d_- -foreground red\n>\n> diff --git a/lib/diff.tcl b/lib/diff.tcl\n> index c628750..dcf0711 100644\n> --- a/lib/diff.tcl\n> +++ b/lib/diff.tcl\n> @@ -294,7 +294,7 @@ proc start_show_diff {cont_info {add_opts {}}} {\n>        }\n>\n>        lappend cmd -p\n> -       lappend cmd --no-color\n> +       lappend cmd --color\n>        if {$repo_config(gui.diffcontext) >= 1} {\n>                lappend cmd \"-U$repo_config(gui.diffcontext)\"\n>        }\n> @@ -332,6 +332,23 @@ proc start_show_diff {cont_info {add_opts {}}} {\n>        fileevent $fd readable [list read_diff $fd $cont_info]\n>  }\n>\n> +proc parse_color_line {line} {\n> +       set start 0\n> +       set result \"\"\n> +       set markup [list]\n> +       set regexp {\\033\\[((?:\\d+;)*\\d+)?m}\n> +       while {[regexp -indices -start $start $regexp $line match code]} {\n> +               foreach {begin end} $match break\n> +               append result [string range $line $start [expr {$begin - 1}]]\n> +               lappend markup [string length $result] \\\n> +                       [eval [linsert $code 0 string range $line]]\n> +               set start [incr end]\n> +       }\n> +       append result [string range $line $start end]\n> +       if {[llength $markup] < 4} {set markup {}}\n> +       return [list $result $markup]\n> +}\n> +\n>  proc read_diff {fd cont_info} {\n>        global ui_diff diff_active is_submodule_diff\n>        global is_3way_diff is_conflict_diff current_diff_header\n> @@ -340,6 +357,9 @@ proc read_diff {fd cont_info} {\n>\n>        $ui_diff conf -state normal\n>        while {[gets $fd line] >= 0} {\n> +               foreach {line markup} [parse_color_line $line] break\n> +               set line [string map {\\033 ^} $line]\n> +\n>                # -- Cleanup uninteresting diff header lines.\n>                #\n>                if {$::current_diff_inheader} {\n> @@ -434,11 +454,23 @@ proc read_diff {fd cont_info} {\n>                        }\n>                        }\n>                }\n> +               set mark [$ui_diff index \"end - 1 line linestart\"]\n>                $ui_diff insert end $line $tags\n>                if {[string index $line end] eq \"\\r\"} {\n>                        $ui_diff tag add d_cr {end - 2c}\n>                }\n>                $ui_diff insert end \"\\n\" $tags\n> +\n> +               foreach {posbegin colbegin posend colend} $markup {\n> +                       set prefix clr\n> +                       foreach style [split $colbegin \";\"] {\n> +                               if {$style eq \"7\"} {append prefix i; continue}\n> +                               if {$style < 30 || $style > 47} {continue}\n> +                               set a \"$mark linestart + $posbegin chars\"\n> +                               set b \"$mark linestart + $posend chars\"\n> +                               catch {$ui_diff tag add $prefix$style $a $b}\n> +                       }\n> +               }\n>        }\n>        $ui_diff conf -state disabled\n>\n> --\n> 1.7.3.1.msysgit.0\n>\n>\n>\n"},{"id":"154156","messageId":"87lj5qtfwx.fsf@fox.patthoyts.tk","threadId":"25475","inReplyTo":"AANLkTimSrQ07pPKJ=4H+JL=TpGd7vJD63eea=waATiru@mail.gmail.com","subject":"Re: [PATCH] git-gui: support core.whitespace rules in diff view","fromName":"Pat Thoyts","fromEmail":"patthoyts@users.sourceforge.net","sentAt":"2010-10-22T15:18:06Z","receivedAt":"2010-10-22T15:18:06Z","isPatch":true,"sender":{"key":"patthoyts@users.sourceforge.net","avatar":"https://avatars.githubusercontent.com/u/30739?v=4"},"body":"Tor Arvid Lund <torarvid@gmail.com> writes:\n\n>On Thu, Oct 21, 2010 at 8:58 PM, Pat Thoyts\n><patthoyts@users.sourceforge.net> wrote:\n>> Tor Arvid Lund <torarvid@gmail.com> writes:\n><snip>\n>>>I did a quick test (with core.whitespace unset, so the defaults should\n>>>be used). I wonder if there is a little bug somewhere else in git-gui.\n>>>If I have committed a line like this:\n>>>\n>>>............Hello world\n>>>\n>>>and change it to:\n>>>\n>>>........*Hello world\n>>>\n>>>I used '.' to indicate Space, and '*' to indicate Tab, so I changed 4\n>>>spaces to one tab character. As I understand space-before-tab, this\n>>>should render 8 red spaces, 1 white Tab, and then \"Hello world\". But\n>>>instead I get 9 white spaces... So the tab gets converted to a space\n>>>(I verified that it was not my editor that converted it - it really is\n>>>8 SP and 1 TAB).\n>>\n>> This is caused by the tabstyle being defaulted to 'tabular'. This means\n>> the first tab on a line extends to the first tab position and if that\n>> lies to the left then the width of a single space is added. Looks like\n>> this widget should be using -tabstyle wordprocessor which would do what\n>> you expect and move to the next tab position.\n>>\n>> It is still a tab - just the display width looks wrong.\n><snap>\n>\n>Ok. I tried this, which seems to make it better:\n>\n>diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh\n>index 31ca47d..65d5f2a 100755\n>--- a/git-gui/git-gui.sh\n>+++ b/git-gui/git-gui.sh\n>@@ -3283,6 +3283,7 @@ text $ui_diff -background white -foreground black \\\n>        -borderwidth 0 \\\n>        -width 80 -height 5 -wrap none \\\n>        -font font_diff \\\n>+       -tabstyle wordprocessor \\\n>        -xscrollcommand {.vpane.lower.diff.body.sbx set} \\\n>        -yscrollcommand {.vpane.lower.diff.body.sby set} \\\n>        -state disabled\n>\n>(this goes on top of your most recent patch from an hour ago)\n\nI guess I should have mentioned - I already pushed such a patch\nto git-gui.git's master.\n\ncdd321a git-gui: use wordprocessor tab style to ensure tabs work as expected\n\nThanks anyway :)\n-- \nPat Thoyts                            http://www.patthoyts.tk/\nPGP fingerprint 2C 6E 98 07 2C 59 C8 97  10 CE 11 E6 04 E0 B9 DD\n"}]}