#!/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 {Htmlth -- Add keybindings for HTML files

This program teaches text widgets about HTML markups and anchors, providing
traversal and selection functions for both.

} $TH_Bindings_Help {

Widgets of Htmlth
} $TH_Frame_Help {

This module will not work well if the parenth module is not already running on
the widget.}


# Gives app all the code necessary to do our functions.
proc teach_code {} {
  global Widget Class App
  if {$Class != "Text"} {return ""}
  include_files {html.tcl th_anchor_begin} \
	{modes.tcl th_Text_tag_regions} \
	{browse.Text.tcl th_Text_select_range}

  if {[catch "send $App lsearch \\\$TH(Paren,Left,$Widget) <" result] || \
	($result == -1)} {
    do_cmd "th_Misc_paren_add $Widget {<} {>} 0\n" 0}

  do_cmd_set TH(Paint,Hook,$Widget) "th_Text_tag_regions $Widget ANCHOR th_anchor_begin th_anchor_end th_anchor_next \$start \$end"
  do_cmd "$Widget tag configure ANCHOR -foreground yellow\n" 0
  do_cmd "th_Misc_paint_add $Widget MARKUP [list {<[A-Za-z0-9/]*>}] {} -foreground wheat\n" 0
  do_cmd "th_Misc_paint_add $Widget HEADING [list {<[Hh][1-6]>.*</[Hh][1-6]>}] {} -foreground green\n" 0
  do_cmd "th_Misc_paint_add $Widget IMAGE [list {<[AaIi][^>]*\.(gif|jpg|jpeg|mpeg|mpg|au|avi|tar)"[^>]*>}] {} -foreground red\n" 0
  do_cmd "th_Misc_paint_add $Widget FORM [list {<[^>]*\?[^>]*>}] {} -foreground orange\n" 0
  do_cmd "th_Misc_paint_add $Widget CHAR [list {&[A-Za-z0-9]*;}] {} -foreground cyan\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(Html)]
}
