home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 3 / CD ACTUAL 3.iso / linux / incoming / jstools-.6v3 / jstools- / jstools-tk3.6v3.0 / lib / jeditmodes / mail-mode.tcl < prev    next >
Encoding:
Text File  |  1995-02-10  |  3.0 KB  |  123 lines

  1. # ~/.tk/edittkmodes/mail-mode.tcl - mode for composing mail
  2. ######################################################################
  3.  
  4. proc mode:mail:init { t } {
  5.   global JEDIT_MODEPREFS
  6.   
  7.   j:read_prefs -array JEDIT_MODEPREFS -prefix mail \
  8.     -directory ~/.tk/jeditmodes -file mail-defaults {
  9.     {textfont default}
  10.     {textwidth 80}
  11.     {textheight 24}
  12.     {textwrap char}
  13.     {sabbrev 0}
  14.     {dabbrev 0}
  15.     {autobreak 1}
  16.     {autoindent 0}
  17.     {savestate 0}
  18.     {buttonbar 1}
  19.     {menu,editor 1}
  20.     {menu,file 1}
  21.     {menu,edit 1}
  22.     {menu,prefs 0}
  23.     {menu,abbrev 1}
  24.     {menu,filter 1}
  25.     {menu,format 0}
  26.     {menu,display 0}
  27.     {menu,mode1 1}
  28.     {menu,mode2 1}
  29.     {menu,user 1}
  30.   }
  31. }
  32.  
  33. ######################################################################
  34. # more procedures:
  35.  
  36. # delete the signature if it exists (and is tagged so):
  37.  
  38. proc mode:mail:delete_sig { t } {
  39.   catch {
  40.     $t delete sig.first end
  41.   }
  42. }
  43.  
  44. proc mode:mail:insert_sig { t } {
  45.   global env
  46.   mode:mail:delete_sig $t
  47.   set end [$t index end]
  48.   $t insert end "\n"
  49.   $t insert end [exec cat $env(HOME)/.signature]
  50.   $t insert end "\n"
  51.   $t tag add sig $end end
  52.   $t tag configure sig -font {-*-courier-bold-r-normal--10-100-*}
  53.   $t tag lower sig
  54. }
  55.  
  56. proc mode:mail:start_reply { t } {
  57.   set reply [exec cat "@" | sed {1,/^$/d} | \
  58.     sed {s/^>/  /} | sed {s/^/  /}]
  59.   $t insert end $reply
  60. }
  61.  
  62. proc mode:mail:whom { t } {
  63.   jedit:cmd:save $t
  64.   set filename [jedit:get_filename $t]
  65.   j:more -height 10 -width 60 -title "Recipients" \
  66.     -text [exec whom -check $filename]
  67. }
  68.  
  69. proc mode:mail:to_body { t } {
  70.   $t mark set insert {header.last + 1 lines}
  71. }
  72.  
  73. # BUG - doesn't handle multi-line headers.
  74.  
  75. proc mode:mail:next_header { t } {
  76.   if [$t compare header.last <= insert] {
  77.     $t mark set insert 1.0
  78.   }
  79.   
  80.   set headpart [$t get insert header.last]
  81.   
  82.   set regex [format {(^|%s)[A-Za-z-]*:[ %s]*} "\n" "\t"]
  83.   if [regexp -indices -- $regex $headpart indices] {
  84.     $t tag remove sel 1.0 end
  85.     set valuestart [expr [lindex $indices 1] + 1]
  86.     $t mark set hdrfrom "insert + $valuestart chars"
  87.     $t tag add sel hdrfrom {hdrfrom lineend}
  88.     $t mark set insert {hdrfrom lineend}
  89.   } else {
  90.     # assume we're in the last header field, so jump to body
  91.     mode:mail:to_body $t
  92.   }
  93. }
  94.  
  95. ######################################################################
  96. # define the Mail menu:
  97. ######################################################################
  98.  
  99. proc mode:mail:mkmenu1 { menu t } {
  100.   menubutton $menu -text {Mail} -menu $menu.m
  101.   
  102.   menu $menu.m
  103.   $menu.m add command -label {Sign Email} -command "
  104.     mode:mail:insert_sig $t
  105.   "
  106.   $menu.m add command -label {Done} -command "
  107.     jedit:cmd:done $t
  108.   "
  109. }
  110.  
  111. ######################################################################
  112. # define the button bar:
  113. ######################################################################
  114.  
  115. proc mode:mail:mkbuttons { w t } {
  116.   j:buttonbar $w -pady 2 -buttons [format {
  117.     {done Done {jedit:cmd:done %s}}
  118.     {sign Sign {mode:mail:insert_sig %s}}
  119.   } $t $t]
  120.   return $w
  121. }
  122.  
  123.