This is a small tool to indent/unindent Tcl code for this Wiki. package require Tk proc doIndent {indent} { set d [string trimright [.text get 1.0 end] " \r\n"] set nd "" foreach line [split $d \n] { if {$indent && ([string index $line 0] != " ")} { set line " $line" } elseif {(!$indent) && ([string index $line 0] == " ") && ([string index $line 1] != " ")} { set line [string range $line 1 end] } append nd $line \n } set nd [string trimright $nd " \r\n"] .text delete 1.0 end .text insert end $nd } text .text -yscrollcommand [list .scroll set] -font {{Lucida Console} 8} scrollbar .scroll -command [list .text yview] grid .text .scroll -sticky news grid columnconfigure . 0 -weight 1 grid rowconfigure . 0 -weight 1 bind all {doIndent 0} bind all {doIndent 1}