* Help Indented text
@ 2001-05-07 4:47 marian
0 siblings, 0 replies; only message in thread
From: marian @ 2001-05-07 4:47 UTC (permalink / raw)
To: sourcenav
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 <braceleft> {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
}
}
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2001-05-07 4:47 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-05-07 4:47 Help Indented text marian
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).