#!/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]]/../util/frame.tcl"

# Help text.
set Help "" ; append Help {Msgth -- Add keybindings for message files

This program teaches text widgets about mail/news headers and markups.

} $TH_Bindings_Help {

Widgets of Msgth
} $TH_Frame_Help


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

  do_cmd_set TH(Paint,Hook,$Widget) "th_Text_tag_msgs $Widget \$start \$end"
  do_cmd "th_Misc_paint_add $Widget QUOTATION [list {^[|>].*}] {} -foreground wheat\n" 0
  do_cmd "$Widget tag configure HEADER -font 7x13\n" 0

  do_cmd "th_Misc_paint_add $Widget ADDRESS [list {([(<, 	`'"]|^)[A-Za-z][-A-Za-z0-9%._+]*@[-A-Za-z0-9]+\.[-A-Za-z0-9]}] [list {[-A-Za-z0-9%._+]*@[-A-Za-z0-9.]*}] -underline 1\n" 0
  do_cmd "th_Misc_paint_add $Widget URL [list {(http|ftp|file|telnet|news|mailto|gohper)://[-A-Za-z0-9./?@%~]*}] {} -relief raised -borderwidth 2\n" 0

  do_cmd "th_Misc_paint_add $Widget TO [list {^[>|]? *(Apparently-)?(To|TO|to|CC|Cc|cc):.*}] {} -foreground yellow -font \[option get $Widget font Font\]\n" 0
  do_cmd "th_Misc_paint_add $Widget FROM [list {^[>|]? *From:.*}] {} -foreground cyan -font \[option get $Widget font Font\]\n" 0
  do_cmd "th_Misc_paint_add $Widget DATE [list {^[>|]? *Date:.*}] {} -foreground red -font \[option get $Widget font Font\]\n" 0
  do_cmd "th_Misc_paint_add $Widget SUBJECT [list {^[>|]? *Subj(ect)?:.*}] {} -foreground green -font \[option get $Widget font Font\]\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(Msg)]
}
