From mboxrd@z Thu Jan 1 00:00:00 1970 From: marian To: sourcenav@sources.redhat.com Subject: Help Indented text Date: Mon, 07 May 2001 04:47:00 -0000 Message-id: <3AF68A47.674D2BBE@mail.jozep.com.au> X-SW-Source: 2001-q2/msg00137.html I have this little patch to give me auto brace completion, which call should I use to get proper indenting. I have used the tkTextInsert but this does not give correct nested indenting. proc sn_rc_editor {view text} { global auto_brace global sn_text_highlight_group if {$sn_text_highlight_group($text) == "c++"} { set auto_brace(for) {" \( ; ; \) \{\n\t" "\n\}"} set auto_brace(if) {" \( FALSE \) \{\n\t" "\n\}"} set auto_brace(else) {" \{\n\t" "\n\}"} set auto_brace(switch) {" \( \) \{\n\tcase " ":\n\tdefault:\n\}"} set auto_brace(while) {" \( \) \{\n\t" "\n\}"} set auto_brace(do) {" \{\n\t" "\n\} while \( FALSE \);"} # Auto build regexp string set names [array names auto_brace] set names [ join $names | ] set auto_brace(names) $names bind $text {auto_brace %W; break} } if {$sn_text_highlight_group($text) == "tcl"} { } proc auto_brace {W} { global auto_brace global sn_text_highlight_group set word [$W get "insert -1 chars wordstart" insert] if { [regexp {[$auto_brace(names)]} $word {}] } { tkTextInsert $w insert [lindex $auto_brace($word) 0] set index [$W index insert] tkTextInsert $w insert [lindex $auto_brace($word) 1] # Crunch out any trailing elements to make it all a bit tidier set tlist [lrange $auto_brace($word) 2 end] foreach element $tlist { ac_paste $W $element } $W mark set insert $index } } }