#!/afs/ece/usr/tcl/bin/wish -f

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.

} $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.

Tclth tags all comments when teaching an application, but it does not tag the
procedures. This would take too much time, it is better that the user explicitly
tag the procedures if he so chooses.

It is possible to screw up the procedure and comment tags when editing the file.
This will not visibly affect the text, but it will screw up the Tags menu. The
'Update Prodecure/Comment' options will fix this problem when it surfaces.
}


# Gives app all the code necessary to do our functions.
proc teach_code {app widget} {
  if {[widget_bindings $app $widget] == ""} {return ""}
  include_files $app {tcl.tcl th_proc_begin} \
	{modes.tcl th_Text_tag_regions} \
	{edit.Text.tcl th_Text_delete_range} \
	{browse.Text.tcl th_Text_select_range} \
	{paren.Text.tcl th_Text_left_exp}
  do_cmd $app "th_Text_tag_regions $widget comment th_tclcomment_begin th_tclcomment_end th_tclcomment_next\n" 0
}

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


