Version 12 of A minimal editor

Updated 2004-07-23 16:42:53 by MG

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"... ;-)

For another study in literate programming, see A minimal editor explained. }

For a slightly extended minimal editor with some fun (I think) additional abilities A minimally extended minimal editor. -- CB

 set about "minEd - a minimal editor
 Richard Suchenwirth 2003
 F1: help
 F2: load
 F3: save
 "
 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 . <F1> {tk_messageBox -message $about}
 bind . <F2> {loadText .t [tk_getOpenFile]}
 bind . <F3> {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!}

RLH: On Windows XP, I get an error when I try to pass a file to the editor. It gives me invalid command name loadText while executing.... There are spaces in the path to the file so maybe that is it? - RS: That error message means that loadText was called before it was defined. Are you sure you pasted exactly this code into a file? When manually copying, take care not to confuse braces {} and brackets [] - looks like that's your trouble...

MG - If you pass a file to it on the command-line, wouldn't loadText be called before it was defined, from that if {$argv != ""} ? It looks like that should be at the end of the script?


Arts and crafts of Tcl-Tk programming Category Application Category Editor utility`