[prev in list] [next in list] [prev in thread] [next in thread] 

List:       fossil-users
Subject:    [fossil-users] fossil diff --tk
From:       Ramon_Ribó <ramsan () compassis ! com>
Date:       2014-04-22 11:39:18
Message-ID: CAF_UOkNGRw=RCNkxRiE5a7gxgwkWa8OWTbGr_PSk-eAR9Uhz_g () mail ! gmail ! com
[Download RAW message or body]

Hello,

I've implemented in diff -tk a new capability and a bug fix:

- Keys 'p' and 'n' are used to navigate to the previous and next difference

- A bug fix in "Save as" when users cancels file selection

There is an attached patch with the code. Please feel free to use it
in any way in case you consider it interesting.

RR

["improved-diff-tk-8afa2fea7c.patch" (text/x-patch)]

Index: src/diffcmd.c
==================================================================
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -772,8 +772,91 @@
 @       viewDiff [lindex $range 0]
 @     }
 @   }
 @ }
+@
+@ proc prev_next_diff { prev_next } {
+@	
+@	set range [.txtA tag nextrange active 1.0 end]
+@	
+@	if { $prev_next eq "prev" } {
+@	    set idx0 [lindex $range 0]
+@	    if { $idx0 eq "" } { set idx0 end }
+@	    
+@	    set idx ""
+@	    foreach tag [list add rm chng fn] {
+@		if { $tag in "rm chng fn" } {
+@		    set w .txtA
+@		} else {
+@		    set w .txtB
+@		}
+@		lassign [$w tag prevrange $tag $idx0 1.0] a b
+@		if { $idx eq "" || ($a ne "" && [$w compare $a > $idx]) } {
+@		    set idx $a
+@		    set idx_end $b
+@		    set tagB $tag
+@		    set wB $w
+@		}
+@	    }
+@	    if { $idx ne "" } {
+@		while 1 {
+@		    lassign [$wB tag prevrange $tagB $idx 1.0] a b
+@		    if { $b ne "" && [$wB compare $b == "$idx - 1 l lineend"] } {
+@		        set idx $a
+@		    } else {
+@		        break
+@		    }
+@		}
+@	    }
+@	} else {
+@	    set idx0 [lindex $range 1]
+@	    if { $idx0 eq "" } { set idx0 1.0 }
+@	    
+@	    set idx ""
+@	    foreach tag [list add rm chng fn] {
+@		if { $tag in "rm chng fn" } {
+@		    set w .txtA
+@		} else {
+@		    set w .txtB
+@		}
+@		lassign [$w tag nextrange $tag $idx0 end] a b
+@		if { $idx eq "" || ($a ne "" && [$w compare $a < $idx]) } {
+@		    set idx $a
+@		    set idx_end $b
+@		    set tagB $tag
+@		    set wB $w
+@		}
+@	    }
+@	    if { $idx ne "" } {
+@		while 1 {
+@		    lassign [$wB tag nextrange $tagB $idx_end end] a b
+@		    if { $a ne "" && [$wB compare $a == "$idx_end + 1 l linestart"] } {
+@		        set idx_end $b
+@		    } else {
+@		        break
+@		    }
+@		}
+@	    }
+@	}
+@	if { $idx eq "" } {
+@	    bell
+@	    return
+@	}
+@	set idx [.txtA index "$idx linestart"]
+@	if { $tagB ne "fn" } {
+@	    set idx_end [.txtA index "$idx_end +1l linestart"]
+@	}
+@	.txtA tag remove active 1.0 end
+@	.txtA tag add active $idx $idx_end
+@	.txtA tag configure active -borderwidth 2 -relief raised -background #eeeeee -foreground black
+@	if { $tagB ne "fn" } {
+@	    .txtA tag lower active
+@	} else {
+@	    .txtA tag raise active
+@	}
+@	.txtA see 1.0
+@	.txtA see $idx
+@ }
 @
 @ proc xvis {col} {
 @   set view [$col xview]
 @   return [expr {[lindex $view 1]-[lindex $view 0]}]
@@ -835,8 +918,10 @@
 @ bind . <q> exit
 @ bind . <Destroy> {after 0 exit}
 @ bind . <Tab> {cycleDiffs; break}
 @ bind . <<PrevWindow>> {cycleDiffs 1; break}
+@ bind . <Key-p> {prev_next_diff prev}
+@ bind . <Key-n> {prev_next_diff next}
 @ bind . <Return> {
 @   event generate .bb.files <1>
 @   event generate .bb.files <ButtonRelease-1>
 @   break
@@ -933,8 +1018,9 @@
 @ update idletasks
 @
 @ proc saveDiff {} {
 @   set fn [tk_getSaveFile]
+@   if { $fn eq "" } { return }
 @   set out [open $fn wb]
 @   puts $out "#!/usr/bin/tclsh\n#\n# Run this script using 'tclsh' or 'wish'"
 @   puts $out "# to see the graphical diff.\n#"
 @   puts $out "set fossilcmd {}"


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic