if 0 {[Richard Suchenwirth] 2003-08-12 - In contrast to [a basic editor] which has quite some features, here's an utterly simple one which just allows to load and save files, and of course edit, and cut and paste, and whatever is built-in into the [text] widget anyway. And it has a bit "online help"... ;-) This is yet another study in [literate programming]. For the bare source code (26 lines), see [A minimal editor]. It is always a good idea to start a source file with some explanations on the name, purpose, author, and date. I have recently picked up the habit to put this information into a string variable (which in Tcl can easily span multiple lines), so the same info is presented to the reader of the source code, and can be displayed as online help: } set about "minEd - a minimal editor Richard Suchenwirth 2003 F1: help F2: load F3: save " if 0 {The visible part of Graphical User Interfaces consists of [widgets]. For this editor, I of course need a [text] widget, and a vertical [scrollbar]. With the option "-wrap word" for the text widget, another horizontal scrollbar is not needed - lines longer than the window just wrap at word boundaries. Although the scrollbar comes to the right of the text, I create and [pack] it first. The reason is that when a window is made smaller by the user, the widgets last packed first lose visibility. These two lines also illustrate the coupling between a scrollbar and the widget it controls } pack [scrollbar .y -command ".t yview"] -side right -fill y pack [text .t -wrap word -yscrollc ".y set"] -side right -fill both -expand 1 bind . {tk_messageBox -message $about} bind . {loadText .t [tk_getOpenFile]} bind . {saveText .t [tk_getSaveFile]} if {$argv != ""} {loadText .t [lindex $argv 0]} proc loadText {w fn} { if {$fn==""} return wm title . [file tail $fn] set fp [open $fn] $w delete 1.0 end $w insert end [read $fp] close $fp } proc saveText {w fn} { if {$fn==""} return set fp [open $fn w] puts -nonewline $fp [$w get 1.0 "end - 1 c"] close $fp } if 0 {[DKF]: Are you targetting 8.4 or later? If so, add ''-undo 1'' to the options to [text] and get full undo/redo support. Easy!} ---- [Arts and crafts of Tcl-Tk programming]