Version 0 of WikIndenTk

Updated 2006-03-29 08:27:21

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 <F2> {doIndent 0}
 bind all <F3> {doIndent 1}