#!../wafe --f
# script to catch the current selection and to display it
# in a Text widget. It is quite conveniant to bind
# in a *twm for example Meta Button 2 to this script by 
# adding the following line to the *twmrc file. 
#
#  Button2 = m : root : !"xpaste &"
#
# It is also a good idea to remove the window title...
# Gustaf Neumann, May 93

# set font "-adobe-*-medium-r-*-*-18-*-*-*-m-*-*-*"
# set font "-adobe-*-medium-r-*-*-14-*-*-*-m-*-*-*"
 set font "-b&h-*-medium-r-*-*-12-*-*-*-m-*-*-*"
# set font "-b&h-*-medium-r-*-*-10-*-*-*-m-*-*-*"

mergeResources topLevel *background wheat *borderWidth 0

# set variable buf to selection buffer and variable lines to a List of lines
set lines [split [set buf [string trim [fetchBuffer topLevel 0] \n]] \n]
if [string match "" $buf] {quit}   # empty selection

# find line with maximum length, assume, a tab takes 8 spaces
set width 0
foreach l $lines {
  regsub -all \t $l {        } l
  set llength [string length $l]
  if $llength>$width {set width $llength}
}

Form f topLevel
  Command Quit f callback quit \
      font "-b&h-lucida-bold-r-*-*-14-*-*-*-p-*-iso8859-*" \
      top chainTop bottom chainTop left chainLeft right chainLeft
  Text t f fromHoriz Quit \
      string $buf font $font wrap word scrollVertical whenNeeded \
      left chainLeft right chainRight bottom chainBottom top chainTop \
      rightMargin 0  translations "#override\n<Key>q: exec(quit)"

sV t height [expr [llength $lines]*[fontHeight t font]+4] \
    width  [expr $width*[textWidth t font 0]+2]
realize

