#!/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 {Cth -- Add keybindings for standard C function/comment management.

This program teaches text widgets about C functions and comments. It is assumed
that the widget will contain C or C++ code.

} $TH_Bindings_Help {

Widgets of Cth
} $TH_Frame_Help {
The heuristic for finding a function's boundaries are: A function begins with a
type (such as int or char*). (Previous line ends with a close brace or
whitespace or is empty) A function contains some stuff in parentheses and
follows with an open brace. The function ends with said open brace's matching
close brace. If a function does not follow this format, the bounding procs will
screw up on it.

Comments are easier, since their boundaries are strictly defined by C. This
module does not search for C++-style comments beginning with "//"

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

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


# Gives app all the code necessary to do our functions.
proc teach_code {} {
  global Widget
  if {[widget_bindings] == ""} {return ""}
  include_files {c.tcl th_fn_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 "th_Text_tag_regions $Widget comment th_ccomment_begin th_ccomment_end th_ccomment_next\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(C)]
}


