#!/usr/bin/X11/wafe --f
# script to catch the current selection and to display it
# in a asciiText 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 fw 11;set fh 17
# set font "-adobe-*-medium-r-*-*-14-*-*-*-m-*-*-*"; set fw 9;set fh 14
# set font "-b&h-*-medium-r-*-*-12-*-*-*-m-*-*-*"; set fw 7;set fh 13
 set font "-b&h-*-medium-r-*-*-10-*-*-*-m-*-*-*"; set fw 6;set fh 11

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 {$buf==""} {quit}   # empty selection

# find line with maximum length
set width 0
foreach l $lines {if [string length $l]>$width {set width [string length $l]}}

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
  asciiText t f fromHoriz Quit string $buf font $font wrap word \
    width [expr $width*$fw+2] height [expr [llength $lines]*$fh+4] \
    left chainLeft right chainRight bottom chainBottom rightMargin 0

action t override "<Key>q: exec(quit)"
realize
