#!/afs/ece/usr/tcl/bin/wish -f
# The next line is executed by most shells, but not Tcl \
wish $0 $*


set Bind_Keyword [file tail [info script]]
source "[file dirname [info script]]/../aux/frame.tcl"

# Help text.
set Help "" ; append Help {Tclth -- Add keybindings for standard Tcl procedure/comment management.

This program teaches text widgets about Tcl procedures and comments. It is
assumed that the widget will contain Tcl code. Alternately it will work on
Perl code or shell scripts.

} $TH_Bindings_Help {

Widgets of Tclth
} $TH_Frame_Help {

The procedure boundary routines assume your procedures look like:
proc <myproc> {<any_args>} {
<code>
}

There may be as many newlines in the procedure 'header' as you like. However,
a procedure with a different order of things (such as one that uses quotes for
its body), will confuse the procedure boundary routines.

The width used for comment formatting is the width of the text widget, which
may not necessarily be the actual window size.}


# Gives app all the code necessary to do our functions.
proc teach_code {} {
  global Widget Class App
  if {$Class != "Text"} {return ""}
  include_files {tcl.tcl th_proc_begin} \
	{modes.tcl th_Text_tag_regions} \
	{edit.Text.tcl th_Text_indent} \
	{edit.Misc.tcl th_indent} \
	{browse.Text.tcl th_Text_select_range} \
	{paren.Text.tcl th_Text_left_exp}

  do_cmd_set TH(Paint,Hook,$Widget) "th_Text_tag_regions $Widget FUNCTION th_proc_begin th_proc_end th_proc_next \$start \$end"
  do_cmd "$Widget tag configure FUNCTION -background MidnightBlue\n" 0

  do_cmd "th_Misc_paint_add $Widget CONFIG [list { -[A-Za-z]}] [list {-[A-Za-z0-9_]+}] -foreground orange\n" 0
  do_cmd "th_Misc_paint_add $Widget CONFIG [list { --}] [list {-[A-Za-z0-9_]+}] -foreground orange\n" 0
  do_cmd "th_Misc_paint_add $Widget STRING [list {"[^"]*"}] {} -foreground yellow\n" 0
  do_cmd "th_Misc_paint_add $Widget STRING [list {'[^']*'}] {} -foreground yellow\n" 0
  do_cmd "th_Misc_paint_add $Widget KEYWORD [list {(^|[^A-Za-z0-9_])(return|case|switch|if|while|for|foreach|do|else|elseif|goto)($|[^A-Za-z0-9_])}] [list {[A-Za-z0-9_]+}] -foreground red\n" 0
  do_cmd "th_Misc_paint_add $Widget INCLUDE [list {(^|[^A-Za-z0-9_])source .*}] {} -foreground cyan\n" 0
  do_cmd "th_Misc_paint_add $Widget VARIABLE [list {\$\(?\{?[A-Za-z0-9_]*\}?\)?}] {} -foreground green\n" 0
  do_cmd "th_Misc_paint_add $Widget COMMENT {\#.*} {} -foreground wheat\n" 0
  do_cmd "$Widget tag raise sel\n" 0
}

# For a widget, returns the appropriate bindings. (They will depend on the
# widget)
proc widget_bindings {} {
  global Bindings Class
  if {$Class != "Text"} {return ""}
  return [widget_frame_bindings $Bindings(Tcl)]
}
