A text widget which can be split into two view using emacs shortcuts <Ctrl-x><Key-1> or 2 or 3 etc.
package require snit snit::widget speertext { option -test "" variable mtext delegate method * to mtext constructor {args} { $self configurelist $args pack [panedwindow $win.pan -orient vertical] -side top -expand yes -fill both -pady 2 -padx 2 set pan $win.pan frame $pan.ftext set text [text $pan.ftext.t -yscrollcommand "$pan.ftext.scrolly set"] set mtext $text set sy [scrollbar $pan.ftext.scrolly -orient v -command "$pan.ftext.t yview"] pack $text -side left -expand yes -fill both pack $sy -side right -fill y #::autoscroll::autoscroll $sy frame $pan.ftextp set text [$text peer create $pan.ftextp.t] $text configure -yscrollcommand "$pan.ftextp.scrolly set" set sy [scrollbar $pan.ftextp.scrolly -orient v -command "$pan.ftextp.t yview"] pack $text -side left -expand yes -fill both pack $sy -side right -fill y #::autoscroll::autoscroll $sy $pan add $pan.ftext $pan.ftextp foreach w [list $mtext $text] { bind $w <Control-x><Key-2> [mymethod bindControlXSplit vertical] bind $w <Control-x><Key-3> [mymethod bindControlXSplit horizontal] bind $w <Control-x><Key-1> [mymethod bindControlXSplit zero] } } method bindControlXSplit {orient} { puts $orient if {$orient eq "zero"} { $win.pan forget $win.pan.ftextp return -code break } if {[llength [$win.pan panes]] == 1} { $win.pan add $win.pan.ftextp } $win.pan configure -orient $orient return -code break } }
And here a test.
pack [speertext .spt] -side left -fill both -expand yes for {set i 0} {$i < 50} {incr i 1} { .spt insert end "Hello $i\n" }